From 4d51316c23687f658a4676c6ba2bb18b653caeff Mon Sep 17 00:00:00 2001 From: Florrie Date: Thu, 16 Aug 2018 23:08:33 -0300 Subject: Warmech AI recover move --- index.js | 43 ++++++++++++++++++++++++++----------------- 1 file changed, 26 insertions(+), 17 deletions(-) (limited to 'index.js') diff --git a/index.js b/index.js index f54e41f..b0e57b9 100644 --- a/index.js +++ b/index.js @@ -17,7 +17,7 @@ const actionDatabase = { fira: {id: 'fira', chain: 'fire', label: 'Fira', size: 2, target: 'enemy', color: '#F77', damage: 40, stun: 0.2}, firaga: {id: 'firaga', chain: 'fire', label: 'Firaga', size: 3, target: 'enemy', color: '#F77', damage: 60, stun: 0.3}, - cure: {id: 'cure', chain: 'cure', label: 'Cure', size: 1, target: 'ally', color: '#AFA'}, + cure: {id: 'cure', chain: 'cure', label: 'Cure', size: 1, target: 'ally', color: '#AFA', heal: 80}, blizz: {id: 'blizz', chain: 'blizz', label: 'Blizz', size: 1, target: 'enemy', color: '#AAF', damage: 15, stun: 0.2}, blizzara: {id: 'blizzara', chain: 'blizz', label: 'Blizzara', size: 2, target: 'enemy', color: '#AAF', damage: 30, stun: 0.35}, @@ -28,6 +28,7 @@ const actionDatabase = { aquaga: {id: 'aquaga', chain: 'aqua', label: 'Aquaga', size: 3, target: 'enemy', color: '#33F', damage: 90, stun: 0}, manasvinSwipe: {id: 'manasvinSwipe', label: 'Swipe', size: 3, target: 'enemy', color: '#CCC', damage: 125, stun: 1.25}, + manasvinRecover: {id: 'manasvinRecover', label: 'Recover', size: 6, target: 'ally', color: '#AFA', heal: 300} } class Sprite { @@ -190,21 +191,28 @@ class ATBBar { // Determine a target // TODO: AI logic for when to change target - if (!this.battleCharacter.isExecutingChain && (true || !this.battleCharacter.targetCharacter)) { - this.battleCharacter.determineNewTarget('enemy') + // TODO: Maybe need to bump the Math.random() chances. + if (!this.battleCharacter.isExecutingChain && !this.battleCharacter.willExecuteChain && (this.battleCharacter.aiID === 'manasvinWarmech' || !this.battleCharacter.targetCharacter)) { + if (this.battleCharacter.aiID === 'manasvinWarmech' && Math.random() < 1 - this.battleCharacter.hp / this.battleCharacter.maxHP) { + this.battleCharacter.determineNewTarget('ally') + } else { + this.battleCharacter.determineNewTarget('enemy') + } } // ATB gauge not full? Try to queue actions if (!this.battleCharacter.isExecutingChain && this.battleCharacter.targetCharacter && this.getRemainingSpace() >= 0) { // TODO: Actual AI logic here - enqueueMoves: while (this.getRemainingSpace()) { - const moves = this.battleCharacter.knownActions.slice() - while (moves.length) { - const index = randomIndex(moves) - const moveID = moves[index] - moves.splice(index, 1) - if (this.enqueue(actionDatabase[moveID])) { - continue enqueueMoves + enqueueActions: while (this.getRemainingSpace()) { + const actions = this.battleCharacter.knownActions + .map(actionID => actionDatabase[actionID]) + .filter(a => a.target === this.battleCharacter.targetType) + while (actions.length) { + const index = randomIndex(actions) + const action = actions[index] + actions.splice(index, 1) + if (this.enqueue(action)) { + continue enqueueActions } } break @@ -679,6 +687,7 @@ class BattleCharacter extends Sprite { determineNewTarget(targetType) { const targets = this.getValidTargets(targetType) + this.targetType = targetType if (targets.length) { // TODO: Some sort of "follow the leader" mechanic this.targetCharacter = pickRandom(targets) @@ -1081,7 +1090,7 @@ class BattleCamera extends Camera { super() this.battlefieldCenterX = 20 - this.battlefieldCenterY = 200 + this.battlefieldCenterY = 220 } getSpriteFollowCoords(sprite) { @@ -1113,8 +1122,8 @@ class MagicProjectile { if (this.action.target === 'enemy') { if (this.action.damage) this.target.takeDamage(this.action.damage) if (this.action.stun) this.target.addStunTime(this.action.stun || 0) - } else if (this.action.id === 'cure') { - this.target.recoverHP(40) + } else if (this.action.target === 'ally') { + if (this.action.heal) this.target.recoverHP(this.action.heal) } this.discarded = true } @@ -1177,11 +1186,11 @@ class SlideacrossMessage { const battle = new Battle({ teamData: [ {characterData: [ - {x: -70, y: 200, name: 'Ren', hp: 400, maxHP: 400, knownActions: ['fire', 'fira', 'firaga', 'blizz', 'blizzara', 'cure']}, - {x: -85, y: 210, name: 'Fie', hp: 375, maxHP: 375, knownActions: ['fire', 'blizz', 'blizzara', 'blizzaga', 'aqua', 'aquara']} + {x: -75, y: 190, name: 'Ren', hp: 400, maxHP: 400, knownActions: ['fire', 'fira', 'firaga', 'blizz', 'blizzara', 'cure']}, + {x: -95, y: 225, name: 'Fie', hp: 375, maxHP: 375, knownActions: ['fire', 'blizz', 'blizzara', 'blizzaga', 'aqua', 'aquara']} ]}, {characterData: [ - {x: 70, y: 200, name: 'Manasvin Warmech', hp: 700, maxHP: 700, knownActions: ['aqua', 'aquaga', 'manasvinSwipe']} + {x: 100, y: 200, aiID: 'manasvinWarmech', name: 'Manasvin Warmech', hp: 1600, maxHP: 1600, knownActions: ['aqua', 'aquaga', 'manasvinSwipe', 'manasvinRecover']} ]} ] }) -- cgit 1.3.0-6-gf8a5