From 9cee9f4bfb66f7f737e79dc6293cdf9eb11430fc Mon Sep 17 00:00:00 2001 From: ntr Date: Tue, 26 Mar 2019 13:02:23 +1100 Subject: [PATCH] add skills to events --- server/WORKLOG.md | 2 ++ server/src/cryp.rs | 17 +++++++++++++++-- server/src/game.rs | 24 ++++++++++++------------ server/src/skill.rs | 38 +++++++++++++++++++------------------- 4 files changed, 48 insertions(+), 33 deletions(-) diff --git a/server/WORKLOG.md b/server/WORKLOG.md index 2acc618f..ad812a5f 100644 --- a/server/WORKLOG.md +++ b/server/WORKLOG.md @@ -22,6 +22,8 @@ ensure all skills impl Skill::Slay -> red attack with bonus somethingorother for blue / maim no healing Hatred -> damage received converted into bonus dmg +change inversion to several events + make parry semi-aggressive constants change to ownership pattern diff --git a/server/src/cryp.rs b/server/src/cryp.rs index 43df7cbf..bf0b850e 100644 --- a/server/src/cryp.rs +++ b/server/src/cryp.rs @@ -439,8 +439,10 @@ impl Cryp { } pub fn recharge(&mut self) -> Event { - if let Some(immunity) = self.immune(Skill::Recharge) { + let skill = Skill::Recharge; + if let Some(immunity) = self.immune(skill) { return Event::Immunity { + skill, immunity, }; } @@ -451,13 +453,14 @@ impl Cryp { let blue = self.blue_shield.max.saturating_sub(self.blue_shield.value); self.blue_shield.value = self.blue_shield.max; - Event::Recharge { red, blue } + Event::Recharge { red, blue, skill } } pub fn deal_green_damage(&mut self, skill: Skill, amount: u64) -> Event { if let Some(immunity) = self.immune(skill) { return Event::Immunity { immunity, + skill, }; } @@ -480,6 +483,7 @@ impl Cryp { let overhealing = modified_healing - healing; return Event::Healing { + skill, amount: healing, overhealing, }; @@ -491,6 +495,7 @@ impl Cryp { let delta = current_hp - self.hp(); return Event::Inversion { + skill, damage: delta, healing: 0, recharge: 0, @@ -503,6 +508,7 @@ impl Cryp { pub fn deal_red_damage(&mut self, skill: Skill, amount: u64) -> Event { if let Some(immunity) = self.immune(skill) { return Event::Immunity { + skill, immunity, }; } @@ -534,6 +540,7 @@ impl Cryp { let delta = current_hp - self.hp(); return Event::Damage { + skill, amount: delta, mitigation, category: Category::RedDamage, @@ -554,6 +561,7 @@ impl Cryp { damage: 0, healing, recharge, + skill, category: Category::RedDamage, }; } @@ -563,6 +571,7 @@ impl Cryp { pub fn deal_blue_damage(&mut self, skill: Skill, amount: u64) -> Event { if let Some(immunity) = self.immune(skill) { return Event::Immunity { + skill, immunity, }; } @@ -587,6 +596,7 @@ impl Cryp { let delta = current_hp - self.hp(); return Event::Damage { + skill, amount: delta, mitigation, category: Category::BlueDamage, @@ -604,6 +614,7 @@ impl Cryp { let recharge = self.blue_shield.value - current_shield; return Event::Inversion { + skill, damage: 0, healing, recharge, @@ -616,6 +627,7 @@ impl Cryp { pub fn add_effect(&mut self, skill: Skill, effect: CrypEffect) -> Event { if let Some(immunity) = self.immune(skill) { return Event::Immunity { + skill, immunity, }; } @@ -624,6 +636,7 @@ impl Cryp { let result = Event::Effect { effect: effect.effect, duration: effect.effect.duration(), + skill, }; // println!("{:?} {:?} adding effect", self.name, effect.effect); diff --git a/server/src/game.rs b/server/src/game.rs index c6e53cdc..9a8dfefa 100644 --- a/server/src/game.rs +++ b/server/src/game.rs @@ -435,7 +435,7 @@ impl Game { resolutions.reverse(); while let Some(resolution) = resolutions.pop() { // fixme for mash - self.log_resolution(cast.speed, cast.skill, &resolution); + self.log_resolution(cast.speed, &resolution); // the results go into the resolutions self.resolved.push(resolution); } @@ -490,33 +490,33 @@ impl Game { self } - fn log_resolution(&mut self, speed: u64, skill: Skill, resolution: &Resolution) -> &mut Game { + fn log_resolution(&mut self, speed: u64, resolution: &Resolution) -> &mut Game { let Resolution { source, target, event } = resolution; match event { Event::Ko => self.log.push(format!("{:} KO!", target.name)), - Event::Disable { disable } => + Event::Disable { skill, disable } => self.log.push(format!("{:} {:?} {:} disabled {:?}", source.name, skill, target.name, disable)), - Event::Immunity { immunity } => + Event::Immunity { skill, immunity } => self.log.push(format!("[{:}] {:} {:?} {:} immune {:?}", speed, source.name, skill, target.name, immunity)), - Event::TargetKo => + Event::TargetKo { skill } => self.log.push(format!("[{:}] {:} {:?} {:} - target is KO", speed, source.name, skill, target.name)), - Event::Damage { amount, mitigation, category: _ } => + Event::Damage { skill, amount, mitigation, category: _ } => self.log.push(format!("[{:}] {:} {:?} {:} {:} ({:} mitigated)", speed, source.name, skill, target.name, amount, mitigation)), - Event::Healing { amount, overhealing } => + Event::Healing { skill, amount, overhealing } => self.log.push(format!("[{:}] {:} {:?} {:} {:} ({:}OH)", speed, source.name, skill, target.name, amount, overhealing)), - Event::Inversion { healing, damage, recharge, category: _ } => { + Event::Inversion { skill, healing, damage, recharge, category: _ } => { match *healing > 0 { true => self.log.push(format!("[{:}] {:} {:?} {:} INVERTED {:} ({:} recharge)", speed, source.name, skill, target.name, healing, recharge)), @@ -525,7 +525,7 @@ impl Game { } }, - Event::Effect { effect, duration } => + Event::Effect { skill, effect, duration } => self.log.push(format!("[{:}] {:} {:?} {:} {:?} {:}T", speed, source.name, skill, target.name, effect, duration)), @@ -533,11 +533,11 @@ impl Game { self.log.push(format!("[{:}] {:?} removed {:} {:?}", speed, source.name, target.name, effect)), - Event::Recharge { red, blue } => + Event::Recharge { skill, red, blue } => self.log.push(format!("[{:}] {:} {:?} {:} {:}R {:}B", speed, source.name, skill, target.name, red, blue)), - Event::Evasion { skill: _, evasion_rating } => + Event::Evasion { skill, evasion_rating } => self.log.push(format!("[{:}] {:} {:?} {:} evaded ({:}%)", speed, source.name, skill, target.name, evasion_rating)), @@ -1150,7 +1150,7 @@ mod tests { let Resolution { source, target: _, event } = r; match source.id == x_cryp.id { true => match event { - Event::Effect { effect, duration } => { + Event::Effect { effect, duration, skill: _ } => { assert!(*effect == Effect::Ruin); assert!(*duration == 1); true diff --git a/server/src/skill.rs b/server/src/skill.rs index 9e13ba88..4ad51cdf 100644 --- a/server/src/skill.rs +++ b/server/src/skill.rs @@ -72,16 +72,16 @@ impl Resolution { #[derive(Debug,Clone,PartialEq,Serialize,Deserialize)] pub enum Event { - TargetKo, - Disable { disable: Disable }, - Immunity { immunity: Immunity }, - Damage { amount: u64, mitigation: u64, category: Category }, - Healing { amount: u64, overhealing: u64 }, - Recharge { red: u64, blue: u64 }, - Inversion { healing: u64, damage: u64, recharge: u64, category: Category }, - Effect { effect: Effect, duration: u8 }, - Removal { effect: Effect }, - Evasion { skill: Skill, evasion_rating: u64 }, + Disable { skill: Skill, disable: Disable }, + Immunity { skill: Skill, immunity: Immunity }, + Damage { skill: Skill, amount: u64, mitigation: u64, category: Category }, + Healing { skill: Skill, amount: u64, overhealing: u64 }, + Recharge { skill: Skill, red: u64, blue: u64 }, + Inversion { skill: Skill, healing: u64, damage: u64, recharge: u64, category: Category }, + Effect { skill: Skill, effect: Effect, duration: u8 }, + Removal { effect: Effect }, + Evasion { skill: Skill, evasion_rating: u64 }, + TargetKo { skill: Skill }, Ko, Incomplete, @@ -616,12 +616,12 @@ impl Skill { let mut results = vec![]; if let Some(disable) = source.disabled(*self) { - results.push(Resolution::new(source, target).event(Event::Disable { disable })); + results.push(Resolution::new(source, target).event(Event::Disable { disable, skill: *self })); return results; } if target.is_ko() { - results.push(Resolution::new(source, target).event(Event::TargetKo)); + results.push(Resolution::new(source, target).event(Event::TargetKo { skill: *self })); return results; } @@ -700,7 +700,7 @@ impl Skill { results = match target.affected(Effect::Corrupt) { true => match results.iter().any(|r| match r.event { - Event::Damage { amount: _, mitigation: _, category: _ } => true, + Event::Damage { amount: _, mitigation: _, category: _, skill: _ } => true, _ => false, }) { true => corruption(target, source, results), @@ -976,7 +976,7 @@ fn siphon_tick(source: &mut Cryp, target: &mut Cryp, mut results: Resolutions) - results.push(Resolution::new(source, target).event(siphon_damage.clone())); match siphon_damage { - Event::Damage { amount, mitigation: _, category: _, } => { + Event::Damage { amount, mitigation: _, category: _, skill: _ } => { results.push(Resolution::new(source, source).event(source.deal_green_damage(Skill::Heal, amount))); }, _ => panic!("siphon tick damage not dealt {:?}", siphon_damage), @@ -1087,7 +1087,7 @@ mod tests { let Resolution { source: _, target: _, event } = results.remove(0); match event { - Event::Damage { amount, mitigation: _, category: _ } => assert_eq!(amount, 50), + Event::Damage { amount, mitigation: _, category: _, skill: _ } => assert_eq!(amount, 50), _ => panic!("not damage"), }; } @@ -1110,7 +1110,7 @@ mod tests { let Resolution { source: _, target: _, event } = results.remove(0); match event { - Event::Damage { amount, mitigation: _, category: _ } => assert_eq!(amount, 1023), + Event::Damage { amount, mitigation: _, category: _, skill: _ } => assert_eq!(amount, 1023), _ => panic!("not damage"), }; } @@ -1141,7 +1141,7 @@ mod tests { let Resolution { source: _, target: _, event } = results.remove(0); match event { - Event::Inversion { damage: _, healing: _, recharge, category: _ } => assert_eq!(recharge, 64), + Event::Inversion { damage: _, healing: _, recharge, category: _, skill: _ } => assert_eq!(recharge, 64), _ => panic!("not inversion"), }; } @@ -1163,7 +1163,7 @@ mod tests { let Resolution { source: _, target: _, event } = results.remove(0); match event { - Event::Damage { amount, mitigation: _, category: _ } => assert_eq!(amount, 256), + Event::Damage { amount, mitigation: _, category: _, skill: _ } => assert_eq!(amount, 256), _ => panic!("not damage"), }; } @@ -1226,7 +1226,7 @@ mod tests { let Resolution { source: _, target: _, event } = results.remove(0); match event { - Event::Recharge { red, blue } => { + Event::Recharge { red, blue, skill: _ } => { assert!(red == 5); assert!(blue == 5); }