Changed how the lantern swap is caught

This commit is contained in:
ninefox 2022-01-18 17:42:08 -08:00
parent 64f6faece5
commit 8ca627342a
7 changed files with 11 additions and 36 deletions

View File

@ -1081,12 +1081,6 @@ impl Client {
self.send_msg(ClientGeneral::ControlEvent(ControlEvent::DisableLantern));
}
pub fn update_lantern(&mut self, lantern: comp::item::Lantern) {
self.send_msg(ClientGeneral::ControlEvent(ControlEvent::UpdateLantern(
lantern,
)));
}
pub fn remove_buff(&mut self, buff_id: BuffKind) {
self.send_msg(ClientGeneral::ControlEvent(ControlEvent::RemoveBuff(
buff_id,

View File

@ -125,7 +125,6 @@ pub enum ControlEvent {
//ToggleLantern,
EnableLantern,
DisableLantern,
UpdateLantern(crate::comp::item::Lantern),
Interact(Uid),
InitiateInvite(Uid, InviteKind),
InviteResponse(InviteResponse),

View File

@ -93,7 +93,6 @@ pub enum ServerEvent {
},
EnableLantern(EcsEntity),
DisableLantern(EcsEntity),
UpdateLantern(EcsEntity, comp::item::Lantern),
NpcInteract(EcsEntity, EcsEntity),
InviteResponse(EcsEntity, InviteResponse),
InitiateInvite(EcsEntity, Uid, InviteKind),

View File

@ -71,9 +71,6 @@ impl<'a> System<'a> for Sys {
ControlEvent::DisableLantern => {
server_emitter.emit(ServerEvent::DisableLantern(entity))
},
ControlEvent::UpdateLantern(lantern) => {
server_emitter.emit(ServerEvent::UpdateLantern(entity, lantern))
},
ControlEvent::Interact(npc_uid) => {
if let Some(npc_entity) = read_data
.uid_allocator

View File

@ -427,6 +427,16 @@ pub fn handle_inventory(server: &mut Server, entity: EcsEntity, manip: comp::Inv
comp::InventoryManip::Swap(a, b) => {
let ecs = state.ecs();
if let (Slot::Inventory(inv_slot), Slot::Equip(slot::EquipSlot::Lantern))
| (Slot::Equip(slot::EquipSlot::Lantern), Slot::Inventory(inv_slot)) = (a, b)
{
if let Some(comp::item::ItemKind::Lantern(lantern)) =
inventory.get(inv_slot).and_then(|item| Some(item.kind()))
{
swap_lantern(&mut ecs.write_storage(), entity, &lantern);
}
}
if let Some(pos) = ecs.read_storage::<comp::Pos>().get(entity) {
let mut merged_stacks = false;

View File

@ -17,7 +17,7 @@ use interaction::{
handle_create_sprite, handle_lantern, handle_mine_block, handle_mount, handle_npc_interaction,
handle_possess, handle_sound, handle_unmount,
};
use inventory_manip::{handle_inventory, swap_lantern};
use inventory_manip::handle_inventory;
use invite::{handle_invite, handle_invite_response};
use player::{handle_client_disconnect, handle_exit_ingame};
use specs::{Builder, Entity as EcsEntity, WorldExt};
@ -107,14 +107,6 @@ impl Server {
},
ServerEvent::EnableLantern(entity) => handle_lantern(self, entity, true),
ServerEvent::DisableLantern(entity) => handle_lantern(self, entity, false),
ServerEvent::UpdateLantern(entity, lantern) => swap_lantern(
&mut self
.state
.ecs()
.write_storage::<common::comp::LightEmitter>(),
entity,
&lantern,
),
ServerEvent::NpcInteract(interactor, target) => {
handle_npc_interaction(self, interactor, target)
},

View File

@ -1234,7 +1234,6 @@ impl PlayState for SessionState {
bypass_dialog,
} => {
let mut move_allowed = true;
let mut lantern_opt: Option<comp::item::Lantern> = None;
if !bypass_dialog {
if let Some(inventory) = self
.client
@ -1247,18 +1246,6 @@ impl PlayState for SessionState {
match (slot_a, slot_b) {
(Slot::Inventory(inv_slot), Slot::Equip(equip_slot))
| (Slot::Equip(equip_slot), Slot::Inventory(inv_slot)) => {
if let EquipSlot::Lantern = equip_slot {
lantern_opt =
inventory.get(inv_slot).and_then(|item| {
if let comp::item::ItemKind::Lantern(l) =
item.kind()
{
Some(l.clone())
} else {
None
}
});
}
if !inventory.can_swap(inv_slot, equip_slot) {
move_allowed = false;
} else {
@ -1290,9 +1277,6 @@ impl PlayState for SessionState {
}
if move_allowed {
self.client.borrow_mut().swap_slots(slot_a, slot_b);
if let Some(lantern) = lantern_opt {
self.client.borrow_mut().update_lantern(lantern)
}
}
},
HudEvent::SplitSwapSlots {