diff --git a/core/Cargo.toml b/core/Cargo.toml index 66e37389..57a24193 100644 --- a/core/Cargo.toml +++ b/core/Cargo.toml @@ -1,17 +1,13 @@ [package] -name = "mnml-core" +name = "mnml_core" version = "1.10.0" authors = ["ntr ", "mashy "] [dependencies] +chrono = { version = "0.4", features = ["serde"] } +failure = "0.1" +log = "0.4" +rand = "0.6" serde = "1" serde_derive = "1" - -rand = "0.6" uuid = { version = "0.5", features = ["serde", "v4"] } -chrono = { version = "0.4", features = ["serde"] } -bcrypt = "0.2" - -failure = "0.1" - -log = "0.4" diff --git a/core/src/construct.rs b/core/src/construct.rs index 725387b6..7deb7abb 100644 --- a/core/src/construct.rs +++ b/core/src/construct.rs @@ -438,7 +438,6 @@ impl Construct { if skill.skill.base_cd().is_some() { // what is the current cd if let Some(current_cd) = skill.cd { - // if it's 1 set it to none if current_cd == 1 { skill.cd = None; @@ -1006,4 +1005,20 @@ mod tests { return; } + #[test] + fn construct_reduce_cooldown_test() { + let mut construct = Construct::new() + .named(&"sleepygirl".to_string()); + + construct.learn_mut(Skill::Sleep); + + let mut i = 0; + while construct.skill_on_cd(Skill::Sleep).is_some() { + construct.reduce_cooldowns(); + i += 1; + } + + assert_eq!(i, Skill::Sleep.base_cd().unwrap()); + } + } diff --git a/core/src/game.rs b/core/src/game.rs index 818e5643..2f9274a4 100644 --- a/core/src/game.rs +++ b/core/src/game.rs @@ -398,7 +398,7 @@ impl Game { self.phase = Phase::Resolve; // self.log.push("".to_string()); - self.resolve_skills() + self.resolve_stack() } fn stack_sort_speed(&mut self) -> &mut Game { @@ -444,7 +444,7 @@ impl Game { } } - fn resolve_skills(mut self) -> Game { + fn resolve_stack(mut self) -> Game { if self.phase != Phase::Resolve { panic!("game not in Resolve phase"); } @@ -466,28 +466,23 @@ impl Game { // temp vec of this round's resolving skills // because need to check cooldown use before pushing them into the complete list - let mut casts = vec![]; + let mut casters = vec![]; let mut r_animation_ms = 0; while let Some(cast) = self.stack.pop() { // info!("{:} casts ", cast); - let mut resolutions = resolve(&cast, &mut self); + let mut resolutions = vec![]; + resolutions = resolve(&cast, &mut self, resolutions); r_animation_ms = resolutions.iter().fold(r_animation_ms, |acc, r| acc + r.clone().get_delay()); - - // the cast itself goes into this temp vec to handle cooldowns // if theres no resolution events, the skill didn't trigger (disable etc) - if resolutions.len() > 0 { - casts.push(cast); + if resolutions.len() > 0 && cast.used_cooldown() { + casters.push(cast); } self.resolved.append(&mut resolutions); - // while let Some(resolution) = resolutions.pop() { - // self.log_resolution(cast.speed, &resolution); - // // the results go into the resolutions - // self.resolved.push(resolution); - // } + // println!("{:?}", self.resolved); // sort the stack again in case speeds have changed self.stack_sort_speed(); @@ -496,7 +491,7 @@ impl Game { // info!("{:#?}", self.casts); // handle cooldowns and statuses - self.progress_durations(&casts); + self.progress_durations(&casters); if self.finished() { return self.finish() @@ -513,16 +508,10 @@ impl Game { continue; } - // only reduce cooldowns if no cd was used - { - if let Some(skill) = resolved.iter() - .filter(|s| s.source_construct_id == construct.id) - .find(|s| s.used_cooldown()) { - construct.skill_set_cd(skill.skill); - } else { - construct.reduce_cooldowns(); - } - } + match resolved.iter().find(|s| s.source_construct_id == construct.id) { + Some(skill) => { construct.skill_set_cd(skill.skill); }, + None => { construct.reduce_cooldowns(); }, + }; // always reduce durations construct.reduce_effect_durations(); diff --git a/core/src/lib.rs b/core/src/lib.rs index 2fb53670..dface4fe 100644 --- a/core/src/lib.rs +++ b/core/src/lib.rs @@ -1,6 +1,5 @@ extern crate rand; extern crate uuid; -extern crate bcrypt; extern crate chrono; extern crate serde; diff --git a/core/src/skill.rs b/core/src/skill.rs index 13fdcf82..b370840b 100644 --- a/core/src/skill.rs +++ b/core/src/skill.rs @@ -21,9 +21,7 @@ pub fn dev_resolve(a_id: Uuid, b_id: Uuid, skill: Skill) -> Resolutions { return resolve_skill(skill, &mut a, &mut b, resolutions); } -pub fn resolve(cast: &Cast, game: &mut Game) -> Resolutions { - let mut resolutions = vec![]; - +pub fn resolve(cast: &Cast, game: &mut Game, mut resolutions: Resolutions) -> Resolutions { let skill = cast.skill; let source = game.construct_by_id(cast.source_construct_id).unwrap().clone(); let targets = game.get_targets(cast.skill, &source, cast.target_construct_id);