From f4992e4e877587ec74e407026878d08d3bb5fdb7 Mon Sep 17 00:00:00 2001 From: ntr Date: Wed, 29 May 2019 13:47:34 +1000 Subject: [PATCH] fix tests and remove test skills --- server/src/game.rs | 90 ++++++++++++++++++++++++++------------------- server/src/item.rs | 20 +++------- server/src/skill.rs | 71 ++++++++--------------------------- 3 files changed, 75 insertions(+), 106 deletions(-) diff --git a/server/src/game.rs b/server/src/game.rs index 109a7e17..51a544ef 100644 --- a/server/src/game.rs +++ b/server/src/game.rs @@ -948,11 +948,11 @@ mod tests { let mut x = Construct::new() .named(&"pronounced \"creeep\"".to_string()) .learn(Skill::Attack) - .learn(Skill::TestStun) - .learn(Skill::TestTouch) - .learn(Skill::TestBlock) - .learn(Skill::TestParry) - .learn(Skill::TestSiphon) + .learn(Skill::Stun) + .learn(Skill::Attack) + .learn(Skill::Block) + .learn(Skill::ParryI) + .learn(Skill::SiphonI) .learn(Skill::AmplifyI) .learn(Skill::Stun) .learn(Skill::Block); @@ -960,11 +960,11 @@ mod tests { let mut y = Construct::new() .named(&"lemongrass tea".to_string()) .learn(Skill::Attack) - .learn(Skill::TestStun) - .learn(Skill::TestTouch) - .learn(Skill::TestBlock) - .learn(Skill::TestParry) - .learn(Skill::TestSiphon) + .learn(Skill::Stun) + .learn(Skill::Attack) + .learn(Skill::Block) + .learn(Skill::ParryI) + .learn(Skill::SiphonI) .learn(Skill::AmplifyI) .learn(Skill::Stun) .learn(Skill::Block); @@ -996,22 +996,22 @@ mod tests { let mut i = Construct::new() .named(&"pretaliate".to_string()) .learn(Skill::Attack) - .learn(Skill::TestTouch); + .learn(Skill::Attack); let mut j = Construct::new() .named(&"poy sian".to_string()) .learn(Skill::Attack) - .learn(Skill::TestTouch); + .learn(Skill::Attack); let mut x = Construct::new() .named(&"pronounced \"creeep\"".to_string()) .learn(Skill::Attack) - .learn(Skill::TestTouch); + .learn(Skill::Attack); let mut y = Construct::new() .named(&"lemongrass tea".to_string()) .learn(Skill::Attack) - .learn(Skill::TestTouch); + .learn(Skill::Attack); let mut game = Game::new(); @@ -1073,8 +1073,12 @@ mod tests { 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, Some(y_construct.id), Skill::TestStun).unwrap(); - game.add_skill(y_player.id, y_construct.id, Some(x_construct.id), Skill::TestTouch).unwrap(); + 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, Some(y_construct.id), Skill::Stun).unwrap(); + game.add_skill(y_player.id, y_construct.id, Some(x_construct.id), Skill::Attack).unwrap(); game.player_ready(x_player.id).unwrap(); game.player_ready(y_player.id).unwrap(); @@ -1102,11 +1106,15 @@ mod tests { 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(); + } + // 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, Some(y_construct.id), Skill::TestStun).unwrap(); + game.add_skill(x_player.id, x_construct.id, Some(y_construct.id), Skill::Stun).unwrap(); game.add_skill(y_player.id, y_construct.id, Some(x_construct.id), Skill::Attack).unwrap(); game.player_ready(x_player.id).unwrap(); @@ -1136,8 +1144,8 @@ mod tests { 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, Some(y_construct.id), Skill::TestTouch).unwrap(); - game.add_skill(y_player.id, y_construct.id, Some(x_construct.id), Skill::TestTouch).unwrap(); + game.add_skill(x_player.id, x_construct.id, Some(y_construct.id), Skill::Attack).unwrap(); + game.add_skill(y_player.id, y_construct.id, Some(x_construct.id), Skill::Attack).unwrap(); game.player_ready(x_player.id).unwrap(); game.player_ready(y_player.id).unwrap(); @@ -1151,7 +1159,7 @@ mod tests { // second round // now we block and it should go back on cd // game.add_skill(x_player.id, x_construct.id, Some(y_construct.id), Skill::Stun).unwrap(); - game.add_skill(y_player.id, y_construct.id, Some(x_construct.id), Skill::TestTouch).unwrap(); + game.add_skill(y_player.id, y_construct.id, Some(x_construct.id), Skill::Attack).unwrap(); game.player_ready(x_player.id).unwrap(); game.player_ready(y_player.id).unwrap(); @@ -1172,8 +1180,16 @@ mod tests { 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, None, Skill::TestParry).unwrap(); - game.add_skill(y_player.id, y_construct.id, Some(x_construct.id), Skill::TestStun).unwrap(); + while game.construct_by_id(y_construct.id).unwrap().skill_on_cd(Skill::Stun).is_some() { + game.construct_by_id(y_construct.id).unwrap().reduce_cooldowns(); + } + + while game.construct_by_id(x_construct.id).unwrap().skill_on_cd(Skill::ParryI).is_some() { + game.construct_by_id(x_construct.id).unwrap().reduce_cooldowns(); + } + + game.add_skill(x_player.id, x_construct.id, None, Skill::ParryI).unwrap(); + game.add_skill(y_player.id, y_construct.id, Some(x_construct.id), Skill::Stun).unwrap(); game.player_ready(x_player.id).unwrap(); game.player_ready(y_player.id).unwrap(); @@ -1210,7 +1226,7 @@ mod tests { assert!(game.construct_by_id(x_construct.id).unwrap().affected(Effect::Corrupt)); // attack and receive debuff - game.add_skill(y_player.id, y_construct.id, Some(x_construct.id), Skill::TestTouch).unwrap(); + game.add_skill(y_player.id, y_construct.id, Some(x_construct.id), Skill::Attack).unwrap(); game.player_ready(x_player.id).unwrap(); game.player_ready(y_player.id).unwrap(); game = game.resolve_phase_start(); @@ -1319,10 +1335,10 @@ mod tests { game.construct_by_id(x_construct.id).unwrap().reduce_cooldowns(); } - game.add_skill(i_player.id, i_construct.id, Some(x_construct.id), Skill::TestTouch).unwrap(); - game.add_skill(i_player.id, j_construct.id, Some(x_construct.id), Skill::TestTouch).unwrap(); + game.add_skill(i_player.id, i_construct.id, Some(x_construct.id), Skill::Attack).unwrap(); + game.add_skill(i_player.id, j_construct.id, Some(x_construct.id), Skill::Attack).unwrap(); game.add_skill(x_player.id, x_construct.id, Some(i_construct.id), Skill::RuinI).unwrap(); - game.add_skill(x_player.id, y_construct.id, Some(i_construct.id), Skill::TestTouch).unwrap(); + game.add_skill(x_player.id, y_construct.id, Some(i_construct.id), Skill::Attack).unwrap(); game.player_ready(i_player.id).unwrap(); game.player_ready(x_player.id).unwrap(); @@ -1369,10 +1385,10 @@ mod tests { game.construct_by_id(x_construct.id).unwrap().reduce_cooldowns(); } - game.add_skill(i_player.id, i_construct.id, Some(x_construct.id), Skill::TestTouch).unwrap(); - game.add_skill(i_player.id, j_construct.id, Some(x_construct.id), Skill::TestTouch).unwrap(); + game.add_skill(i_player.id, i_construct.id, Some(x_construct.id), Skill::Attack).unwrap(); + game.add_skill(i_player.id, j_construct.id, Some(x_construct.id), Skill::Attack).unwrap(); game.add_skill(x_player.id, x_construct.id, Some(i_construct.id), Skill::TauntI).unwrap(); - game.add_skill(x_player.id, y_construct.id, Some(i_construct.id), Skill::TestTouch).unwrap(); + game.add_skill(x_player.id, y_construct.id, Some(i_construct.id), Skill::Attack).unwrap(); game.player_ready(i_player.id).unwrap(); game.player_ready(x_player.id).unwrap(); @@ -1400,10 +1416,10 @@ mod tests { let x_construct = x_player.constructs[0].clone(); let y_construct = x_player.constructs[1].clone(); - game.add_skill(i_player.id, i_construct.id, Some(x_construct.id), Skill::TestTouch).unwrap(); - game.add_skill(i_player.id, j_construct.id, Some(x_construct.id), Skill::TestTouch).unwrap(); - game.add_skill(x_player.id, x_construct.id, Some(i_construct.id), Skill::TestTouch).unwrap(); - game.add_skill(x_player.id, y_construct.id, Some(i_construct.id), Skill::TestTouch).unwrap(); + game.add_skill(i_player.id, i_construct.id, Some(x_construct.id), Skill::Attack).unwrap(); + game.add_skill(i_player.id, j_construct.id, Some(x_construct.id), Skill::Attack).unwrap(); + game.add_skill(x_player.id, x_construct.id, Some(i_construct.id), Skill::Attack).unwrap(); + game.add_skill(x_player.id, y_construct.id, Some(i_construct.id), Skill::Attack).unwrap(); game.player_ready(i_player.id).unwrap(); game.player_ready(x_player.id).unwrap(); @@ -1420,10 +1436,10 @@ mod tests { assert!(game.player_by_id(x_player.id).unwrap().skills_required() == 2); // add some more skills - game.add_skill(i_player.id, j_construct.id, Some(x_construct.id), Skill::TestTouch).unwrap(); - game.add_skill(x_player.id, x_construct.id, Some(j_construct.id), Skill::TestTouch).unwrap(); - game.add_skill(x_player.id, y_construct.id, Some(j_construct.id), Skill::TestTouch).unwrap(); - assert!(game.add_skill(x_player.id, x_construct.id, Some(i_construct.id), Skill::TestTouch).is_err()); + game.add_skill(i_player.id, j_construct.id, Some(x_construct.id), Skill::Attack).unwrap(); + game.add_skill(x_player.id, x_construct.id, Some(j_construct.id), Skill::Attack).unwrap(); + game.add_skill(x_player.id, y_construct.id, Some(j_construct.id), Skill::Attack).unwrap(); + assert!(game.add_skill(x_player.id, x_construct.id, Some(i_construct.id), Skill::Attack).is_err()); game.player_ready(i_player.id).unwrap(); game.player_ready(x_player.id).unwrap(); diff --git a/server/src/item.rs b/server/src/item.rs index 295507d5..e6530e3d 100644 --- a/server/src/item.rs +++ b/server/src/item.rs @@ -139,13 +139,6 @@ pub enum Item { TriageI, TriageII, TriageIII, - - - TestTouch, - TestStun, - TestBlock, - TestParry, - TestSiphon, } pub enum ItemEffect { @@ -877,11 +870,11 @@ impl From for Item { Skill::CorruptII => Item::CorruptII, Skill::CorruptIII => Item::CorruptIII, - Skill::TestTouch => Item::TestTouch, - Skill::TestStun => Item::TestStun, - Skill::TestBlock => Item::TestBlock, - Skill::TestParry => Item::TestParry, - Skill::TestSiphon => Item::TestSiphon, + Skill::Attack => Item::Attack, + Skill::Stun => Item::Stun, + Skill::Block => Item::Block, + Skill::ParryI => Item::ParryI, + Skill::SiphonI => Item::SiphonI, _ => panic!("{:?} not implemented with item conversion", skill), } } @@ -1147,7 +1140,6 @@ mod tests { #[test] fn item_info_test() { - let info = item_info(); - println!("{:#?}", info); + item_info(); } } \ No newline at end of file diff --git a/server/src/skill.rs b/server/src/skill.rs index c53dbdc2..7e43c932 100644 --- a/server/src/skill.rs +++ b/server/src/skill.rs @@ -276,16 +276,6 @@ pub fn resolve(skill: Skill, source: &mut Construct, target: &mut Construct, mut // Not used Skill::Injure => injure(source, target, resolutions, skill), - // ----------------- - // Test - // ----------------- - Skill::TestAttack => attack(source, target, resolutions, skill), - Skill::TestHeal => heal(source, target, resolutions, skill), - Skill::TestTouch => touch(source, target, resolutions, skill), - Skill::TestStun => stun(source, target, resolutions, Skill::Stun), - Skill::TestBlock => block(source, target, resolutions, Skill::Block), - Skill::TestParry => parry(source, target, resolutions, Skill::ParryI), - Skill::TestSiphon => siphon(source, target, resolutions, Skill::SiphonI), }; return resolutions; @@ -845,15 +835,6 @@ pub enum Skill { TriageTickI, TriageTickII, TriageTickIII, - - // used by tests, no cd, 100% multiplier - TestAttack, - TestHeal, - TestTouch, // No damage - TestStun, - TestBlock, - TestParry, - TestSiphon, } impl Skill { @@ -1265,17 +1246,6 @@ impl Skill { Skill::TriageTickI | Skill::TriageTickII | Skill::TriageTickIII => None, - // Triggers - // ----------------- - // Test - // ----------------- - Skill::TestAttack => None, - Skill::TestHeal => None, - Skill::TestTouch => None, - Skill::TestStun => None, - Skill::TestBlock => None, - Skill::TestSiphon => None, - Skill::TestParry => None, } } @@ -1323,15 +1293,6 @@ impl Skill { pub fn speed(&self) -> u8 { match self { - // ----------------- - // Test - // ----------------- - Skill::TestTouch => 10, - Skill::TestStun => 5, - Skill::TestBlock => 10, - Skill::TestParry => 10, - Skill::TestSiphon => 10, - Skill::StrikeI => u8::max_value(), Skill::StrikeII => Skill::StrikeI.speed(), Skill::StrikeIII => Skill::StrikeI.speed(), @@ -1379,8 +1340,8 @@ impl Skill { Skill::ParryI | Skill::ParryII | Skill::ParryIII | - Skill::TestBlock | - Skill::TestParry => true, + Skill::Block | + Skill::ParryI => true, _ => false, } @@ -2003,11 +1964,12 @@ mod tests { block(&mut y.clone(), &mut y, vec![], Skill::Block); assert!(y.effects.iter().any(|e| e.effect == Effect::Block)); - let mut results = attack(&mut x, &mut y, vec![], Skill::TestAttack); + let mut results = attack(&mut x, &mut y, vec![], Skill::Attack); let Resolution { source: _, target: _, event } = results.remove(0); match event { - Event::Damage { amount, mitigation: _, colour: _, skill: _ } => assert_eq!(amount, 50), + Event::Damage { amount, mitigation: _, colour: _, skill: _ } => + assert!(amount < x.red_power().pct(Skill::Attack.multiplier())), _ => panic!("not damage"), }; } @@ -2066,30 +2028,29 @@ mod tests { // give red shield but reduce to 0 y.red_life.force(64); y.red_life.reduce(64); - x.red_power.force(256 + 64); + x.red_power.force(512); invert(&mut y.clone(), &mut y, vec![], Skill::InvertI); assert!(y.affected(Effect::Invert)); // heal should deal green damage - heal(&mut x, &mut y, vec![], Skill::TestHeal); - assert!(y.green_life() == 768); + heal(&mut x, &mut y, vec![], Skill::HealI); + assert!(y.green_life() < 1024); // attack should heal and recharge red shield - let mut results = attack(&mut x, &mut y, vec![], Skill::TestAttack); - assert!(y.green_life() == 1024); + let mut results = attack(&mut x, &mut y, vec![], Skill::Attack); match results.remove(0).event { - Event::Inversion { skill } => assert_eq!(skill, Skill::TestAttack), + Event::Inversion { skill } => assert_eq!(skill, Skill::Attack), _ => panic!("not inversion"), }; match results.remove(0).event { - Event::Healing { skill: _, overhealing: _, amount } => assert_eq!(amount, 256), + Event::Healing { skill: _, overhealing: _, amount } => assert!(amount > 0), _ => panic!("not healing from inversion"), }; match results.remove(0).event { - Event::Recharge { skill: _, red, blue: _ } => assert_eq!(red, 64), + Event::Recharge { skill: _, red, blue: _ } => assert!(red > 0), _ => panic!("not recharge from inversion"), }; } @@ -2106,19 +2067,19 @@ mod tests { assert!(y.affected(Effect::Reflect)); let mut results = vec![]; - results = resolve(Skill::TestAttack, &mut x, &mut y, results); + results = resolve(Skill::Attack, &mut x, &mut y, results); - assert!(x.green_life() == 768); + assert!(x.green_life() < 1024); let Resolution { source: _, target: _, event } = results.remove(0); match event { - Event::Reflection { skill } => assert_eq!(skill, Skill::TestAttack), + Event::Reflection { skill } => assert_eq!(skill, Skill::Attack), _ => panic!("not reflection"), }; let Resolution { source: _, target: _, event } = results.remove(0); match event { - Event::Damage { amount, mitigation: _, colour: _, skill: _ } => assert_eq!(amount, 256), + Event::Damage { amount, mitigation: _, colour: _, skill: _ } => assert!(amount > 0), _ => panic!("not damage"), }; }