Owned mine loot

This commit is contained in:
Isse 2022-06-12 17:56:59 +00:00 committed by Marcel
parent 179bf7216e
commit e03b733ad7
2 changed files with 14 additions and 5 deletions

View File

@ -30,6 +30,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
- Bamboo collectibles now spawn near rivers - Bamboo collectibles now spawn near rivers
- Chest sprites can longer be exploded - Chest sprites can longer be exploded
- Smoke varies by temperature, humidity, time of day and house - Smoke varies by temperature, humidity, time of day and house
- Added loot ownership for drops from mining
### Changed ### Changed

View File

@ -8,8 +8,9 @@ use common::{
agent::{AgentEvent, Sound, SoundKind}, agent::{AgentEvent, Sound, SoundKind},
dialogue::Subject, dialogue::Subject,
inventory::slot::EquipSlot, inventory::slot::EquipSlot,
loot_owner::LootOwnerKind,
tool::ToolKind, tool::ToolKind,
Inventory, Pos, SkillGroupKind, Inventory, LootOwner, Pos, SkillGroupKind,
}, },
consts::{MAX_MOUNT_RANGE, SOUND_TRAVEL_DIST_PER_VOLUME}, consts::{MAX_MOUNT_RANGE, SOUND_TRAVEL_DIST_PER_VOLUME},
event::EventBus, event::EventBus,
@ -169,6 +170,8 @@ pub fn handle_mine_block(
if let Some(block) = block.filter(|b| b.mine_tool().map_or(false, |t| Some(t) == tool)) { if let Some(block) = block.filter(|b| b.mine_tool().map_or(false, |t| Some(t) == tool)) {
// Drop item if one is recoverable from the block // Drop item if one is recoverable from the block
if let Some(mut item) = comp::Item::try_reclaim_from_block(block) { if let Some(mut item) = comp::Item::try_reclaim_from_block(block) {
let maybe_uid = state.ecs().uid_from_entity(entity);
if let Some(mut skillset) = state if let Some(mut skillset) = state
.ecs() .ecs()
.write_storage::<comp::SkillSet>() .write_storage::<comp::SkillSet>()
@ -176,7 +179,7 @@ pub fn handle_mine_block(
{ {
if let (Some(tool), Some(uid), Some(exp_reward)) = ( if let (Some(tool), Some(uid), Some(exp_reward)) = (
tool, tool,
state.ecs().uid_from_entity(entity), maybe_uid,
item.item_definition_id() item.item_definition_id()
.itemdef_id() .itemdef_id()
.and_then(|id| RESOURCE_EXPERIENCE_MANIFEST.read().0.get(id).copied()), .and_then(|id| RESOURCE_EXPERIENCE_MANIFEST.read().0.get(id).copied()),
@ -232,9 +235,14 @@ pub fn handle_mine_block(
let _ = item.increase_amount(1); let _ = item.increase_amount(1);
} }
} }
state let item_drop = state
.create_item_drop(Default::default(), item) .create_item_drop(Default::default(), item)
.with(comp::Pos(pos.map(|e| e as f32) + Vec3::new(0.5, 0.5, 0.0))) .with(comp::Pos(pos.map(|e| e as f32) + Vec3::new(0.5, 0.5, 0.0)));
if let Some(uid) = maybe_uid {
item_drop.with(LootOwner::new(LootOwnerKind::Player(uid)))
} else {
item_drop
}
.build(); .build();
} }