mirror of
https://gitlab.com/veloren/veloren.git
synced 2024-08-30 18:12:32 +00:00
Loadout manipulations now emit a separate event from client instead of hackily intercepting inventory manipulations in common.
This commit is contained in:
parent
f026aeb2dc
commit
1c83c5ee6f
@ -22,8 +22,9 @@ use common::{
|
||||
chat::{KillSource, KillType},
|
||||
group,
|
||||
skills::Skill,
|
||||
slot::Slot,
|
||||
ControlAction, ControlEvent, Controller, ControllerInputs, GroupManip, InventoryManip,
|
||||
InventoryUpdateEvent,
|
||||
InventoryUpdateEvent, LoadoutManip,
|
||||
},
|
||||
event::{EventBus, LocalEvent},
|
||||
grid::Grid,
|
||||
@ -598,22 +599,32 @@ impl Client {
|
||||
self.send_msg(ClientGeneral::SetViewDistance(self.view_distance.unwrap()));
|
||||
}
|
||||
|
||||
pub fn use_slot(&mut self, slot: comp::slot::Slot) {
|
||||
pub fn use_slot(&mut self, slot: Slot) {
|
||||
self.send_msg(ClientGeneral::ControlEvent(ControlEvent::InventoryManip(
|
||||
InventoryManip::Use(slot),
|
||||
)));
|
||||
}
|
||||
|
||||
pub fn swap_slots(&mut self, a: comp::slot::Slot, b: comp::slot::Slot) {
|
||||
self.send_msg(ClientGeneral::ControlEvent(ControlEvent::InventoryManip(
|
||||
InventoryManip::Swap(a, b),
|
||||
)));
|
||||
pub fn swap_slots(&mut self, a: Slot, b: Slot) {
|
||||
match (a, b) {
|
||||
(Slot::Equip(equip), slot) | (slot, Slot::Equip(equip)) => {
|
||||
self.control_action(ControlAction::LoadoutManip(LoadoutManip::Swap(equip, slot)))
|
||||
},
|
||||
_ => self.send_msg(ClientGeneral::ControlEvent(ControlEvent::InventoryManip(
|
||||
InventoryManip::Swap(a, b),
|
||||
))),
|
||||
}
|
||||
}
|
||||
|
||||
pub fn drop_slot(&mut self, slot: comp::slot::Slot) {
|
||||
self.send_msg(ClientGeneral::ControlEvent(ControlEvent::InventoryManip(
|
||||
InventoryManip::Drop(slot),
|
||||
)));
|
||||
pub fn drop_slot(&mut self, slot: Slot) {
|
||||
match slot {
|
||||
Slot::Equip(equip) => {
|
||||
self.control_action(ControlAction::LoadoutManip(LoadoutManip::Drop(equip)))
|
||||
},
|
||||
_ => self.send_msg(ClientGeneral::ControlEvent(ControlEvent::InventoryManip(
|
||||
InventoryManip::Drop(slot),
|
||||
))),
|
||||
}
|
||||
}
|
||||
|
||||
pub fn pick_up(&mut self, entity: EcsEntity) {
|
||||
@ -807,7 +818,7 @@ impl Client {
|
||||
|
||||
/// Checks whether a player can swap their weapon+ability `Loadout` settings
|
||||
/// and sends the `ControlAction` event that signals to do the swap.
|
||||
pub fn swap_loadout(&mut self) { self.control_action(ControlAction::SwapLoadout) }
|
||||
pub fn swap_loadout(&mut self) { self.control_action(ControlAction::SwapEquippedWeapons) }
|
||||
|
||||
pub fn toggle_wield(&mut self) {
|
||||
let is_wielding = self
|
||||
|
@ -16,7 +16,7 @@ pub struct StateUpdate {
|
||||
pub vel: Vel,
|
||||
pub ori: Ori,
|
||||
pub energy: Energy,
|
||||
pub swap_loadout: bool,
|
||||
pub swap_equipped_weapons: bool,
|
||||
pub local_events: VecDeque<LocalEvent>,
|
||||
pub server_events: VecDeque<ServerEvent>,
|
||||
}
|
||||
@ -28,7 +28,7 @@ impl From<&JoinData<'_>> for StateUpdate {
|
||||
vel: *data.vel,
|
||||
ori: *data.ori,
|
||||
energy: *data.energy,
|
||||
swap_loadout: false,
|
||||
swap_equipped_weapons: false,
|
||||
character: data.character.clone(),
|
||||
local_events: VecDeque::new(),
|
||||
server_events: VecDeque::new(),
|
||||
|
@ -1,5 +1,8 @@
|
||||
use crate::{
|
||||
comp::{inventory::slot::Slot, BuffKind},
|
||||
comp::{
|
||||
inventory::slot::{EquipSlot, Slot},
|
||||
BuffKind,
|
||||
},
|
||||
uid::Uid,
|
||||
util::Dir,
|
||||
};
|
||||
@ -24,25 +27,15 @@ pub enum InventoryManip {
|
||||
|
||||
#[derive(Clone, Copy, Debug, PartialEq, Serialize, Deserialize)]
|
||||
pub enum LoadoutManip {
|
||||
Swap(Slot, Slot),
|
||||
Drop(Slot),
|
||||
Swap(EquipSlot, Slot),
|
||||
Drop(EquipSlot),
|
||||
}
|
||||
|
||||
impl From<LoadoutManip> for InventoryManip {
|
||||
fn from(loadout_manip: LoadoutManip) -> Self {
|
||||
match loadout_manip {
|
||||
LoadoutManip::Swap(slot1, slot2) => Self::Swap(slot1, slot2),
|
||||
LoadoutManip::Drop(slot) => Self::Drop(slot),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl From<InventoryManip> for Option<LoadoutManip> {
|
||||
fn from(inv_manip: InventoryManip) -> Self {
|
||||
match inv_manip {
|
||||
InventoryManip::Swap(slot1, slot2) => Some(LoadoutManip::Swap(slot1, slot2)),
|
||||
InventoryManip::Drop(slot) => Some(LoadoutManip::Drop(slot)),
|
||||
_ => None,
|
||||
LoadoutManip::Swap(equip, slot) => Self::Swap(Slot::Equip(equip), slot),
|
||||
LoadoutManip::Drop(equip) => Self::Drop(Slot::Equip(equip)),
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -73,8 +66,8 @@ pub enum ControlEvent {
|
||||
|
||||
#[derive(Clone, Copy, Debug, PartialEq, Serialize, Deserialize)]
|
||||
pub enum ControlAction {
|
||||
SwapLoadout,
|
||||
ModifyLoadout(Option<LoadoutManip>),
|
||||
SwapEquippedWeapons,
|
||||
LoadoutManip(LoadoutManip),
|
||||
Wield,
|
||||
GlideWield,
|
||||
Unwield,
|
||||
|
@ -16,8 +16,8 @@ use specs_idvs::IdvStorage;
|
||||
pub trait CharacterBehavior {
|
||||
fn behavior(&self, data: &JoinData) -> StateUpdate;
|
||||
// Impl these to provide behavior for these inputs
|
||||
fn swap_loadout(&self, data: &JoinData) -> StateUpdate { StateUpdate::from(data) }
|
||||
fn modify_loadout(&self, data: &JoinData, _loadout_manip: Option<LoadoutManip>) -> StateUpdate {
|
||||
fn swap_equipped_weapons(&self, data: &JoinData) -> StateUpdate { StateUpdate::from(data) }
|
||||
fn manipulate_loadout(&self, data: &JoinData, _loadout_manip: LoadoutManip) -> StateUpdate {
|
||||
StateUpdate::from(data)
|
||||
}
|
||||
fn wield(&self, data: &JoinData) -> StateUpdate { StateUpdate::from(data) }
|
||||
@ -30,8 +30,10 @@ pub trait CharacterBehavior {
|
||||
fn talk(&self, data: &JoinData) -> StateUpdate { StateUpdate::from(data) }
|
||||
fn handle_event(&self, data: &JoinData, event: ControlAction) -> StateUpdate {
|
||||
match event {
|
||||
ControlAction::SwapLoadout => self.swap_loadout(data),
|
||||
ControlAction::ModifyLoadout(loadout_manip) => self.modify_loadout(data, loadout_manip),
|
||||
ControlAction::SwapEquippedWeapons => self.swap_equipped_weapons(data),
|
||||
ControlAction::LoadoutManip(loadout_manip) => {
|
||||
self.manipulate_loadout(data, loadout_manip)
|
||||
},
|
||||
ControlAction::Wield => self.wield(data),
|
||||
ControlAction::GlideWield => self.glide_wield(data),
|
||||
ControlAction::Unwield => self.unwield(data),
|
||||
|
@ -42,9 +42,9 @@ impl CharacterBehavior for Data {
|
||||
update
|
||||
}
|
||||
|
||||
fn modify_loadout(&self, data: &JoinData, loadout_manip: Option<LoadoutManip>) -> StateUpdate {
|
||||
fn manipulate_loadout(&self, data: &JoinData, loadout_manip: LoadoutManip) -> StateUpdate {
|
||||
let mut update = StateUpdate::from(data);
|
||||
handle_modify_loadout(&data, &mut update, loadout_manip);
|
||||
handle_manipulate_loadout(&data, &mut update, loadout_manip);
|
||||
update
|
||||
}
|
||||
}
|
||||
|
@ -69,9 +69,9 @@ impl CharacterBehavior for Data {
|
||||
update
|
||||
}
|
||||
|
||||
fn modify_loadout(&self, data: &JoinData, loadout_manip: Option<LoadoutManip>) -> StateUpdate {
|
||||
fn manipulate_loadout(&self, data: &JoinData, loadout_manip: LoadoutManip) -> StateUpdate {
|
||||
let mut update = StateUpdate::from(data);
|
||||
handle_modify_loadout(&data, &mut update, loadout_manip);
|
||||
handle_manipulate_loadout(&data, &mut update, loadout_manip);
|
||||
update
|
||||
}
|
||||
}
|
||||
|
@ -55,15 +55,15 @@ impl CharacterBehavior for Data {
|
||||
update
|
||||
}
|
||||
|
||||
fn swap_loadout(&self, data: &JoinData) -> StateUpdate {
|
||||
fn swap_equipped_weapons(&self, data: &JoinData) -> StateUpdate {
|
||||
let mut update = StateUpdate::from(data);
|
||||
attempt_swap_loadout(data, &mut update);
|
||||
attempt_swap_equipped_weapons(data, &mut update);
|
||||
update
|
||||
}
|
||||
|
||||
fn modify_loadout(&self, data: &JoinData, loadout_manip: Option<LoadoutManip>) -> StateUpdate {
|
||||
fn manipulate_loadout(&self, data: &JoinData, loadout_manip: LoadoutManip) -> StateUpdate {
|
||||
let mut update = StateUpdate::from(data);
|
||||
handle_modify_loadout(&data, &mut update, loadout_manip);
|
||||
handle_manipulate_loadout(&data, &mut update, loadout_manip);
|
||||
update
|
||||
}
|
||||
}
|
||||
|
@ -42,9 +42,9 @@ impl CharacterBehavior for Data {
|
||||
update
|
||||
}
|
||||
|
||||
fn modify_loadout(&self, data: &JoinData, loadout_manip: Option<LoadoutManip>) -> StateUpdate {
|
||||
fn manipulate_loadout(&self, data: &JoinData, loadout_manip: LoadoutManip) -> StateUpdate {
|
||||
let mut update = StateUpdate::from(data);
|
||||
handle_modify_loadout(&data, &mut update, loadout_manip);
|
||||
handle_manipulate_loadout(&data, &mut update, loadout_manip);
|
||||
update
|
||||
}
|
||||
}
|
||||
|
@ -48,9 +48,9 @@ impl CharacterBehavior for Data {
|
||||
update
|
||||
}
|
||||
|
||||
fn swap_loadout(&self, data: &JoinData) -> StateUpdate {
|
||||
fn swap_equipped_weapons(&self, data: &JoinData) -> StateUpdate {
|
||||
let mut update = StateUpdate::from(data);
|
||||
attempt_swap_loadout(data, &mut update);
|
||||
attempt_swap_equipped_weapons(data, &mut update);
|
||||
update
|
||||
}
|
||||
|
||||
@ -60,9 +60,9 @@ impl CharacterBehavior for Data {
|
||||
update
|
||||
}
|
||||
|
||||
fn modify_loadout(&self, data: &JoinData, loadout_manip: Option<LoadoutManip>) -> StateUpdate {
|
||||
fn manipulate_loadout(&self, data: &JoinData, loadout_manip: LoadoutManip) -> StateUpdate {
|
||||
let mut update = StateUpdate::from(data);
|
||||
handle_modify_loadout(&data, &mut update, loadout_manip);
|
||||
handle_manipulate_loadout(&data, &mut update, loadout_manip);
|
||||
update
|
||||
}
|
||||
}
|
||||
|
@ -47,9 +47,9 @@ impl CharacterBehavior for Data {
|
||||
update
|
||||
}
|
||||
|
||||
fn modify_loadout(&self, data: &JoinData, loadout_manip: Option<LoadoutManip>) -> StateUpdate {
|
||||
fn manipulate_loadout(&self, data: &JoinData, loadout_manip: LoadoutManip) -> StateUpdate {
|
||||
let mut update = StateUpdate::from(data);
|
||||
handle_modify_loadout(&data, &mut update, loadout_manip);
|
||||
handle_manipulate_loadout(&data, &mut update, loadout_manip);
|
||||
update
|
||||
}
|
||||
}
|
||||
|
@ -353,24 +353,22 @@ pub fn handle_climb(data: &JoinData, update: &mut StateUpdate) {
|
||||
}
|
||||
|
||||
/// Checks that player can Swap Weapons and updates `Loadout` if so
|
||||
pub fn attempt_swap_loadout(data: &JoinData, update: &mut StateUpdate) {
|
||||
pub fn attempt_swap_equipped_weapons(data: &JoinData, update: &mut StateUpdate) {
|
||||
if data.inventory.equipped(EquipSlot::Offhand).is_some() {
|
||||
update.swap_loadout = true;
|
||||
update.swap_equipped_weapons = true;
|
||||
}
|
||||
}
|
||||
|
||||
/// Handles inventory manipulations that affect the loadout
|
||||
pub fn handle_modify_loadout(
|
||||
pub fn handle_manipulate_loadout(
|
||||
data: &JoinData,
|
||||
update: &mut StateUpdate,
|
||||
loadout_manip: Option<LoadoutManip>,
|
||||
loadout_manip: LoadoutManip,
|
||||
) {
|
||||
if let Some(loadout_manip) = loadout_manip {
|
||||
update.server_events.push_front(ServerEvent::InventoryManip(
|
||||
data.entity,
|
||||
loadout_manip.into(),
|
||||
));
|
||||
}
|
||||
update.server_events.push_front(ServerEvent::InventoryManip(
|
||||
data.entity,
|
||||
loadout_manip.into(),
|
||||
));
|
||||
}
|
||||
|
||||
/// Checks that player can wield the glider and updates `CharacterState` if so
|
||||
|
@ -51,15 +51,15 @@ impl CharacterBehavior for Data {
|
||||
update
|
||||
}
|
||||
|
||||
fn swap_loadout(&self, data: &JoinData) -> StateUpdate {
|
||||
fn swap_equipped_weapons(&self, data: &JoinData) -> StateUpdate {
|
||||
let mut update = StateUpdate::from(data);
|
||||
attempt_swap_loadout(data, &mut update);
|
||||
attempt_swap_equipped_weapons(data, &mut update);
|
||||
update
|
||||
}
|
||||
|
||||
fn modify_loadout(&self, data: &JoinData, loadout_manip: Option<LoadoutManip>) -> StateUpdate {
|
||||
fn manipulate_loadout(&self, data: &JoinData, loadout_manip: LoadoutManip) -> StateUpdate {
|
||||
let mut update = StateUpdate::from(data);
|
||||
handle_modify_loadout(&data, &mut update, loadout_manip);
|
||||
handle_manipulate_loadout(&data, &mut update, loadout_manip);
|
||||
update
|
||||
}
|
||||
}
|
||||
|
@ -30,7 +30,7 @@ fn incorporate_update(tuple: &mut JoinTuple, state_update: StateUpdate) {
|
||||
if tuple.6.get_unchecked() != &state_update.energy {
|
||||
*tuple.6.get_mut_unchecked() = state_update.energy
|
||||
};
|
||||
if state_update.swap_loadout {
|
||||
if state_update.swap_equipped_weapons {
|
||||
let mut inventory = tuple.7.get_mut_unchecked();
|
||||
let inventory = &mut *inventory;
|
||||
inventory
|
||||
|
@ -1,5 +1,5 @@
|
||||
use common::{
|
||||
comp::{slot::Slot, BuffChange, ControlAction, ControlEvent, Controller, InventoryManip},
|
||||
comp::{BuffChange, ControlEvent, Controller},
|
||||
event::{EventBus, LocalEvent, ServerEvent},
|
||||
metrics::SysMetrics,
|
||||
resources::DeltaTime,
|
||||
@ -99,20 +99,7 @@ impl<'a> System<'a> for Sys {
|
||||
}
|
||||
},
|
||||
ControlEvent::InventoryManip(manip) => {
|
||||
// if an equipped slot is being changed, send a control action that the
|
||||
// loadout was modified
|
||||
match manip {
|
||||
InventoryManip::Drop(Slot::Equip(_))
|
||||
| InventoryManip::Swap(_, Slot::Equip(_))
|
||||
| InventoryManip::Swap(Slot::Equip(_), _) => {
|
||||
controller
|
||||
.actions
|
||||
.push(ControlAction::ModifyLoadout(manip.into()));
|
||||
},
|
||||
_ => {
|
||||
server_emitter.emit(ServerEvent::InventoryManip(entity, manip));
|
||||
},
|
||||
}
|
||||
server_emitter.emit(ServerEvent::InventoryManip(entity, manip));
|
||||
},
|
||||
ControlEvent::GroupManip(manip) => {
|
||||
server_emitter.emit(ServerEvent::GroupManip(entity, manip))
|
||||
|
Loading…
Reference in New Issue
Block a user