remove finalise
This commit is contained in:
parent
ab2549219d
commit
d35e1ede60
@ -22,9 +22,6 @@ ensure all skills impl
|
|||||||
Skill::Slay -> red attack with bonus somethingorother for blue / maim no healing
|
Skill::Slay -> red attack with bonus somethingorother for blue / maim no healing
|
||||||
Hatred -> damage received converted into bonus dmg
|
Hatred -> damage received converted into bonus dmg
|
||||||
|
|
||||||
aoe
|
|
||||||
Skill::Ruin -> aoe stun
|
|
||||||
|
|
||||||
on attack
|
on attack
|
||||||
Skill::Taunt -> redirect incomnig attacks to self
|
Skill::Taunt -> redirect incomnig attacks to self
|
||||||
Skill::Toxic -> apply debuff to attackers
|
Skill::Toxic -> apply debuff to attackers
|
||||||
|
|||||||
@ -168,17 +168,6 @@ impl Game {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn cryp_name(&mut self, id: Uuid) -> String {
|
|
||||||
match self.teams.iter_mut().find(|t| t.cryps.iter().any(|c| c.id == id)) {
|
|
||||||
Some(team) => {
|
|
||||||
let cryp = team.cryps.iter_mut().find(|c| c.id == id).expect("cryp not in team");
|
|
||||||
return cryp.name.clone();
|
|
||||||
}
|
|
||||||
None => panic!("{:?} not in game", id),
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
fn all_cryps(&self) -> Vec<Cryp> {
|
fn all_cryps(&self) -> Vec<Cryp> {
|
||||||
self.teams.clone()
|
self.teams.clone()
|
||||||
.into_iter()
|
.into_iter()
|
||||||
@ -188,16 +177,6 @@ impl Game {
|
|||||||
.collect::<Vec<Cryp>>()
|
.collect::<Vec<Cryp>>()
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn cryp_aoe_targets(&self, cryp_id: Uuid) -> Vec<Uuid> {
|
|
||||||
self.teams.iter()
|
|
||||||
.find(|t| t.cryps.iter().any(|c| c.id == cryp_id))
|
|
||||||
.unwrap()
|
|
||||||
.cryps
|
|
||||||
.iter()
|
|
||||||
.map(|c| c.id)
|
|
||||||
.collect()
|
|
||||||
}
|
|
||||||
|
|
||||||
fn update_cryp(&mut self, cryp: &mut Cryp) -> &mut Game {
|
fn update_cryp(&mut self, cryp: &mut Cryp) -> &mut Game {
|
||||||
match self.teams.iter_mut().find(|t| t.cryps.iter().any(|c| c.id == cryp.id)) {
|
match self.teams.iter_mut().find(|t| t.cryps.iter().any(|c| c.id == cryp.id)) {
|
||||||
Some(team) => {
|
Some(team) => {
|
||||||
@ -372,79 +351,47 @@ impl Game {
|
|||||||
self.resolve_skills()
|
self.resolve_skills()
|
||||||
}
|
}
|
||||||
|
|
||||||
// remove names from the cast
|
|
||||||
// put them in teh result
|
|
||||||
// just add the results to the resolved vec
|
|
||||||
// try remove casts altogether
|
|
||||||
|
|
||||||
fn log_resolution(&mut self, cast: &Cast) -> &mut Game {
|
|
||||||
for resolution in cast.resolutions.iter() {
|
|
||||||
let Resolution { source, target, event } = resolution;
|
|
||||||
match event {
|
|
||||||
Event::Disable { disable } =>
|
|
||||||
self.log.push(format!("{:} {:?} {:} disabled {:?}",
|
|
||||||
source.name, cast.skill, target.name, disable)),
|
|
||||||
|
|
||||||
Event::Immunity { immunity } =>
|
|
||||||
self.log.push(format!("[{:}] {:} {:?} {:} immune {:?}",
|
|
||||||
cast.speed, source.name, cast.skill, target.name, immunity)),
|
|
||||||
|
|
||||||
Event::TargetKo =>
|
|
||||||
self.log.push(format!("[{:}] {:} {:?} {:} - KO",
|
|
||||||
cast.speed, source.name, cast.skill, target.name)),
|
|
||||||
|
|
||||||
Event::Damage { amount, mitigation, category: _ } =>
|
|
||||||
self.log.push(format!("[{:}] {:} {:?} {:} {:} ({:} mitigated)",
|
|
||||||
cast.speed, source.name, cast.skill, target.name, amount, mitigation)),
|
|
||||||
|
|
||||||
Event::Healing { amount, overhealing } =>
|
|
||||||
self.log.push(format!("[{:}] {:} {:?} {:} {:} ({:}OH)",
|
|
||||||
cast.speed, source.name, cast.skill, target.name, amount, overhealing)),
|
|
||||||
|
|
||||||
Event::Inversion { healing, damage, recharge, category: _ } => {
|
|
||||||
match *healing > 0 {
|
|
||||||
true => self.log.push(format!("[{:}] {:} {:?} {:} INVERTED {:} ({:} recharge)",
|
|
||||||
cast.speed, source.name, cast.skill, target.name, healing, recharge)),
|
|
||||||
false => self.log.push(format!("[{:}] {:} {:?} {:} INVERTED {:}",
|
|
||||||
cast.speed, source.name, cast.skill, target.name, damage)),
|
|
||||||
}
|
|
||||||
},
|
|
||||||
|
|
||||||
Event::Effect { effect, duration } =>
|
|
||||||
self.log.push(format!("[{:}] {:} {:?} {:} {:?} {:}T",
|
|
||||||
cast.speed, source.name, cast.skill, target.name, effect, duration)),
|
|
||||||
|
|
||||||
Event::Removal { effect } =>
|
|
||||||
self.log.push(format!("[{:}] {:?} removed {:} {:?}",
|
|
||||||
cast.speed, source.name, target.name, effect)),
|
|
||||||
|
|
||||||
Event::Recharge { red, blue } =>
|
|
||||||
self.log.push(format!("[{:}] {:} {:?} {:} {:}R {:}B",
|
|
||||||
cast.speed, source.name, cast.skill, target.name, red, blue)),
|
|
||||||
|
|
||||||
Event::Evasion { skill: _, evasion_rating } =>
|
|
||||||
self.log.push(format!("[{:}] {:} {:?} {:} evaded ({:}%)",
|
|
||||||
cast.speed, source.name, cast.skill, target.name, evasion_rating)),
|
|
||||||
|
|
||||||
Event::Incomplete => panic!("incomplete resolution {:?}", resolution),
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
self
|
|
||||||
}
|
|
||||||
|
|
||||||
fn stack_sort_speed(&mut self) -> &mut Game {
|
fn stack_sort_speed(&mut self) -> &mut Game {
|
||||||
let mut sorted = self.stack.clone();
|
let mut sorted = self.stack.clone();
|
||||||
sorted.sort_unstable_by_key(|s| -> u64 {
|
sorted.iter_mut()
|
||||||
|
.for_each(|s| {
|
||||||
let caster = self.cryp_by_id(s.source_cryp_id).unwrap();
|
let caster = self.cryp_by_id(s.source_cryp_id).unwrap();
|
||||||
caster.skill_speed(s.skill)
|
let speed = caster.skill_speed(s.skill);
|
||||||
|
s.speed = speed;
|
||||||
});
|
});
|
||||||
|
|
||||||
|
sorted.sort_unstable_by_key(|s| s.speed);
|
||||||
|
|
||||||
self.stack = sorted;
|
self.stack = sorted;
|
||||||
|
|
||||||
self
|
self
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn cryp_aoe_targets(&self, cryp_id: Uuid) -> Vec<Uuid> {
|
||||||
|
self.teams.iter()
|
||||||
|
.find(|t| t.cryps.iter().any(|c| c.id == cryp_id))
|
||||||
|
.unwrap()
|
||||||
|
.cryps
|
||||||
|
.iter()
|
||||||
|
.map(|c| c.id)
|
||||||
|
.collect()
|
||||||
|
}
|
||||||
|
|
||||||
|
fn get_targets(&self, skill: Skill, source: &Cryp, target_cryp_id: Uuid) -> Vec<Uuid> {
|
||||||
|
// match self.teams.iter_mut().find(|t| t.cryps.iter().any(|c| c.id == id)) {
|
||||||
|
// Some(team) => team.cryps.iter_mut().find(|c| c.id == id),
|
||||||
|
// None => None,
|
||||||
|
// }
|
||||||
|
|
||||||
|
// let target_team = self.teams.iter_mut().find(|t| t.cryps.iter().any(|c| c.id == id)).unwrap();
|
||||||
|
// let target = team.cryps.iter_mut().find(|c| c.id == id).unwrap();
|
||||||
|
|
||||||
|
match source.skill_is_aoe(skill) {
|
||||||
|
true => self.cryp_aoe_targets(target_cryp_id),
|
||||||
|
false => vec![target_cryp_id],
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
fn resolve_skills(mut self) -> Game {
|
fn resolve_skills(mut self) -> Game {
|
||||||
if self.phase != Phase::Resolve {
|
if self.phase != Phase::Resolve {
|
||||||
panic!("game not in Resolve phase");
|
panic!("game not in Resolve phase");
|
||||||
@ -469,35 +416,31 @@ impl Game {
|
|||||||
// because need to check cooldown use before pushing them into the complete list
|
// because need to check cooldown use before pushing them into the complete list
|
||||||
let mut resolving = vec![];
|
let mut resolving = vec![];
|
||||||
|
|
||||||
while let Some(mut cast) = self.stack.pop() {
|
while let Some(cast) = self.stack.pop() {
|
||||||
// println!("{:} resolving ", cast);
|
// println!("{:} resolving ", cast);
|
||||||
|
|
||||||
cast.finalise(&mut self);
|
let mut resolutions = vec![];
|
||||||
|
let mut source = self.cryp_by_id(cast.source_cryp_id).unwrap().clone();
|
||||||
|
|
||||||
self.log_resolution(&cast);
|
let targets = self.get_targets(cast.skill, &source, cast.target_cryp_id);
|
||||||
|
for target_id in targets {
|
||||||
|
// let mut source = game.cryp_by_id(self.source_cryp_id).unwrap();
|
||||||
|
let mut target = self.cryp_by_id(target_id).unwrap();
|
||||||
|
resolutions.append(&mut cast.skill.resolve(&mut source, target));
|
||||||
|
}
|
||||||
|
|
||||||
|
while let Some(resolution) = resolutions.pop() {
|
||||||
|
// fixme for mash
|
||||||
|
self.log_resolution(cast.speed, cast.skill, &resolution);
|
||||||
// the results go into the resolutions
|
// the results go into the resolutions
|
||||||
self.resolved.append(&mut cast.resolutions);
|
self.resolved.push(resolution);
|
||||||
|
}
|
||||||
|
|
||||||
// the cast itself goes into this temp vec
|
// the cast itself goes into this temp vec
|
||||||
// to handle cooldowns
|
// to handle cooldowns
|
||||||
resolving.push(cast);
|
resolving.push(cast);
|
||||||
|
|
||||||
// if target.is_ko() && !target.ko_logged {
|
// sort the stack again in case speeds have changed
|
||||||
// self.log.push(format!("{:} KO", target.name));
|
|
||||||
// target.effects.clear();
|
|
||||||
// target.ko_logged = true;
|
|
||||||
// }
|
|
||||||
|
|
||||||
// if source.is_ko() && !source.ko_logged {
|
|
||||||
// self.log.push(format!("{:} KO", source.name));
|
|
||||||
// source.effects.clear();
|
|
||||||
// source.ko_logged = true;
|
|
||||||
// }
|
|
||||||
|
|
||||||
// self.update_cryp(&mut source);
|
|
||||||
// self.update_cryp(&mut target);
|
|
||||||
|
|
||||||
self.stack_sort_speed();
|
self.stack_sort_speed();
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -543,6 +486,60 @@ impl Game {
|
|||||||
self
|
self
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn log_resolution(&mut self, speed: u64, skill: Skill, resolution: &Resolution) -> &mut Game {
|
||||||
|
let Resolution { source, target, event } = resolution;
|
||||||
|
match event {
|
||||||
|
Event::Disable { disable } =>
|
||||||
|
self.log.push(format!("{:} {:?} {:} disabled {:?}",
|
||||||
|
source.name, skill, target.name, disable)),
|
||||||
|
|
||||||
|
Event::Immunity { immunity } =>
|
||||||
|
self.log.push(format!("[{:}] {:} {:?} {:} immune {:?}",
|
||||||
|
speed, source.name, skill, target.name, immunity)),
|
||||||
|
|
||||||
|
Event::TargetKo =>
|
||||||
|
self.log.push(format!("[{:}] {:} {:?} {:} - KO",
|
||||||
|
speed, source.name, skill, target.name)),
|
||||||
|
|
||||||
|
Event::Damage { amount, mitigation, category: _ } =>
|
||||||
|
self.log.push(format!("[{:}] {:} {:?} {:} {:} ({:} mitigated)",
|
||||||
|
speed, source.name, skill, target.name, amount, mitigation)),
|
||||||
|
|
||||||
|
Event::Healing { amount, overhealing } =>
|
||||||
|
self.log.push(format!("[{:}] {:} {:?} {:} {:} ({:}OH)",
|
||||||
|
speed, source.name, skill, target.name, amount, overhealing)),
|
||||||
|
|
||||||
|
Event::Inversion { healing, damage, recharge, category: _ } => {
|
||||||
|
match *healing > 0 {
|
||||||
|
true => self.log.push(format!("[{:}] {:} {:?} {:} INVERTED {:} ({:} recharge)",
|
||||||
|
speed, source.name, skill, target.name, healing, recharge)),
|
||||||
|
false => self.log.push(format!("[{:}] {:} {:?} {:} INVERTED {:}",
|
||||||
|
speed, source.name, skill, target.name, damage)),
|
||||||
|
}
|
||||||
|
},
|
||||||
|
|
||||||
|
Event::Effect { effect, duration } =>
|
||||||
|
self.log.push(format!("[{:}] {:} {:?} {:} {:?} {:}T",
|
||||||
|
speed, source.name, skill, target.name, effect, duration)),
|
||||||
|
|
||||||
|
Event::Removal { effect } =>
|
||||||
|
self.log.push(format!("[{:}] {:?} removed {:} {:?}",
|
||||||
|
speed, source.name, target.name, effect)),
|
||||||
|
|
||||||
|
Event::Recharge { red, blue } =>
|
||||||
|
self.log.push(format!("[{:}] {:} {:?} {:} {:}R {:}B",
|
||||||
|
speed, source.name, skill, target.name, red, blue)),
|
||||||
|
|
||||||
|
Event::Evasion { skill: _, evasion_rating } =>
|
||||||
|
self.log.push(format!("[{:}] {:} {:?} {:} evaded ({:}%)",
|
||||||
|
speed, source.name, skill, target.name, evasion_rating)),
|
||||||
|
|
||||||
|
Event::Incomplete => panic!("incomplete resolution {:?}", resolution),
|
||||||
|
}
|
||||||
|
|
||||||
|
self
|
||||||
|
}
|
||||||
|
|
||||||
pub fn finished(&self) -> bool {
|
pub fn finished(&self) -> bool {
|
||||||
self.teams.iter().any(|t| t.cryps.iter().all(|c| c.is_ko()))
|
self.teams.iter().any(|t| t.cryps.iter().all(|c| c.is_ko()))
|
||||||
}
|
}
|
||||||
@ -1141,7 +1138,7 @@ mod tests {
|
|||||||
assert!(effect == Effect::Ruin);
|
assert!(effect == Effect::Ruin);
|
||||||
assert!(duration == 1);
|
assert!(duration == 1);
|
||||||
}
|
}
|
||||||
_ => panic!("result was not recharge"),
|
_ => panic!("ruin result not effect"),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -33,26 +33,6 @@ impl Cast {
|
|||||||
Cast::new(source.id, source.account, target.id, skill)
|
Cast::new(source.id, source.account, target.id, skill)
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn finalise(&mut self, game: &mut Game) -> &mut Cast {
|
|
||||||
let mut results = vec![];
|
|
||||||
let mut source = game.cryp_by_id(self.source_cryp_id).unwrap().clone();
|
|
||||||
self.speed = source.skill_speed(self.skill);
|
|
||||||
|
|
||||||
let targets = match source.skill_is_aoe(self.skill) {
|
|
||||||
true => game.cryp_aoe_targets(self.target_cryp_id),
|
|
||||||
false => vec![self.target_cryp_id],
|
|
||||||
};
|
|
||||||
|
|
||||||
for target_id in targets {
|
|
||||||
// let mut source = game.cryp_by_id(self.source_cryp_id).unwrap();
|
|
||||||
let mut target = game.cryp_by_id(target_id).unwrap();
|
|
||||||
results.append(&mut self.skill.resolve(&mut source, target));
|
|
||||||
}
|
|
||||||
|
|
||||||
self.resolutions = results;
|
|
||||||
self
|
|
||||||
}
|
|
||||||
|
|
||||||
pub fn used_cooldown(&self) -> bool {
|
pub fn used_cooldown(&self) -> bool {
|
||||||
return self.skill.base_cd().is_some();
|
return self.skill.base_cd().is_some();
|
||||||
}
|
}
|
||||||
@ -615,16 +595,6 @@ impl Skill {
|
|||||||
return results;
|
return results;
|
||||||
}
|
}
|
||||||
|
|
||||||
// match self.category() == Category::Red {
|
|
||||||
// true => {
|
|
||||||
// if let Some(evasion) = target.evade(*self) {
|
|
||||||
// results.push(evasion);
|
|
||||||
// return Event;
|
|
||||||
// }
|
|
||||||
// },
|
|
||||||
// false => (),
|
|
||||||
// }
|
|
||||||
|
|
||||||
if target.is_ko() {
|
if target.is_ko() {
|
||||||
results.push(Resolution::new(source, target).event(Event::TargetKo));
|
results.push(Resolution::new(source, target).event(Event::TargetKo));
|
||||||
return results;
|
return results;
|
||||||
@ -638,6 +608,29 @@ impl Skill {
|
|||||||
return self.resolve(target, source);
|
return self.resolve(target, source);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// match self.category() == Category::Red {
|
||||||
|
// true => {
|
||||||
|
// if let Some(evasion) = target.evade(*self) {
|
||||||
|
// results.push(evasion);
|
||||||
|
// return Event;
|
||||||
|
// }
|
||||||
|
// },
|
||||||
|
// false => (),
|
||||||
|
// }
|
||||||
|
|
||||||
|
// if target.is_ko() && !target.ko_logged {
|
||||||
|
// self.log.push(format!("{:} KO", target.name));
|
||||||
|
// target.effects.clear();
|
||||||
|
// target.ko_logged = true;
|
||||||
|
// }
|
||||||
|
|
||||||
|
// if source.is_ko() && !source.ko_logged {
|
||||||
|
// self.log.push(format!("{:} KO", source.name));
|
||||||
|
// source.effects.clear();
|
||||||
|
// source.ko_logged = true;
|
||||||
|
// }
|
||||||
|
|
||||||
|
|
||||||
match self {
|
match self {
|
||||||
Skill::Amplify => amplify(source, target, results), // increase magic damage
|
Skill::Amplify => amplify(source, target, results), // increase magic damage
|
||||||
Skill::Attack => attack(source, target, results),
|
Skill::Attack => attack(source, target, results),
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user