team combos and green damage

This commit is contained in:
ntr 2019-03-18 19:42:20 +11:00
parent 1f39479085
commit d19391ea27
5 changed files with 112 additions and 35 deletions

View File

@ -11,10 +11,6 @@
## NOW ## NOW
combo specs combo specs
fix global matchmaking
startup checks
scoreboard scoreboard
constants constants

View File

@ -100,7 +100,7 @@ impl CrypStat {
// self.recalculate(specs) // self.recalculate(specs)
// } // }
pub fn recalculate(&mut self, specs: &Vec<Spec>) -> &mut CrypStat { pub fn recalculate(&mut self, specs: &Vec<Spec>, team_colours: &Colours) -> &mut CrypStat {
let specs = specs let specs = specs
.iter() .iter()
.filter(|s| s.affects().contains(&self.stat)) .filter(|s| s.affects().contains(&self.stat))
@ -109,7 +109,7 @@ impl CrypStat {
// applied with fold because it can be zeroed or multiplied // applied with fold because it can be zeroed or multiplied
// but still needs access to the base amount // but still needs access to the base amount
let value = specs.iter().fold(self.base, |acc, s| s.apply(acc, self.base)); let value = specs.iter().fold(self.base, |acc, s| s.apply(acc, self.base, team_colours));
self.value = value; self.value = value;
self.max = value; self.max = value;
@ -149,6 +149,7 @@ pub struct Cryp {
pub red_shield: CrypStat, pub red_shield: CrypStat,
pub blue_shield: CrypStat, pub blue_shield: CrypStat,
pub blue_damage: CrypStat, pub blue_damage: CrypStat,
pub green_damage: CrypStat,
pub speed: CrypStat, pub speed: CrypStat,
pub hp: CrypStat, pub hp: CrypStat,
pub evasion: CrypStat, pub evasion: CrypStat,
@ -170,8 +171,9 @@ impl Cryp {
red_shield: CrypStat { base: 0, value: 0, max: 0, stat: Stat::RedShield }, red_shield: CrypStat { base: 0, value: 0, max: 0, stat: Stat::RedShield },
blue_damage: CrypStat { base: 256, value: 256, max: 256, stat: Stat::BlueDamage }, blue_damage: CrypStat { base: 256, value: 256, max: 256, stat: Stat::BlueDamage },
blue_shield: CrypStat { base: 0, value: 0, max: 0, stat: Stat::BlueShield }, blue_shield: CrypStat { base: 0, value: 0, max: 0, stat: Stat::BlueShield },
speed: CrypStat { base: 128, value: 128, max: 128, stat: Stat::Speed }, green_damage: CrypStat { base: 256, value: 256, max: 256, stat: Stat::GreenDamage },
hp: CrypStat { base: 1024, value: 1024, max: 1024, stat: Stat::Hp }, hp: CrypStat { base: 1024, value: 1024, max: 1024, stat: Stat::Hp },
speed: CrypStat { base: 128, value: 128, max: 128, stat: Stat::Speed },
evasion: CrypStat { base: 0, value: 0, max: 0, stat: Stat::Evasion }, evasion: CrypStat { base: 0, value: 0, max: 0, stat: Stat::Evasion },
skills: vec![], skills: vec![],
effects: vec![], effects: vec![],
@ -200,15 +202,14 @@ impl Cryp {
pub fn learn_mut(&mut self, s: Skill) -> &mut Cryp { pub fn learn_mut(&mut self, s: Skill) -> &mut Cryp {
self.skills.push(CrypSkill::new(s)); self.skills.push(CrypSkill::new(s));
self.colours = Colours::from_cryp(&self); self.calculate_colours()
self
} }
pub fn forget(&mut self, skill: Skill) -> Result<&mut Cryp, Error> { pub fn forget(&mut self, skill: Skill) -> Result<&mut Cryp, Error> {
match self.skills.iter().position(|s| s.skill == skill) { match self.skills.iter().position(|s| s.skill == skill) {
Some(i) => { Some(i) => {
self.skills.remove(i); self.skills.remove(i);
return Ok(self); return Ok(self.calculate_colours());
}, },
None => Err(format_err!("{:?} does not know {:?}", self.name, skill)), None => Err(format_err!("{:?} does not know {:?}", self.name, skill)),
} }
@ -216,7 +217,7 @@ impl Cryp {
pub fn spec_add(&mut self, spec: Spec) -> Result<&mut Cryp, Error> { pub fn spec_add(&mut self, spec: Spec) -> Result<&mut Cryp, Error> {
self.specs.push(spec); self.specs.push(spec);
return Ok(self.recalculate_stats()); return Ok(self.calculate_colours());
} }
pub fn spec_remove(&mut self, spec: Spec) -> Result<&mut Cryp, Error> { pub fn spec_remove(&mut self, spec: Spec) -> Result<&mut Cryp, Error> {
@ -225,23 +226,25 @@ impl Cryp {
None => return Err(err_msg("spec not found")), None => return Err(err_msg("spec not found")),
}; };
Ok(self.recalculate_stats()) Ok(self.calculate_colours())
} }
fn calculate_colours(&mut self) -> &mut Cryp {
self.colours = Colours::from_cryp(&self);
self
}
fn recalculate_stats(&mut self) -> &mut Cryp { pub fn apply_modifiers(&mut self, team_colours: &Colours) -> &mut Cryp {
self.specs.sort_unstable(); self.specs.sort_unstable();
// recalculate the colours for the spec bonuses self.red_damage.recalculate(&self.specs, team_colours);
self.colours = Colours::from_cryp(&self); self.red_shield.recalculate(&self.specs, team_colours);
self.blue_damage.recalculate(&self.specs, team_colours);
self.red_damage.recalculate(&self.specs); self.blue_shield.recalculate(&self.specs, team_colours);
self.red_shield.recalculate(&self.specs); self.evasion.recalculate(&self.specs, team_colours);
self.blue_damage.recalculate(&self.specs); self.speed.recalculate(&self.specs, team_colours);
self.blue_shield.recalculate(&self.specs); self.green_damage.recalculate(&self.specs, team_colours);
self.evasion.recalculate(&self.specs); self.hp.recalculate(&self.specs, team_colours);
self.speed.recalculate(&self.specs);
self.hp.recalculate(&self.specs);
self self
} }
@ -393,6 +396,17 @@ impl Cryp {
return modified_blue_damage; return modified_blue_damage;
} }
pub fn green_damage(&self) -> u64 {
let green_damage_mods = self.effects.iter()
.filter(|e| e.effect.modifications().contains(&Stat::GreenDamage))
.map(|cryp_effect| cryp_effect.effect)
.collect::<Vec<Effect>>();
let modified_green_damage = green_damage_mods.iter().fold(self.green_damage.value, |acc, m| m.apply(acc));
return modified_green_damage;
}
pub fn skill_speed(&self, s: Skill) -> u64 { pub fn skill_speed(&self, s: Skill) -> u64 {
self.speed().saturating_mul(s.speed() as u64) self.speed().saturating_mul(s.speed() as u64)
} }
@ -648,7 +662,7 @@ pub fn cryp_recover(cryp_bytes: Vec<u8>, tx: &mut Transaction) -> Result<Cryp, E
#[cfg(test)] #[cfg(test)]
mod tests { mod tests {
use cryp::*; use cryp::*;
// use skill::*; use spec::IntPct;
#[test] #[test]
fn create_cryp_test() { fn create_cryp_test() {
@ -677,4 +691,32 @@ mod tests {
return; return;
} }
#[test]
fn cryp_team_modifiers_test() {
let mut cryp = Cryp::new()
.named(&"team player".to_string());
cryp.spec_add(Spec::RedDamageI).unwrap();
cryp.spec_add(Spec::GreenDamageI).unwrap();
cryp.spec_add(Spec::BlueDamageI).unwrap();
let team_colours = Colours {
red: 5,
green: 15,
blue: 25,
};
cryp.apply_modifiers(&team_colours);
println!("{:?}", cryp.red_damage.value);
println!("{:?}", cryp.blue_damage.value);
assert_eq!(cryp.red_damage.value, cryp.red_damage.base + cryp.red_damage.base.pct(5));
assert_eq!(cryp.green_damage.value, cryp.green_damage.base + cryp.green_damage.base.pct(15));
assert_eq!(cryp.blue_damage.value, cryp.blue_damage.base + cryp.blue_damage.base.pct(20));
return;
}
} }

View File

@ -728,7 +728,7 @@ fn empower(_cryp: &mut Cryp, target: &mut Cryp, mut resolution: Resolution) -> R
} }
fn heal(cryp: &mut Cryp, target: &mut Cryp, mut resolution: Resolution) -> Resolution { fn heal(cryp: &mut Cryp, target: &mut Cryp, mut resolution: Resolution) -> Resolution {
let amount = cryp.blue_damage(); let amount = cryp.green_damage();
resolution.results.push(target.heal(Skill::Heal, amount)); resolution.results.push(target.heal(Skill::Heal, amount));
return resolution; return resolution;
} }

View File

@ -1,6 +1,6 @@
use rand::prelude::*; use rand::prelude::*;
use cryp::{Stat}; use cryp::{Stat, Colours};
#[derive(Debug,Copy,Clone,Serialize,Deserialize,PartialEq,PartialOrd,Ord,Eq)] #[derive(Debug,Copy,Clone,Serialize,Deserialize,PartialEq,PartialOrd,Ord,Eq)]
pub enum Spec { pub enum Spec {
@ -20,6 +20,16 @@ pub enum Spec {
BlueDamageI, BlueDamageI,
} }
pub trait IntPct {
fn pct(self, pct: u64) -> u64;
}
impl IntPct for u64 {
fn pct(self, pct: u64) -> u64 {
self * pct / 100
}
}
impl Spec { impl Spec {
pub fn affects(&self) -> Vec<Stat> { pub fn affects(&self) -> Vec<Stat> {
match *self { match *self {
@ -39,25 +49,40 @@ impl Spec {
} }
} }
pub fn apply(&self, modified: u64, base: u64) -> u64 { pub fn apply(&self, modified: u64, base: u64, team_colours: &Colours) -> u64 {
let mut rng = thread_rng(); let mut rng = thread_rng();
let i_min = 32; let i_min = 32;
let i_max = 64; let i_max = 64;
match *self { match *self {
Spec::RedDamageI => modified + (base * 5 / 100), Spec::RedDamageI => modified + match team_colours.red {
Spec::GreenDamageI => modified + (base * 5 / 100), 0...5 => base.pct(5),
Spec::BlueDamageI => modified + (base * 5 / 100), 6...10 => base.pct(10),
11...15 => base.pct(15),
_ => base.pct(20)
},
Spec::GreenDamageI => modified + match team_colours.green {
0...5 => base.pct(5),
6...10 => base.pct(10),
11...15 => base.pct(15),
_ => base.pct(20)
},
Spec::BlueDamageI => modified + match team_colours.blue {
0...5 => base.pct(5),
6...10 => base.pct(10),
11...15 => base.pct(15),
_ => base.pct(20)
},
Spec::SpeedI => modified + (base * 5 / 100), Spec::SpeedI => modified + base.pct(5),
Spec::LifeI => modified + (base * 5 / 100), Spec::LifeI => modified + base.pct(5),
Spec::RedShieldI => modified + rng.gen_range(i_min, i_max), Spec::RedShieldI => modified + rng.gen_range(i_min, i_max),
Spec::BlueShieldI => modified + rng.gen_range(i_min, i_max), Spec::BlueShieldI => modified + rng.gen_range(i_min, i_max),
Spec::LRSI => modified + (base * 5 / 100), Spec::LRSI => modified + base.pct(5),
Spec::LBSI => modified + (base * 5 / 100), Spec::LBSI => modified + base.pct(5),
Spec::RBSI => modified + (base * 5 / 100), Spec::RBSI => modified + base.pct(5),
} }
} }

View File

@ -516,6 +516,20 @@ pub fn vbox_apply(params: VboxApplyParams, tx: &mut Transaction, account: &Accou
None => return Err(err_msg("var has no effect on cryps")), None => return Err(err_msg("var has no effect on cryps")),
} }
// now the var has been applied
// recalculate the stats of the whole team
let team_colours = player.cryps.iter().fold(Colours::new(), |tc, c| {
Colours {
red: tc.red + c.colours.red,
green: tc.green + c.colours.green,
blue: tc.blue + c.colours.blue
}
});
for cryp in player.cryps.iter_mut() {
cryp.apply_modifiers(&team_colours);
}
return player_update(tx, player, false); return player_update(tx, player, false);
} }