From 5ea6b911ad4fd30739e9af39850716cd34016e3f Mon Sep 17 00:00:00 2001 From: ntr Date: Wed, 6 Mar 2019 18:08:39 +1100 Subject: [PATCH] vbox specs --- client/src/scenes/elements/item.js | 10 +- client/src/scenes/header.js | 2 +- server/src/cryp.rs | 100 ++++--------------- server/src/spec.rs | 59 ++++-------- server/src/vbox.rs | 150 +++++++++++++++++++++-------- 5 files changed, 155 insertions(+), 166 deletions(-) diff --git a/client/src/scenes/elements/item.js b/client/src/scenes/elements/item.js index 4a4abee1..54d6b512 100644 --- a/client/src/scenes/elements/item.js +++ b/client/src/scenes/elements/item.js @@ -8,9 +8,13 @@ const { function FindColour(item) { // Future add skills and use a constants lookup file ?? switch (item) { - case 'Green': return 0x61B329; - case 'Red': return 0xCC3333; - case 'Blue': return 0x6633FF; + case 'Green': return 0x396E26; + case 'Red': return 0x622433; + case 'Blue': return 0x223158; + // case 'Green': return 0x043003; + // case 'Red': return 0x5C0202; + // case 'Blue': return 0x040345; + default: return 0x222222; } } diff --git a/client/src/scenes/header.js b/client/src/scenes/header.js index bccae709..9923a04d 100644 --- a/client/src/scenes/header.js +++ b/client/src/scenes/header.js @@ -20,7 +20,7 @@ class Header extends Phaser.Scene { } create() { - this.add.text(0, 0, 'cryps.gg', TEXT.HEADER); + this.add.text(0, 0, 'CRYPS.GG', TEXT.HEADER); } } diff --git a/server/src/cryp.rs b/server/src/cryp.rs index abd97bbc..56fb7314 100644 --- a/server/src/cryp.rs +++ b/server/src/cryp.rs @@ -10,7 +10,7 @@ use failure::err_msg; use account::{Account}; use rpc::{CrypSpawnParams, CrypLearnParams, CrypForgetParams, CrypUnspecParams}; use skill::{Skill, Cooldown, Effect, Cast, Category, Immunity, Disable, ResolutionResult}; -use spec::{Spec, SpecLevel}; +use spec::{Spec}; use game::{Log}; #[derive(Debug,Clone,Copy,PartialEq,Serialize,Deserialize)] @@ -49,8 +49,8 @@ pub enum Stat { RedDamageTaken, BlueDamage, BlueDamageTaken, - Healing, - HealingTaken, + GreenDamage, + GreenDamageTaken, RedShield, BlueShield, Evasion, @@ -64,13 +64,18 @@ pub struct CrypStat { } impl CrypStat { - pub fn set(&mut self, v: u64, specs: &CrypSpecs) -> &mut CrypStat { + pub fn set(&mut self, v: u64, specs: &Vec) -> &mut CrypStat { self.base = v; self.recalculate(specs) } - pub fn recalculate(&mut self, specs: &CrypSpecs) -> &mut CrypStat { - let specs = specs.affects(self.stat); + pub fn recalculate(&mut self, specs: &Vec) -> &mut CrypStat { + let specs = specs + .iter() + .filter(|s| s.affects() == self.stat) + .map(|s| *s) + .collect::>(); + // applied with fold because it can be zeroed or multiplied // but still needs access to the base amount let value = specs.iter().fold(self.base, |acc, s| s.apply(acc, self.base)); @@ -97,32 +102,6 @@ impl CrypStat { } } - -#[derive(Debug,Clone,Serialize,Deserialize)] -pub struct CrypSpecs { - common: Vec, - uncommon: Vec, - rare: Vec, -} - -impl CrypSpecs { - fn new() -> CrypSpecs { - CrypSpecs { - common: vec![], - uncommon: vec![], - rare: vec![], - } - } - - fn affects(&self, stat: Stat) -> Vec { - [&self.common, &self.uncommon, &self.rare] - .iter() - .flat_map(|specs| specs.iter().filter(|s| s.affects == stat)) - .map(|s| *s) - .collect::>() - } -} - #[derive(Debug,Clone,Serialize,Deserialize)] pub struct CrypRecover { pub id: Uuid, @@ -148,7 +127,7 @@ pub struct Cryp { pub lvl: u8, pub skills: Vec, pub effects: Vec, - pub specs: CrypSpecs, + pub specs: Vec, pub name: String, pub ko_logged: bool, } @@ -176,7 +155,7 @@ impl Cryp { xp: 0, skills: vec![], effects: vec![], - specs: CrypSpecs::new(), + specs: vec![], name: String::new(), ko_logged: false, }; @@ -276,57 +255,14 @@ impl Cryp { } pub fn spec_add(&mut self, spec: Spec) -> Result<&mut Cryp, Error> { - let max_common = 20; - let max_uncommon = 10; - let max_rare = 5; - - match spec.level { - SpecLevel::Common => { - if self.specs.common.len() >= max_common { - return Err(format_err!("cryp at maximum common specalisations ({:})", max_common)) - } - - self.specs.common.push(spec); - }, - SpecLevel::Uncommon => { - if self.specs.uncommon.len() >= max_uncommon { - return Err(format_err!("cryp at maximum uncommon specalisations ({:})", max_uncommon)) - } - - self.specs.uncommon.push(spec); - }, - SpecLevel::Rare => { - if self.specs.rare.len() >= max_rare { - return Err(format_err!("cryp at maximum rare specalisations ({:})", max_rare)) - } - - if self.specs.rare.iter().find(|s| s.spec == spec.spec).is_some() { - return Err(format_err!("duplicate rare specialisation {:?}", spec.spec)); - } - - self.specs.rare.push(spec); - }, - }; - + self.specs.push(spec); return Ok(self.recalculate_stats()); } pub fn spec_remove(&mut self, spec: Spec) -> Result<&mut Cryp, Error> { - let find_spec = |spec_v: &Vec| spec_v.iter().position(|s| s.spec == spec.spec); - - match spec.level { - SpecLevel::Common => match find_spec(&self.specs.common) { - Some(p) => self.specs.common.remove(p), - None => return Err(err_msg("spec not found")), - }, - SpecLevel::Uncommon => match find_spec(&self.specs.uncommon) { - Some(p) => self.specs.uncommon.remove(p), - None => return Err(err_msg("spec not found")), - }, - SpecLevel::Rare => match find_spec(&self.specs.rare) { - Some(p) => self.specs.rare.remove(p), - None => return Err(err_msg("spec not found")), - }, + match self.specs.iter().position(|s| *s == spec) { + Some(p) => self.specs.remove(p), + None => return Err(err_msg("spec not found")), }; Ok(self.recalculate_stats()) @@ -529,7 +465,7 @@ impl Cryp { } let healing_mods = self.effects.iter() - .filter(|e| e.effect.modifications().contains(&Stat::HealingTaken)) + .filter(|e| e.effect.modifications().contains(&Stat::GreenDamageTaken)) .map(|cryp_effect| cryp_effect.effect) .collect::>(); diff --git a/server/src/spec.rs b/server/src/spec.rs index de3f793b..b4622b0c 100644 --- a/server/src/spec.rs +++ b/server/src/spec.rs @@ -1,54 +1,33 @@ use cryp::{Stat}; -#[derive(Debug,Copy,Clone,Serialize,Deserialize)] -pub enum SpecLevel { - Common, - Uncommon, - Rare, -} - -#[derive(Debug,Copy,Clone,Serialize,Deserialize)] -pub struct Spec { - pub affects: Stat, - pub spec: SpecType, - pub level: SpecLevel, +#[derive(Debug,Copy,Clone,Serialize,Deserialize,PartialEq)] +pub enum Spec { + SpeedI, + StaminaI, + RedDamageI, + GreenDamageI, + BlueDamageI, } impl Spec { - pub fn new(spec_type: SpecType) -> Spec { - Spec { - affects: spec_type.affects(), - level: spec_type.level(), - spec: spec_type, + pub fn affects(&self) -> Stat { + match *self { + Spec::RedDamageI => Stat::RedDamage, + Spec::GreenDamageI => Stat::GreenDamage, + Spec::BlueDamageI => Stat::BlueDamage, + Spec::SpeedI => Stat::Speed, + Spec::StaminaI => Stat::Stamina, } } pub fn apply(&self, modified: u64, base: u64) -> u64 { - match self.spec { - SpecType::RedDamage5 => modified + (base * 5 / 100), - SpecType::BlueDamage5 => modified + (base * 5 / 100), - } - } -} - -#[derive(Debug,Copy,Clone,Serialize,Deserialize,PartialEq)] -pub enum SpecType { - RedDamage5, - BlueDamage5, -} - -impl SpecType { - fn affects(&self) -> Stat { match *self { - SpecType::RedDamage5 => Stat::RedDamage, - SpecType::BlueDamage5 => Stat::BlueDamage, + Spec::RedDamageI => modified + (base * 5 / 100), + Spec::GreenDamageI => modified + (base * 5 / 100), + Spec::BlueDamageI => modified + (base * 5 / 100), + Spec::SpeedI => modified + (base * 5 / 100), + Spec::StaminaI => modified + (base * 5 / 100), } } - fn level(&self) -> SpecLevel { - match *self { - SpecType::RedDamage5 => SpecLevel::Common, - SpecType::BlueDamage5 => SpecLevel::Common, - } - } } diff --git a/server/src/vbox.rs b/server/src/vbox.rs index a1b6af7b..64aa38aa 100644 --- a/server/src/vbox.rs +++ b/server/src/vbox.rs @@ -14,6 +14,7 @@ use failure::err_msg; use account::Account; use rpc::{VboxAcceptParams, VboxDiscardParams, VboxCombineParams, VboxApplyParams, VboxDropParams}; use skill::{Skill}; +use spec::{Spec}; use player::{Player, player_get, player_update}; use cryp::{cryp_get, cryp_write}; @@ -37,8 +38,10 @@ pub enum Var { Speed, Hp, - HpI, - StamI, + StaminaI, + RedDamageI, + BlueDamageI, + GreenDamageI, SpeedI, Amplify, @@ -69,6 +72,11 @@ pub enum Var { Triage, } +enum VarEffect { + Skill, + Spec, +} + impl Var { fn is_base(&self) -> bool { match self { @@ -81,34 +89,78 @@ impl Var { } } - fn skill(&self) -> Result { + fn effect(&self) -> Result { match self { - Var::Amplify => Ok(Skill::Amplify), - Var::Banish => Ok(Skill::Banish), - Var::Blast => Ok(Skill::Blast), - Var::Curse => Ok(Skill::Curse), - Var::Empower => Ok(Skill::Empower), - Var::Haste => Ok(Skill::Haste), - Var::Heal => Ok(Skill::Heal), - Var::Hex => Ok(Skill::Hex), - Var::Parry => Ok(Skill::Parry), - Var::Purge => Ok(Skill::Purge), - Var::Purify => Ok(Skill::Purify), - // Var::Reflect => Ok(Skill::Reflect), - Var::Ruin => Ok(Skill::Ruin), - Var::Shield => Ok(Skill::Shield), - Var::Silence => Ok(Skill::Silence), - Var::Slay => Ok(Skill::Slay), - Var::Slow => Ok(Skill::Slow), - Var::Snare => Ok(Skill::Snare), - Var::Strangle => Ok(Skill::Strangle), - Var::Strike => Ok(Skill::Strike), - // Var::Clutch => Ok(Skill::Clutch), - // Var::Taunt => Ok(Skill::Taunt), - Var::Throw => Ok(Skill::Throw), - // Var::Toxic => Ok(Skill::Toxic), - Var::Triage => Ok(Skill::Triage), - _ => Err(err_msg("not a usable var")) + Var::Amplify | + Var::Banish | + Var::Blast | + Var::Curse | + Var::Empower | + Var::Haste | + Var::Heal | + Var::Hex | + Var::Parry | + Var::Purge | + Var::Purify | + // Var::Reflect | + Var::Ruin | + Var::Shield | + Var::Silence | + Var::Slay | + Var::Slow | + Var::Snare | + Var::Strangle | + Var::Strike | + // Var::Clutch | + // Var::Taunt | + Var::Throw | + // Var::Toxic | + Var::Triage => Ok(VarEffect::Skill), + + Var::StaminaI | + Var::SpeedI => Ok(VarEffect::Spec), + + _ => Err(err_msg("var has no effect on cryps")) + } + } + + fn skill(&self) -> Skill { + match self { + Var::Amplify => Skill::Amplify, + Var::Banish => Skill::Banish, + Var::Blast => Skill::Blast, + Var::Curse => Skill::Curse, + Var::Empower => Skill::Empower, + Var::Haste => Skill::Haste, + Var::Heal => Skill::Heal, + Var::Hex => Skill::Hex, + Var::Parry => Skill::Parry, + Var::Purge => Skill::Purge, + Var::Purify => Skill::Purify, + // Var::Reflect => Skill::Reflect, + Var::Ruin => Skill::Ruin, + Var::Shield => Skill::Shield, + Var::Silence => Skill::Silence, + Var::Slay => Skill::Slay, + Var::Slow => Skill::Slow, + Var::Snare => Skill::Snare, + Var::Strangle => Skill::Strangle, + Var::Strike => Skill::Strike, + // Var::Clutch => Skill::Clutch, + // Var::Taunt => Skill::Taunt, + Var::Throw => Skill::Throw, + // Var::Toxic => Skill::Toxic, + Var::Triage => Skill::Triage, + _ => panic!("not a skill var"), + } + } + + fn spec(&self) -> Spec { + match *self { + Var::StaminaI => Spec::StaminaI, + Var::RedDamageI => Spec::RedDamageI, + Var::SpeedI => Spec::SpeedI, + _ => panic!("not a spec var"), } } } @@ -139,7 +191,7 @@ impl Vbox { Var::Attack, Var::Attack, Var::Attack, - Var::HpI, + Var::StaminaI, Var::SpeedI, Var::Damage, Var::Red, @@ -312,6 +364,17 @@ impl Vbox { ColourCode::GB => Var::Silence, ColourCode::BR => Var::Hex, }, + + // SPECS + Var::Damage => match colour_code { + ColourCode::RR => Var::RedDamageI, + ColourCode::GG => Var::GreenDamageI, + ColourCode::BB => Var::BlueDamageI, + ColourCode::RG => return Err(err_msg("unhandled skill combo")), + ColourCode::GB => return Err(err_msg("unhandled skill combo")), + ColourCode::BR => return Err(err_msg("unhandled skill combo")), + }, + _ => panic!("wrong base {:?}", base), }; @@ -348,18 +411,25 @@ pub fn vbox_drop(params: VboxDropParams, tx: &mut Transaction, account: &Account pub fn vbox_apply(params: VboxApplyParams, tx: &mut Transaction, account: &Account) -> Result { let mut player = player_get(tx, account.id, params.instance_id)?; let var = player.vbox.bound.remove(params.index); - let skill = var.skill()?; - // mess with cryp then release it - { - let cryp = player.cryp_get(params.cryp_id)?; - // done here because i teach them a tonne of skills for tests - let max_skills = 4; - if cryp.skills.len() >= max_skills { - return Err(format_err!("cryp at max skills ({:?})", max_skills)); - } + match var.effect()? { + VarEffect::Skill => { + let skill = var.skill(); + let cryp = player.cryp_get(params.cryp_id)?; + // done here because i teach them a tonne of skills for tests + let max_skills = 4; + if cryp.skills.len() >= max_skills { + return Err(format_err!("cryp at max skills ({:?})", max_skills)); + } - cryp.learn_mut(skill); + cryp.learn_mut(skill); + }, + VarEffect::Spec => { + let spec = var.spec(); + let cryp = player.cryp_get(params.cryp_id)?; + cryp.spec_add(spec)?; + + }, } return player_update(tx, player);