|
|
@ -15,6 +15,7 @@ use crate::ship::trade::TradeItem; |
|
|
|
use crate::ship::drops::{ItemDrop, ItemDropType};
|
|
|
|
use crate::ship::location::{AreaClient, RoomId};
|
|
|
|
use crate::ship::shops::ShopItem;
|
|
|
|
use crate::ship::packet::handler::trade::TradeError;
|
|
|
|
|
|
|
|
use crate::ship::items::bank::*;
|
|
|
|
use crate::ship::items::floor::*;
|
|
|
@ -329,7 +330,7 @@ impl ItemManager { |
|
|
|
}));
|
|
|
|
TriggerCreateItem::No
|
|
|
|
},
|
|
|
|
SpaceForStack::No => {
|
|
|
|
SpaceForStack::No(_) => {
|
|
|
|
return Err(ItemManagerError::CouldNotAddToInventory(*item_id).into());
|
|
|
|
},
|
|
|
|
}
|
|
|
@ -945,9 +946,48 @@ impl ItemManager { |
|
|
|
let p1_inventory = it.manager.get_character_inventory(p1.1)?;
|
|
|
|
let p2_inventory = it.manager.get_character_inventory(p2.1)?;
|
|
|
|
|
|
|
|
//TODO: inv-selftrade+othertrade <= 30
|
|
|
|
//if p1_inventory
|
|
|
|
|
|
|
|
[(p2_inventory, p1_inventory, p2.2), (p1_inventory, p2_inventory, p1.2)].iter()
|
|
|
|
.map(|(src_inventory, dest_inventory, to_trade)| {
|
|
|
|
to_trade
|
|
|
|
.iter()
|
|
|
|
.try_fold(dest_inventory.count(), |acc, item| {
|
|
|
|
match item {
|
|
|
|
TradeItem::Individual(..) => {
|
|
|
|
if acc >= 30 {
|
|
|
|
Err(TradeError::NoInventorySpace)
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
Ok(acc + 1)
|
|
|
|
}
|
|
|
|
},
|
|
|
|
TradeItem::Stacked(item_id, amount) => {
|
|
|
|
let stacked_inventory_item = src_inventory
|
|
|
|
.get_item_by_id(*item_id)
|
|
|
|
.ok_or_else(|| TradeError::InvalidItemId(*item_id))?
|
|
|
|
.stacked()
|
|
|
|
.ok_or_else(|| TradeError::InvalidItemId(*item_id))?;
|
|
|
|
match dest_inventory.space_for_stacked_item(&stacked_inventory_item.tool, *amount) {
|
|
|
|
SpaceForStack::Yes(YesThereIsSpace::ExistingStack) => {
|
|
|
|
Ok(acc)
|
|
|
|
},
|
|
|
|
SpaceForStack::Yes(YesThereIsSpace::NewStack) => {
|
|
|
|
Ok(acc + 1)
|
|
|
|
},
|
|
|
|
SpaceForStack::No(NoThereIsNotSpace::FullStack) => {
|
|
|
|
Err(TradeError::NoStackSpace)
|
|
|
|
},
|
|
|
|
SpaceForStack::No(NoThereIsNotSpace::FullInventory) => {
|
|
|
|
Err(TradeError::NoInventorySpace)
|
|
|
|
},
|
|
|
|
}
|
|
|
|
},
|
|
|
|
TradeItem::Meseta(..) => {
|
|
|
|
Ok(acc)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
})
|
|
|
|
})
|
|
|
|
.collect::<Result<Vec<_>, _>>()?;
|
|
|
|
|
|
|
|
let trade_items = [(p1, p2, p1_inventory, p2_inventory), (p2, p1, p2_inventory, p1_inventory)]
|
|
|
|
.map(|(src_client, dest_client, src_inventory, dest_inventory)| {
|
|
|
|