|
@ -1,3 +1,5 @@ |
|
|
|
|
|
// TODO: replace various u32s and usizes denoting item amounts for ItemAmount(u32) for consistency
|
|
|
|
|
|
|
|
|
use crate::ship::items::ClientItemId;
|
|
|
use crate::ship::items::ClientItemId;
|
|
|
use crate::entity::item::{Meseta, ItemNote};
|
|
|
use crate::entity::item::{Meseta, ItemNote};
|
|
|
use std::future::Future;
|
|
|
use std::future::Future;
|
|
@ -14,7 +16,7 @@ use crate::entity::item::tool::Tool; |
|
|
use crate::entity::item::ItemModifier;
|
|
|
use crate::entity::item::ItemModifier;
|
|
|
use crate::ship::shops::ShopItem;
|
|
|
use crate::ship::shops::ShopItem;
|
|
|
use crate::ship::trade::TradeItem;
|
|
|
use crate::ship::trade::TradeItem;
|
|
|
use crate::ship::location::{AreaClient, RoomId};
|
|
|
|
|
|
|
|
|
use crate::ship::location::AreaClient;
|
|
|
use crate::ship::drops::{ItemDrop, ItemDropType};
|
|
|
use crate::ship::drops::{ItemDrop, ItemDropType};
|
|
|
|
|
|
|
|
|
pub enum TriggerCreateItem {
|
|
|
pub enum TriggerCreateItem {
|
|
@ -107,7 +109,7 @@ fn take_item_from_inventory(character_id: CharacterEntityId, item_id: ClientItem |
|
|
move |(mut item_state, mut transaction), _| {
|
|
|
move |(mut item_state, mut transaction), _| {
|
|
|
Box::pin(async move {
|
|
|
Box::pin(async move {
|
|
|
let mut inventory = item_state.inventory(&character_id)?;
|
|
|
let mut inventory = item_state.inventory(&character_id)?;
|
|
|
let item = inventory.take_item(&item_id, amount).ok_or_else (|| ItemStateError::NoFloorItem(item_id))?;
|
|
|
|
|
|
|
|
|
let item = inventory.take_item(&item_id, amount).ok_or (ItemStateError::NoFloorItem(item_id))?;
|
|
|
|
|
|
|
|
|
transaction.gateway().set_character_inventory(&character_id, &inventory.as_inventory_entity(&character_id)).await?;
|
|
|
transaction.gateway().set_character_inventory(&character_id, &inventory.as_inventory_entity(&character_id)).await?;
|
|
|
item_state.set_inventory(inventory);
|
|
|
item_state.set_inventory(inventory);
|
|
@ -235,7 +237,7 @@ fn add_meseta_to_shared_floor(character_id: CharacterEntityId, amount: u32, map_ |
|
|
let floor_item = FloorItem {
|
|
|
let floor_item = FloorItem {
|
|
|
item_id: item_state.new_item_id()?,
|
|
|
item_id: item_state.new_item_id()?,
|
|
|
item: FloorItemDetail::Meseta(Meseta(amount)),
|
|
|
item: FloorItemDetail::Meseta(Meseta(amount)),
|
|
|
map_area: map_area,
|
|
|
|
|
|
|
|
|
map_area,
|
|
|
x: drop_position.0,
|
|
|
x: drop_position.0,
|
|
|
y: 0.0,
|
|
|
y: 0.0,
|
|
|
z: drop_position.1,
|
|
|
z: drop_position.1,
|
|
@ -352,7 +354,7 @@ where |
|
|
{
|
|
|
{
|
|
|
entity_gateway.with_transaction(|transaction| async move {
|
|
|
entity_gateway.with_transaction(|transaction| async move {
|
|
|
let item_state_proxy = ItemStateProxy::new(item_state);
|
|
|
let item_state_proxy = ItemStateProxy::new(item_state);
|
|
|
let ((item_state_proxy, transaction), result) = ItemStateAction::default()
|
|
|
|
|
|
|
|
|
let ((item_state_proxy, transaction), _) = ItemStateAction::default()
|
|
|
.act(take_meseta_from_inventory(character.id, amount))
|
|
|
.act(take_meseta_from_inventory(character.id, amount))
|
|
|
.act(add_meseta_to_bank(character.id, amount))
|
|
|
.act(add_meseta_to_bank(character.id, amount))
|
|
|
.commit((item_state_proxy, transaction))
|
|
|
.commit((item_state_proxy, transaction))
|
|
@ -369,7 +371,7 @@ fn take_item_from_bank(character_id: CharacterEntityId, item_id: ClientItemId, a |
|
|
move |(mut item_state, mut transaction), _| {
|
|
|
move |(mut item_state, mut transaction), _| {
|
|
|
Box::pin(async move {
|
|
|
Box::pin(async move {
|
|
|
let mut bank = item_state.bank(&character_id)?;
|
|
|
let mut bank = item_state.bank(&character_id)?;
|
|
|
let item = bank.take_item(&item_id, amount).ok_or_else(|| ItemStateError::NoBankItem(item_id))?;
|
|
|
|
|
|
|
|
|
let item = bank.take_item(&item_id, amount).ok_or(ItemStateError::NoBankItem(item_id))?;
|
|
|
transaction.gateway().set_character_bank(&character_id, &bank.as_bank_entity(), &bank.name).await?;
|
|
|
transaction.gateway().set_character_bank(&character_id, &bank.as_bank_entity(), &bank.name).await?;
|
|
|
item_state.set_bank(bank);
|
|
|
item_state.set_bank(bank);
|
|
|
|
|
|
|
|
@ -440,7 +442,7 @@ where |
|
|
.act(take_item_from_bank(character.id, *item_id, amount))
|
|
|
.act(take_item_from_bank(character.id, *item_id, amount))
|
|
|
//.act(bank_item_to_inventory_item)
|
|
|
//.act(bank_item_to_inventory_item)
|
|
|
//.act(add_item_to_inventory)
|
|
|
//.act(add_item_to_inventory)
|
|
|
.act(add_bank_item_to_inventory(&character))
|
|
|
|
|
|
|
|
|
.act(add_bank_item_to_inventory(character))
|
|
|
.commit((item_state_proxy, transaction))
|
|
|
.commit((item_state_proxy, transaction))
|
|
|
.await?;
|
|
|
.await?;
|
|
|
item_state_proxy.commit();
|
|
|
item_state_proxy.commit();
|
|
@ -664,10 +666,10 @@ fn feed_mag_item(character: CharacterEntity, mag_item_id: ClientItemId) |
|
|
Box::pin(async move {
|
|
|
Box::pin(async move {
|
|
|
let mut inventory = item_state.inventory(&character.id)?;
|
|
|
let mut inventory = item_state.inventory(&character.id)?;
|
|
|
let mag_entity = inventory.get_by_client_id_mut(&mag_item_id)
|
|
|
let mag_entity = inventory.get_by_client_id_mut(&mag_item_id)
|
|
|
.ok_or_else(|| ItemStateError::InvalidItemId(mag_item_id))?
|
|
|
|
|
|
|
|
|
.ok_or(ItemStateError::InvalidItemId(mag_item_id))?
|
|
|
.item
|
|
|
.item
|
|
|
.as_individual_mut()
|
|
|
.as_individual_mut()
|
|
|
.ok_or_else(|| ItemStateError::NotAMag(mag_item_id))?;
|
|
|
|
|
|
|
|
|
.ok_or(ItemStateError::NotAMag(mag_item_id))?;
|
|
|
let mag_entity_id = mag_entity.entity_id;
|
|
|
let mag_entity_id = mag_entity.entity_id;
|
|
|
|
|
|
|
|
|
let mut transaction = tool.with_entity_id(transaction, |mut transaction, entity_id| {
|
|
|
let mut transaction = tool.with_entity_id(transaction, |mut transaction, entity_id| {
|
|
@ -683,13 +685,13 @@ fn feed_mag_item(character: CharacterEntity, mag_item_id: ClientItemId) |
|
|
let food_tool = tool
|
|
|
let food_tool = tool
|
|
|
.item
|
|
|
.item
|
|
|
.stacked()
|
|
|
.stacked()
|
|
|
.ok_or_else(|| ItemStateError::NotMagFood(tool.item_id))?
|
|
|
|
|
|
|
|
|
.ok_or(ItemStateError::NotMagFood(tool.item_id))?
|
|
|
.tool
|
|
|
.tool
|
|
|
.tool;
|
|
|
.tool;
|
|
|
|
|
|
|
|
|
let mag_entity = mag_entity
|
|
|
let mag_entity = mag_entity
|
|
|
.as_mag_mut()
|
|
|
.as_mag_mut()
|
|
|
.ok_or_else(|| ItemStateError::NotAMag(mag_item_id))?;
|
|
|
|
|
|
|
|
|
.ok_or(ItemStateError::NotAMag(mag_item_id))?;
|
|
|
|
|
|
|
|
|
mag_entity.feed(food_tool);
|
|
|
mag_entity.feed(food_tool);
|
|
|
|
|
|
|
|
@ -745,7 +747,7 @@ fn add_bought_item_to_inventory<'a>(character_id: CharacterEntityId, |
|
|
item: ItemDetail::Tool(tool),
|
|
|
item: ItemDetail::Tool(tool),
|
|
|
}).await?;
|
|
|
}).await?;
|
|
|
transaction.gateway().add_item_note(&item_entity.id, ItemNote::BoughtAtShop {
|
|
|
transaction.gateway().add_item_note(&item_entity.id, ItemNote::BoughtAtShop {
|
|
|
character_id: character_id,
|
|
|
|
|
|
|
|
|
character_id,
|
|
|
}).await?;
|
|
|
}).await?;
|
|
|
item_entities.push(item_entity);
|
|
|
item_entities.push(item_entity);
|
|
|
}
|
|
|
}
|
|
@ -754,7 +756,7 @@ fn add_bought_item_to_inventory<'a>(character_id: CharacterEntityId, |
|
|
item_id,
|
|
|
item_id,
|
|
|
item: InventoryItemDetail::Stacked(StackedItemDetail {
|
|
|
item: InventoryItemDetail::Stacked(StackedItemDetail {
|
|
|
entity_ids: item_entities.into_iter().map(|i| i.id).collect(),
|
|
|
entity_ids: item_entities.into_iter().map(|i| i.id).collect(),
|
|
|
tool: tool,
|
|
|
|
|
|
|
|
|
tool,
|
|
|
})
|
|
|
})
|
|
|
};
|
|
|
};
|
|
|
inventory.add_item(inventory_item)?.1
|
|
|
inventory.add_item(inventory_item)?.1
|
|
@ -764,7 +766,7 @@ fn add_bought_item_to_inventory<'a>(character_id: CharacterEntityId, |
|
|
item: item_detail.clone(),
|
|
|
item: item_detail.clone(),
|
|
|
}).await?;
|
|
|
}).await?;
|
|
|
transaction.gateway().add_item_note(&item_entity.id, ItemNote::BoughtAtShop {
|
|
|
transaction.gateway().add_item_note(&item_entity.id, ItemNote::BoughtAtShop {
|
|
|
character_id: character_id,
|
|
|
|
|
|
|
|
|
character_id,
|
|
|
}).await?;
|
|
|
}).await?;
|
|
|
|
|
|
|
|
|
let inventory_item = InventoryItem {
|
|
|
let inventory_item = InventoryItem {
|
|
@ -816,7 +818,7 @@ fn sell_inventory_item<'a>(character_id: CharacterEntityId) |
|
|
-> impl Fn((ItemStateProxy<'a>, Box<dyn EntityGatewayTransaction + 'a>), InventoryItem)
|
|
|
-> 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>>
|
|
|
-> Pin<Box<dyn Future<Output=Result<((ItemStateProxy<'a>, Box<dyn EntityGatewayTransaction + 'a>), InventoryItem), ItemStateError>> + Send + 'a>>
|
|
|
{
|
|
|
{
|
|
|
move |(mut item_state, mut transaction), inventory_item| {
|
|
|
|
|
|
|
|
|
move |(mut item_state, transaction), inventory_item| {
|
|
|
Box::pin(async move {
|
|
|
Box::pin(async move {
|
|
|
let mut inventory = item_state.inventory(&character_id)?;
|
|
|
let mut inventory = item_state.inventory(&character_id)?;
|
|
|
let price = inventory_item.item.sell_price()?;
|
|
|
let price = inventory_item.item.sell_price()?;
|
|
@ -899,7 +901,7 @@ where |
|
|
-> Pin<Box<dyn Future<Output=Result<((ItemStateProxy<'a>, Box<dyn EntityGatewayTransaction + 'a>), O), ItemStateError>> + Send + 'a>> + Send + Sync,
|
|
|
-> Pin<Box<dyn Future<Output=Result<((ItemStateProxy<'a>, Box<dyn EntityGatewayTransaction + 'a>), O), ItemStateError>> + Send + 'a>> + Send + Sync,
|
|
|
T: Clone + Send + Sync,
|
|
|
T: Clone + Send + Sync,
|
|
|
{
|
|
|
{
|
|
|
move |(mut item_state, mut transaction), arg| {
|
|
|
|
|
|
|
|
|
move |(item_state, transaction), arg| {
|
|
|
let input = input.clone();
|
|
|
let input = input.clone();
|
|
|
let func = func.clone();
|
|
|
let func = func.clone();
|
|
|
println!("i {:?} {:?}", input, arg);
|
|
|
println!("i {:?} {:?}", input, arg);
|
|
@ -958,18 +960,6 @@ where |
|
|
}
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
fn clear<'a, T: Send + Clone + 'a>()
|
|
|
|
|
|
-> impl Fn((ItemStateProxy<'a>, Box<dyn EntityGatewayTransaction + 'a>), T)
|
|
|
|
|
|
-> Pin<Box<dyn Future<Output=Result<((ItemStateProxy<'a>, Box<dyn EntityGatewayTransaction + 'a>), ()), ItemStateError>> + Send + 'a>>
|
|
|
|
|
|
{
|
|
|
|
|
|
move |state, _| {
|
|
|
|
|
|
Box::pin(async move {
|
|
|
|
|
|
Ok((state, ()))
|
|
|
|
|
|
})
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
fn insert<'a, T: Send + Clone + 'a>(element: T)
|
|
|
fn insert<'a, T: Send + Clone + 'a>(element: T)
|
|
|
-> impl Fn((ItemStateProxy<'a>, Box<dyn EntityGatewayTransaction + 'a>), ())
|
|
|
-> impl Fn((ItemStateProxy<'a>, Box<dyn EntityGatewayTransaction + 'a>), ())
|
|
|
-> Pin<Box<dyn Future<Output=Result<((ItemStateProxy<'a>, Box<dyn EntityGatewayTransaction + 'a>), T), ItemStateError>> + Send + 'a>>
|
|
|
-> Pin<Box<dyn Future<Output=Result<((ItemStateProxy<'a>, Box<dyn EntityGatewayTransaction + 'a>), T), ItemStateError>> + Send + 'a>>
|
|
@ -986,26 +976,10 @@ fn add_item_to_inventory(character: CharacterEntity) |
|
|
-> impl for<'a> Fn((ItemStateProxy<'a>, Box<dyn EntityGatewayTransaction + 'a>), InventoryItem)
|
|
|
-> 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
|
|
|
-> Pin<Box<dyn Future<Output=Result<((ItemStateProxy<'a>, Box<dyn EntityGatewayTransaction + 'a>), InventoryItem), ItemStateError>> + Send + 'a>> + Clone
|
|
|
{
|
|
|
{
|
|
|
let character = character.clone();
|
|
|
|
|
|
move |(mut item_state, transaction), inventory_item| {
|
|
|
move |(mut item_state, transaction), inventory_item| {
|
|
|
let character = character.clone();
|
|
|
let character = character.clone();
|
|
|
Box::pin(async move {
|
|
|
Box::pin(async move {
|
|
|
//let bank_name = item_state.bank(&character.id)?.name;
|
|
|
|
|
|
let mut inventory = item_state.inventory(&character.id)?;
|
|
|
let mut inventory = item_state.inventory(&character.id)?;
|
|
|
|
|
|
|
|
|
let character_id = character.id;
|
|
|
|
|
|
/*
|
|
|
|
|
|
let transaction = bank_item.with_entity_id(transaction, |mut transaction, entity_id| {
|
|
|
|
|
|
let bank_name = bank_name.clone();
|
|
|
|
|
|
async move {
|
|
|
|
|
|
transaction.gateway().add_item_note(&entity_id, ItemNote::Withdraw {
|
|
|
|
|
|
character_id,
|
|
|
|
|
|
bank: bank_name,
|
|
|
|
|
|
}).await?;
|
|
|
|
|
|
Ok(transaction)
|
|
|
|
|
|
}}).await?;
|
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
|
|
let mut transaction = inventory_item.with_mag(transaction, |mut transaction, entity_id, _mag| {
|
|
|
let mut transaction = inventory_item.with_mag(transaction, |mut transaction, entity_id, _mag| {
|
|
|
let character = character.clone();
|
|
|
let character = character.clone();
|
|
|
async move {
|
|
|
async move {
|
|
@ -1060,7 +1034,6 @@ fn assign_new_item_id() |
|
|
pub async fn trade_items<'a, EG> (
|
|
|
pub async fn trade_items<'a, EG> (
|
|
|
item_state: &'a mut ItemState,
|
|
|
item_state: &'a mut ItemState,
|
|
|
entity_gateway: &mut EG,
|
|
|
entity_gateway: &mut EG,
|
|
|
room_id: RoomId,
|
|
|
|
|
|
p1: (&AreaClient, &CharacterEntity, &Vec<TradeItem>, Meseta),
|
|
|
p1: (&AreaClient, &CharacterEntity, &Vec<TradeItem>, Meseta),
|
|
|
p2: (&AreaClient, &CharacterEntity, &Vec<TradeItem>, Meseta))
|
|
|
p2: (&AreaClient, &CharacterEntity, &Vec<TradeItem>, Meseta))
|
|
|
-> Result<(Vec<InventoryItem>, Vec<InventoryItem>), ItemStateError>
|
|
|
-> Result<(Vec<InventoryItem>, Vec<InventoryItem>), ItemStateError>
|
|
@ -1137,9 +1110,9 @@ pub async fn take_meseta<'a, EG> ( |
|
|
where
|
|
|
where
|
|
|
EG: EntityGateway,
|
|
|
EG: EntityGateway,
|
|
|
{
|
|
|
{
|
|
|
entity_gateway.with_transaction(|mut transaction| async move {
|
|
|
|
|
|
|
|
|
entity_gateway.with_transaction(|transaction| async move {
|
|
|
let item_state_proxy = ItemStateProxy::new(item_state);
|
|
|
let item_state_proxy = ItemStateProxy::new(item_state);
|
|
|
let ((item_state_proxy, transaction), p1_removed_items) = ItemStateAction::default()
|
|
|
|
|
|
|
|
|
let ((item_state_proxy, transaction), _) = ItemStateAction::default()
|
|
|
.act(take_meseta_from_inventory(*character_id, meseta.0))
|
|
|
.act(take_meseta_from_inventory(*character_id, meseta.0))
|
|
|
.commit((item_state_proxy, transaction))
|
|
|
.commit((item_state_proxy, transaction))
|
|
|
.await?;
|
|
|
.await?;
|
|
@ -1270,7 +1243,7 @@ pub async fn enemy_drops_item<'a, EG> ( |
|
|
where
|
|
|
where
|
|
|
EG: EntityGateway,
|
|
|
EG: EntityGateway,
|
|
|
{
|
|
|
{
|
|
|
entity_gateway.with_transaction(|mut transaction| async move {
|
|
|
|
|
|
|
|
|
entity_gateway.with_transaction(|transaction| async move {
|
|
|
let item_state_proxy = ItemStateProxy::new(item_state);
|
|
|
let item_state_proxy = ItemStateProxy::new(item_state);
|
|
|
let ((item_state_proxy, transaction), floor_item) = ItemStateAction::default()
|
|
|
let ((item_state_proxy, transaction), floor_item) = ItemStateAction::default()
|
|
|
.act(convert_item_drop_to_floor_item(character_id, item_drop))
|
|
|
.act(convert_item_drop_to_floor_item(character_id, item_drop))
|
|
@ -1283,17 +1256,17 @@ where |
|
|
}).await
|
|
|
}).await
|
|
|
}
|
|
|
}
|
|
|
|
|
|
|
|
|
fn apply_modifier_to_inventory_item(character_id: CharacterEntityId, modifier: ItemModifier)
|
|
|
|
|
|
|
|
|
fn apply_modifier_to_inventory_item(modifier: ItemModifier)
|
|
|
-> impl for<'a> Fn((ItemStateProxy<'a>, Box<dyn EntityGatewayTransaction + 'a>), InventoryItem)
|
|
|
-> 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>>
|
|
|
-> Pin<Box<dyn Future<Output=Result<((ItemStateProxy<'a>, Box<dyn EntityGatewayTransaction + 'a>), InventoryItem), ItemStateError>> + Send + 'a>>
|
|
|
{
|
|
|
{
|
|
|
move |(item_state, mut transaction), mut inventory_item| {
|
|
|
move |(item_state, mut transaction), mut inventory_item| {
|
|
|
let modifier = modifier.clone();
|
|
|
let modifier = modifier.clone();
|
|
|
Box::pin(async move {
|
|
|
Box::pin(async move {
|
|
|
match (&inventory_item.item, modifier) {
|
|
|
|
|
|
(InventoryItemDetail::Individual(IndividualItemDetail{entity_id, item: ItemDetail::Weapon(mut weapon), ..}), ItemModifier::WeaponModifier(modifier)) => {
|
|
|
|
|
|
|
|
|
match (&mut inventory_item.item, modifier) {
|
|
|
|
|
|
(InventoryItemDetail::Individual(IndividualItemDetail{entity_id, item: ItemDetail::Weapon(ref mut weapon), ..}), ItemModifier::WeaponModifier(modifier)) => {
|
|
|
weapon.apply_modifier(&modifier);
|
|
|
weapon.apply_modifier(&modifier);
|
|
|
transaction.gateway().add_weapon_modifier(&entity_id, modifier).await?;
|
|
|
|
|
|
|
|
|
transaction.gateway().add_weapon_modifier(entity_id, modifier).await?;
|
|
|
},
|
|
|
},
|
|
|
_ => return Err(ItemStateError::InvalidModifier)
|
|
|
_ => return Err(ItemStateError::InvalidModifier)
|
|
|
}
|
|
|
}
|
|
@ -1334,7 +1307,7 @@ where |
|
|
let item_state_proxy = ItemStateProxy::new(item_state);
|
|
|
let item_state_proxy = ItemStateProxy::new(item_state);
|
|
|
let ((item_state_proxy, transaction), item) = ItemStateAction::default()
|
|
|
let ((item_state_proxy, transaction), item) = ItemStateAction::default()
|
|
|
.act(take_item_from_inventory(character.id, item_id, 1))
|
|
|
.act(take_item_from_inventory(character.id, item_id, 1))
|
|
|
.act(apply_modifier_to_inventory_item(character.id, modifier))
|
|
|
|
|
|
|
|
|
.act(apply_modifier_to_inventory_item(modifier))
|
|
|
.act(add_item_to_inventory(character.clone()))
|
|
|
.act(add_item_to_inventory(character.clone()))
|
|
|
.act(as_individual_item())
|
|
|
.act(as_individual_item())
|
|
|
.commit((item_state_proxy, transaction))
|
|
|
.commit((item_state_proxy, transaction))
|
|
|