fix cooldown bug

This commit is contained in:
ntr 2018-12-14 13:52:00 +11:00
parent d225843e35
commit e20aabb6e4
2 changed files with 24 additions and 14 deletions

View File

@ -255,16 +255,20 @@ impl Cryp {
pub fn reduce_cooldowns(&mut self) -> &mut Cryp {
for skill in self.skills.iter_mut() {
// if used cooldown
if let Some(cd) = skill.skill.cd() {
// if the cd is 1 it becomes none
if cd == 1 {
// println!("{:?} is now off cd", skill.skill);
skill.cd = None;
continue;
if skill.skill.cd().is_some() {
// what is the current cd
if let Some(current_cd) = skill.cd {
// if it's 1 set it to none
if current_cd == 1 {
skill.cd = None;
continue;
}
// otherwise decrement it
skill.cd = Some(current_cd.saturating_sub(1));
}
// otherwise decrement it
skill.cd = Some(cd.saturating_sub(1));
}
}
@ -273,7 +277,6 @@ impl Cryp {
pub fn reduce_effect_durations(&mut self, log: &mut Log) -> &mut Cryp {
self.effects = self.effects.clone().into_iter().filter_map(|mut effect| {
effect.duration = effect.duration.saturating_sub(1);
if effect.duration == 0 {

View File

@ -889,6 +889,7 @@ mod tests {
.learn(Skill::TestTouch)
.learn(Skill::TestBlock)
.learn(Skill::TestDrain)
.learn(Skill::Empower)
.learn(Skill::Block)
.create();
@ -899,6 +900,7 @@ mod tests {
.learn(Skill::TestTouch)
.learn(Skill::TestBlock)
.learn(Skill::TestDrain)
.learn(Skill::Empower)
.learn(Skill::Block)
.create();
@ -1066,12 +1068,11 @@ mod tests {
game.resolve_phase_start();
// resolution should have been prevented by KO
println!("{:#?}", game);
// println!("{:#?}", game);
assert!(!game.team_by_id(y_team.id).cryps[0].is_stunned());
assert!(game.phase == Phase::Finish);
}
#[test]
fn cooldown_test() {
let mut game = create_test_game();
@ -1094,19 +1095,25 @@ mod tests {
// should auto progress back to skill phase
assert!(game.phase == Phase::Skill);
// after 1 turn block should be off cooldown
assert!(game.team_by_id(y_team.id).cryps[0].skill_on_cd(Skill::Block).is_none());
assert!(game.team_by_id(y_team.id).cryps[0].skill_on_cd(Skill::Empower).is_some());
assert!(game.team_by_id(x_team.id).cryps[0].skill_on_cd(Skill::Block).is_none());
// second round
// now we block and it should go back on cd
let _x_block_id = game.add_skill(x_team.id, x_cryp.id, None, Skill::Block).unwrap();
let _y_block_id = game.add_skill(y_team.id, y_cryp.id, None, Skill::Block).unwrap();
let y_touch_id = game.add_skill(y_team.id, y_cryp.id, Some(x_team.id), Skill::TestTouch).unwrap();
game.target_phase_start();
assert!(game.team_by_id(y_team.id).cryps[0].skill_on_cd(Skill::Block).is_some());
game.add_target(x_team.id, x_cryp.id, y_touch_id).unwrap();
game.resolve_phase_start();
assert!(game.team_by_id(x_team.id).cryps[0].skill_on_cd(Skill::Block).is_some());
assert!(game.team_by_id(y_team.id).cryps[0].skill_on_cd(Skill::Empower).is_none());
}
#[test]
@ -1119,7 +1126,7 @@ mod tests {
let x_cryp = x_team.cryps[0].clone();
let y_cryp = y_team.cryps[0].clone();
let x_block_id = game.add_skill(x_team.id, x_cryp.id, None, Skill::TestBlock).unwrap();
let _x_block_id = game.add_skill(x_team.id, x_cryp.id, None, Skill::TestBlock).unwrap();
let y_attack_id = game.add_skill(y_team.id, y_cryp.id, Some(x_team.id), Skill::TestStun).unwrap();
game.target_phase_start();