]> www.infradead.org Git - users/mchehab/andors-trail.git/commitdiff
Refactored how item stats are applied to actors, in preparation of fighting style...
authorOskar Wiksten <oskar.wiksten@gmail.com>
Sun, 9 Sep 2012 08:26:28 +0000 (10:26 +0200)
committerOskar Wiksten <oskar.wiksten@gmail.com>
Sun, 7 Oct 2012 14:10:39 +0000 (16:10 +0200)
AndorsTrail/src/com/gpl/rpg/AndorsTrail/activity/HeroinfoActivity_Inventory.java
AndorsTrail/src/com/gpl/rpg/AndorsTrail/controller/ActorStatsController.java
AndorsTrail/src/com/gpl/rpg/AndorsTrail/controller/ItemController.java
AndorsTrail/src/com/gpl/rpg/AndorsTrail/controller/SkillController.java
AndorsTrail/src/com/gpl/rpg/AndorsTrail/model/ability/ActorConditionTypeCollection.java
AndorsTrail/src/com/gpl/rpg/AndorsTrail/model/item/Inventory.java
AndorsTrail/src/com/gpl/rpg/AndorsTrail/model/item/ItemCategory.java
AndorsTrail/src/com/gpl/rpg/AndorsTrail/model/item/ItemType.java

index 5868dbfb36c69136708fcacf3ee413fa368b998f..6906ce21d8c8570fe5d251db6b7a5561fda80a8a 100644 (file)
@@ -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;
        }
index 0d53eab0efb9e5fc32e9b5ec1d0d2be695c12625..48c0a7a59f090e499e85757cb30fadcee1a75688 100644 (file)
@@ -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) {
index 7681e5e8cd2de3d77a223cdee494fa9a4a5c0bd5..41cfe90741e40a6a69b9364340c1d33365cbf226 100644 (file)
@@ -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) {
index d9eb9faf0c3b2bcfa742ed6fd9f6f69daa5a955b..3313ffc2451578c214882bbc093745242ea3bbca 100644 (file)
@@ -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;
+       }
 }
index aeb13357db5165f095e4477ad99dc70c9271ebfe..92793fc78dc505bab18594d7dd397774dbc21058 100644 (file)
@@ -21,4 +21,8 @@ public class ActorConditionTypeCollection {
        public void initialize(final ActorConditionsTypeParser parser, String input) {
                parser.parseRows(input, conditionTypes);
        }
+
+       public HashMap<String, ActorConditionType> UNITTEST_getAllActorConditionsTypes() {
+               return conditionTypes;
+       }
 }
index 54925a199d8a609e2e548d91beef83296c6ee07c..d2175681241b68b6a937f1ad56bfdf8e49d23540 100644 (file)
@@ -42,6 +42,14 @@ public final class Inventory extends ItemContainer {
                return false;\r
        }\r
        \r
+       public static boolean isArmorSlot(int slot) {\r
+               if (slot == WEARSLOT_HEAD) return true;\r
+               else if (slot == WEARSLOT_BODY) return true;\r
+               else if (slot == WEARSLOT_HAND) return true;\r
+               else if (slot == WEARSLOT_FEET) return true;\r
+               else return false;\r
+       }\r
+       \r
        \r
        // ====== PARCELABLE ===================================================================\r
 \r
index d519c52ca01cc920c4376d7f2a08c50ca420c77f..43dd3ff7d61fa2b01333fdfccd3476286d7934c8 100644 (file)
@@ -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;
        }
 }
index bbae17c22e8a5d9a06af0c898a8a3b9c0c9213fd..6ccd3d643eb5fb961ce2f3a9fe88e1faccb2d76a 100644 (file)
@@ -45,6 +45,8 @@ public final class ItemType {
        public boolean isQuestItem() { return displayType == DISPLAYTYPE_QUEST; }\r
        public boolean isOrdinaryItem() { return displayType == DISPLAYTYPE_ORDINARY; }\r
        public boolean isWeapon() { return category.isWeapon(); }\r
+       public boolean isArmor() { return category.isArmor(); }\r
+       public boolean isShield() { return category.isShield(); }\r
        public boolean isTwohandWeapon() { return category.isTwohandWeapon(); }\r
        public boolean isOffhandCapableWeapon() { return category.isOffhandCapableWeapon(); }\r
        public boolean isSellable() {\r