Browse Source

floor item limit reached

pull/135/head
andy 2 years ago
parent
commit
1ea1bbc226
  1. 13
      src/entity/gateway/postgres/models.rs
  2. 4
      src/entity/item/mod.rs
  3. 20
      src/ship/items/actions.rs
  4. 24
      src/ship/items/tasks.rs
  5. 27
      src/ship/packet/handler/message.rs
  6. 4
      src/ship/ship.rs

13
src/entity/gateway/postgres/models.rs

@ -612,6 +612,9 @@ pub enum PgItemNoteDetail {
Deposit {
character_id: u32,
bank: BankIdentifier,
},
FloorLimitReached {
map_area: MapArea,
}
}
@ -658,7 +661,12 @@ impl From<ItemNote> for PgItemNoteDetail {
character_id: character_id.0,
bank,
}
}
},
ItemNote::FloorLimitReached { map_area } => {
PgItemNoteDetail::FloorLimitReached {
map_area: map_area,
}
},
}
}
}
@ -703,6 +711,9 @@ impl From<PgItemNoteDetail> for ItemNote {
character_id: CharacterEntityId(character_id),
bank,
},
PgItemNoteDetail::FloorLimitReached { map_area } => ItemNote::FloorLimitReached {
map_area: map_area,
},
}
}
}

4
src/entity/item/mod.rs

@ -10,6 +10,7 @@ pub mod esweapon;
use serde::{Serialize, Deserialize};
use crate::entity::character::CharacterEntityId;
use crate::ship::items::ClientItemId;
use crate::ship::map::MapArea;
use crate::ship::drops::ItemDropType;
@ -74,6 +75,9 @@ pub enum ItemNote {
character_id: CharacterEntityId,
bank: BankIdentifier,
},
FloorLimitReached {
map_area: MapArea,
},
}
#[derive(Debug, Copy, Clone, PartialEq, Eq)]

20
src/ship/items/actions.rs

@ -1148,3 +1148,23 @@ where
})
}
}
pub(super) fn delete_item_from_floor<'a, EG, TR>(
map_area: MapArea
) -> impl Fn((ItemStateProxy, TR), FloorItem)
-> BoxFuture<'a, Result<((ItemStateProxy, TR), ()), anyhow::Error>>
where
EG: EntityGateway,
TR: EntityGatewayTransaction<ParentGateway = EG> + Clone + 'a,
{
move |(item_state, transaction), floor_item| {
Box::pin(async move {
let transaction = floor_item.with_entity_id(transaction, |mut transaction, entity_id| {
async move {
transaction.gateway().add_item_note(&entity_id, ItemNote::FloorLimitReached { map_area: map_area }).await?;
Ok(transaction)
}}).await?;
Ok(((item_state, transaction), ()))
})
}
}

24
src/ship/items/tasks.rs

@ -508,3 +508,27 @@ where
Ok((transaction, item))
})
}
pub async fn floor_item_limit_reached<'a, EG> (
item_state: &'a mut ItemState,
entity_gateway: &'a mut EG,
character: &'a CharacterEntity,
item_id: &'a ClientItemId,
map_area: MapArea
) -> BoxFuture<'a, Result<(), anyhow::Error>>
where
EG: EntityGateway + 'static,
EG::Transaction<'a>: Clone,
{
entity_gateway.with_transaction(move |transaction| async move {
let item_state_proxy = ItemStateProxy::new(item_state.clone());
let((item_state_proxy, transaction), result) = ItemStateAction::default()
.act(actions::take_item_from_floor(character.id, *item_id))
.act(actions::delete_item_from_floor(map_area))
.commit((item_state_proxy, transaction))
.await?;
item_state_proxy.commit().await;
Ok((transaction, result))
})
}

27
src/ship/packet/handler/message.rs

@ -10,7 +10,7 @@ use crate::ship::location::{ClientLocation, ClientLocationError};
use crate::ship::items::ClientItemId;
use crate::ship::packet::builder;
use crate::ship::items::state::ItemState;
use crate::ship::items::tasks::{drop_item, drop_partial_item, drop_meseta, equip_item, unequip_item, sort_inventory, use_item, feed_mag, sell_item, take_meseta};
use crate::ship::items::tasks::{drop_item, drop_partial_item, drop_meseta, equip_item, unequip_item, sort_inventory, use_item, feed_mag, sell_item, take_meseta, floor_item_limit_reached};
pub async fn request_exp<EG>(id: ClientId,
request_exp: RequestExp,
@ -500,3 +500,28 @@ where
})}).await??;
Ok(Vec::new()) // TODO: send the packet to other clients
}
pub async fn floor_item_limit_deletion<EG> (id: ClientId,
floor_item_limit_delete: FloorItemLimitItemDeletion,
entity_gateway: &mut EG,
client_location: &ClientLocation,
clients: &Clients,
rooms: &Rooms,
item_state: &mut ItemState)
-> Result<Vec<(ClientId, SendShipPacket)>, anyhow::Error>
where
EG: EntityGateway + Clone + 'static,
{
let room_id = client_location.get_room(id).await.map_err(|err| -> ClientLocationError { err.into() })?;
let map_area = rooms.with(room_id, |room| Box::pin(async move {
room.map_areas.get_area_map(floor_item_limit_delete.map_area)
})).await??;
clients.with(id, |client| {
let mut entity_gateway = entity_gateway.clone();
let mut item_state = item_state.clone();
Box::pin(async move {
floor_item_limit_reached(&mut item_state, &mut entity_gateway, &client.character, &ClientItemId(floor_item_limit_delete.item_id), map_area).await
})}).await??;
Ok(Vec::new())
}

4
src/ship/ship.rs

@ -577,6 +577,10 @@ impl<EG: EntityGateway + Clone + 'static> ShipServerState<EG> {
GameMessage::PlayerSoldItem(player_sold_item) => {
handler::message::player_sells_item(id, player_sold_item, &mut self.entity_gateway, &self.clients, &mut self.item_state).await?
},
GameMessage::FloorItemLimitItemDeletion(floor_item_limit_delete) => {
let block = self.blocks.get_from_client(id, &self.clients).await?;
handler::message::floor_item_limit_deletion(id, floor_item_limit_delete, &mut self.entity_gateway, &block.client_location, &self.clients, &block.rooms, &mut self.item_state).await?
},
_ => {
let cmsg = msg.clone();
let block = self.blocks.get_from_client(id, &self.clients).await?;

Loading…
Cancel
Save