From 40caa6ab3716d20d2366539d2e2c4048f2b3e601 Mon Sep 17 00:00:00 2001 From: ntr Date: Thu, 13 Dec 2018 14:25:50 +1100 Subject: [PATCH] fix logs for immunity and make bots target smarter --- server/src/game.rs | 55 ++++++++++++++++++++++++++++++++-------------- 1 file changed, 39 insertions(+), 16 deletions(-) diff --git a/server/src/game.rs b/server/src/game.rs index 7c06544b..fa3ec985 100644 --- a/server/src/game.rs +++ b/server/src/game.rs @@ -303,15 +303,26 @@ impl Game { let mobs = self.team_by_id(mob_team_id).clone(); // TODO attack multiple players based on some criteria - for incoming_skill_id in self.stack.clone().iter() + for (i, incoming_skill_id) in self.stack.clone().iter() .filter(|s| s.target_cryp_id.is_none() && s.target_team_id == mob_team_id) - .map(|s| s.id) { - let target_id = match mobs.cryps.iter().find(|c| { - self.cryp_targetable(mob_team_id, c.id).is_ok()}) - { - Some(c) => c.id, - None => panic!("could not find a targetable pve cryp"), - }; + .enumerate() + .map(|(i, s)| (i, s.id)) { + // let target_id = match mobs.cryps.iter().find(|c| { + // self.cryp_targetable(mob_team_id, c.id).is_ok()}) + // { + // Some(c) => c.id, + // None => panic!("could not find a targetable pve cryp"), + // }; + let targets = mobs.cryps + .iter() + .filter(|c| self.cryp_targetable(mob_team_id, c.id).is_ok()) + .collect::>(); + + if targets.len() == 0 { + panic!("could not find a targetable pve cryp"); + } + + let target_id = targets[i % targets.len()].id; self.add_target(mob_team_id, target_id, incoming_skill_id).unwrap(); } } @@ -418,17 +429,29 @@ impl Game { for result in cast.resolution.results.iter() { match result { - ResolutionResult::Damage { amount, category: _, immunity: _ } => { - self.log.push(format!("{:} {:?} {:} {:}", source.name, cast.skill, target.name, amount)); + ResolutionResult::Damage { amount, category: _, immunity } => { + match immunity.immune { + true => self.log.push(format!("{:} {:?} {:} immune {:?}", source.name, cast.skill, target.name, immunity.effects)), + false => self.log.push(format!("{:} {:?} {:} {:}", source.name, cast.skill, target.name, amount)), + } }, - ResolutionResult::Healing { amount, category: _, immunity: _ } => { - self.log.push(format!("{:} {:?} {:} {:}", source.name, cast.skill, target.name, amount)); + ResolutionResult::Healing { amount, category: _, immunity } => { + match immunity.immune { + true => self.log.push(format!("{:} {:?} {:} immune {:?}", source.name, cast.skill, target.name, immunity.effects)), + false => self.log.push(format!("{:} {:?} {:} {:}", source.name, cast.skill, target.name, amount)), + } }, - ResolutionResult::Effect { effect, duration, immunity: _ } => { - self.log.push(format!("{:} {:?} {:} {:?} {:}T", source.name, cast.skill, target.name, effect, duration)); + ResolutionResult::Effect { effect, duration, immunity } => { + match immunity.immune { + true => self.log.push(format!("{:} {:?} {:} immune {:?}", source.name, cast.skill, target.name, immunity.effects)), + false => self.log.push(format!("{:} {:?} {:} {:?} {:}T", source.name, cast.skill, target.name, effect, duration)), + } }, - ResolutionResult::Removal { effect, immunity: _ } => { - self.log.push(format!("{:?} removed {:} {:?}", source.name, target.name, effect)); + ResolutionResult::Removal { effect, immunity } => { + match immunity.immune { + true => self.log.push(format!("{:} {:?} {:} immune {:?}", source.name, cast.skill, target.name, immunity.effects)), + false => self.log.push(format!("{:?} removed {:} {:?}", source.name, target.name, effect)), + } }, } }