Explorar el Código

Utilize stances in combat.

Reddo hace 5 años
padre
commit
b8a44b275b
Se han modificado 1 ficheros con 53 adiciones y 38 borrados
  1. 53 38
      app/World/Classes/Action/ActionAttack.ts

+ 53 - 38
app/World/Classes/Action/ActionAttack.ts

@@ -95,60 +95,75 @@ class ActionAttack extends Action {
         }
     });
 
+    // TODO: Reduce these god functions into smaller functions that are easier to modify by future changes.
     public static checkAccuracyRule = ActionAttack.check.createAndAddRule({
         name : "Attack - Is it a hit?",
         code : async (runner : RulebookRunner<ActionAttack>) => {
             let action = runner.noun;
             let actorDex = (<Person> runner.noun.actor).getStat(Attributes.Agility);
+            let actor = (<Person> runner.noun.actor);
+            if (actor.stance == PersonStance.ALLFOURS) {
+                actorDex = Math.floor(actorDex/2);
+            }
+
             let targetDex = 0;
             let target = runner.noun.getTarget();
             if (target instanceof Person) {
                 targetDex = target.getStat(Attributes.Agility);
-            }
+                if (target.stance == PersonStance.ALLFOURS) {
+                    targetDex = Math.floor(targetDex/2);
+                } else if (target.stance == PersonStance.KNOCKEDOUT) {
+                    targetDex = 0;
+                }
 
 
-            let reaction = ActionAttackReaction.DODGE;
-            if (target == WorldState.player) {
-                Elements.CurrentTurnHandler.printAsContent(new Say(action.actor, " ", ActionAttack.gettingAttacked.getOne()));
-                let choices = ["Counter-Attack", "Dodge", "Resist"];
-                let choice = await Controls.giveChoices(false, ...choices);
-                if (choice[1] == 0) {
-                    reaction = ActionAttackReaction.COUNTERATTACK;
-                } else if (choice[1] == 2) {
-                    reaction = ActionAttackReaction.DODGE;
-                } else {
+                let reaction = ActionAttackReaction.DODGE;
+                if (target.stance == PersonStance.KNOCKEDOUT) {
                     reaction = ActionAttackReaction.RESIST;
+                } else {
+                    if (target == WorldState.player) {
+                        Elements.CurrentTurnHandler.printAsContent(new Say(action.actor, " ", ActionAttack.gettingAttacked.getOne()));
+                        let choices = ["Counter-Attack", "Dodge", "Resist"];
+                        let choice = await Controls.giveChoices(false, ...choices);
+                        if (choice[1] == 0) {
+                            reaction = ActionAttackReaction.COUNTERATTACK;
+                        } else if (choice[1] == 2) {
+                            reaction = ActionAttackReaction.DODGE;
+                        } else {
+                            reaction = ActionAttackReaction.RESIST;
+                        }
+                    }
                 }
-            }
 
-            let weapons = action.getWeapons();
-            for (let i = 0; i < weapons.length; i++) {
-                (<Person> action.actor).changeStamina(- weapons[i].attackCost);
-            }
-            if (weapons.length == 0) {
-                (<Person> action.actor).changeStamina(- ActionAttack.fistCost)
-            }
+                let weapons = action.getWeapons();
+                for (let i = 0; i < weapons.length; i++) {
+                    (<Person> action.actor).changeStamina(- weapons[i].attackCost);
+                }
+                if (weapons.length == 0) {
+                    (<Person> action.actor).changeStamina(- ActionAttack.fistCost)
+                }
 
-            action.targetReaction = reaction;
+                action.targetReaction = reaction;
 
-            if (reaction == ActionAttackReaction.DODGE) {
-                (<Person> target).changeStamina(- ActionAttack.dodgeCost);
-                let attack =  Math.floor(Math.random() * (ActionAttack.randomness + ActionAttack.randomness + 1)) - ActionAttack.randomness;
-                let defense = Math.floor(Math.random() * (ActionAttack.randomness + ActionAttack.randomness + 1)) - ActionAttack.randomness;
-                attack += actorDex;
-                defense += targetDex;
-                if (attack < defense) {
-                    action.generateDescription(
-                        (new ContentGroup())
-                            .addUnit(
-                                (new CombatUnit())
-                                    .setActor(action.actor)
-                                    .setTarget(target)
-                                    .setWeapon(...weapons)
-                                    .addMarker(CombatHit.MISS)
-                            )
-                    );
-                    return false;
+                if (reaction == ActionAttackReaction.DODGE) {
+                    (<Person> target).changeStamina(- ActionAttack.dodgeCost);
+                    let attack =  Math.floor(Math.random() * (ActionAttack.randomness + ActionAttack.randomness + 1)) - ActionAttack.randomness;
+                    let defense = Math.floor(Math.random() * (ActionAttack.randomness + ActionAttack.randomness + 1)) - ActionAttack.randomness;
+                    attack += actorDex;
+                    defense += targetDex;
+                    if (attack < defense) {
+                        action.generateDescription(
+                            (new ContentGroup())
+                                .addUnit(
+                                    (new CombatUnit())
+                                        .setActor(action.actor)
+                                        .setTarget(target)
+                                        .setWeapon(...weapons)
+                                        .addMarker(CombatHit.MISS)
+                                )
+                        );
+                        return false;
+                    }
                 }
             }
         }