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:
@ -896,7 +896,8 @@ impl Client {
|
|||||||
.write_storage::<Controller>()
|
.write_storage::<Controller>()
|
||||||
.get_mut(self.entity)
|
.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));
|
self.send_msg(ClientGeneral::ControlAction(control_action));
|
||||||
}
|
}
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
use crate::{
|
use crate::{
|
||||||
combat::Attack,
|
combat::Attack,
|
||||||
comp::{Energy, Ori, Pos, Vel},
|
comp::{Energy, InventoryManip, Ori, Pos, Vel},
|
||||||
event::{LocalEvent, ServerEvent},
|
event::{LocalEvent, ServerEvent},
|
||||||
states::{behavior::JoinData, *},
|
states::{behavior::JoinData, *},
|
||||||
};
|
};
|
||||||
@ -17,6 +17,7 @@ pub struct StateUpdate {
|
|||||||
pub ori: Ori,
|
pub ori: Ori,
|
||||||
pub energy: Energy,
|
pub energy: Energy,
|
||||||
pub swap_loadout: bool,
|
pub swap_loadout: bool,
|
||||||
|
pub modify_loadout: Option<InventoryManip>,
|
||||||
pub local_events: VecDeque<LocalEvent>,
|
pub local_events: VecDeque<LocalEvent>,
|
||||||
pub server_events: VecDeque<ServerEvent>,
|
pub server_events: VecDeque<ServerEvent>,
|
||||||
}
|
}
|
||||||
@ -29,6 +30,7 @@ impl From<&JoinData<'_>> for StateUpdate {
|
|||||||
ori: *data.ori,
|
ori: *data.ori,
|
||||||
energy: *data.energy,
|
energy: *data.energy,
|
||||||
swap_loadout: false,
|
swap_loadout: false,
|
||||||
|
modify_loadout: None,
|
||||||
character: data.character.clone(),
|
character: data.character.clone(),
|
||||||
local_events: VecDeque::new(),
|
local_events: VecDeque::new(),
|
||||||
server_events: VecDeque::new(),
|
server_events: VecDeque::new(),
|
||||||
|
@ -46,9 +46,10 @@ pub enum ControlEvent {
|
|||||||
Respawn,
|
Respawn,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Clone, Copy, Debug, PartialEq, Serialize, Deserialize)]
|
#[derive(Clone, Debug, PartialEq, Serialize, Deserialize)]
|
||||||
pub enum ControlAction {
|
pub enum ControlAction {
|
||||||
SwapLoadout,
|
SwapLoadout,
|
||||||
|
ModifyLoadout(InventoryManip),
|
||||||
Wield,
|
Wield,
|
||||||
GlideWield,
|
GlideWield,
|
||||||
Unwield,
|
Unwield,
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
use crate::{
|
use crate::{
|
||||||
comp::{
|
comp::{
|
||||||
Beam, Body, CharacterState, ControlAction, Controller, ControllerInputs, Energy, Health,
|
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,
|
resources::DeltaTime,
|
||||||
uid::Uid,
|
uid::Uid,
|
||||||
@ -17,6 +17,9 @@ pub trait CharacterBehavior {
|
|||||||
fn behavior(&self, data: &JoinData) -> StateUpdate;
|
fn behavior(&self, data: &JoinData) -> StateUpdate;
|
||||||
// Impl these to provide behavior for these inputs
|
// Impl these to provide behavior for these inputs
|
||||||
fn swap_loadout(&self, data: &JoinData) -> StateUpdate { StateUpdate::from(data) }
|
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 wield(&self, data: &JoinData) -> StateUpdate { StateUpdate::from(data) }
|
||||||
fn glide_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) }
|
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 {
|
fn handle_event(&self, data: &JoinData, event: ControlAction) -> StateUpdate {
|
||||||
match event {
|
match event {
|
||||||
ControlAction::SwapLoadout => self.swap_loadout(data),
|
ControlAction::SwapLoadout => self.swap_loadout(data),
|
||||||
|
ControlAction::ModifyLoadout(inv_manip) => self.modify_loadout(data, inv_manip),
|
||||||
ControlAction::Wield => self.wield(data),
|
ControlAction::Wield => self.wield(data),
|
||||||
ControlAction::GlideWield => self.glide_wield(data),
|
ControlAction::GlideWield => self.glide_wield(data),
|
||||||
ControlAction::Unwield => self.unwield(data),
|
ControlAction::Unwield => self.unwield(data),
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
use super::utils::*;
|
use super::utils::*;
|
||||||
use crate::{
|
use crate::{
|
||||||
comp::StateUpdate,
|
comp::{InventoryManip, StateUpdate},
|
||||||
states::behavior::{CharacterBehavior, JoinData},
|
states::behavior::{CharacterBehavior, JoinData},
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -60,4 +60,10 @@ impl CharacterBehavior for Data {
|
|||||||
attempt_swap_loadout(data, &mut update);
|
attempt_swap_loadout(data, &mut update);
|
||||||
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},
|
item::{Hands, ItemKind, Tool, ToolKind},
|
||||||
quadruped_low, quadruped_medium,
|
quadruped_low, quadruped_medium,
|
||||||
skills::{AxeSkill, BowSkill, HammerSkill, Skill, StaffSkill, SwordSkill},
|
skills::{AxeSkill, BowSkill, HammerSkill, Skill, StaffSkill, SwordSkill},
|
||||||
theropod, Body, CharacterState, StateUpdate,
|
theropod, Body, CharacterState, InventoryManip, StateUpdate,
|
||||||
},
|
},
|
||||||
consts::{FRIC_GROUND, GRAVITY},
|
consts::{FRIC_GROUND, GRAVITY},
|
||||||
event::LocalEvent,
|
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
|
/// Checks that player can wield the glider and updates `CharacterState` if so
|
||||||
pub fn attempt_glide_wield(data: &JoinData, update: &mut StateUpdate) {
|
pub fn attempt_glide_wield(data: &JoinData, update: &mut StateUpdate) {
|
||||||
if data.inventory.equipped(EquipSlot::Glider).is_some()
|
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);
|
local_emitter.append(&mut state_update.local_events);
|
||||||
server_emitter.append(&mut state_update.server_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);
|
incorporate_update(&mut tuple, state_update);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1,8 +1,5 @@
|
|||||||
use common::{
|
use common::{
|
||||||
comp::{
|
comp::{slot::Slot, BuffChange, ControlAction, ControlEvent, Controller, InventoryManip},
|
||||||
slot::{EquipSlot, Slot},
|
|
||||||
BuffChange, CharacterState, ControlEvent, Controller, InventoryManip,
|
|
||||||
},
|
|
||||||
event::{EventBus, LocalEvent, ServerEvent},
|
event::{EventBus, LocalEvent, ServerEvent},
|
||||||
metrics::SysMetrics,
|
metrics::SysMetrics,
|
||||||
resources::DeltaTime,
|
resources::DeltaTime,
|
||||||
@ -30,7 +27,6 @@ impl<'a> System<'a> for Sys {
|
|||||||
Read<'a, DeltaTime>,
|
Read<'a, DeltaTime>,
|
||||||
ReadExpect<'a, SysMetrics>,
|
ReadExpect<'a, SysMetrics>,
|
||||||
WriteStorage<'a, Controller>,
|
WriteStorage<'a, Controller>,
|
||||||
WriteStorage<'a, CharacterState>,
|
|
||||||
ReadStorage<'a, Uid>,
|
ReadStorage<'a, Uid>,
|
||||||
);
|
);
|
||||||
|
|
||||||
@ -44,7 +40,6 @@ impl<'a> System<'a> for Sys {
|
|||||||
_dt,
|
_dt,
|
||||||
sys_metrics,
|
sys_metrics,
|
||||||
mut controllers,
|
mut controllers,
|
||||||
mut character_states,
|
|
||||||
uids,
|
uids,
|
||||||
): Self::SystemData,
|
): Self::SystemData,
|
||||||
) {
|
) {
|
||||||
@ -52,9 +47,7 @@ impl<'a> System<'a> for Sys {
|
|||||||
span!(_guard, "run", "controller::Sys::run");
|
span!(_guard, "run", "controller::Sys::run");
|
||||||
let mut server_emitter = server_bus.emitter();
|
let mut server_emitter = server_bus.emitter();
|
||||||
|
|
||||||
for (entity, _uid, controller, mut character_state) in
|
for (entity, _uid, controller) in (&entities, &uids, &mut controllers).join() {
|
||||||
(&entities, &uids, &mut controllers, &mut character_states).join()
|
|
||||||
{
|
|
||||||
let mut inputs = &mut controller.inputs;
|
let mut inputs = &mut controller.inputs;
|
||||||
|
|
||||||
// Note(imbris): I avoided incrementing the duration with inputs.tick() because
|
// Note(imbris): I avoided incrementing the duration with inputs.tick() because
|
||||||
@ -106,19 +99,18 @@ impl<'a> System<'a> for Sys {
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
ControlEvent::InventoryManip(manip) => {
|
ControlEvent::InventoryManip(manip) => {
|
||||||
// Unwield if a wielded equipment slot is being modified, to avoid entering
|
// if an equipped slot is being changed, send a control action that the
|
||||||
// a barehanded wielding state.
|
// loadout was modified
|
||||||
if character_state.is_wield() {
|
match manip {
|
||||||
match manip {
|
InventoryManip::Drop(Slot::Equip(_))
|
||||||
InventoryManip::Drop(Slot::Equip(EquipSlot::Mainhand))
|
| InventoryManip::Swap(_, Slot::Equip(_))
|
||||||
| InventoryManip::Swap(_, Slot::Equip(EquipSlot::Mainhand))
|
| InventoryManip::Swap(Slot::Equip(_), _) => {
|
||||||
| InventoryManip::Swap(Slot::Equip(EquipSlot::Mainhand), _) => {
|
controller.actions.push(ControlAction::ModifyLoadout(manip));
|
||||||
*character_state = CharacterState::Idle;
|
},
|
||||||
},
|
_ => {
|
||||||
_ => (),
|
server_emitter.emit(ServerEvent::InventoryManip(entity, manip));
|
||||||
}
|
},
|
||||||
}
|
}
|
||||||
server_emitter.emit(ServerEvent::InventoryManip(entity, manip))
|
|
||||||
},
|
},
|
||||||
ControlEvent::GroupManip(manip) => {
|
ControlEvent::GroupManip(manip) => {
|
||||||
server_emitter.emit(ServerEvent::GroupManip(entity, manip))
|
server_emitter.emit(ServerEvent::GroupManip(entity, manip))
|
||||||
|
Reference in New Issue
Block a user