|
|
@ -1,33 +1,46 @@ |
|
|
|
// TODO: replace various u32s and usizes denoting item amounts for ItemAmount(u32) for consistency
|
|
|
|
use crate::ship::items::ClientItemId;
|
|
|
|
use crate::entity::item::{Meseta, ItemNote};
|
|
|
|
use async_std::sync::Arc;
|
|
|
|
use std::future::Future;
|
|
|
|
use std::pin::Pin;
|
|
|
|
use std::iter::IntoIterator;
|
|
|
|
|
|
|
|
use libpso::packet::{ship::Message, messages::GameMessage};
|
|
|
|
use crate::ship::map::MapArea;
|
|
|
|
use crate::ship::ship::SendShipPacket;
|
|
|
|
use crate::entity::character::{CharacterEntity, CharacterEntityId};
|
|
|
|
use crate::entity::gateway::EntityGatewayTransaction;
|
|
|
|
use crate::entity::gateway::{EntityGateway, EntityGatewayTransaction};
|
|
|
|
use crate::ship::items::state::{ItemStateProxy, ItemStateError, AddItemResult, StackedItemDetail, IndividualItemDetail};
|
|
|
|
use crate::ship::items::bank::{BankItem, BankItemDetail};
|
|
|
|
use crate::ship::items::inventory::{InventoryItem, InventoryItemDetail};
|
|
|
|
use crate::ship::items::floor::{FloorItem, FloorItemDetail};
|
|
|
|
use crate::ship::items::apply_item::apply_item;
|
|
|
|
use crate::ship::items::apply_item::{apply_item, ApplyItemAction};
|
|
|
|
use crate::entity::item::{ItemDetail, NewItemEntity, TradeId};
|
|
|
|
use crate::entity::item::tool::Tool;
|
|
|
|
use crate::entity::item::ItemModifier;
|
|
|
|
use crate::ship::shops::ShopItem;
|
|
|
|
use crate::ship::drops::{ItemDrop, ItemDropType};
|
|
|
|
use crate::ship::packet::builder;
|
|
|
|
use crate::ship::location::AreaClient;
|
|
|
|
|
|
|
|
type BoxFuture<T> = Pin<Box<dyn Future<Output=T> + Send>>;
|
|
|
|
|
|
|
|
pub enum TriggerCreateItem {
|
|
|
|
Yes,
|
|
|
|
No
|
|
|
|
}
|
|
|
|
|
|
|
|
pub(super) fn take_item_from_floor(character_id: CharacterEntityId, item_id: ClientItemId)
|
|
|
|
-> impl for<'a> Fn((ItemStateProxy<'a>, Box<dyn EntityGatewayTransaction + 'a>), ())
|
|
|
|
-> Pin<Box<dyn Future<Output=Result<((ItemStateProxy<'a>, Box<dyn EntityGatewayTransaction + 'a>), FloorItem), ItemStateError>> + Send + 'a>>
|
|
|
|
pub(super) fn take_item_from_floor<EG, TR>(
|
|
|
|
character_id: CharacterEntityId,
|
|
|
|
item_id: ClientItemId
|
|
|
|
) -> impl Fn((ItemStateProxy, TR), ())
|
|
|
|
-> BoxFuture<Result<((ItemStateProxy, TR), FloorItem), ItemStateError>>
|
|
|
|
where
|
|
|
|
EG: EntityGateway + Send,
|
|
|
|
TR: EntityGatewayTransaction<ParentGateway = EG> + 'static,
|
|
|
|
{
|
|
|
|
move |(mut item_state, transaction): (ItemStateProxy<'_>, Box<dyn EntityGatewayTransaction + '_>) , _| {
|
|
|
|
move |(mut item_state, transaction): (ItemStateProxy, TR) , _| {
|
|
|
|
Box::pin(async move {
|
|
|
|
let mut floor = item_state.floor(&character_id).await?;
|
|
|
|
let item = floor.take_item(&item_id).ok_or_else(|| ItemStateError::NoFloorItem(item_id))?;
|
|
|
@ -38,9 +51,13 @@ pub(super) fn take_item_from_floor(character_id: CharacterEntityId, item_id: Cli |
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
pub(super) fn add_floor_item_to_inventory(character: &CharacterEntity)
|
|
|
|
-> impl for<'a> Fn((ItemStateProxy<'a>, Box<dyn EntityGatewayTransaction + 'a>), FloorItem)
|
|
|
|
-> Pin<Box<dyn Future<Output=Result<((ItemStateProxy<'a>, Box<dyn EntityGatewayTransaction + 'a>), TriggerCreateItem), ItemStateError>> + Send + 'a>>
|
|
|
|
pub(super) fn add_floor_item_to_inventory<EG, TR>(
|
|
|
|
character: &CharacterEntity
|
|
|
|
) -> impl Fn((ItemStateProxy, TR), FloorItem)
|
|
|
|
-> BoxFuture<Result<((ItemStateProxy, TR), TriggerCreateItem), ItemStateError>>
|
|
|
|
where
|
|
|
|
EG: EntityGateway,
|
|
|
|
TR: EntityGatewayTransaction<ParentGateway = EG> + Clone + 'static,
|
|
|
|
{
|
|
|
|
let character = character.clone();
|
|
|
|
move |(mut item_state, transaction), floor_item| {
|
|
|
@ -67,7 +84,7 @@ pub(super) fn add_floor_item_to_inventory(character: &CharacterEntity) |
|
|
|
let add_result = inventory.add_floor_item(floor_item)?;
|
|
|
|
transaction.gateway().set_character_inventory(&character.id, &inventory.as_inventory_entity(&character.id)).await?;
|
|
|
|
transaction.gateway().set_character_meseta(&character_id, inventory.meseta).await?;
|
|
|
|
item_state.set_inventory(inventory);
|
|
|
|
item_state.set_inventory(inventory).await;
|
|
|
|
|
|
|
|
Ok(((item_state, transaction),
|
|
|
|
match add_result {
|
|
|
@ -81,9 +98,15 @@ pub(super) fn add_floor_item_to_inventory(character: &CharacterEntity) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
pub(super) fn take_item_from_inventory(character_id: CharacterEntityId, item_id: ClientItemId, amount: u32)
|
|
|
|
-> impl for<'a> Fn((ItemStateProxy<'a>, Box<dyn EntityGatewayTransaction + 'a>), ())
|
|
|
|
-> Pin<Box<dyn Future<Output=Result<((ItemStateProxy<'a>, Box<dyn EntityGatewayTransaction + 'a>), InventoryItem), ItemStateError>> + Send + 'a>>
|
|
|
|
pub(super) fn take_item_from_inventory<EG, TR>(
|
|
|
|
character_id: CharacterEntityId,
|
|
|
|
item_id: ClientItemId,
|
|
|
|
amount: u32,
|
|
|
|
) -> impl Fn((ItemStateProxy, TR), ())
|
|
|
|
-> BoxFuture<Result<((ItemStateProxy, TR), InventoryItem), ItemStateError>>
|
|
|
|
where
|
|
|
|
EG: EntityGateway,
|
|
|
|
TR: EntityGatewayTransaction<ParentGateway = EG> + 'static,
|
|
|
|
{
|
|
|
|
move |(mut item_state, mut transaction), _| {
|
|
|
|
Box::pin(async move {
|
|
|
@ -91,7 +114,7 @@ pub(super) fn take_item_from_inventory(character_id: CharacterEntityId, item_id: |
|
|
|
let item = inventory.take_item(&item_id, amount).ok_or_else(|| ItemStateError::NoFloorItem(item_id))?;
|
|
|
|
|
|
|
|
transaction.gateway().set_character_inventory(&character_id, &inventory.as_inventory_entity(&character_id)).await?;
|
|
|
|
item_state.set_inventory(inventory);
|
|
|
|
item_state.set_inventory(inventory).await;
|
|
|
|
|
|
|
|
Ok(((item_state, transaction), item))
|
|
|
|
})
|
|
|
@ -99,9 +122,15 @@ pub(super) fn take_item_from_inventory(character_id: CharacterEntityId, item_id: |
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
pub(super) fn add_inventory_item_to_shared_floor(character_id: CharacterEntityId, map_area: MapArea, drop_position: (f32, f32, f32))
|
|
|
|
-> impl for<'a> Fn((ItemStateProxy<'a>, Box<dyn EntityGatewayTransaction + 'a>), InventoryItem)
|
|
|
|
-> Pin<Box<dyn Future<Output=Result<((ItemStateProxy<'a>, Box<dyn EntityGatewayTransaction + 'a>), FloorItem), ItemStateError>> + Send + 'a>>
|
|
|
|
pub(super) fn add_inventory_item_to_shared_floor<EG, TR>(
|
|
|
|
character_id: CharacterEntityId,
|
|
|
|
map_area: MapArea,
|
|
|
|
drop_position: (f32, f32, f32),
|
|
|
|
) -> impl Fn((ItemStateProxy, TR), InventoryItem)
|
|
|
|
-> BoxFuture<Result<((ItemStateProxy, TR), FloorItem), ItemStateError>>
|
|
|
|
where
|
|
|
|
EG: EntityGateway,
|
|
|
|
TR: EntityGatewayTransaction<ParentGateway = EG> + 'static,
|
|
|
|
{
|
|
|
|
move |(mut item_state, transaction), inventory_item| {
|
|
|
|
Box::pin(async move {
|
|
|
@ -127,43 +156,59 @@ pub(super) fn add_inventory_item_to_shared_floor(character_id: CharacterEntityId |
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
pub(super) fn take_meseta_from_inventory(character_id: CharacterEntityId, amount: u32)
|
|
|
|
-> impl for<'a> Fn((ItemStateProxy<'a>, Box<dyn EntityGatewayTransaction + 'a>), ())
|
|
|
|
-> Pin<Box<dyn Future<Output=Result<((ItemStateProxy<'a>, Box<dyn EntityGatewayTransaction + 'a>), ()), ItemStateError>> + Send + 'a>>
|
|
|
|
pub(super) fn take_meseta_from_inventory<EG, TR>(
|
|
|
|
character_id: CharacterEntityId,
|
|
|
|
amount: u32,
|
|
|
|
) -> impl Fn((ItemStateProxy, TR), ())
|
|
|
|
-> BoxFuture<Result<((ItemStateProxy, TR), ()), ItemStateError>>
|
|
|
|
where
|
|
|
|
EG: EntityGateway,
|
|
|
|
TR: EntityGatewayTransaction<ParentGateway = EG> + 'static,
|
|
|
|
{
|
|
|
|
move |(mut item_state, mut transaction), _| {
|
|
|
|
Box::pin(async move {
|
|
|
|
let mut inventory = item_state.inventory(&character_id).await?;
|
|
|
|
inventory.remove_meseta(amount)?;
|
|
|
|
transaction.gateway().set_character_meseta(&character_id, inventory.meseta).await?;
|
|
|
|
item_state.set_inventory(inventory);
|
|
|
|
item_state.set_inventory(inventory).await;
|
|
|
|
|
|
|
|
Ok(((item_state, transaction), ()))
|
|
|
|
})
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
pub(super) fn add_meseta_to_inventory(character_id: CharacterEntityId, amount: u32)
|
|
|
|
-> impl for<'a> Fn((ItemStateProxy<'a>, Box<dyn EntityGatewayTransaction + 'a>), ())
|
|
|
|
-> Pin<Box<dyn Future<Output=Result<((ItemStateProxy<'a>, Box<dyn EntityGatewayTransaction + 'a>), ()), ItemStateError>> + Send + 'a>>
|
|
|
|
pub(super) fn add_meseta_to_inventory<EG, TR>(
|
|
|
|
character_id: CharacterEntityId,
|
|
|
|
amount: u32 |
|
|
|
) -> impl Fn((ItemStateProxy, TR), ())
|
|
|
|
-> BoxFuture<Result<((ItemStateProxy, TR), ()), ItemStateError>>
|
|
|
|
where
|
|
|
|
EG: EntityGateway,
|
|
|
|
TR: EntityGatewayTransaction<ParentGateway = EG> + 'static,
|
|
|
|
{
|
|
|
|
move |(mut item_state, mut transaction), _| {
|
|
|
|
Box::pin(async move {
|
|
|
|
let mut inventory = item_state.inventory(&character_id).await?;
|
|
|
|
inventory.add_meseta(amount)?;
|
|
|
|
transaction.gateway().set_character_meseta(&character_id, inventory.meseta).await?;
|
|
|
|
item_state.set_inventory(inventory);
|
|
|
|
item_state.set_inventory(inventory).await;
|
|
|
|
|
|
|
|
Ok(((item_state, transaction), ()))
|
|
|
|
})
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
pub(super) fn add_meseta_to_shared_floor(character_id: CharacterEntityId, amount: u32, map_area: MapArea, drop_position: (f32, f32))
|
|
|
|
-> impl for<'a> Fn((ItemStateProxy<'a>, Box<dyn EntityGatewayTransaction + 'a>), ())
|
|
|
|
-> Pin<Box<dyn Future<Output=Result<((ItemStateProxy<'a>, Box<dyn EntityGatewayTransaction + 'a>), FloorItem), ItemStateError>> + Send + 'a>>
|
|
|
|
pub(super) fn add_meseta_to_shared_floor<EG, TR>(
|
|
|
|
character_id: CharacterEntityId,
|
|
|
|
amount: u32,
|
|
|
|
map_area: MapArea,
|
|
|
|
drop_position: (f32, f32)
|
|
|
|
) -> impl Fn((ItemStateProxy, TR), ())
|
|
|
|
-> BoxFuture<Result<((ItemStateProxy, TR), FloorItem), ItemStateError>>
|
|
|
|
where
|
|
|
|
EG: EntityGateway,
|
|
|
|
TR: EntityGatewayTransaction<ParentGateway = EG> + 'static,
|
|
|
|
{
|
|
|
|
|
|
|
|
move |(mut item_state, transaction), _| {
|
|
|
|
Box::pin(async move {
|
|
|
|
let floor_item = FloorItem {
|
|
|
@ -184,9 +229,14 @@ pub(super) fn add_meseta_to_shared_floor(character_id: CharacterEntityId, amount |
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
pub(super) fn take_meseta_from_bank(character_id: CharacterEntityId, amount: u32)
|
|
|
|
-> impl for<'a> Fn((ItemStateProxy<'a>, Box<dyn EntityGatewayTransaction + 'a>), ())
|
|
|
|
-> Pin<Box<dyn Future<Output=Result<((ItemStateProxy<'a>, Box<dyn EntityGatewayTransaction + 'a>), ()), ItemStateError>> + Send + 'a>>
|
|
|
|
pub(super) fn take_meseta_from_bank<EG, TR>(
|
|
|
|
character_id: CharacterEntityId,
|
|
|
|
amount: u32,
|
|
|
|
) -> impl Fn((ItemStateProxy, TR), ())
|
|
|
|
-> BoxFuture<Result<((ItemStateProxy, TR), ()), ItemStateError>>
|
|
|
|
where
|
|
|
|
EG: EntityGateway,
|
|
|
|
TR: EntityGatewayTransaction<ParentGateway = EG> + 'static,
|
|
|
|
{
|
|
|
|
move |(mut item_state, mut transaction), _| {
|
|
|
|
Box::pin(async move {
|
|
|
@ -199,9 +249,14 @@ pub(super) fn take_meseta_from_bank(character_id: CharacterEntityId, amount: u32 |
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
pub(super) fn add_meseta_from_bank_to_inventory(character_id: CharacterEntityId, amount: u32)
|
|
|
|
-> impl for<'a> Fn((ItemStateProxy<'a>, Box<dyn EntityGatewayTransaction + 'a>), ())
|
|
|
|
-> Pin<Box<dyn Future<Output=Result<((ItemStateProxy<'a>, Box<dyn EntityGatewayTransaction + 'a>), ()), ItemStateError>> + Send + 'a>>
|
|
|
|
pub(super) fn add_meseta_from_bank_to_inventory<EG, TR>(
|
|
|
|
character_id: CharacterEntityId,
|
|
|
|
amount: u32,
|
|
|
|
) -> impl Fn((ItemStateProxy, TR), ())
|
|
|
|
-> BoxFuture<Result<((ItemStateProxy, TR), ()), ItemStateError>>
|
|
|
|
where
|
|
|
|
EG: EntityGateway,
|
|
|
|
TR: EntityGatewayTransaction<ParentGateway = EG> + 'static,
|
|
|
|
{
|
|
|
|
move |(mut item_state, mut transaction), _| {
|
|
|
|
Box::pin(async move {
|
|
|
@ -215,9 +270,14 @@ pub(super) fn add_meseta_from_bank_to_inventory(character_id: CharacterEntityId, |
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
pub(super) fn add_meseta_to_bank(character_id: CharacterEntityId, amount: u32)
|
|
|
|
-> impl for<'a> Fn((ItemStateProxy<'a>, Box<dyn EntityGatewayTransaction + 'a>), ())
|
|
|
|
-> Pin<Box<dyn Future<Output=Result<((ItemStateProxy<'a>, Box<dyn EntityGatewayTransaction + 'a>), ()), ItemStateError>> + Send + 'a>>
|
|
|
|
pub(super) fn add_meseta_to_bank<EG, TR>(
|
|
|
|
character_id: CharacterEntityId,
|
|
|
|
amount: u32,
|
|
|
|
) -> impl Fn((ItemStateProxy, TR), ())
|
|
|
|
-> BoxFuture<Result<((ItemStateProxy, TR), ()), ItemStateError>>
|
|
|
|
where
|
|
|
|
EG: EntityGateway,
|
|
|
|
TR: EntityGatewayTransaction<ParentGateway = EG> + 'static,
|
|
|
|
{
|
|
|
|
move |(mut item_state, mut transaction), _| {
|
|
|
|
Box::pin(async move {
|
|
|
@ -231,25 +291,35 @@ pub(super) fn add_meseta_to_bank(character_id: CharacterEntityId, amount: u32) |
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
pub(super) fn take_item_from_bank(character_id: CharacterEntityId, item_id: ClientItemId, amount: u32)
|
|
|
|
-> impl for<'a> Fn((ItemStateProxy<'a>, Box<dyn EntityGatewayTransaction + 'a>), ())
|
|
|
|
-> Pin<Box<dyn Future<Output=Result<((ItemStateProxy<'a>, Box<dyn EntityGatewayTransaction + 'a>), BankItem), ItemStateError>> + Send + 'a>>
|
|
|
|
pub(super) fn take_item_from_bank<EG, TR>(
|
|
|
|
character_id: CharacterEntityId,
|
|
|
|
item_id: ClientItemId,
|
|
|
|
amount: u32,
|
|
|
|
) -> impl Fn((ItemStateProxy, TR), ())
|
|
|
|
-> BoxFuture<Result<((ItemStateProxy, TR), BankItem), ItemStateError>>
|
|
|
|
where
|
|
|
|
EG: EntityGateway,
|
|
|
|
TR: EntityGatewayTransaction<ParentGateway = EG> + 'static,
|
|
|
|
{
|
|
|
|
move |(mut item_state, mut transaction), _| {
|
|
|
|
Box::pin(async move {
|
|
|
|
let mut bank = item_state.bank(&character_id).await?;
|
|
|
|
let item = bank.take_item(&item_id, amount).ok_or_else(|| ItemStateError::NoBankItem(item_id))?;
|
|
|
|
transaction.gateway().set_character_bank(&character_id, &bank.as_bank_entity(), &bank.name).await?;
|
|
|
|
item_state.set_bank(bank);
|
|
|
|
item_state.set_bank(bank).await;
|
|
|
|
|
|
|
|
Ok(((item_state, transaction), item))
|
|
|
|
})
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
pub(super) fn add_bank_item_to_inventory(character: &CharacterEntity)
|
|
|
|
-> impl for<'a> Fn((ItemStateProxy<'a>, Box<dyn EntityGatewayTransaction + 'a>), BankItem)
|
|
|
|
-> Pin<Box<dyn Future<Output=Result<((ItemStateProxy<'a>, Box<dyn EntityGatewayTransaction + 'a>), InventoryItem), ItemStateError>> + Send + 'a>>
|
|
|
|
pub(super) fn add_bank_item_to_inventory<EG, TR>(
|
|
|
|
character: &CharacterEntity,
|
|
|
|
) -> impl Fn((ItemStateProxy, TR), BankItem)
|
|
|
|
-> BoxFuture<Result<((ItemStateProxy, TR), InventoryItem), ItemStateError>>
|
|
|
|
where
|
|
|
|
EG: EntityGateway,
|
|
|
|
TR: EntityGatewayTransaction<ParentGateway = EG> + 'static,
|
|
|
|
{
|
|
|
|
let character = character.clone();
|
|
|
|
move |(mut item_state, transaction), bank_item| {
|
|
|
@ -286,7 +356,7 @@ pub(super) fn add_bank_item_to_inventory(character: &CharacterEntity) |
|
|
|
|
|
|
|
inventory.add_item(inventory_item.clone())?;
|
|
|
|
transaction.gateway().set_character_inventory(&character.id, &inventory.as_inventory_entity(&character.id)).await?;
|
|
|
|
item_state.set_inventory(inventory);
|
|
|
|
item_state.set_inventory(inventory).await;
|
|
|
|
|
|
|
|
Ok(((item_state, transaction), inventory_item))
|
|
|
|
})
|
|
|
@ -294,9 +364,13 @@ pub(super) fn add_bank_item_to_inventory(character: &CharacterEntity) |
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
pub(super) fn add_inventory_item_to_bank(character_id: CharacterEntityId)
|
|
|
|
-> impl for<'a> Fn((ItemStateProxy<'a>, Box<dyn EntityGatewayTransaction + 'a>), InventoryItem)
|
|
|
|
-> Pin<Box<dyn Future<Output=Result<((ItemStateProxy<'a>, Box<dyn EntityGatewayTransaction + 'a>), ()), ItemStateError>> + Send + 'a>>
|
|
|
|
pub(super) fn add_inventory_item_to_bank<EG, TR>(
|
|
|
|
character_id: CharacterEntityId,
|
|
|
|
) -> impl Fn((ItemStateProxy, TR), InventoryItem)
|
|
|
|
-> BoxFuture<Result<((ItemStateProxy, TR), ()), ItemStateError>>
|
|
|
|
where
|
|
|
|
EG: EntityGateway,
|
|
|
|
TR: EntityGatewayTransaction<ParentGateway = EG> + 'static,
|
|
|
|
{
|
|
|
|
move |(mut item_state, transaction), inventory_item| {
|
|
|
|
Box::pin(async move {
|
|
|
@ -315,7 +389,7 @@ pub(super) fn add_inventory_item_to_bank(character_id: CharacterEntityId) |
|
|
|
bank.add_inventory_item(inventory_item)?;
|
|
|
|
|
|
|
|
transaction.gateway().set_character_bank(&character_id, &bank.as_bank_entity(), &bank.name).await?;
|
|
|
|
item_state.set_bank(bank);
|
|
|
|
item_state.set_bank(bank).await;
|
|
|
|
|
|
|
|
|
|
|
|
Ok(((item_state, transaction), ()))
|
|
|
@ -324,16 +398,22 @@ pub(super) fn add_inventory_item_to_bank(character_id: CharacterEntityId) |
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
pub(super) fn equip_inventory_item(character_id: CharacterEntityId, item_id: ClientItemId, equip_slot: u8)
|
|
|
|
-> impl for<'a> Fn((ItemStateProxy<'a>, Box<dyn EntityGatewayTransaction + 'a>), ())
|
|
|
|
-> Pin<Box<dyn Future<Output=Result<((ItemStateProxy<'a>, Box<dyn EntityGatewayTransaction + 'a>), ()), ItemStateError>> + Send + 'a>>
|
|
|
|
pub(super) fn equip_inventory_item<EG, TR>(
|
|
|
|
character_id: CharacterEntityId,
|
|
|
|
item_id: ClientItemId,
|
|
|
|
equip_slot: u8,
|
|
|
|
) -> impl Fn((ItemStateProxy, TR), ())
|
|
|
|
-> BoxFuture<Result<((ItemStateProxy, TR), ()), ItemStateError>>
|
|
|
|
where
|
|
|
|
EG: EntityGateway,
|
|
|
|
TR: EntityGatewayTransaction<ParentGateway = EG> + 'static,
|
|
|
|
{
|
|
|
|
move |(mut item_state, mut transaction), _| {
|
|
|
|
Box::pin(async move {
|
|
|
|
let mut inventory = item_state.inventory(&character_id).await?;
|
|
|
|
inventory.equip(&item_id, equip_slot);
|
|
|
|
transaction.gateway().set_character_equips(&character_id, &inventory.as_equipped_entity()).await?;
|
|
|
|
item_state.set_inventory(inventory);
|
|
|
|
item_state.set_inventory(inventory).await;
|
|
|
|
|
|
|
|
Ok(((item_state, transaction), ()))
|
|
|
|
})
|
|
|
@ -341,16 +421,21 @@ pub(super) fn equip_inventory_item(character_id: CharacterEntityId, item_id: Cli |
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
pub(super) fn unequip_inventory_item(character_id: CharacterEntityId, item_id: ClientItemId)
|
|
|
|
-> impl for<'a> Fn((ItemStateProxy<'a>, Box<dyn EntityGatewayTransaction + 'a>), ())
|
|
|
|
-> Pin<Box<dyn Future<Output=Result<((ItemStateProxy<'a>, Box<dyn EntityGatewayTransaction + 'a>), ()), ItemStateError>> + Send + 'a>>
|
|
|
|
pub(super) fn unequip_inventory_item<EG, TR>(
|
|
|
|
character_id: CharacterEntityId,
|
|
|
|
item_id: ClientItemId,
|
|
|
|
) -> impl Fn((ItemStateProxy, TR), ())
|
|
|
|
-> BoxFuture<Result<((ItemStateProxy, TR), ()), ItemStateError>>
|
|
|
|
where
|
|
|
|
EG: EntityGateway,
|
|
|
|
TR: EntityGatewayTransaction<ParentGateway = EG> + 'static,
|
|
|
|
{
|
|
|
|
move |(mut item_state, mut transaction), _| {
|
|
|
|
Box::pin(async move {
|
|
|
|
let mut inventory = item_state.inventory(&character_id).await?;
|
|
|
|
inventory.unequip(&item_id);
|
|
|
|
transaction.gateway().set_character_equips(&character_id, &inventory.as_equipped_entity()).await?;
|
|
|
|
item_state.set_inventory(inventory);
|
|
|
|
item_state.set_inventory(inventory).await;
|
|
|
|
|
|
|
|
Ok(((item_state, transaction), ()))
|
|
|
|
})
|
|
|
@ -359,9 +444,14 @@ pub(super) fn unequip_inventory_item(character_id: CharacterEntityId, item_id: C |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
pub(super) fn sort_inventory_items(character_id: CharacterEntityId, item_ids: Vec<ClientItemId>)
|
|
|
|
-> impl for<'a> Fn((ItemStateProxy<'a>, Box<dyn EntityGatewayTransaction + 'a>), ())
|
|
|
|
-> Pin<Box<dyn Future<Output=Result<((ItemStateProxy<'a>, Box<dyn EntityGatewayTransaction + 'a>), ()), ItemStateError>> + Send + 'a>>
|
|
|
|
pub(super) fn sort_inventory_items<EG, TR>(
|
|
|
|
character_id: CharacterEntityId,
|
|
|
|
item_ids: Vec<ClientItemId>,
|
|
|
|
) -> impl Fn((ItemStateProxy, TR), ())
|
|
|
|
-> BoxFuture<Result<((ItemStateProxy, TR), ()), ItemStateError>>
|
|
|
|
where
|
|
|
|
EG: EntityGateway,
|
|
|
|
TR: EntityGatewayTransaction<ParentGateway = EG> + 'static,
|
|
|
|
{
|
|
|
|
move |(mut item_state, mut transaction), _| {
|
|
|
|
let item_ids = item_ids.clone();
|
|
|
@ -369,7 +459,7 @@ pub(super) fn sort_inventory_items(character_id: CharacterEntityId, item_ids: Ve |
|
|
|
let mut inventory = item_state.inventory(&character_id).await?;
|
|
|
|
inventory.sort(&item_ids);
|
|
|
|
transaction.gateway().set_character_inventory(&character_id, &inventory.as_inventory_entity(&character_id)).await?;
|
|
|
|
item_state.set_inventory(inventory);
|
|
|
|
item_state.set_inventory(inventory).await;
|
|
|
|
|
|
|
|
Ok(((item_state, transaction), ()))
|
|
|
|
})
|
|
|
@ -377,10 +467,15 @@ pub(super) fn sort_inventory_items(character_id: CharacterEntityId, item_ids: Ve |
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
pub(super) fn use_consumed_item(character: CharacterEntity)
|
|
|
|
-> impl for<'a> Fn((ItemStateProxy<'a>, Box<dyn EntityGatewayTransaction + 'a>), InventoryItem)
|
|
|
|
-> Pin<Box<dyn Future<Output=Result<((ItemStateProxy<'a>, Box<dyn EntityGatewayTransaction + 'a>), CharacterEntity), ItemStateError>> + Send + 'a>>
|
|
|
|
pub(super) fn use_consumed_item<EG, TR>(
|
|
|
|
character: &CharacterEntity,
|
|
|
|
) -> impl Fn((ItemStateProxy, TR), InventoryItem)
|
|
|
|
-> BoxFuture<Result<((ItemStateProxy, TR), Vec<ApplyItemAction>), ItemStateError>>
|
|
|
|
where
|
|
|
|
EG: EntityGateway + Clone + 'static,
|
|
|
|
TR: EntityGatewayTransaction<ParentGateway = EG> + 'static,
|
|
|
|
{
|
|
|
|
let character = character.clone();
|
|
|
|
move |(mut item_state, transaction), inventory_item| {
|
|
|
|
let mut character = character.clone();
|
|
|
|
Box::pin(async move {
|
|
|
@ -390,17 +485,22 @@ pub(super) fn use_consumed_item(character: CharacterEntity) |
|
|
|
Ok(transaction)
|
|
|
|
}}).await?;
|
|
|
|
|
|
|
|
apply_item(&mut item_state, transaction.gateway(), &mut character, inventory_item).await?;
|
|
|
|
let apply_item_actions = apply_item(&mut item_state, transaction.gateway(), &mut character, inventory_item).await?;
|
|
|
|
|
|
|
|
Ok(((item_state, transaction), character))
|
|
|
|
Ok(((item_state, transaction), apply_item_actions))
|
|
|
|
})
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
pub(super) fn feed_mag_item(character: CharacterEntity, mag_item_id: ClientItemId)
|
|
|
|
-> impl for<'a> Fn((ItemStateProxy<'a>, Box<dyn EntityGatewayTransaction + 'a>), InventoryItem)
|
|
|
|
-> Pin<Box<dyn Future<Output=Result<((ItemStateProxy<'a>, Box<dyn EntityGatewayTransaction + 'a>), CharacterEntity), ItemStateError>> + Send + 'a>>
|
|
|
|
pub(super) fn feed_mag_item<EG, TR>(
|
|
|
|
character: CharacterEntity,
|
|
|
|
mag_item_id: ClientItemId,
|
|
|
|
) -> impl Fn((ItemStateProxy, TR), InventoryItem)
|
|
|
|
-> BoxFuture<Result<((ItemStateProxy, TR), CharacterEntity), ItemStateError>>
|
|
|
|
where
|
|
|
|
EG: EntityGateway,
|
|
|
|
TR: EntityGatewayTransaction<ParentGateway = EG> + 'static,
|
|
|
|
{
|
|
|
|
move |(mut item_state, transaction), tool| {
|
|
|
|
let character = character.clone();
|
|
|
@ -437,20 +537,24 @@ pub(super) fn feed_mag_item(character: CharacterEntity, mag_item_id: ClientItemI |
|
|
|
mag_entity.feed(food_tool);
|
|
|
|
|
|
|
|
transaction.gateway().set_character_inventory(&character.id, &inventory.as_inventory_entity(&character.id)).await?;
|
|
|
|
item_state.set_inventory(inventory);
|
|
|
|
item_state.set_inventory(inventory).await;
|
|
|
|
|
|
|
|
Ok(((item_state, transaction), character))
|
|
|
|
})
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
pub(super) fn add_bought_item_to_inventory<'a>(character_id: CharacterEntityId,
|
|
|
|
#[allow(clippy::needless_lifetimes)] // clippy this lifetime is not needless get off my case
|
|
|
|
pub(super) fn add_bought_item_to_inventory<'a, EG, TR>(
|
|
|
|
character_id: CharacterEntityId,
|
|
|
|
shop_item: &'a (dyn ShopItem + Send + Sync),
|
|
|
|
item_id: ClientItemId,
|
|
|
|
amount: u32)
|
|
|
|
-> impl Fn((ItemStateProxy<'a>, Box<dyn EntityGatewayTransaction + 'a>), ())
|
|
|
|
-> Pin<Box<dyn Future<Output=Result<((ItemStateProxy<'a>, Box<dyn EntityGatewayTransaction + 'a>), InventoryItem), ItemStateError>> + Send + 'a>>
|
|
|
|
amount: u32,
|
|
|
|
) -> impl Fn((ItemStateProxy, TR), ())
|
|
|
|
-> Pin<Box<dyn Future<Output=Result<((ItemStateProxy, TR), InventoryItem), ItemStateError>> + Send + 'a>>
|
|
|
|
where
|
|
|
|
EG: EntityGateway,
|
|
|
|
TR: EntityGatewayTransaction<ParentGateway = EG> + 'static,
|
|
|
|
{
|
|
|
|
move |(mut item_state, mut transaction), _| {
|
|
|
|
Box::pin(async move {
|
|
|
@ -499,16 +603,20 @@ pub(super) fn add_bought_item_to_inventory<'a>(character_id: CharacterEntityId, |
|
|
|
};
|
|
|
|
|
|
|
|
transaction.gateway().set_character_inventory(&character_id, &inventory.as_inventory_entity(&character_id)).await?;
|
|
|
|
item_state.set_inventory(inventory);
|
|
|
|
item_state.set_inventory(inventory).await;
|
|
|
|
Ok(((item_state, transaction), inventory_item))
|
|
|
|
})
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
pub(super) fn sell_inventory_item<'a>(character_id: CharacterEntityId)
|
|
|
|
-> impl Fn((ItemStateProxy<'a>, Box<dyn EntityGatewayTransaction + 'a>), InventoryItem)
|
|
|
|
-> Pin<Box<dyn Future<Output=Result<((ItemStateProxy<'a>, Box<dyn EntityGatewayTransaction + 'a>), InventoryItem), ItemStateError>> + Send + 'a>>
|
|
|
|
pub(super) fn sell_inventory_item<EG, TR>(
|
|
|
|
character_id: CharacterEntityId,
|
|
|
|
) -> impl Fn((ItemStateProxy, TR), InventoryItem)
|
|
|
|
-> BoxFuture<Result<((ItemStateProxy, TR), InventoryItem), ItemStateError>>
|
|
|
|
where
|
|
|
|
EG: EntityGateway,
|
|
|
|
TR: EntityGatewayTransaction<ParentGateway = EG> + 'static,
|
|
|
|
{
|
|
|
|
move |(mut item_state, transaction), inventory_item| {
|
|
|
|
Box::pin(async move {
|
|
|
@ -522,7 +630,7 @@ pub(super) fn sell_inventory_item<'a>(character_id: CharacterEntityId) |
|
|
|
Ok(transaction)
|
|
|
|
}}).await?;
|
|
|
|
transaction.gateway().set_character_meseta(&character_id, inventory.meseta).await?;
|
|
|
|
item_state.set_inventory(inventory);
|
|
|
|
item_state.set_inventory(inventory).await;
|
|
|
|
Ok(((item_state, transaction), inventory_item))
|
|
|
|
})
|
|
|
|
}
|
|
|
@ -530,19 +638,22 @@ pub(super) fn sell_inventory_item<'a>(character_id: CharacterEntityId) |
|
|
|
|
|
|
|
|
|
|
|
#[async_recursion::async_recursion]
|
|
|
|
async fn iterate_inner<'a, I, O, T, F, FR>(state: (ItemStateProxy<'a>, Box<dyn EntityGatewayTransaction + 'a>),
|
|
|
|
async fn iterate_inner<'a, EG, TR, I, O, T, F, FR>(
|
|
|
|
state: (ItemStateProxy, TR),
|
|
|
|
mut input: Vec<I>,
|
|
|
|
func: F,
|
|
|
|
arg: T)
|
|
|
|
-> Result<((ItemStateProxy<'a>, Box<dyn EntityGatewayTransaction + 'a>), Vec<O>), ItemStateError>
|
|
|
|
arg: T,
|
|
|
|
) -> Result<((ItemStateProxy, TR), Vec<O>), ItemStateError>
|
|
|
|
where
|
|
|
|
'a: 'async_recursion,
|
|
|
|
EG: EntityGateway,
|
|
|
|
TR: EntityGatewayTransaction<ParentGateway = EG>,
|
|
|
|
I: Send,
|
|
|
|
O: Send,
|
|
|
|
T: Clone + Send + Sync,
|
|
|
|
F: Fn(I) -> FR + Send + Sync + Clone + 'static,
|
|
|
|
FR: Fn((ItemStateProxy<'a>, Box<dyn EntityGatewayTransaction + 'a>), T)
|
|
|
|
-> Pin<Box<dyn Future<Output=Result<((ItemStateProxy<'a>, Box<dyn EntityGatewayTransaction + 'a>), O), ItemStateError>> + Send + 'a>> + Send + Sync,
|
|
|
|
FR: Fn((ItemStateProxy, TR), T)
|
|
|
|
-> BoxFuture<Result<((ItemStateProxy, TR), O), ItemStateError>> + Send + Sync,
|
|
|
|
{
|
|
|
|
let item = match input.pop() {
|
|
|
|
Some(item) => item,
|
|
|
@ -558,18 +669,20 @@ where |
|
|
|
Ok((state, output))
|
|
|
|
}
|
|
|
|
|
|
|
|
pub(super) fn iterate<'k, I, O, T, F, FR>(
|
|
|
|
pub(super) fn iterate<EG, TR, I, O, T, F, FR>(
|
|
|
|
input: Vec<I>,
|
|
|
|
func: F)
|
|
|
|
-> impl for<'a> Fn((ItemStateProxy<'a>, Box<dyn EntityGatewayTransaction + 'a>), T)
|
|
|
|
-> Pin<Box<dyn Future<Output=Result<((ItemStateProxy<'a>, Box<dyn EntityGatewayTransaction + 'a>), Vec<O>), ItemStateError>> + Send + 'a>>
|
|
|
|
func: F,
|
|
|
|
) -> impl Fn((ItemStateProxy, TR), T)
|
|
|
|
-> BoxFuture<Result<((ItemStateProxy, TR), Vec<O>), ItemStateError>>
|
|
|
|
where
|
|
|
|
EG: EntityGateway,
|
|
|
|
TR: EntityGatewayTransaction<ParentGateway = EG> + 'static,
|
|
|
|
O: Send,
|
|
|
|
I: Send + Clone + 'static + std::fmt::Debug,
|
|
|
|
T: Send + Clone + 'static + std::fmt::Debug,
|
|
|
|
F: Fn(I) -> FR + Send + Sync + Clone + 'static,
|
|
|
|
FR: for<'a> Fn((ItemStateProxy<'a>, Box<dyn EntityGatewayTransaction + 'a>), T)
|
|
|
|
-> Pin<Box<dyn Future<Output=Result<((ItemStateProxy<'a>, Box<dyn EntityGatewayTransaction + 'a>), O), ItemStateError>> + Send + 'a>> + Send + Sync,
|
|
|
|
FR: Fn((ItemStateProxy, TR), T)
|
|
|
|
-> BoxFuture<Result<((ItemStateProxy, TR), O), ItemStateError>> + Send + Sync,
|
|
|
|
T: Clone + Send + Sync,
|
|
|
|
{
|
|
|
|
move |(item_state, transaction), arg| {
|
|
|
@ -584,19 +697,22 @@ where |
|
|
|
|
|
|
|
|
|
|
|
#[async_recursion::async_recursion]
|
|
|
|
async fn foreach_inner<'a, O, T, F>(state: (ItemStateProxy<'a>, Box<dyn EntityGatewayTransaction + 'a>),
|
|
|
|
mut input: Vec<T>,
|
|
|
|
func: F)
|
|
|
|
-> Result<((ItemStateProxy<'a>, Box<dyn EntityGatewayTransaction + 'a>), Vec<O>), ItemStateError>
|
|
|
|
async fn foreach_inner<'a, EG, TR, O, T, F, I>(
|
|
|
|
state: (ItemStateProxy, TR),
|
|
|
|
mut input: I,
|
|
|
|
func: Arc<F>,
|
|
|
|
) -> Result<((ItemStateProxy, TR), Vec<O>), ItemStateError>
|
|
|
|
where
|
|
|
|
'a: 'async_recursion,
|
|
|
|
EG: EntityGateway,
|
|
|
|
TR: EntityGatewayTransaction<ParentGateway = EG> + 'static,
|
|
|
|
O: Send,
|
|
|
|
T: Clone + Send,
|
|
|
|
F: Fn((ItemStateProxy<'a>, Box<dyn EntityGatewayTransaction + 'a>), T)
|
|
|
|
-> Pin<Box<dyn Future<Output=Result<((ItemStateProxy<'a>, Box<dyn EntityGatewayTransaction + 'a>), O), ItemStateError>> + Send + 'a>> + Send + Sync,
|
|
|
|
F: Clone,
|
|
|
|
T: Send,
|
|
|
|
F: Fn((ItemStateProxy, TR), T)
|
|
|
|
-> BoxFuture<Result<((ItemStateProxy, TR), O), ItemStateError>> + Send + Sync,
|
|
|
|
I: Iterator<Item = T> + Send + Sync + 'static,
|
|
|
|
{
|
|
|
|
let item = match input.pop() {
|
|
|
|
let item = match input.next() {
|
|
|
|
Some(item) => item,
|
|
|
|
None => return Ok((state, Vec::new()))
|
|
|
|
};
|
|
|
@ -609,19 +725,25 @@ where |
|
|
|
Ok((state, output))
|
|
|
|
}
|
|
|
|
|
|
|
|
pub(super) fn foreach<'k, O, T, F>(func: F)
|
|
|
|
-> impl for<'a> Fn((ItemStateProxy<'a>, Box<dyn EntityGatewayTransaction + 'a>), Vec<T>)
|
|
|
|
-> Pin<Box<dyn Future<Output=Result<((ItemStateProxy<'a>, Box<dyn EntityGatewayTransaction + 'a>), Vec<O>), ItemStateError>> + Send + 'a>>
|
|
|
|
pub(super) fn foreach<EG, TR, O, T, F, I>(
|
|
|
|
func: F
|
|
|
|
) -> impl Fn((ItemStateProxy, TR), I)
|
|
|
|
-> BoxFuture<Result<((ItemStateProxy, TR), Vec<O>), ItemStateError>>
|
|
|
|
where
|
|
|
|
EG: EntityGateway,
|
|
|
|
TR: EntityGatewayTransaction<ParentGateway = EG> + 'static,
|
|
|
|
O: Send,
|
|
|
|
T: Send + Clone + 'static + std::fmt::Debug,
|
|
|
|
F: for<'a> Fn((ItemStateProxy<'a>, Box<dyn EntityGatewayTransaction + 'a>), T)
|
|
|
|
-> Pin<Box<dyn Future<Output=Result<((ItemStateProxy<'a>, Box<dyn EntityGatewayTransaction + 'a>), O), ItemStateError>> + Send + 'a>> + Send + Sync + 'static,
|
|
|
|
F: Clone,
|
|
|
|
T: Clone + Send + Sync,
|
|
|
|
F: Fn((ItemStateProxy, TR), T)
|
|
|
|
-> BoxFuture<Result<((ItemStateProxy, TR), O), ItemStateError>> + Send + Sync + 'static,
|
|
|
|
T: Send + Sync,
|
|
|
|
I: IntoIterator<Item = T> + Send + Sync + 'static,
|
|
|
|
I::IntoIter: Send + Sync,
|
|
|
|
{
|
|
|
|
let func = Arc::new(func);
|
|
|
|
move |(item_state, transaction), items| {
|
|
|
|
let func = func.clone();
|
|
|
|
let items = items.into_iter();
|
|
|
|
Box::pin(async move {
|
|
|
|
let (state, result) = foreach_inner((item_state, transaction), items, func).await?;
|
|
|
|
Ok((state, result))
|
|
|
@ -629,9 +751,14 @@ where |
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
pub(super) fn insert<'a, T: Send + Clone + 'a>(element: T)
|
|
|
|
-> impl Fn((ItemStateProxy<'a>, Box<dyn EntityGatewayTransaction + 'a>), ())
|
|
|
|
-> Pin<Box<dyn Future<Output=Result<((ItemStateProxy<'a>, Box<dyn EntityGatewayTransaction + 'a>), T), ItemStateError>> + Send + 'a>>
|
|
|
|
pub(super) fn insert<'a, EG, TR, T>(
|
|
|
|
element: T
|
|
|
|
) -> impl Fn((ItemStateProxy, TR), ())
|
|
|
|
-> Pin<Box<dyn Future<Output=Result<((ItemStateProxy, TR), T), ItemStateError>> + Send + 'a>>
|
|
|
|
where
|
|
|
|
EG: EntityGateway,
|
|
|
|
TR: EntityGatewayTransaction<ParentGateway = EG> + 'static,
|
|
|
|
T: Send + Clone + 'a,
|
|
|
|
{
|
|
|
|
move |state, _| {
|
|
|
|
let element = element.clone();
|
|
|
@ -641,9 +768,41 @@ pub(super) fn insert<'a, T: Send + Clone + 'a>(element: T) |
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
pub(super) fn add_item_to_inventory(character: CharacterEntity)
|
|
|
|
-> impl for<'a> Fn((ItemStateProxy<'a>, Box<dyn EntityGatewayTransaction + 'a>), InventoryItem)
|
|
|
|
-> Pin<Box<dyn Future<Output=Result<((ItemStateProxy<'a>, Box<dyn EntityGatewayTransaction + 'a>), InventoryItem), ItemStateError>> + Send + 'a>> + Clone
|
|
|
|
pub(super) fn fork<EG, TR, F1, F2, T, O1, O2>(
|
|
|
|
func1: F1,
|
|
|
|
func2: F2,
|
|
|
|
) -> impl Fn((ItemStateProxy, TR), T)
|
|
|
|
-> BoxFuture<Result<((ItemStateProxy, TR), (O1, O2)), ItemStateError>>
|
|
|
|
where
|
|
|
|
EG: EntityGateway,
|
|
|
|
TR: EntityGatewayTransaction<ParentGateway = EG> + 'static,
|
|
|
|
F1: Fn((ItemStateProxy, TR), T) -> BoxFuture<Result<((ItemStateProxy, TR), O1), ItemStateError>> + Send + Sync + 'static,
|
|
|
|
F2: Fn((ItemStateProxy, TR), T) -> BoxFuture<Result<((ItemStateProxy, TR), O2), ItemStateError>> + Send + Sync + 'static,
|
|
|
|
T: Send + Sync + Clone + 'static,
|
|
|
|
O1: Send,
|
|
|
|
O2: Send,
|
|
|
|
{
|
|
|
|
let func1 = Arc::new(func1);
|
|
|
|
let func2 = Arc::new(func2);
|
|
|
|
move |(item_state, transaction), input| {
|
|
|
|
let func1 = func1.clone();
|
|
|
|
let func2 = func2.clone();
|
|
|
|
Box::pin(async move {
|
|
|
|
let ((item_state, transaction), result1) = func1((item_state, transaction), input.clone()).await?;
|
|
|
|
let ((item_state, transaction), result2) = func2((item_state, transaction), input).await?;
|
|
|
|
|
|
|
|
Ok(((item_state, transaction), (result1, result2)))
|
|
|
|
})
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
pub(super) fn add_item_to_inventory<EG, TR>(
|
|
|
|
character: CharacterEntity,
|
|
|
|
) -> impl Fn((ItemStateProxy, TR), InventoryItem)
|
|
|
|
-> BoxFuture<Result<((ItemStateProxy, TR), InventoryItem), ItemStateError>> + Clone
|
|
|
|
where
|
|
|
|
EG: EntityGateway,
|
|
|
|
TR: EntityGatewayTransaction<ParentGateway = EG> + 'static,
|
|
|
|
{
|
|
|
|
move |(mut item_state, transaction), inventory_item| {
|
|
|
|
let character = character.clone();
|
|
|
@ -658,16 +817,22 @@ pub(super) fn add_item_to_inventory(character: CharacterEntity) |
|
|
|
|
|
|
|
inventory.add_item(inventory_item.clone())?;
|
|
|
|
transaction.gateway().set_character_inventory(&character.id, &inventory.as_inventory_entity(&character.id)).await?;
|
|
|
|
item_state.set_inventory(inventory);
|
|
|
|
item_state.set_inventory(inventory).await;
|
|
|
|
|
|
|
|
Ok(((item_state, transaction), inventory_item))
|
|
|
|
})
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
pub(super) fn record_trade(trade_id: TradeId, character_to: CharacterEntityId, character_from: CharacterEntityId)
|
|
|
|
-> impl for<'a> Fn((ItemStateProxy<'a>, Box<dyn EntityGatewayTransaction + 'a>), Vec<InventoryItem>)
|
|
|
|
-> Pin<Box<dyn Future<Output=Result<((ItemStateProxy<'a>, Box<dyn EntityGatewayTransaction + 'a>), Vec<InventoryItem>), ItemStateError>> + Send + 'a>> + Clone
|
|
|
|
pub(super) fn record_trade<EG, TR>(
|
|
|
|
trade_id: TradeId,
|
|
|
|
character_to: CharacterEntityId,
|
|
|
|
character_from: CharacterEntityId,
|
|
|
|
) -> impl Fn((ItemStateProxy, TR), Vec<InventoryItem>)
|
|
|
|
-> BoxFuture<Result<((ItemStateProxy, TR), Vec<InventoryItem>), ItemStateError>> + Clone
|
|
|
|
where
|
|
|
|
EG: EntityGateway,
|
|
|
|
TR: EntityGatewayTransaction<ParentGateway = EG> + 'static,
|
|
|
|
{
|
|
|
|
move |(item_state, mut transaction), traded_items| {
|
|
|
|
Box::pin(async move {
|
|
|
@ -688,9 +853,12 @@ pub(super) fn record_trade(trade_id: TradeId, character_to: CharacterEntityId, c |
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
pub(super) fn assign_new_item_id()
|
|
|
|
-> impl for<'a> Fn((ItemStateProxy<'a>, Box<dyn EntityGatewayTransaction + 'a>), InventoryItem)
|
|
|
|
-> Pin<Box<dyn Future<Output=Result<((ItemStateProxy<'a>, Box<dyn EntityGatewayTransaction + 'a>), InventoryItem), ItemStateError>> + Send + 'a>> + Clone
|
|
|
|
pub(super) fn assign_new_item_id<EG, TR>(
|
|
|
|
) -> impl Fn((ItemStateProxy, TR), InventoryItem)
|
|
|
|
-> BoxFuture<Result<((ItemStateProxy, TR), InventoryItem), ItemStateError>> + Clone
|
|
|
|
where
|
|
|
|
EG: EntityGateway,
|
|
|
|
TR: EntityGatewayTransaction<ParentGateway = EG> + 'static,
|
|
|
|
{
|
|
|
|
move |(mut item_state, transaction), mut inventory_item| {
|
|
|
|
Box::pin(async move {
|
|
|
@ -701,9 +869,14 @@ pub(super) fn assign_new_item_id() |
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
pub(super) fn convert_item_drop_to_floor_item(character_id: CharacterEntityId, item_drop: ItemDrop)
|
|
|
|
-> impl for<'a> Fn((ItemStateProxy<'a>, Box<dyn EntityGatewayTransaction + 'a>), ())
|
|
|
|
-> Pin<Box<dyn Future<Output=Result<((ItemStateProxy<'a>, Box<dyn EntityGatewayTransaction + 'a>), FloorItem), ItemStateError>> + Send + 'a>> + Clone
|
|
|
|
pub(super) fn convert_item_drop_to_floor_item<EG, TR>(
|
|
|
|
character_id: CharacterEntityId,
|
|
|
|
item_drop: ItemDrop,
|
|
|
|
) -> impl Fn((ItemStateProxy, TR), ())
|
|
|
|
-> BoxFuture<Result<((ItemStateProxy, TR), FloorItem), ItemStateError>> + Clone
|
|
|
|
where
|
|
|
|
EG: EntityGateway,
|
|
|
|
TR: EntityGatewayTransaction<ParentGateway = EG> + 'static,
|
|
|
|
{
|
|
|
|
move |(mut item_state, mut transaction), _| {
|
|
|
|
let item_drop = item_drop.clone();
|
|
|
@ -798,9 +971,13 @@ pub(super) fn convert_item_drop_to_floor_item(character_id: CharacterEntityId, i |
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
pub(super) fn add_item_to_local_floor(character_id: CharacterEntityId)
|
|
|
|
-> impl for<'a> Fn((ItemStateProxy<'a>, Box<dyn EntityGatewayTransaction + 'a>), FloorItem)
|
|
|
|
-> Pin<Box<dyn Future<Output=Result<((ItemStateProxy<'a>, Box<dyn EntityGatewayTransaction + 'a>), FloorItem), ItemStateError>> + Send + 'a>>
|
|
|
|
pub(super) fn add_item_to_local_floor<EG, TR>(
|
|
|
|
character_id: CharacterEntityId,
|
|
|
|
) -> impl Fn((ItemStateProxy, TR), FloorItem)
|
|
|
|
-> BoxFuture<Result<((ItemStateProxy, TR), FloorItem), ItemStateError>>
|
|
|
|
where
|
|
|
|
EG: EntityGateway,
|
|
|
|
TR: EntityGatewayTransaction<ParentGateway = EG> + 'static,
|
|
|
|
{
|
|
|
|
move |(mut item_state, transaction) , floor_item| {
|
|
|
|
Box::pin(async move {
|
|
|
@ -813,9 +990,13 @@ pub(super) fn add_item_to_local_floor(character_id: CharacterEntityId) |
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
pub(super) fn apply_modifier_to_inventory_item(modifier: ItemModifier)
|
|
|
|
-> impl for<'a> Fn((ItemStateProxy<'a>, Box<dyn EntityGatewayTransaction + 'a>), InventoryItem)
|
|
|
|
-> Pin<Box<dyn Future<Output=Result<((ItemStateProxy<'a>, Box<dyn EntityGatewayTransaction + 'a>), InventoryItem), ItemStateError>> + Send + 'a>>
|
|
|
|
pub(super) fn apply_modifier_to_inventory_item<EG, TR>(
|
|
|
|
modifier: ItemModifier,
|
|
|
|
) -> impl Fn((ItemStateProxy, TR), InventoryItem)
|
|
|
|
-> BoxFuture<Result<((ItemStateProxy, TR), InventoryItem), ItemStateError>>
|
|
|
|
where
|
|
|
|
EG: EntityGateway,
|
|
|
|
TR: EntityGatewayTransaction<ParentGateway = EG> + 'static,
|
|
|
|
{
|
|
|
|
move |(item_state, mut transaction), mut inventory_item| {
|
|
|
|
let modifier = modifier.clone();
|
|
|
@ -833,9 +1014,12 @@ pub(super) fn apply_modifier_to_inventory_item(modifier: ItemModifier) |
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
pub(super) fn as_individual_item()
|
|
|
|
-> impl for<'a> Fn((ItemStateProxy<'a>, Box<dyn EntityGatewayTransaction + 'a>), InventoryItem)
|
|
|
|
-> Pin<Box<dyn Future<Output=Result<((ItemStateProxy<'a>, Box<dyn EntityGatewayTransaction + 'a>), IndividualItemDetail), ItemStateError>> + Send + 'a>>
|
|
|
|
pub(super) fn as_individual_item<EG, TR>(
|
|
|
|
) -> impl Fn((ItemStateProxy, TR), InventoryItem)
|
|
|
|
-> BoxFuture<Result<((ItemStateProxy, TR), IndividualItemDetail), ItemStateError>>
|
|
|
|
where
|
|
|
|
EG: EntityGateway,
|
|
|
|
TR: EntityGatewayTransaction<ParentGateway = EG> + 'static,
|
|
|
|
{
|
|
|
|
move |(item_state, transaction), inventory_item| {
|
|
|
|
Box::pin(async move {
|
|
|
@ -848,3 +1032,85 @@ pub(super) fn as_individual_item() |
|
|
|
})
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
pub(super) fn apply_item_action_packets<EG, TR>(
|
|
|
|
character_id: CharacterEntityId,
|
|
|
|
area_client: AreaClient,
|
|
|
|
) -> impl Fn((ItemStateProxy, TR), ApplyItemAction)
|
|
|
|
-> BoxFuture<Result<((ItemStateProxy, TR), Vec<SendShipPacket>), ItemStateError>>
|
|
|
|
where
|
|
|
|
EG: EntityGateway,
|
|
|
|
TR: EntityGatewayTransaction<ParentGateway = EG> + 'static,
|
|
|
|
{
|
|
|
|
move |(mut item_state, mut transaction), apply_item_action| {
|
|
|
|
Box::pin(async move {
|
|
|
|
let pkts = if let ApplyItemAction::CreateItem(item_detail) = apply_item_action {
|
|
|
|
let new_item = transaction.gateway().create_item(NewItemEntity {
|
|
|
|
item: item_detail.clone(),
|
|
|
|
}).await?;
|
|
|
|
|
|
|
|
let item_id = item_state.new_item_id().await?;
|
|
|
|
|
|
|
|
let (inventory_item_detail, create_item) = if item_detail.is_stackable() {
|
|
|
|
let tool = item_detail.as_tool().ok_or_else(|| ItemStateError::NotATool(ClientItemId(0xFFFFFFFF)))?;
|
|
|
|
|
|
|
|
let create_item = builder::message::create_stacked_item(area_client, item_id, &tool, 1).map_err(|_err| ItemStateError::Dummy)?;
|
|
|
|
let item_detail = StackedItemDetail {
|
|
|
|
entity_ids: vec![new_item.id],
|
|
|
|
tool
|
|
|
|
};
|
|
|
|
(InventoryItemDetail::Stacked(item_detail), create_item)
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
let item_detail = IndividualItemDetail {
|
|
|
|
entity_id: new_item.id,
|
|
|
|
item: item_detail,
|
|
|
|
};
|
|
|
|
let create_item = builder::message::create_individual_item(area_client, item_id, &item_detail).map_err(|_err| ItemStateError::Dummy)?;
|
|
|
|
(InventoryItemDetail::Individual(item_detail), create_item)
|
|
|
|
};
|
|
|
|
|
|
|
|
let inventory_item = InventoryItem {
|
|
|
|
item_id,
|
|
|
|
item: inventory_item_detail,
|
|
|
|
};
|
|
|
|
|
|
|
|
let mut inventory = item_state.inventory(&character_id).await?;
|
|
|
|
inventory.add_item(inventory_item)?;
|
|
|
|
transaction.gateway().set_character_inventory(&character_id, &inventory.as_inventory_entity(&character_id)).await?;
|
|
|
|
item_state.set_inventory(inventory).await;
|
|
|
|
|
|
|
|
vec![SendShipPacket::Message(Message::new(GameMessage::CreateItem(create_item)))]
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
Vec::new()
|
|
|
|
};
|
|
|
|
|
|
|
|
Ok(((item_state, transaction), pkts))
|
|
|
|
})
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
pub(super) fn apply_item_action_character<EG, TR>(
|
|
|
|
character: &CharacterEntity
|
|
|
|
) -> impl Fn((ItemStateProxy, TR), Vec<ApplyItemAction>)
|
|
|
|
-> BoxFuture<Result<((ItemStateProxy, TR), CharacterEntity), ItemStateError>>
|
|
|
|
where
|
|
|
|
EG: EntityGateway,
|
|
|
|
TR: EntityGatewayTransaction<ParentGateway = EG> + 'static,
|
|
|
|
{
|
|
|
|
let character = character.clone();
|
|
|
|
move |(item_state, transaction), apply_item_actions| {
|
|
|
|
let mut character = character.clone();
|
|
|
|
Box::pin(async move {
|
|
|
|
for action in apply_item_actions {
|
|
|
|
if let ApplyItemAction::UpdateCharacter(new_character) = action {
|
|
|
|
character = *new_character
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
Ok(((item_state, transaction), character))
|
|
|
|
})
|
|
|
|
}
|
|
|
|
}
|