refactor the delay code

This commit is contained in:
Mashy 2019-12-09 15:11:14 +10:00
parent 994d1c8fb0
commit c5469a651d

View File

@ -497,7 +497,7 @@ impl Game {
return targets; return targets;
} }
fn calculate_amount(&mut self, values: &Vec<Value>, resolutions: &Vec<Resolution>) -> usize { fn calculate_amount(&mut self, values: &Vec<Value>, events: &Vec<Event>) -> usize {
values.iter() values.iter()
.fold(0, |total, value| { .fold(0, |total, value| {
total + match value { total + match value {
@ -511,9 +511,9 @@ impl Game {
Value::ColourSkills { construct, colour, mult } => unimplemented!(), Value::ColourSkills { construct, colour, mult } => unimplemented!(),
Value::DamageTaken { construct, colour, mult } => Value::DamageTaken { construct, colour, mult } =>
resolutions.iter().fold(0, |dmg, res| match res.event { events.iter().fold(0, |dmg, e| match e {
Event::Damage { construct: event_construct, amount, mitigation:_, colour: event_colour, display: _ } => Event::Damage { construct: event_construct, amount, mitigation:_, colour: event_colour, display: _ } =>
match *construct == event_construct && *colour == event_colour { match *construct == *event_construct && *colour == *event_colour {
true => dmg + amount, true => dmg + amount,
false => dmg, false => dmg,
} }
@ -529,20 +529,20 @@ impl Game {
// calculate values first? // calculate values first?
// for result damage value need to pass &Resolutions and .find() // for result damage value need to pass &Resolutions and .find()
let mut resolved = vec![]; let mut event_list = vec![];
for action in cast.actions() { for action in cast.actions() {
let events = match action { let mut events = match action {
Action::Cast => self.cast(cast), Action::Cast => self.cast(cast),
Action::Hit => self.hit(cast), Action::Hit => self.hit(cast),
Action::Damage { construct, values, colour } => { Action::Damage { construct, values, colour } => {
let amount = self.calculate_amount(&values, &resolved); let amount = self.calculate_amount(&values, &event_list);
self.damage(construct, amount, colour) self.damage(construct, amount, colour)
}, },
Action::Heal { construct, values, colour } => { Action::Heal { construct, values, colour } => {
let amount = self.calculate_amount(&values, &resolved); let amount = self.calculate_amount(&values, &event_list);
self.heal(construct, amount, colour) self.heal(construct, amount, colour)
}, },
@ -550,52 +550,17 @@ impl Game {
Action::Remove { construct, effect } => self.effect_remove(construct, effect), Action::Remove { construct, effect } => self.effect_remove(construct, effect),
Action::IncreaseCooldowns { construct, turns } => self.increase_cooldowns(construct, turns), Action::IncreaseCooldowns { construct, turns } => self.increase_cooldowns(construct, turns),
}; };
event_list.append(&mut events);
let mut resolutions = events.into_iter()
.map(|event| Resolution::new(cast, event))
.collect::<Vec<Resolution>>();
resolved.append(&mut resolutions);
} }
{ let mut resolutions = vec![];
let mut r_iter = resolved.iter_mut().peekable(); let mut iter = event_list.into_iter().peekable();
while let Some(r) = r_iter.next() {
let set_full_delay = match r.event {
Event::Cast { construct: _, player: _, direction: _} => {
match r_iter.peek() {
Some(next_r) => {
match next_r.event {
Event::Cast { construct: _, player: _, direction: _} => true,
_ => false
}
},
None => true,
}
},
Event::Hit { construct: _, player: _, direction: _} => { while let Some(event) = iter.next() {
match r_iter.peek() { resolutions.push(Resolution::new(cast, event, iter.peek()));
Some(next_r) => {
match next_r.event {
Event::Cast { construct: _, player: _, direction: _} |
Event::Hit { construct: _, player: _, direction: _} => true,
_ => false
}
},
None => true,
}
},
_ => false,
};
if set_full_delay {
r.set_full_delay();
}
}
} }
self.resolutions.last_mut().unwrap().append(&mut resolved); self.resolutions.last_mut().unwrap().append(&mut resolutions);
self self
} }
@ -912,7 +877,7 @@ pub struct Resolution {
} }
impl Resolution { impl Resolution {
pub fn new(cast: Cast, event: Event) -> Resolution { pub fn new(cast: Cast, event: Event, next_event: Option<&Event>) -> Resolution {
// maybe map events construct_ids // maybe map events construct_ids
let focus = match event { let focus = match event {
@ -920,7 +885,8 @@ impl Resolution {
_ => vec![cast.source, cast.target], _ => vec![cast.source, cast.target],
}; };
let delay = event.delay(); let delay = event.delay(next_event);
Resolution { Resolution {
skill: cast.skill, skill: cast.skill,
delay, delay,
@ -928,11 +894,6 @@ impl Resolution {
event, event,
} }
} }
pub fn set_full_delay(&mut self) -> &mut Resolution {
self.delay = self.event.set_full_delay();
self
}
} }
pub type Disable = Vec<Effect>; pub type Disable = Vec<Effect>;
@ -960,27 +921,39 @@ pub enum Event {
} }
impl Event { impl Event {
fn delay(&self) -> i64 { fn delay(&self, next_event: Option<&Event>) -> i64 {
let target_delay = 500; // Add delay if theres source animation let source_overlapping = 500;
let combat_text_delay = 900; // Time for target animation let target_overlapping = 900;
let combat_text_duration = 1300; // Time for all post skill
match self {
Event::Cast { construct: _, direction: _, player: _ } => target_delay,
Event::Hit { construct: _, direction: _, player: _ } |
Event::HitAoe { construct: _ } => combat_text_delay,
_ => combat_text_duration,
}
}
fn set_full_delay(&self) -> i64 {
let source_duration = 1000; let source_duration = 1000;
let target_duration = 1500; let target_duration = 1500;
let combat_text_duration = 1300; let combat_text_duration = 1300;
match self { match self {
Event::Cast { construct: _, direction: _, player: _ } => source_duration, Event::Cast { construct: _, direction: _, player: _ } => {
match next_event {
Some(e) => {
match e {
Event::Cast { construct: _, direction: _, player: _ } => source_duration,
_ => source_overlapping,
}
},
None => source_duration
}
},
Event::Hit { construct: _, direction: _, player: _ } | Event::Hit { construct: _, direction: _, player: _ } |
Event::HitAoe { construct: _ } => target_duration, Event::HitAoe { construct: _ } => {
match next_event {
Some(e) => {
match e {
Event::Cast { construct: _, direction: _, player: _ } |
Event::Hit { construct: _, direction: _, player: _ } => target_duration,
_ => target_overlapping,
}
}
None => target_duration,
}
},
_ => combat_text_duration, _ => combat_text_duration,
} }
} }