From e7bb51b0454512f6c16a32875438fe0753aae6b5 Mon Sep 17 00:00:00 2001 From: andy Date: Mon, 29 Jun 2020 22:40:26 -0400 Subject: [PATCH] handle charge attack packet. works for regular weapons and vjaya (#179) Co-authored-by: Andy Newjack --- src/ship/packet/handler/message.rs | 20 +++++++++++++++++++- src/ship/ship.rs | 4 ++++ 2 files changed, 23 insertions(+), 1 deletion(-) diff --git a/src/ship/packet/handler/message.rs b/src/ship/packet/handler/message.rs index 4dfeb7e..0637903 100644 --- a/src/ship/packet/handler/message.rs +++ b/src/ship/packet/handler/message.rs @@ -191,4 +191,22 @@ pub fn update_player_position(id: ClientId, } } else {} Ok(Box::new(None.into_iter())) -} \ No newline at end of file +} + +pub async fn charge_attack(id: ClientId, + charge: &ChargeAttack, + clients: &mut Clients, + entity_gateway: &mut EG) + -> Result + Send>, ShipError> +where + EG: EntityGateway +{ + let client = clients.get_mut(&id).ok_or(ShipError::ClientNotFound(id))?; + if client.character.meseta >= charge.meseta { + client.character.meseta -= charge.meseta; + entity_gateway.save_character(&client.character).await; + Ok(Box::new(None.into_iter())) + } else { + Err(ShipError::NotEnoughMeseta(id, client.character.meseta)) + } +} diff --git a/src/ship/ship.rs b/src/ship/ship.rs index 45f0fbc..0abc001 100644 --- a/src/ship/ship.rs +++ b/src/ship/ship.rs @@ -57,6 +57,7 @@ pub enum ShipError { InvalidQuest(u32), InvalidQuestFilename(String), IoError(#[from] std::io::Error), + NotEnoughMeseta(ClientId, u32), } #[derive(Debug)] @@ -289,6 +290,9 @@ impl ShipServerState { GameMessage::PlayerWarped(_) | GameMessage::PlayerChangedFloor(_) | GameMessage::InitializeSpeechNpc(_) => { handler::message::update_player_position(id, &msg.msg, &mut self.clients, &mut self.client_location, &self.rooms) }, + GameMessage::ChargeAttack(charge_attack) => { + handler::message::charge_attack(id, charge_attack, &mut self.clients, &mut self.entity_gateway).await + }, _ => { let cmsg = msg.clone(); Ok(Box::new(self.client_location.get_client_neighbors(id).unwrap().into_iter()