From: Oskar Wiksten Date: Sun, 9 Sep 2012 08:26:28 +0000 (+0200) Subject: Refactored how item stats are applied to actors, in preparation of fighting style... X-Git-Url: https://www.infradead.org/git/?a=commitdiff_plain;h=ec8609374643ca3dc0a43ea794c05552fcc50fd7;p=users%2Fmchehab%2Fandors-trail.git Refactored how item stats are applied to actors, in preparation of fighting style skills. --- diff --git a/AndorsTrail/src/com/gpl/rpg/AndorsTrail/activity/HeroinfoActivity_Inventory.java b/AndorsTrail/src/com/gpl/rpg/AndorsTrail/activity/HeroinfoActivity_Inventory.java index 5868dbf..6906ce2 100644 --- a/AndorsTrail/src/com/gpl/rpg/AndorsTrail/activity/HeroinfoActivity_Inventory.java +++ b/AndorsTrail/src/com/gpl/rpg/AndorsTrail/activity/HeroinfoActivity_Inventory.java @@ -137,10 +137,14 @@ public final class HeroinfoActivity_Inventory extends Activity { private static int suggestInventorySlot(ItemType itemType, Player player) { int slot = itemType.category.inventorySlot; + if (player.inventory.isEmptySlot(slot)) return slot; + if (slot == Inventory.WEARSLOT_RING) { - if (!player.inventory.isEmptySlot(slot)) return slot + 1; - } else if (itemType.isOffhandCapableWeapon()) { - if (player.inventory.isEmptySlot(Inventory.WEARSLOT_SHIELD)) return Inventory.WEARSLOT_SHIELD; + return slot + 1; + } else if (itemType.isOffhandCapableWeapon()) { + ItemType mainWeapon = player.inventory.wear[Inventory.WEARSLOT_WEAPON]; + if (mainWeapon != null && mainWeapon.isTwohandWeapon()) return slot; + else if (player.inventory.isEmptySlot(Inventory.WEARSLOT_SHIELD)) return Inventory.WEARSLOT_SHIELD; } return slot; } diff --git a/AndorsTrail/src/com/gpl/rpg/AndorsTrail/controller/ActorStatsController.java b/AndorsTrail/src/com/gpl/rpg/AndorsTrail/controller/ActorStatsController.java index 0d53eab..48c0a7a 100644 --- a/AndorsTrail/src/com/gpl/rpg/AndorsTrail/controller/ActorStatsController.java +++ b/AndorsTrail/src/com/gpl/rpg/AndorsTrail/controller/ActorStatsController.java @@ -146,33 +146,29 @@ public class ActorStatsController { private static void applyEffectsFromCurrentConditions(Actor actor) { for (ActorCondition c : actor.conditions) { - applyAbilityEffects(actor, c.conditionType.abilityEffect, false, c.magnitude); + applyAbilityEffects(actor, c.conditionType.abilityEffect, c.magnitude); } - actor.health.capAtMax(); - actor.ap.capAtMax(); } - public static void applyAbilityEffects(Actor actor, AbilityModifierTraits effects, boolean isWeapon, int magnitude) { + public static void applyAbilityEffects(Actor actor, AbilityModifierTraits effects, int multiplier) { if (effects == null) return; CombatTraits actorCombatTraits = actor.combatTraits; - actor.health.addToMax(effects.maxHPBoost * magnitude); - actor.ap.addToMax(effects.maxAPBoost * magnitude); - actor.actorTraits.moveCost += (effects.moveCostPenalty * magnitude); + actor.health.addToMax(effects.maxHPBoost * multiplier); + actor.ap.addToMax(effects.maxAPBoost * multiplier); + actor.actorTraits.moveCost += effects.moveCostPenalty * multiplier; CombatTraits combatTraits = effects.combatProficiency; if (combatTraits != null) { - if (!isWeapon) { // For weapons, these stats are modified elsewhere (since they are not cumulative) - actorCombatTraits.attackCost += (combatTraits.attackCost * magnitude); - actorCombatTraits.criticalMultiplier += (combatTraits.criticalMultiplier * magnitude); - } - actorCombatTraits.attackChance += (combatTraits.attackChance * magnitude); - actorCombatTraits.criticalSkill += (combatTraits.criticalSkill * magnitude); - actorCombatTraits.damagePotential.add(combatTraits.damagePotential.current * magnitude, true); - actorCombatTraits.damagePotential.max += (combatTraits.damagePotential.max * magnitude); - actorCombatTraits.blockChance += (combatTraits.blockChance * magnitude); - actorCombatTraits.damageResistance += (combatTraits.damageResistance * magnitude); + actorCombatTraits.attackCost += combatTraits.attackCost * multiplier; + //criticalMultiplier should not be increased. It is always defined by the weapon in use. + actorCombatTraits.attackChance += combatTraits.attackChance * multiplier; + actorCombatTraits.criticalSkill += combatTraits.criticalSkill * multiplier; + actorCombatTraits.damagePotential.add(combatTraits.damagePotential.current * multiplier, true); + actorCombatTraits.damagePotential.addToMax(combatTraits.damagePotential.max * multiplier); + actorCombatTraits.blockChance += combatTraits.blockChance * multiplier; + actorCombatTraits.damageResistance += combatTraits.damageResistance * multiplier; } if (actorCombatTraits.attackCost <= 0) actorCombatTraits.attackCost = 1; @@ -189,6 +185,8 @@ public class ActorStatsController { if (actor.isPlayer) SkillController.applySkillEffects((Player) actor); applyEffectsFromCurrentConditions(actor); if (actor.isPlayer) ItemController.recalculateHitEffectsFromWornItems((Player) actor); + actor.health.capAtMax(); + actor.ap.capAtMax(); } public void applyConditionsToPlayer(Player player, boolean isFullRound) { diff --git a/AndorsTrail/src/com/gpl/rpg/AndorsTrail/controller/ItemController.java b/AndorsTrail/src/com/gpl/rpg/AndorsTrail/controller/ItemController.java index 7681e5e..41cfe90 100644 --- a/AndorsTrail/src/com/gpl/rpg/AndorsTrail/controller/ItemController.java +++ b/AndorsTrail/src/com/gpl/rpg/AndorsTrail/controller/ItemController.java @@ -7,7 +7,6 @@ import android.view.View; import com.gpl.rpg.AndorsTrail.Dialogs; import com.gpl.rpg.AndorsTrail.context.ViewContext; import com.gpl.rpg.AndorsTrail.context.WorldContext; -import com.gpl.rpg.AndorsTrail.model.CombatTraits; import com.gpl.rpg.AndorsTrail.model.ModelContainer; import com.gpl.rpg.AndorsTrail.model.ability.ActorConditionEffect; import com.gpl.rpg.AndorsTrail.model.ability.SkillCollection; @@ -101,24 +100,41 @@ public final class ItemController { } public static void applyInventoryEffects(Player player) { - ItemType weapon = player.inventory.wear[Inventory.WEARSLOT_WEAPON]; + ItemType weapon = getMainWeapon(player); if (weapon != null) { - if (weapon.effects_equip != null) { - CombatTraits weaponTraits = weapon.effects_equip.combatProficiency; - if (weaponTraits != null) { - player.combatTraits.attackCost = weaponTraits.attackCost; - player.combatTraits.criticalMultiplier = weaponTraits.criticalMultiplier; - } - } + player.combatTraits.attackCost = 0; + player.combatTraits.criticalMultiplier = weapon.effects_equip.combatProficiency.criticalMultiplier; } - for (int i = 0; i < Inventory.NUM_WORN_SLOTS; ++i) { - ItemType type = player.inventory.wear[i]; - if (type == null) continue; - - final boolean isWeapon = type.isWeapon(); - ActorStatsController.applyAbilityEffects(player, type.effects_equip, isWeapon, 1); + applyInventoryEffects(player, Inventory.WEARSLOT_WEAPON); + applyInventoryEffects(player, Inventory.WEARSLOT_SHIELD); + applyInventoryEffects(player, Inventory.WEARSLOT_HEAD); + applyInventoryEffects(player, Inventory.WEARSLOT_BODY); + applyInventoryEffects(player, Inventory.WEARSLOT_HAND); + applyInventoryEffects(player, Inventory.WEARSLOT_FEET); + applyInventoryEffects(player, Inventory.WEARSLOT_NECK); + applyInventoryEffects(player, Inventory.WEARSLOT_RING); + + SkillController.applySkillEffectsFromItemProficiencies(player); + SkillController.applySkillEffectsFromFightingStyles(player); + } + public static ItemType getMainWeapon(Player player) { + ItemType itemType = player.inventory.wear[Inventory.WEARSLOT_WEAPON]; + if (itemType != null) return itemType; + itemType = player.inventory.wear[Inventory.WEARSLOT_SHIELD]; + if (itemType != null && itemType.isWeapon()) return itemType; + return null; + } + + private static void applyInventoryEffects(Player player, int slot) { + ItemType type = player.inventory.wear[slot]; + if (type == null) return; + if (slot == Inventory.WEARSLOT_SHIELD) { + ItemType mainHandItem = player.inventory.wear[Inventory.WEARSLOT_WEAPON]; + // The stats for off-hand weapons will be added later in SkillController.applySkillEffectsFromFightingStyles + if (SkillController.isDualWielding(mainHandItem, type)) return; } + ActorStatsController.applyAbilityEffects(player, type.effects_equip, 1); } public static void recalculateHitEffectsFromWornItems(Player player) { diff --git a/AndorsTrail/src/com/gpl/rpg/AndorsTrail/controller/SkillController.java b/AndorsTrail/src/com/gpl/rpg/AndorsTrail/controller/SkillController.java index d9eb9fa..3313ffc 100644 --- a/AndorsTrail/src/com/gpl/rpg/AndorsTrail/controller/SkillController.java +++ b/AndorsTrail/src/com/gpl/rpg/AndorsTrail/controller/SkillController.java @@ -10,6 +10,7 @@ import com.gpl.rpg.AndorsTrail.model.ability.SkillInfo; import com.gpl.rpg.AndorsTrail.model.actor.Actor; import com.gpl.rpg.AndorsTrail.model.actor.Monster; import com.gpl.rpg.AndorsTrail.model.actor.Player; +import com.gpl.rpg.AndorsTrail.model.item.ItemType; import com.gpl.rpg.AndorsTrail.model.item.ItemTypeCollection; import com.gpl.rpg.AndorsTrail.model.item.DropList.DropItem; import com.gpl.rpg.AndorsTrail.util.ConstRange; @@ -152,4 +153,14 @@ public final class SkillController { } } } + + public static void applySkillEffectsFromItemProficiencies(Player player) { + } + + public static void applySkillEffectsFromFightingStyles(Player player) { + } + + public static boolean isDualWielding(ItemType mainHandItem, ItemType offHandItem) { + return false; + } } diff --git a/AndorsTrail/src/com/gpl/rpg/AndorsTrail/model/ability/ActorConditionTypeCollection.java b/AndorsTrail/src/com/gpl/rpg/AndorsTrail/model/ability/ActorConditionTypeCollection.java index aeb1335..92793fc 100644 --- a/AndorsTrail/src/com/gpl/rpg/AndorsTrail/model/ability/ActorConditionTypeCollection.java +++ b/AndorsTrail/src/com/gpl/rpg/AndorsTrail/model/ability/ActorConditionTypeCollection.java @@ -21,4 +21,8 @@ public class ActorConditionTypeCollection { public void initialize(final ActorConditionsTypeParser parser, String input) { parser.parseRows(input, conditionTypes); } + + public HashMap UNITTEST_getAllActorConditionsTypes() { + return conditionTypes; + } } diff --git a/AndorsTrail/src/com/gpl/rpg/AndorsTrail/model/item/Inventory.java b/AndorsTrail/src/com/gpl/rpg/AndorsTrail/model/item/Inventory.java index 54925a1..d217568 100644 --- a/AndorsTrail/src/com/gpl/rpg/AndorsTrail/model/item/Inventory.java +++ b/AndorsTrail/src/com/gpl/rpg/AndorsTrail/model/item/Inventory.java @@ -42,6 +42,14 @@ public final class Inventory extends ItemContainer { return false; } + public static boolean isArmorSlot(int slot) { + if (slot == WEARSLOT_HEAD) return true; + else if (slot == WEARSLOT_BODY) return true; + else if (slot == WEARSLOT_HAND) return true; + else if (slot == WEARSLOT_FEET) return true; + else return false; + } + // ====== PARCELABLE =================================================================== diff --git a/AndorsTrail/src/com/gpl/rpg/AndorsTrail/model/item/ItemCategory.java b/AndorsTrail/src/com/gpl/rpg/AndorsTrail/model/item/ItemCategory.java index d519c52..43dd3ff 100644 --- a/AndorsTrail/src/com/gpl/rpg/AndorsTrail/model/item/ItemCategory.java +++ b/AndorsTrail/src/com/gpl/rpg/AndorsTrail/model/item/ItemCategory.java @@ -1,16 +1,16 @@ package com.gpl.rpg.AndorsTrail.model.item; public final class ItemCategory { - private static final int SIZE_NONE = 0; - private static final int SIZE_LIGHT = 1; - private static final int SIZE_STD = 2; - private static final int SIZE_LARGE = 3; + public static final int SIZE_NONE = 0; + public static final int SIZE_LIGHT = 1; + public static final int SIZE_STD = 2; + public static final int SIZE_LARGE = 3; public final String id; public final String displayName; public final int inventorySlot; private final int actionType; - private final int size; + public final int size; public ItemCategory(String id, String displayName, int actionType, int inventorySlot, int size) { this.id = id; @@ -26,15 +26,17 @@ public final class ItemCategory { public boolean isEquippable() { return actionType == ACTIONTYPE_EQUIP; } public boolean isUsable() { return actionType == ACTIONTYPE_USE; } public boolean isWeapon() { return inventorySlot == Inventory.WEARSLOT_WEAPON; } + public boolean isShield() { return inventorySlot == Inventory.WEARSLOT_SHIELD; } + public boolean isArmor() { return Inventory.isArmorSlot(inventorySlot); } public boolean isTwohandWeapon() { - if (!isWeapon()) return false; + /*if (!isWeapon()) return false; else if (size == SIZE_LARGE) return true; - else return false; + else*/ return false; } public boolean isOffhandCapableWeapon() { - if (!isWeapon()) return false; + /*if (!isWeapon()) return false; else if (size == SIZE_LIGHT) return true; else if (size == SIZE_STD) return true; - else return false; + else*/ return false; } } diff --git a/AndorsTrail/src/com/gpl/rpg/AndorsTrail/model/item/ItemType.java b/AndorsTrail/src/com/gpl/rpg/AndorsTrail/model/item/ItemType.java index bbae17c..6ccd3d6 100644 --- a/AndorsTrail/src/com/gpl/rpg/AndorsTrail/model/item/ItemType.java +++ b/AndorsTrail/src/com/gpl/rpg/AndorsTrail/model/item/ItemType.java @@ -45,6 +45,8 @@ public final class ItemType { public boolean isQuestItem() { return displayType == DISPLAYTYPE_QUEST; } public boolean isOrdinaryItem() { return displayType == DISPLAYTYPE_ORDINARY; } public boolean isWeapon() { return category.isWeapon(); } + public boolean isArmor() { return category.isArmor(); } + public boolean isShield() { return category.isShield(); } public boolean isTwohandWeapon() { return category.isTwohandWeapon(); } public boolean isOffhandCapableWeapon() { return category.isOffhandCapableWeapon(); } public boolean isSellable() {