2020-04-22 07:14:59 -06:00
|
|
|
use log::warn;
|
2020-05-13 22:32:30 -06:00
|
|
|
use libpso::packet::ship::*;
|
2020-04-22 07:14:59 -06:00
|
|
|
use libpso::packet::messages::*;
|
2020-05-13 22:32:30 -06:00
|
|
|
use crate::entity::gateway::EntityGateway;
|
2020-04-22 07:14:59 -06:00
|
|
|
use crate::common::serverstate::ClientId;
|
2020-05-14 23:38:18 -06:00
|
|
|
use crate::ship::ship::{SendShipPacket, ShipError, Rooms, Clients, ItemDropLocation};
|
2020-05-13 22:32:30 -06:00
|
|
|
use crate::ship::location::{ClientLocation, ClientLocationError, RoomLobby};
|
|
|
|
use crate::ship::map::{MapArea};
|
|
|
|
use crate::ship::items::{ItemManager, ClientItemId};
|
2020-05-14 23:38:18 -06:00
|
|
|
use crate::ship::packet::builder;
|
2020-04-22 07:14:59 -06:00
|
|
|
|
|
|
|
pub fn request_exp(id: ClientId,
|
|
|
|
request_exp: &RequestExp,
|
|
|
|
client_location: &ClientLocation,
|
|
|
|
rooms: &Rooms)
|
|
|
|
-> Box<dyn Iterator<Item = (ClientId, SendShipPacket)> + Send> {
|
|
|
|
|
|
|
|
match client_location.get_area(id).unwrap() {
|
|
|
|
RoomLobby::Room(room) => {
|
|
|
|
let r = rooms[room.0].as_ref().unwrap();
|
2020-04-26 22:01:05 -06:00
|
|
|
warn!("killed a {:?}", r.maps.enemy_by_id(request_exp.enemy_id as usize).unwrap().monster);
|
2020-04-22 07:14:59 -06:00
|
|
|
},
|
|
|
|
_ => {}
|
|
|
|
};
|
|
|
|
Box::new(None.into_iter())
|
|
|
|
}
|
2020-05-13 22:32:30 -06:00
|
|
|
|
2020-06-02 18:51:18 -06:00
|
|
|
pub async fn player_drop_item<EG>(id: ClientId,
|
2020-05-14 09:45:05 -06:00
|
|
|
player_drop_item: &PlayerDropItem,
|
2020-05-13 22:32:30 -06:00
|
|
|
entity_gateway: &mut EG,
|
|
|
|
client_location: &ClientLocation,
|
|
|
|
clients: &mut Clients,
|
|
|
|
rooms: &mut Rooms,
|
|
|
|
item_manager: &mut ItemManager)
|
|
|
|
-> Result<Box<dyn Iterator<Item = (ClientId, SendShipPacket)> + Send>, ShipError>
|
|
|
|
where
|
|
|
|
EG: EntityGateway
|
|
|
|
{
|
|
|
|
let client = clients.get_mut(&id).ok_or(ShipError::ClientNotFound(id))?;
|
|
|
|
let room_id = client_location.get_room(id).map_err(|err| -> ClientLocationError { err.into() })?;
|
|
|
|
let room = rooms.get_mut(room_id.0)
|
|
|
|
.ok_or_else(|| ShipError::InvalidRoom(room_id.0 as u32))?
|
|
|
|
.as_mut()
|
|
|
|
.ok_or_else(|| ShipError::InvalidRoom(room_id.0 as u32))?;
|
|
|
|
let area = MapArea::from_value(&room.mode.episode(), player_drop_item.area as u32)?;
|
|
|
|
let item = item_manager.get_inventory_item_by_id(&client.character, ClientItemId(player_drop_item.item_id))?;
|
2020-06-02 18:51:18 -06:00
|
|
|
item_manager.player_drop_item_on_shared_floor(entity_gateway, &client.character, item, (area, player_drop_item.x, player_drop_item.y, player_drop_item.z)).await?;
|
2020-05-13 22:32:30 -06:00
|
|
|
let clients_in_area = client_location.get_clients_in_room(room_id).map_err(|err| -> ClientLocationError { err.into() })?;
|
|
|
|
let pdi = player_drop_item.clone();
|
|
|
|
Ok(Box::new(clients_in_area.into_iter()
|
|
|
|
.map(move |c| {
|
2020-05-14 09:46:59 -06:00
|
|
|
(c.client, SendShipPacket::Message(Message::new(GameMessage::PlayerDropItem(pdi.clone()))))
|
2020-05-13 22:32:30 -06:00
|
|
|
})))
|
|
|
|
}
|
2020-05-14 23:38:18 -06:00
|
|
|
|
|
|
|
pub fn drop_coordinates(id: ClientId,
|
|
|
|
drop_coordinates: &DropCoordinates,
|
|
|
|
client_location: &ClientLocation,
|
|
|
|
clients: &mut Clients,
|
|
|
|
rooms: &Rooms)
|
|
|
|
-> Result<Box<dyn Iterator<Item = (ClientId, SendShipPacket)> + Send>, ShipError>
|
|
|
|
{
|
|
|
|
let client = clients.get_mut(&id).ok_or(ShipError::ClientNotFound(id))?;
|
|
|
|
let room_id = client_location.get_room(id).map_err(|err| -> ClientLocationError { err.into() })?;
|
|
|
|
let room = rooms.get(room_id.0)
|
|
|
|
.ok_or_else(|| ShipError::InvalidRoom(room_id.0 as u32))?
|
|
|
|
.as_ref()
|
|
|
|
.ok_or_else(|| ShipError::InvalidRoom(room_id.0 as u32))?;
|
|
|
|
|
|
|
|
client.item_drop_location = Some(ItemDropLocation {
|
|
|
|
map_area: MapArea::from_value(&room.mode.episode(), drop_coordinates.map_area)?,
|
|
|
|
x: drop_coordinates.x,
|
|
|
|
z: drop_coordinates.z,
|
|
|
|
item_id: ClientItemId(drop_coordinates.item_id),
|
|
|
|
});
|
|
|
|
|
|
|
|
Ok(Box::new(None.into_iter()))
|
|
|
|
}
|
|
|
|
|
2020-06-02 18:51:18 -06:00
|
|
|
pub async fn split_item_stack<EG>(id: ClientId,
|
|
|
|
split_item_stack: &PlayerSplitItemStack,
|
|
|
|
entity_gateway: &mut EG,
|
|
|
|
client_location: &ClientLocation,
|
|
|
|
clients: &mut Clients,
|
|
|
|
item_manager: &mut ItemManager)
|
|
|
|
-> Result<Box<dyn Iterator<Item = (ClientId, SendShipPacket)> + Send>, ShipError>
|
2020-05-14 23:38:18 -06:00
|
|
|
where
|
|
|
|
EG: EntityGateway
|
|
|
|
{
|
|
|
|
let client = clients.get_mut(&id).ok_or(ShipError::ClientNotFound(id))?;
|
|
|
|
let area_client = client_location.get_local_client(id).map_err(|err| -> ClientLocationError { err.into() })?;
|
|
|
|
let room_id = client_location.get_room(id).map_err(|err| -> ClientLocationError { err.into() })?;
|
|
|
|
let drop_location = client.item_drop_location.ok_or(ShipError::ItemDropLocationNotSet)?;
|
|
|
|
|
|
|
|
if drop_location.item_id.0 != split_item_stack.item_id {
|
|
|
|
return Err(ShipError::DropInvalidItemId(split_item_stack.item_id));
|
|
|
|
}
|
|
|
|
|
|
|
|
if split_item_stack.item_id == 0xFFFFFFFF {
|
2020-06-02 18:51:18 -06:00
|
|
|
let dropped_meseta = item_manager.player_drops_meseta_on_shared_floor(entity_gateway, &mut client.character, drop_location, split_item_stack.amount as u32).await?;
|
2020-05-14 23:38:18 -06:00
|
|
|
|
|
|
|
let dropped_meseta_pkt = builder::message::drop_split_stack(area_client, &dropped_meseta)?;
|
|
|
|
client.item_drop_location = None;
|
|
|
|
|
|
|
|
let clients_in_area = client_location.get_clients_in_room(room_id).map_err(|err| -> ClientLocationError { err.into() })?;
|
|
|
|
Ok(Box::new(clients_in_area.into_iter()
|
|
|
|
.map(move |c| {
|
|
|
|
(c.client, SendShipPacket::Message(Message::new(GameMessage::DropSplitStack(dropped_meseta_pkt.clone()))))
|
|
|
|
})))
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
let item_to_split = item_manager.get_inventory_item_by_id(&client.character, drop_location.item_id)?;
|
2020-06-02 18:51:18 -06:00
|
|
|
let dropped_item = item_manager.player_drops_partial_stack_on_shared_floor(entity_gateway, &client.character, item_to_split, drop_location, split_item_stack.amount as usize).await?;
|
2020-05-14 23:38:18 -06:00
|
|
|
|
|
|
|
let dropped_item_pkt = builder::message::drop_split_stack(area_client, &dropped_item)?;
|
|
|
|
client.item_drop_location = None;
|
|
|
|
|
|
|
|
let clients_in_area = client_location.get_clients_in_room(room_id).map_err(|err| -> ClientLocationError { err.into() })?;
|
|
|
|
Ok(Box::new(clients_in_area.into_iter()
|
|
|
|
.map(move |c| {
|
|
|
|
(c.client, SendShipPacket::Message(Message::new(GameMessage::DropSplitStack(dropped_item_pkt.clone()))))
|
|
|
|
})))
|
|
|
|
}
|
|
|
|
}
|