diff --git a/core/fixme.md b/core/fixme.md index 32934560..d05c4692 100644 --- a/core/fixme.md +++ b/core/fixme.md @@ -5,4 +5,5 @@ aoe event cooldown events leak skills hit event reqs moving eventconstruct into specific events + cooldown checking -> go through round and find all casters \ No newline at end of file diff --git a/core/src/construct.rs b/core/src/construct.rs index 81aa785b..d40cf2bd 100644 --- a/core/src/construct.rs +++ b/core/src/construct.rs @@ -4,7 +4,7 @@ use rand::prelude::*; use failure::Error; use failure::err_msg; -use skill::{Skill, Cast, Disable, Event, EventVariant}; +use skill::{Skill, Cast, Disable, Event, EventVariant, EventConstruct}; use game::{Colour}; use effect::{Cooldown, Effect}; use spec::{Spec}; @@ -418,18 +418,16 @@ impl Construct { pub fn increase_cooldowns(&mut self, turns: usize) -> Vec { let mut events = vec![]; - let state = self.clone(); - for skill in self.skills.iter_mut() { if skill.skill.base_cd().is_some() { // if has a cooldown match skill.cd { Some(cd) => { skill.cd = Some(cd.saturating_add(turns)); - events.push(Event::new(EventVariant::CooldownIncrease { turns, skill: skill.skill }, &state)) + events.push(Event::new(EventVariant::CooldownIncrease { turns, skill: skill.skill }, self.id)) }, None => { skill.cd = Some(turns); - events.push(Event::new(EventVariant::CooldownIncrease { turns, skill: skill.skill }, &state)) + events.push(Event::new(EventVariant::CooldownIncrease { turns, skill: skill.skill }, self.id)) }, } } @@ -567,7 +565,7 @@ impl Construct { let blue = new_blue_life - current_blue_life; if red != 0 || blue != 0 { - events.push(Event::new(EventVariant::Recharge { red, blue }, self)); + events.push(Event::new(EventVariant::Recharge { red, blue }, self.id)); } }, true => { @@ -596,8 +594,9 @@ impl Construct { events.push(Event::new(EventVariant::Damage { amount: red_damage_amount, mitigation: red_mitigation, - colour: Colour::Red - }, self)); + colour: Colour::Red, + stats: EventConstruct::new(self), + }, self.id)); } if blue_amount != 0 { @@ -624,8 +623,9 @@ impl Construct { events.push(Event::new(EventVariant::Damage { amount: blue_damage_amount, mitigation: blue_mitigation, - colour: Colour::Blue - }, self)); + colour: Colour::Blue, + stats: EventConstruct::new(self), + }, self.id)); } } } @@ -656,7 +656,7 @@ impl Construct { events.push(Event::new(EventVariant::Healing { amount: healing, overhealing, - }, self)); + }, self.id)); }, true => { // events.push(Event::new(EventVariant::Inversion { skill })); @@ -670,7 +670,8 @@ impl Construct { amount: delta, mitigation: 0, colour: Colour::Green, - }, self)); + stats: EventConstruct::new(self), + }, self.id)); } } @@ -712,8 +713,9 @@ impl Construct { amount: delta, mitigation, colour: Colour::Red, + stats: EventConstruct::new(self), }, - self + self.id )); }, true => { @@ -734,12 +736,12 @@ impl Construct { EventVariant::Healing{ amount: healing, overhealing: overhealing - recharge, - }, self + }, self.id )); } if recharge > 0 { - events.push(Event::new(EventVariant::Recharge { red: recharge, blue: 0 }, self)); + events.push(Event::new(EventVariant::Recharge { red: recharge, blue: 0 }, self.id)); } } }; @@ -777,7 +779,8 @@ impl Construct { amount: delta, mitigation, colour: Colour::Blue, - }, self)); + stats: EventConstruct::new(self), + }, self.id)); }, true => { // events.push(Event::new(EventVariant::Inversion { skill })); @@ -798,12 +801,12 @@ impl Construct { amount: healing, overhealing, }, - self + self.id )); } if recharge > 0 { - events.push(Event::new(EventVariant::Recharge { red: 0, blue: recharge }, self)); + events.push(Event::new(EventVariant::Recharge { red: 0, blue: recharge }, self.id)); } } }; @@ -833,7 +836,7 @@ impl Construct { effect: effect.effect, duration: effect.duration, construct_effects: self.effects.clone(), - }, self + }, self.id ); return vec![result]; diff --git a/core/src/game.rs b/core/src/game.rs index 2f3362d7..b1947ccb 100644 --- a/core/src/game.rs +++ b/core/src/game.rs @@ -10,7 +10,7 @@ use failure::Error; use failure::err_msg; use construct::{Construct, ConstructEffect, Stat}; -use skill::{Skill, Cast, Event, resolve}; +use skill::{Skill, Cast, Event, EventVariant, resolve}; use player::{Player}; use instance::{TimeControl}; @@ -40,6 +40,7 @@ pub enum Colour { #[derive(Debug,Clone,PartialEq,Serialize,Deserialize)] pub enum Action { + Hit { construct: Uuid, skill: Skill }, Damage { construct: Uuid, values: Vec, colour: Colour }, Effect { construct: Uuid, effect: ConstructEffect }, IncreaseCooldowns { construct: Uuid, turns: usize }, @@ -491,7 +492,7 @@ impl Game { self.skill_phase_start(r_animation_ms) } - fn resolution_add(&mut self, mut events: Vec) -> &mut Game { + fn event_add(&mut self, mut events: Vec) -> &mut Game { self.events.last_mut().unwrap().append(&mut events); self } @@ -499,6 +500,7 @@ impl Game { pub fn actions(&mut self, actions: Vec) -> &mut Game { for action in actions { match action { + Action::Hit { construct, skill } => self.hit(construct, skill), Action::Damage { construct, values, colour } => self.damage(construct, values, colour), Action::Effect { construct, effect } => self.effect(construct, effect), Action::IncreaseCooldowns { construct, turns } => self.increase_cooldowns(construct, turns), @@ -508,24 +510,29 @@ impl Game { self } + fn hit(&mut self, construct: Uuid, skill: Skill) -> &mut Game { + self.event_add(vec![Event::new(EventVariant::Hit { skill: skill }, construct)]); + self + } + fn damage(&mut self, construct: Uuid, values: Vec, colour: Colour) -> &mut Game { let events = match colour { _ => self.construct_by_id(construct).unwrap().deal_red_damage(128) // fixme unwrap }; - self.resolution_add(events); + self.event_add(events); self } fn effect(&mut self, construct: Uuid, effect: ConstructEffect) -> &mut Game { let events = self.construct_by_id(construct).unwrap().add_effect(effect); - self.resolution_add(events); + self.event_add(events); self } fn increase_cooldowns(&mut self, construct: Uuid, turns: usize) -> &mut Game { let events = self.construct_by_id(construct).unwrap().increase_cooldowns(turns); - self.resolution_add(events); + self.event_add(events); self } diff --git a/core/src/skill.rs b/core/src/skill.rs index fc9f307c..1e3708e9 100644 --- a/core/src/skill.rs +++ b/core/src/skill.rs @@ -62,9 +62,7 @@ pub fn resolve(game: &mut Game, cast: Cast) { // } for cast in casts { - let mut actions = vec![]; // fixme hit event - actions.append(&mut cast.actions()); - game.actions(actions); + game.actions(cast.actions()); } } @@ -107,8 +105,9 @@ impl Cast { } pub fn actions(&self) -> Vec { - match self.skill { + let mut actions = vec![Action::Hit { construct: self.target, skill: self.skill }]; + let mut rest = match self.skill { Skill::Amplify => vec![ Action::Effect { construct: self.target, @@ -169,7 +168,7 @@ impl Cast { }, Action::Effect { construct: self.target, - effect: ConstructEffect {effect: Effect::Stun, duration: 2, meta: Some(EffectMeta::Skill(Skill::Bash)), tick: None } + effect: ConstructEffect {effect: Effect::Stun, duration: 2, meta: None, tick: None } }, Action::IncreaseCooldowns { construct: self.target, @@ -217,33 +216,29 @@ impl Cast { ], _ => unimplemented!() - } - -} + }; + actions.append(&mut rest); + return actions; + } } pub type Disable = Vec; #[derive(Debug,Clone,PartialEq,Serialize,Deserialize)] pub struct Event { - pub target: EventConstruct, + pub target: Uuid, pub variant: EventVariant, pub stages: EventStages, pub delay: i64, } impl Event { - pub fn new(variant: EventVariant, target: &Construct) -> Event { + pub fn new(variant: EventVariant, target: Uuid) -> Event { let stages = variant.stages(); Event { - target: EventConstruct { - id: target.id, - red: target.red_life(), - green: target.green_life(), - blue: target.blue_life(), - }, + target, variant, delay: stages.delay(), stages: stages, @@ -254,15 +249,15 @@ impl Event { #[derive(Debug,Clone,PartialEq,Serialize,Deserialize)] pub enum EventVariant { Hit { skill: Skill }, + Damage { amount: usize, mitigation: usize, colour: Colour, stats: EventConstruct }, + Effect { effect: Effect, duration: u8, construct_effects: Vec }, Disable { disable: Disable }, - Damage { amount: usize, mitigation: usize, colour: Colour }, Healing { amount: usize, overhealing: usize }, Recharge { red: usize, blue: usize }, Inversion { skill: Skill }, Reflection { skill: Skill }, AoeSkill { skill: Skill }, Skill { skill: Skill }, - Effect { effect: Effect, duration: u8, construct_effects: Vec }, Removal { effect: Option, construct_effects: Vec }, TargetKo { skill: Skill }, // skill not necessary but makes it neater as all events are arrays in js @@ -281,7 +276,7 @@ impl EventVariant { match self { EventVariant::Disable { disable: _} => EventStages::PostOnly, - EventVariant::Damage { amount: _, mitigation: _, colour: _} + EventVariant::Damage { amount: _, mitigation: _, colour: _, stats: _ } => EventStages::PostOnly, EventVariant::Healing { amount: _, overhealing: _} => EventStages::PostOnly, @@ -331,6 +326,17 @@ pub struct EventConstruct { pub blue: usize, } +impl EventConstruct { + pub fn new(construct: &Construct) -> EventConstruct { + EventConstruct { + id: construct.id, + red: construct.red_life(), + green: construct.green_life(), + blue: construct.blue_life(), + } + } +} + #[derive(Debug,Clone,Copy,PartialEq,Serialize,Deserialize)] pub enum EventStages { #[serde(rename = "START_SKILL END_SKILL POST_SKILL")] @@ -1637,8 +1643,16 @@ mod tests { #[test] fn attack_actions_test() { let cast = Cast::new(Uuid::new_v4(), Uuid::new_v4(), Uuid::new_v4(), Skill::Attack); - let mut actions = cast.actions(); + let actions = cast.actions(); + match actions[0] { + Action::Hit { construct: _, skill } => { + assert_eq!(skill, Skill::Attack); + }, + _ => panic!("{:?}", actions), + }; + + match actions[1] { Action::Damage { construct: _, values: _, colour } => { assert_eq!(colour, Colour::Red); },