|
|
@ -3,6 +3,7 @@ use crate::ship::items::ClientItemId; |
|
|
|
use crate::entity::item::{Meseta, ItemNote};
|
|
|
|
use async_std::sync::Arc;
|
|
|
|
use std::future::Future;
|
|
|
|
use futures::future::BoxFuture;
|
|
|
|
use std::pin::Pin;
|
|
|
|
use std::iter::IntoIterator;
|
|
|
|
use anyhow::Context;
|
|
|
@ -25,21 +26,22 @@ 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>>;
|
|
|
|
//type BoxFuture<T> = Pin<Box<dyn Future<Output=T> + Send>>;
|
|
|
|
//type LBoxFuture<'a, T> = Pin<Box<dyn Future<Output=T> + Send + 'a>>;
|
|
|
|
|
|
|
|
pub enum TriggerCreateItem {
|
|
|
|
Yes,
|
|
|
|
No
|
|
|
|
}
|
|
|
|
|
|
|
|
pub(super) fn take_item_from_floor<EG, TR>(
|
|
|
|
pub(super) fn take_item_from_floor<'a, EG, TR>(
|
|
|
|
character_id: CharacterEntityId,
|
|
|
|
item_id: ClientItemId
|
|
|
|
) -> impl Fn((ItemStateProxy, TR), ())
|
|
|
|
-> BoxFuture<Result<((ItemStateProxy, TR), FloorItem), anyhow::Error>>
|
|
|
|
-> BoxFuture<'a, Result<((ItemStateProxy, TR), FloorItem), anyhow::Error>> + 'a
|
|
|
|
where
|
|
|
|
EG: EntityGateway + Send,
|
|
|
|
TR: EntityGatewayTransaction<ParentGateway = EG> + 'static,
|
|
|
|
TR: EntityGatewayTransaction<ParentGateway = EG> + 'a,
|
|
|
|
{
|
|
|
|
move |(mut item_state, transaction): (ItemStateProxy, TR) , _| {
|
|
|
|
Box::pin(async move {
|
|
|
@ -52,13 +54,13 @@ where |
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
pub(super) fn add_floor_item_to_inventory<EG, TR>(
|
|
|
|
pub(super) fn add_floor_item_to_inventory<'a, EG, TR>(
|
|
|
|
character: &CharacterEntity
|
|
|
|
) -> impl Fn((ItemStateProxy, TR), FloorItem)
|
|
|
|
-> BoxFuture<Result<((ItemStateProxy, TR), TriggerCreateItem), anyhow::Error>>
|
|
|
|
-> BoxFuture<'a, Result<((ItemStateProxy, TR), TriggerCreateItem), anyhow::Error>>
|
|
|
|
where
|
|
|
|
EG: EntityGateway,
|
|
|
|
TR: EntityGatewayTransaction<ParentGateway = EG> + Clone + 'static,
|
|
|
|
TR: EntityGatewayTransaction<ParentGateway = EG> + Clone + 'a,
|
|
|
|
{
|
|
|
|
let character = character.clone();
|
|
|
|
move |(mut item_state, transaction), floor_item| {
|
|
|
@ -98,15 +100,15 @@ where |
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
pub(super) fn remove_item_from_inventory<EG, TR>(
|
|
|
|
pub(super) fn remove_item_from_inventory<'a, EG, TR>(
|
|
|
|
character_id: CharacterEntityId,
|
|
|
|
item_id: ClientItemId,
|
|
|
|
amount: u32,
|
|
|
|
) -> impl Fn((ItemStateProxy, TR), ())
|
|
|
|
-> BoxFuture<Result<((ItemStateProxy, TR), InventoryItemDetail), anyhow::Error>>
|
|
|
|
-> BoxFuture<'a, Result<((ItemStateProxy, TR), InventoryItemDetail), anyhow::Error>>
|
|
|
|
where
|
|
|
|
EG: EntityGateway,
|
|
|
|
TR: EntityGatewayTransaction<ParentGateway = EG> + 'static,
|
|
|
|
TR: EntityGatewayTransaction<ParentGateway = EG> + 'a,
|
|
|
|
{
|
|
|
|
move |(mut item_state, mut transaction), _| {
|
|
|
|
Box::pin(async move {
|
|
|
@ -124,22 +126,23 @@ where |
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
pub(super) fn take_item_from_inventory<EG, TR>(
|
|
|
|
pub(super) fn take_item_from_inventory<'a, EG, TR>(
|
|
|
|
character_id: CharacterEntityId,
|
|
|
|
item_id: ClientItemId,
|
|
|
|
amount: u32,
|
|
|
|
) -> impl Fn((ItemStateProxy, TR), ())
|
|
|
|
-> BoxFuture<Result<((ItemStateProxy, TR), InventoryItem), anyhow::Error>>
|
|
|
|
-> BoxFuture<'a, Result<((ItemStateProxy, TR), InventoryItem), anyhow::Error>>
|
|
|
|
where
|
|
|
|
EG: EntityGateway,
|
|
|
|
TR: EntityGatewayTransaction<ParentGateway = EG> + 'static,
|
|
|
|
EG: EntityGateway + 'a,
|
|
|
|
TR: EntityGatewayTransaction<ParentGateway = EG> + 'a,
|
|
|
|
{
|
|
|
|
move |(mut item_state, mut transaction), _| {
|
|
|
|
Box::pin(async move {
|
|
|
|
let mut inventory = item_state.inventory(&character_id).await?;
|
|
|
|
let item = inventory.take_item(&item_id, amount)
|
|
|
|
.await
|
|
|
|
.ok_or_else(|| ItemStateError::NoInventoryItem(item_id))?;
|
|
|
|
.ok_or_else(|| ItemStateError::NoInventoryItem(item_id))
|
|
|
|
.with_context(|| format!("{inventory:#?}"))?;
|
|
|
|
|
|
|
|
transaction.gateway().set_character_inventory(&character_id, &inventory.as_inventory_entity(&character_id)).await?;
|
|
|
|
item_state.set_inventory(inventory).await;
|
|
|
@ -150,15 +153,15 @@ where |
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
pub(super) fn add_inventory_item_to_shared_floor<EG, TR>(
|
|
|
|
pub(super) fn add_inventory_item_to_shared_floor<'a, EG, TR>(
|
|
|
|
character_id: CharacterEntityId,
|
|
|
|
map_area: MapArea,
|
|
|
|
drop_position: (f32, f32, f32),
|
|
|
|
) -> impl Fn((ItemStateProxy, TR), InventoryItem)
|
|
|
|
-> BoxFuture<Result<((ItemStateProxy, TR), FloorItem), anyhow::Error>>
|
|
|
|
-> BoxFuture<'a, Result<((ItemStateProxy, TR), FloorItem), anyhow::Error>>
|
|
|
|
where
|
|
|
|
EG: EntityGateway,
|
|
|
|
TR: EntityGatewayTransaction<ParentGateway = EG> + 'static,
|
|
|
|
TR: EntityGatewayTransaction<ParentGateway = EG> + 'a,
|
|
|
|
{
|
|
|
|
move |(mut item_state, transaction), inventory_item| {
|
|
|
|
Box::pin(async move {
|
|
|
@ -184,14 +187,14 @@ where |
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
pub(super) fn take_meseta_from_inventory<EG, TR>(
|
|
|
|
pub(super) fn take_meseta_from_inventory<'a, EG, TR>(
|
|
|
|
character_id: CharacterEntityId,
|
|
|
|
amount: u32,
|
|
|
|
) -> impl Fn((ItemStateProxy, TR), ())
|
|
|
|
-> BoxFuture<Result<((ItemStateProxy, TR), ()), anyhow::Error>>
|
|
|
|
-> BoxFuture<'a, Result<((ItemStateProxy, TR), ()), anyhow::Error>>
|
|
|
|
where
|
|
|
|
EG: EntityGateway,
|
|
|
|
TR: EntityGatewayTransaction<ParentGateway = EG> + 'static,
|
|
|
|
TR: EntityGatewayTransaction<ParentGateway = EG> + 'a,
|
|
|
|
{
|
|
|
|
move |(mut item_state, mut transaction), _| {
|
|
|
|
Box::pin(async move {
|
|
|
@ -205,14 +208,14 @@ where |
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
pub(super) fn add_meseta_to_inventory<EG, TR>(
|
|
|
|
pub(super) fn add_meseta_to_inventory<'a, EG, TR>(
|
|
|
|
character_id: CharacterEntityId,
|
|
|
|
amount: u32 |
|
|
|
) -> impl Fn((ItemStateProxy, TR), ())
|
|
|
|
-> BoxFuture<Result<((ItemStateProxy, TR), ()), anyhow::Error>>
|
|
|
|
-> BoxFuture<'a, Result<((ItemStateProxy, TR), ()), anyhow::Error>>
|
|
|
|
where
|
|
|
|
EG: EntityGateway,
|
|
|
|
TR: EntityGatewayTransaction<ParentGateway = EG> + 'static,
|
|
|
|
TR: EntityGatewayTransaction<ParentGateway = EG> + 'a,
|
|
|
|
{
|
|
|
|
move |(mut item_state, mut transaction), _| {
|
|
|
|
Box::pin(async move {
|
|
|
@ -226,16 +229,16 @@ where |
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
pub(super) fn add_meseta_to_shared_floor<EG, TR>(
|
|
|
|
pub(super) fn add_meseta_to_shared_floor<'a, EG, TR>(
|
|
|
|
character_id: CharacterEntityId,
|
|
|
|
amount: u32,
|
|
|
|
map_area: MapArea,
|
|
|
|
drop_position: (f32, f32)
|
|
|
|
) -> impl Fn((ItemStateProxy, TR), ())
|
|
|
|
-> BoxFuture<Result<((ItemStateProxy, TR), FloorItem), anyhow::Error>>
|
|
|
|
-> BoxFuture<'a, Result<((ItemStateProxy, TR), FloorItem), anyhow::Error>>
|
|
|
|
where
|
|
|
|
EG: EntityGateway,
|
|
|
|
TR: EntityGatewayTransaction<ParentGateway = EG> + 'static,
|
|
|
|
TR: EntityGatewayTransaction<ParentGateway = EG> + 'a,
|
|
|
|
{
|
|
|
|
move |(mut item_state, transaction), _| {
|
|
|
|
Box::pin(async move {
|
|
|
@ -257,14 +260,14 @@ where |
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
pub(super) fn take_meseta_from_bank<EG, TR>(
|
|
|
|
pub(super) fn take_meseta_from_bank<'a, EG, TR>(
|
|
|
|
character_id: CharacterEntityId,
|
|
|
|
amount: u32,
|
|
|
|
) -> impl Fn((ItemStateProxy, TR), ())
|
|
|
|
-> BoxFuture<Result<((ItemStateProxy, TR), ()), anyhow::Error>>
|
|
|
|
-> BoxFuture<'a, Result<((ItemStateProxy, TR), ()), anyhow::Error>>
|
|
|
|
where
|
|
|
|
EG: EntityGateway,
|
|
|
|
TR: EntityGatewayTransaction<ParentGateway = EG> + 'static,
|
|
|
|
TR: EntityGatewayTransaction<ParentGateway = EG> + 'a,
|
|
|
|
{
|
|
|
|
move |(mut item_state, mut transaction), _| {
|
|
|
|
Box::pin(async move {
|
|
|
@ -278,14 +281,14 @@ where |
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
pub(super) fn add_meseta_from_bank_to_inventory<EG, TR>(
|
|
|
|
pub(super) fn add_meseta_from_bank_to_inventory<'a, EG, TR>(
|
|
|
|
character_id: CharacterEntityId,
|
|
|
|
amount: u32,
|
|
|
|
) -> impl Fn((ItemStateProxy, TR), ())
|
|
|
|
-> BoxFuture<Result<((ItemStateProxy, TR), ()), anyhow::Error>>
|
|
|
|
-> BoxFuture<'a, Result<((ItemStateProxy, TR), ()), anyhow::Error>>
|
|
|
|
where
|
|
|
|
EG: EntityGateway,
|
|
|
|
TR: EntityGatewayTransaction<ParentGateway = EG> + 'static,
|
|
|
|
TR: EntityGatewayTransaction<ParentGateway = EG> + 'a,
|
|
|
|
{
|
|
|
|
move |(mut item_state, mut transaction), _| {
|
|
|
|
Box::pin(async move {
|
|
|
@ -300,14 +303,14 @@ where |
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
pub(super) fn add_meseta_to_bank<EG, TR>(
|
|
|
|
pub(super) fn add_meseta_to_bank<'a, EG, TR>(
|
|
|
|
character_id: CharacterEntityId,
|
|
|
|
amount: u32,
|
|
|
|
) -> impl Fn((ItemStateProxy, TR), ())
|
|
|
|
-> BoxFuture<Result<((ItemStateProxy, TR), ()), anyhow::Error>>
|
|
|
|
-> BoxFuture<'a, Result<((ItemStateProxy, TR), ()), anyhow::Error>>
|
|
|
|
where
|
|
|
|
EG: EntityGateway,
|
|
|
|
TR: EntityGatewayTransaction<ParentGateway = EG> + 'static,
|
|
|
|
TR: EntityGatewayTransaction<ParentGateway = EG> + 'a,
|
|
|
|
{
|
|
|
|
move |(mut item_state, mut transaction), _| {
|
|
|
|
Box::pin(async move {
|
|
|
@ -322,15 +325,15 @@ where |
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
pub(super) fn take_item_from_bank<EG, TR>(
|
|
|
|
pub(super) fn take_item_from_bank<'a, EG, TR>(
|
|
|
|
character_id: CharacterEntityId,
|
|
|
|
item_id: ClientItemId,
|
|
|
|
amount: u32,
|
|
|
|
) -> impl Fn((ItemStateProxy, TR), ())
|
|
|
|
-> BoxFuture<Result<((ItemStateProxy, TR), BankItem), anyhow::Error>>
|
|
|
|
-> BoxFuture<'a, Result<((ItemStateProxy, TR), BankItem), anyhow::Error>>
|
|
|
|
where
|
|
|
|
EG: EntityGateway,
|
|
|
|
TR: EntityGatewayTransaction<ParentGateway = EG> + 'static,
|
|
|
|
TR: EntityGatewayTransaction<ParentGateway = EG> + 'a,
|
|
|
|
{
|
|
|
|
move |(mut item_state, mut transaction), _| {
|
|
|
|
Box::pin(async move {
|
|
|
@ -346,13 +349,13 @@ where |
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
pub(super) fn add_bank_item_to_inventory<EG, TR>(
|
|
|
|
pub(super) fn add_bank_item_to_inventory<'a, EG, TR>(
|
|
|
|
character: &CharacterEntity,
|
|
|
|
) -> impl Fn((ItemStateProxy, TR), BankItem)
|
|
|
|
-> BoxFuture<Result<((ItemStateProxy, TR), InventoryItem), anyhow::Error>>
|
|
|
|
-> BoxFuture<'a, Result<((ItemStateProxy, TR), InventoryItem), anyhow::Error>>
|
|
|
|
where
|
|
|
|
EG: EntityGateway,
|
|
|
|
TR: EntityGatewayTransaction<ParentGateway = EG> + 'static,
|
|
|
|
TR: EntityGatewayTransaction<ParentGateway = EG> + 'a,
|
|
|
|
{
|
|
|
|
let character = character.clone();
|
|
|
|
move |(mut item_state, transaction), bank_item| {
|
|
|
@ -397,13 +400,13 @@ where |
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
pub(super) fn add_inventory_item_to_bank<EG, TR>(
|
|
|
|
pub(super) fn add_inventory_item_to_bank<'a, EG, TR>(
|
|
|
|
character_id: CharacterEntityId,
|
|
|
|
) -> impl Fn((ItemStateProxy, TR), InventoryItem)
|
|
|
|
-> BoxFuture<Result<((ItemStateProxy, TR), ()), anyhow::Error>>
|
|
|
|
-> BoxFuture<'a, Result<((ItemStateProxy, TR), ()), anyhow::Error>>
|
|
|
|
where
|
|
|
|
EG: EntityGateway,
|
|
|
|
TR: EntityGatewayTransaction<ParentGateway = EG> + 'static,
|
|
|
|
TR: EntityGatewayTransaction<ParentGateway = EG> + 'a,
|
|
|
|
{
|
|
|
|
move |(mut item_state, transaction), inventory_item| {
|
|
|
|
Box::pin(async move {
|
|
|
@ -430,15 +433,15 @@ where |
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
pub(super) fn equip_inventory_item<EG, TR>(
|
|
|
|
pub(super) fn equip_inventory_item<'a, EG, TR>(
|
|
|
|
character_id: CharacterEntityId,
|
|
|
|
item_id: ClientItemId,
|
|
|
|
equip_slot: u8,
|
|
|
|
) -> impl Fn((ItemStateProxy, TR), ())
|
|
|
|
-> BoxFuture<Result<((ItemStateProxy, TR), ()), anyhow::Error>>
|
|
|
|
-> BoxFuture<'a, Result<((ItemStateProxy, TR), ()), anyhow::Error>>
|
|
|
|
where
|
|
|
|
EG: EntityGateway,
|
|
|
|
TR: EntityGatewayTransaction<ParentGateway = EG> + 'static,
|
|
|
|
TR: EntityGatewayTransaction<ParentGateway = EG> + 'a,
|
|
|
|
{
|
|
|
|
move |(mut item_state, mut transaction), _| {
|
|
|
|
Box::pin(async move {
|
|
|
@ -453,14 +456,14 @@ where |
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
pub(super) fn unequip_inventory_item<EG, TR>(
|
|
|
|
pub(super) fn unequip_inventory_item<'a, EG, TR>(
|
|
|
|
character_id: CharacterEntityId,
|
|
|
|
item_id: ClientItemId,
|
|
|
|
) -> impl Fn((ItemStateProxy, TR), ())
|
|
|
|
-> BoxFuture<Result<((ItemStateProxy, TR), ()), anyhow::Error>>
|
|
|
|
-> BoxFuture<'a, Result<((ItemStateProxy, TR), ()), anyhow::Error>>
|
|
|
|
where
|
|
|
|
EG: EntityGateway,
|
|
|
|
TR: EntityGatewayTransaction<ParentGateway = EG> + 'static,
|
|
|
|
TR: EntityGatewayTransaction<ParentGateway = EG> + 'a,
|
|
|
|
{
|
|
|
|
move |(mut item_state, mut transaction), _| {
|
|
|
|
Box::pin(async move {
|
|
|
@ -476,14 +479,14 @@ where |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
pub(super) fn sort_inventory_items<EG, TR>(
|
|
|
|
pub(super) fn sort_inventory_items<'a, EG, TR>(
|
|
|
|
character_id: CharacterEntityId,
|
|
|
|
item_ids: Vec<ClientItemId>,
|
|
|
|
) -> impl Fn((ItemStateProxy, TR), ())
|
|
|
|
-> BoxFuture<Result<((ItemStateProxy, TR), ()), anyhow::Error>>
|
|
|
|
-> BoxFuture<'a, Result<((ItemStateProxy, TR), ()), anyhow::Error>>
|
|
|
|
where
|
|
|
|
EG: EntityGateway,
|
|
|
|
TR: EntityGatewayTransaction<ParentGateway = EG> + 'static,
|
|
|
|
TR: EntityGatewayTransaction<ParentGateway = EG> + 'a,
|
|
|
|
{
|
|
|
|
move |(mut item_state, mut transaction), _| {
|
|
|
|
let item_ids = item_ids.clone();
|
|
|
@ -499,13 +502,13 @@ where |
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
pub(super) fn use_consumed_item<EG, TR>(
|
|
|
|
pub(super) fn use_consumed_item<'a, EG, TR>(
|
|
|
|
character: &CharacterEntity,
|
|
|
|
) -> impl Fn((ItemStateProxy, TR), InventoryItemDetail)
|
|
|
|
-> BoxFuture<Result<((ItemStateProxy, TR), Vec<ApplyItemAction>), anyhow::Error>>
|
|
|
|
-> BoxFuture<'a, Result<((ItemStateProxy, TR), Vec<ApplyItemAction>), anyhow::Error>>
|
|
|
|
where
|
|
|
|
EG: EntityGateway + Clone + 'static,
|
|
|
|
TR: EntityGatewayTransaction<ParentGateway = EG> + 'static,
|
|
|
|
EG: EntityGateway + Clone + 'a,
|
|
|
|
TR: EntityGatewayTransaction<ParentGateway = EG> + 'a,
|
|
|
|
{
|
|
|
|
let character = character.clone();
|
|
|
|
move |(mut item_state, transaction), inventory_item| {
|
|
|
@ -525,14 +528,14 @@ where |
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
pub(super) fn feed_mag_item<EG, TR>(
|
|
|
|
pub(super) fn feed_mag_item<'a, EG, TR>(
|
|
|
|
character: CharacterEntity,
|
|
|
|
mag_item_id: ClientItemId,
|
|
|
|
) -> impl Fn((ItemStateProxy, TR), InventoryItem)
|
|
|
|
-> BoxFuture<Result<((ItemStateProxy, TR), CharacterEntity), anyhow::Error>>
|
|
|
|
-> BoxFuture<'a, Result<((ItemStateProxy, TR), CharacterEntity), anyhow::Error>>
|
|
|
|
where
|
|
|
|
EG: EntityGateway,
|
|
|
|
TR: EntityGatewayTransaction<ParentGateway = EG> + 'static,
|
|
|
|
TR: EntityGatewayTransaction<ParentGateway = EG> + 'a,
|
|
|
|
{
|
|
|
|
move |(mut item_state, transaction), tool| {
|
|
|
|
let character = character.clone();
|
|
|
@ -586,7 +589,7 @@ pub(super) fn add_bought_item_to_inventory<'a, EG, TR>( |
|
|
|
-> Pin<Box<dyn Future<Output=Result<((ItemStateProxy, TR), InventoryItem), anyhow::Error>> + Send + 'a>>
|
|
|
|
where
|
|
|
|
EG: EntityGateway,
|
|
|
|
TR: EntityGatewayTransaction<ParentGateway = EG> + 'static,
|
|
|
|
TR: EntityGatewayTransaction<ParentGateway = EG> + 'a,
|
|
|
|
{
|
|
|
|
move |(mut item_state, mut transaction), _| {
|
|
|
|
Box::pin(async move {
|
|
|
@ -644,13 +647,13 @@ where |
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
pub(super) fn sell_inventory_item<EG, TR>(
|
|
|
|
pub(super) fn sell_inventory_item<'a, EG, TR>(
|
|
|
|
character_id: CharacterEntityId,
|
|
|
|
) -> impl Fn((ItemStateProxy, TR), InventoryItem)
|
|
|
|
-> BoxFuture<Result<((ItemStateProxy, TR), InventoryItem), anyhow::Error>>
|
|
|
|
-> BoxFuture<'a, Result<((ItemStateProxy, TR), InventoryItem), anyhow::Error>>
|
|
|
|
where
|
|
|
|
EG: EntityGateway,
|
|
|
|
TR: EntityGatewayTransaction<ParentGateway = EG> + 'static,
|
|
|
|
TR: EntityGatewayTransaction<ParentGateway = EG> + 'a,
|
|
|
|
{
|
|
|
|
move |(mut item_state, transaction), inventory_item| {
|
|
|
|
Box::pin(async move {
|
|
|
@ -685,9 +688,9 @@ where |
|
|
|
I: Send,
|
|
|
|
O: Send,
|
|
|
|
T: Clone + Send + Sync,
|
|
|
|
F: Fn(I) -> FR + Send + Sync + Clone + 'static,
|
|
|
|
F: Fn(I) -> FR + Send + Sync + Clone + 'a,
|
|
|
|
FR: Fn((ItemStateProxy, TR), T)
|
|
|
|
-> BoxFuture<Result<((ItemStateProxy, TR), O), anyhow::Error>> + Send + Sync,
|
|
|
|
-> BoxFuture<'a, Result<((ItemStateProxy, TR), O), anyhow::Error>> + Send + Sync,
|
|
|
|
{
|
|
|
|
let item = match input.pop() {
|
|
|
|
Some(item) => item,
|
|
|
@ -703,20 +706,20 @@ where |
|
|
|
Ok((state, output))
|
|
|
|
}
|
|
|
|
|
|
|
|
pub(super) fn iterate<EG, TR, I, O, T, F, FR>(
|
|
|
|
pub(super) fn iterate<'a, EG, TR, I, O, T, F, FR>(
|
|
|
|
input: Vec<I>,
|
|
|
|
func: F,
|
|
|
|
) -> impl Fn((ItemStateProxy, TR), T)
|
|
|
|
-> BoxFuture<Result<((ItemStateProxy, TR), Vec<O>), anyhow::Error>>
|
|
|
|
-> BoxFuture<'a, Result<((ItemStateProxy, TR), Vec<O>), anyhow::Error>>
|
|
|
|
where
|
|
|
|
EG: EntityGateway,
|
|
|
|
TR: EntityGatewayTransaction<ParentGateway = EG> + 'static,
|
|
|
|
TR: EntityGatewayTransaction<ParentGateway = EG> + 'a,
|
|
|
|
O: Send,
|
|
|
|
I: Send + Clone + 'static + std::fmt::Debug,
|
|
|
|
T: Send + Clone + 'static + std::fmt::Debug,
|
|
|
|
F: Fn(I) -> FR + Send + Sync + Clone + 'static,
|
|
|
|
F: Fn(I) -> FR + Send + Sync + Clone + 'a,
|
|
|
|
FR: Fn((ItemStateProxy, TR), T)
|
|
|
|
-> BoxFuture<Result<((ItemStateProxy, TR), O), anyhow::Error>> + Send + Sync,
|
|
|
|
-> BoxFuture<'a, Result<((ItemStateProxy, TR), O), anyhow::Error>> + Send + Sync,
|
|
|
|
T: Clone + Send + Sync,
|
|
|
|
{
|
|
|
|
move |(item_state, transaction), arg| {
|
|
|
@ -739,12 +742,12 @@ async fn foreach_inner<'a, EG, TR, O, T, F, I>( |
|
|
|
where
|
|
|
|
'a: 'async_recursion,
|
|
|
|
EG: EntityGateway,
|
|
|
|
TR: EntityGatewayTransaction<ParentGateway = EG> + 'static,
|
|
|
|
TR: EntityGatewayTransaction<ParentGateway = EG> + 'a,
|
|
|
|
O: Send,
|
|
|
|
T: Send,
|
|
|
|
F: Fn((ItemStateProxy, TR), T)
|
|
|
|
-> BoxFuture<Result<((ItemStateProxy, TR), O), anyhow::Error>> + Send + Sync,
|
|
|
|
I: Iterator<Item = T> + Send + Sync + 'static,
|
|
|
|
-> BoxFuture<'a, Result<((ItemStateProxy, TR), O), anyhow::Error>> + Send + Sync,
|
|
|
|
I: Iterator<Item = T> + Send + Sync + 'a,
|
|
|
|
{
|
|
|
|
let item = match input.next() {
|
|
|
|
Some(item) => item,
|
|
|
@ -759,19 +762,19 @@ where |
|
|
|
Ok((state, output))
|
|
|
|
}
|
|
|
|
|
|
|
|
pub(super) fn foreach<EG, TR, O, T, F, I>(
|
|
|
|
pub(super) fn foreach<'a, EG, TR, O, T, F, I>(
|
|
|
|
func: F
|
|
|
|
) -> impl Fn((ItemStateProxy, TR), I)
|
|
|
|
-> BoxFuture<Result<((ItemStateProxy, TR), Vec<O>), anyhow::Error>>
|
|
|
|
-> BoxFuture<'a, Result<((ItemStateProxy, TR), Vec<O>), anyhow::Error>>
|
|
|
|
where
|
|
|
|
EG: EntityGateway,
|
|
|
|
TR: EntityGatewayTransaction<ParentGateway = EG> + 'static,
|
|
|
|
TR: EntityGatewayTransaction<ParentGateway = EG> + 'a,
|
|
|
|
O: Send,
|
|
|
|
T: Send + Clone + 'static + std::fmt::Debug,
|
|
|
|
F: Fn((ItemStateProxy, TR), T)
|
|
|
|
-> BoxFuture<Result<((ItemStateProxy, TR), O), anyhow::Error>> + Send + Sync + 'static,
|
|
|
|
-> BoxFuture<'a, Result<((ItemStateProxy, TR), O), anyhow::Error>> + Send + Sync + 'a,
|
|
|
|
T: Send + Sync,
|
|
|
|
I: IntoIterator<Item = T> + Send + Sync + 'static,
|
|
|
|
I: IntoIterator<Item = T> + Send + Sync + 'a,
|
|
|
|
I::IntoIter: Send + Sync,
|
|
|
|
{
|
|
|
|
let func = Arc::new(func);
|
|
|
@ -791,7 +794,7 @@ pub(super) fn insert<'a, EG, TR, T>( |
|
|
|
-> Pin<Box<dyn Future<Output=Result<((ItemStateProxy, TR), T), anyhow::Error>> + Send + 'a>>
|
|
|
|
where
|
|
|
|
EG: EntityGateway,
|
|
|
|
TR: EntityGatewayTransaction<ParentGateway = EG> + 'static,
|
|
|
|
TR: EntityGatewayTransaction<ParentGateway = EG> + 'a,
|
|
|
|
T: Send + Clone + 'a,
|
|
|
|
{
|
|
|
|
move |state, _| {
|
|
|
@ -802,17 +805,17 @@ where |
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
pub(super) fn fork<EG, TR, F1, F2, T, O1, O2>(
|
|
|
|
pub(super) fn fork<'a, EG, TR, F1, F2, T, O1, O2>(
|
|
|
|
func1: F1,
|
|
|
|
func2: F2,
|
|
|
|
) -> impl Fn((ItemStateProxy, TR), T)
|
|
|
|
-> BoxFuture<Result<((ItemStateProxy, TR), (O1, O2)), anyhow::Error>>
|
|
|
|
-> BoxFuture<'a, Result<((ItemStateProxy, TR), (O1, O2)), anyhow::Error>>
|
|
|
|
where
|
|
|
|
EG: EntityGateway,
|
|
|
|
TR: EntityGatewayTransaction<ParentGateway = EG> + 'static,
|
|
|
|
F1: Fn((ItemStateProxy, TR), T) -> BoxFuture<Result<((ItemStateProxy, TR), O1), anyhow::Error>> + Send + Sync + 'static,
|
|
|
|
F2: Fn((ItemStateProxy, TR), T) -> BoxFuture<Result<((ItemStateProxy, TR), O2), anyhow::Error>> + Send + Sync + 'static,
|
|
|
|
T: Send + Sync + Clone + 'static,
|
|
|
|
TR: EntityGatewayTransaction<ParentGateway = EG> + 'a,
|
|
|
|
F1: Fn((ItemStateProxy, TR), T) -> BoxFuture<'a, Result<((ItemStateProxy, TR), O1), anyhow::Error>> + Send + Sync + 'a,
|
|
|
|
F2: Fn((ItemStateProxy, TR), T) -> BoxFuture<'a, Result<((ItemStateProxy, TR), O2), anyhow::Error>> + Send + Sync + 'a,
|
|
|
|
T: Send + Sync + Clone + 'a,
|
|
|
|
O1: Send,
|
|
|
|
O2: Send,
|
|
|
|
{
|
|
|
@ -830,13 +833,13 @@ where |
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
pub(super) fn add_item_to_inventory<EG, TR>(
|
|
|
|
pub(super) fn add_item_to_inventory<'a, EG, TR>(
|
|
|
|
character: CharacterEntity,
|
|
|
|
) -> impl Fn((ItemStateProxy, TR), InventoryItem)
|
|
|
|
-> BoxFuture<Result<((ItemStateProxy, TR), InventoryItem), anyhow::Error>> + Clone
|
|
|
|
-> BoxFuture<'a, Result<((ItemStateProxy, TR), InventoryItem), anyhow::Error>> + Clone
|
|
|
|
where
|
|
|
|
EG: EntityGateway,
|
|
|
|
TR: EntityGatewayTransaction<ParentGateway = EG> + 'static,
|
|
|
|
TR: EntityGatewayTransaction<ParentGateway = EG> + 'a,
|
|
|
|
{
|
|
|
|
move |(mut item_state, transaction), inventory_item| {
|
|
|
|
let character = character.clone();
|
|
|
@ -858,15 +861,15 @@ where |
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
pub(super) fn record_trade<EG, TR>(
|
|
|
|
pub(super) fn record_trade<'a, EG, TR>(
|
|
|
|
trade_id: TradeId,
|
|
|
|
character_to: CharacterEntityId,
|
|
|
|
character_from: CharacterEntityId,
|
|
|
|
) -> impl Fn((ItemStateProxy, TR), Vec<InventoryItem>)
|
|
|
|
-> BoxFuture<Result<((ItemStateProxy, TR), Vec<InventoryItem>), anyhow::Error>> + Clone
|
|
|
|
-> BoxFuture<'a, Result<((ItemStateProxy, TR), Vec<InventoryItem>), anyhow::Error>> + Clone
|
|
|
|
where
|
|
|
|
EG: EntityGateway,
|
|
|
|
TR: EntityGatewayTransaction<ParentGateway = EG> + 'static,
|
|
|
|
TR: EntityGatewayTransaction<ParentGateway = EG> + 'a,
|
|
|
|
{
|
|
|
|
move |(item_state, mut transaction), traded_items| {
|
|
|
|
Box::pin(async move {
|
|
|
@ -887,12 +890,12 @@ where |
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
pub(super) fn assign_new_item_id<EG, TR>(
|
|
|
|
pub(super) fn assign_new_item_id<'a, EG, TR>(
|
|
|
|
) -> impl Fn((ItemStateProxy, TR), InventoryItem)
|
|
|
|
-> BoxFuture<Result<((ItemStateProxy, TR), InventoryItem), anyhow::Error>> + Clone
|
|
|
|
-> BoxFuture<'a, Result<((ItemStateProxy, TR), InventoryItem), anyhow::Error>> + Clone
|
|
|
|
where
|
|
|
|
EG: EntityGateway,
|
|
|
|
TR: EntityGatewayTransaction<ParentGateway = EG> + 'static,
|
|
|
|
TR: EntityGatewayTransaction<ParentGateway = EG> + 'a,
|
|
|
|
{
|
|
|
|
move |(mut item_state, transaction), mut inventory_item| {
|
|
|
|
Box::pin(async move {
|
|
|
@ -903,14 +906,14 @@ where |
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
pub(super) fn convert_item_drop_to_floor_item<EG, TR>(
|
|
|
|
pub(super) fn convert_item_drop_to_floor_item<'a, EG, TR>(
|
|
|
|
character_id: CharacterEntityId,
|
|
|
|
item_drop: ItemDrop,
|
|
|
|
) -> impl Fn((ItemStateProxy, TR), ())
|
|
|
|
-> BoxFuture<Result<((ItemStateProxy, TR), FloorItem), anyhow::Error>> + Clone
|
|
|
|
-> BoxFuture<'a, Result<((ItemStateProxy, TR), FloorItem), anyhow::Error>> + Clone
|
|
|
|
where
|
|
|
|
EG: EntityGateway,
|
|
|
|
TR: EntityGatewayTransaction<ParentGateway = EG> + 'static,
|
|
|
|
TR: EntityGatewayTransaction<ParentGateway = EG> + 'a,
|
|
|
|
{
|
|
|
|
move |(mut item_state, mut transaction), _| {
|
|
|
|
let item_drop = item_drop.clone();
|
|
|
@ -1005,13 +1008,13 @@ where |
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
pub(super) fn add_item_to_local_floor<EG, TR>(
|
|
|
|
pub(super) fn add_item_to_local_floor<'a, EG, TR>(
|
|
|
|
character_id: CharacterEntityId,
|
|
|
|
) -> impl Fn((ItemStateProxy, TR), FloorItem)
|
|
|
|
-> BoxFuture<Result<((ItemStateProxy, TR), FloorItem), anyhow::Error>>
|
|
|
|
-> BoxFuture<'a, Result<((ItemStateProxy, TR), FloorItem), anyhow::Error>>
|
|
|
|
where
|
|
|
|
EG: EntityGateway,
|
|
|
|
TR: EntityGatewayTransaction<ParentGateway = EG> + 'static,
|
|
|
|
TR: EntityGatewayTransaction<ParentGateway = EG> + 'a,
|
|
|
|
{
|
|
|
|
move |(mut item_state, transaction) , floor_item| {
|
|
|
|
Box::pin(async move {
|
|
|
@ -1024,13 +1027,13 @@ where |
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
pub(super) fn apply_modifier_to_inventory_item<EG, TR>(
|
|
|
|
pub(super) fn apply_modifier_to_inventory_item<'a, EG, TR>(
|
|
|
|
modifier: ItemModifier,
|
|
|
|
) -> impl Fn((ItemStateProxy, TR), InventoryItem)
|
|
|
|
-> BoxFuture<Result<((ItemStateProxy, TR), InventoryItem), anyhow::Error>>
|
|
|
|
-> BoxFuture<'a, Result<((ItemStateProxy, TR), InventoryItem), anyhow::Error>>
|
|
|
|
where
|
|
|
|
EG: EntityGateway,
|
|
|
|
TR: EntityGatewayTransaction<ParentGateway = EG> + 'static,
|
|
|
|
TR: EntityGatewayTransaction<ParentGateway = EG> + 'a,
|
|
|
|
{
|
|
|
|
move |(item_state, mut transaction), mut inventory_item| {
|
|
|
|
let modifier = modifier.clone();
|
|
|
@ -1048,12 +1051,12 @@ where |
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
pub(super) fn as_individual_item<EG, TR>(
|
|
|
|
pub(super) fn as_individual_item<'a, EG, TR>(
|
|
|
|
) -> impl Fn((ItemStateProxy, TR), InventoryItem)
|
|
|
|
-> BoxFuture<Result<((ItemStateProxy, TR), IndividualItemDetail), anyhow::Error>>
|
|
|
|
-> BoxFuture<'a, Result<((ItemStateProxy, TR), IndividualItemDetail), anyhow::Error>>
|
|
|
|
where
|
|
|
|
EG: EntityGateway,
|
|
|
|
TR: EntityGatewayTransaction<ParentGateway = EG> + 'static,
|
|
|
|
TR: EntityGatewayTransaction<ParentGateway = EG> + 'a,
|
|
|
|
{
|
|
|
|
move |(item_state, transaction), inventory_item| {
|
|
|
|
Box::pin(async move {
|
|
|
@ -1068,14 +1071,14 @@ where |
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
pub(super) fn apply_item_action_packets<EG, TR>(
|
|
|
|
pub(super) fn apply_item_action_packets<'a, EG, TR>(
|
|
|
|
character_id: CharacterEntityId,
|
|
|
|
area_client: AreaClient,
|
|
|
|
) -> impl Fn((ItemStateProxy, TR), ApplyItemAction)
|
|
|
|
-> BoxFuture<Result<((ItemStateProxy, TR), Vec<SendShipPacket>), anyhow::Error>>
|
|
|
|
-> BoxFuture<'a, Result<((ItemStateProxy, TR), Vec<SendShipPacket>), anyhow::Error>>
|
|
|
|
where
|
|
|
|
EG: EntityGateway,
|
|
|
|
TR: EntityGatewayTransaction<ParentGateway = EG> + 'static,
|
|
|
|
TR: EntityGatewayTransaction<ParentGateway = EG> + 'a,
|
|
|
|
{
|
|
|
|
move |(mut item_state, mut transaction), apply_item_action| {
|
|
|
|
Box::pin(async move {
|
|
|
@ -1126,13 +1129,13 @@ where |
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
pub(super) fn apply_item_action_character<EG, TR>(
|
|
|
|
pub(super) fn apply_item_action_character<'a, EG, TR>(
|
|
|
|
character: &CharacterEntity
|
|
|
|
) -> impl Fn((ItemStateProxy, TR), Vec<ApplyItemAction>)
|
|
|
|
-> BoxFuture<Result<((ItemStateProxy, TR), CharacterEntity), anyhow::Error>>
|
|
|
|
-> BoxFuture<'a, Result<((ItemStateProxy, TR), CharacterEntity), anyhow::Error>>
|
|
|
|
where
|
|
|
|
EG: EntityGateway,
|
|
|
|
TR: EntityGatewayTransaction<ParentGateway = EG> + 'static,
|
|
|
|
TR: EntityGatewayTransaction<ParentGateway = EG> + 'a,
|
|
|
|
{
|
|
|
|
let character = character.clone();
|
|
|
|
move |(item_state, transaction), apply_item_actions| {
|
|
|
|