From 16488ee0ee556de5b5d43a394d56116c29265540 Mon Sep 17 00:00:00 2001 From: ntr Date: Thu, 19 Dec 2019 13:50:26 +1000 Subject: [PATCH 1/2] log panics --- server/Cargo.toml | 1 + server/src/lib.rs | 3 +++ 2 files changed, 4 insertions(+) diff --git a/server/Cargo.toml b/server/Cargo.toml index accc74b3..2dfe13f5 100644 --- a/server/Cargo.toml +++ b/server/Cargo.toml @@ -25,6 +25,7 @@ dotenv = "0.9.0" log = "0.4" fern = { version = "0.5", features = ["colored", "syslog-4"] } syslog = "4" +log-panics = "2" iron = "0.6" bodyparser = "0.8" diff --git a/server/src/lib.rs b/server/src/lib.rs index 954197e4..66efa49d 100644 --- a/server/src/lib.rs +++ b/server/src/lib.rs @@ -15,6 +15,7 @@ extern crate serde_cbor; #[macro_use] extern crate failure; extern crate fern; +extern crate log_panics; #[macro_use] extern crate log; extern crate stripe; @@ -55,6 +56,8 @@ use crossbeam_channel::{unbounded}; #[cfg(unix)] pub fn setup_logger() -> Result<(), fern::InitError> { + log_panics::init(); + let formatter = syslog::Formatter3164 { facility: syslog::Facility::LOG_USER, hostname: None, From 9a5a93ce242afc4b1ed9464b4f866236d8ec3b1c Mon Sep 17 00:00:00 2001 From: ntr Date: Thu, 19 Dec 2019 14:42:42 +1000 Subject: [PATCH 2/2] fix ruin cooldown --- core/src/construct.rs | 4 +- core/src/game.rs | 91 +++++++++++++++++-------------------------- core/src/item.rs | 21 ++++------ core/src/skill.rs | 7 ---- 4 files changed, 45 insertions(+), 78 deletions(-) diff --git a/core/src/construct.rs b/core/src/construct.rs index 47c60095..32579e7b 100644 --- a/core/src/construct.rs +++ b/core/src/construct.rs @@ -435,12 +435,14 @@ impl Construct { } pub fn skill_set_cd(&mut self, skill: Skill) -> &mut Construct { + // println!("{:?} {:?} skill cooldown set", self.name, skill); + // tests force resolve some skills // which cause the game to attempt to put them on cd // even though the construct doesn't know the skill if let Some(i) = self.skills.iter().position(|s| s.skill == skill) { self.skills.remove(i); - self.skills.push(ConstructSkill::new(skill)); + self.skills.insert(i, ConstructSkill::new(skill)); } self diff --git a/core/src/game.rs b/core/src/game.rs index 6724e12b..917cec9d 100644 --- a/core/src/game.rs +++ b/core/src/game.rs @@ -508,14 +508,14 @@ impl Game { self.resolve(Cast { skill, ..cast }); } - // for aoe events send the source / target animations before each set of casts + if cast.skill.cast_animation() { + self.action(cast, Action::Cast); + } + if cast.skill.aoe() { - if cast.skill.cast_animation() { - let event = self.cast(cast); - self.add_resolution(&cast, &event); - } - let event = self.hit_aoe(cast); - self.add_resolution(&cast, &event); + self.action(cast, Action::HitAoe); + } else { + self.action(cast, Action::Hit); } let casts = self.modify_cast(cast); @@ -559,6 +559,7 @@ impl Game { let new_events = match action { Action::Cast => vec![self.cast(cast)], Action::Hit => vec![self.hit(cast)], + Action::HitAoe => vec![self.hit_aoe(cast)], Action::Damage { construct, amount, colour } => self.damage(construct, amount, colour), Action::Heal { construct, amount, colour } => self.heal(construct, amount, colour), @@ -848,6 +849,7 @@ pub enum Value { #[derive(Debug,Clone,PartialEq)] pub enum Action { Hit, + HitAoe, Cast, Heal { construct: Uuid, amount: usize, colour: Colour }, Damage { construct: Uuid, amount: usize, colour: Colour }, @@ -1033,6 +1035,7 @@ mod tests { .learn(Skill::Siphon) .learn(Skill::Amplify) .learn(Skill::Stun) + .learn(Skill::Ruin) .learn(Skill::Block) .learn(Skill::Sleep) .learn(Skill::Decay); @@ -1251,6 +1254,31 @@ mod tests { assert!(game.player_by_id(y_player.id).unwrap().constructs[0].skill_on_cd(Skill::Block).is_none()); } + + #[test] + fn ruin_cooldown_test() { + let mut game = create_test_game(); + + 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(); + + while game.construct_by_id(x_construct.id).unwrap().skill_on_cd(Skill::Ruin).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::Ruin).unwrap(); + + game.player_ready(x_player.id).unwrap(); + game.player_ready(y_player.id).unwrap(); + + game = game.resolve_phase_start(); + + assert!(game.player_by_id(x_player.id).unwrap().constructs[0].skill_on_cd(Skill::Ruin).is_some()); + } + // #[cfg(test)] // mod tests { // use skill::*; @@ -1595,55 +1623,6 @@ mod tests { // } // } - - #[test] - fn sleep_cooldown_test() { - let mut game = create_test_game(); - - 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(); - - - for _n in 1..10 { - // should auto progress back to skill phase - assert!(game.phase == Phase::Skill); - - // Sleep 2T CD - assert!(game.player_by_id(x_player.id).unwrap().constructs[0].skill_on_cd(Skill::Decay).is_none()); - assert!(game.player_by_id(x_player.id).unwrap().constructs[0].skill_on_cd(Skill::Sleep).is_some()); - - game.player_ready(x_player.id).unwrap(); - game.player_ready(y_player.id).unwrap(); - game = game.resolve_phase_start(); - - // Sleep 1T CD - assert!(game.player_by_id(x_player.id).unwrap().constructs[0].skill_on_cd(Skill::Decay).is_none()); - assert!(game.player_by_id(x_player.id).unwrap().constructs[0].skill_on_cd(Skill::Sleep).is_some()); - - game.add_skill(x_player.id, x_construct.id, y_construct.id, Skill::Decay).unwrap(); - // game.add_skill(x_player.id, x_construct.id, y_construct.id, Skill::Attack).unwrap(); - game.player_ready(x_player.id).unwrap(); - game.player_ready(y_player.id).unwrap(); - game = game.resolve_phase_start(); - - // Sleep 0T CD (we use it here) - assert!(game.player_by_id(x_player.id).unwrap().constructs[0].skill_on_cd(Skill::Decay).is_none()); - assert!(game.player_by_id(x_player.id).unwrap().constructs[0].skill_on_cd(Skill::Sleep).is_none()); - - game.add_skill(x_player.id, x_construct.id, y_construct.id, Skill::Sleep).unwrap(); - game.player_ready(x_player.id).unwrap(); - game.player_ready(y_player.id).unwrap(); - game = game.resolve_phase_start(); - - // Sleep back to 2T CD - assert!(game.player_by_id(x_player.id).unwrap().constructs[0].skill_on_cd(Skill::Decay).is_none()); - assert!(game.player_by_id(x_player.id).unwrap().constructs[0].skill_on_cd(Skill::Sleep).is_some()); - } - } - // #[test] // fn counter_test() { // let mut game = create_test_game(); diff --git a/core/src/item.rs b/core/src/item.rs index 43b2a73e..185b1832 100644 --- a/core/src/item.rs +++ b/core/src/item.rs @@ -716,7 +716,7 @@ impl Item { Item::HealPlusPlus | Item::Triage | Item::TriagePlus | - Item::TriagePlusPlus | + Item::TriagePlusPlus | Item::Break | Item::BreakPlus | Item::BreakPlusPlus | @@ -735,7 +735,7 @@ impl Item { Item::Invert | Item::InvertPlus | Item::InvertPlusPlus | - Item::Decay | + Item::Decay | Item::DecayPlus | Item::DecayPlusPlus | Item::Siphon| @@ -817,7 +817,7 @@ impl Item { Item::AmplifyPlus => vec![Item::Amplify, Item::Amplify], Item::AmplifyPlusPlus => vec![Item::AmplifyPlus, Item::AmplifyPlus], - + Item::HastePlus => vec![Item::Haste, Item::Haste], Item::HastePlusPlus => vec![Item::HastePlus, Item::HastePlus], @@ -832,9 +832,9 @@ impl Item { Item::Curse => vec![Item::Debuff, Item::Red, Item::Blue], Item::Decay => vec![Item::Debuff, Item::Green, Item::Blue], - Item::PurgePlus => vec![Item::Purge, Item::Purge], + Item::PurgePlus => vec![Item::Purge, Item::Purge], Item::PurgePlusPlus => vec![Item::PurgePlus, Item::PurgePlus], - + Item::InvertPlus => vec![Item::Invert, Item::Invert], Item::InvertPlusPlus => vec![Item::InvertPlus, Item::InvertPlus], @@ -843,10 +843,10 @@ impl Item { Item::SilencePlus => vec![Item::Silence, Item::Silence], Item::SilencePlusPlus => vec![Item::SilencePlus, Item::SilencePlus], - + Item::CursePlus => vec![Item::Curse, Item::Curse], Item::CursePlusPlus => vec![Item::CursePlus, Item::CursePlus], - + Item::DecayPlus => vec![Item::Decay, Item::Decay], Item::DecayPlusPlus => vec![Item::DecayPlus, Item::DecayPlus], @@ -1427,20 +1427,13 @@ mod tests { assert_eq!(Item::StrikePlus.components(), vec![ Item::Red, Item::Red, Item::Attack, Item::Red, Item::Red, Item::Attack, - Item::Red, Item::Red, Item::Attack, ]); assert_eq!(Item::StrikePlusPlus.components(), vec![ Item::Red, Item::Red, Item::Attack, Item::Red, Item::Red, Item::Attack, - Item::Red, Item::Red, Item::Attack, Item::Red, Item::Red, Item::Attack, Item::Red, Item::Red, Item::Attack, - Item::Red, Item::Red, Item::Attack, - - Item::Red, Item::Red, Item::Attack, - Item::Red, Item::Red, Item::Attack, - Item::Red, Item::Red, Item::Attack, ]); } diff --git a/core/src/skill.rs b/core/src/skill.rs index 6599ba96..51465b07 100644 --- a/core/src/skill.rs +++ b/core/src/skill.rs @@ -42,13 +42,6 @@ impl Cast { } pub fn resolve(self, game: &mut Game) { - if !self.skill.aoe() { - if self.skill.cast_animation() { - game.action(self, Action::Cast); - } - game.action(self, Action::Hit); - } - match self.skill { Skill::Attack => attack(self, game, Attack::Base), Skill::Block => block(self, game, Block::Base),