mirror of
https://gitlab.com/veloren/veloren.git
synced 2024-08-30 18:12:32 +00:00
Salvaging now requires a salvaging station.
This commit is contained in:
parent
6ff7317e05
commit
e28ca15059
@ -1026,13 +1026,13 @@ impl Client {
|
||||
.map_or(false, |item| item.is_salvageable())
|
||||
}
|
||||
|
||||
pub fn salvage_item(&mut self, slot: InvSlotId) -> bool {
|
||||
pub fn salvage_item(&mut self, slot: InvSlotId, salvage_pos: Vec3<i32>) -> bool {
|
||||
let is_salvageable = self.can_salvage_item(slot);
|
||||
if is_salvageable {
|
||||
self.send_msg(ClientGeneral::ControlEvent(ControlEvent::InventoryEvent(
|
||||
InventoryEvent::CraftRecipe {
|
||||
craft_event: CraftEvent::Salvage(slot),
|
||||
craft_sprite: None,
|
||||
craft_sprite: Some(salvage_pos),
|
||||
},
|
||||
)));
|
||||
}
|
||||
|
@ -12,6 +12,7 @@ use common::{
|
||||
},
|
||||
consts::MAX_PICKUP_RANGE,
|
||||
recipe::{self, default_recipe_book},
|
||||
terrain::SpriteKind,
|
||||
trade::Trades,
|
||||
uid::Uid,
|
||||
util::find_dist::{self, FindDist},
|
||||
@ -613,7 +614,33 @@ pub fn handle_inventory(server: &mut Server, entity: EcsEntity, manip: comp::Inv
|
||||
.ok()
|
||||
}),
|
||||
CraftEvent::Salvage(slot) => {
|
||||
recipe::try_salvage(&mut inventory, slot, ability_map, &msm).ok()
|
||||
let sprite = craft_sprite
|
||||
.filter(|pos| {
|
||||
let entity_cylinder = get_cylinder(state, entity);
|
||||
if !within_pickup_range(entity_cylinder, || {
|
||||
Some(find_dist::Cube {
|
||||
min: pos.as_(),
|
||||
side_length: 1.0,
|
||||
})
|
||||
}) {
|
||||
debug!(
|
||||
?entity_cylinder,
|
||||
"Failed to craft recipe as not within range of required \
|
||||
sprite, sprite pos: {}",
|
||||
pos
|
||||
);
|
||||
false
|
||||
} else {
|
||||
true
|
||||
}
|
||||
})
|
||||
.and_then(|pos| state.terrain().get(pos).ok().copied())
|
||||
.and_then(|block| block.get_sprite());
|
||||
if matches!(sprite, Some(SpriteKind::SalvagingBench)) {
|
||||
recipe::try_salvage(&mut inventory, slot, ability_map, &msm).ok()
|
||||
} else {
|
||||
None
|
||||
}
|
||||
},
|
||||
};
|
||||
|
||||
|
@ -521,7 +521,10 @@ pub enum Event {
|
||||
recipe: String,
|
||||
craft_sprite: Option<(Vec3<i32>, SpriteKind)>,
|
||||
},
|
||||
SalvageItem(InvSlotId),
|
||||
SalvageItem {
|
||||
slot: InvSlotId,
|
||||
salvage_pos: Vec3<i32>,
|
||||
},
|
||||
InviteMember(Uid),
|
||||
AcceptInvite,
|
||||
DeclineInvite,
|
||||
@ -725,6 +728,7 @@ impl Show {
|
||||
self.selected_crafting_tab(tab);
|
||||
self.crafting(true);
|
||||
self.craft_sprite = self.craft_sprite.or(craft_sprite);
|
||||
self.salvage = matches!(craft_sprite, Some((_, SpriteKind::SalvagingBench)));
|
||||
}
|
||||
|
||||
fn diary(&mut self, open: bool) {
|
||||
@ -1079,8 +1083,6 @@ impl Hud {
|
||||
camera: &Camera,
|
||||
interactable: Option<Interactable>,
|
||||
) -> Vec<Event> {
|
||||
self.show.salvage =
|
||||
self.show.crafting && matches!(self.show.crafting_tab, CraftingTab::Dismantle);
|
||||
span!(_guard, "update_layout", "Hud::update_layout");
|
||||
let mut events = core::mem::take(&mut self.events);
|
||||
if global_state.settings.interface.map_show_voxel_map {
|
||||
@ -3334,11 +3336,13 @@ impl Hud {
|
||||
slot::Event::Used(from) => {
|
||||
// Item used (selected and then clicked again)
|
||||
if let Some(from) = to_slot(from) {
|
||||
if self.show.crafting
|
||||
if self.show.salvage
|
||||
&& matches!(self.show.crafting_tab, CraftingTab::Dismantle)
|
||||
{
|
||||
if let Slot::Inventory(slot) = from {
|
||||
events.push(Event::SalvageItem(slot))
|
||||
if let (Slot::Inventory(slot), Some((salvage_pos, _sprite_kind))) =
|
||||
(from, self.show.craft_sprite)
|
||||
{
|
||||
events.push(Event::SalvageItem { slot, salvage_pos })
|
||||
}
|
||||
} else {
|
||||
events.push(Event::UseSlot {
|
||||
|
@ -114,9 +114,8 @@ impl BlocksOfInterest {
|
||||
Some(SpriteKind::SmokeDummy) => {
|
||||
smokers.push(pos);
|
||||
},
|
||||
Some(SpriteKind::Forge) => {
|
||||
interactables.push((pos, Interaction::Craft(CraftingTab::Dismantle)))
|
||||
},
|
||||
Some(SpriteKind::Forge) => interactables
|
||||
.push((pos, Interaction::Craft(CraftingTab::ProcessedMaterial))),
|
||||
Some(SpriteKind::TanningRack) => interactables
|
||||
.push((pos, Interaction::Craft(CraftingTab::ProcessedMaterial))),
|
||||
Some(SpriteKind::SpinningWheel) => {
|
||||
|
@ -1412,8 +1412,8 @@ impl PlayState for SessionState {
|
||||
.craft_recipe(&recipe, slots, craft_sprite);
|
||||
}
|
||||
},
|
||||
HudEvent::SalvageItem(slot) => {
|
||||
self.client.borrow_mut().salvage_item(slot);
|
||||
HudEvent::SalvageItem { slot, salvage_pos } => {
|
||||
self.client.borrow_mut().salvage_item(slot, salvage_pos);
|
||||
},
|
||||
HudEvent::InviteMember(uid) => {
|
||||
self.client.borrow_mut().send_invite(uid, InviteKind::Group);
|
||||
|
Loading…
Reference in New Issue
Block a user