Browse Source

handle charge attack packet. works for regular weapons and vjaya (#179)

Co-authored-by: Andy Newjack <andynewjack@protonmail.com>
pbs
andy 4 years ago
committed by jake
parent
commit
e7bb51b045
  1. 18
      src/ship/packet/handler/message.rs
  2. 4
      src/ship/ship.rs

18
src/ship/packet/handler/message.rs

@ -192,3 +192,21 @@ pub fn update_player_position(id: ClientId,
} else {}
Ok(Box::new(None.into_iter()))
}
pub async fn charge_attack<EG>(id: ClientId,
charge: &ChargeAttack,
clients: &mut Clients,
entity_gateway: &mut EG)
-> Result<Box<dyn Iterator<Item = (ClientId, SendShipPacket)> + 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))
}
}

4
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<EG: EntityGateway> ShipServerState<EG> {
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()

Loading…
Cancel
Save