Merge branch 'core' of ssh://git.mnml.gg:40022/~/mnml into core
This commit is contained in:
commit
02311680ae
206
core/src/game.rs
206
core/src/game.rs
@ -715,23 +715,25 @@ impl Game {
|
||||
|
||||
fn progress_durations(&mut self) -> &mut Game {
|
||||
let last = self.resolutions.len() - 1;
|
||||
let used_cooldown = self.resolutions[last].iter()
|
||||
.filter_map(|r| match r.event {
|
||||
Event::Cast { construct, player: _, direction: _ } => match r.skill.base_cd().is_some() {
|
||||
true => Some(construct),
|
||||
false => None,
|
||||
}
|
||||
_ => None,
|
||||
})
|
||||
.collect::<Vec<Uuid>>();
|
||||
|
||||
for player in self.players.iter_mut() {
|
||||
for construct in player.constructs.iter_mut() {
|
||||
if construct.is_ko() {
|
||||
continue;
|
||||
}
|
||||
|
||||
if !used_cooldown.contains(&construct.id) {
|
||||
let cooldown = self.resolutions[last].iter()
|
||||
.find_map(|r| match r.event {
|
||||
Event::Cast { construct: caster, player: _, direction: _ } =>
|
||||
match caster == construct.id && r.skill.base_cd().is_some() {
|
||||
true => Some(r.skill),
|
||||
false => None,
|
||||
},
|
||||
_ => None,
|
||||
});
|
||||
|
||||
if let Some(skill) = cooldown {
|
||||
construct.skill_set_cd(skill);
|
||||
} else {
|
||||
construct.reduce_cooldowns();
|
||||
};
|
||||
|
||||
@ -1107,137 +1109,137 @@ mod tests {
|
||||
return game.resolve_phase_start();
|
||||
}
|
||||
|
||||
// #[test]
|
||||
// fn phase_test() {
|
||||
// let mut game = create_test_game();
|
||||
#[test]
|
||||
fn phase_test() {
|
||||
let mut game = create_test_game();
|
||||
|
||||
// let x_player = game.players[0].clone();
|
||||
// let y_player = game.players[1].clone();
|
||||
let x_player = game.players[0].clone();
|
||||
let y_player = game.players[1].clone();
|
||||
|
||||
// let x_construct = x_player.constructs[0].clone();
|
||||
// let y_construct = y_player.constructs[0].clone();
|
||||
let x_construct = x_player.constructs[0].clone();
|
||||
let y_construct = y_player.constructs[0].clone();
|
||||
|
||||
// game.add_skill(x_player.id, x_construct.id, y_construct.id, Skill::Attack).unwrap();
|
||||
// game.add_skill(y_player.id, y_construct.id, x_construct.id, Skill::Attack).unwrap();
|
||||
game.add_skill(x_player.id, x_construct.id, y_construct.id, Skill::Attack).unwrap();
|
||||
game.add_skill(y_player.id, y_construct.id, x_construct.id, Skill::Attack).unwrap();
|
||||
|
||||
// game.player_ready(x_player.id).unwrap();
|
||||
// game.player_ready(y_player.id).unwrap();
|
||||
game.player_ready(x_player.id).unwrap();
|
||||
game.player_ready(y_player.id).unwrap();
|
||||
|
||||
// assert!(game.skill_phase_finished());
|
||||
assert!(game.skill_phase_finished());
|
||||
|
||||
// game = game.resolve_phase_start();
|
||||
game = game.resolve_phase_start();
|
||||
|
||||
// assert!([Phase::Skill, Phase::Finished].contains(&game.phase));
|
||||
assert!([Phase::Skill, Phase::Finished].contains(&game.phase));
|
||||
|
||||
// return;
|
||||
// }
|
||||
return;
|
||||
}
|
||||
|
||||
// #[test]
|
||||
// fn stun_test() {
|
||||
// let mut game = create_test_game();
|
||||
#[test]
|
||||
fn stun_test() {
|
||||
let mut game = create_test_game();
|
||||
|
||||
// let x_player = game.players[0].clone();
|
||||
// let y_player = game.players[1].clone();
|
||||
let x_player = game.players[0].clone();
|
||||
let y_player = game.players[1].clone();
|
||||
|
||||
// let x_construct = x_player.constructs[0].clone();
|
||||
// let y_construct = y_player.constructs[0].clone();
|
||||
let x_construct = x_player.constructs[0].clone();
|
||||
let y_construct = y_player.constructs[0].clone();
|
||||
|
||||
// while game.construct_by_id(x_construct.id).unwrap().skill_on_cd(Skill::Stun).is_some() {
|
||||
// game.construct_by_id(x_construct.id).unwrap().reduce_cooldowns();
|
||||
// }
|
||||
while game.construct_by_id(x_construct.id).unwrap().skill_on_cd(Skill::Stun).is_some() {
|
||||
game.construct_by_id(x_construct.id).unwrap().reduce_cooldowns();
|
||||
}
|
||||
|
||||
// game.add_skill(x_player.id, x_construct.id, y_construct.id, Skill::Stun).unwrap();
|
||||
// game.add_skill(y_player.id, y_construct.id, x_construct.id, Skill::Attack).unwrap();
|
||||
game.add_skill(x_player.id, x_construct.id, y_construct.id, Skill::Stun).unwrap();
|
||||
game.add_skill(y_player.id, y_construct.id, x_construct.id, Skill::Attack).unwrap();
|
||||
|
||||
// game.player_ready(x_player.id).unwrap();
|
||||
// game.player_ready(y_player.id).unwrap();
|
||||
game.player_ready(x_player.id).unwrap();
|
||||
game.player_ready(y_player.id).unwrap();
|
||||
|
||||
// assert!(game.skill_phase_finished());
|
||||
// game = game.resolve_phase_start();
|
||||
assert!(game.skill_phase_finished());
|
||||
game = game.resolve_phase_start();
|
||||
|
||||
// // should auto progress back to skill phase
|
||||
// assert!(game.phase == Phase::Skill);
|
||||
// should auto progress back to skill phase
|
||||
assert!(game.phase == Phase::Skill);
|
||||
|
||||
// // assert!(game.player_by_id(y_player.id).constructs[0].is_stunned());
|
||||
// // assert!(game.player_by_id(y_player.id).skills_required() == 0);
|
||||
// }
|
||||
assert!(game.player_by_id(y_player.id).unwrap().constructs[0].affected(Effect::Stun));
|
||||
assert!(game.player_by_id(y_player.id).unwrap().skills_required() == 0);
|
||||
}
|
||||
|
||||
// #[test]
|
||||
// fn ko_resolution_test() {
|
||||
// let mut game = create_test_game();
|
||||
#[test]
|
||||
fn ko_resolution_test() {
|
||||
let mut game = create_test_game();
|
||||
|
||||
// let x_player = game.players[0].clone();
|
||||
// let y_player = game.players[1].clone();
|
||||
let x_player = game.players[0].clone();
|
||||
let y_player = game.players[1].clone();
|
||||
|
||||
// let x_construct = x_player.constructs[0].clone();
|
||||
// let y_construct = y_player.constructs[0].clone();
|
||||
let x_construct = x_player.constructs[0].clone();
|
||||
let y_construct = y_player.constructs[0].clone();
|
||||
|
||||
// game.player_by_id(y_player.id).unwrap().construct_by_id(y_construct.id).unwrap().red_power.force(1000000000);
|
||||
// game.player_by_id(y_player.id).unwrap().construct_by_id(y_construct.id).unwrap().speed.force(1000000000);
|
||||
game.player_by_id(y_player.id).unwrap().construct_by_id(y_construct.id).unwrap().red_power.force(1000000000);
|
||||
game.player_by_id(y_player.id).unwrap().construct_by_id(y_construct.id).unwrap().speed.force(1000000000);
|
||||
|
||||
// while game.construct_by_id(x_construct.id).unwrap().skill_on_cd(Skill::Stun).is_some() {
|
||||
// game.construct_by_id(x_construct.id).unwrap().reduce_cooldowns();
|
||||
// }
|
||||
while game.construct_by_id(x_construct.id).unwrap().skill_on_cd(Skill::Stun).is_some() {
|
||||
game.construct_by_id(x_construct.id).unwrap().reduce_cooldowns();
|
||||
}
|
||||
|
||||
// // just in case
|
||||
// // remove all mitigation
|
||||
// game.player_by_id(x_player.id).unwrap().construct_by_id(x_construct.id).unwrap().red_life.force(0);
|
||||
// just in case
|
||||
// remove all mitigation
|
||||
game.player_by_id(x_player.id).unwrap().construct_by_id(x_construct.id).unwrap().red_life.force(0);
|
||||
|
||||
// game.add_skill(x_player.id, x_construct.id, y_construct.id, Skill::Stun).unwrap();
|
||||
// game.add_skill(y_player.id, y_construct.id, x_construct.id, Skill::Attack).unwrap();
|
||||
game.add_skill(x_player.id, x_construct.id, y_construct.id, Skill::Stun).unwrap();
|
||||
game.add_skill(y_player.id, y_construct.id, x_construct.id, Skill::Attack).unwrap();
|
||||
|
||||
// game.player_ready(x_player.id).unwrap();
|
||||
// game.player_ready(y_player.id).unwrap();
|
||||
game.player_ready(x_player.id).unwrap();
|
||||
game.player_ready(y_player.id).unwrap();
|
||||
|
||||
// assert!(game.skill_phase_finished());
|
||||
// game = game.resolve_phase_start();
|
||||
assert!(game.skill_phase_finished());
|
||||
game = game.resolve_phase_start();
|
||||
|
||||
// assert!(!game.player_by_id(y_player.id).unwrap().constructs[0].is_stunned());
|
||||
// assert!(game.phase == Phase::Finished);
|
||||
// }
|
||||
assert!(!game.player_by_id(y_player.id).unwrap().constructs[0].is_stunned());
|
||||
assert!(game.phase == Phase::Finished);
|
||||
}
|
||||
|
||||
// #[test]
|
||||
// fn cooldown_test() {
|
||||
// let mut game = create_test_game();
|
||||
#[test]
|
||||
fn cooldown_test() {
|
||||
let mut game = create_test_game();
|
||||
|
||||
// let x_player = game.players[0].clone();
|
||||
// let y_player = game.players[1].clone();
|
||||
let x_player = game.players[0].clone();
|
||||
let y_player = game.players[1].clone();
|
||||
|
||||
// let x_construct = x_player.constructs[0].clone();
|
||||
// let y_construct = y_player.constructs[0].clone();
|
||||
let x_construct = x_player.constructs[0].clone();
|
||||
let y_construct = y_player.constructs[0].clone();
|
||||
|
||||
// // should auto progress back to skill phase
|
||||
// assert!(game.phase == Phase::Skill);
|
||||
// should auto progress back to skill phase
|
||||
assert!(game.phase == Phase::Skill);
|
||||
|
||||
// assert!(game.player_by_id(y_player.id).unwrap().constructs[0].skill_on_cd(Skill::Block).is_none());
|
||||
// assert!(game.player_by_id(y_player.id).unwrap().constructs[0].skill_on_cd(Skill::Stun).is_some());
|
||||
// assert!(game.player_by_id(x_player.id).unwrap().constructs[0].skill_on_cd(Skill::Block).is_none());
|
||||
assert!(game.player_by_id(y_player.id).unwrap().constructs[0].skill_on_cd(Skill::Stun).is_some());
|
||||
assert!(game.player_by_id(x_player.id).unwrap().constructs[0].skill_on_cd(Skill::Block).is_none());
|
||||
|
||||
// game.add_skill(x_player.id, x_construct.id, y_construct.id, Skill::Attack).unwrap();
|
||||
// game.add_skill(y_player.id, y_construct.id, x_construct.id, Skill::Attack).unwrap();
|
||||
game.add_skill(x_player.id, x_construct.id, y_construct.id, Skill::Attack).unwrap();
|
||||
game.add_skill(y_player.id, y_construct.id, x_construct.id, Skill::Attack).unwrap();
|
||||
|
||||
// game.player_ready(x_player.id).unwrap();
|
||||
// game.player_ready(y_player.id).unwrap();
|
||||
game.player_ready(x_player.id).unwrap();
|
||||
game.player_ready(y_player.id).unwrap();
|
||||
|
||||
// game = game.resolve_phase_start();
|
||||
game = game.resolve_phase_start();
|
||||
|
||||
// // should auto progress back to skill phase
|
||||
// assert!(game.phase == Phase::Skill);
|
||||
// assert!(game.player_by_id(y_player.id).unwrap().constructs[0].skill_on_cd(Skill::Stun).is_some());
|
||||
// should auto progress back to skill phase
|
||||
assert!(game.phase == Phase::Skill);
|
||||
assert!(game.player_by_id(y_player.id).unwrap().constructs[0].skill_on_cd(Skill::Stun).is_none());
|
||||
|
||||
// // second round
|
||||
// // now we block and it should go back on cd
|
||||
// // game.add_skill(x_player.id, x_construct.id, y_construct.id, Skill::Stun).unwrap();
|
||||
// game.add_skill(y_player.id, y_construct.id, x_construct.id, Skill::Attack).unwrap();
|
||||
// second round
|
||||
// now we block and it should go back on cd
|
||||
game.add_skill(x_player.id, x_construct.id, y_construct.id, Skill::Stun).unwrap();
|
||||
game.add_skill(y_player.id, y_construct.id, x_construct.id, Skill::Attack).unwrap();
|
||||
|
||||
// game.player_ready(x_player.id).unwrap();
|
||||
// game.player_ready(y_player.id).unwrap();
|
||||
game.player_ready(x_player.id).unwrap();
|
||||
game.player_ready(y_player.id).unwrap();
|
||||
|
||||
// game = game.resolve_phase_start();
|
||||
game = game.resolve_phase_start();
|
||||
|
||||
// assert!(game.player_by_id(x_player.id).unwrap().constructs[0].skill_on_cd(Skill::Stun).is_none());
|
||||
// assert!(game.player_by_id(y_player.id).unwrap().constructs[0].skill_on_cd(Skill::Block).is_none());
|
||||
// }
|
||||
println!("{:?}", game.player_by_id(x_player.id).unwrap().constructs[0]);
|
||||
assert!(game.player_by_id(x_player.id).unwrap().constructs[0].skill_on_cd(Skill::Stun).is_some());
|
||||
assert!(game.player_by_id(y_player.id).unwrap().constructs[0].skill_on_cd(Skill::Block).is_none());
|
||||
}
|
||||
|
||||
// #[test]
|
||||
// fn sleep_cooldown_test() {
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user