From 6d9e13598cae4549eaca20c75590da33211be89b Mon Sep 17 00:00:00 2001 From: Mashy Date: Fri, 31 May 2019 13:03:50 +1000 Subject: [PATCH] removed life conditional checks, assign reso life to state construct --- client/src/components/game.construct.jsx | 7 +- client/src/utils.jsx | 92 +++++------------------- 2 files changed, 21 insertions(+), 78 deletions(-) diff --git a/client/src/components/game.construct.jsx b/client/src/components/game.construct.jsx index 3ce45990..64df7d28 100644 --- a/client/src/components/game.construct.jsx +++ b/client/src/components/game.construct.jsx @@ -3,7 +3,7 @@ const preact = require('preact'); const range = require('lodash/range'); const actions = require('../actions'); -const { STATS, eventClasses, getCombatText, ConstructAvatar, constructHealth } = require('../utils'); +const { STATS, eventClasses, getCombatText, ConstructAvatar } = require('../utils'); const { animationDivs } = require('../animations'); const shapes = require('./shapes'); @@ -56,12 +56,11 @@ function GameConstruct(props) { const ko = construct.green_life.value === 0 ? 'ko' : ''; const classes = eventClasses(resolution, construct); - const life = constructHealth(resolution, construct); const stats = ['RedLife', 'GreenLife', 'BlueLife'].map((s, j) => (
{shapes[s]()} -
{life[s]} / {construct[STATS[s].stat].max}
-
{life[s]}
+
{construct[STATS[s].stat].value} / {construct[STATS[s].stat].max}
+
{construct[STATS[s].stat].value}
)); diff --git a/client/src/utils.jsx b/client/src/utils.jsx index 42de2871..6eaa2a6a 100644 --- a/client/src/utils.jsx +++ b/client/src/utils.jsx @@ -157,74 +157,6 @@ const STATS = { }, }; - -function constructHealth(resolution, construct) { - if (!resolution) { - return { - RedLife: construct.red_life.value, - GreenLife: construct.green_life.value, - BlueLife: construct.blue_life.value, - }; - } - const [type, event] = resolution.event; - - - if (construct.id !== resolution.target.id) { - if (construct.id === resolution.source.id) { - return { - RedLife: resolution.source.red, - GreenLife: resolution.source.green, - BlueLife: resolution.source.blue, - }; - } - return { - RedLife: construct.red_life.value, - GreenLife: construct.green_life.value, - BlueLife: construct.blue_life.value, - }; - } - - let RedLife = resolution.target.red; - let BlueLife = resolution.target.blue; - let GreenLife = resolution.target.green; - - if (resolution.stage === 'POST_SKILL') { - return { RedLife, GreenLife, BlueLife }; - } - - if (type === 'Damage') { - const { amount, mitigation, colour } = event; - - GreenLife = construct.green_life.max < GreenLife + amount - ? construct.green_life.max - : GreenLife + amount; - - if (colour === 'Red') { - RedLife = construct.red_life.max < RedLife + mitigation - ? construct.red_life.max - : RedLife + mitigation; - } - if (colour === 'Blue') { - BlueLife = construct.blue_life.max < BlueLife + mitigation - ? construct.blue_life.max - : BlueLife + mitigation; - } - } - - if (type === 'Healing') { - const { amount } = event; - GreenLife = GreenLife - amount < 0 ? 0 : GreenLife - amount; - } - - if (type === 'Recharge') { - const { red, blue } = event; - RedLife = RedLife - red < 0 ? 0 : RedLife - red; - BlueLife = BlueLife - red < 0 ? 0 : BlueLife - blue; - } - - return { RedLife, GreenLife, BlueLife }; -} - function eventClasses(resolution, construct) { if (!resolution) return ''; const startSkill = resolution.stage === 'START_SKILL'; @@ -264,15 +196,16 @@ function eventClasses(resolution, construct) { // Deal damage to construct and return effect if (target && postSkill) { + construct.green_life.value = resolution.target.green; if (colour === 'Red') { + construct.red_life.value = resolution.target.red; return 'red-damage'; } if (colour === 'Blue') { + construct.blue_life.value = resolution.target.blue; return 'blue-damage'; } - if (colour === 'Green') return 'green-damage'; } - } if (type === 'Healing') { @@ -280,7 +213,9 @@ function eventClasses(resolution, construct) { if (source && startSkill) return 'active-skill'; if (target && endSkill) return 'active-skill'; if (target && postSkill) { + construct.green_life.value = resolution.target.green; return 'green-damage'; + } } @@ -314,9 +249,19 @@ function eventClasses(resolution, construct) { if (source && startSkill) return 'active-skill'; if (target && endSkill) return 'active-skill'; if (target && postSkill) { - if (red > 0 && blue > 0) return 'purple-damage'; - if (red > 0) return 'red-damage'; - if (blue > 0) return 'blue-damage'; + if (red > 0 && blue > 0) { + construct.red_life.value = resolution.target.red; + construct.blue_life.value = resolution.target.blue; + return 'purple-damage'; + } + if (red > 0) { + construct.red_life.value = resolution.target.red; + return 'red-damage'; + } + if (blue > 0) { + construct.blue_life.value = resolution.target.blue; + return 'blue-damage'; + } } } @@ -488,7 +433,6 @@ module.exports = { eventClasses, getCombatSequence, getCombatText, - constructHealth, NULL_UUID, STATS, COLOURS,