From 24767b9c86b3e251ed881ba7a9381d78de33dd71 Mon Sep 17 00:00:00 2001 From: ntr Date: Tue, 26 Mar 2019 17:40:37 +1100 Subject: [PATCH] make skill resolution a regular function --- server/src/cryp.rs | 23 +++- server/src/game.rs | 17 +-- server/src/skill.rs | 312 +++++++++++++++++++++----------------------- server/src/spec.rs | 2 - 4 files changed, 180 insertions(+), 174 deletions(-) diff --git a/server/src/cryp.rs b/server/src/cryp.rs index e28fe464..55d92b8c 100644 --- a/server/src/cryp.rs +++ b/server/src/cryp.rs @@ -11,7 +11,6 @@ use account::{Account}; use rpc::{CrypSpawnParams}; use skill::{Skill, Cooldown, Effect, Cast, Category, Immunity, Disable, Event}; use spec::{Spec}; -use game::{Log}; use vbox::Var; #[derive(Debug,Clone,Serialize,Deserialize)] @@ -61,13 +60,35 @@ impl CrypSkill { } } +#[derive(Debug,Clone,PartialEq,Serialize,Deserialize)] +pub enum EffectMeta { + TickAmount(u64), +} + #[derive(Debug,Clone,PartialEq,Serialize,Deserialize)] pub struct CrypEffect { pub effect: Effect, pub duration: u8, + pub meta: Option, pub tick: Option, } +impl CrypEffect { + pub fn new(effect: Effect) -> CrypEffect { + CrypEffect { effect, duration: effect.duration(), meta: None, tick: None } + } + + pub fn set_tick(mut self, tick: Cast) -> CrypEffect { + self.tick = Some(tick); + self + } + + pub fn set_meta(mut self, meta: EffectMeta) -> CrypEffect { + self.meta = Some(meta); + self + } +} + #[derive(Debug,Clone,Copy,PartialEq,Serialize,Deserialize)] pub enum Stat { Str, diff --git a/server/src/game.rs b/server/src/game.rs index 69bba67f..552ed08e 100644 --- a/server/src/game.rs +++ b/server/src/game.rs @@ -10,12 +10,10 @@ use failure::err_msg; use account::Account; use rpc::{GameStateParams, GameSkillParams}; use cryp::{Cryp}; -use skill::{Skill, Effect, Cast, Resolution, Event}; +use skill::{Skill, Effect, Cast, Resolution, Event, resolve}; use player::{Player}; use instance::{instance_game_finished, global_game_finished}; -pub type Log = Vec; - #[derive(Debug,Clone,Serialize,Deserialize)] pub struct Team { pub id: Uuid, @@ -417,10 +415,10 @@ impl Game { // temp vec of this round's resolving skills // because need to check cooldown use before pushing them into the complete list - let mut resolving = vec![]; + let mut casts = vec![]; while let Some(cast) = self.stack.pop() { - // println!("{:} resolving ", cast); + // println!("{:} casts ", cast); let mut resolutions = vec![]; let mut source = self.cryp_by_id(cast.source_cryp_id).unwrap().clone(); @@ -429,12 +427,11 @@ impl Game { for target_id in targets { // let mut source = game.cryp_by_id(self.source_cryp_id).unwrap(); let mut target = self.cryp_by_id(target_id).unwrap(); - resolutions = cast.skill.resolve(&mut source, target, resolutions); + resolutions = resolve(cast.skill, &mut source, target, resolutions); } resolutions.reverse(); while let Some(resolution) = resolutions.pop() { - // fixme for mash self.log_resolution(cast.speed, &resolution); // the results go into the resolutions self.resolved.push(resolution); @@ -442,16 +439,16 @@ impl Game { // the cast itself goes into this temp vec // to handle cooldowns - resolving.push(cast); + casts.push(cast); // sort the stack again in case speeds have changed self.stack_sort_speed(); }; - // println!("{:#?}", self.resolving); + // println!("{:#?}", self.casts); // handle cooldowns and statuses - self.progress_durations(&resolving); + self.progress_durations(&casts); if self.finished() { return self.finish() diff --git a/server/src/skill.rs b/server/src/skill.rs index 7ab5532e..edd50fea 100644 --- a/server/src/skill.rs +++ b/server/src/skill.rs @@ -3,7 +3,116 @@ use uuid::Uuid; use cryp::{Cryp, CrypEffect, Stat}; use vbox::{Var}; -use game::{Game}; + +pub fn resolve(skill: Skill, source: &mut Cryp, target: &mut Cryp, mut resolutions: Vec) -> Resolutions { + let mut rng = thread_rng(); + let _base: u64 = rng.gen(); + + if let Some(disable) = source.disabled(skill) { + resolutions.push(Resolution::new(source, target).event(Event::Disable { disable, skill })); + return resolutions; + } + + if target.is_ko() { + resolutions.push(Resolution::new(source, target).event(Event::TargetKo { skill })); + return resolutions; + } + + if target.affected(Effect::Reflect) { + // guard against overflow + if source.affected(Effect::Reflect) { + return resolutions; + } + resolutions.push(Resolution::new(source, target).event(Event::Reflection { skill })); + return resolve(skill, target, source, resolutions); + } + + // match self.category() == Category::Red { + // true => { + // if let Some(evasion) = target.evade(*self) { + // resolutions.push(evasion); + // return Event; + // } + // }, + // false => (), + // } + + resolutions = match skill { + Skill::Amplify => amplify(source, target, resolutions), // increase magic damage + Skill::Attack => attack(source, target, resolutions), + Skill::Banish => banish(source, target, resolutions), // TODO prevent all actions + Skill::Blast => blast(source, target, resolutions), + Skill::Block => block(source, target, resolutions), + Skill::Curse => curse(source, target, resolutions), + Skill::Decay => decay(source, target, resolutions), // dot + Skill::DecayTick => decay_tick(source, target, resolutions), // dot + Skill::Empower => empower(source, target, resolutions), // increased phys damage + Skill::Haste => haste(source, target, resolutions), // speed slow + Skill::Heal => heal(source, target, resolutions), + Skill::Hex => hex(source, target, resolutions), // todo prevent casting + Skill::Invert => invert(source, target, resolutions), // todo prevent casting + Skill::Parry => parry(source, target, resolutions), + Skill::Purge => purge(source, target, resolutions), // dispel all buffs + Skill::Purify => purify(source, target, resolutions), // dispel all debuffs + Skill::Recharge => recharge(source, target, resolutions), // target is immune to magic damage and fx + Skill::Shield => shield(source, target, resolutions), // target is immune to magic damage and fx + Skill::Silence => silence(source, target, resolutions), // target cannot cast spells + Skill::Siphon => siphon(source, target, resolutions), + Skill::SiphonTick => siphon_tick(source, target, resolutions), // hot + Skill::Slow => slow(source, target, resolutions), // speed slow + Skill::Snare => snare(source, target, resolutions), // TODO prevent physical moves + Skill::Strike => strike(source, target, resolutions), + Skill::Stun => stun(source, target, resolutions), + Skill::Throw => throw(source, target, resolutions), // no damage stun, adds vulnerable + Skill::Triage => triage(source, target, resolutions), // hot + Skill::TriageTick => triage_tick(source, target, resolutions), // hot + Skill::Clutch => clutch(source, target, resolutions), + Skill::Strangle => strangle(source, target, resolutions), + Skill::StrangleTick => strangle_tick(source, target, resolutions), + + Skill::Reflect => reflect(source, target, resolutions), + Skill::Ruin => ruin(source, target, resolutions), + Skill::Slay => unimplemented!(), + Skill::Taunt => taunt(source, target, resolutions), + + Skill::Corrupt => corrupt(source, target, resolutions), + Skill::Corruption => panic!("corruption should not be castable"), + Skill::CorruptionTick => corruption_tick(source, target, resolutions), + + // ----------------- + // Test + // ----------------- + Skill::TestTouch => touch(source, target, resolutions), + Skill::TestStun => stun(source, target, resolutions), + Skill::TestBlock => block(source, target, resolutions), + Skill::TestParry => parry(source, target, resolutions), + Skill::TestSiphon => siphon(source, target, resolutions), + }; + + // if any event dealt damage to target cryp + // hit them with corruption + resolutions = match target.affected(Effect::Corrupt) { + true => match resolutions.iter().any(|r| + match r.event { + Event::Damage { amount: _, mitigation: _, category: _, skill: _ } => true, + _ => false, + }) { + true => corruption(target, source, resolutions), + false => resolutions, + }, + false => resolutions, + }; + + // i don't think we need to check the source being ko + if target.is_ko() { + resolutions.push(Resolution::new(source, target).event(Event::Ko)); + target.effects.clear(); + } + + return resolutions; +} + + #[derive(Debug,Clone,PartialEq,Serialize,Deserialize)] pub struct Cast { @@ -447,7 +556,7 @@ impl Skill { Skill::Throw => Some(1), // no damage stun, adds vulnerable Skill::Blast => None, Skill::Amplify => Some(1), - Skill::Invert => Some(1), + Skill::Invert => Some(2), Skill::Decay => None, // dot Skill::DecayTick => None, Skill::Siphon => Some(1), @@ -459,7 +568,7 @@ impl Skill { Skill::Purify => None, Skill::Purge => None, Skill::Banish => Some(1), - Skill::Hex => None, + Skill::Hex => Some(1), Skill::Haste => None, Skill::Slow => None, Skill::Reflect => Some(2), @@ -610,114 +719,6 @@ impl Skill { } } - pub fn resolve(&self, source: &mut Cryp, target: &mut Cryp, mut resolutions: Vec) -> Resolutions { - let mut rng = thread_rng(); - let _base: u64 = rng.gen(); - - if let Some(disable) = source.disabled(*self) { - resolutions.push(Resolution::new(source, target).event(Event::Disable { disable, skill: *self })); - return resolutions; - } - - if target.is_ko() { - resolutions.push(Resolution::new(source, target).event(Event::TargetKo { skill: *self })); - return resolutions; - } - - if target.affected(Effect::Reflect) { - // guard against overflow - if source.affected(Effect::Reflect) { - return resolutions; - } - resolutions.push(Resolution::new(source, target).event(Event::Reflection { skill: *self })); - return self.resolve(target, source, resolutions); - } - - // match self.category() == Category::Red { - // true => { - // if let Some(evasion) = target.evade(*self) { - // resolutions.push(evasion); - // return Event; - // } - // }, - // false => (), - // } - - resolutions = match self { - Skill::Amplify => amplify(source, target, resolutions), // increase magic damage - Skill::Attack => attack(source, target, resolutions), - Skill::Banish => banish(source, target, resolutions), // TODO prevent all actions - Skill::Blast => blast(source, target, resolutions), - Skill::Block => block(source, target, resolutions), - Skill::Curse => curse(source, target, resolutions), - Skill::Decay => decay(source, target, resolutions), // dot - Skill::DecayTick => decay_tick(source, target, resolutions), // dot - Skill::Empower => empower(source, target, resolutions), // increased phys damage - Skill::Haste => haste(source, target, resolutions), // speed slow - Skill::Heal => heal(source, target, resolutions), - Skill::Hex => hex(source, target, resolutions), // todo prevent casting - Skill::Invert => invert(source, target, resolutions), // todo prevent casting - Skill::Parry => parry(source, target, resolutions), - Skill::Purge => purge(source, target, resolutions), // dispel all buffs - Skill::Purify => purify(source, target, resolutions), // dispel all debuffs - Skill::Recharge => recharge(source, target, resolutions), // target is immune to magic damage and fx - Skill::Shield => shield(source, target, resolutions), // target is immune to magic damage and fx - Skill::Silence => silence(source, target, resolutions), // target cannot cast spells - Skill::Siphon => siphon(source, target, resolutions), - Skill::SiphonTick => siphon_tick(source, target, resolutions), // hot - Skill::Slow => slow(source, target, resolutions), // speed slow - Skill::Snare => snare(source, target, resolutions), // TODO prevent physical moves - Skill::Strike => strike(source, target, resolutions), - Skill::Stun => stun(source, target, resolutions), - Skill::Throw => throw(source, target, resolutions), // no damage stun, adds vulnerable - Skill::Triage => triage(source, target, resolutions), // hot - Skill::TriageTick => triage_tick(source, target, resolutions), // hot - Skill::Clutch => clutch(source, target, resolutions), - Skill::Strangle => strangle(source, target, resolutions), - Skill::StrangleTick => strangle_tick(source, target, resolutions), - - Skill::Reflect => reflect(source, target, resolutions), - Skill::Ruin => ruin(source, target, resolutions), - Skill::Slay => unimplemented!(), - Skill::Taunt => taunt(source, target, resolutions), - - Skill::Corrupt => corrupt(source, target, resolutions), - Skill::Corruption => panic!("corruption should not be castable"), - Skill::CorruptionTick => corruption_tick(source, target, resolutions), - - // ----------------- - // Test - // ----------------- - Skill::TestTouch => touch(source, target, resolutions), - Skill::TestStun => stun(source, target, resolutions), - Skill::TestBlock => block(source, target, resolutions), - Skill::TestParry => parry(source, target, resolutions), - Skill::TestSiphon => siphon(source, target, resolutions), - }; - - // if any event dealt damage to target cryp - // hit them with corruption - resolutions = match target.affected(Effect::Corrupt) { - true => match resolutions.iter().any(|r| - match r.event { - Event::Damage { amount: _, mitigation: _, category: _, skill: _ } => true, - _ => false, - }) { - true => corruption(target, source, resolutions), - false => resolutions, - }, - false => resolutions, - }; - - // i don't think we need to check the source being ko - if target.is_ko() { - resolutions.push(Resolution::new(source, target).event(Event::Ko)); - target.effects.clear(); - } - - return resolutions; - } - pub fn self_targeting(&self) -> bool { match self { Skill::Block => true, @@ -773,26 +774,26 @@ fn strike(source: &mut Cryp, target: &mut Cryp, mut results: Resolutions) -> Res fn stun(source: &mut Cryp, target: &mut Cryp, mut results: Resolutions) -> Resolutions { - let effect = CrypEffect { effect: Effect::Stun, duration: Effect::Stun.duration(), tick: None }; + let effect = CrypEffect::new(Effect::Stun); results.push(Resolution::new(source, target).event(target.add_effect(Skill::Stun, effect))); return results; } fn clutch(source: &mut Cryp, target: &mut Cryp, mut results: Resolutions) -> Resolutions { - let effect = CrypEffect { effect: Effect::Clutch, duration: Effect::Clutch.duration(), tick: None }; + let effect = CrypEffect::new(Effect::Clutch); results.push(Resolution::new(source, target).event(target.add_effect(Skill::Clutch, effect))); return results; } fn taunt(source: &mut Cryp, target: &mut Cryp, mut results: Resolutions) -> Resolutions { - let effect = CrypEffect { effect: Effect::Taunt, duration: Effect::Taunt.duration(), tick: None }; + let effect = CrypEffect::new(Effect::Taunt); results.push(Resolution::new(source, target).event(target.add_effect(Skill::Taunt, effect))); return results; } fn throw(source: &mut Cryp, target: &mut Cryp, mut results: Resolutions) -> Resolutions { - let stun = CrypEffect { effect: Effect::Stun, duration: Effect::Stun.duration(), tick: None }; - let vulnerable = CrypEffect { effect: Effect::Vulnerable, duration: Effect::Vulnerable.duration(), tick: None }; + let stun = CrypEffect::new(Effect::Stun); + let vulnerable = CrypEffect::new(Effect::Vulnerable); results.push(Resolution::new(source, target).event(target.add_effect(Skill::Throw, stun))); results.push(Resolution::new(source, target).event(target.add_effect(Skill::Throw, vulnerable))); @@ -801,12 +802,10 @@ fn throw(source: &mut Cryp, target: &mut Cryp, mut results: Resolutions) -> Reso } fn strangle(source: &mut Cryp, target: &mut Cryp, mut results: Resolutions) -> Resolutions { - let target_stun = CrypEffect { - effect: Effect::Strangle, - duration: Effect::Strangle.duration(), - tick: Some(Cast::new_tick(source, target, Skill::StrangleTick)) - }; - let attacker_immunity = CrypEffect { effect: Effect::Strangling, duration: Effect::Strangling.duration(), tick: None }; + let target_stun = CrypEffect::new(Effect::Strangle) + .set_tick(Cast::new_tick(source, target, Skill::StrangleTick)); + + let attacker_immunity = CrypEffect::new(Effect::Strangling); results.push(Resolution::new(source, target).event(target.add_effect(Skill::Strangle, target_stun))); results.push(Resolution::new(source, source).event(source.add_effect(Skill::Strangle, attacker_immunity))); @@ -833,26 +832,25 @@ fn strangle_tick(source: &mut Cryp, target: &mut Cryp, mut results: Resolutions) } fn block(source: &mut Cryp, target: &mut Cryp, mut results: Resolutions) -> Resolutions { - let block = CrypEffect { effect: Effect::Block, duration: Effect::Block.duration(), tick: None }; + let block = CrypEffect::new(Effect::Block); results.push(Resolution::new(source, target).event(target.add_effect(Skill::Block, block))); return results; } fn parry(source: &mut Cryp, target: &mut Cryp, mut results: Resolutions) -> Resolutions { - let effect = CrypEffect { effect: Effect::Parry, duration: Effect::Parry.duration(), tick: None }; + let effect = CrypEffect::new(Effect::Parry); results.push(Resolution::new(source, target).event(target.add_effect(Skill::Parry, effect))); return results; } - fn snare(source: &mut Cryp, target: &mut Cryp, mut results: Resolutions) -> Resolutions { - let snare = CrypEffect { effect: Effect::Snare, duration: Effect::Snare.duration(), tick: None }; + let snare = CrypEffect::new(Effect::Snare); results.push(Resolution::new(source, target).event(target.add_effect(Skill::Snare, snare))); return results; } fn empower(source: &mut Cryp, target: &mut Cryp, mut results: Resolutions) -> Resolutions { - let empower = CrypEffect { effect: Effect::Empower, duration: Effect::Empower.duration(), tick: None }; + let empower = CrypEffect::new(Effect::Empower); results.push(Resolution::new(source, target).event(target.add_effect(Skill::Empower, empower))); return results; } @@ -866,11 +864,9 @@ fn heal(source: &mut Cryp, target: &mut Cryp, mut results: Resolutions) -> Resol } fn triage(source: &mut Cryp, target: &mut Cryp, mut results: Resolutions) -> Resolutions { - let effect = CrypEffect { - effect: Effect::Triage, - duration: Effect::Triage.duration(), - tick: Some(Cast::new_tick(source, target, Skill::TriageTick)), - }; + let effect = CrypEffect::new(Effect::Triage) + .set_tick(Cast::new_tick(source, target, Skill::TriageTick)); + results.push(Resolution::new(source, target).event(target.add_effect(Skill::Triage, effect))); return triage_tick(source, target, results); } @@ -892,29 +888,27 @@ fn blast(source: &mut Cryp, target: &mut Cryp, mut results: Resolutions) -> Reso } fn amplify(source: &mut Cryp, target: &mut Cryp, mut results: Resolutions) -> Resolutions { - let amplify = CrypEffect { effect: Effect::Amplify, duration: Effect::Amplify.duration(), tick: None }; + let amplify = CrypEffect::new(Effect::Amplify); results.push(Resolution::new(source, target).event(target.add_effect(Skill::Amplify, amplify))); return results;; } fn haste(source: &mut Cryp, target: &mut Cryp, mut results: Resolutions) -> Resolutions { - let effect = CrypEffect { effect: Effect::Haste, duration: Effect::Haste.duration(), tick: None }; + let effect = CrypEffect::new(Effect::Haste); results.push(Resolution::new(source, target).event(target.add_effect(Skill::Haste, effect))); return results;; } fn slow(source: &mut Cryp, target: &mut Cryp, mut results: Resolutions) -> Resolutions { - let effect = CrypEffect { effect: Effect::Slow, duration: Effect::Slow.duration(), tick: None }; + let effect = CrypEffect::new(Effect::Slow); results.push(Resolution::new(source, target).event(target.add_effect(Skill::Slow, effect))); return results;; } fn decay(source: &mut Cryp, target: &mut Cryp, mut results: Resolutions) -> Resolutions { - let decay = CrypEffect { - effect: Effect::Decay, - duration: Effect::Decay.duration(), - tick: Some(Cast::new_tick(source, target, Skill::DecayTick)), - }; + let decay = CrypEffect::new(Effect::Decay) + .set_tick(Cast::new_tick(source, target, Skill::DecayTick)); + results.push(Resolution::new(source, target).event(target.add_effect(Skill::Decay, decay))); return decay_tick(source, target, results); } @@ -930,17 +924,15 @@ fn decay_tick(source: &mut Cryp, target: &mut Cryp, mut results: Resolutions) -> // corrupt is the buff effect // when attacked it runs corruption and applies a debuff fn corrupt(source: &mut Cryp, target: &mut Cryp, mut results: Resolutions) -> Resolutions { - let effect = CrypEffect { effect: Effect::Corrupt, duration: Effect::Corrupt.duration(), tick: None }; + let effect = CrypEffect::new(Effect::Corrupt); results.push(Resolution::new(source, target).event(target.add_effect(Skill::Corrupt, effect))); return results;; } fn corruption(source: &mut Cryp, target: &mut Cryp, mut results: Resolutions) -> Resolutions { - let effect = CrypEffect { - effect: Effect::Corruption, - duration: Effect::Corruption.duration(), - tick: Some(Cast::new_tick(source, target, Skill::CorruptionTick)), - }; + let effect = CrypEffect::new(Effect::Corruption) + .set_tick(Cast::new_tick(source, target, Skill::CorruptionTick)); + results.push(Resolution::new(source, target).event(target.add_effect(Skill::Corruption, effect))); return corruption_tick(source, target, results); } @@ -954,31 +946,31 @@ fn corruption_tick(source: &mut Cryp, target: &mut Cryp, mut results: Resolution } fn ruin(source: &mut Cryp, target: &mut Cryp, mut results: Resolutions) -> Resolutions { - let effect = CrypEffect { effect: Effect::Ruin, duration: Effect::Ruin.duration(), tick: None }; + let effect = CrypEffect::new(Effect::Ruin); results.push(Resolution::new(source, target).event(target.add_effect(Skill::Ruin, effect))); return results;; } fn hex(source: &mut Cryp, target: &mut Cryp, mut results: Resolutions) -> Resolutions { - let hex = CrypEffect { effect: Effect::Hex, duration: Effect::Hex.duration(), tick: None }; + let hex = CrypEffect::new(Effect::Hex); results.push(Resolution::new(source, target).event(target.add_effect(Skill::Hex, hex))); return results;; } fn curse(source: &mut Cryp, target: &mut Cryp, mut results: Resolutions) -> Resolutions { - let curse = CrypEffect { effect: Effect::Curse, duration: Effect::Curse.duration(), tick: None }; + let curse = CrypEffect::new(Effect::Curse); results.push(Resolution::new(source, target).event(target.add_effect(Skill::Curse, curse))); return results;; } fn invert(source: &mut Cryp, target: &mut Cryp, mut results: Resolutions) -> Resolutions { - let effect = CrypEffect { effect: Effect::Invert, duration: Effect::Invert.duration(), tick: None }; + let effect = CrypEffect::new(Effect::Invert); results.push(Resolution::new(source, target).event(target.add_effect(Skill::Invert, effect))); return results;; } fn reflect(source: &mut Cryp, target: &mut Cryp, mut results: Resolutions) -> Resolutions { - let effect = CrypEffect { effect: Effect::Reflect, duration: Effect::Reflect.duration(), tick: None }; + let effect = CrypEffect::new(Effect::Reflect); results.push(Resolution::new(source, target).event(target.add_effect(Skill::Reflect, effect))); return results;; } @@ -989,11 +981,9 @@ fn recharge(source: &mut Cryp, target: &mut Cryp, mut results: Resolutions) -> R } fn siphon(source: &mut Cryp, target: &mut Cryp, mut results: Resolutions) -> Resolutions { - let siphon = CrypEffect { - effect: Effect::Siphon, - duration: Effect::Siphon.duration(), - tick: Some(Cast::new_tick(source, target, Skill::SiphonTick)), - }; + let siphon = CrypEffect::new(Effect::Siphon) + .set_tick(Cast::new_tick(source, target, Skill::SiphonTick)); + results.push(Resolution::new(source, target).event(target.add_effect(Skill::Siphon, siphon))); return siphon_tick(source, target, results); } @@ -1020,13 +1010,13 @@ fn siphon_tick(source: &mut Cryp, target: &mut Cryp, mut results: Resolutions) - } fn shield(source: &mut Cryp, target: &mut Cryp, mut results: Resolutions) -> Resolutions { - let shield = CrypEffect { effect: Effect::Shield, duration: Effect::Shield.duration(), tick: None }; + let shield = CrypEffect::new(Effect::Shield); results.push(Resolution::new(source, target).event(target.add_effect(Skill::Shield, shield))); return results; } fn silence(source: &mut Cryp, target: &mut Cryp, mut results: Resolutions) -> Resolutions { - let silence = CrypEffect { effect: Effect::Silence, duration: Effect::Silence.duration(), tick: None }; + let silence = CrypEffect::new(Effect::Silence); results.push(Resolution::new(source, target).event(target.add_effect(Skill::Silence, silence))); return results; } @@ -1054,7 +1044,7 @@ fn purify(source: &mut Cryp, target: &mut Cryp, mut results: Resolutions) -> Res } fn banish(source: &mut Cryp, target: &mut Cryp, mut results: Resolutions) -> Resolutions { - let banish = CrypEffect { effect: Effect::Banish, duration: Effect::Banish.duration(), tick: None }; + let banish = CrypEffect::new(Effect::Banish); results.push(Resolution::new(source, target).event(target.add_effect(Skill::Banish, banish))); return results; } @@ -1194,7 +1184,7 @@ mod tests { assert!(y.affected(Effect::Reflect)); let mut results = vec![]; - results = Skill::Attack.resolve(&mut x, &mut y, results); + results = resolve(Skill::Attack, &mut x, &mut y, results); assert!(x.hp() == 768); @@ -1222,7 +1212,7 @@ mod tests { corrupt(&mut y.clone(), &mut y, vec![]); assert!(y.affected(Effect::Corrupt)); - Skill::Attack.resolve(&mut x, &mut y, vec![]); + resolve(Skill::Attack, &mut x, &mut y, vec![]); assert!(x.affected(Effect::Corruption)); } diff --git a/server/src/spec.rs b/server/src/spec.rs index 813c57db..538cc856 100644 --- a/server/src/spec.rs +++ b/server/src/spec.rs @@ -1,5 +1,3 @@ -use rand::prelude::*; - use cryp::{Stat, Colours}; #[derive(Debug,Copy,Clone,Serialize,Deserialize,PartialEq,PartialOrd,Ord,Eq)]