From 433b20fdb5fed91aad1fa29347ffed085b6d2b14 Mon Sep 17 00:00:00 2001 From: ntr Date: Sat, 27 Oct 2018 17:53:05 +1100 Subject: [PATCH] remove unused fns --- server/src/game.rs | 44 ++++++++++++-------------------------------- server/src/rpc.rs | 2 +- 2 files changed, 13 insertions(+), 33 deletions(-) diff --git a/server/src/game.rs b/server/src/game.rs index 69f2d0ff..d40a03dc 100755 --- a/server/src/game.rs +++ b/server/src/game.rs @@ -37,13 +37,6 @@ impl Team { self } - fn update_cryp(&mut self, updated: Cryp) -> &mut Team { - let index = self.cryps.iter().position(|c| c.id == updated.id).unwrap(); - self.cryps.remove(index); - self.cryps.push(updated); - self - } - pub fn cryp_by_id(&mut self, id: Uuid) -> Option<&mut Cryp> { self.cryps.iter_mut().find(|c| c.id == id) } @@ -119,25 +112,13 @@ impl Game { } } - fn cryp_by_id(&mut self, id: Uuid) -> &mut Cryp { - for team in self.teams.iter_mut() { - let in_team = team.cryp_by_id(id); - if in_team.is_some() { - return in_team.unwrap(); - } - } - panic!("cryp not in game"); - } - - fn update_team(&mut self, updated: &mut Team) -> &mut Game { - match self.teams.iter().position(|t| t.id == updated.id) { - Some(index) => { - self.teams.remove(index); - self.teams.push(updated.clone()); - self - } - None => panic!("team not in game"), - } + fn cryp_by_id(&mut self, id: Uuid) -> Option<&mut Cryp> { + match self.teams.iter_mut().find(|t| t.cryps.iter().any(|c| c.id == id)) { + Some(team) => { + return team.cryps.iter_mut().find(|c| c.id == id); + }, + None => panic!("cryp not in game"), + }; } fn update_cryp(&mut self, cryp: &mut Cryp) -> &mut Game { @@ -202,8 +183,7 @@ impl Game { } { - let team = self.team_by_id(team_id); - let cryp = match team.cryp_by_id(source_cryp_id) { + let cryp = match self.cryp_by_id(source_cryp_id) { Some(c) => c, None => return Err(err_msg("cryp not in team")), }; @@ -331,8 +311,8 @@ impl Game { } for skill in self.skills.clone().iter_mut() { - let mut source = self.cryp_by_id(skill.source_cryp_id).clone(); - let mut target = self.cryp_by_id(skill.target_cryp_id.unwrap()).clone(); + let mut source = self.cryp_by_id(skill.source_cryp_id).unwrap().clone(); + let mut target = self.cryp_by_id(skill.target_cryp_id.unwrap()).unwrap().clone(); let resolution = skill.resolve(&mut source, &mut target); self.update_cryp(&mut source); @@ -349,7 +329,7 @@ impl Game { fn progress_cooldowns(&mut self) -> &mut Game { for skill in self.skills.clone().iter() { // copy the creep cause we will replace it - let mut cryp = self.cryp_by_id(skill.source_cryp_id).clone(); + let mut cryp = self.cryp_by_id(skill.source_cryp_id).unwrap().clone(); if skill.used_cooldown() { cryp.skill_set_cd(skill.skill); @@ -430,7 +410,7 @@ pub fn game_target(params: GameTargetParams, tx: &mut Transaction, account: &Acc let game_bytes: Vec = returned.get("data"); let mut game = from_slice::(&game_bytes)?; - game.add_target(account.id, params.cryp_id, params.cast_id)?; + game.add_target(account.id, params.cryp_id, params.skill_id)?; if game.target_phase_finished() { game.damage_phase_start(); diff --git a/server/src/rpc.rs b/server/src/rpc.rs index a7b3b08a..736560b2 100755 --- a/server/src/rpc.rs +++ b/server/src/rpc.rs @@ -355,7 +355,7 @@ struct GameTargetMsg { pub struct GameTargetParams { pub game_id: Uuid, pub cryp_id: Uuid, - pub cast_id: Uuid, + pub skill_id: Uuid, } #[derive(Debug,Clone,Serialize,Deserialize)]