handle charge attack packet. works for regular weapons and vjaya (#179)
Co-authored-by: Andy Newjack <andynewjack@protonmail.com>
This commit is contained in:
parent
b50d37cbb7
commit
e7bb51b045
@ -192,3 +192,21 @@ pub fn update_player_position(id: ClientId,
|
|||||||
} else {}
|
} else {}
|
||||||
Ok(Box::new(None.into_iter()))
|
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))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
@ -57,6 +57,7 @@ pub enum ShipError {
|
|||||||
InvalidQuest(u32),
|
InvalidQuest(u32),
|
||||||
InvalidQuestFilename(String),
|
InvalidQuestFilename(String),
|
||||||
IoError(#[from] std::io::Error),
|
IoError(#[from] std::io::Error),
|
||||||
|
NotEnoughMeseta(ClientId, u32),
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Debug)]
|
#[derive(Debug)]
|
||||||
@ -289,6 +290,9 @@ impl<EG: EntityGateway> ShipServerState<EG> {
|
|||||||
GameMessage::PlayerWarped(_) | GameMessage::PlayerChangedFloor(_) | GameMessage::InitializeSpeechNpc(_) => {
|
GameMessage::PlayerWarped(_) | GameMessage::PlayerChangedFloor(_) | GameMessage::InitializeSpeechNpc(_) => {
|
||||||
handler::message::update_player_position(id, &msg.msg, &mut self.clients, &mut self.client_location, &self.rooms)
|
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();
|
let cmsg = msg.clone();
|
||||||
Ok(Box::new(self.client_location.get_client_neighbors(id).unwrap().into_iter()
|
Ok(Box::new(self.client_location.get_client_neighbors(id).unwrap().into_iter()
|
||||||
|
Loading…
x
Reference in New Issue
Block a user