simplify resolutions further

This commit is contained in:
ntr 2019-03-25 15:03:49 +11:00
parent 171367ab06
commit cff22550f9
3 changed files with 9 additions and 30 deletions

View File

@ -373,7 +373,7 @@ impl Cryp {
self
}
pub fn reduce_effect_durations(&mut self, _log: &mut Log) -> &mut Cryp {
pub fn reduce_effect_durations(&mut self) -> &mut Cryp {
self.effects = self.effects.clone().into_iter().filter_map(|mut effect| {
effect.duration = effect.duration.saturating_sub(1);

View File

@ -86,7 +86,7 @@ pub struct Game {
pub teams: Vec<Team>,
pub phase: Phase,
pub stack: Vec<Cast>,
pub resolved: Vec<Cast>,
pub resolved: Vec<Resolution>,
pub log: Vec<String>,
pub instance: Option<Uuid>,
pub mode: GameMode,
@ -476,6 +476,11 @@ impl Game {
self.log_resolution(&cast);
// the results go into the resolutions
self.resolved.append(&mut cast.resolutions);
// the cast itself goes into this temp vec
// to handle cooldowns
resolving.push(cast);
// if target.is_ko() && !target.ko_logged {
@ -498,10 +503,8 @@ impl Game {
// println!("{:#?}", self.resolving);
// now Resolve has all been assigned
// handle cooldowns and statuses
self.progress_durations(&resolving);
self.resolved.append(&mut resolving);
if self.finished() {
return self.finish()
@ -533,7 +536,7 @@ impl Game {
}
// always reduce durations
cryp.reduce_effect_durations(&mut self.log);
cryp.reduce_effect_durations();
self.update_cryp(&mut cryp);
}
@ -1105,29 +1108,6 @@ mod tests {
assert!(game.team_by_id(x_team.id).cryps[0].is_stunned() == false);
}
#[test]
fn siphon_test() {
let mut game = create_test_game();
let x_team = game.teams[0].clone();
let y_team = game.teams[1].clone();
let x_cryp = x_team.cryps[0].clone();
let y_cryp = y_team.cryps[0].clone();
let _x_siphon_id = game.add_skill(x_team.id, x_cryp.id, Some(y_cryp.id), Skill::TestSiphon).unwrap();
let _y_touch_id = game.add_skill(y_team.id, y_cryp.id, Some(x_cryp.id), Skill::TestTouch).unwrap();
game = game.resolve_phase_start();
game.add_skill(x_team.id, x_cryp.id, None, Skill::TestBlock).unwrap();
game.add_skill(y_team.id, y_cryp.id, None, Skill::TestBlock).unwrap();
game = game.resolve_phase_start();
assert!(game.resolved.iter().any(|r| r.skill == Skill::SiphonTick));
}
#[test]
fn ko_pve_test() {
let mut game = create_2v2_test_game();

View File

@ -981,12 +981,11 @@ mod tests {
let mut y = Cryp::new()
.named(&"camel".to_string());
let mut log = vec![];
decay(&mut x, &mut y, vec![]);
assert!(y.effects.iter().any(|e| e.effect == Effect::Decay));
y.reduce_effect_durations(&mut log);
y.reduce_effect_durations();
let _decay = y.effects.iter().find(|e| e.effect == Effect::Decay);
// assert!(y.hp() == y.hp().saturating_sub(decay.unwrap().tick.unwrap().amount));
}