update effects during combat anim loop

This commit is contained in:
Mashy 2019-05-31 13:27:23 +10:00
parent 6d9e13598c
commit 6295d8888e
4 changed files with 26 additions and 19 deletions

View File

@ -228,9 +228,10 @@ function eventClasses(resolution, construct) {
} }
if (type === 'Effect') { if (type === 'Effect') {
const { skill, effect, duration } = event; const { skill, effect, duration, construct_effects: constructEffects } = event;
if (source && startSkill) return 'active-skill'; if (source && startSkill) return 'active-skill';
if (target && endSkill) return 'active-skill'; if (target && endSkill) return 'active-skill';
if (target && postSkill) construct.effects = constructEffects;
} }
if (type === 'Skill') { if (type === 'Skill') {
@ -241,7 +242,10 @@ function eventClasses(resolution, construct) {
} }
if (type === 'Removal') { if (type === 'Removal') {
const { effect } = event; const { effect, construct_effects: constructEffects } = event;
if (source && startSkill) return 'active-skill';
if (target && endSkill) return 'active-skill';
if (target && postSkill) construct.effects = constructEffects;
} }
if (type === 'Recharge') { if (type === 'Recharge') {

View File

@ -757,13 +757,6 @@ impl Construct {
}; };
} }
// todo modified durations cause of buffs
let result = Event::Effect {
effect: effect.effect,
duration: effect.duration,
skill,
};
if let Some(p) = self.effects.iter().position(|ce| ce.effect == effect.effect) { if let Some(p) = self.effects.iter().position(|ce| ce.effect == effect.effect) {
// duplicate effect // duplicate effect
// replace existing // replace existing
@ -775,6 +768,13 @@ impl Construct {
self.effects.push(effect); self.effects.push(effect);
} }
// todo modified durations cause of buffs
let result = Event::Effect {
effect: effect.effect,
duration: effect.duration,
construct_effects: self.effects.clone(),
skill,
};
return result; return result;
} }

View File

@ -528,7 +528,7 @@ impl Game {
self.log.push(format!("[{:}] {:} {:?} {:} REFLECTED", self.log.push(format!("[{:}] {:} {:?} {:} REFLECTED",
speed, source.name, skill, target.name)), speed, source.name, skill, target.name)),
Event::Effect { skill, effect, duration } => Event::Effect { skill, effect, duration, construct_effects: _ } =>
self.log.push(format!("[{:}] {:} {:?} {:} {:?} {:}T", self.log.push(format!("[{:}] {:} {:?} {:} {:?} {:}T",
speed, source.name, skill, target.name, effect, duration)), speed, source.name, skill, target.name, effect, duration)),
@ -540,7 +540,7 @@ impl Game {
self.log.push(format!("[{:}] {:} {:?} {:}", self.log.push(format!("[{:}] {:} {:?} {:}",
speed, source.name, skill, target.name)), speed, source.name, skill, target.name)),
Event::Removal { effect } => Event::Removal { effect, construct_effects: _ } =>
self.log.push(format!("[{:}] {:?} removed {:} {:?}", self.log.push(format!("[{:}] {:?} removed {:} {:?}",
speed, source.name, target.name, effect)), speed, source.name, target.name, effect)),
@ -1265,7 +1265,7 @@ mod tests {
let Resolution { source: _, target: _, event } = game.resolved.pop().unwrap(); let Resolution { source: _, target: _, event } = game.resolved.pop().unwrap();
match event { match event {
Event::Effect { effect, skill: _, duration: _ } => assert_eq!(effect, Effect::Scatter), Event::Effect { effect, skill: _, duration: _, construct_effects: _ } => assert_eq!(effect, Effect::Scatter),
_ => panic!("not siphon"), _ => panic!("not siphon"),
}; };
@ -1357,7 +1357,7 @@ mod tests {
let Resolution { source, target: _, event } = r; let Resolution { source, target: _, event } = r;
match source.id == x_construct.id { match source.id == x_construct.id {
true => match event { true => match event {
Event::Effect { effect, duration, skill: _ } => { Event::Effect { effect, duration, skill: _, construct_effects: _ } => {
assert!(*effect == Effect::Stun); assert!(*effect == Effect::Stun);
assert!(*duration == 1); assert!(*duration == 1);
true true

View File

@ -437,10 +437,10 @@ pub enum Event {
Recharge { skill: Skill, red: u64, blue: u64 }, Recharge { skill: Skill, red: u64, blue: u64 },
Inversion { skill: Skill }, Inversion { skill: Skill },
Reflection { skill: Skill }, Reflection { skill: Skill },
Effect { skill: Skill, effect: Effect, duration: u8 },
AoeSkill { skill: Skill }, AoeSkill { skill: Skill },
Skill { skill: Skill }, Skill { skill: Skill },
Removal { effect: Effect }, Effect { skill: Skill, effect: Effect, duration: u8, construct_effects: Vec<ConstructEffect> },
Removal { effect: Effect, construct_effects: Vec<ConstructEffect> },
TargetKo { skill: Skill }, TargetKo { skill: Skill },
// skill not necessary but makes it neater as all events are arrays in js // skill not necessary but makes it neater as all events are arrays in js
Ko { skill: Skill }, Ko { skill: Skill },
@ -1539,7 +1539,8 @@ fn strangle_tick(source: &mut Construct, target: &mut Construct, mut results: Re
.position(|e| e.effect == Effect::Strangling) .position(|e| e.effect == Effect::Strangling)
.expect("no strangling on construct"); .expect("no strangling on construct");
source.effects.remove(i); source.effects.remove(i);
results.push(Resolution::new(source, source).event(Event::Removal { effect: Effect::Strangling })); results.push(Resolution::new(source, source)
.event(Event::Removal { effect: Effect::Strangling, construct_effects: target.effects.clone() }));
} }
return results; return results;
@ -1877,7 +1878,8 @@ fn purge(source: &mut Construct, target: &mut Construct, mut results: Resolution
.iter() .iter()
.position(|ce| ce.effect.category() == EffectCategory::Buff) { .position(|ce| ce.effect.category() == EffectCategory::Buff) {
let ce = target.effects.remove(i); let ce = target.effects.remove(i);
results.push(Resolution::new(source, target).event(Event::Removal { effect: ce.effect })); results.push(Resolution::new(source, target)
.event(Event::Removal { effect: ce.effect, construct_effects: target.effects.clone() }));
} }
return results; return results;
@ -1890,7 +1892,8 @@ fn purify(source: &mut Construct, target: &mut Construct, mut results: Resolutio
.iter() .iter()
.position(|ce| ce.effect.category() == EffectCategory::Debuff) { .position(|ce| ce.effect.category() == EffectCategory::Debuff) {
let ce = target.effects.remove(i); let ce = target.effects.remove(i);
results.push(Resolution::new(source, target).event(Event::Removal { effect: ce.effect })); results.push(Resolution::new(source, target)
.event(Event::Removal { effect: ce.effect, construct_effects: target.effects.clone() }));
target.deal_green_damage(skill, amount) target.deal_green_damage(skill, amount)
.into_iter() .into_iter()
.for_each(|e| results.push(Resolution::new(source, target).event(e))); .for_each(|e| results.push(Resolution::new(source, target).event(e)));
@ -2092,7 +2095,7 @@ mod tests {
let Resolution { source: _, target: _, event } = results.remove(0); let Resolution { source: _, target: _, event } = results.remove(0);
match event { match event {
Event::Effect { effect, skill: _, duration: _ } => assert_eq!(effect, Effect::Siphon), Event::Effect { effect, skill: _, duration: _, construct_effects: _ } => assert_eq!(effect, Effect::Siphon),
_ => panic!("not siphon"), _ => panic!("not siphon"),
}; };