diff --git a/server/src/cryp.rs b/server/src/cryp.rs index d9db26dc..f9957733 100644 --- a/server/src/cryp.rs +++ b/server/src/cryp.rs @@ -12,6 +12,37 @@ use rpc::{CrypSpawnParams}; use skill::{Skill, Cooldown, Effect, Cast, Category, Immunity, Disable, ResolutionResult}; use spec::{Spec}; use game::{Log}; +use vbox::Var; + +#[derive(Debug,Clone,Serialize,Deserialize)] +pub struct Colours { + pub red: u8, + pub green: u8, + pub blue: u8, +} + +impl Colours { + pub fn new() -> Colours { + Colours { red: 0, green: 0, blue: 0 } + } + + pub fn from_cryp(cryp: &Cryp) -> Colours { + let mut count = Colours::new(); + + for spec in cryp.specs.iter() { + let v = Var::from(*spec); + v.colours(&mut count); + } + + for cs in cryp.skills.iter() { + let v = Var::from(cs.skill); + v.colours(&mut count); + } + + count + } +} + #[derive(Debug,Clone,Copy,PartialEq,Serialize,Deserialize)] pub struct CrypSkill { @@ -107,7 +138,6 @@ impl CrypStat { pub struct CrypRecover { pub id: Uuid, pub account: Uuid, - pub xp: u64, pub name: String, } @@ -125,6 +155,7 @@ pub struct Cryp { pub skills: Vec, pub effects: Vec, pub specs: Vec, + pub colours: Colours, pub name: String, pub ko_logged: bool, } @@ -145,6 +176,7 @@ impl Cryp { skills: vec![], effects: vec![], specs: vec![], + colours: Colours::new(), name: String::new(), ko_logged: false, }; @@ -162,11 +194,13 @@ impl Cryp { pub fn learn(mut self, s: Skill) -> Cryp { self.skills.push(CrypSkill::new(s)); + self.colours = Colours::from_cryp(&self); self } pub fn learn_mut(&mut self, s: Skill) -> &mut Cryp { self.skills.push(CrypSkill::new(s)); + self.colours = Colours::from_cryp(&self); self } @@ -197,6 +231,10 @@ impl Cryp { fn recalculate_stats(&mut self) -> &mut Cryp { self.specs.sort_unstable(); + + // recalculate the colours for the spec bonuses + self.colours = Colours::from_cryp(&self); + self.red_damage.recalculate(&self.specs); self.red_shield.recalculate(&self.specs); self.blue_damage.recalculate(&self.specs); @@ -612,12 +650,31 @@ mod tests { use cryp::*; // use skill::*; - #[test] - fn create_cryp_test() { + #[test] + fn create_cryp_test() { let cryp = Cryp::new() .named(&"hatchling".to_string()); assert_eq!(cryp.name, "hatchling".to_string()); return; } + + #[test] + fn cryp_colours_test() { + let mut cryp = Cryp::new() + .named(&"redboi".to_string()); + + cryp.learn_mut(Skill::Strike); + cryp.spec_add(Spec::LifeI).unwrap(); + cryp.spec_add(Spec::RedDamageI).unwrap(); + cryp.spec_add(Spec::RedDamageI).unwrap(); + cryp.spec_add(Spec::BlueShieldI).unwrap(); + + assert_eq!(cryp.colours.red, 6); + assert_eq!(cryp.colours.green, 2); + assert_eq!(cryp.colours.blue, 2); + + return; + } + } diff --git a/server/src/vbox.rs b/server/src/vbox.rs index f10f7d85..99fc5bcd 100644 --- a/server/src/vbox.rs +++ b/server/src/vbox.rs @@ -16,6 +16,7 @@ use rpc::{VboxAcceptParams, VboxDiscardParams, VboxCombineParams, VboxApplyParam use skill::{Skill}; use spec::{Spec}; use player::{Player, player_get, player_update}; +use cryp::{Colours}; #[derive(Debug,Copy,Clone,Serialize,Deserialize,PartialEq,PartialOrd,Ord,Eq)] pub enum Var { @@ -51,6 +52,7 @@ pub enum Var { Banish, Blast, Curse, + Decay, Empower, Haste, Heal, @@ -73,6 +75,13 @@ pub enum Var { Throw, Toxic, Triage, + + + TestTouch, + TestStun, + TestBlock, + TestParry, + TestSiphon, } enum VarEffect { @@ -81,6 +90,20 @@ enum VarEffect { } impl Var { + pub fn colours(&self, count: &mut Colours) { + let combos = get_combos(); + let combo = combos.iter().find(|c| c.var == *self); + match combo { + Some(c) => c.units.iter().for_each(|unit| match unit { + Var::Red => count.red += 1, + Var::Blue => count.blue += 1, + Var::Green => count.green += 1, + _ => (), + }), + None => (), + } + } + fn cost(&self) -> u16 { match self { Var::Red => 1, @@ -193,6 +216,13 @@ impl From for Var { Skill::Stun => Var::Stun, Skill::Throw => Var::Throw, Skill::Triage => Var::Triage, + Skill::Decay => Var::Decay, + + Skill::TestTouch => Var::TestTouch, + Skill::TestStun => Var::TestStun, + Skill::TestBlock => Var::TestBlock, + Skill::TestParry => Var::TestParry, + Skill::TestSiphon => Var::TestSiphon, _ => panic!("{:?} not implemented as a var", skill), } } @@ -218,6 +248,7 @@ impl From for Var { } } + struct Combo { var: Var, units: Vec, @@ -228,9 +259,9 @@ fn get_combos() -> Vec { Combo { units: vec![Var::Attack, Var::Red, Var::Red], var: Var::Strike }, Combo { units: vec![Var::Attack, Var::Green, Var::Green], var: Var::Heal }, Combo { units: vec![Var::Attack, Var::Blue, Var::Blue], var: Var::Blast }, - Combo { units: vec![Var::Attack, Var::Red, Var::Green], var: Var::Strike }, - Combo { units: vec![Var::Attack, Var::Green, Var::Blue], var: Var::Heal }, - Combo { units: vec![Var::Attack, Var::Red, Var::Blue], var: Var::Blast }, + // Combo { units: vec![Var::Attack, Var::Red, Var::Green], var: Var::Strike }, + Combo { units: vec![Var::Attack, Var::Green, Var::Blue], var: Var::Decay }, + // Combo { units: vec![Var::Attack, Var::Red, Var::Blue], var: Var::Blast }, Combo { units: vec![Var::Block, Var::Red, Var::Red], var: Var::Parry }, Combo { units: vec![Var::Block, Var::Green, Var::Green], var: Var::Reflect }, @@ -547,4 +578,13 @@ mod tests { assert_eq!(vbox.bits, 22); } + #[test] + fn colours_count_test() { + let strike = Var::Strike; + + let mut count = Colours::new(); + strike.colours(&mut count); + assert_eq!(count.red, 2); + } + } \ No newline at end of file