« get me outta code hell

Target most hurt player with cure - 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:
authorFlorrie <towerofnix@gmail.com>2018-08-16 16:32:29 -0300
committerFlorrie <towerofnix@gmail.com>2018-08-16 16:32:29 -0300
commit409fb44793d3b4125155e4d42aae1b629adab91b (patch)
tree4fb633dc0236cd09db8db3b0abf49a076dca3ed4 /index.js
parentd01cafba4ae56121ddd18ce6b46f7857ad2db2b8 (diff)
Target most hurt player with cure
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)
+    }
   }
 }