From 006a670027a32339379401a74896324b7f3906ce Mon Sep 17 00:00:00 2001 From: ntr Date: Mon, 9 Dec 2019 21:12:27 +1000 Subject: [PATCH] resolve flow --- core/fixme.md | 2 + core/src/game.rs | 138 +++++++++++++++++++++++++---------------------- 2 files changed, 76 insertions(+), 64 deletions(-) diff --git a/core/fixme.md b/core/fixme.md index 806bb382..ff73860f 100644 --- a/core/fixme.md +++ b/core/fixme.md @@ -3,6 +3,8 @@ last round of animations skipped cause no skill phase to add new vec ko constructs are still casting +check for ko in cast_modifier + tick skips for triage etc game ready not auto starting resolve phase healing action diff --git a/core/src/game.rs b/core/src/game.rs index 0e6a39cc..89cbf3f2 100644 --- a/core/src/game.rs +++ b/core/src/game.rs @@ -9,7 +9,7 @@ use chrono::Duration; use failure::Error; use failure::err_msg; -use construct::{Construct, ConstructEffect, Stat}; +use construct::{Construct, ConstructEffect, Stat, EffectMeta}; use skill::{Skill, Cast}; use effect::{Effect}; use util::{IntPct}; @@ -438,12 +438,6 @@ impl Game { while let Some(cast) = self.stack.pop() { // info!("{:} casts ", cast); - let casts = self.pre_resolve(cast); - - for cast in casts { - self.resolve(cast); - } - // r_animation_ms = Resolutions.iter().fold(r_animation_ms, |acc, r| acc + r.clone().get_delay()); // if theres no resolution Resolutions, the skill didn't trigger (disable etc) @@ -451,6 +445,8 @@ impl Game { // casters.push(cast); // } + self.resolve(cast); + // sort the stack again in case speeds have changed self.stack_sort_speed(); }; @@ -467,7 +463,15 @@ impl Game { self.skill_phase_start(r_animation_ms) } - fn pre_resolve(&self, cast: Cast) -> Vec { + fn resolve(&mut self, cast: Cast) -> &mut Game { + let casts = self.finalise_casts(cast); + for cast in casts { + self.execute(cast); + } + self + } + + fn finalise_casts(&self, cast: Cast) -> Vec { let target_player = self.players.iter() .find(|t| t.constructs.iter().any(|c| c.id == cast.target)) .unwrap(); @@ -494,6 +498,8 @@ impl Game { false => vec![cast], }; + // check for reflect + return targets; } @@ -537,11 +543,11 @@ impl Game { }) } - fn resolve(&mut self, cast: Cast) -> &mut Game { + fn execute(&mut self, cast: Cast) -> &mut Game { let mut event_list = vec![]; for action in cast.actions() { - let mut events = match action { + let events = match action { Action::Cast => self.cast(cast), Action::Hit => self.hit(cast), @@ -560,7 +566,11 @@ impl Game { Action::RemoveAll { construct } => self.remove_all(construct), Action::IncreaseCooldowns { construct, turns } => self.increase_cooldowns(construct, turns), }; - event_list.append(&mut events); + + for event in events { + event_list.push(event); // ensure it goes into the list before doing extra processing + self.event_reactions(&cast, &event_list[event_list.len() - 1]); + } } let mut resolutions = vec![]; @@ -575,60 +585,60 @@ impl Game { self } - fn post_resolve(&mut self, resolutions: &Vec) -> &mut Game { + fn event_reactions(&mut self, cast: &Cast, event: &Event) -> &mut Game { + match event { + Event::Damage { construct, colour, amount, mitigation, display: _ } => { + if self.construct_by_id(*construct).unwrap().affected(Effect::Electric) && !cast.skill.is_tick() { + let ConstructEffect { effect: _, duration: _, meta, tick: _ } = + self.construct_by_id(*construct).unwrap().effects.iter().find(|e| e.effect == Effect::Electric).unwrap().clone(); + + let skill = match meta { + Some(EffectMeta::Skill(s)) => s, + _ => panic!("no electrify skill"), + }; + + let source = construct; + let player = self.construct_by_id(*construct).unwrap().account; + let target = cast.source; + + self.resolve(Cast::new(*source, player, target, skill)); + } + + // if self.construct_by_id(*construct).unwrap().affected(Effect::Absorb) { + // let ConstructEffect { effect: _, duration: _, meta, tick: _ } = + // self.construct_by_id(*construct).unwrap().effects.iter().find(|e| e.effect == Effect::Absorb).unwrap().clone(); + + // let skill = match meta { + // Some(EffectMeta::Skill(s)) => s, + // _ => panic!("no absorption skill"), + // }; + + // let source = construct; + // let player = self.construct_by_id(*construct).unwrap().account; + // let target = cast.source; + + // self.resolve(Cast::new(*source, player, target, skill)); + // } + + if self.construct_by_id(*construct).unwrap().affected(Effect::Electric) && *colour == Colour::Red { + let ConstructEffect { effect: _, duration: _, meta, tick: _ } = + self.construct_by_id(*construct).unwrap().effects.iter().find(|e| e.effect == Effect::Counter).unwrap().clone(); + + let skill = match meta { + Some(EffectMeta::Skill(s)) => s, + _ => panic!("no counter skill"), + }; + + let source = construct; + let player = self.construct_by_id(*construct).unwrap().account; + let target = cast.source; + + self.resolve(Cast::new(*source, player, target, skill)); + } + }, + _ => (), + }; self - // for Event { source: event_source, target: event_target, event, stages: _ } in resolutions.clone() { - // let mut source = game.construct_by_id(event_source.id).unwrap().clone(); - // let mut target = game.construct_by_id(event_target.id).unwrap().clone(); - - // match event { - // Event::Damage { amount, skill, mitigation, colour: c } => { - // if target.affected(Effect::Electric) && !skill.is_tick() { - // let ConstructEffect { effect: _, duration: _, meta, tick: _ } = target.effects.iter() - // .find(|e| e.effect == Effect::Electric).unwrap().clone(); - // match meta { - // Some(EffectMeta::Skill(s)) => { - // // Gurad against reflect overflow - // if !(source.affected(Effect::Reflect) && target.affected(Effect::Reflect)) { - // // Check reflect don't bother if electrocute is procing on death - // if source.affected(Effect::Reflect) && !target.is_ko() { - // game.event(Event::new(&target, &source) - // .event(Event::Reflection { skill: s }).stages(EventStages::EndPost)); - // electrocute(&mut source, &mut target, resolutions, s); - // } else { - // electrocute(&mut target, &mut source, resolutions, s); - // } - // } - // }, - // _ => panic!("no electrify skill"), - // }; - // } - - // if target.affected(Effect::Absorb) && !target.is_ko() { - // let ConstructEffect { effect: _, duration: _, meta, tick: _ } = target.effects.iter() - // .find(|e| e.effect == Effect::Absorb).unwrap().clone(); - // match meta { - // Some(EffectMeta::Skill(s)) => { - // absorption(&mut source, &mut target, resolutions, skill, amount + mitigation, s); - // }, - // _ => panic!("no absorb skill"), - // }; - // } - // if c == Colour::Red { - // if target.affected(Effect::Counter) && !target.is_ko() { - // let ConstructEffect { effect: _, duration: _, meta, tick: _ } = target.effects.iter() - // .find(|e| e.effect == Effect::Counter).unwrap().clone(); - // match meta { - // Some(EffectMeta::Skill(s)) => { - // counter_attack(&mut target, &mut source, resolutions, s); - // }, - // _ => panic!("no counter skill"), - // }; - // } - // } - // _ => (), - // }; - // } } fn cast(&mut self, cast: Cast) -> Vec {