Merge branch 'master' of ssh://cryps.gg:40022/~/cryps

This commit is contained in:
Mashy 2018-12-14 16:10:03 +10:00
commit f78cf7ffff
3 changed files with 27 additions and 17 deletions

View File

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

View File

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

View File

@ -50,7 +50,7 @@ impl Cast {
} }
pub fn used_cooldown(&self) -> bool { pub fn used_cooldown(&self) -> bool {
return self.skill.cd().is_some(); return self.skill.base_cd().is_some();
} }
} }
@ -344,7 +344,7 @@ pub enum Skill {
} }
impl Skill { impl Skill {
pub fn cd(&self) -> Cooldown { pub fn base_cd(&self) -> Cooldown {
match self { match self {
Skill::Attack => None, Skill::Attack => None,