add aoe events cleanup client anim code

This commit is contained in:
Mashy
2019-12-10 20:57:19 +10:00
parent 89fb27d858
commit 5ea22ec4b3
8 changed files with 81 additions and 72 deletions
+29 -7
View File
@@ -468,9 +468,18 @@ impl Game {
}
fn resolve(&mut self, cast: Cast) -> &mut Game {
// Send custom intial cast / hit aoe actions
if cast.skill.aoe() {
let actions = match cast.skill.cast_animation() {
true => vec![Action::Cast, Action::HitAoe],
false => vec![Action::HitAoe]
};
self.execute(cast, actions);
}
let casts = self.modify_cast(cast);
for cast in casts {
self.execute(cast);
self.execute(cast, cast.actions());
}
self
@@ -508,16 +517,17 @@ impl Game {
return casts;
}
fn execute(&mut self, cast: Cast) -> &mut Game {
fn execute(&mut self, cast: Cast, actions: Vec<Action>) -> &mut Game {
// this list is used to calculate values
// that are dependent on the result of previous events
// such as healing based on damage done etc
let mut event_list = vec![];
for action in cast.actions() {
for action in actions {
let events = match action {
Action::Cast => self.cast(cast),
Action::Hit => self.hit(cast),
Action::HitAoe => self.hit_aoe(cast),
Action::Damage { construct, values, colour } => {
let amount = self.reduce_values(&values, &event_list);
@@ -616,6 +626,18 @@ impl Game {
vec![Event::Hit { construct: cast.target, player: cast.player, direction: self.direction(cast) }]
}
fn hit_aoe(&mut self, cast: Cast) -> Vec<Event> {
let construct = self.players.iter()
.find(|t| t.constructs.iter().any(|c| c.id == cast.target))
.unwrap()
.constructs
.iter()
.map(|c| c.id)
.collect();
vec![Event::HitAoe { construct, player: cast.player, direction: self.direction(cast) }]
}
fn damage(&mut self, construct: Uuid, amount: usize, colour: Colour) -> Vec<Event> {
self.construct_by_id(construct).unwrap().damage(amount, colour)
}
@@ -841,6 +863,7 @@ pub enum Value {
#[derive(Debug,Clone,PartialEq)]
pub enum Action {
Hit,
HitAoe,
Cast,
Heal { construct: Uuid, values: Vec<Value>, colour: Colour },
Damage { construct: Uuid, values: Vec<Value>, colour: Colour },
@@ -848,7 +871,6 @@ pub enum Action {
Remove { construct: Uuid, effect: Effect },
RemoveAll { construct: Uuid },
IncreaseCooldowns { construct: Uuid, turns: usize },
// Recharge { skill: Skill, red: usize, blue: usize },
}
#[derive(Debug,Clone,PartialEq,Serialize,Deserialize)]
@@ -864,7 +886,7 @@ impl Resolution {
// maybe map events construct_ids
let focus = match event {
Event::HitAoe { construct: _ } => vec![cast.source, cast.target], // fixme
Event::HitAoe { construct: _, player: _, direction: _ } => vec![cast.source],
_ => vec![cast.source, cast.target],
};
@@ -889,7 +911,7 @@ pub type Direction = (i8, i8);
pub enum Event {
Cast { construct: Uuid, player: Uuid, direction: Direction },
Hit { construct: Uuid, player: Uuid, direction: Direction },
HitAoe { construct: Uuid },
HitAoe { construct: Vec<Uuid>, player: Uuid, direction: Direction },
Damage { construct: Uuid, amount: usize, mitigation: usize, colour: Colour, display: EventConstruct },
Effect { construct: Uuid, effect: Effect, duration: u8, display: EventConstruct },
@@ -927,7 +949,7 @@ impl Event {
}
},
Event::Hit { construct: _, direction: _, player: _ } |
Event::HitAoe { construct: _ } => {
Event::HitAoe { construct: _, direction: _, player: _ } => {
match next_event {
Some(e) => {
match e.event {
+6 -5
View File
@@ -56,12 +56,13 @@ impl Cast {
let mut actions = vec![];
if self.skill.cast_animation() {
actions.push(Action::Cast);
if !self.skill.aoe() {
if self.skill.cast_animation() {
actions.push(Action::Cast);
}
actions.push(Action::Hit);
}
actions.push(Action::Hit);
let mut rest = match self.skill {
Skill::Attack => vec![
Action::Damage {
@@ -1545,7 +1546,7 @@ impl Skill {
}
}
fn cast_animation(&self) -> bool {
pub fn cast_animation(&self) -> bool {
match self {
Skill::HybridBlast |
Skill::HasteStrike |