add to resolutions immediately
This commit is contained in:
parent
5ad13968d6
commit
2a63f26dc6
@ -575,93 +575,6 @@ impl Construct {
|
||||
}
|
||||
}
|
||||
|
||||
pub fn recharge(&mut self, red_amount: usize, blue_amount: usize) -> Vec<Event> {
|
||||
let mut events = vec![];
|
||||
if self.is_ko() { return events; }
|
||||
|
||||
match self.affected(Effect::Invert) {
|
||||
false => {
|
||||
// Do we need inversion?
|
||||
let current_red_life = self.red_life();
|
||||
self.red_life.increase(red_amount);
|
||||
let new_red_life = self.red_life.value;
|
||||
let red = new_red_life - current_red_life;
|
||||
|
||||
let current_blue_life = self.blue_life();
|
||||
self.blue_life.increase(blue_amount);
|
||||
let new_blue_life = self.blue_life.value;
|
||||
let blue = new_blue_life - current_blue_life;
|
||||
|
||||
if red != 0 || blue != 0 {
|
||||
events.push(Event::Recharge { construct: self.id, red, blue });
|
||||
}
|
||||
},
|
||||
true => {
|
||||
// Recharge takes a red and blue amount so check for them
|
||||
if red_amount != 0 {
|
||||
let red_mods = self.effects.iter()
|
||||
.filter(|e| e.effect.modifications().contains(&Stat::RedDamageTaken))
|
||||
.map(|e| (e.effect, e.meta))
|
||||
.collect::<Vec<(Effect, Option<EffectMeta>)>>();
|
||||
|
||||
let red_modified_power = red_mods.iter()
|
||||
.fold(red_amount, |acc, fx| fx.0.apply(acc, fx.1));
|
||||
|
||||
|
||||
let red_remainder = red_modified_power.saturating_sub(self.red_life.value);
|
||||
let red_mitigation = red_modified_power.saturating_sub(red_remainder);
|
||||
|
||||
// reduce red_life by mitigation amount
|
||||
self.red_life.reduce(red_mitigation);
|
||||
|
||||
// deal remainder to green_life
|
||||
let red_current_green_life = self.green_life();
|
||||
self.reduce_green_life(red_remainder);
|
||||
let red_damage_amount = red_current_green_life - self.green_life();
|
||||
|
||||
events.push(Event::Damage {
|
||||
construct: self.id,
|
||||
amount: red_damage_amount,
|
||||
mitigation: red_mitigation,
|
||||
colour: Colour::Red,
|
||||
display: EventConstruct::new(self),
|
||||
});
|
||||
}
|
||||
|
||||
if blue_amount != 0 {
|
||||
let blue_mods = self.effects.iter()
|
||||
.filter(|e| e.effect.modifications().contains(&Stat::BlueDamageTaken))
|
||||
.map(|e| (e.effect, e.meta))
|
||||
.collect::<Vec<(Effect, Option<EffectMeta>)>>();
|
||||
|
||||
let blue_modified_power = blue_mods.iter()
|
||||
.fold(blue_amount, |acc, fx| fx.0.apply(acc, fx.1));
|
||||
|
||||
|
||||
let blue_remainder = blue_modified_power.saturating_sub(self.blue_life.value);
|
||||
let blue_mitigation = blue_modified_power.saturating_sub(blue_remainder);
|
||||
|
||||
// reduce blue_life by mitigation amount
|
||||
self.blue_life.reduce(blue_mitigation);
|
||||
|
||||
// deal remainder to green_life
|
||||
let blue_current_green_life = self.green_life();
|
||||
self.reduce_green_life(blue_remainder);
|
||||
let blue_damage_amount = blue_current_green_life - self.green_life();
|
||||
|
||||
events.push(Event::Damage {
|
||||
construct: self.id,
|
||||
amount: blue_damage_amount,
|
||||
mitigation: blue_mitigation,
|
||||
colour: Colour::Blue,
|
||||
display: EventConstruct::new(self),
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
return events;
|
||||
}
|
||||
|
||||
pub fn deal_green_damage(&mut self, amount: usize) -> Vec<Event> {
|
||||
let mut events = vec![];
|
||||
if self.is_ko() { return events; }
|
||||
@ -715,6 +628,124 @@ impl Construct {
|
||||
return events;
|
||||
}
|
||||
|
||||
pub fn heal(&mut self, amount: usize, colour: Colour) -> Vec<Event> {
|
||||
let mut events = vec![];
|
||||
if self.is_ko() { return events; }
|
||||
let construct = self.id;
|
||||
|
||||
|
||||
// match self.affected(Effect::Invert) {
|
||||
// false => {
|
||||
// let current_red_life = self.red_life();
|
||||
// self.red_life.increase(red_amount);
|
||||
// let new_red_life = self.red_life.value;
|
||||
// let red = new_red_life - current_red_life;
|
||||
|
||||
// let current_blue_life = self.blue_life();
|
||||
// self.blue_life.increase(blue_amount);
|
||||
// let new_blue_life = self.blue_life.value;
|
||||
// let blue = new_blue_life - current_blue_life;
|
||||
|
||||
// if red != 0 || blue != 0 {
|
||||
// events.push(Event::Recharge { construct: self.id, red, blue });
|
||||
// }
|
||||
// },
|
||||
// true => {
|
||||
// // Recharge takes a red and blue amount so check for them
|
||||
// if red_amount != 0 {
|
||||
// let red_mods = self.effects.iter()
|
||||
// .filter(|e| e.effect.modifications().contains(&Stat::RedDamageTaken))
|
||||
// .map(|e| (e.effect, e.meta))
|
||||
// .collect::<Vec<(Effect, Option<EffectMeta>)>>();
|
||||
|
||||
// let red_modified_power = red_mods.iter()
|
||||
// .fold(red_amount, |acc, fx| fx.0.apply(acc, fx.1));
|
||||
|
||||
// let red_remainder = red_modified_power.saturating_sub(self.red_life.value);
|
||||
// let red_mitigation = red_modified_power.saturating_sub(red_remainder);
|
||||
|
||||
// // reduce red_life by mitigation amount
|
||||
// self.red_life.reduce(red_mitigation);
|
||||
|
||||
// // deal remainder to green_life
|
||||
// let red_current_green_life = self.green_life();
|
||||
// self.reduce_green_life(red_remainder);
|
||||
// let red_damage_amount = red_current_green_life - self.green_life();
|
||||
|
||||
// events.push(Event::Damage {
|
||||
// construct: self.id,
|
||||
// amount: red_damage_amount,
|
||||
// mitigation: red_mitigation,
|
||||
// colour: Colour::Red,
|
||||
// display: EventConstruct::new(self),
|
||||
// });
|
||||
// }
|
||||
|
||||
// if blue_amount != 0 {
|
||||
// let blue_mods = self.effects.iter()
|
||||
// .filter(|e| e.effect.modifications().contains(&Stat::BlueDamageTaken))
|
||||
// .map(|e| (e.effect, e.meta))
|
||||
// .collect::<Vec<(Effect, Option<EffectMeta>)>>();
|
||||
|
||||
// let blue_modified_power = blue_mods.iter()
|
||||
// .fold(blue_amount, |acc, fx| fx.0.apply(acc, fx.1));
|
||||
|
||||
|
||||
// let blue_remainder = blue_modified_power.saturating_sub(self.blue_life.value);
|
||||
// let blue_mitigation = blue_modified_power.saturating_sub(blue_remainder);
|
||||
|
||||
// // reduce blue_life by mitigation amount
|
||||
// self.blue_life.reduce(blue_mitigation);
|
||||
|
||||
// // deal remainder to green_life
|
||||
// let blue_current_green_life = self.green_life();
|
||||
// self.reduce_green_life(blue_remainder);
|
||||
// let blue_damage_amount = blue_current_green_life - self.green_life();
|
||||
|
||||
// events.push(Event::Damage {
|
||||
// construct: self.id,
|
||||
// amount: blue_damage_amount,
|
||||
// mitigation: blue_mitigation,
|
||||
// colour: Colour::Blue,
|
||||
// display: EventConstruct::new(self),
|
||||
// });
|
||||
// }
|
||||
// }
|
||||
|
||||
// match colour {
|
||||
// Colour::Red => {
|
||||
|
||||
// },
|
||||
// Colour::Green => {
|
||||
// let mods = self.effects.iter()
|
||||
// .filter(|e| e.effect.modifications().contains(&Stat::GreenDamageTaken))
|
||||
// .map(|e| (e.effect, e.meta))
|
||||
// .collect::<Vec<(Effect, Option<EffectMeta>)>>();
|
||||
|
||||
// let modified_power = mods.iter()
|
||||
// .fold(amount, |acc, fx| fx.0.apply(acc, fx.1));
|
||||
|
||||
// let current_green_life = self.green_life();
|
||||
// self.green_life.increase(modified_power);
|
||||
// let new_green_life = self.green_life.value;
|
||||
|
||||
// let healing = new_green_life - current_green_life;
|
||||
// let overhealing = modified_power - healing;
|
||||
|
||||
// events.push(Event::Healing {
|
||||
// construct,
|
||||
// amount: healing,
|
||||
// overhealing,
|
||||
// });
|
||||
// },
|
||||
// Colour::Blue => {
|
||||
|
||||
// },
|
||||
// }
|
||||
|
||||
return events;
|
||||
}
|
||||
|
||||
pub fn deal_red_damage(&mut self, amount: usize) -> Vec<Event> {
|
||||
let mut events = vec![];
|
||||
|
||||
|
||||
100
core/src/game.rs
100
core/src/game.rs
@ -468,6 +468,13 @@ impl Game {
|
||||
for cast in casts {
|
||||
self.execute(cast);
|
||||
}
|
||||
|
||||
// update to go through the whole most recent round and modify durations
|
||||
// let mut iter = event_list.into_iter().peekable();
|
||||
// while let Some(event) = iter.next() {
|
||||
// resolutions.push(Resolution::new(cast, event, iter.peek()));
|
||||
// }
|
||||
|
||||
self
|
||||
}
|
||||
|
||||
@ -504,6 +511,9 @@ impl Game {
|
||||
}
|
||||
|
||||
fn execute(&mut self, cast: Cast) -> &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() {
|
||||
@ -528,20 +538,17 @@ impl Game {
|
||||
};
|
||||
|
||||
for event in events {
|
||||
event_list.push(event); // ensure it goes into the list before doing extra processing
|
||||
// this event is now considered to have happened
|
||||
// for chronological ordering it is added to the resolution list
|
||||
// before extra processing on it begins
|
||||
let last = self.resolutions.len() - 1;
|
||||
self.resolutions[last].push(Resolution::new(cast, event.clone()));
|
||||
|
||||
event_list.push(event);
|
||||
self.event_reactions(&cast, &event_list[event_list.len() - 1]);
|
||||
}
|
||||
}
|
||||
|
||||
let mut resolutions = vec![];
|
||||
let mut iter = event_list.into_iter().peekable();
|
||||
|
||||
while let Some(event) = iter.next() {
|
||||
resolutions.push(Resolution::new(cast, event, iter.peek()));
|
||||
}
|
||||
|
||||
self.resolutions.last_mut().unwrap().append(&mut resolutions);
|
||||
|
||||
self
|
||||
}
|
||||
|
||||
@ -613,7 +620,9 @@ impl Game {
|
||||
|
||||
fn damage(&mut self, construct: Uuid, amount: usize, colour: Colour) -> Vec<Event> {
|
||||
match colour {
|
||||
_ => self.construct_by_id(construct).unwrap().deal_red_damage(amount) // fixme unwrap
|
||||
Colour::Red => self.construct_by_id(construct).unwrap().deal_red_damage(amount), // fixme unwrap
|
||||
Colour::Green => self.construct_by_id(construct).unwrap().deal_green_damage(amount), // fixme unwrap
|
||||
Colour::Blue => self.construct_by_id(construct).unwrap().deal_blue_damage(amount), // fixme unwrap
|
||||
}
|
||||
}
|
||||
|
||||
@ -859,7 +868,7 @@ pub struct Resolution {
|
||||
}
|
||||
|
||||
impl Resolution {
|
||||
pub fn new(cast: Cast, event: Event, next_event: Option<&Event>) -> Resolution {
|
||||
pub fn new(cast: Cast, event: Event) -> Resolution {
|
||||
|
||||
// maybe map events construct_ids
|
||||
let focus = match event {
|
||||
@ -867,7 +876,7 @@ impl Resolution {
|
||||
_ => vec![cast.source, cast.target],
|
||||
};
|
||||
|
||||
let delay = event.delay(next_event);
|
||||
let delay = event.delay(None);
|
||||
|
||||
Resolution {
|
||||
skill: cast.skill,
|
||||
@ -904,40 +913,41 @@ pub enum Event {
|
||||
|
||||
impl Event {
|
||||
fn delay(&self, next_event: Option<&Event>) -> i64 {
|
||||
let source_overlapping = 500;
|
||||
let target_overlapping = 900;
|
||||
900
|
||||
// let source_overlapping = 500;
|
||||
// let target_overlapping = 900;
|
||||
|
||||
let source_duration = 1000;
|
||||
let target_duration = 1500;
|
||||
let combat_text_duration = 1300;
|
||||
// let source_duration = 1000;
|
||||
// let target_duration = 1500;
|
||||
// let combat_text_duration = 1300;
|
||||
|
||||
match self {
|
||||
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::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,
|
||||
}
|
||||
// match self {
|
||||
// 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::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,
|
||||
// }
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user