fix bug where picking up a stack caused 2x that item to be picked up
This commit is contained in:
parent
ed51aa379c
commit
ddee920080
@ -28,7 +28,6 @@ pub enum ActiveItemEntityId {
|
||||
Meseta(Meseta),
|
||||
}
|
||||
|
||||
|
||||
#[derive(Debug, Clone, PartialEq)]
|
||||
pub enum HeldItemType {
|
||||
Individual(ItemDetail),
|
||||
@ -142,6 +141,12 @@ impl<'a> CharacterInventory<'a> {
|
||||
}
|
||||
}
|
||||
|
||||
pub enum TriggerCreateItem {
|
||||
Yes,
|
||||
No
|
||||
}
|
||||
|
||||
|
||||
#[derive(Error, Debug)]
|
||||
#[error("")]
|
||||
pub enum ItemManagerError {
|
||||
@ -284,7 +289,7 @@ impl ItemManager {
|
||||
.map(Clone::clone)
|
||||
}
|
||||
|
||||
pub fn character_picks_up_item<EG: EntityGateway>(&mut self, entity_gateway: &mut EG, character: &mut CharacterEntity, floor_item: FloorItem) -> Result<(), ItemManagerError> {
|
||||
pub fn character_picks_up_item<EG: EntityGateway>(&mut self, entity_gateway: &mut EG, character: &mut CharacterEntity, floor_item: FloorItem) -> Result<TriggerCreateItem, ItemManagerError> {
|
||||
let local_floor = self.character_floor.get_mut(&character.id).ok_or(ItemManagerError::NoCharacter(character.id))?;
|
||||
let inventory = self.character_inventory.get_mut(&character.id).ok_or(ItemManagerError::NoCharacter(character.id))?;
|
||||
let room_id = self.character_room.get(&character.id).ok_or(ItemManagerError::NoCharacter(character.id))?;
|
||||
@ -333,7 +338,7 @@ impl ItemManager {
|
||||
return Err(ItemManagerError::NoSuchItemId(floor_item.item_id))
|
||||
}
|
||||
|
||||
match floor_item.item {
|
||||
let trigger_create = match floor_item.item {
|
||||
FloorItemType::Individual(item) => {
|
||||
let inventory_item = InventoryItem {
|
||||
entity_id: floor_item.entity_id,
|
||||
@ -354,9 +359,10 @@ impl ItemManager {
|
||||
}); // TODO: error check
|
||||
inventory.push(inventory_item);
|
||||
} // else something went very wrong TODO: log it
|
||||
TriggerCreateItem::Yes
|
||||
},
|
||||
FloorItemType::Stacked(tool, amount) => {
|
||||
let inventory_item = inventory.iter_mut()
|
||||
let (trigger_create, inventory_item) = inventory.iter_mut()
|
||||
.filter(|i| {
|
||||
if let HeldItemType::Stacked(tooltype, _amount) = i.item {
|
||||
tooltype == tool
|
||||
@ -382,7 +388,7 @@ impl ItemManager {
|
||||
*inv_amount += floor_amount
|
||||
}
|
||||
|
||||
existing_inv_item.clone()
|
||||
(TriggerCreateItem::No, existing_inv_item.clone())
|
||||
})
|
||||
.unwrap_or_else(|| {
|
||||
let picked_up_item = InventoryItem {
|
||||
@ -392,7 +398,7 @@ impl ItemManager {
|
||||
equipped: false,
|
||||
};
|
||||
inventory.push(picked_up_item.clone());
|
||||
picked_up_item
|
||||
(TriggerCreateItem::Yes, picked_up_item)
|
||||
});
|
||||
|
||||
if let ActiveItemEntityId::Stacked(item_ids) = &inventory_item.entity_id {
|
||||
@ -408,14 +414,16 @@ impl ItemManager {
|
||||
}); // TODO: error check
|
||||
};
|
||||
} // else something went very wrong TODO: log it
|
||||
trigger_create
|
||||
},
|
||||
FloorItemType::Meseta(meseta) => {
|
||||
character.meseta = std::cmp::min(character.meseta + meseta.0, 999999);
|
||||
entity_gateway.save_character(&character);
|
||||
TriggerCreateItem::No
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
Ok(())
|
||||
Ok(trigger_create)
|
||||
}
|
||||
|
||||
pub fn enemy_drop_item_on_local_floor<EG: EntityGateway>(&mut self, entity_gateway: &mut EG, character: &CharacterEntity, item_drop: ItemDrop) -> Result<&FloorItem, ItemManagerError> {
|
||||
|
@ -5,7 +5,7 @@ use crate::common::serverstate::ClientId;
|
||||
use crate::ship::ship::{SendShipPacket, ShipError, Clients, Rooms};
|
||||
use crate::ship::location::{ClientLocation, ClientLocationError};
|
||||
use crate::ship::drops::ItemDrop;
|
||||
use crate::ship::items::{ItemManager, FloorItemType, ClientItemId};
|
||||
use crate::ship::items::{ItemManager, FloorItemType, ClientItemId, TriggerCreateItem};
|
||||
use crate::entity::gateway::EntityGateway;
|
||||
use libpso::utf8_to_utf16_array;
|
||||
use crate::ship::packet::builder;
|
||||
@ -119,7 +119,7 @@ where
|
||||
};
|
||||
|
||||
match item_manager.character_picks_up_item(entity_gateway, &mut client.character, item) {
|
||||
Ok(_) => {
|
||||
Ok(trigger_create_item) => {
|
||||
Ok(Box::new(Vec::new().into_iter()
|
||||
.chain(clients_in_area.clone().into_iter()
|
||||
.map(move |c| {
|
||||
@ -127,7 +127,10 @@ where
|
||||
}))
|
||||
.chain(clients_in_area.into_iter().
|
||||
filter_map(move |c| {
|
||||
create_item.clone().map(|ci| (c.client, SendShipPacket::Message(Message::new(GameMessage::CreateItem(ci)))))
|
||||
match trigger_create_item {
|
||||
TriggerCreateItem::Yes => create_item.clone().map(|ci| (c.client, SendShipPacket::Message(Message::new(GameMessage::CreateItem(ci))))),
|
||||
_ => None
|
||||
}
|
||||
}
|
||||
)))
|
||||
)
|
||||
|
Loading…
x
Reference in New Issue
Block a user