This commit is contained in:
ntr 2019-12-10 22:30:09 +10:00
parent 1739045f2c
commit 2bb9482bc5

View File

@ -120,6 +120,16 @@ impl Game {
}
}
pub fn construct(&self, id: Uuid) -> &Construct {
self.players.iter()
.find(|t| t.constructs.iter().any(|c| c.id == id))
.unwrap()
.constructs
.iter()
.find(|c| c.id == id)
.unwrap()
}
fn all_constructs(&self) -> Vec<Construct> {
self.players.clone()
.into_iter()
@ -485,13 +495,6 @@ impl Game {
return vec![Cast { target: t.id, ..cast }];
}
// if self.construct[source].multistrike() {
// return vec![
// Cast { target: t.id, ..cast },
// Cast { target: t.id, ..cast },
// ];
// }
let casts = match cast.skill.aoe() {
true => self.players.iter()
.find(|t| t.constructs.iter().any(|c| c.id == cast.target))
@ -514,6 +517,23 @@ impl Game {
// such as healing based on damage done etc
let mut event_list = vec![];
if self.construct(cast.target).is_ko() {
self.add_resolution(&cast, &Event::TargetKo { construct: cast.target });
return self;
}
if self.construct(cast.target).affected(Effect::Reflect) && cast.skill.colours().contains(&Colour::Blue) && !cast.skill.is_tick() {
self.add_resolution(&cast, &Event::Reflection { construct: cast.target });
// both reflecting, show it and bail
if self.construct(cast.source).affected(Effect::Reflect) {
self.add_resolution(&cast, &Event::Reflection { construct: cast.source });
return self;
}
return self.execute(Cast { target: cast.source, ..cast });
}
for action in cast.actions() {
let events = match action {
Action::Cast => self.cast(cast),
@ -529,19 +549,17 @@ impl Game {
self.heal(construct, amount, colour)
},
Action::Effect { construct, effect } => self.effect(construct, effect),
Action::Remove { construct, effect } => self.effect_remove(construct, effect),
Action::RemoveAll { construct } => self.remove_all(construct),
Action::IncreaseCooldowns { construct, turns } => self.increase_cooldowns(construct, turns),
Action::Effect { construct, effect } => self.effect(construct, effect),
Action::Remove { construct, effect } => self.effect_remove(construct, effect),
Action::RemoveAll { construct } => self.remove_all(construct),
Action::IncreaseCooldowns { construct, turns } => self.increase_cooldowns(construct, turns),
};
for event in events {
// 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()));
self.add_resolution(&cast, &event);
event_list.push(event);
self.event_reactions(&cast, &event_list[event_list.len() - 1]);
}
@ -550,6 +568,12 @@ impl Game {
self
}
fn add_resolution(&mut self, cast: &Cast, event: &Event) -> &mut Game {
let last = self.resolutions.len() - 1;
self.resolutions[last].push(Resolution::new(cast.clone(), event.clone()));
self
}
fn event_reactions(&mut self, cast: &Cast, event: &Event) -> &mut Game {
let casts = match event {
Event::Damage { construct, colour, amount, mitigation, display: _ } =>
@ -898,11 +922,14 @@ pub enum Event {
Healing { construct: Uuid, amount: usize, overhealing: usize, colour: Colour, display: EventConstruct },
Inversion { construct: Uuid },
Reflection { construct: Uuid },
Ko { construct: Uuid },
Disable { construct: Uuid, effects: Vec<Effect> },
TargetKo { construct: Uuid },
Ko { construct: Uuid },
CooldownIncrease { construct: Uuid, turns: usize },
CooldownDecrease { construct: Uuid, turns: usize },
Forfeit (),
}