|
@ -28,7 +28,6 @@ pub enum ActiveItemEntityId { |
|
|
Meseta(Meseta),
|
|
|
Meseta(Meseta),
|
|
|
}
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
#[derive(Debug, Clone, PartialEq)]
|
|
|
#[derive(Debug, Clone, PartialEq)]
|
|
|
pub enum HeldItemType {
|
|
|
pub enum HeldItemType {
|
|
|
Individual(ItemDetail),
|
|
|
Individual(ItemDetail),
|
|
@ -142,6 +141,12 @@ impl<'a> CharacterInventory<'a> { |
|
|
}
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
pub enum TriggerCreateItem {
|
|
|
|
|
|
Yes,
|
|
|
|
|
|
No
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
#[derive(Error, Debug)]
|
|
|
#[derive(Error, Debug)]
|
|
|
#[error("")]
|
|
|
#[error("")]
|
|
|
pub enum ItemManagerError {
|
|
|
pub enum ItemManagerError {
|
|
@ -284,7 +289,7 @@ impl ItemManager { |
|
|
.map(Clone::clone)
|
|
|
.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 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 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))?;
|
|
|
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))
|
|
|
return Err(ItemManagerError::NoSuchItemId(floor_item.item_id))
|
|
|
}
|
|
|
}
|
|
|
|
|
|
|
|
|
match floor_item.item {
|
|
|
|
|
|
|
|
|
let trigger_create = match floor_item.item {
|
|
|
FloorItemType::Individual(item) => {
|
|
|
FloorItemType::Individual(item) => {
|
|
|
let inventory_item = InventoryItem {
|
|
|
let inventory_item = InventoryItem {
|
|
|
entity_id: floor_item.entity_id,
|
|
|
entity_id: floor_item.entity_id,
|
|
@ -354,9 +359,10 @@ impl ItemManager { |
|
|
}); // TODO: error check
|
|
|
}); // TODO: error check
|
|
|
inventory.push(inventory_item);
|
|
|
inventory.push(inventory_item);
|
|
|
} // else something went very wrong TODO: log it
|
|
|
} // else something went very wrong TODO: log it
|
|
|
|
|
|
TriggerCreateItem::Yes
|
|
|
},
|
|
|
},
|
|
|
FloorItemType::Stacked(tool, amount) => {
|
|
|
FloorItemType::Stacked(tool, amount) => {
|
|
|
let inventory_item = inventory.iter_mut()
|
|
|
|
|
|
|
|
|
let (trigger_create, inventory_item) = inventory.iter_mut()
|
|
|
.filter(|i| {
|
|
|
.filter(|i| {
|
|
|
if let HeldItemType::Stacked(tooltype, _amount) = i.item {
|
|
|
if let HeldItemType::Stacked(tooltype, _amount) = i.item {
|
|
|
tooltype == tool
|
|
|
tooltype == tool
|
|
@ -382,7 +388,7 @@ impl ItemManager { |
|
|
*inv_amount += floor_amount
|
|
|
*inv_amount += floor_amount
|
|
|
}
|
|
|
}
|
|
|
|
|
|
|
|
|
existing_inv_item.clone()
|
|
|
|
|
|
|
|
|
(TriggerCreateItem::No, existing_inv_item.clone())
|
|
|
})
|
|
|
})
|
|
|
.unwrap_or_else(|| {
|
|
|
.unwrap_or_else(|| {
|
|
|
let picked_up_item = InventoryItem {
|
|
|
let picked_up_item = InventoryItem {
|
|
@ -392,7 +398,7 @@ impl ItemManager { |
|
|
equipped: false,
|
|
|
equipped: false,
|
|
|
};
|
|
|
};
|
|
|
inventory.push(picked_up_item.clone());
|
|
|
inventory.push(picked_up_item.clone());
|
|
|
picked_up_item
|
|
|
|
|
|
|
|
|
(TriggerCreateItem::Yes, picked_up_item)
|
|
|
});
|
|
|
});
|
|
|
|
|
|
|
|
|
if let ActiveItemEntityId::Stacked(item_ids) = &inventory_item.entity_id {
|
|
|
if let ActiveItemEntityId::Stacked(item_ids) = &inventory_item.entity_id {
|
|
@ -408,14 +414,16 @@ impl ItemManager { |
|
|
}); // TODO: error check
|
|
|
}); // TODO: error check
|
|
|
};
|
|
|
};
|
|
|
} // else something went very wrong TODO: log it
|
|
|
} // else something went very wrong TODO: log it
|
|
|
|
|
|
trigger_create
|
|
|
},
|
|
|
},
|
|
|
FloorItemType::Meseta(meseta) => {
|
|
|
FloorItemType::Meseta(meseta) => {
|
|
|
character.meseta = std::cmp::min(character.meseta + meseta.0, 999999);
|
|
|
character.meseta = std::cmp::min(character.meseta + meseta.0, 999999);
|
|
|
entity_gateway.save_character(&character);
|
|
|
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> {
|
|
|
pub fn enemy_drop_item_on_local_floor<EG: EntityGateway>(&mut self, entity_gateway: &mut EG, character: &CharacterEntity, item_drop: ItemDrop) -> Result<&FloorItem, ItemManagerError> {
|
|
|