From 1fa645cbfde30541709afd179e2944699f940054 Mon Sep 17 00:00:00 2001 From: ntr Date: Sat, 8 Jun 2019 18:07:25 +1000 Subject: [PATCH] move into own mod --- server/src/construct.rs | 27 ++++- server/src/game.rs | 3 +- server/src/item.rs | 3 +- server/src/main.rs | 1 + server/src/player.rs | 2 +- server/src/skill.rs | 217 +--------------------------------------- 6 files changed, 35 insertions(+), 218 deletions(-) diff --git a/server/src/construct.rs b/server/src/construct.rs index 5b7f4471..873debac 100644 --- a/server/src/construct.rs +++ b/server/src/construct.rs @@ -9,7 +9,8 @@ use failure::err_msg; use account::{Account}; use rpc::{ConstructSpawnParams}; -use skill::{Skill, Cooldown, Effect, Cast, Colour, Immunity, Disable, Event}; +use skill::{Skill, Cast, Immunity, Disable, Event}; +use effect::{Cooldown, Effect, Colour}; use spec::{Spec}; use item::{Item}; @@ -975,6 +976,30 @@ mod tests { return; } + #[test] + fn construct_colour_calc_test() { + let mut construct = Construct::new() + .named(&"player player".to_string()); + + construct.spec_add(Spec::PowerRRI).unwrap(); + construct.spec_add(Spec::PowerGGI).unwrap(); + construct.spec_add(Spec::PowerBBI).unwrap(); + + let colours = Colours::from_construct(&construct); + assert!(colours.red == 2); + assert!(colours.blue == 2); + assert!(colours.green == 2); + + let construct = construct + .learn(Skill::StrikeI) + .learn(Skill::BlastIII); + + let colours = Colours::from_construct(&construct); + assert!(colours.red == 4); + assert!(colours.blue == 20); + assert!(colours.green == 2); + } + #[test] fn construct_player_modifiers_spec_bonus_test() { let mut construct = Construct::new() diff --git a/server/src/game.rs b/server/src/game.rs index c01bbfde..0ff64881 100644 --- a/server/src/game.rs +++ b/server/src/game.rs @@ -14,7 +14,8 @@ use failure::err_msg; use account::Account; use rpc::{GameStateParams, GameSkillParams}; use construct::{Construct}; -use skill::{Skill, Effect, Cast, Resolution, Event, resolution_steps}; +use skill::{Skill, Cast, Resolution, Event, resolution_steps}; +use effect::{Effect}; use player::{Player}; use instance::{TimeControl, instance_game_finished}; diff --git a/server/src/item.rs b/server/src/item.rs index cbf1582e..6473b41b 100644 --- a/server/src/item.rs +++ b/server/src/item.rs @@ -1,6 +1,7 @@ -use skill::{Skill, Colour}; +use skill::{Skill}; use spec::{Spec, SpecValues}; use construct::{Colours}; +use effect::{Colour}; #[derive(Debug,Copy,Clone,Serialize,Deserialize,PartialEq,PartialOrd,Ord,Eq)] pub enum Item { diff --git a/server/src/main.rs b/server/src/main.rs index 239139e3..3daa167b 100644 --- a/server/src/main.rs +++ b/server/src/main.rs @@ -28,6 +28,7 @@ mod net; mod player; mod rpc; mod skill; +mod effect; mod spec; mod util; mod vbox; diff --git a/server/src/player.rs b/server/src/player.rs index aaca7799..e44c7cbd 100644 --- a/server/src/player.rs +++ b/server/src/player.rs @@ -10,7 +10,7 @@ use account::Account; use construct::{Construct, Colours}; use vbox::{Vbox}; use item::{Item, ItemEffect}; -use skill::{Effect}; +use effect::{Effect}; const DISCARD_COST: u16 = 5; diff --git a/server/src/skill.rs b/server/src/skill.rs index 2c243f05..87e9058b 100644 --- a/server/src/skill.rs +++ b/server/src/skill.rs @@ -2,10 +2,11 @@ use rand::{thread_rng, Rng}; use uuid::Uuid; use util::{IntPct}; -use construct::{Construct, ConstructEffect, EffectMeta, Stat}; +use construct::{Construct, ConstructEffect, EffectMeta}; use item::{Item}; use game::{Game}; +use effect::{Effect, Colour, Cooldown}; pub fn resolution_steps(cast: &Cast, game: &mut Game) -> Resolutions { let mut resolutions = vec![]; @@ -464,218 +465,6 @@ pub enum Event { } type Resolutions = Vec; -pub type Cooldown = Option; - -#[derive(Debug,Clone,Copy,PartialEq,Serialize,Deserialize)] -pub enum Effect { - Amplify, - Banish, - Block, - Buff, - Clutch, - Curse, - Haste, - Hex, - Impurity, - Invert, - Parry, - Purge, - Reflect, - Slow, - Snare, - Stun, - Taunt, - Vulnerable, - Silence, - Wither, // Reduce green dmg (healing) taken - - // corrupt is the buff that applies - // corruption the dmg debuff - Corrupt, - Corruption, - - // hostility is the buff - // hatred is the increased damage - Hostility, - Hatred, - - // magic immunity - Scatter, - - // effects over time - Triage, - Decay, - Regen, - Siphon, - - // Airborne, - // Boost - // Bleed, - // Blind, - // Deadly, - // Enslave, - // Fury, - // Injured, - // Leech, - // Mesmerise, - // Untouchable, - // SpeedSiphon, - // SpeedIncrease, - - Ko, -} - -impl Effect { - pub fn immune(&self, skill: Skill) -> bool { - match self { - Effect::Parry => match skill { - Skill::Attack => true, - Skill::Stun => true, - _ => skill.colours().contains(&Colour::Red) - }, - Effect::Banish => true, - Effect::Clutch => [ - Skill::Stun, - Skill::HexI, - Skill::HexII, - Skill::HexIII, - Skill::SilenceI, - Skill::SilenceII, - Skill::SilenceIII, - Skill::RuinI, - Skill::RuinII, - Skill::RuinIII, - Skill::SnareI, - Skill::SnareII, - Skill::SnareIII - ].contains(&skill), - _ => false, - } - } - - pub fn disables_skill(&self, skill: Skill) -> bool { - if skill.is_tick() { - return false; - } - - match self { - Effect::Stun => true, - Effect::Hex => true, - Effect::Banish => true, - Effect::Silence => skill.colours().contains(&Colour::Blue), - Effect::Snare => skill.colours().contains(&Colour::Red), - Effect::Purge => skill.colours().contains(&Colour::Green), - Effect::Ko => skill.ko_castable(), - _ => false, - } - } - - pub fn modifications(&self) -> Vec { - match self { - Effect::Vulnerable => vec![Stat::RedDamageTaken], - Effect::Block => vec![Stat::RedDamageTaken], - Effect::Buff => vec![Stat::RedPower, Stat::Speed], - - Effect::Hatred => vec![Stat::RedPower, Stat::BluePower], - - Effect::Amplify => vec![Stat::RedPower, Stat::BluePower], - Effect::Curse => vec![Stat::BlueDamageTaken], - - Effect::Impurity => vec![Stat::GreenPower], - Effect::Wither => vec![Stat::GreenDamageTaken], - - Effect::Haste => vec![Stat::Speed], - Effect::Slow => vec![Stat::Speed], - - Effect::Scatter => vec![Stat::BlueDamageTaken, Stat::GreenDamageTaken, Stat::RedDamageTaken], - - _ => vec![], - } - } - - pub fn apply(&self, value: u64, meta: Option) -> u64 { - match self { - Effect::Amplify | - Effect::Vulnerable | - Effect::Block | - Effect::Buff | - Effect::Curse | - Effect::Haste | - Effect::Slow | - Effect::Impurity | - Effect::Wither => value.pct(match meta { - Some(EffectMeta::Multiplier(d)) => d, - _ => 100, - }), - - Effect::Scatter => value >> 1, - - Effect::Hatred => value + match meta { - Some(EffectMeta::AddedDamage(d)) => d, - _ => panic!("hatred meta not damage"), - }, - - _ => { - info!("{:?} does not have a mod effect", self); - return value; - }, - } - } - - fn colour(&self) -> Option { - match self { - // physical - Effect::Stun => Some(Colour::Red), - Effect::Block => Some(Colour::Green), - Effect::Buff => Some(Colour::Green), - Effect::Parry => Some(Colour::Green), - Effect::Vulnerable => Some(Colour::Red), - Effect::Snare => Some(Colour::Red), - Effect::Clutch => Some(Colour::Green), - Effect::Taunt => Some(Colour::Green), - - // magic - Effect::Hex => Some(Colour::Blue), - Effect::Curse => Some(Colour::Blue), - Effect::Banish => None, - // Effect::Banish => rng.gen_bool(0.5), - - Effect::Slow => Some(Colour::Blue), - Effect::Haste => Some(Colour::Green), - Effect::Hatred => Some(Colour::Green), - Effect::Reflect => Some(Colour::Green), - Effect::Amplify => Some(Colour::Green), - Effect::Silence => Some(Colour::Blue), - Effect::Wither => Some(Colour::Blue), - Effect::Purge => Some(Colour::Blue), - - Effect::Corrupt => Some(Colour::Green), - Effect::Corruption => Some(Colour::Blue), - - Effect::Hostility => Some(Colour::Green), - - // magic - Effect::Impurity => Some(Colour::Green), - Effect::Scatter => Some(Colour::Green), - Effect::Invert => Some(Colour::Green), - - // effects over time - Effect::Triage => Some(Colour::Green), - Effect::Decay => Some(Colour::Blue), - Effect::Regen => Some(Colour::Green), - Effect::Siphon => Some(Colour::Blue), - - Effect::Ko => None, - } - } -} - -#[derive(Debug,Clone,Copy,PartialEq,Serialize,Deserialize)] -pub enum Colour { - Red, - Blue, - Green, -} #[derive(Debug,Clone,Copy,PartialEq,Serialize,Deserialize)] pub enum Skill { @@ -1395,7 +1184,7 @@ impl Skill { return components; } - fn colours(&self) -> Vec { + pub fn colours(&self) -> Vec { let mut components = self.components(); let colour_items = [Item::Red, Item::Green, Item::Blue]; components.dedup();