mirror of
https://gitlab.com/veloren/veloren.git
synced 2024-08-30 18:12:32 +00:00
Fix loot forcing
This commit is contained in:
parent
37c14037cb
commit
5da2850624
@ -63,6 +63,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
|
|||||||
- You are now immune to poise damage for 1 second after leaving a stunned state
|
- You are now immune to poise damage for 1 second after leaving a stunned state
|
||||||
- Removed or reduced poise damage from most abilities
|
- Removed or reduced poise damage from most abilities
|
||||||
- Made the hotbar link to items by item definition id and component composition instead of specific inventory slots.
|
- Made the hotbar link to items by item definition id and component composition instead of specific inventory slots.
|
||||||
|
- Made loot boxes drop items instead of doing nothing in order to loot forcing
|
||||||
|
|
||||||
### Removed
|
### Removed
|
||||||
|
|
||||||
|
@ -192,6 +192,7 @@ pub fn handle_inventory(server: &mut Server, entity: EcsEntity, manip: comp::Inv
|
|||||||
},
|
},
|
||||||
comp::InventoryManip::Collect(pos) => {
|
comp::InventoryManip::Collect(pos) => {
|
||||||
let block = state.terrain().get(pos).ok().copied();
|
let block = state.terrain().get(pos).ok().copied();
|
||||||
|
let mut drop_item = None;
|
||||||
|
|
||||||
if let Some(block) = block {
|
if let Some(block) = block {
|
||||||
if block.is_collectible() && state.can_set_block(pos) {
|
if block.is_collectible() && state.can_set_block(pos) {
|
||||||
@ -201,7 +202,7 @@ pub fn handle_inventory(server: &mut Server, entity: EcsEntity, manip: comp::Inv
|
|||||||
&state.ecs().read_resource::<AbilityMap>(),
|
&state.ecs().read_resource::<AbilityMap>(),
|
||||||
&state.ecs().read_resource::<MaterialStatManifest>(),
|
&state.ecs().read_resource::<MaterialStatManifest>(),
|
||||||
);
|
);
|
||||||
let (event, item_was_added) = match inventory.push(item) {
|
let event = match inventory.push(item) {
|
||||||
Ok(_) => {
|
Ok(_) => {
|
||||||
let ecs = state.ecs();
|
let ecs = state.ecs();
|
||||||
if let Some(group_id) =
|
if let Some(group_id) =
|
||||||
@ -209,33 +210,26 @@ pub fn handle_inventory(server: &mut Server, entity: EcsEntity, manip: comp::Inv
|
|||||||
{
|
{
|
||||||
announce_loot_to_group(group_id, ecs, entity, &item_msg.name);
|
announce_loot_to_group(group_id, ecs, entity, &item_msg.name);
|
||||||
}
|
}
|
||||||
(
|
comp::InventoryUpdate::new(comp::InventoryUpdateEvent::Collected(
|
||||||
Some(comp::InventoryUpdate::new(
|
item_msg,
|
||||||
comp::InventoryUpdateEvent::Collected(item_msg),
|
))
|
||||||
)),
|
|
||||||
true,
|
|
||||||
)
|
|
||||||
},
|
},
|
||||||
// The item we created was in some sense "fake" so it's safe to
|
// The item we created was in some sense "fake" so it's safe to
|
||||||
// drop it.
|
// drop it.
|
||||||
Err(_) => (
|
Err(_) => {
|
||||||
Some(comp::InventoryUpdate::new(
|
drop_item = Some(item_msg);
|
||||||
|
comp::InventoryUpdate::new(
|
||||||
comp::InventoryUpdateEvent::BlockCollectFailed(pos),
|
comp::InventoryUpdateEvent::BlockCollectFailed(pos),
|
||||||
)),
|
)
|
||||||
false,
|
},
|
||||||
),
|
|
||||||
};
|
};
|
||||||
if let Some(event) = event {
|
|
||||||
state
|
state
|
||||||
.ecs()
|
.ecs()
|
||||||
.write_storage()
|
.write_storage()
|
||||||
.insert(entity, event)
|
.insert(entity, event)
|
||||||
.expect("We know entity exists since we got its inventory.");
|
.expect("We know entity exists since we got its inventory.");
|
||||||
if item_was_added {
|
|
||||||
// we made sure earlier the block was not already modified this tick
|
// we made sure earlier the block was not already modified this tick
|
||||||
state.set_block(pos, block.into_vacant())
|
state.set_block(pos, block.into_vacant());
|
||||||
};
|
|
||||||
}
|
|
||||||
} else {
|
} else {
|
||||||
debug!(
|
debug!(
|
||||||
"Failed to reclaim item from block at pos={} or entity had no \
|
"Failed to reclaim item from block at pos={} or entity had no \
|
||||||
@ -252,6 +246,22 @@ pub fn handle_inventory(server: &mut Server, entity: EcsEntity, manip: comp::Inv
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
drop(inventories);
|
drop(inventories);
|
||||||
|
if let Some(item) = drop_item {
|
||||||
|
// TODO: Choose a body appropriate for the item
|
||||||
|
let body = match item.item_definition_id() {
|
||||||
|
"common.items.utility.coins" => comp::object::Body::Coins,
|
||||||
|
_ => comp::object::Body::Pouch,
|
||||||
|
};
|
||||||
|
|
||||||
|
state
|
||||||
|
.create_object(Default::default(), body)
|
||||||
|
.with(comp::Pos(
|
||||||
|
Vec3::new(pos.x as f32, pos.y as f32, pos.z as f32) + Vec3::unit_z(),
|
||||||
|
))
|
||||||
|
.with(item)
|
||||||
|
.with(comp::Vel(Vec3::zero()))
|
||||||
|
.build();
|
||||||
|
}
|
||||||
},
|
},
|
||||||
comp::InventoryManip::Use(slot) => {
|
comp::InventoryManip::Use(slot) => {
|
||||||
let mut maybe_effect = None;
|
let mut maybe_effect = None;
|
||||||
|
Loading…
Reference in New Issue
Block a user