|
|
@ -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> {
|
|
|
|