diff --git a/client/src/actions.jsx b/client/src/actions.jsx index 4f93f33d..910d3be5 100644 --- a/client/src/actions.jsx +++ b/client/src/actions.jsx @@ -2,6 +2,7 @@ export const setAccount = value => ({ type: 'SET_ACCOUNT', value }); export const setActiveConstruct = value => ({ type: 'SET_ACTIVE_CONSTRUCT', value }); export const setAnimating = value => ({ type: 'SET_ANIMATING', value }); +export const setAnimFocus = value => ({ type: 'SET_ANIM_FOCUS', value }); export const setAnimSource = value => ({ type: 'SET_ANIM_SOURCE', value }); export const setAnimTarget = value => ({ type: 'SET_ANIM_TARGET', value }); export const setAnimText = value => ({ type: 'SET_ANIM_TEXT', value }); diff --git a/client/src/animations.utils.jsx b/client/src/animations.utils.jsx index 70d4cc68..559de717 100644 --- a/client/src/animations.utils.jsx +++ b/client/src/animations.utils.jsx @@ -86,94 +86,116 @@ function getSequence(resolution) { } } -const SOURCE_DURATION_MS = 1000; -const TARGET_DELAY_MS = 500; -const TARGET_DURATION_MS = 1500; -const POST_SKILL_DELAY_MS = 2000; -const POST_SKILL_DURATION_MS = 1000; -const SOURCE_AND_TARGET_TOTAL_DURATION = TARGET_DELAY_MS + TARGET_DURATION_MS + POST_SKILL_DURATION_MS; - function getTime(stages) { - if (stages.includes('START_SKILL') && stages.includes('END_SKILL')) { - return TIMES.SOURCE_AND_TARGET_TOTAL_DURATION; - } - let time = 0; - - if (stages.includes('START_SKILL')) time += TIMES.SOURCE_DURATION_MS; - if (stages.includes('END_SKILL')) time += TIMES.TARGET_DURATION_MS; + if (stages.includes('START_SKILL') && stages.includes('END_SKILL')) { + time += TIMES.SOURCE_AND_TARGET_TOTAL_DURATION; + } else { + if (stages.includes('START_SKILL')) time += TIMES.SOURCE_DURATION_MS; + if (stages.includes('END_SKILL')) time += TIMES.TARGET_DURATION_MS; + } if (stages.includes('POST_SKILL')) time += TIMES.POST_SKILL_DURATION_MS; return time; } -function getText(resolution, sequence) { - if (!resolution) return { text: null, constructId: null }; - if (!sequence.includes('POST_SKILL')) return { text: null, constructId: null }; +function getFocusTargets(resolution, game) { + if (!resolution) return []; + if (!resolution.event) return []; + const [type] = resolution.event; + const source = resolution.source.id; + const target = resolution.target.id; - function generateText() { + 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); + return targetTeamIds; + } + if (source !== target) return [source, target]; + return target; +} + +function getText(resolution, sequence) { + const nullText = { text: null, constructId: null, life: null }; + if (!resolution) return nullText; + if (!sequence.includes('POST_SKILL')) return nullText; + + function generatePostSkill() { const [type, event] = resolution.event; if (type === 'Ko') { - return 'KO!'; + return { text: 'KO!', css: 'ko' }; } if (type === 'Disable') { const { disable } = event; - return `${disable}`; + return { text: `${disable}`, css: '' }; } if (type === 'Immunity') { - return 'IMMUNE'; + return { text: 'IMMUNE', css: '' }; } if (type === 'Damage') { const { mitigation, colour } = event; let { amount } = event; - if (colour === 'Green') amount *= -1; + let css = ''; + if (colour === 'Green') { + css = 'green-damage'; + amount *= -1; + } + if (colour === 'Red') css = 'red-damage'; + if (colour === 'Blue') css = 'blue-damage'; + const mitigationText = mitigation ? `(${mitigation})` : ''; - return `${amount} ${mitigationText}`; + return { text: `${amount} ${mitigationText}`, css }; } if (type === 'Healing') { const { amount, overhealing } = event; - return `${amount} (${overhealing} OH)`; + return { text: `${amount} (${overhealing} OH)`, css: 'green-damage' }; } if (type === 'Inversion') { - return 'INVERT'; + return { text: 'INVERT', css: '' }; } if (type === 'Reflection') { - return 'REFLECT'; + return { text: 'REFLECT', css: '' }; } if (type === 'Effect') { - const { effect, duration } = event; - return `+ ${effect} ${duration}T`; + const { effect, duration, construct_effects: effects } = event; + return { text: `+ ${effect} ${duration}T`, css: '', effects }; } if (type === 'Recharge') { const { red, blue } = event; - return [`+${red}R ${blue}B`, '']; + return { text: [`+${red}R ${blue}B`, ''], css: '' }; } if (type === 'Removal') { - const { effect } = event; - return `-${effect}`; + const { effect, construct_effects: effects } = event; + return { text: `-${effect}`, css: '', effects }; } - return false; } + const { green, red, blue } = resolution.target; + const { text, css, effects } = generatePostSkill(); return { - text: generateText(), + css, + text, + effects, + life: { green, red, blue }, constructId: resolution.target.id, }; } module.exports = { + getFocusTargets, getObjects, getTime, getSequence, diff --git a/client/src/components/game.construct.jsx b/client/src/components/game.construct.jsx index 41c30b8b..39c39cfc 100644 --- a/client/src/components/game.construct.jsx +++ b/client/src/components/game.construct.jsx @@ -3,7 +3,7 @@ const { Component } = require('preact'); const preact = require('preact'); const range = require('lodash/range'); -const { STATS, eventClasses } = require('../utils'); +const { STATS } = require('../utils'); const { ConstructAvatar, ConstructText } = require('./construct'); const { ConstructAnimation } = require('./animations'); const shapes = require('./shapes'); @@ -21,8 +21,9 @@ const addState = connect( game, account, activeSkill, + animFocus, resolution, - + animating, animText, } = state; @@ -41,13 +42,31 @@ const addState = connect( game, account, resolution, + animating, + animFocus, animText, activeSkill, selectSkillTarget, }; - }, + } ); +const eventClasses = (animating, animFocus, construct, postSkill) => { + if (!animating) return ''; + if (!postSkill) { + if (animFocus.includes(construct.id)) return ''; + return 'unfocus'; + } + if (postSkill.constructId !== construct.id) { + if (animFocus.includes(construct.id)) return ''; + return 'unfocus'; + } + if (postSkill.effects) construct.effects = postSkill.effects; + construct.green_life.value = postSkill.life.green; + construct.red_life.value = postSkill.life.red; + construct.blue_life.value = postSkill.life.blue; + return postSkill.css; +}; class GameConstruct extends Component { constructor() { @@ -58,21 +77,17 @@ class GameConstruct extends Component { render() { const { i, - game, - account, + animating, construct, player, activeSkill, selectSkillTarget, - - // todo remove dep - resolution, - + animFocus, animText, } = this.props; const ko = construct.green_life.value === 0 ? 'ko' : ''; - const classes = eventClasses(game, account, resolution, construct, animText); + const classes = eventClasses(animating, animFocus, construct, animText); const stats = ['RedLife', 'GreenLife', 'BlueLife'].map((s, j) => (