|
|
@ -1,14 +1,15 @@ |
|
|
|
use libpso::packet::ship::*;
|
|
|
|
use libpso::packet::messages::*;
|
|
|
|
use crate::entity::gateway::EntityGateway;
|
|
|
|
use crate::entity::item::Meseta;
|
|
|
|
use crate::common::serverstate::ClientId;
|
|
|
|
use crate::common::leveltable::CharacterLevelTable;
|
|
|
|
use crate::ship::ship::{SendShipPacket, ShipError, Rooms, Clients, ItemDropLocation};
|
|
|
|
use crate::ship::location::{ClientLocation, ClientLocationError};
|
|
|
|
use crate::ship::items::{ItemManager, ClientItemId};
|
|
|
|
use crate::ship::items::ClientItemId;
|
|
|
|
use crate::ship::packet::builder;
|
|
|
|
use crate::ship::items::state::ItemState;
|
|
|
|
use crate::ship::items::actions::{drop_item, drop_partial_item, drop_meseta, equip_item, unequip_item, sort_inventory, use_item, feed_mag, sell_item};
|
|
|
|
use crate::ship::items::actions::{drop_item, drop_partial_item, drop_meseta, equip_item, unequip_item, sort_inventory, use_item, feed_mag, sell_item, take_meseta};
|
|
|
|
|
|
|
|
pub async fn request_exp<EG: EntityGateway>(id: ClientId,
|
|
|
|
request_exp: &RequestExp,
|
|
|
@ -257,25 +258,25 @@ pub fn update_player_position(id: ClientId, |
|
|
|
}
|
|
|
|
|
|
|
|
pub async fn charge_attack<EG>(id: ClientId,
|
|
|
|
charge: &ChargeAttack,
|
|
|
|
clients: &mut Clients,
|
|
|
|
entity_gateway: &mut EG,
|
|
|
|
item_manager: &mut ItemManager)
|
|
|
|
-> Result<Box<dyn Iterator<Item = (ClientId, SendShipPacket)> + Send>, anyhow::Error>
|
|
|
|
charge: &ChargeAttack,
|
|
|
|
entity_gateway: &mut EG,
|
|
|
|
client_location: &ClientLocation,
|
|
|
|
clients: &mut Clients,
|
|
|
|
item_state: &mut ItemState)
|
|
|
|
-> Result<Box<dyn Iterator<Item = (ClientId, SendShipPacket)> + Send>, anyhow::Error>
|
|
|
|
where
|
|
|
|
EG: EntityGateway
|
|
|
|
{
|
|
|
|
let client = clients.get_mut(&id).ok_or(ShipError::ClientNotFound(id))?;
|
|
|
|
let meseta = item_manager.get_character_meseta_mut(&client.character.id)?;
|
|
|
|
|
|
|
|
if meseta.0 >= charge.meseta {
|
|
|
|
meseta.0 -= charge.meseta;
|
|
|
|
entity_gateway.set_character_meseta(&client.character.id, *meseta).await?;
|
|
|
|
// TODO: this should probably echo the packet
|
|
|
|
Ok(Box::new(None.into_iter()))
|
|
|
|
} else {
|
|
|
|
Err(ShipError::NotEnoughMeseta(id, meseta.0).into())
|
|
|
|
}
|
|
|
|
|
|
|
|
// TODO: should probably validate this to be a legit number, I'd just hardcode 200 but vjaya
|
|
|
|
take_meseta(item_state, entity_gateway, &client.character.id, Meseta(charge.meseta)).await?;
|
|
|
|
|
|
|
|
let charge = charge.clone();
|
|
|
|
Ok(Box::new(client_location.get_client_neighbors(id).unwrap().into_iter()
|
|
|
|
.map(move |client| {
|
|
|
|
(client.client, SendShipPacket::Message(Message::new(GameMessage::ChargeAttack(charge.clone()))))
|
|
|
|
})))
|
|
|
|
}
|
|
|
|
|
|
|
|
pub async fn player_uses_item<EG>(id: ClientId,
|
|
|
@ -294,24 +295,24 @@ where |
|
|
|
}
|
|
|
|
|
|
|
|
pub async fn player_used_medical_center<EG>(id: ClientId,
|
|
|
|
_pumc: &PlayerUsedMedicalCenter, // not needed?
|
|
|
|
pumc: &PlayerUsedMedicalCenter,
|
|
|
|
entity_gateway: &mut EG,
|
|
|
|
client_location: &ClientLocation,
|
|
|
|
clients: &mut Clients,
|
|
|
|
item_manager: &mut ItemManager)
|
|
|
|
item_state: &mut ItemState)
|
|
|
|
-> Result<Box<dyn Iterator<Item = (ClientId, SendShipPacket)> + Send>, anyhow::Error>
|
|
|
|
where
|
|
|
|
EG: EntityGateway
|
|
|
|
{
|
|
|
|
let client = clients.get_mut(&id).ok_or(ShipError::ClientNotFound(id))?;
|
|
|
|
let meseta = item_manager.get_character_meseta_mut(&client.character.id)?;
|
|
|
|
if meseta.0 >= 10 {
|
|
|
|
meseta.0 -= 10;
|
|
|
|
entity_gateway.set_character_meseta(&client.character.id, *meseta).await?;
|
|
|
|
// TODO: this should probably echo the packet
|
|
|
|
Ok(Box::new(None.into_iter()))
|
|
|
|
} else {
|
|
|
|
Err(ShipError::NotEnoughMeseta(id, meseta.0).into())
|
|
|
|
}
|
|
|
|
|
|
|
|
take_meseta(item_state, entity_gateway, &client.character.id, Meseta(10)).await?;
|
|
|
|
|
|
|
|
let pumc = pumc.clone();
|
|
|
|
Ok(Box::new(client_location.get_client_neighbors(id).unwrap().into_iter()
|
|
|
|
.map(move |client| {
|
|
|
|
(client.client, SendShipPacket::Message(Message::new(GameMessage::PlayerUsedMedicalCenter(pumc.clone()))))
|
|
|
|
})))
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|