« get me outta code hell

csb-game - Pixelly spin-off of the Command Synergy Battle system used in Final Fantasy XIII
summary refs log tree commit diff
path: root/index.js
diff options
context:
space:
mode:
Diffstat (limited to 'index.js')
-rw-r--r--index.js9
1 files changed, 9 insertions, 0 deletions
diff --git a/index.js b/index.js
index 37859c8..39517f5 100644
--- a/index.js
+++ b/index.js
@@ -522,6 +522,15 @@ class TargetMenu extends BaseBattleMenu {
   buildOptions(targetType) {
     this.options = this.battle.playerCharacter.getValidTargets(targetType)
       .map(char => ({label: char.name, battleCharacter: char}))
+
+    // If the top action is a 'cure' action, pick the character with the least health by default.
+    // TODO: Some property like "healsAlive" on the action itself, so things like potions (which target one) are also affected by this
+    if (last(this.battle.playerCharacter.atbBar.queuedActions).chain === 'cure') {
+      const allies = this.battle.playerCharacter.team.characters
+      const aliveCharacter = allies.find(c => !c.dead)
+      const mostHurtCharacter = allies.reduce((a, b) => (b.hp < a.hp && !b.dead ? b : a), aliveCharacter)
+      this.currentOptionIndex = this.options.findIndex(opt => opt.battleCharacter === mostHurtCharacter)
+    }
   }
 }