resolve flow

This commit is contained in:
ntr 2019-12-09 21:12:27 +10:00
parent a80c398c85
commit 006a670027
2 changed files with 76 additions and 64 deletions

View File

@ -3,6 +3,8 @@
last round of animations skipped cause no skill phase to add new vec last round of animations skipped cause no skill phase to add new vec
ko constructs are still casting ko constructs are still casting
check for ko in cast_modifier
tick skips for triage etc tick skips for triage etc
game ready not auto starting resolve phase game ready not auto starting resolve phase
healing action healing action

View File

@ -9,7 +9,7 @@ use chrono::Duration;
use failure::Error; use failure::Error;
use failure::err_msg; use failure::err_msg;
use construct::{Construct, ConstructEffect, Stat}; use construct::{Construct, ConstructEffect, Stat, EffectMeta};
use skill::{Skill, Cast}; use skill::{Skill, Cast};
use effect::{Effect}; use effect::{Effect};
use util::{IntPct}; use util::{IntPct};
@ -438,12 +438,6 @@ impl Game {
while let Some(cast) = self.stack.pop() { while let Some(cast) = self.stack.pop() {
// info!("{:} casts ", cast); // 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()); // 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) // if theres no resolution Resolutions, the skill didn't trigger (disable etc)
@ -451,6 +445,8 @@ impl Game {
// casters.push(cast); // casters.push(cast);
// } // }
self.resolve(cast);
// sort the stack again in case speeds have changed // sort the stack again in case speeds have changed
self.stack_sort_speed(); self.stack_sort_speed();
}; };
@ -467,7 +463,15 @@ impl Game {
self.skill_phase_start(r_animation_ms) self.skill_phase_start(r_animation_ms)
} }
fn pre_resolve(&self, cast: Cast) -> Vec<Cast> { 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<Cast> {
let target_player = self.players.iter() let target_player = self.players.iter()
.find(|t| t.constructs.iter().any(|c| c.id == cast.target)) .find(|t| t.constructs.iter().any(|c| c.id == cast.target))
.unwrap(); .unwrap();
@ -494,6 +498,8 @@ impl Game {
false => vec![cast], false => vec![cast],
}; };
// check for reflect
return targets; 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![]; let mut event_list = vec![];
for action in cast.actions() { for action in cast.actions() {
let mut events = match action { let events = match action {
Action::Cast => self.cast(cast), Action::Cast => self.cast(cast),
Action::Hit => self.hit(cast), Action::Hit => self.hit(cast),
@ -560,7 +566,11 @@ impl Game {
Action::RemoveAll { construct } => self.remove_all(construct), Action::RemoveAll { construct } => self.remove_all(construct),
Action::IncreaseCooldowns { construct, turns } => self.increase_cooldowns(construct, turns), 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![]; let mut resolutions = vec![];
@ -575,60 +585,60 @@ impl Game {
self self
} }
fn post_resolve(&mut self, resolutions: &Vec<Resolution>) -> &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 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<Event> { fn cast(&mut self, cast: Cast) -> Vec<Event> {