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-10-21 00:54:23 -03:00
|
|
|
use crate::entity::item::{ItemType};
|
2020-04-22 07:14:59 -06:00
|
|
|
use crate::common::serverstate::ClientId;
|
2020-06-05 22:12:44 -06:00
|
|
|
use crate::common::leveltable::CharacterLevelTable;
|
2020-05-14 23:38:18 -06:00
|
|
|
use crate::ship::ship::{SendShipPacket, ShipError, Rooms, Clients, ItemDropLocation};
|
2020-06-06 08:46:02 -06:00
|
|
|
use crate::ship::location::{ClientLocation, ClientLocationError};
|
2020-10-31 01:25:18 -03:00
|
|
|
use crate::ship::items::{ItemManager, ClientItemId, InventoryItem};
|
2020-05-14 23:38:18 -06:00
|
|
|
use crate::ship::packet::builder;
|
2020-04-22 07:14:59 -06:00
|
|
|
|
2020-06-05 22:12:44 -06:00
|
|
|
pub async fn request_exp<EG: EntityGateway>(id: ClientId,
|
|
|
|
request_exp: &RequestExp,
|
|
|
|
entity_gateway: &mut EG,
|
|
|
|
client_location: &ClientLocation,
|
|
|
|
clients: &mut Clients,
|
|
|
|
rooms: &mut Rooms,
|
|
|
|
level_table: &CharacterLevelTable)
|
2020-11-16 21:27:03 -07:00
|
|
|
-> Result<Box<dyn Iterator<Item = (ClientId, SendShipPacket)> + Send>, anyhow::Error> {
|
2020-06-05 22:12:44 -06:00
|
|
|
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 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 monster = room.maps.enemy_by_id(request_exp.enemy_id as usize)?;
|
2020-10-31 19:13:45 -06:00
|
|
|
let monster_stats = room.monster_stats.get(&monster.monster).ok_or(ShipError::UnknownMonster(monster.monster.clone()))?;
|
2020-06-05 22:12:44 -06:00
|
|
|
|
2020-06-05 22:19:20 -06:00
|
|
|
let exp_gain = if request_exp.last_hitter == 1 {
|
|
|
|
monster_stats.exp
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
((monster_stats.exp as f32) * 0.8) as u32
|
|
|
|
};
|
|
|
|
|
2020-06-05 22:12:44 -06:00
|
|
|
let clients_in_area = client_location.get_clients_in_room(room_id).map_err(|err| -> ClientLocationError { err.into() })?;
|
2020-06-05 22:19:20 -06:00
|
|
|
let gain_exp_pkt = builder::message::character_gained_exp(area_client, exp_gain);
|
2020-06-05 22:12:44 -06:00
|
|
|
let mut exp_pkts: Box<dyn Iterator<Item = _> + Send> = Box::new(clients_in_area.clone().into_iter()
|
|
|
|
.map(move |c| {
|
|
|
|
(c.client, SendShipPacket::Message(Message::new(GameMessage::GiveCharacterExp(gain_exp_pkt.clone()))))
|
|
|
|
}));
|
|
|
|
|
|
|
|
let before_level = level_table.get_level_from_exp(client.character.char_class, client.character.exp);
|
2020-06-05 22:19:20 -06:00
|
|
|
let after_level = level_table.get_level_from_exp(client.character.char_class, client.character.exp + exp_gain);
|
2020-06-05 22:12:44 -06:00
|
|
|
let level_up = before_level != after_level;
|
|
|
|
|
|
|
|
if level_up {
|
|
|
|
let (_, before_stats) = level_table.get_stats_from_exp(client.character.char_class, client.character.exp);
|
2020-06-05 22:19:20 -06:00
|
|
|
let (after_level, after_stats) = level_table.get_stats_from_exp(client.character.char_class, client.character.exp + exp_gain);
|
2020-06-05 22:12:44 -06:00
|
|
|
|
|
|
|
let level_up_pkt = builder::message::character_leveled_up(area_client, after_level, before_stats, after_stats);
|
|
|
|
exp_pkts = Box::new(exp_pkts.chain(clients_in_area.into_iter()
|
|
|
|
.map(move |c| {
|
|
|
|
(c.client, SendShipPacket::Message(Message::new(GameMessage::PlayerLevelUp(level_up_pkt.clone()))))
|
|
|
|
})))
|
|
|
|
}
|
|
|
|
|
2020-06-05 22:19:20 -06:00
|
|
|
client.character.exp += exp_gain;
|
2020-10-26 00:02:48 -06:00
|
|
|
entity_gateway.save_character(&client.character).await?;
|
2020-06-05 22:12:44 -06:00
|
|
|
|
|
|
|
Ok(exp_pkts)
|
2020-04-22 07:14:59 -06:00
|
|
|
}
|
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)
|
2020-11-16 21:27:03 -07:00
|
|
|
-> Result<Box<dyn Iterator<Item = (ClientId, SendShipPacket)> + Send>, anyhow::Error>
|
2020-05-13 22:32:30 -06:00
|
|
|
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))?;
|
2020-08-04 19:50:30 -06:00
|
|
|
let area = room.map_areas.get_area_map(player_drop_item.map_area)?;
|
|
|
|
item_manager.player_drop_item_on_shared_floor(entity_gateway, &client.character, ClientItemId(player_drop_item.item_id), (*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)
|
2020-11-16 21:27:03 -07:00
|
|
|
-> Result<Box<dyn Iterator<Item = (ClientId, SendShipPacket)> + Send>, anyhow::Error>
|
2020-05-14 23:38:18 -06:00
|
|
|
{
|
|
|
|
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 {
|
2020-08-04 19:50:30 -06:00
|
|
|
map_area: *room.map_areas.get_area_map(drop_coordinates.map_area)?,
|
2020-05-14 23:38:18 -06:00
|
|
|
x: drop_coordinates.x,
|
|
|
|
z: drop_coordinates.z,
|
|
|
|
item_id: ClientItemId(drop_coordinates.item_id),
|
|
|
|
});
|
|
|
|
|
|
|
|
Ok(Box::new(None.into_iter()))
|
|
|
|
}
|
|
|
|
|
2020-12-03 15:04:48 -07:00
|
|
|
pub async fn no_longer_has_item<EG>(id: ClientId,
|
|
|
|
no_longer_has_item: &PlayerNoLongerHasItem,
|
|
|
|
entity_gateway: &mut EG,
|
|
|
|
client_location: &ClientLocation,
|
|
|
|
clients: &mut Clients,
|
|
|
|
item_manager: &mut ItemManager)
|
|
|
|
-> Result<Box<dyn Iterator<Item = (ClientId, SendShipPacket)> + Send>, anyhow::Error>
|
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() })?;
|
2020-12-03 15:04:48 -07:00
|
|
|
if let Some(drop_location) = client.item_drop_location {
|
|
|
|
if drop_location.item_id.0 != no_longer_has_item.item_id {
|
|
|
|
return Err(ShipError::DropInvalidItemId(no_longer_has_item.item_id).into());
|
|
|
|
}
|
|
|
|
|
|
|
|
if no_longer_has_item.item_id == 0xFFFFFFFF {
|
|
|
|
let dropped_meseta = item_manager.player_drops_meseta_on_shared_floor(entity_gateway, &mut client.character, drop_location, no_longer_has_item.amount as u32).await?;
|
|
|
|
|
|
|
|
let dropped_meseta_pkt = builder::message::drop_split_meseta_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 dropped_item = item_manager.player_drops_partial_stack_on_shared_floor(entity_gateway, &client.character, drop_location.item_id, drop_location, no_longer_has_item.amount as usize).await?;
|
|
|
|
|
|
|
|
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()))))
|
|
|
|
})))
|
|
|
|
}
|
2020-05-14 23:38:18 -06:00
|
|
|
}
|
2020-12-03 15:04:48 -07:00
|
|
|
else if let Some(_tek) = client.tek {
|
|
|
|
let neighbors = client_location.get_client_neighbors(id).map_err(|err| -> ClientLocationError { err.into() })?;
|
|
|
|
let no_longer_has_item = no_longer_has_item.clone();
|
|
|
|
Ok(Box::new(neighbors.into_iter()
|
2020-05-14 23:38:18 -06:00
|
|
|
.map(move |c| {
|
2020-12-03 15:04:48 -07:00
|
|
|
(c.client, SendShipPacket::Message(Message::new(GameMessage::PlayerNoLongerHasItem(no_longer_has_item.clone()))))
|
2020-05-14 23:38:18 -06:00
|
|
|
})))
|
|
|
|
}
|
|
|
|
else {
|
2020-12-03 15:04:48 -07:00
|
|
|
Err(ShipError::InvalidItem(ClientItemId(no_longer_has_item.item_id)).into())
|
2020-05-14 23:38:18 -06:00
|
|
|
}
|
|
|
|
}
|
2020-06-07 18:33:36 -03:00
|
|
|
|
|
|
|
pub fn update_player_position(id: ClientId,
|
2020-07-27 19:28:50 -03:00
|
|
|
message: &Message,
|
2020-06-08 13:19:36 -03:00
|
|
|
clients: &mut Clients,
|
|
|
|
client_location: &ClientLocation,
|
|
|
|
rooms: &Rooms)
|
2020-11-16 21:27:03 -07:00
|
|
|
-> Result<Box<dyn Iterator<Item = (ClientId, SendShipPacket)> + Send>, anyhow::Error> {
|
2020-06-07 18:33:36 -03:00
|
|
|
let client = clients.get_mut(&id).ok_or(ShipError::ClientNotFound(id))?;
|
|
|
|
if let Ok(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))?;
|
2020-07-27 19:28:50 -03:00
|
|
|
|
|
|
|
match &message.msg {
|
2020-08-04 19:50:58 -06:00
|
|
|
GameMessage::PlayerChangedMap(p) => {
|
|
|
|
client.x = p.x;
|
|
|
|
client.y = p.y;
|
|
|
|
client.z = p.z;
|
|
|
|
},
|
|
|
|
GameMessage::PlayerChangedMap2(p) => {
|
|
|
|
client.area = room.map_areas.get_area_map(p.map_area).ok().cloned();
|
|
|
|
},
|
|
|
|
GameMessage::TellOtherPlayerMyLocation(p) => {
|
|
|
|
client.x = p.x;
|
|
|
|
client.y = p.y;
|
|
|
|
client.z = p.z;
|
|
|
|
client.area = room.map_areas.get_area_map(p.map_area).ok().cloned();
|
|
|
|
},
|
|
|
|
GameMessage::PlayerWarpingToFloor(p) => {
|
|
|
|
client.area = room.map_areas.get_area_map(p.area as u16).ok().cloned();
|
|
|
|
},
|
|
|
|
GameMessage::PlayerTeleported(p) => {
|
|
|
|
client.x = p.x;
|
|
|
|
client.y = p.y;
|
|
|
|
client.z = p.z;
|
|
|
|
},
|
|
|
|
GameMessage::PlayerStopped(p) => {
|
|
|
|
client.x = p.x;
|
|
|
|
client.y = p.y;
|
|
|
|
client.z = p.z;
|
|
|
|
},
|
|
|
|
GameMessage::PlayerLoadedIn(p) => {
|
|
|
|
client.x = p.x;
|
|
|
|
client.y = p.y;
|
|
|
|
client.z = p.z;
|
|
|
|
},
|
|
|
|
GameMessage::PlayerWalking(p) => {
|
|
|
|
client.x = p.x;
|
|
|
|
client.z = p.z;
|
|
|
|
},
|
|
|
|
GameMessage::PlayerRunning(p) => {
|
|
|
|
client.x = p.x;
|
|
|
|
client.z = p.z;
|
|
|
|
},
|
|
|
|
GameMessage::PlayerWarped(p) => {
|
|
|
|
client.x = p.x;
|
|
|
|
client.y = p.y;
|
|
|
|
},
|
2020-07-25 22:31:00 -03:00
|
|
|
// GameMessage::PlayerChangedFloor(p) => {client.area = MapArea::from_value(&room.mode.episode(), p.map).ok();},
|
2020-08-04 19:50:58 -06:00
|
|
|
GameMessage::InitializeSpeechNpc(p) => {
|
|
|
|
client.x = p.x;
|
|
|
|
client.z = p.z;
|
|
|
|
}
|
2020-06-07 18:33:36 -03:00
|
|
|
_ => {},
|
|
|
|
}
|
|
|
|
} else {}
|
2020-07-27 19:28:50 -03:00
|
|
|
let m = message.clone();
|
|
|
|
Ok(Box::new(client_location.get_client_neighbors(id).unwrap().into_iter()
|
|
|
|
.map(move |client| {
|
|
|
|
(client.client, SendShipPacket::Message(m.clone()))
|
|
|
|
})))
|
2020-06-29 22:40:26 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
pub async fn charge_attack<EG>(id: ClientId,
|
|
|
|
charge: &ChargeAttack,
|
|
|
|
clients: &mut Clients,
|
|
|
|
entity_gateway: &mut EG)
|
2020-11-16 21:27:03 -07:00
|
|
|
-> Result<Box<dyn Iterator<Item = (ClientId, SendShipPacket)> + Send>, anyhow::Error>
|
2020-06-29 22:40:26 -04:00
|
|
|
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;
|
2020-10-26 00:02:48 -06:00
|
|
|
entity_gateway.save_character(&client.character).await?;
|
2020-06-29 22:40:26 -04:00
|
|
|
Ok(Box::new(None.into_iter()))
|
|
|
|
} else {
|
2020-11-16 21:27:03 -07:00
|
|
|
Err(ShipError::NotEnoughMeseta(id, client.character.meseta).into())
|
2020-06-29 22:40:26 -04:00
|
|
|
}
|
|
|
|
}
|
2020-06-29 19:26:35 -06:00
|
|
|
|
|
|
|
pub async fn use_item<EG>(id: ClientId,
|
|
|
|
player_use_tool: &PlayerUseItem,
|
|
|
|
entity_gateway: &mut EG,
|
2020-07-19 14:50:52 -06:00
|
|
|
_client_location: &ClientLocation,
|
2020-06-29 19:26:35 -06:00
|
|
|
clients: &mut Clients,
|
|
|
|
item_manager: &mut ItemManager)
|
2020-11-16 21:27:03 -07:00
|
|
|
-> Result<Box<dyn Iterator<Item = (ClientId, SendShipPacket)> + Send>, anyhow::Error>
|
2020-06-29 19:26:35 -06:00
|
|
|
where
|
|
|
|
EG: EntityGateway
|
|
|
|
{
|
|
|
|
let client = clients.get_mut(&id).ok_or(ShipError::ClientNotFound(id))?;
|
2020-11-16 20:46:52 -04:00
|
|
|
let item_used_type = item_manager.player_consumes_tool(entity_gateway, &mut client.character, ClientItemId(player_use_tool.item_id), 1).await?;
|
2020-06-29 19:26:35 -06:00
|
|
|
|
2020-09-05 22:06:39 -06:00
|
|
|
item_manager.use_item(item_used_type, entity_gateway, &mut client.character).await?;
|
2020-06-29 19:26:35 -06:00
|
|
|
Ok(Box::new(None.into_iter()))
|
|
|
|
}
|
2020-08-11 17:17:24 -03:00
|
|
|
|
|
|
|
pub async fn player_used_medical_center<EG>(id: ClientId,
|
|
|
|
_pumc: &PlayerUsedMedicalCenter, // not needed?
|
|
|
|
entity_gateway: &mut EG,
|
|
|
|
clients: &mut Clients)
|
2020-11-16 21:27:03 -07:00
|
|
|
-> Result<Box<dyn Iterator<Item = (ClientId, SendShipPacket)> + Send>, anyhow::Error>
|
2020-08-11 17:17:24 -03:00
|
|
|
where
|
2020-10-21 00:54:23 -03:00
|
|
|
EG: EntityGateway
|
2020-08-11 17:17:24 -03:00
|
|
|
{
|
|
|
|
let client = clients.get_mut(&id).ok_or(ShipError::ClientNotFound(id))?;
|
|
|
|
if client.character.meseta >= 10 {
|
|
|
|
client.character.meseta -= 10;
|
2020-10-26 00:02:48 -06:00
|
|
|
entity_gateway.save_character(&client.character).await?;
|
2020-08-11 17:17:24 -03:00
|
|
|
Ok(Box::new(None.into_iter()))
|
|
|
|
} else {
|
2020-11-16 21:27:03 -07:00
|
|
|
Err(ShipError::NotEnoughMeseta(id, client.character.meseta).into())
|
2020-08-11 17:17:24 -03:00
|
|
|
}
|
2020-08-31 23:46:15 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
pub async fn player_feed_mag<EG>(id: ClientId,
|
|
|
|
mag_feed: &PlayerFeedMag,
|
|
|
|
entity_gateway: &mut EG,
|
|
|
|
client_location: &ClientLocation,
|
|
|
|
clients: &Clients,
|
|
|
|
item_manager: &mut ItemManager)
|
2020-11-16 21:27:03 -07:00
|
|
|
-> Result<Box<dyn Iterator<Item = (ClientId, SendShipPacket)> + Send>, anyhow::Error>
|
2020-08-31 23:46:15 -06:00
|
|
|
where
|
|
|
|
EG: EntityGateway
|
|
|
|
{
|
|
|
|
let client = clients.get(&id).ok_or(ShipError::ClientNotFound(id))?;
|
|
|
|
item_manager.player_feeds_mag_item(entity_gateway, &client.character, ClientItemId(mag_feed.mag_id), ClientItemId(mag_feed.item_id)).await?;
|
|
|
|
|
|
|
|
let mag_feed = mag_feed.clone();
|
|
|
|
Ok(Box::new(client_location.get_client_neighbors(id).unwrap().into_iter()
|
|
|
|
.map(move |client| {
|
|
|
|
(client.client, SendShipPacket::Message(Message::new(GameMessage::PlayerFeedMag(mag_feed.clone()))))
|
|
|
|
})))
|
|
|
|
}
|
2020-10-06 21:35:20 -03:00
|
|
|
|
|
|
|
pub async fn player_equips_item<EG>(id: ClientId,
|
|
|
|
pkt: &PlayerEquipItem,
|
|
|
|
entity_gateway: &mut EG,
|
|
|
|
clients: &Clients,
|
|
|
|
item_manager: &mut ItemManager)
|
2020-11-16 21:27:03 -07:00
|
|
|
-> Result<Box<dyn Iterator<Item = (ClientId, SendShipPacket)> + Send>, anyhow::Error>
|
2020-10-06 21:35:20 -03:00
|
|
|
where
|
|
|
|
EG: EntityGateway
|
|
|
|
{
|
|
|
|
let client = clients.get(&id).ok_or(ShipError::ClientNotFound(id))?;
|
2020-11-09 16:47:35 -07:00
|
|
|
let equip_slot = if pkt.sub_menu > 0 {
|
|
|
|
((pkt.sub_menu & 0x7) - 1) % 4
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
0
|
|
|
|
};
|
2020-11-09 16:35:47 -07:00
|
|
|
item_manager.player_equips_item(entity_gateway, &client.character, ClientItemId(pkt.item_id), equip_slot).await?;
|
2020-10-06 21:35:20 -03:00
|
|
|
Ok(Box::new(None.into_iter()))
|
|
|
|
}
|
|
|
|
|
|
|
|
pub async fn player_unequips_item<EG>(id: ClientId,
|
|
|
|
pkt: &PlayerUnequipItem,
|
|
|
|
entity_gateway: &mut EG,
|
|
|
|
clients: &Clients,
|
|
|
|
item_manager: &mut ItemManager)
|
2020-11-16 21:27:03 -07:00
|
|
|
-> Result<Box<dyn Iterator<Item = (ClientId, SendShipPacket)> + Send>, anyhow::Error>
|
2020-10-06 21:35:20 -03:00
|
|
|
where
|
|
|
|
EG: EntityGateway
|
|
|
|
{
|
|
|
|
let client = clients.get(&id).ok_or(ShipError::ClientNotFound(id))?;
|
2020-11-09 16:35:47 -07:00
|
|
|
item_manager.player_unequips_item(entity_gateway, &client.character, ClientItemId(pkt.item_id)).await?;
|
2020-10-21 00:54:23 -03:00
|
|
|
Ok(Box::new(None.into_iter()))
|
2020-10-26 00:02:48 -06:00
|
|
|
}
|
2020-10-31 01:25:18 -03:00
|
|
|
|
|
|
|
pub async fn player_sorts_items<EG>(id: ClientId,
|
|
|
|
pkt: &SortItems,
|
|
|
|
entity_gateway: &mut EG,
|
|
|
|
clients: &Clients,
|
|
|
|
item_manager: &mut ItemManager)
|
2020-11-16 21:27:03 -07:00
|
|
|
-> Result<Box<dyn Iterator<Item = (ClientId, SendShipPacket)> + Send>, anyhow::Error>
|
2020-10-31 01:25:18 -03:00
|
|
|
where
|
|
|
|
EG: EntityGateway
|
|
|
|
{
|
|
|
|
let client = clients.get(&id).ok_or(ShipError::ClientNotFound(id))?;
|
|
|
|
item_manager.player_sorts_items(entity_gateway, &client.character, pkt.item_ids).await?;
|
|
|
|
Ok(Box::new(None.into_iter())) // Do clients care about the order of other clients items?
|
2020-11-05 16:36:39 -07:00
|
|
|
}
|