Merge branch 'isse/owned-mine-drop' into 'master'

Owned mine loot

See merge request veloren/veloren!3431
This commit is contained in:
Marcel 2022-06-12 17:56:59 +00:00
commit e83cd45913
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
- Chest sprites can longer be exploded
- Smoke varies by temperature, humidity, time of day and house
- Added loot ownership for drops from mining
### Changed

View File

@ -8,8 +8,9 @@ use common::{
agent::{AgentEvent, Sound, SoundKind},
dialogue::Subject,
inventory::slot::EquipSlot,
loot_owner::LootOwnerKind,
tool::ToolKind,
Inventory, Pos, SkillGroupKind,
Inventory, LootOwner, Pos, SkillGroupKind,
},
consts::{MAX_MOUNT_RANGE, SOUND_TRAVEL_DIST_PER_VOLUME},
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)) {
// Drop item if one is recoverable from the 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
.ecs()
.write_storage::<comp::SkillSet>()
@ -176,7 +179,7 @@ pub fn handle_mine_block(
{
if let (Some(tool), Some(uid), Some(exp_reward)) = (
tool,
state.ecs().uid_from_entity(entity),
maybe_uid,
item.item_definition_id()
.itemdef_id()
.and_then(|id| RESOURCE_EXPERIENCE_MANIFEST.read().0.get(id).copied()),
@ -232,10 +235,15 @@ pub fn handle_mine_block(
let _ = item.increase_amount(1);
}
}
state
let item_drop = state
.create_item_drop(Default::default(), item)
.with(comp::Pos(pos.map(|e| e as f32) + Vec3::new(0.5, 0.5, 0.0)))
.build();
.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();
}
state.set_block(pos, block.into_vacant());