Salvaging now requires a salvaging station.

This commit is contained in:
Sam 2021-10-12 19:47:14 -04:00
parent 6ff7317e05
commit e28ca15059
5 changed files with 44 additions and 14 deletions

View File

@ -1026,13 +1026,13 @@ impl Client {
.map_or(false, |item| item.is_salvageable()) .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); let is_salvageable = self.can_salvage_item(slot);
if is_salvageable { if is_salvageable {
self.send_msg(ClientGeneral::ControlEvent(ControlEvent::InventoryEvent( self.send_msg(ClientGeneral::ControlEvent(ControlEvent::InventoryEvent(
InventoryEvent::CraftRecipe { InventoryEvent::CraftRecipe {
craft_event: CraftEvent::Salvage(slot), craft_event: CraftEvent::Salvage(slot),
craft_sprite: None, craft_sprite: Some(salvage_pos),
}, },
))); )));
} }

View File

@ -12,6 +12,7 @@ use common::{
}, },
consts::MAX_PICKUP_RANGE, consts::MAX_PICKUP_RANGE,
recipe::{self, default_recipe_book}, recipe::{self, default_recipe_book},
terrain::SpriteKind,
trade::Trades, trade::Trades,
uid::Uid, uid::Uid,
util::find_dist::{self, FindDist}, util::find_dist::{self, FindDist},
@ -613,7 +614,33 @@ pub fn handle_inventory(server: &mut Server, entity: EcsEntity, manip: comp::Inv
.ok() .ok()
}), }),
CraftEvent::Salvage(slot) => { CraftEvent::Salvage(slot) => {
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() recipe::try_salvage(&mut inventory, slot, ability_map, &msm).ok()
} else {
None
}
}, },
}; };

View File

@ -521,7 +521,10 @@ pub enum Event {
recipe: String, recipe: String,
craft_sprite: Option<(Vec3<i32>, SpriteKind)>, craft_sprite: Option<(Vec3<i32>, SpriteKind)>,
}, },
SalvageItem(InvSlotId), SalvageItem {
slot: InvSlotId,
salvage_pos: Vec3<i32>,
},
InviteMember(Uid), InviteMember(Uid),
AcceptInvite, AcceptInvite,
DeclineInvite, DeclineInvite,
@ -725,6 +728,7 @@ impl Show {
self.selected_crafting_tab(tab); self.selected_crafting_tab(tab);
self.crafting(true); self.crafting(true);
self.craft_sprite = self.craft_sprite.or(craft_sprite); self.craft_sprite = self.craft_sprite.or(craft_sprite);
self.salvage = matches!(craft_sprite, Some((_, SpriteKind::SalvagingBench)));
} }
fn diary(&mut self, open: bool) { fn diary(&mut self, open: bool) {
@ -1079,8 +1083,6 @@ impl Hud {
camera: &Camera, camera: &Camera,
interactable: Option<Interactable>, interactable: Option<Interactable>,
) -> Vec<Event> { ) -> Vec<Event> {
self.show.salvage =
self.show.crafting && matches!(self.show.crafting_tab, CraftingTab::Dismantle);
span!(_guard, "update_layout", "Hud::update_layout"); span!(_guard, "update_layout", "Hud::update_layout");
let mut events = core::mem::take(&mut self.events); let mut events = core::mem::take(&mut self.events);
if global_state.settings.interface.map_show_voxel_map { if global_state.settings.interface.map_show_voxel_map {
@ -3334,11 +3336,13 @@ impl Hud {
slot::Event::Used(from) => { slot::Event::Used(from) => {
// Item used (selected and then clicked again) // Item used (selected and then clicked again)
if let Some(from) = to_slot(from) { if let Some(from) = to_slot(from) {
if self.show.crafting if self.show.salvage
&& matches!(self.show.crafting_tab, CraftingTab::Dismantle) && matches!(self.show.crafting_tab, CraftingTab::Dismantle)
{ {
if let Slot::Inventory(slot) = from { if let (Slot::Inventory(slot), Some((salvage_pos, _sprite_kind))) =
events.push(Event::SalvageItem(slot)) (from, self.show.craft_sprite)
{
events.push(Event::SalvageItem { slot, salvage_pos })
} }
} else { } else {
events.push(Event::UseSlot { events.push(Event::UseSlot {

View File

@ -114,9 +114,8 @@ impl BlocksOfInterest {
Some(SpriteKind::SmokeDummy) => { Some(SpriteKind::SmokeDummy) => {
smokers.push(pos); smokers.push(pos);
}, },
Some(SpriteKind::Forge) => { Some(SpriteKind::Forge) => interactables
interactables.push((pos, Interaction::Craft(CraftingTab::Dismantle))) .push((pos, Interaction::Craft(CraftingTab::ProcessedMaterial))),
},
Some(SpriteKind::TanningRack) => interactables Some(SpriteKind::TanningRack) => interactables
.push((pos, Interaction::Craft(CraftingTab::ProcessedMaterial))), .push((pos, Interaction::Craft(CraftingTab::ProcessedMaterial))),
Some(SpriteKind::SpinningWheel) => { Some(SpriteKind::SpinningWheel) => {

View File

@ -1412,8 +1412,8 @@ impl PlayState for SessionState {
.craft_recipe(&recipe, slots, craft_sprite); .craft_recipe(&recipe, slots, craft_sprite);
} }
}, },
HudEvent::SalvageItem(slot) => { HudEvent::SalvageItem { slot, salvage_pos } => {
self.client.borrow_mut().salvage_item(slot); self.client.borrow_mut().salvage_item(slot, salvage_pos);
}, },
HudEvent::InviteMember(uid) => { HudEvent::InviteMember(uid) => {
self.client.borrow_mut().send_invite(uid, InviteKind::Group); self.client.borrow_mut().send_invite(uid, InviteKind::Group);