specs init

This commit is contained in:
ntr
2019-01-15 22:29:51 +11:00
parent a44b9bc929
commit 17d71b2258
3 changed files with 53 additions and 13 deletions
+26
View File
@@ -10,6 +10,7 @@ use failure::err_msg;
use account::Account;
use rpc::{CrypSpawnParams, CrypLearnParams, CrypForgetParams};
use skill::{Skill, Cooldown, Effect, Cast, Category, Immunity, Disable, ResolutionResult};
use spec::{Spec};
use game::{Log};
#[derive(Debug,Clone,Copy,PartialEq,Serialize,Deserialize)]
@@ -77,6 +78,31 @@ impl CrypStat {
self
}
fn modified(&self, specs: &CrypSpecs) -> u64 {
let specs = specs.affects(self.stat);
// applied with fold because it can be zeroed or multiplied
// but still needs access to the base amount
let modified = specs.iter().fold(self.base, |acc, s| s.apply(acc, self.base));
return modified;
}
}
#[derive(Debug,Clone,Serialize,Deserialize)]
struct CrypSpecs {
common: Vec<Spec>,
uncommon: Vec<Spec>,
rare: Vec<Spec>,
}
impl CrypSpecs {
fn affects(&self, stat: Stat) -> Vec<Spec> {
[&self.common, &self.uncommon, &self.rare]
.iter()
.flat_map(|specs| specs.iter().filter(|s| s.affects == stat))
.map(|s| *s)
.collect::<Vec<Spec>>()
}
}
#[derive(Debug,Clone,Serialize,Deserialize)]
+2 -1
View File
@@ -22,7 +22,8 @@ mod cryp;
mod game;
mod net;
mod skill;
mod passives;
mod spec;
// mod passives;
mod rpc;
mod account;
mod item;