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

Co-authored-by: Andy Newjack <andynewjack@protonmail.com>
This commit is contained in:
andy 2020-06-29 22:40:26 -04:00 committed by jake
parent b50d37cbb7
commit e7bb51b045
2 changed files with 23 additions and 1 deletions

View File

@ -191,4 +191,22 @@ 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))
}
}

View File

@ -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()