mirror of
https://gitlab.com/veloren/veloren.git
synced 2024-08-30 18:12:32 +00:00
Inventory changes that modify the loadout now go through a control action instead of a control event.
This commit is contained in:
parent
bcc9c2058c
commit
8eebcdfcd2
@ -896,7 +896,8 @@ impl Client {
|
||||
.write_storage::<Controller>()
|
||||
.get_mut(self.entity)
|
||||
{
|
||||
controller.actions.push(control_action);
|
||||
// TODO: Undo this clone, somehow...
|
||||
controller.actions.push(control_action.clone());
|
||||
}
|
||||
self.send_msg(ClientGeneral::ControlAction(control_action));
|
||||
}
|
||||
|
@ -1,6 +1,6 @@
|
||||
use crate::{
|
||||
combat::Attack,
|
||||
comp::{Energy, Ori, Pos, Vel},
|
||||
comp::{Energy, InventoryManip, Ori, Pos, Vel},
|
||||
event::{LocalEvent, ServerEvent},
|
||||
states::{behavior::JoinData, *},
|
||||
};
|
||||
@ -17,6 +17,7 @@ pub struct StateUpdate {
|
||||
pub ori: Ori,
|
||||
pub energy: Energy,
|
||||
pub swap_loadout: bool,
|
||||
pub modify_loadout: Option<InventoryManip>,
|
||||
pub local_events: VecDeque<LocalEvent>,
|
||||
pub server_events: VecDeque<ServerEvent>,
|
||||
}
|
||||
@ -29,6 +30,7 @@ impl From<&JoinData<'_>> for StateUpdate {
|
||||
ori: *data.ori,
|
||||
energy: *data.energy,
|
||||
swap_loadout: false,
|
||||
modify_loadout: None,
|
||||
character: data.character.clone(),
|
||||
local_events: VecDeque::new(),
|
||||
server_events: VecDeque::new(),
|
||||
|
@ -46,9 +46,10 @@ pub enum ControlEvent {
|
||||
Respawn,
|
||||
}
|
||||
|
||||
#[derive(Clone, Copy, Debug, PartialEq, Serialize, Deserialize)]
|
||||
#[derive(Clone, Debug, PartialEq, Serialize, Deserialize)]
|
||||
pub enum ControlAction {
|
||||
SwapLoadout,
|
||||
ModifyLoadout(InventoryManip),
|
||||
Wield,
|
||||
GlideWield,
|
||||
Unwield,
|
||||
|
@ -1,7 +1,7 @@
|
||||
use crate::{
|
||||
comp::{
|
||||
Beam, Body, CharacterState, ControlAction, Controller, ControllerInputs, Energy, Health,
|
||||
Inventory, Melee, Ori, PhysicsState, Pos, StateUpdate, Stats, Vel,
|
||||
Inventory, InventoryManip, Melee, Ori, PhysicsState, Pos, StateUpdate, Stats, Vel,
|
||||
},
|
||||
resources::DeltaTime,
|
||||
uid::Uid,
|
||||
@ -17,6 +17,9 @@ 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, _inv_manip: InventoryManip) -> StateUpdate {
|
||||
StateUpdate::from(data)
|
||||
}
|
||||
fn wield(&self, data: &JoinData) -> StateUpdate { StateUpdate::from(data) }
|
||||
fn glide_wield(&self, data: &JoinData) -> StateUpdate { StateUpdate::from(data) }
|
||||
fn unwield(&self, data: &JoinData) -> StateUpdate { StateUpdate::from(data) }
|
||||
@ -28,6 +31,7 @@ pub trait CharacterBehavior {
|
||||
fn handle_event(&self, data: &JoinData, event: ControlAction) -> StateUpdate {
|
||||
match event {
|
||||
ControlAction::SwapLoadout => self.swap_loadout(data),
|
||||
ControlAction::ModifyLoadout(inv_manip) => self.modify_loadout(data, inv_manip),
|
||||
ControlAction::Wield => self.wield(data),
|
||||
ControlAction::GlideWield => self.glide_wield(data),
|
||||
ControlAction::Unwield => self.unwield(data),
|
||||
|
@ -1,6 +1,6 @@
|
||||
use super::utils::*;
|
||||
use crate::{
|
||||
comp::StateUpdate,
|
||||
comp::{InventoryManip, StateUpdate},
|
||||
states::behavior::{CharacterBehavior, JoinData},
|
||||
};
|
||||
|
||||
@ -60,4 +60,10 @@ impl CharacterBehavior for Data {
|
||||
attempt_swap_loadout(data, &mut update);
|
||||
update
|
||||
}
|
||||
|
||||
fn modify_loadout(&self, data: &JoinData, inv_manip: InventoryManip) -> StateUpdate {
|
||||
let mut update = StateUpdate::from(data);
|
||||
handle_modify_loadout(&mut update, inv_manip);
|
||||
update
|
||||
}
|
||||
}
|
||||
|
@ -4,7 +4,7 @@ use crate::{
|
||||
item::{Hands, ItemKind, Tool, ToolKind},
|
||||
quadruped_low, quadruped_medium,
|
||||
skills::{AxeSkill, BowSkill, HammerSkill, Skill, StaffSkill, SwordSkill},
|
||||
theropod, Body, CharacterState, StateUpdate,
|
||||
theropod, Body, CharacterState, InventoryManip, StateUpdate,
|
||||
},
|
||||
consts::{FRIC_GROUND, GRAVITY},
|
||||
event::LocalEvent,
|
||||
@ -359,6 +359,11 @@ pub fn attempt_swap_loadout(data: &JoinData, update: &mut StateUpdate) {
|
||||
}
|
||||
}
|
||||
|
||||
/// Handles inventory manipulations that affect the loadout
|
||||
pub fn handle_modify_loadout(update: &mut StateUpdate, inv_manip: InventoryManip) {
|
||||
update.modify_loadout = Some(inv_manip);
|
||||
}
|
||||
|
||||
/// Checks that player can wield the glider and updates `CharacterState` if so
|
||||
pub fn attempt_glide_wield(data: &JoinData, update: &mut StateUpdate) {
|
||||
if data.inventory.equipped(EquipSlot::Glider).is_some()
|
||||
|
@ -268,6 +268,10 @@ impl<'a> System<'a> for Sys {
|
||||
};
|
||||
local_emitter.append(&mut state_update.local_events);
|
||||
server_emitter.append(&mut state_update.server_events);
|
||||
if let Some(ref inv_manip) = state_update.modify_loadout {
|
||||
// TODO: Delete this clone, somehow...
|
||||
server_emitter.emit(ServerEvent::InventoryManip(j.entity, inv_manip.clone()));
|
||||
}
|
||||
incorporate_update(&mut tuple, state_update);
|
||||
}
|
||||
|
||||
|
@ -1,8 +1,5 @@
|
||||
use common::{
|
||||
comp::{
|
||||
slot::{EquipSlot, Slot},
|
||||
BuffChange, CharacterState, ControlEvent, Controller, InventoryManip,
|
||||
},
|
||||
comp::{slot::Slot, BuffChange, ControlAction, ControlEvent, Controller, InventoryManip},
|
||||
event::{EventBus, LocalEvent, ServerEvent},
|
||||
metrics::SysMetrics,
|
||||
resources::DeltaTime,
|
||||
@ -30,7 +27,6 @@ impl<'a> System<'a> for Sys {
|
||||
Read<'a, DeltaTime>,
|
||||
ReadExpect<'a, SysMetrics>,
|
||||
WriteStorage<'a, Controller>,
|
||||
WriteStorage<'a, CharacterState>,
|
||||
ReadStorage<'a, Uid>,
|
||||
);
|
||||
|
||||
@ -44,7 +40,6 @@ impl<'a> System<'a> for Sys {
|
||||
_dt,
|
||||
sys_metrics,
|
||||
mut controllers,
|
||||
mut character_states,
|
||||
uids,
|
||||
): Self::SystemData,
|
||||
) {
|
||||
@ -52,9 +47,7 @@ impl<'a> System<'a> for Sys {
|
||||
span!(_guard, "run", "controller::Sys::run");
|
||||
let mut server_emitter = server_bus.emitter();
|
||||
|
||||
for (entity, _uid, controller, mut character_state) in
|
||||
(&entities, &uids, &mut controllers, &mut character_states).join()
|
||||
{
|
||||
for (entity, _uid, controller) in (&entities, &uids, &mut controllers).join() {
|
||||
let mut inputs = &mut controller.inputs;
|
||||
|
||||
// Note(imbris): I avoided incrementing the duration with inputs.tick() because
|
||||
@ -106,19 +99,18 @@ impl<'a> System<'a> for Sys {
|
||||
}
|
||||
},
|
||||
ControlEvent::InventoryManip(manip) => {
|
||||
// Unwield if a wielded equipment slot is being modified, to avoid entering
|
||||
// a barehanded wielding state.
|
||||
if character_state.is_wield() {
|
||||
match manip {
|
||||
InventoryManip::Drop(Slot::Equip(EquipSlot::Mainhand))
|
||||
| InventoryManip::Swap(_, Slot::Equip(EquipSlot::Mainhand))
|
||||
| InventoryManip::Swap(Slot::Equip(EquipSlot::Mainhand), _) => {
|
||||
*character_state = CharacterState::Idle;
|
||||
},
|
||||
_ => (),
|
||||
}
|
||||
// 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));
|
||||
},
|
||||
_ => {
|
||||
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