From 6d9e13598cae4549eaca20c75590da33211be89b Mon Sep 17 00:00:00 2001 From: Mashy Date: Fri, 31 May 2019 13:03:50 +1000 Subject: [PATCH 1/2] 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, From 6295d8888e07e9ad86a23746db13cf4d0ed3c9f5 Mon Sep 17 00:00:00 2001 From: Mashy Date: Fri, 31 May 2019 13:27:23 +1000 Subject: [PATCH 2/2] update effects during combat anim loop --- client/src/utils.jsx | 8 ++++++-- server/src/construct.rs | 14 +++++++------- server/src/game.rs | 8 ++++---- server/src/skill.rs | 15 +++++++++------ 4 files changed, 26 insertions(+), 19 deletions(-) diff --git a/client/src/utils.jsx b/client/src/utils.jsx index 6eaa2a6a..42087198 100644 --- a/client/src/utils.jsx +++ b/client/src/utils.jsx @@ -228,9 +228,10 @@ function eventClasses(resolution, construct) { } if (type === 'Effect') { - const { skill, effect, duration } = event; + const { skill, effect, duration, construct_effects: constructEffects } = event; if (source && startSkill) return 'active-skill'; if (target && endSkill) return 'active-skill'; + if (target && postSkill) construct.effects = constructEffects; } if (type === 'Skill') { @@ -241,7 +242,10 @@ function eventClasses(resolution, construct) { } if (type === 'Removal') { - const { effect } = event; + const { effect, construct_effects: constructEffects } = event; + if (source && startSkill) return 'active-skill'; + if (target && endSkill) return 'active-skill'; + if (target && postSkill) construct.effects = constructEffects; } if (type === 'Recharge') { diff --git a/server/src/construct.rs b/server/src/construct.rs index 99425daa..a8fd838e 100644 --- a/server/src/construct.rs +++ b/server/src/construct.rs @@ -757,13 +757,6 @@ impl Construct { }; } - // todo modified durations cause of buffs - let result = Event::Effect { - effect: effect.effect, - duration: effect.duration, - skill, - }; - if let Some(p) = self.effects.iter().position(|ce| ce.effect == effect.effect) { // duplicate effect // replace existing @@ -775,6 +768,13 @@ impl Construct { self.effects.push(effect); } + // todo modified durations cause of buffs + let result = Event::Effect { + effect: effect.effect, + duration: effect.duration, + construct_effects: self.effects.clone(), + skill, + }; return result; } diff --git a/server/src/game.rs b/server/src/game.rs index 12c5ba26..dc68daff 100644 --- a/server/src/game.rs +++ b/server/src/game.rs @@ -528,7 +528,7 @@ impl Game { self.log.push(format!("[{:}] {:} {:?} {:} REFLECTED", speed, source.name, skill, target.name)), - Event::Effect { skill, effect, duration } => + Event::Effect { skill, effect, duration, construct_effects: _ } => self.log.push(format!("[{:}] {:} {:?} {:} {:?} {:}T", speed, source.name, skill, target.name, effect, duration)), @@ -540,7 +540,7 @@ impl Game { self.log.push(format!("[{:}] {:} {:?} {:}", speed, source.name, skill, target.name)), - Event::Removal { effect } => + Event::Removal { effect, construct_effects: _ } => self.log.push(format!("[{:}] {:?} removed {:} {:?}", speed, source.name, target.name, effect)), @@ -1265,7 +1265,7 @@ mod tests { let Resolution { source: _, target: _, event } = game.resolved.pop().unwrap(); match event { - Event::Effect { effect, skill: _, duration: _ } => assert_eq!(effect, Effect::Scatter), + Event::Effect { effect, skill: _, duration: _, construct_effects: _ } => assert_eq!(effect, Effect::Scatter), _ => panic!("not siphon"), }; @@ -1357,7 +1357,7 @@ mod tests { let Resolution { source, target: _, event } = r; match source.id == x_construct.id { true => match event { - Event::Effect { effect, duration, skill: _ } => { + Event::Effect { effect, duration, skill: _, construct_effects: _ } => { assert!(*effect == Effect::Stun); assert!(*duration == 1); true diff --git a/server/src/skill.rs b/server/src/skill.rs index 5019030c..ae633b37 100644 --- a/server/src/skill.rs +++ b/server/src/skill.rs @@ -437,10 +437,10 @@ pub enum Event { Recharge { skill: Skill, red: u64, blue: u64 }, Inversion { skill: Skill }, Reflection { skill: Skill }, - Effect { skill: Skill, effect: Effect, duration: u8 }, AoeSkill { skill: Skill }, Skill { skill: Skill }, - Removal { effect: Effect }, + Effect { skill: Skill, effect: Effect, duration: u8, construct_effects: Vec }, + Removal { effect: Effect, construct_effects: Vec }, TargetKo { skill: Skill }, // skill not necessary but makes it neater as all events are arrays in js Ko { skill: Skill }, @@ -1539,7 +1539,8 @@ fn strangle_tick(source: &mut Construct, target: &mut Construct, mut results: Re .position(|e| e.effect == Effect::Strangling) .expect("no strangling on construct"); source.effects.remove(i); - results.push(Resolution::new(source, source).event(Event::Removal { effect: Effect::Strangling })); + results.push(Resolution::new(source, source) + .event(Event::Removal { effect: Effect::Strangling, construct_effects: target.effects.clone() })); } return results; @@ -1877,7 +1878,8 @@ fn purge(source: &mut Construct, target: &mut Construct, mut results: Resolution .iter() .position(|ce| ce.effect.category() == EffectCategory::Buff) { let ce = target.effects.remove(i); - results.push(Resolution::new(source, target).event(Event::Removal { effect: ce.effect })); + results.push(Resolution::new(source, target) + .event(Event::Removal { effect: ce.effect, construct_effects: target.effects.clone() })); } return results; @@ -1890,7 +1892,8 @@ fn purify(source: &mut Construct, target: &mut Construct, mut results: Resolutio .iter() .position(|ce| ce.effect.category() == EffectCategory::Debuff) { let ce = target.effects.remove(i); - results.push(Resolution::new(source, target).event(Event::Removal { effect: ce.effect })); + results.push(Resolution::new(source, target) + .event(Event::Removal { effect: ce.effect, construct_effects: target.effects.clone() })); target.deal_green_damage(skill, amount) .into_iter() .for_each(|e| results.push(Resolution::new(source, target).event(e))); @@ -2092,7 +2095,7 @@ mod tests { let Resolution { source: _, target: _, event } = results.remove(0); match event { - Event::Effect { effect, skill: _, duration: _ } => assert_eq!(effect, Effect::Siphon), + Event::Effect { effect, skill: _, duration: _, construct_effects: _ } => assert_eq!(effect, Effect::Siphon), _ => panic!("not siphon"), };