From 4c68d11a28ccc59561169add3d803c8ecd9bbb0c Mon Sep 17 00:00:00 2001 From: Mashy Date: Tue, 23 Jul 2019 18:04:33 +1000 Subject: [PATCH] aoe targetting fixed --- client/src/animations.utils.jsx | 19 +++++++++++++------ client/src/components/animations.jsx | 2 +- client/src/components/anims/break.jsx | 2 +- client/src/components/anims/ruin.jsx | 7 ++++++- client/src/components/construct.jsx | 4 ++-- client/src/components/game.construct.jsx | 4 ---- client/src/events.jsx | 2 +- 7 files changed, 24 insertions(+), 16 deletions(-) diff --git a/client/src/animations.utils.jsx b/client/src/animations.utils.jsx index 559de717..c563e597 100644 --- a/client/src/animations.utils.jsx +++ b/client/src/animations.utils.jsx @@ -12,7 +12,7 @@ function getObjects(resolution, stages, game, account) { if (!resolution) return none(); if (!resolution.target) return none(); - const [, event] = resolution.event; + const [type, event] = resolution.event; if (!event || !event.skill) return none(); const playerTeam = game.players.find(t => t.id === account.id); @@ -22,6 +22,14 @@ function getObjects(resolution, stages, game, account) { const sourceIsPlayer = playerTeamIds.includes(resolution.source.id); const targetIsPlayer = playerTeamIds.includes(resolution.target.id); + const targetting = () => { + if (type === 'AoeSkill') { + if (targetIsPlayer) return playerTeamIds; + return otherTeamIds; + } + return [resolution.target.id]; + }; + const sameTeam = (sourceIsPlayer && targetIsPlayer) || (!sourceIsPlayer && !targetIsPlayer); let y = 0; if (!sameTeam) y = targetIsPlayer ? 1 : -1; @@ -29,7 +37,7 @@ function getObjects(resolution, stages, game, account) { const i = sourceIsPlayer ? playerTeamIds.findIndex(c => c === resolution.source.id) : otherTeamIds.findIndex(c => c === resolution.source.id); - + const j = targetIsPlayer ? playerTeamIds.findIndex(c => c === resolution.target.id) : otherTeamIds.findIndex(c => c === resolution.target.id); @@ -56,11 +64,10 @@ function getObjects(resolution, stages, game, account) { const animTarget = { skill, - constructId: resolution.target.id, + constructId: targetting(), player: playerTeamIds.includes(resolution.target.id), direction, }; - return { animSource, animTarget, @@ -109,11 +116,11 @@ function getFocusTargets(resolution, game) { if (type === 'AoeSkill') { const targetTeam = game.players.find(t => t.constructs.find(c => c.id === target)); const targetTeamIds = targetTeam.constructs.map(c => c.id); - if (source !== target) return targetTeamIds.push(source); + if (source !== target) targetTeamIds.push(source); return targetTeamIds; } if (source !== target) return [source, target]; - return target; + return [target]; } function getText(resolution, sequence) { diff --git a/client/src/components/animations.jsx b/client/src/components/animations.jsx index 1a4e3ee6..d3fdc00f 100644 --- a/client/src/components/animations.jsx +++ b/client/src/components/animations.jsx @@ -63,7 +63,7 @@ class ConstructAnimation extends Component { constructId, } = animTarget; - if (construct.id !== constructId) return false; + if (!constructId.includes(construct.id)) return false; // find target animation const chooseAnim = (skill) => { diff --git a/client/src/components/anims/break.jsx b/client/src/components/anims/break.jsx index 598d5379..289eddfa 100644 --- a/client/src/components/anims/break.jsx +++ b/client/src/components/anims/break.jsx @@ -106,7 +106,7 @@ class Break extends Component { componentWillUnmount() { for (let i = this.animations.length - 1; i >= 0; i--) { this.animations[i].reset(); - } + } this.props.animCb(); } } diff --git a/client/src/components/anims/ruin.jsx b/client/src/components/anims/ruin.jsx index 2216b04f..7022f3a0 100644 --- a/client/src/components/anims/ruin.jsx +++ b/client/src/components/anims/ruin.jsx @@ -98,7 +98,12 @@ class Ruin extends Component { componentWillUnmount() { for (let i = this.animations.length - 1; i >= 0; i--) { this.animations[i].reset(); - } this.props.animCb(); + } + try { + this.props.animCb(); + } catch (e) { + console.log(e); + } } } diff --git a/client/src/components/construct.jsx b/client/src/components/construct.jsx index b6793d82..249a9e22 100644 --- a/client/src/components/construct.jsx +++ b/client/src/components/construct.jsx @@ -132,7 +132,7 @@ class ConstructAvatar extends Component { } // this is the target - if (animTarget && animTarget.constructId === construct.id) { + if (animTarget && animTarget.constructId.includes(construct.id)) { // console.warn(construct.name, 'should update') return true; } @@ -141,7 +141,7 @@ class ConstructAvatar extends Component { const prevSrc = this.props.animSource && this.props.animSource.constructId === construct.id; if (prevSrc && !animSource) return true; - const prevTarget = this.props.animTarget && this.props.animTarget.constructId === construct.id; + const prevTarget = this.props.animTarget && this.props.animTarget.constructId.includes(construct.id); if (prevTarget && !animTarget) return true; // console.warn(construct.name, 'not updating'); diff --git a/client/src/components/game.construct.jsx b/client/src/components/game.construct.jsx index 39c39cfc..14b298bf 100644 --- a/client/src/components/game.construct.jsx +++ b/client/src/components/game.construct.jsx @@ -8,12 +8,8 @@ const { ConstructAvatar, ConstructText } = require('./construct'); const { ConstructAnimation } = require('./animations'); const shapes = require('./shapes'); - const SkillBtn = require('./skill.btn'); - -const actions = require('../actions'); - const addState = connect( function receiveState(state) { const { diff --git a/client/src/events.jsx b/client/src/events.jsx index 7c02a7b0..122b4187 100644 --- a/client/src/events.jsx +++ b/client/src/events.jsx @@ -62,7 +62,7 @@ function registerEvents(store) { const anims = animations.getObjects(r, sequence, game, account); const text = animations.getText(r, sequence); - store.dispatch(actions.setAnimFocus(animations.getFocusTargets(r))); + store.dispatch(actions.setAnimFocus(animations.getFocusTargets(r, game))); if (sequence.includes('START_SKILL')) store.dispatch(actions.setAnimSource(anims.animSource)); if (sequence.includes('END_SKILL')) {