From c6d8daaae39b87cb5ebb4fc6cc23e8486e941651 Mon Sep 17 00:00:00 2001 From: Sam Date: Fri, 5 Mar 2021 01:09:56 -0500 Subject: [PATCH 1/7] Primary input now activated from control actions. Moved a lot of key_state to a HashSet so that it is handled automatically. --- client/src/lib.rs | 16 +- common/src/comp/character_state.rs | 6 +- common/src/comp/controller.rs | 35 +- common/src/comp/mod.rs | 2 +- common/src/states/basic_block.rs | 4 +- common/src/states/behavior.rs | 14 +- common/src/states/utils.rs | 26 +- common/src/states/wielding.rs | 17 +- common/sys/src/character_behavior.rs | 4 + server/src/sys/agent.rs | 133 ++++-- voxygen/src/key_state.rs | 18 - voxygen/src/session.rs | 580 +++++++++++++-------------- 12 files changed, 488 insertions(+), 367 deletions(-) diff --git a/client/src/lib.rs b/client/src/lib.rs index 5377600805..c98ab89829 100644 --- a/client/src/lib.rs +++ b/client/src/lib.rs @@ -26,7 +26,7 @@ use common::{ invite::{InviteKind, InviteResponse}, skills::Skill, slot::Slot, - ChatMode, ControlAction, ControlEvent, Controller, ControllerInputs, GroupManip, + ChatMode, ControlAction, ControlEvent, Controller, ControllerInputs, GroupManip, InputKind, InventoryAction, InventoryEvent, InventoryUpdateEvent, }, event::{EventBus, LocalEvent}, @@ -60,7 +60,7 @@ use num::traits::FloatConst; use rayon::prelude::*; use specs::Component; use std::{ - collections::VecDeque, + collections::{BTreeSet, VecDeque}, sync::Arc, time::{Duration, Instant}, }; @@ -991,6 +991,17 @@ impl Client { } } + pub fn handle_input(&mut self, input: InputKind, pressed: bool) { + if pressed { + self.control_action(ControlAction::StartInput { + ability: input, + target: None, + }); + } else { + self.control_action(ControlAction::CancelInput); + } + } + fn control_action(&mut self, control_action: ControlAction) { if let Some(controller) = self .state @@ -1133,6 +1144,7 @@ impl Client { entry .or_insert_with(|| Controller { inputs: inputs.clone(), + queued_inputs: BTreeSet::new(), events: Vec::new(), actions: Vec::new(), }) diff --git a/common/src/comp/character_state.rs b/common/src/comp/character_state.rs index 89df35baa7..33eb2752d6 100644 --- a/common/src/comp/character_state.rs +++ b/common/src/comp/character_state.rs @@ -1,13 +1,13 @@ use crate::{ combat::Attack, - comp::{Energy, Ori, Pos, Vel}, + comp::{Energy, InputKind, Ori, Pos, Vel}, event::{LocalEvent, ServerEvent}, states::{behavior::JoinData, *}, }; use serde::{Deserialize, Serialize}; use specs::{Component, DerefFlaggedStorage, VecStorage}; use specs_idvs::IdvStorage; -use std::collections::VecDeque; +use std::collections::{BTreeSet, VecDeque}; /// Data returned from character behavior fn's to Character Behavior System. pub struct StateUpdate { @@ -17,6 +17,7 @@ pub struct StateUpdate { pub ori: Ori, pub energy: Energy, pub swap_equipped_weapons: bool, + pub queued_inputs: BTreeSet, pub local_events: VecDeque, pub server_events: VecDeque, } @@ -30,6 +31,7 @@ impl From<&JoinData<'_>> for StateUpdate { energy: *data.energy, swap_equipped_weapons: false, character: data.character.clone(), + queued_inputs: BTreeSet::new(), local_events: VecDeque::new(), server_events: VecDeque::new(), } diff --git a/common/src/comp/controller.rs b/common/src/comp/controller.rs index 000c13de57..bdd32b95ef 100644 --- a/common/src/comp/controller.rs +++ b/common/src/comp/controller.rs @@ -11,7 +11,7 @@ use crate::{ use serde::{Deserialize, Serialize}; use specs::{Component, DerefFlaggedStorage}; use specs_idvs::IdvStorage; -use std::time::Duration; +use std::{collections::BTreeSet, time::Duration}; use vek::*; /// Default duration before an input is considered 'held'. @@ -111,6 +111,24 @@ pub enum ControlAction { Sneak, Stand, Talk, + StartInput { + ability: InputKind, + target: Option, + }, + CancelInput, +} + +#[derive(Clone, Copy, Debug, PartialEq, Serialize, Deserialize, Eq, Ord, PartialOrd)] +#[repr(u32)] +pub enum InputKind { + Primary = 0, + /* Secondary = 1, + * Ability(usize) = 2, + * Jump = 3, + * Roll = 4, + * Glide = 5, + * Fly = 6, + * WallLeap = 7, */ } #[derive(Copy, Clone, Debug, PartialEq, Serialize, Deserialize)] @@ -225,7 +243,7 @@ pub enum Climb { #[derive(Clone, Debug, Default, PartialEq, Serialize, Deserialize)] pub struct ControllerInputs { - pub primary: Input, + //pub primary: Input, pub secondary: Input, pub ability3: Input, pub ability4: Input, @@ -245,6 +263,7 @@ pub struct ControllerInputs { #[derive(Clone, Debug, Default, PartialEq, Serialize, Deserialize)] pub struct Controller { pub inputs: ControllerInputs, + pub queued_inputs: BTreeSet, // TODO: consider SmallVec pub events: Vec, pub actions: Vec, @@ -253,7 +272,7 @@ pub struct Controller { impl ControllerInputs { /// Updates all inputs, accounting for delta time pub fn tick(&mut self, dt: Duration) { - self.primary.tick(dt); + //self.primary.tick(dt); self.secondary.tick(dt); self.ability3.tick(dt); self.ability4.tick(dt); @@ -266,7 +285,7 @@ impl ControllerInputs { } pub fn tick_freshness(&mut self) { - self.primary.tick_freshness(); + //self.primary.tick_freshness(); self.secondary.tick_freshness(); self.ability3.tick_freshness(); self.ability4.tick_freshness(); @@ -280,7 +299,7 @@ impl ControllerInputs { /// Updates Controller inputs with new version received from the client pub fn update_with_new(&mut self, new: Self) { - self.primary.update_with_new(new.primary); + //self.primary.update_with_new(new.primary); self.secondary.update_with_new(new.secondary); self.ability3.update_with_new(new.ability3); self.ability4.update_with_new(new.ability4); @@ -297,10 +316,8 @@ impl ControllerInputs { } pub fn holding_ability_key(&self) -> bool { - self.primary.is_pressed() - || self.secondary.is_pressed() - || self.ability3.is_pressed() - || self.ability4.is_pressed() + //self.primary.is_pressed() || + self.secondary.is_pressed() || self.ability3.is_pressed() || self.ability4.is_pressed() } } diff --git a/common/src/comp/mod.rs b/common/src/comp/mod.rs index 420f16fea4..e586e851ed 100644 --- a/common/src/comp/mod.rs +++ b/common/src/comp/mod.rs @@ -62,7 +62,7 @@ pub use self::{ combo::Combo, controller::{ Climb, ControlAction, ControlEvent, Controller, ControllerInputs, GroupManip, Input, - InventoryAction, InventoryEvent, InventoryManip, MountState, Mounting, + InputKind, InventoryAction, InventoryEvent, InventoryManip, MountState, Mounting, }, energy::{Energy, EnergyChange, EnergySource}, group::Group, diff --git a/common/src/states/basic_block.rs b/common/src/states/basic_block.rs index a4d56687b9..487d9a6eb6 100644 --- a/common/src/states/basic_block.rs +++ b/common/src/states/basic_block.rs @@ -17,9 +17,7 @@ impl CharacterBehavior for Data { handle_move(&data, &mut update, 0.4); - if !data.physics.on_ground - || !(data.inputs.secondary.is_pressed() || data.inputs.primary.is_pressed()) - { + if !data.physics.on_ground || !data.inputs.secondary.is_pressed() { attempt_wield(data, &mut update); } update diff --git a/common/src/states/behavior.rs b/common/src/states/behavior.rs index cbc31ec5de..9cb467c79f 100644 --- a/common/src/states/behavior.rs +++ b/common/src/states/behavior.rs @@ -1,8 +1,8 @@ use crate::{ comp::{ item::MaterialStatManifest, Beam, Body, CharacterState, Combo, ControlAction, Controller, - ControllerInputs, Energy, Health, Inventory, InventoryAction, Melee, Ori, PhysicsState, - Pos, StateUpdate, Stats, Vel, + ControllerInputs, Energy, Health, InputKind, Inventory, InventoryAction, Melee, Ori, + PhysicsState, Pos, StateUpdate, Stats, Vel, }, resources::DeltaTime, uid::Uid, @@ -29,6 +29,12 @@ pub trait CharacterBehavior { fn sneak(&self, data: &JoinData) -> StateUpdate { StateUpdate::from(data) } fn stand(&self, data: &JoinData) -> StateUpdate { StateUpdate::from(data) } fn talk(&self, data: &JoinData) -> StateUpdate { StateUpdate::from(data) } + fn handle_input(&self, data: &JoinData, input: InputKind, _target: Option) -> StateUpdate { + let mut update = StateUpdate::from(data); + update.queued_inputs.insert(input); + update + } + fn cancel_input(&self, data: &JoinData) -> StateUpdate { StateUpdate::from(data) } fn handle_event(&self, data: &JoinData, event: ControlAction) -> StateUpdate { match event { ControlAction::SwapEquippedWeapons => self.swap_equipped_weapons(data), @@ -41,6 +47,10 @@ pub trait CharacterBehavior { ControlAction::Sneak => self.sneak(data), ControlAction::Stand => self.stand(data), ControlAction::Talk => self.talk(data), + ControlAction::StartInput { ability, target } => { + self.handle_input(data, ability, target) + }, + ControlAction::CancelInput => self.cancel_input(data), } } // fn init(data: &JoinData) -> CharacterState; diff --git a/common/src/states/utils.rs b/common/src/states/utils.rs index fef074dd46..eac9496cd5 100644 --- a/common/src/states/utils.rs +++ b/common/src/states/utils.rs @@ -5,7 +5,7 @@ use crate::{ item::{Hands, ItemKind, Tool, ToolKind}, quadruped_low, quadruped_medium, quadruped_small, skills::Skill, - theropod, Body, CharacterAbility, CharacterState, InventoryAction, StateUpdate, + theropod, Body, CharacterAbility, CharacterState, InputKind, InventoryAction, StateUpdate, }, consts::{FRIC_GROUND, GRAVITY}, event::{LocalEvent, ServerEvent}, @@ -314,8 +314,10 @@ fn fly_move(data: &JoinData, update: &mut StateUpdate, efficiency: f32) { /// First checks whether `primary`, `secondary`, `ability3`, or `ability4` input /// is pressed, then attempts to go into Equipping state, otherwise Idle pub fn handle_wield(data: &JoinData, update: &mut StateUpdate) { - if data.inputs.primary.is_pressed() - || data.inputs.secondary.is_pressed() + if + /*data.inputs.primary.is_pressed() + || */ + data.inputs.secondary.is_pressed() || data.inputs.ability3.is_pressed() || data.inputs.ability4.is_pressed() { @@ -489,11 +491,17 @@ fn handle_ability_pressed(data: &JoinData, update: &mut StateUpdate, ability_key } } -pub fn handle_ability1_input(data: &JoinData, update: &mut StateUpdate) { +pub fn handle_input(data: &JoinData, update: &mut StateUpdate, input: InputKind) { + match input { + InputKind::Primary => handle_ability_pressed(data, update, AbilityKey::Mouse1), + } +} + +/*pub fn handle_ability1_input(data: &JoinData, update: &mut StateUpdate) { if data.inputs.primary.is_pressed() { handle_ability_pressed(data, update, AbilityKey::Mouse1); } -} +}*/ pub fn handle_ability2_input(data: &JoinData, update: &mut StateUpdate) { if data.inputs.secondary.is_pressed() { @@ -595,7 +603,7 @@ pub fn get_crit_data(data: &JoinData, ai: AbilityInfo) -> (f32, f32) { pub fn handle_interrupt(data: &JoinData, update: &mut StateUpdate, attacks_interrupt: bool) { if attacks_interrupt { - handle_ability1_input(data, update); + //handle_ability1_input(data, update); handle_ability2_input(data, update); handle_ability3_input(data, update); handle_ability4_input(data, update); @@ -605,7 +613,11 @@ pub fn handle_interrupt(data: &JoinData, update: &mut StateUpdate, attacks_inter pub fn ability_key_is_pressed(data: &JoinData, ability_key: AbilityKey) -> bool { match ability_key { - AbilityKey::Mouse1 => data.inputs.primary.is_pressed(), + AbilityKey::Mouse1 => + /* data.inputs.primary.is_pressed() */ + { + false + }, AbilityKey::Mouse2 => data.inputs.secondary.is_pressed(), AbilityKey::Skill1 => data.inputs.ability3.is_pressed(), AbilityKey::Skill2 => data.inputs.ability4.is_pressed(), diff --git a/common/src/states/wielding.rs b/common/src/states/wielding.rs index d0a67f9ec9..0bc4c069c9 100644 --- a/common/src/states/wielding.rs +++ b/common/src/states/wielding.rs @@ -2,9 +2,10 @@ use super::utils::*; use crate::{ comp::{ slot::{EquipSlot, Slot}, - CharacterState, InventoryAction, StateUpdate, + CharacterState, InputKind, InventoryAction, StateUpdate, }, states::behavior::{CharacterBehavior, JoinData}, + uid::Uid, }; pub struct Data; @@ -16,7 +17,7 @@ impl CharacterBehavior for Data { handle_move(&data, &mut update, 1.0); handle_jump(&data, &mut update); handle_climb(&data, &mut update); - handle_ability1_input(&data, &mut update); + //handle_ability1_input(&data, &mut update); handle_ability2_input(&data, &mut update); handle_ability3_input(&data, &mut update); handle_ability4_input(&data, &mut update); @@ -25,6 +26,18 @@ impl CharacterBehavior for Data { update } + fn handle_input( + &self, + data: &JoinData, + ability: InputKind, + _target: Option, + ) -> StateUpdate { + let mut update = StateUpdate::from(data); + handle_input(&data, &mut update, ability); + + update + } + fn sit(&self, data: &JoinData) -> StateUpdate { let mut update = StateUpdate::from(data); attempt_sit(data, &mut update); diff --git a/common/sys/src/character_behavior.rs b/common/sys/src/character_behavior.rs index e68da90340..1c438729e0 100644 --- a/common/sys/src/character_behavior.rs +++ b/common/sys/src/character_behavior.rs @@ -350,6 +350,10 @@ impl<'a> System<'a> for Sys { local_emitter.append(&mut state_update.local_events); server_emitter.append(&mut state_update.server_events); + join_struct + .controller + .queued_inputs + .append(&mut state_update.queued_inputs); incorporate_update(&mut join_struct, state_update); } } diff --git a/server/src/sys/agent.rs b/server/src/sys/agent.rs index daef971747..4d48e29051 100644 --- a/server/src/sys/agent.rs +++ b/server/src/sys/agent.rs @@ -11,8 +11,8 @@ use common::{ }, skills::{AxeSkill, BowSkill, HammerSkill, Skill, StaffSkill, SwordSkill}, Agent, Alignment, Body, CharacterState, ControlAction, ControlEvent, Controller, Energy, - Health, Inventory, LightEmitter, MountState, Ori, PhysicsState, Pos, Scale, Stats, - UnresolvedChatMsg, Vel, + Health, InputKind, Inventory, LightEmitter, MountState, Ori, PhysicsState, Pos, Scale, + Stats, UnresolvedChatMsg, Vel, }, event::{Emitter, EventBus, ServerEvent}, path::TraversalConfig, @@ -1081,7 +1081,11 @@ impl<'a> AgentData<'a> { match tactic { Tactic::Melee => { if dist_sqrd < (min_attack_dist * self.scale).powi(2) { - controller.inputs.primary.set_state(true); + controller.actions.push(ControlAction::StartInput { + ability: InputKind::Primary, + target: None, + }); + //controller.inputs.primary.set_state(true); controller.inputs.move_dir = Vec2::zero(); } else if dist_sqrd < MAX_CHASE_DIST.powi(2) { if let Some((bearing, speed)) = agent.chaser.chase( @@ -1129,7 +1133,11 @@ impl<'a> AgentData<'a> { controller.inputs.ability3.set_state(true); agent.action_timer += dt.0; } else { - controller.inputs.primary.set_state(true); + controller.actions.push(ControlAction::StartInput { + ability: InputKind::Primary, + target: None, + }); + //controller.inputs.primary.set_state(true); agent.action_timer += dt.0; } } else if dist_sqrd < MAX_CHASE_DIST.powi(2) { @@ -1177,7 +1185,11 @@ impl<'a> AgentData<'a> { controller.inputs.ability3.set_state(true); agent.action_timer += dt.0; } else { - controller.inputs.primary.set_state(true); + controller.actions.push(ControlAction::StartInput { + ability: InputKind::Primary, + target: None, + }); + //controller.inputs.primary.set_state(true); agent.action_timer += dt.0; } } else if dist_sqrd < MAX_CHASE_DIST.powi(2) { @@ -1237,7 +1249,11 @@ impl<'a> AgentData<'a> { } else if agent.action_timer > 2.0 { agent.action_timer = 0.0; } else { - controller.inputs.primary.set_state(true); + controller.actions.push(ControlAction::StartInput { + ability: InputKind::Primary, + target: None, + }); + //controller.inputs.primary.set_state(true); agent.action_timer += dt.0; } } else if dist_sqrd < MAX_CHASE_DIST.powi(2) { @@ -1318,7 +1334,11 @@ impl<'a> AgentData<'a> { agent.action_timer += dt.0; } else { controller.inputs.secondary.set_state(false); - controller.inputs.primary.set_state(true); + controller.actions.push(ControlAction::StartInput { + ability: InputKind::Primary, + target: None, + }); + //controller.inputs.primary.set_state(true); agent.action_timer += dt.0; } } else { @@ -1388,7 +1408,11 @@ impl<'a> AgentData<'a> { } else if self.energy.current() > 10 { controller.inputs.secondary.set_state(true); } else { - controller.inputs.primary.set_state(true); + controller.actions.push(ControlAction::StartInput { + ability: InputKind::Primary, + target: None, + }); + //controller.inputs.primary.set_state(true); } } else if dist_sqrd < MAX_CHASE_DIST.powi(2) { if let Some((bearing, speed)) = agent.chaser.chase( @@ -1408,7 +1432,11 @@ impl<'a> AgentData<'a> { .try_normalized() .unwrap_or_else(Vec2::zero) * speed; - controller.inputs.primary.set_state(true); + controller.actions.push(ControlAction::StartInput { + ability: InputKind::Primary, + target: None, + }); + //controller.inputs.primary.set_state(true); } else { controller.inputs.move_dir = bearing.xy().try_normalized().unwrap_or_else(Vec2::zero) * speed; @@ -1447,7 +1475,11 @@ impl<'a> AgentData<'a> { // 2.0 is temporary correction factor to allow them to melee with their // large hitbox controller.inputs.move_dir = Vec2::zero(); - controller.inputs.primary.set_state(true); + controller.actions.push(ControlAction::StartInput { + ability: InputKind::Primary, + target: None, + }); + //controller.inputs.primary.set_state(true); } else if dist_sqrd < MAX_CHASE_DIST.powi(2) { if self.vel.0.is_approx_zero() { controller.inputs.ability3.set_state(true); @@ -1489,7 +1521,11 @@ impl<'a> AgentData<'a> { if dist_sqrd < (min_attack_dist * self.scale).powi(2) && thread_rng().gen_bool(0.5) { controller.inputs.move_dir = Vec2::zero(); - controller.inputs.primary.set_state(true); + controller.actions.push(ControlAction::StartInput { + ability: InputKind::Primary, + target: None, + }); + //controller.inputs.primary.set_state(true); } else if dist_sqrd < (radius as f32 * min_attack_dist * self.scale).powi(2) { controller.inputs.move_dir = (self.pos.0 - tgt_pos.0) .xy() @@ -1547,7 +1583,11 @@ impl<'a> AgentData<'a> { .xy() .try_normalized() .unwrap_or_else(Vec2::unit_y); - controller.inputs.primary.set_state(true); + controller.actions.push(ControlAction::StartInput { + ability: InputKind::Primary, + target: None, + }); + //controller.inputs.primary.set_state(true); } else if dist_sqrd < MAX_CHASE_DIST.powi(2) { if let Some((bearing, speed)) = agent.chaser.chase( &*terrain, @@ -1598,10 +1638,15 @@ impl<'a> AgentData<'a> { Tactic::TailSlap => { if dist_sqrd < (1.5 * min_attack_dist * self.scale).powi(2) { if agent.action_timer > 4.0 { - controller.inputs.primary.set_state(false); + controller.actions.push(ControlAction::CancelInput); + //controller.inputs.primary.set_state(false); agent.action_timer = 0.0; } else if agent.action_timer > 1.0 { - controller.inputs.primary.set_state(true); + controller.actions.push(ControlAction::StartInput { + ability: InputKind::Primary, + target: None, + }); + //controller.inputs.primary.set_state(true); agent.action_timer += dt.0; } else { controller.inputs.secondary.set_state(true); @@ -1639,7 +1684,11 @@ impl<'a> AgentData<'a> { } else if dist_sqrd < (3.0 * min_attack_dist * self.scale).powi(2) && dist_sqrd > (2.0 * min_attack_dist * self.scale).powi(2) { - controller.inputs.primary.set_state(true); + controller.actions.push(ControlAction::StartInput { + ability: InputKind::Primary, + target: None, + }); + //controller.inputs.primary.set_state(true); controller.inputs.move_dir = (tgt_pos.0 - self.pos.0) .xy() .rotated_z(-0.47 * PI) @@ -1674,7 +1723,11 @@ impl<'a> AgentData<'a> { controller.inputs.secondary.set_state(true); agent.action_timer += dt.0; } else { - controller.inputs.primary.set_state(true); + controller.actions.push(ControlAction::StartInput { + ability: InputKind::Primary, + target: None, + }); + //controller.inputs.primary.set_state(true); agent.action_timer += dt.0; } } else if dist_sqrd < MAX_CHASE_DIST.powi(2) { @@ -1715,7 +1768,11 @@ impl<'a> AgentData<'a> { }, ) { if can_see_tgt(&*terrain, self.pos, tgt_pos, dist_sqrd) { - controller.inputs.primary.set_state(true); + controller.actions.push(ControlAction::StartInput { + ability: InputKind::Primary, + target: None, + }); + //controller.inputs.primary.set_state(true); controller.inputs.move_dir = bearing.xy().try_normalized().unwrap_or_else(Vec2::zero) * speed; } else { @@ -1736,7 +1793,11 @@ impl<'a> AgentData<'a> { controller.inputs.secondary.set_state(true); agent.action_timer += dt.0; } else if agent.action_timer < 3.0 { - controller.inputs.primary.set_state(true); + controller.actions.push(ControlAction::StartInput { + ability: InputKind::Primary, + target: None, + }); + //controller.inputs.primary.set_state(true); agent.action_timer += dt.0; } else { agent.action_timer = 0.0; @@ -1772,7 +1833,11 @@ impl<'a> AgentData<'a> { .rotated_z(0.47 * PI) .try_normalized() .unwrap_or_else(Vec2::unit_y); - controller.inputs.primary.set_state(true); + controller.actions.push(ControlAction::StartInput { + ability: InputKind::Primary, + target: None, + }); + //controller.inputs.primary.set_state(true); agent.action_timer += dt.0; } else if agent.action_timer < 4.0 { controller.inputs.move_dir = (tgt_pos.0 - self.pos.0) @@ -1780,7 +1845,11 @@ impl<'a> AgentData<'a> { .rotated_z(-0.47 * PI) .try_normalized() .unwrap_or_else(Vec2::unit_y); - controller.inputs.primary.set_state(true); + controller.actions.push(ControlAction::StartInput { + ability: InputKind::Primary, + target: None, + }); + //controller.inputs.primary.set_state(true); agent.action_timer += dt.0; } else if agent.action_timer < 6.0 { controller.inputs.ability3.set_state(true); @@ -1811,7 +1880,11 @@ impl<'a> AgentData<'a> { Tactic::Theropod => { if dist_sqrd < (2.0 * min_attack_dist * self.scale).powi(2) { controller.inputs.move_dir = Vec2::zero(); - controller.inputs.primary.set_state(true); + controller.actions.push(ControlAction::StartInput { + ability: InputKind::Primary, + target: None, + }); + //controller.inputs.primary.set_state(true); } else if dist_sqrd < MAX_CHASE_DIST.powi(2) { if let Some((bearing, speed)) = agent.chaser.chase( &*terrain, @@ -1834,7 +1907,11 @@ impl<'a> AgentData<'a> { }, Tactic::Turret => { if can_see_tgt(&*terrain, self.pos, tgt_pos, dist_sqrd) { - controller.inputs.primary.set_state(true); + controller.actions.push(ControlAction::StartInput { + ability: InputKind::Primary, + target: None, + }); + //controller.inputs.primary.set_state(true); } else { agent.target = None; } @@ -1842,7 +1919,11 @@ impl<'a> AgentData<'a> { Tactic::FixedTurret => { controller.inputs.look_dir = self.ori.look_dir(); if can_see_tgt(&*terrain, self.pos, tgt_pos, dist_sqrd) { - controller.inputs.primary.set_state(true); + controller.actions.push(ControlAction::StartInput { + ability: InputKind::Primary, + target: None, + }); + //controller.inputs.primary.set_state(true); } else { agent.target = None; } @@ -1856,7 +1937,11 @@ impl<'a> AgentData<'a> { .unwrap_or_default(), ); if can_see_tgt(&*terrain, self.pos, tgt_pos, dist_sqrd) { - controller.inputs.primary.set_state(true); + controller.actions.push(ControlAction::StartInput { + ability: InputKind::Primary, + target: None, + }); + //controller.inputs.primary.set_state(true); } else { agent.target = None; } diff --git a/voxygen/src/key_state.rs b/voxygen/src/key_state.rs index fd2dd56688..0b9dfc155d 100644 --- a/voxygen/src/key_state.rs +++ b/voxygen/src/key_state.rs @@ -10,16 +10,7 @@ pub struct KeyState { pub swim_up: bool, pub swim_down: bool, pub fly: bool, - pub toggle_wield: bool, - pub toggle_glide: bool, - pub toggle_lantern: bool, - pub toggle_sit: bool, - pub toggle_sneak: bool, - pub toggle_dance: bool, pub auto_walk: bool, - pub swap_loadout: bool, - pub respawn: bool, - pub interact: bool, pub trade: bool, pub analog_matrix: Vec2, } @@ -36,16 +27,7 @@ impl Default for KeyState { swim_up: false, swim_down: false, fly: false, - toggle_wield: false, - toggle_glide: false, - toggle_lantern: false, - toggle_sit: false, - toggle_sneak: false, - toggle_dance: false, auto_walk: false, - swap_loadout: false, - respawn: false, - interact: false, trade: false, analog_matrix: Vec2::zero(), } diff --git a/voxygen/src/session.rs b/voxygen/src/session.rs index 0617b607b8..17ab13b253 100644 --- a/voxygen/src/session.rs +++ b/voxygen/src/session.rs @@ -1,4 +1,4 @@ -use std::{cell::RefCell, rc::Rc, time::Duration}; +use std::{cell::RefCell, collections::HashSet, rc::Rc, time::Duration}; use ordered_float::OrderedFloat; use specs::{Join, WorldExt}; @@ -10,8 +10,8 @@ use common::{ assets::AssetExt, comp, comp::{ - inventory::slot::Slot, invite::InviteKind, ChatMsg, ChatType, InventoryUpdateEvent, Pos, - Vel, + inventory::slot::Slot, invite::InviteKind, ChatMsg, ChatType, InputKind, + InventoryUpdateEvent, Pos, Vel, }, consts::{MAX_MOUNT_RANGE, MAX_PICKUP_RANGE}, outcome::Outcome, @@ -61,6 +61,7 @@ pub struct SessionState { hud: Hud, key_state: KeyState, inputs: comp::ControllerInputs, + inputs_state: HashSet, selected_block: Block, walk_forward_dir: Vec2, walk_right_dir: Vec2, @@ -96,6 +97,7 @@ impl SessionState { client, key_state: KeyState::default(), inputs: comp::ControllerInputs::default(), + inputs_state: HashSet::new(), hud, selected_block: Block::new(BlockKind::Misc, Rgb::broadcast(255)), walk_forward_dir, @@ -349,313 +351,297 @@ impl PlayState for SessionState { Event::Close => { return PlayStateResult::Shutdown; }, - Event::InputUpdate(GameInput::Primary, state) => { - // If we can build, use LMB to break blocks, if not, use it to attack - let mut client = self.client.borrow_mut(); - if state && can_build { - if let Some(select_pos) = select_pos { - client.remove_block(select_pos); - } - } else { - self.inputs.primary.set_state(state); - } - }, - - Event::InputUpdate(GameInput::Secondary, state) => { - self.inputs.secondary.set_state(false); // To be changed later on - - let mut client = self.client.borrow_mut(); - - if state && can_build { - if let Some(build_pos) = build_pos { - client.place_block(build_pos, self.selected_block); - } - } else { - self.inputs.secondary.set_state(state); - } - }, - - Event::InputUpdate(GameInput::Roll, state) => { - let client = self.client.borrow(); - if can_build { - if state { - if let Some(block) = select_pos - .and_then(|sp| client.state().terrain().get(sp).ok().copied()) - { - self.selected_block = block; - } - } - } else { - self.inputs.roll.set_state(state); - } - }, - Event::InputUpdate(GameInput::Respawn, state) - if state != self.key_state.respawn => + Event::InputUpdate(input, state) + if state != self.inputs_state.contains(&input) => { - self.stop_auto_walk(); - self.key_state.respawn = state; - if state { - self.client.borrow_mut().respawn(); + if !self.inputs_state.insert(input) { + self.inputs_state.remove(&input); } - } - Event::InputUpdate(GameInput::Jump, state) => { - self.inputs.jump.set_state(state); - }, - Event::InputUpdate(GameInput::SwimUp, state) => { - self.key_state.swim_up = state; - }, - Event::InputUpdate(GameInput::SwimDown, state) => { - self.key_state.swim_down = state; - }, - Event::InputUpdate(GameInput::Sit, state) - if state != self.key_state.toggle_sit => - { - self.key_state.toggle_sit = state; - - if state { - self.stop_auto_walk(); - self.client.borrow_mut().toggle_sit(); - } - } - Event::InputUpdate(GameInput::Dance, state) - if state != self.key_state.toggle_dance => - { - self.key_state.toggle_dance = state; - if state { - self.stop_auto_walk(); - self.client.borrow_mut().toggle_dance(); - } - } - Event::InputUpdate(GameInput::Sneak, state) - if state != self.key_state.toggle_sneak => - { - self.key_state.toggle_sneak = state; - if state { - self.stop_auto_walk(); - self.client.borrow_mut().toggle_sneak(); - } - } - Event::InputUpdate(GameInput::MoveForward, state) => { - if state && global_state.settings.gameplay.stop_auto_walk_on_input { - self.stop_auto_walk(); - } - self.key_state.up = state - }, - Event::InputUpdate(GameInput::MoveBack, state) => { - if state && global_state.settings.gameplay.stop_auto_walk_on_input { - self.stop_auto_walk(); - } - self.key_state.down = state - }, - Event::InputUpdate(GameInput::MoveLeft, state) => { - if state && global_state.settings.gameplay.stop_auto_walk_on_input { - self.stop_auto_walk(); - } - self.key_state.left = state - }, - Event::InputUpdate(GameInput::MoveRight, state) => { - if state && global_state.settings.gameplay.stop_auto_walk_on_input { - self.stop_auto_walk(); - } - self.key_state.right = state - }, - Event::InputUpdate(GameInput::Glide, state) - if state != self.key_state.toggle_glide => - { - self.key_state.toggle_glide = state; - if state { - self.client.borrow_mut().toggle_glide(); - } - } - Event::InputUpdate(GameInput::Fly, state) => { - self.key_state.fly ^= state; - }, - Event::InputUpdate(GameInput::Climb, state) => { - self.key_state.climb_up = state; - }, - Event::InputUpdate(GameInput::ClimbDown, state) => { - self.key_state.climb_down = state; - }, - /*Event::InputUpdate(GameInput::WallLeap, state) => { - self.inputs.wall_leap.set_state(state) - },*/ - Event::InputUpdate(GameInput::ToggleWield, state) - if state != self.key_state.toggle_wield => - { - self.key_state.toggle_wield = state; - if state { - self.client.borrow_mut().toggle_wield(); - } - } - Event::InputUpdate(GameInput::SwapLoadout, state) - if state != self.key_state.swap_loadout => - { - self.key_state.swap_loadout = state; - if state { - self.client.borrow_mut().swap_loadout(); - } - } - Event::InputUpdate(GameInput::ToggleLantern, true) => { - let mut client = self.client.borrow_mut(); - if client.is_lantern_enabled() { - client.disable_lantern(); - } else { - client.enable_lantern(); - } - }, - Event::InputUpdate(GameInput::Mount, true) => { - let mut client = self.client.borrow_mut(); - if client.is_mounted() { - client.unmount(); - } else { - let player_pos = client - .state() - .read_storage::() - .get(client.entity()) - .copied(); - if let Some(player_pos) = player_pos { - // Find closest mountable entity - let closest_mountable_entity = ( - &client.state().ecs().entities(), - &client.state().ecs().read_storage::(), - &client.state().ecs().read_storage::(), - ) - .join() - .filter(|(entity, _, mount_state)| { - *entity != client.entity() - && **mount_state == comp::MountState::Unmounted - }) - .map(|(entity, pos, _)| { - (entity, player_pos.0.distance_squared(pos.0)) - }) - .filter(|(_, dist_sqr)| *dist_sqr < MAX_MOUNT_RANGE.powi(2)) - .min_by_key(|(_, dist_sqr)| OrderedFloat(*dist_sqr)); - if let Some((mountee_entity, _)) = closest_mountable_entity { - client.mount(mountee_entity); - } - } - } - }, - Event::InputUpdate(GameInput::Interact, state) - if state != self.key_state.interact => - { - self.key_state.interact = state; - - if state { - if let Some(interactable) = self.interactable { + match input { + GameInput::Primary => { + // If we can build, use LMB to break blocks, if not, use it to + // attack let mut client = self.client.borrow_mut(); - match interactable { - Interactable::Block(block, pos) => { - if block.is_collectible() { - client.collect_block(pos); - } - }, - Interactable::Entity(entity) => { - if client - .state() - .ecs() - .read_storage::() - .get(entity) - .is_some() - { - client.pick_up(entity); - } else { - client.npc_interact(entity); - } - }, + if state && can_build { + if let Some(select_pos) = select_pos { + client.remove_block(select_pos); + } + } else { + client.handle_input(InputKind::Primary, state); + //self.inputs.primary.set_state(state); } - } - } - } - Event::InputUpdate(GameInput::Trade, state) - if state != self.key_state.trade => - { - self.key_state.trade = state; + }, + GameInput::Secondary => { + self.inputs.secondary.set_state(false); // To be changed later on - if state { - if let Some(interactable) = self.interactable { let mut client = self.client.borrow_mut(); - match interactable { - Interactable::Block(_, _) => {}, - Interactable::Entity(entity) => { - if let Some(uid) = - client.state().ecs().uid_from_entity(entity) - { - let name = client - .player_list() - .get(&uid) - .map(|info| info.player_alias.clone()) - .unwrap_or_else(|| format!("", uid)); - let msg = global_state - .i18n - .read() - .get("hud.trade.invite_sent") - .replace("{playername}", &name); - self.hud.new_message(ChatType::Meta.chat_msg(msg)); - client.send_invite(uid, InviteKind::Trade) - }; - }, + + if state && can_build { + if let Some(build_pos) = build_pos { + client.place_block(build_pos, self.selected_block); + } + } else { + self.inputs.secondary.set_state(state); } - } - } - } - /*Event::InputUpdate(GameInput::Charge, state) => { - self.inputs.charge.set_state(state); - },*/ - Event::InputUpdate(GameInput::FreeLook, state) => { - match (global_state.settings.gameplay.free_look_behavior, state) { - (PressBehavior::Toggle, true) => { - self.free_look = !self.free_look; - self.hud.free_look(self.free_look); }, - (PressBehavior::Hold, state) => { - self.free_look = state; - self.hud.free_look(self.free_look); + GameInput::Roll => { + let client = self.client.borrow(); + if can_build { + if state { + if let Some(block) = select_pos.and_then(|sp| { + client.state().terrain().get(sp).ok().copied() + }) { + self.selected_block = block; + } + } + } else { + self.inputs.roll.set_state(state); + } }, - _ => {}, - }; - }, - Event::InputUpdate(GameInput::AutoWalk, state) => { - match (global_state.settings.gameplay.auto_walk_behavior, state) { - (PressBehavior::Toggle, true) => { - self.auto_walk = !self.auto_walk; - self.key_state.auto_walk = self.auto_walk; - self.hud.auto_walk(self.auto_walk); + GameInput::Respawn => { + self.stop_auto_walk(); + if state { + self.client.borrow_mut().respawn(); + } }, - (PressBehavior::Hold, state) => { - self.auto_walk = state; - self.key_state.auto_walk = self.auto_walk; - self.hud.auto_walk(self.auto_walk); + GameInput::Jump => { + self.inputs.jump.set_state(state); + }, + GameInput::SwimUp => { + self.key_state.swim_up = state; + }, + GameInput::SwimDown => { + self.key_state.swim_down = state; + }, + GameInput::Sit => { + if state { + self.stop_auto_walk(); + self.client.borrow_mut().toggle_sit(); + } + }, + GameInput::Dance => { + if state { + self.stop_auto_walk(); + self.client.borrow_mut().toggle_dance(); + } + }, + GameInput::Sneak => { + if state { + self.stop_auto_walk(); + self.client.borrow_mut().toggle_sneak(); + } + }, + GameInput::MoveForward => { + if state && global_state.settings.gameplay.stop_auto_walk_on_input { + self.stop_auto_walk(); + } + self.key_state.up = state + }, + GameInput::MoveBack => { + if state && global_state.settings.gameplay.stop_auto_walk_on_input { + self.stop_auto_walk(); + } + self.key_state.down = state + }, + GameInput::MoveLeft => { + if state && global_state.settings.gameplay.stop_auto_walk_on_input { + self.stop_auto_walk(); + } + self.key_state.left = state + }, + GameInput::MoveRight => { + if state && global_state.settings.gameplay.stop_auto_walk_on_input { + self.stop_auto_walk(); + } + self.key_state.right = state + }, + GameInput::Glide => { + if state { + self.client.borrow_mut().toggle_glide(); + } + }, + GameInput::Fly => { + self.key_state.fly ^= state; + }, + GameInput::Climb => { + self.key_state.climb_up = state; + }, + GameInput::ClimbDown => { + self.key_state.climb_down = state; + }, + GameInput::ToggleWield => { + if state { + self.client.borrow_mut().toggle_wield(); + } + }, + GameInput::SwapLoadout => { + if state { + self.client.borrow_mut().swap_loadout(); + } + }, + GameInput::ToggleLantern if state => { + let mut client = self.client.borrow_mut(); + if client.is_lantern_enabled() { + client.disable_lantern(); + } else { + client.enable_lantern(); + } + }, + GameInput::Mount if state => { + let mut client = self.client.borrow_mut(); + if client.is_mounted() { + client.unmount(); + } else { + let player_pos = client + .state() + .read_storage::() + .get(client.entity()) + .copied(); + if let Some(player_pos) = player_pos { + // Find closest mountable entity + let closest_mountable_entity = ( + &client.state().ecs().entities(), + &client.state().ecs().read_storage::(), + &client + .state() + .ecs() + .read_storage::(), + ) + .join() + .filter(|(entity, _, mount_state)| { + *entity != client.entity() + && **mount_state == comp::MountState::Unmounted + }) + .map(|(entity, pos, _)| { + (entity, player_pos.0.distance_squared(pos.0)) + }) + .filter(|(_, dist_sqr)| { + *dist_sqr < MAX_MOUNT_RANGE.powi(2) + }) + .min_by_key(|(_, dist_sqr)| OrderedFloat(*dist_sqr)); + if let Some((mountee_entity, _)) = closest_mountable_entity + { + client.mount(mountee_entity); + } + } + } + }, + GameInput::Interact => { + if state { + if let Some(interactable) = self.interactable { + let mut client = self.client.borrow_mut(); + match interactable { + Interactable::Block(block, pos) => { + if block.is_collectible() { + client.collect_block(pos); + } + }, + Interactable::Entity(entity) => { + if client + .state() + .ecs() + .read_storage::() + .get(entity) + .is_some() + { + client.pick_up(entity); + } else { + client.npc_interact(entity); + } + }, + } + } + } + }, + GameInput::Trade => { + if state { + if let Some(interactable) = self.interactable { + let mut client = self.client.borrow_mut(); + match interactable { + Interactable::Block(_, _) => {}, + Interactable::Entity(entity) => { + if let Some(uid) = + client.state().ecs().uid_from_entity(entity) + { + let name = client + .player_list() + .get(&uid) + .map(|info| info.player_alias.clone()) + .unwrap_or_else(|| { + format!("", uid) + }); + let msg = global_state + .i18n + .read() + .get("hud.trade.invite_sent") + .replace("{playername}", &name); + self.hud + .new_message(ChatType::Meta.chat_msg(msg)); + client.send_invite(uid, InviteKind::Trade) + }; + }, + } + } + } + }, + GameInput::FreeLook => { + match (global_state.settings.gameplay.free_look_behavior, state) { + (PressBehavior::Toggle, true) => { + self.free_look = !self.free_look; + self.hud.free_look(self.free_look); + }, + (PressBehavior::Hold, state) => { + self.free_look = state; + self.hud.free_look(self.free_look); + }, + _ => {}, + }; + }, + GameInput::AutoWalk => { + match (global_state.settings.gameplay.auto_walk_behavior, state) { + (PressBehavior::Toggle, true) => { + self.auto_walk = !self.auto_walk; + self.key_state.auto_walk = self.auto_walk; + self.hud.auto_walk(self.auto_walk); + }, + (PressBehavior::Hold, state) => { + self.auto_walk = state; + self.key_state.auto_walk = self.auto_walk; + self.hud.auto_walk(self.auto_walk); + }, + _ => {}, + } + }, + GameInput::CycleCamera if state => { + // Prevent accessing camera modes which aren't available in + // multiplayer unless you are an + // admin. This is an easily bypassed clientside check. + // The server should do its own filtering of which entities are sent + // to clients to prevent abuse. + let camera = self.scene.camera_mut(); + camera.next_mode(self.client.borrow().is_admin()); + }, + GameInput::Select => { + if !state { + self.selected_entity = + self.target_entity.map(|e| (e, std::time::Instant::now())); + } + }, + GameInput::AcceptGroupInvite if state => { + let mut client = self.client.borrow_mut(); + if client.invite().is_some() { + client.accept_invite(); + } + }, + GameInput::DeclineGroupInvite if state => { + let mut client = self.client.borrow_mut(); + if client.invite().is_some() { + client.decline_invite(); + } }, _ => {}, } - }, - Event::InputUpdate(GameInput::CycleCamera, true) => { - // Prevent accessing camera modes which aren't available in multiplayer - // unless you are an admin. This is an easily bypassed clientside check. - // The server should do its own filtering of which entities are sent to - // clients to prevent abuse. - let camera = self.scene.camera_mut(); - camera.next_mode(self.client.borrow().is_admin()); - }, - Event::InputUpdate(GameInput::Select, state) => { - if !state { - self.selected_entity = - self.target_entity.map(|e| (e, std::time::Instant::now())); - } - }, - Event::InputUpdate(GameInput::AcceptGroupInvite, true) => { - let mut client = self.client.borrow_mut(); - if client.invite().is_some() { - client.accept_invite(); - } - }, - Event::InputUpdate(GameInput::DeclineGroupInvite, true) => { - let mut client = self.client.borrow_mut(); - if client.invite().is_some() { - client.decline_invite(); - } - }, + } Event::AnalogGameInput(input) => match input { AnalogGameInput::MovementX(v) => { self.key_state.analog_matrix.x = v; From 19c81f15286f7a82dfc4941ee8d3d77398d52748 Mon Sep 17 00:00:00 2001 From: Sam Date: Thu, 11 Mar 2021 23:53:25 -0500 Subject: [PATCH 2/7] Support for canceling an input. Boost state hooked up to system. --- client/src/lib.rs | 2 +- common/src/comp/ability.rs | 2 ++ common/src/comp/character_state.rs | 2 ++ common/src/comp/controller.rs | 2 +- common/src/states/behavior.rs | 8 +++-- common/src/states/boost.rs | 29 ++++++++++++++++-- common/src/states/utils.rs | 45 ++++++++++++++++++++-------- common/sys/src/character_behavior.rs | 17 +++++++---- server/src/sys/agent.rs | 4 ++- 9 files changed, 87 insertions(+), 24 deletions(-) diff --git a/client/src/lib.rs b/client/src/lib.rs index c98ab89829..4580f0ef0e 100644 --- a/client/src/lib.rs +++ b/client/src/lib.rs @@ -998,7 +998,7 @@ impl Client { target: None, }); } else { - self.control_action(ControlAction::CancelInput); + self.control_action(ControlAction::CancelInput(input)); } } diff --git a/common/src/comp/ability.rs b/common/src/comp/ability.rs index 9194b552f5..a84efef9ce 100644 --- a/common/src/comp/ability.rs +++ b/common/src/comp/ability.rs @@ -1156,8 +1156,10 @@ impl From<(&CharacterAbility, AbilityInfo)> for CharacterState { static_data: boost::StaticData { movement_duration: Duration::from_secs_f32(*movement_duration), only_up: *only_up, + ability_info, }, timer: Duration::default(), + end: false, }), CharacterAbility::DashMelee { energy_cost: _, diff --git a/common/src/comp/character_state.rs b/common/src/comp/character_state.rs index 33eb2752d6..25d16beeb9 100644 --- a/common/src/comp/character_state.rs +++ b/common/src/comp/character_state.rs @@ -18,6 +18,7 @@ pub struct StateUpdate { pub energy: Energy, pub swap_equipped_weapons: bool, pub queued_inputs: BTreeSet, + pub removed_inputs: Vec, pub local_events: VecDeque, pub server_events: VecDeque, } @@ -32,6 +33,7 @@ impl From<&JoinData<'_>> for StateUpdate { swap_equipped_weapons: false, character: data.character.clone(), queued_inputs: BTreeSet::new(), + removed_inputs: Vec::new(), local_events: VecDeque::new(), server_events: VecDeque::new(), } diff --git a/common/src/comp/controller.rs b/common/src/comp/controller.rs index bdd32b95ef..70d00e28aa 100644 --- a/common/src/comp/controller.rs +++ b/common/src/comp/controller.rs @@ -115,7 +115,7 @@ pub enum ControlAction { ability: InputKind, target: Option, }, - CancelInput, + CancelInput(InputKind), } #[derive(Clone, Copy, Debug, PartialEq, Serialize, Deserialize, Eq, Ord, PartialOrd)] diff --git a/common/src/states/behavior.rs b/common/src/states/behavior.rs index 9cb467c79f..391aaf09c1 100644 --- a/common/src/states/behavior.rs +++ b/common/src/states/behavior.rs @@ -34,7 +34,11 @@ pub trait CharacterBehavior { update.queued_inputs.insert(input); update } - fn cancel_input(&self, data: &JoinData) -> StateUpdate { StateUpdate::from(data) } + fn cancel_input(&self, data: &JoinData, input: InputKind) -> StateUpdate { + let mut update = StateUpdate::from(data); + update.removed_inputs.push(input); + update + } fn handle_event(&self, data: &JoinData, event: ControlAction) -> StateUpdate { match event { ControlAction::SwapEquippedWeapons => self.swap_equipped_weapons(data), @@ -50,7 +54,7 @@ pub trait CharacterBehavior { ControlAction::StartInput { ability, target } => { self.handle_input(data, ability, target) }, - ControlAction::CancelInput => self.cancel_input(data), + ControlAction::CancelInput(input) => self.cancel_input(data, input), } } // fn init(data: &JoinData) -> CharacterState; diff --git a/common/src/states/boost.rs b/common/src/states/boost.rs index 562e120913..a18b520700 100644 --- a/common/src/states/boost.rs +++ b/common/src/states/boost.rs @@ -1,5 +1,5 @@ use crate::{ - comp::{CharacterState, StateUpdate}, + comp::{CharacterState, InputKind, StateUpdate}, states::{ behavior::{CharacterBehavior, JoinData}, utils::*, @@ -13,6 +13,7 @@ use std::time::Duration; pub struct StaticData { pub movement_duration: Duration, pub only_up: bool, + pub ability_info: AbilityInfo, } #[derive(Copy, Clone, Debug, PartialEq, Serialize, Deserialize)] @@ -22,6 +23,8 @@ pub struct Data { pub static_data: StaticData, /// Timer for each stage pub timer: Duration, + /// Whether or not the state should end + pub end: bool, } impl CharacterBehavior for Data { @@ -46,9 +49,31 @@ impl CharacterBehavior for Data { }); } else { // Done - update.character = CharacterState::Wielding; + if self.end || self.static_data.ability_info.input.is_none() { + update.character = CharacterState::Wielding; + } else { + reset_state(self, &mut update); + } + } + + update + } + + fn cancel_input(&self, data: &JoinData, input: InputKind) -> StateUpdate { + let mut update = StateUpdate::from(data); + update.removed_inputs.push(input); + + if Some(input) == self.static_data.ability_info.input { + update.character = CharacterState::Boost(Data { end: true, ..*self }); } update } } + +fn reset_state(data: &Data, update: &mut StateUpdate) { + update.character = CharacterState::Boost(Data { + timer: Duration::default(), + ..*data + }) +} diff --git a/common/src/states/utils.rs b/common/src/states/utils.rs index eac9496cd5..b39c32f60a 100644 --- a/common/src/states/utils.rs +++ b/common/src/states/utils.rs @@ -434,7 +434,12 @@ pub fn handle_jump(data: &JoinData, update: &mut StateUpdate) { } } -fn handle_ability_pressed(data: &JoinData, update: &mut StateUpdate, ability_key: AbilityKey) { +fn handle_ability_pressed( + data: &JoinData, + update: &mut StateUpdate, + ability_key: AbilityKey, + input: Option, +) { let hands = |equip_slot| match data.inventory.equipped(equip_slot).map(|i| i.kind()) { Some(ItemKind::Tool(tool)) => Some(tool.hands), _ => None, @@ -484,7 +489,12 @@ fn handle_ability_pressed(data: &JoinData, update: &mut StateUpdate, ability_key { update.character = ( &ability, - AbilityInfo::from_key(data, ability_key, matches!(equip_slot, EquipSlot::Offhand)), + AbilityInfo::from_key( + data, + ability_key, + matches!(equip_slot, EquipSlot::Offhand), + input, + ), ) .into(); } @@ -493,7 +503,7 @@ fn handle_ability_pressed(data: &JoinData, update: &mut StateUpdate, ability_key pub fn handle_input(data: &JoinData, update: &mut StateUpdate, input: InputKind) { match input { - InputKind::Primary => handle_ability_pressed(data, update, AbilityKey::Mouse1), + InputKind::Primary => handle_ability_pressed(data, update, AbilityKey::Mouse1, Some(input)), } } @@ -505,19 +515,19 @@ pub fn handle_input(data: &JoinData, update: &mut StateUpdate, input: InputKind) pub fn handle_ability2_input(data: &JoinData, update: &mut StateUpdate) { if data.inputs.secondary.is_pressed() { - handle_ability_pressed(data, update, AbilityKey::Mouse2); + handle_ability_pressed(data, update, AbilityKey::Mouse2, None); } } pub fn handle_ability3_input(data: &JoinData, update: &mut StateUpdate) { if data.inputs.ability3.is_pressed() { - handle_ability_pressed(data, update, AbilityKey::Skill1); + handle_ability_pressed(data, update, AbilityKey::Skill1, None); } } pub fn handle_ability4_input(data: &JoinData, update: &mut StateUpdate) { if data.inputs.ability4.is_pressed() { - handle_ability_pressed(data, update, AbilityKey::Skill2); + handle_ability_pressed(data, update, AbilityKey::Skill2, None); } } @@ -539,7 +549,7 @@ pub fn handle_dodge_input(data: &JoinData, update: &mut StateUpdate) { if let CharacterState::ComboMelee(c) = data.character { update.character = ( &ability, - AbilityInfo::from_key(data, AbilityKey::Dodge, false), + AbilityInfo::from_key(data, AbilityKey::Dodge, false, None), ) .into(); if let CharacterState::Roll(roll) = &mut update.character { @@ -549,7 +559,7 @@ pub fn handle_dodge_input(data: &JoinData, update: &mut StateUpdate) { } else if data.character.is_wield() { update.character = ( &ability, - AbilityInfo::from_key(data, AbilityKey::Dodge, false), + AbilityInfo::from_key(data, AbilityKey::Dodge, false, None), ) .into(); if let CharacterState::Roll(roll) = &mut update.character { @@ -558,7 +568,7 @@ pub fn handle_dodge_input(data: &JoinData, update: &mut StateUpdate) { } else if data.character.is_stealthy() { update.character = ( &ability, - AbilityInfo::from_key(data, AbilityKey::Dodge, false), + AbilityInfo::from_key(data, AbilityKey::Dodge, false, None), ) .into(); if let CharacterState::Roll(roll) = &mut update.character { @@ -567,7 +577,7 @@ pub fn handle_dodge_input(data: &JoinData, update: &mut StateUpdate) { } else { update.character = ( &ability, - AbilityInfo::from_key(data, AbilityKey::Dodge, false), + AbilityInfo::from_key(data, AbilityKey::Dodge, false, None), ) .into(); } @@ -687,10 +697,16 @@ pub struct AbilityInfo { pub tool: Option, pub hand: Option, pub key: AbilityKey, + pub input: Option, } impl AbilityInfo { - pub fn from_key(data: &JoinData, key: AbilityKey, from_offhand: bool) -> Self { + pub fn from_key( + data: &JoinData, + key: AbilityKey, + from_offhand: bool, + input: Option, + ) -> Self { let tool_data = if from_offhand { unwrap_tool_data(data, EquipSlot::Offhand) } else { @@ -705,7 +721,12 @@ impl AbilityInfo { ) }; - Self { tool, hand, key } + Self { + tool, + hand, + key, + input, + } } } diff --git a/common/sys/src/character_behavior.rs b/common/sys/src/character_behavior.rs index 1c438729e0..61e0445c51 100644 --- a/common/sys/src/character_behavior.rs +++ b/common/sys/src/character_behavior.rs @@ -23,7 +23,7 @@ use common::{ use common_ecs::{Job, Origin, Phase, System}; use std::time::Duration; -fn incorporate_update(join: &mut JoinStruct, state_update: StateUpdate) { +fn incorporate_update(join: &mut JoinStruct, mut state_update: StateUpdate) { // TODO: if checking equality is expensive use optional field in StateUpdate if join.char_state.get_unchecked() != &state_update.character { *join.char_state.get_mut_unchecked() = state_update.character @@ -35,6 +35,12 @@ fn incorporate_update(join: &mut JoinStruct, state_update: StateUpdate) { if join.energy.get_unchecked() != &state_update.energy { *join.energy.get_mut_unchecked() = state_update.energy }; + join.controller + .queued_inputs + .append(&mut state_update.queued_inputs); + for input in state_update.removed_inputs { + join.controller.queued_inputs.remove(&input); + } if state_update.swap_equipped_weapons { let mut inventory = join.inventory.get_mut_unchecked(); let inventory = &mut *inventory; @@ -350,10 +356,11 @@ impl<'a> System<'a> for Sys { local_emitter.append(&mut state_update.local_events); server_emitter.append(&mut state_update.server_events); - join_struct - .controller - .queued_inputs - .append(&mut state_update.queued_inputs); + // join_struct + // .controller + // .queued_inputs + // .append(&mut state_update.queued_inputs); + // join_struct.controller.queued_inputs. incorporate_update(&mut join_struct, state_update); } } diff --git a/server/src/sys/agent.rs b/server/src/sys/agent.rs index 4d48e29051..0d2ffc1920 100644 --- a/server/src/sys/agent.rs +++ b/server/src/sys/agent.rs @@ -1638,7 +1638,9 @@ impl<'a> AgentData<'a> { Tactic::TailSlap => { if dist_sqrd < (1.5 * min_attack_dist * self.scale).powi(2) { if agent.action_timer > 4.0 { - controller.actions.push(ControlAction::CancelInput); + controller + .actions + .push(ControlAction::CancelInput(InputKind::Primary)); //controller.inputs.primary.set_state(false); agent.action_timer = 0.0; } else if agent.action_timer > 1.0 { From 21e6f4797c1e3c448e2f203f73e05ed303fa0b41 Mon Sep 17 00:00:00 2001 From: Sam Date: Fri, 12 Mar 2021 16:01:30 -0500 Subject: [PATCH 3/7] Primary ability fully functional. --- assets/common/abilities/bow/basic.ron | 1 - assets/common/abilities/bowsimple/basic.ron | 1 - assets/common/abilities/debug/possess.ron | 1 - assets/common/abilities/staff/firebomb.ron | 1 - .../common/abilities/staffsimple/firebomb.ron | 1 - .../unique/quadlowranged/firebomb.ron | 1 - .../common/abilities/unique/turret/arrows.ron | 1 - .../unique/wendigomagic/frostbomb.ron | 1 - client/src/lib.rs | 2 +- common/src/comp/ability.rs | 9 +-- common/src/comp/controller.rs | 2 +- common/src/states/basic_beam.rs | 19 ++++- common/src/states/basic_melee.rs | 31 +++++++- common/src/states/basic_ranged.rs | 67 ++++++++-------- common/src/states/behavior.rs | 4 +- common/src/states/boost.rs | 13 ++-- common/src/states/combo_melee.rs | 77 ++++++++----------- common/src/states/idle.rs | 15 +++- common/src/states/wielding.rs | 9 +-- server/src/sys/agent.rs | 42 +++++----- 20 files changed, 160 insertions(+), 138 deletions(-) diff --git a/assets/common/abilities/bow/basic.ron b/assets/common/abilities/bow/basic.ron index cbc6e28040..fd47e9c51a 100644 --- a/assets/common/abilities/bow/basic.ron +++ b/assets/common/abilities/bow/basic.ron @@ -11,5 +11,4 @@ BasicRanged( projectile_light: None, projectile_gravity: Some(Gravity(0.2)), projectile_speed: 100.0, - can_continue: true, ) diff --git a/assets/common/abilities/bowsimple/basic.ron b/assets/common/abilities/bowsimple/basic.ron index cbc6e28040..fd47e9c51a 100644 --- a/assets/common/abilities/bowsimple/basic.ron +++ b/assets/common/abilities/bowsimple/basic.ron @@ -11,5 +11,4 @@ BasicRanged( projectile_light: None, projectile_gravity: Some(Gravity(0.2)), projectile_speed: 100.0, - can_continue: true, ) diff --git a/assets/common/abilities/debug/possess.ron b/assets/common/abilities/debug/possess.ron index 92f722ee9a..7554d1fa65 100644 --- a/assets/common/abilities/debug/possess.ron +++ b/assets/common/abilities/debug/possess.ron @@ -10,5 +10,4 @@ BasicRanged( }),*/ projectile_gravity: None, projectile_speed: 100.0, - can_continue: false, ) \ No newline at end of file diff --git a/assets/common/abilities/staff/firebomb.ron b/assets/common/abilities/staff/firebomb.ron index 16444d31a3..7b4724217d 100644 --- a/assets/common/abilities/staff/firebomb.ron +++ b/assets/common/abilities/staff/firebomb.ron @@ -14,5 +14,4 @@ BasicRanged( }),*/ projectile_gravity: Some(Gravity(0.3)), projectile_speed: 60.0, - can_continue: true, ) diff --git a/assets/common/abilities/staffsimple/firebomb.ron b/assets/common/abilities/staffsimple/firebomb.ron index 16444d31a3..7b4724217d 100644 --- a/assets/common/abilities/staffsimple/firebomb.ron +++ b/assets/common/abilities/staffsimple/firebomb.ron @@ -14,5 +14,4 @@ BasicRanged( }),*/ projectile_gravity: Some(Gravity(0.3)), projectile_speed: 60.0, - can_continue: true, ) diff --git a/assets/common/abilities/unique/quadlowranged/firebomb.ron b/assets/common/abilities/unique/quadlowranged/firebomb.ron index 160e6def79..4470e21596 100644 --- a/assets/common/abilities/unique/quadlowranged/firebomb.ron +++ b/assets/common/abilities/unique/quadlowranged/firebomb.ron @@ -14,5 +14,4 @@ BasicRanged( }),*/ projectile_gravity: Some(Gravity(5.0)), projectile_speed: 70.0, - can_continue: true, ) diff --git a/assets/common/abilities/unique/turret/arrows.ron b/assets/common/abilities/unique/turret/arrows.ron index f605922937..04845845d1 100644 --- a/assets/common/abilities/unique/turret/arrows.ron +++ b/assets/common/abilities/unique/turret/arrows.ron @@ -11,5 +11,4 @@ BasicRanged( projectile_light: None, projectile_gravity: Some(Gravity(0.1)), projectile_speed: 100.0, - can_continue: true, ) diff --git a/assets/common/abilities/unique/wendigomagic/frostbomb.ron b/assets/common/abilities/unique/wendigomagic/frostbomb.ron index 9f53c6deb9..6ba4652208 100644 --- a/assets/common/abilities/unique/wendigomagic/frostbomb.ron +++ b/assets/common/abilities/unique/wendigomagic/frostbomb.ron @@ -13,5 +13,4 @@ BasicRanged( }),*/ projectile_gravity: Some(Gravity(0.3)), projectile_speed: 60.0, - can_continue: true, ) diff --git a/client/src/lib.rs b/client/src/lib.rs index 4580f0ef0e..72c96efce5 100644 --- a/client/src/lib.rs +++ b/client/src/lib.rs @@ -994,7 +994,7 @@ impl Client { pub fn handle_input(&mut self, input: InputKind, pressed: bool) { if pressed { self.control_action(ControlAction::StartInput { - ability: input, + input, target: None, }); } else { diff --git a/common/src/comp/ability.rs b/common/src/comp/ability.rs index a84efef9ce..9de22f1034 100644 --- a/common/src/comp/ability.rs +++ b/common/src/comp/ability.rs @@ -75,7 +75,6 @@ pub enum CharacterAbility { projectile_light: Option, projectile_gravity: Option, projectile_speed: f32, - can_continue: bool, }, RepeaterRanged { energy_cost: f32, @@ -1121,6 +1120,7 @@ impl From<(&CharacterAbility, AbilityInfo)> for CharacterState { timer: Duration::default(), stage_section: StageSection::Buildup, exhausted: false, + end: false, }), CharacterAbility::BasicRanged { buildup_duration, @@ -1130,7 +1130,6 @@ impl From<(&CharacterAbility, AbilityInfo)> for CharacterState { projectile_light, projectile_gravity, projectile_speed, - can_continue, energy_cost: _, } => CharacterState::BasicRanged(basic_ranged::Data { static_data: basic_ranged::StaticData { @@ -1141,13 +1140,12 @@ impl From<(&CharacterAbility, AbilityInfo)> for CharacterState { projectile_light: *projectile_light, projectile_gravity: *projectile_gravity, projectile_speed: *projectile_speed, - can_continue: *can_continue, ability_info, }, timer: Duration::default(), stage_section: StageSection::Buildup, exhausted: false, - continue_next: false, + end: false, }), CharacterAbility::Boost { movement_duration, @@ -1252,7 +1250,7 @@ impl From<(&CharacterAbility, AbilityInfo)> for CharacterState { stage: 1, timer: Duration::default(), stage_section: StageSection::Buildup, - next_stage: false, + end: false, }), CharacterAbility::LeapMelee { energy_cost: _, @@ -1497,6 +1495,7 @@ impl From<(&CharacterAbility, AbilityInfo)> for CharacterState { }, timer: Duration::default(), stage_section: StageSection::Buildup, + end: false, }), CharacterAbility::BasicAura { buildup_duration, diff --git a/common/src/comp/controller.rs b/common/src/comp/controller.rs index 70d00e28aa..78db2fa100 100644 --- a/common/src/comp/controller.rs +++ b/common/src/comp/controller.rs @@ -112,7 +112,7 @@ pub enum ControlAction { Stand, Talk, StartInput { - ability: InputKind, + input: InputKind, target: Option, }, CancelInput(InputKind), diff --git a/common/src/states/basic_beam.rs b/common/src/states/basic_beam.rs index 4b6d5a3fc9..dc5b992496 100644 --- a/common/src/states/basic_beam.rs +++ b/common/src/states/basic_beam.rs @@ -3,7 +3,7 @@ use crate::{ Attack, AttackDamage, AttackEffect, CombatEffect, CombatRequirement, Damage, DamageSource, GroupTarget, }, - comp::{beam, CharacterState, EnergyChange, EnergySource, Ori, Pos, StateUpdate}, + comp::{beam, CharacterState, EnergyChange, EnergySource, InputKind, Ori, Pos, StateUpdate}, event::ServerEvent, states::{ behavior::{CharacterBehavior, JoinData}, @@ -56,6 +56,8 @@ pub struct Data { pub timer: Duration, /// What section the character stage is in pub stage_section: StageSection, + /// Whether or not the state should end + pub end: bool, } impl CharacterBehavior for Data { @@ -108,7 +110,9 @@ impl CharacterBehavior for Data { } }, StageSection::Cast => { - if ability_key_is_pressed(data, self.static_data.ability_info.key) + if + /* ability_key_is_pressed(data, self.static_data.ability_info.key) */ + !self.end && (self.static_data.energy_drain <= f32::EPSILON || update.energy.current() > 0) { @@ -205,6 +209,17 @@ impl CharacterBehavior for Data { update } + + fn cancel_input(&self, data: &JoinData, input: InputKind) -> StateUpdate { + let mut update = StateUpdate::from(data); + update.removed_inputs.push(input); + + if Some(input) == self.static_data.ability_info.input { + update.character = CharacterState::BasicBeam(Data { end: true, ..*self }); + } + + update + } } #[derive(Copy, Clone, Debug, PartialEq, Serialize, Deserialize)] diff --git a/common/src/states/basic_melee.rs b/common/src/states/basic_melee.rs index a4ce9a4d5a..16c01b3191 100644 --- a/common/src/states/basic_melee.rs +++ b/common/src/states/basic_melee.rs @@ -1,6 +1,6 @@ use crate::{ combat::{Attack, AttackDamage, AttackEffect, CombatBuff, CombatEffect, CombatRequirement}, - comp::{CharacterState, Melee, StateUpdate}, + comp::{CharacterState, InputKind, Melee, StateUpdate}, states::{ behavior::{CharacterBehavior, JoinData}, utils::*, @@ -44,6 +44,8 @@ pub struct Data { pub stage_section: StageSection, /// Whether the attack can deal more damage pub exhausted: bool, + /// Whether or not the state should end + pub end: bool, } impl CharacterBehavior for Data { @@ -162,9 +164,13 @@ impl CharacterBehavior for Data { }); } else { // Done - update.character = CharacterState::Wielding; - // Make sure attack component is removed - data.updater.remove::(data.entity); + if self.end || self.static_data.ability_info.input.is_none() { + update.character = CharacterState::Wielding; + // Make sure attack component is removed + data.updater.remove::(data.entity); + } else { + reset_state(self, data, &mut update); + } } }, _ => { @@ -177,4 +183,21 @@ impl CharacterBehavior for Data { update } + + fn cancel_input(&self, data: &JoinData, input: InputKind) -> StateUpdate { + let mut update = StateUpdate::from(data); + update.removed_inputs.push(input); + + if Some(input) == self.static_data.ability_info.input { + if let CharacterState::BasicMelee(c) = &mut update.character { + c.end = true; + } + } + + update + } +} + +fn reset_state(data: &Data, join: &JoinData, update: &mut StateUpdate) { + handle_input(join, update, data.static_data.ability_info.input.unwrap()); } diff --git a/common/src/states/basic_ranged.rs b/common/src/states/basic_ranged.rs index cb0142e939..128a017804 100644 --- a/common/src/states/basic_ranged.rs +++ b/common/src/states/basic_ranged.rs @@ -1,5 +1,7 @@ use crate::{ - comp::{Body, CharacterState, Gravity, LightEmitter, ProjectileConstructor, StateUpdate}, + comp::{ + Body, CharacterState, Gravity, InputKind, LightEmitter, ProjectileConstructor, StateUpdate, + }, event::ServerEvent, states::{ behavior::{CharacterBehavior, JoinData}, @@ -24,8 +26,6 @@ pub struct StaticData { pub projectile_speed: f32, /// What key is used to press ability pub ability_info: AbilityInfo, - /// Whether or not the ability can auto continue - pub can_continue: bool, } #[derive(Clone, Debug, PartialEq, Serialize, Deserialize)] @@ -39,9 +39,8 @@ pub struct Data { pub stage_section: StageSection, /// Whether the attack fired already pub exhausted: bool, - /// If in buildup, whether the attack has continued form previous attack; if - /// in recover, whether the attack will continue to a new attack - pub continue_next: bool, + /// Whether or not the state should end + pub end: bool, } impl CharacterBehavior for Data { @@ -103,41 +102,24 @@ impl CharacterBehavior for Data { update.character = CharacterState::BasicRanged(Data { exhausted: true, - continue_next: false, ..*self }); } else if self.timer < self.static_data.recover_duration { - if ability_key_is_pressed(data, self.static_data.ability_info.key) { - // Recovers - update.character = CharacterState::BasicRanged(Data { - timer: self - .timer - .checked_add(Duration::from_secs_f32(data.dt.0)) - .unwrap_or_default(), - continue_next: self.static_data.can_continue, - ..*self - }); - } else { - // Recovers - update.character = CharacterState::BasicRanged(Data { - timer: self - .timer - .checked_add(Duration::from_secs_f32(data.dt.0)) - .unwrap_or_default(), - ..*self - }); - } - } else if self.continue_next { - // Restarts character state + // Recovers update.character = CharacterState::BasicRanged(Data { - timer: Duration::default(), - stage_section: StageSection::Buildup, - exhausted: false, + timer: self + .timer + .checked_add(Duration::from_secs_f32(data.dt.0)) + .unwrap_or_default(), ..*self - }) + }); } else { // Done - update.character = CharacterState::Wielding; + if self.end || self.static_data.ability_info.input.is_none() { + update.character = CharacterState::Wielding; + } else { + reset_state(self, data, &mut update); + } } }, _ => { @@ -148,4 +130,21 @@ impl CharacterBehavior for Data { update } + + fn cancel_input(&self, data: &JoinData, input: InputKind) -> StateUpdate { + let mut update = StateUpdate::from(data); + update.removed_inputs.push(input); + + if Some(input) == self.static_data.ability_info.input { + if let CharacterState::BasicRanged(c) = &mut update.character { + c.end = true; + } + } + + update + } +} + +fn reset_state(data: &Data, join: &JoinData, update: &mut StateUpdate) { + handle_input(join, update, data.static_data.ability_info.input.unwrap()); } diff --git a/common/src/states/behavior.rs b/common/src/states/behavior.rs index 391aaf09c1..c0722ba0e3 100644 --- a/common/src/states/behavior.rs +++ b/common/src/states/behavior.rs @@ -51,9 +51,7 @@ pub trait CharacterBehavior { ControlAction::Sneak => self.sneak(data), ControlAction::Stand => self.stand(data), ControlAction::Talk => self.talk(data), - ControlAction::StartInput { ability, target } => { - self.handle_input(data, ability, target) - }, + ControlAction::StartInput { input, target } => self.handle_input(data, input, target), ControlAction::CancelInput(input) => self.cancel_input(data, input), } } diff --git a/common/src/states/boost.rs b/common/src/states/boost.rs index a18b520700..5dbd911b15 100644 --- a/common/src/states/boost.rs +++ b/common/src/states/boost.rs @@ -52,7 +52,7 @@ impl CharacterBehavior for Data { if self.end || self.static_data.ability_info.input.is_none() { update.character = CharacterState::Wielding; } else { - reset_state(self, &mut update); + reset_state(self, data, &mut update); } } @@ -64,16 +64,15 @@ impl CharacterBehavior for Data { update.removed_inputs.push(input); if Some(input) == self.static_data.ability_info.input { - update.character = CharacterState::Boost(Data { end: true, ..*self }); + if let CharacterState::Boost(c) = &mut update.character { + c.end = true; + } } update } } -fn reset_state(data: &Data, update: &mut StateUpdate) { - update.character = CharacterState::Boost(Data { - timer: Duration::default(), - ..*data - }) +fn reset_state(data: &Data, join: &JoinData, update: &mut StateUpdate) { + handle_input(join, update, data.static_data.ability_info.input.unwrap()); } diff --git a/common/src/states/combo_melee.rs b/common/src/states/combo_melee.rs index da269675ba..9696503e43 100644 --- a/common/src/states/combo_melee.rs +++ b/common/src/states/combo_melee.rs @@ -1,6 +1,6 @@ use crate::{ combat::{Attack, AttackDamage, AttackEffect, CombatBuff, CombatEffect, CombatRequirement}, - comp::{CharacterState, Melee, StateUpdate}, + comp::{CharacterState, InputKind, Melee, StateUpdate}, states::{ behavior::{CharacterBehavior, JoinData}, utils::*, @@ -113,8 +113,8 @@ pub struct Data { pub timer: Duration, /// Checks what section a stage is in pub stage_section: StageSection, - /// Whether the state should go onto the next stage - pub next_stage: bool, + /// Whether or not the state should end + pub end: bool, } impl CharacterBehavior for Data { @@ -261,41 +261,23 @@ impl CharacterBehavior for Data { StageSection::Recover => { if self.timer < self.static_data.stage_data[stage_index].base_recover_duration { // Recovers - if ability_key_is_pressed(data, self.static_data.ability_info.key) { - // Checks if state will transition to next stage after recover - update.character = CharacterState::ComboMelee(Data { - static_data: self.static_data.clone(), - timer: self - .timer - .checked_add(Duration::from_secs_f32(data.dt.0 * speed_modifer)) - .unwrap_or_default(), - next_stage: true, - ..*self - }); - } else { - update.character = CharacterState::ComboMelee(Data { - static_data: self.static_data.clone(), - timer: self - .timer - .checked_add(Duration::from_secs_f32(data.dt.0 * speed_modifer)) - .unwrap_or_default(), - ..*self - }); - } - } else if self.next_stage { - // Transitions to buildup section of next stage update.character = CharacterState::ComboMelee(Data { static_data: self.static_data.clone(), - stage: (self.stage % self.static_data.num_stages) + 1, - timer: Duration::default(), - stage_section: StageSection::Buildup, - next_stage: false, + timer: self + .timer + .checked_add(Duration::from_secs_f32(data.dt.0 * speed_modifer)) + .unwrap_or_default(), + ..*self }); } else { // Done - update.character = CharacterState::Wielding; - // Make sure attack component is removed - data.updater.remove::(data.entity); + if self.end || self.static_data.ability_info.input.is_none() { + update.character = CharacterState::Wielding; + // Make sure attack component is removed + data.updater.remove::(data.entity); + } else { + reset_state(self, data, &mut update); + } } }, _ => { @@ -306,20 +288,27 @@ impl CharacterBehavior for Data { }, } - // Grant energy on successful hit - if let Some(attack) = data.melee_attack { - if attack.applied && attack.hit_count > 0 { - update.character = CharacterState::ComboMelee(Data { - static_data: self.static_data.clone(), - stage: self.stage, - timer: self.timer, - stage_section: self.stage_section, - next_stage: self.next_stage, - }); - data.updater.remove::(data.entity); + update + } + + fn cancel_input(&self, data: &JoinData, input: InputKind) -> StateUpdate { + let mut update = StateUpdate::from(data); + update.removed_inputs.push(input); + + if Some(input) == self.static_data.ability_info.input { + if let CharacterState::ComboMelee(c) = &mut update.character { + c.end = true; } } update } } + +fn reset_state(data: &Data, join: &JoinData, update: &mut StateUpdate) { + handle_input(join, update, data.static_data.ability_info.input.unwrap()); + + if let CharacterState::ComboMelee(c) = &mut update.character { + c.stage = (data.stage % data.static_data.num_stages) + 1; + } +} diff --git a/common/src/states/idle.rs b/common/src/states/idle.rs index a32728844e..89ef55d98b 100644 --- a/common/src/states/idle.rs +++ b/common/src/states/idle.rs @@ -1,7 +1,8 @@ use super::utils::*; use crate::{ - comp::{InventoryAction, StateUpdate}, + comp::{CharacterState, InputKind, InventoryAction, StateUpdate}, states::behavior::{CharacterBehavior, JoinData}, + uid::Uid, }; pub struct Data; @@ -19,6 +20,18 @@ impl CharacterBehavior for Data { update } + fn handle_input( + &self, + data: &JoinData, + _input: InputKind, + _target: Option, + ) -> StateUpdate { + let mut update = StateUpdate::from(data); + update.character = CharacterState::Wielding; + + update + } + fn wield(&self, data: &JoinData) -> StateUpdate { let mut update = StateUpdate::from(data); attempt_wield(data, &mut update); diff --git a/common/src/states/wielding.rs b/common/src/states/wielding.rs index 0bc4c069c9..0c904d17fd 100644 --- a/common/src/states/wielding.rs +++ b/common/src/states/wielding.rs @@ -26,14 +26,9 @@ impl CharacterBehavior for Data { update } - fn handle_input( - &self, - data: &JoinData, - ability: InputKind, - _target: Option, - ) -> StateUpdate { + fn handle_input(&self, data: &JoinData, input: InputKind, _target: Option) -> StateUpdate { let mut update = StateUpdate::from(data); - handle_input(&data, &mut update, ability); + handle_input(&data, &mut update, input); update } diff --git a/server/src/sys/agent.rs b/server/src/sys/agent.rs index 0d2ffc1920..5b2e837755 100644 --- a/server/src/sys/agent.rs +++ b/server/src/sys/agent.rs @@ -1082,7 +1082,7 @@ impl<'a> AgentData<'a> { Tactic::Melee => { if dist_sqrd < (min_attack_dist * self.scale).powi(2) { controller.actions.push(ControlAction::StartInput { - ability: InputKind::Primary, + input: InputKind::Primary, target: None, }); //controller.inputs.primary.set_state(true); @@ -1134,7 +1134,7 @@ impl<'a> AgentData<'a> { agent.action_timer += dt.0; } else { controller.actions.push(ControlAction::StartInput { - ability: InputKind::Primary, + input: InputKind::Primary, target: None, }); //controller.inputs.primary.set_state(true); @@ -1186,7 +1186,7 @@ impl<'a> AgentData<'a> { agent.action_timer += dt.0; } else { controller.actions.push(ControlAction::StartInput { - ability: InputKind::Primary, + input: InputKind::Primary, target: None, }); //controller.inputs.primary.set_state(true); @@ -1250,7 +1250,7 @@ impl<'a> AgentData<'a> { agent.action_timer = 0.0; } else { controller.actions.push(ControlAction::StartInput { - ability: InputKind::Primary, + input: InputKind::Primary, target: None, }); //controller.inputs.primary.set_state(true); @@ -1335,7 +1335,7 @@ impl<'a> AgentData<'a> { } else { controller.inputs.secondary.set_state(false); controller.actions.push(ControlAction::StartInput { - ability: InputKind::Primary, + input: InputKind::Primary, target: None, }); //controller.inputs.primary.set_state(true); @@ -1409,7 +1409,7 @@ impl<'a> AgentData<'a> { controller.inputs.secondary.set_state(true); } else { controller.actions.push(ControlAction::StartInput { - ability: InputKind::Primary, + input: InputKind::Primary, target: None, }); //controller.inputs.primary.set_state(true); @@ -1433,7 +1433,7 @@ impl<'a> AgentData<'a> { .unwrap_or_else(Vec2::zero) * speed; controller.actions.push(ControlAction::StartInput { - ability: InputKind::Primary, + input: InputKind::Primary, target: None, }); //controller.inputs.primary.set_state(true); @@ -1476,7 +1476,7 @@ impl<'a> AgentData<'a> { // large hitbox controller.inputs.move_dir = Vec2::zero(); controller.actions.push(ControlAction::StartInput { - ability: InputKind::Primary, + input: InputKind::Primary, target: None, }); //controller.inputs.primary.set_state(true); @@ -1522,7 +1522,7 @@ impl<'a> AgentData<'a> { { controller.inputs.move_dir = Vec2::zero(); controller.actions.push(ControlAction::StartInput { - ability: InputKind::Primary, + input: InputKind::Primary, target: None, }); //controller.inputs.primary.set_state(true); @@ -1584,7 +1584,7 @@ impl<'a> AgentData<'a> { .try_normalized() .unwrap_or_else(Vec2::unit_y); controller.actions.push(ControlAction::StartInput { - ability: InputKind::Primary, + input: InputKind::Primary, target: None, }); //controller.inputs.primary.set_state(true); @@ -1645,7 +1645,7 @@ impl<'a> AgentData<'a> { agent.action_timer = 0.0; } else if agent.action_timer > 1.0 { controller.actions.push(ControlAction::StartInput { - ability: InputKind::Primary, + input: InputKind::Primary, target: None, }); //controller.inputs.primary.set_state(true); @@ -1687,7 +1687,7 @@ impl<'a> AgentData<'a> { && dist_sqrd > (2.0 * min_attack_dist * self.scale).powi(2) { controller.actions.push(ControlAction::StartInput { - ability: InputKind::Primary, + input: InputKind::Primary, target: None, }); //controller.inputs.primary.set_state(true); @@ -1726,7 +1726,7 @@ impl<'a> AgentData<'a> { agent.action_timer += dt.0; } else { controller.actions.push(ControlAction::StartInput { - ability: InputKind::Primary, + input: InputKind::Primary, target: None, }); //controller.inputs.primary.set_state(true); @@ -1771,7 +1771,7 @@ impl<'a> AgentData<'a> { ) { if can_see_tgt(&*terrain, self.pos, tgt_pos, dist_sqrd) { controller.actions.push(ControlAction::StartInput { - ability: InputKind::Primary, + input: InputKind::Primary, target: None, }); //controller.inputs.primary.set_state(true); @@ -1796,7 +1796,7 @@ impl<'a> AgentData<'a> { agent.action_timer += dt.0; } else if agent.action_timer < 3.0 { controller.actions.push(ControlAction::StartInput { - ability: InputKind::Primary, + input: InputKind::Primary, target: None, }); //controller.inputs.primary.set_state(true); @@ -1836,7 +1836,7 @@ impl<'a> AgentData<'a> { .try_normalized() .unwrap_or_else(Vec2::unit_y); controller.actions.push(ControlAction::StartInput { - ability: InputKind::Primary, + input: InputKind::Primary, target: None, }); //controller.inputs.primary.set_state(true); @@ -1848,7 +1848,7 @@ impl<'a> AgentData<'a> { .try_normalized() .unwrap_or_else(Vec2::unit_y); controller.actions.push(ControlAction::StartInput { - ability: InputKind::Primary, + input: InputKind::Primary, target: None, }); //controller.inputs.primary.set_state(true); @@ -1883,7 +1883,7 @@ impl<'a> AgentData<'a> { if dist_sqrd < (2.0 * min_attack_dist * self.scale).powi(2) { controller.inputs.move_dir = Vec2::zero(); controller.actions.push(ControlAction::StartInput { - ability: InputKind::Primary, + input: InputKind::Primary, target: None, }); //controller.inputs.primary.set_state(true); @@ -1910,7 +1910,7 @@ impl<'a> AgentData<'a> { Tactic::Turret => { if can_see_tgt(&*terrain, self.pos, tgt_pos, dist_sqrd) { controller.actions.push(ControlAction::StartInput { - ability: InputKind::Primary, + input: InputKind::Primary, target: None, }); //controller.inputs.primary.set_state(true); @@ -1922,7 +1922,7 @@ impl<'a> AgentData<'a> { controller.inputs.look_dir = self.ori.look_dir(); if can_see_tgt(&*terrain, self.pos, tgt_pos, dist_sqrd) { controller.actions.push(ControlAction::StartInput { - ability: InputKind::Primary, + input: InputKind::Primary, target: None, }); //controller.inputs.primary.set_state(true); @@ -1940,7 +1940,7 @@ impl<'a> AgentData<'a> { ); if can_see_tgt(&*terrain, self.pos, tgt_pos, dist_sqrd) { controller.actions.push(ControlAction::StartInput { - ability: InputKind::Primary, + input: InputKind::Primary, target: None, }); //controller.inputs.primary.set_state(true); From b5d501199d4a6beaafba718f83e7e7ac6b80ea3a Mon Sep 17 00:00:00 2001 From: Sam Date: Fri, 12 Mar 2021 19:38:20 -0500 Subject: [PATCH 4/7] Secondary input now fully functional --- common/src/comp/ability.rs | 5 ++ common/src/comp/controller.rs | 16 ++-- common/src/states/basic_beam.rs | 4 +- common/src/states/basic_block.rs | 3 - common/src/states/charged_melee.rs | 25 +++++- common/src/states/charged_ranged.rs | 31 ++++++-- common/src/states/dash_melee.rs | 26 +++++-- common/src/states/healing_beam.rs | 21 ++++- common/src/states/spin_melee.rs | 19 ++++- common/src/states/utils.rs | 29 +++---- common/src/states/wielding.rs | 2 +- server/src/sys/agent.rs | 115 +++++++++++++++++++++++----- voxygen/src/session.rs | 5 +- 13 files changed, 234 insertions(+), 67 deletions(-) diff --git a/common/src/comp/ability.rs b/common/src/comp/ability.rs index 9de22f1034..eb887ebf43 100644 --- a/common/src/comp/ability.rs +++ b/common/src/comp/ability.rs @@ -1202,6 +1202,7 @@ impl From<(&CharacterAbility, AbilityInfo)> for CharacterState { refresh_distance: 0.0, stage_section: StageSection::Buildup, exhausted: false, + end: false, }), CharacterAbility::BasicBlock => CharacterState::BasicBlock, CharacterAbility::Roll { @@ -1319,6 +1320,7 @@ impl From<(&CharacterAbility, AbilityInfo)> for CharacterState { spins_remaining: *num_spins - 1, stage_section: StageSection::Buildup, exhausted: false, + end: false, }), CharacterAbility::ChargedMelee { energy_cost, @@ -1359,6 +1361,7 @@ impl From<(&CharacterAbility, AbilityInfo)> for CharacterState { timer: Duration::default(), exhausted: false, charge_amount: 0.0, + end: false, }), CharacterAbility::ChargedRanged { energy_cost: _, @@ -1399,6 +1402,7 @@ impl From<(&CharacterAbility, AbilityInfo)> for CharacterState { timer: Duration::default(), stage_section: StageSection::Buildup, exhausted: false, + end: false, }), CharacterAbility::RepeaterRanged { energy_cost: _, @@ -1545,6 +1549,7 @@ impl From<(&CharacterAbility, AbilityInfo)> for CharacterState { }, timer: Duration::default(), stage_section: StageSection::Buildup, + end: false, }), } } diff --git a/common/src/comp/controller.rs b/common/src/comp/controller.rs index 78db2fa100..89e84ef011 100644 --- a/common/src/comp/controller.rs +++ b/common/src/comp/controller.rs @@ -122,8 +122,8 @@ pub enum ControlAction { #[repr(u32)] pub enum InputKind { Primary = 0, - /* Secondary = 1, - * Ability(usize) = 2, + Secondary = 1, + /* Ability(usize) = 2, * Jump = 3, * Roll = 4, * Glide = 5, @@ -244,7 +244,7 @@ pub enum Climb { #[derive(Clone, Debug, Default, PartialEq, Serialize, Deserialize)] pub struct ControllerInputs { //pub primary: Input, - pub secondary: Input, + //pub secondary: Input, pub ability3: Input, pub ability4: Input, pub jump: Input, @@ -273,7 +273,7 @@ impl ControllerInputs { /// Updates all inputs, accounting for delta time pub fn tick(&mut self, dt: Duration) { //self.primary.tick(dt); - self.secondary.tick(dt); + // self.secondary.tick(dt); self.ability3.tick(dt); self.ability4.tick(dt); self.jump.tick(dt); @@ -286,7 +286,7 @@ impl ControllerInputs { pub fn tick_freshness(&mut self) { //self.primary.tick_freshness(); - self.secondary.tick_freshness(); + // self.secondary.tick_freshness(); self.ability3.tick_freshness(); self.ability4.tick_freshness(); self.jump.tick_freshness(); @@ -300,7 +300,7 @@ impl ControllerInputs { /// Updates Controller inputs with new version received from the client pub fn update_with_new(&mut self, new: Self) { //self.primary.update_with_new(new.primary); - self.secondary.update_with_new(new.secondary); + // self.secondary.update_with_new(new.secondary); self.ability3.update_with_new(new.ability3); self.ability4.update_with_new(new.ability4); self.jump.update_with_new(new.jump); @@ -316,8 +316,8 @@ impl ControllerInputs { } pub fn holding_ability_key(&self) -> bool { - //self.primary.is_pressed() || - self.secondary.is_pressed() || self.ability3.is_pressed() || self.ability4.is_pressed() + //self.primary.is_pressed() || self.secondary.is_pressed() || + self.ability3.is_pressed() || self.ability4.is_pressed() } } diff --git a/common/src/states/basic_beam.rs b/common/src/states/basic_beam.rs index dc5b992496..6a52c6ecaf 100644 --- a/common/src/states/basic_beam.rs +++ b/common/src/states/basic_beam.rs @@ -215,7 +215,9 @@ impl CharacterBehavior for Data { update.removed_inputs.push(input); if Some(input) == self.static_data.ability_info.input { - update.character = CharacterState::BasicBeam(Data { end: true, ..*self }); + if let CharacterState::BasicBeam(c) = &mut update.character { + c.end = true; + } } update diff --git a/common/src/states/basic_block.rs b/common/src/states/basic_block.rs index 487d9a6eb6..6db22268cf 100644 --- a/common/src/states/basic_block.rs +++ b/common/src/states/basic_block.rs @@ -17,9 +17,6 @@ impl CharacterBehavior for Data { handle_move(&data, &mut update, 0.4); - if !data.physics.on_ground || !data.inputs.secondary.is_pressed() { - attempt_wield(data, &mut update); - } update } } diff --git a/common/src/states/charged_melee.rs b/common/src/states/charged_melee.rs index f014913946..7720e17a3b 100644 --- a/common/src/states/charged_melee.rs +++ b/common/src/states/charged_melee.rs @@ -1,6 +1,6 @@ use crate::{ combat::{Attack, AttackDamage, AttackEffect, CombatBuff, CombatEffect, CombatRequirement}, - comp::{CharacterState, EnergyChange, EnergySource, Melee, StateUpdate}, + comp::{CharacterState, EnergyChange, EnergySource, InputKind, Melee, StateUpdate}, states::{ behavior::{CharacterBehavior, JoinData}, utils::{StageSection, *}, @@ -60,6 +60,8 @@ pub struct Data { pub exhausted: bool, /// How much the attack charged by pub charge_amount: f32, + /// Whether or not the state should end + pub end: bool, } impl CharacterBehavior for Data { @@ -80,7 +82,9 @@ impl CharacterBehavior for Data { match self.stage_section { StageSection::Charge => { - if ability_key_is_pressed(data, self.static_data.ability_info.key) + if + /* ability_key_is_pressed(data, self.static_data.ability_info.key) */ + !self.end && update.energy.current() as f32 >= self.static_data.energy_cost && self.timer < self.static_data.charge_duration { @@ -107,7 +111,9 @@ impl CharacterBehavior for Data { * self.static_data.speed) as i32, source: EnergySource::Ability, }); - } else if ability_key_is_pressed(data, self.static_data.ability_info.key) + } else if + /* ability_key_is_pressed(data, self.static_data.ability_info.key) */ + !self.end && update.energy.current() as f32 >= self.static_data.energy_cost { // Maintains charge @@ -242,4 +248,17 @@ impl CharacterBehavior for Data { update } + + fn cancel_input(&self, data: &JoinData, input: InputKind) -> StateUpdate { + let mut update = StateUpdate::from(data); + update.removed_inputs.push(input); + + if Some(input) == self.static_data.ability_info.input { + if let CharacterState::ChargedMelee(c) = &mut update.character { + c.end = true; + } + } + + update + } } diff --git a/common/src/states/charged_ranged.rs b/common/src/states/charged_ranged.rs index f28fd350de..68198a843e 100644 --- a/common/src/states/charged_ranged.rs +++ b/common/src/states/charged_ranged.rs @@ -4,8 +4,8 @@ use crate::{ DamageSource, GroupTarget, Knockback, KnockbackDir, }, comp::{ - projectile, Body, CharacterState, EnergyChange, EnergySource, Gravity, LightEmitter, - Projectile, StateUpdate, + projectile, Body, CharacterState, EnergyChange, EnergySource, Gravity, InputKind, + LightEmitter, Projectile, StateUpdate, }, event::ServerEvent, states::{ @@ -60,6 +60,8 @@ pub struct Data { pub stage_section: StageSection, /// Whether the attack fired already pub exhausted: bool, + /// Whether or not the state should end + pub end: bool, } impl CharacterBehavior for Data { @@ -99,9 +101,9 @@ impl CharacterBehavior for Data { } }, StageSection::Charge => { - if !ability_key_is_pressed(data, self.static_data.ability_info.key) - && !self.exhausted - { + if + /* \!ability_key_is_pressed(data, self.static_data.ability_info.key) */ + self.end && !self.exhausted { let charge_frac = (self.timer.as_secs_f32() / self.static_data.charge_duration.as_secs_f32()) .min(1.0); @@ -162,7 +164,7 @@ impl CharacterBehavior for Data { ..*self }); } else if self.timer < self.static_data.charge_duration - && ability_key_is_pressed(data, self.static_data.ability_info.key) + && /*ability_key_is_pressed(data, self.static_data.ability_info.key)*/ !self.end { // Charges update.character = CharacterState::ChargedRanged(Data { @@ -182,7 +184,9 @@ impl CharacterBehavior for Data { * self.static_data.speed) as i32, source: EnergySource::Ability, }); - } else if ability_key_is_pressed(data, self.static_data.ability_info.key) { + } else if + /* ability_key_is_pressed(data, self.static_data.ability_info.key) */ + !self.end { // Holds charge update.character = CharacterState::ChargedRanged(Data { timer: self @@ -227,4 +231,17 @@ impl CharacterBehavior for Data { update } + + fn cancel_input(&self, data: &JoinData, input: InputKind) -> StateUpdate { + let mut update = StateUpdate::from(data); + update.removed_inputs.push(input); + + if Some(input) == self.static_data.ability_info.input { + if let CharacterState::ChargedRanged(c) = &mut update.character { + c.end = true; + } + } + + update + } } diff --git a/common/src/states/dash_melee.rs b/common/src/states/dash_melee.rs index 0922f0e7bf..f487215510 100644 --- a/common/src/states/dash_melee.rs +++ b/common/src/states/dash_melee.rs @@ -1,6 +1,6 @@ use crate::{ combat::{Attack, AttackDamage, AttackEffect, CombatBuff, CombatEffect, CombatRequirement}, - comp::{CharacterState, EnergyChange, EnergySource, Melee, StateUpdate}, + comp::{CharacterState, EnergyChange, EnergySource, InputKind, Melee, StateUpdate}, states::{ behavior::{CharacterBehavior, JoinData}, utils::*, @@ -55,7 +55,8 @@ pub struct Data { /// Struct containing data that does not change over the course of the /// character state pub static_data: StaticData, - /// Whether the charge should end + /// Whether the charge should last a default amount of time or until the + /// mouse is released pub auto_charge: bool, /// Timer for each stage pub timer: Duration, @@ -65,6 +66,8 @@ pub struct Data { pub stage_section: StageSection, /// Whether the state should attempt attacking again pub exhausted: bool, + /// Whether or not the state should end + pub end: bool, } impl CharacterBehavior for Data { @@ -97,10 +100,10 @@ impl CharacterBehavior for Data { } else { // Transitions to charge section of stage update.character = CharacterState::DashMelee(Data { - auto_charge: !ability_key_is_pressed( + auto_charge: /*\!ability_key_is_pressed( data, self.static_data.ability_info.key, - ), + )*/self.end, timer: Duration::default(), stage_section: StageSection::Charge, ..*self @@ -110,7 +113,7 @@ impl CharacterBehavior for Data { StageSection::Charge => { if (self.static_data.infinite_charge || self.timer < self.static_data.charge_duration) - && (ability_key_is_pressed(data, self.static_data.ability_info.key) + && (/* ability_key_is_pressed(data, self.static_data.ability_info.key) */!self.end || (self.auto_charge && self.timer < self.static_data.charge_duration)) && update.energy.current() > 0 { @@ -267,4 +270,17 @@ impl CharacterBehavior for Data { update } + + fn cancel_input(&self, data: &JoinData, input: InputKind) -> StateUpdate { + let mut update = StateUpdate::from(data); + update.removed_inputs.push(input); + + if Some(input) == self.static_data.ability_info.input { + if let CharacterState::DashMelee(c) = &mut update.character { + c.end = true; + } + } + + update + } } diff --git a/common/src/states/healing_beam.rs b/common/src/states/healing_beam.rs index f5c950428e..fe7e2764d1 100644 --- a/common/src/states/healing_beam.rs +++ b/common/src/states/healing_beam.rs @@ -1,6 +1,6 @@ use crate::{ combat::{Attack, AttackEffect, CombatEffect, CombatRequirement, GroupTarget}, - comp::{beam, CharacterState, Ori, Pos, StateUpdate}, + comp::{beam, CharacterState, InputKind, Ori, Pos, StateUpdate}, event::ServerEvent, states::{ behavior::{CharacterBehavior, JoinData}, @@ -46,6 +46,8 @@ pub struct Data { pub timer: Duration, /// What section the character stage is in pub stage_section: StageSection, + /// Whether or not the state should end + pub end: bool, } impl CharacterBehavior for Data { @@ -91,7 +93,9 @@ impl CharacterBehavior for Data { } }, StageSection::Cast => { - if ability_key_is_pressed(data, self.static_data.ability_info.key) { + if + /* ability_key_is_pressed(data, self.static_data.ability_info.key) */ + !self.end { let speed = self.static_data.range / self.static_data.beam_duration.as_secs_f32(); let heal = AttackEffect::new( @@ -164,4 +168,17 @@ impl CharacterBehavior for Data { update } + + fn cancel_input(&self, data: &JoinData, input: InputKind) -> StateUpdate { + let mut update = StateUpdate::from(data); + update.removed_inputs.push(input); + + if Some(input) == self.static_data.ability_info.input { + if let CharacterState::HealingBeam(c) = &mut update.character { + c.end = true; + } + } + + update + } } diff --git a/common/src/states/spin_melee.rs b/common/src/states/spin_melee.rs index 18548937b6..2fe51f18dd 100644 --- a/common/src/states/spin_melee.rs +++ b/common/src/states/spin_melee.rs @@ -1,6 +1,6 @@ use crate::{ combat::{Attack, AttackDamage, AttackEffect, CombatBuff, CombatEffect, CombatRequirement}, - comp::{CharacterState, EnergyChange, EnergySource, Melee, StateUpdate}, + comp::{CharacterState, EnergyChange, EnergySource, InputKind, Melee, StateUpdate}, consts::GRAVITY, states::{ behavior::{CharacterBehavior, JoinData}, @@ -58,6 +58,8 @@ pub struct Data { pub stage_section: StageSection, /// Whether the state can deal damage pub exhausted: bool, + /// Whether or not the state should end + pub end: bool, } impl CharacterBehavior for Data { @@ -179,7 +181,7 @@ impl CharacterBehavior for Data { } else if update.energy.current() as f32 >= self.static_data.energy_cost && (self.spins_remaining != 0 || (self.static_data.is_infinite - && ability_key_is_pressed(data, self.static_data.ability_info.key))) + && /*ability_key_is_pressed(data, self.static_data.ability_info.key)*/ !self.end)) { let new_spins_remaining = if self.static_data.is_infinite { self.spins_remaining @@ -233,6 +235,19 @@ impl CharacterBehavior for Data { update } + + fn cancel_input(&self, data: &JoinData, input: InputKind) -> StateUpdate { + let mut update = StateUpdate::from(data); + update.removed_inputs.push(input); + + if Some(input) == self.static_data.ability_info.input { + if let CharacterState::SpinMelee(c) = &mut update.character { + c.end = true; + } + } + + update + } } #[derive(Copy, Clone, Debug, PartialEq, Serialize, Deserialize)] diff --git a/common/src/states/utils.rs b/common/src/states/utils.rs index b39c32f60a..5a42c05cf5 100644 --- a/common/src/states/utils.rs +++ b/common/src/states/utils.rs @@ -315,12 +315,8 @@ fn fly_move(data: &JoinData, update: &mut StateUpdate, efficiency: f32) { /// is pressed, then attempts to go into Equipping state, otherwise Idle pub fn handle_wield(data: &JoinData, update: &mut StateUpdate) { if - /*data.inputs.primary.is_pressed() - || */ - data.inputs.secondary.is_pressed() - || data.inputs.ability3.is_pressed() - || data.inputs.ability4.is_pressed() - { + // data.inputs.primary.is_pressed() || data.inputs.secondary.is_pressed() || + data.inputs.ability3.is_pressed() || data.inputs.ability4.is_pressed() { attempt_wield(data, update); } } @@ -504,6 +500,9 @@ fn handle_ability_pressed( pub fn handle_input(data: &JoinData, update: &mut StateUpdate, input: InputKind) { match input { InputKind::Primary => handle_ability_pressed(data, update, AbilityKey::Mouse1, Some(input)), + InputKind::Secondary => { + handle_ability_pressed(data, update, AbilityKey::Mouse2, Some(input)) + }, } } @@ -513,11 +512,11 @@ pub fn handle_input(data: &JoinData, update: &mut StateUpdate, input: InputKind) } }*/ -pub fn handle_ability2_input(data: &JoinData, update: &mut StateUpdate) { - if data.inputs.secondary.is_pressed() { - handle_ability_pressed(data, update, AbilityKey::Mouse2, None); - } -} +// pub fn handle_ability2_input(data: &JoinData, update: &mut StateUpdate) { +// if data.inputs.secondary.is_pressed() { +// handle_ability_pressed(data, update, AbilityKey::Mouse2, None); +// } +// } pub fn handle_ability3_input(data: &JoinData, update: &mut StateUpdate) { if data.inputs.ability3.is_pressed() { @@ -614,7 +613,7 @@ pub fn get_crit_data(data: &JoinData, ai: AbilityInfo) -> (f32, f32) { pub fn handle_interrupt(data: &JoinData, update: &mut StateUpdate, attacks_interrupt: bool) { if attacks_interrupt { //handle_ability1_input(data, update); - handle_ability2_input(data, update); + // handle_ability2_input(data, update); handle_ability3_input(data, update); handle_ability4_input(data, update); } @@ -628,7 +627,11 @@ pub fn ability_key_is_pressed(data: &JoinData, ability_key: AbilityKey) -> bool { false }, - AbilityKey::Mouse2 => data.inputs.secondary.is_pressed(), + AbilityKey::Mouse2 => + /* data.inputs.secondary.is_pressed() */ + { + false + }, AbilityKey::Skill1 => data.inputs.ability3.is_pressed(), AbilityKey::Skill2 => data.inputs.ability4.is_pressed(), AbilityKey::Dodge => data.inputs.roll.is_pressed(), diff --git a/common/src/states/wielding.rs b/common/src/states/wielding.rs index 0c904d17fd..cba173261a 100644 --- a/common/src/states/wielding.rs +++ b/common/src/states/wielding.rs @@ -18,7 +18,7 @@ impl CharacterBehavior for Data { handle_jump(&data, &mut update); handle_climb(&data, &mut update); //handle_ability1_input(&data, &mut update); - handle_ability2_input(&data, &mut update); + // handle_ability2_input(&data, &mut update); handle_ability3_input(&data, &mut update); handle_ability4_input(&data, &mut update); handle_dodge_input(&data, &mut update); diff --git a/server/src/sys/agent.rs b/server/src/sys/agent.rs index 5b2e837755..1d6cac847e 100644 --- a/server/src/sys/agent.rs +++ b/server/src/sys/agent.rs @@ -1118,10 +1118,17 @@ impl<'a> AgentData<'a> { if dist_sqrd < (min_attack_dist * self.scale).powi(2) { controller.inputs.move_dir = Vec2::zero(); if agent.action_timer > 6.0 { - controller.inputs.secondary.set_state(false); + controller + .actions + .push(ControlAction::CancelInput(InputKind::Secondary)); + // controller.inputs.secondary.set_state(false); agent.action_timer = 0.0; } else if agent.action_timer > 4.0 && self.energy.current() > 10 { - controller.inputs.secondary.set_state(true); + controller.actions.push(ControlAction::StartInput { + input: InputKind::Secondary, + target: None, + }); + // controller.inputs.secondary.set_state(true); agent.action_timer += dt.0; } else if self .stats @@ -1170,10 +1177,17 @@ impl<'a> AgentData<'a> { if dist_sqrd < (min_attack_dist * self.scale).powi(2) { controller.inputs.move_dir = Vec2::zero(); if agent.action_timer > 4.0 { - controller.inputs.secondary.set_state(false); + controller + .actions + .push(ControlAction::CancelInput(InputKind::Secondary)); + // controller.inputs.secondary.set_state(false); agent.action_timer = 0.0; } else if agent.action_timer > 2.0 { - controller.inputs.secondary.set_state(true); + controller.actions.push(ControlAction::StartInput { + input: InputKind::Secondary, + target: None, + }); + // controller.inputs.secondary.set_state(true); agent.action_timer += dt.0; } else if self .stats @@ -1271,7 +1285,11 @@ impl<'a> AgentData<'a> { controller.inputs.move_dir = bearing.xy().try_normalized().unwrap_or_else(Vec2::zero) * speed; if agent.action_timer > 4.0 { - controller.inputs.secondary.set_state(true); + controller.actions.push(ControlAction::StartInput { + input: InputKind::Secondary, + target: None, + }); + // controller.inputs.secondary.set_state(true); agent.action_timer = 0.0; } else { agent.action_timer += dt.0; @@ -1317,10 +1335,17 @@ impl<'a> AgentData<'a> { .unwrap_or_else(Vec2::zero) * speed; if agent.action_timer > 4.0 { - controller.inputs.secondary.set_state(false); + controller + .actions + .push(ControlAction::CancelInput(InputKind::Secondary)); + // controller.inputs.secondary.set_state(false); agent.action_timer = 0.0; } else if agent.action_timer > 2.0 && self.energy.current() > 300 { - controller.inputs.secondary.set_state(true); + controller.actions.push(ControlAction::StartInput { + input: InputKind::Secondary, + target: None, + }); + // controller.inputs.secondary.set_state(true); agent.action_timer += dt.0; } else if self .stats @@ -1329,11 +1354,17 @@ impl<'a> AgentData<'a> { && self.energy.current() > 400 && thread_rng().gen_bool(0.8) { - controller.inputs.secondary.set_state(false); + controller + .actions + .push(ControlAction::CancelInput(InputKind::Secondary)); + // controller.inputs.secondary.set_state(false); controller.inputs.ability3.set_state(true); agent.action_timer += dt.0; } else { - controller.inputs.secondary.set_state(false); + controller + .actions + .push(ControlAction::CancelInput(InputKind::Secondary)); + // controller.inputs.secondary.set_state(false); controller.actions.push(ControlAction::StartInput { input: InputKind::Primary, target: None, @@ -1406,7 +1437,11 @@ impl<'a> AgentData<'a> { { controller.inputs.ability3.set_state(true); } else if self.energy.current() > 10 { - controller.inputs.secondary.set_state(true); + controller.actions.push(ControlAction::StartInput { + input: InputKind::Secondary, + target: None, + }); + // controller.inputs.secondary.set_state(true); } else { controller.actions.push(ControlAction::StartInput { input: InputKind::Primary, @@ -1498,7 +1533,11 @@ impl<'a> AgentData<'a> { controller.inputs.move_dir = bearing.xy().try_normalized().unwrap_or_else(Vec2::zero) * speed; if agent.action_timer > 5.0 { - controller.inputs.secondary.set_state(true); + controller.actions.push(ControlAction::StartInput { + input: InputKind::Secondary, + target: None, + }); + // controller.inputs.secondary.set_state(true); agent.action_timer = 0.0; } else { agent.action_timer += dt.0; @@ -1542,7 +1581,11 @@ impl<'a> AgentData<'a> { .unwrap_or_else(Vec2::unit_y); agent.action_timer += dt.0; } else if agent.action_timer < circle_time as f32 + 0.5 { - controller.inputs.secondary.set_state(true); + controller.actions.push(ControlAction::StartInput { + input: InputKind::Secondary, + target: None, + }); + // controller.inputs.secondary.set_state(true); agent.action_timer += dt.0; } else if agent.action_timer < 2.0 * circle_time as f32 + 0.5 { controller.inputs.move_dir = (tgt_pos.0 - self.pos.0) @@ -1552,7 +1595,11 @@ impl<'a> AgentData<'a> { .unwrap_or_else(Vec2::unit_y); agent.action_timer += dt.0; } else if agent.action_timer < 2.0 * circle_time as f32 + 1.0 { - controller.inputs.secondary.set_state(true); + controller.actions.push(ControlAction::StartInput { + input: InputKind::Secondary, + target: None, + }); + // controller.inputs.secondary.set_state(true); agent.action_timer += dt.0; } else { agent.action_timer = 0.0; @@ -1619,7 +1666,11 @@ impl<'a> AgentData<'a> { * speed; agent.action_timer += dt.0; } - controller.inputs.secondary.set_state(true); + controller.actions.push(ControlAction::StartInput { + input: InputKind::Secondary, + target: None, + }); + // controller.inputs.secondary.set_state(true); controller.inputs.jump.set_state(bearing.z > 1.5); controller.inputs.move_z = bearing.z; } else { @@ -1651,7 +1702,11 @@ impl<'a> AgentData<'a> { //controller.inputs.primary.set_state(true); agent.action_timer += dt.0; } else { - controller.inputs.secondary.set_state(true); + controller.actions.push(ControlAction::StartInput { + input: InputKind::Secondary, + target: None, + }); + // controller.inputs.secondary.set_state(true); agent.action_timer += dt.0; } controller.inputs.move_dir = (tgt_pos.0 - self.pos.0) @@ -1682,7 +1737,11 @@ impl<'a> AgentData<'a> { Tactic::QuadLowQuick => { if dist_sqrd < (1.5 * min_attack_dist * self.scale).powi(2) { controller.inputs.move_dir = Vec2::zero(); - controller.inputs.secondary.set_state(true); + controller.actions.push(ControlAction::StartInput { + input: InputKind::Secondary, + target: None, + }); + // controller.inputs.secondary.set_state(true); } else if dist_sqrd < (3.0 * min_attack_dist * self.scale).powi(2) && dist_sqrd > (2.0 * min_attack_dist * self.scale).powi(2) { @@ -1722,7 +1781,11 @@ impl<'a> AgentData<'a> { if agent.action_timer > 5.0 { agent.action_timer = 0.0; } else if agent.action_timer > 2.0 { - controller.inputs.secondary.set_state(true); + controller.actions.push(ControlAction::StartInput { + input: InputKind::Secondary, + target: None, + }); + // controller.inputs.secondary.set_state(true); agent.action_timer += dt.0; } else { controller.actions.push(ControlAction::StartInput { @@ -1755,7 +1818,11 @@ impl<'a> AgentData<'a> { Tactic::QuadMedJump => { if dist_sqrd < (1.5 * min_attack_dist * self.scale).powi(2) { controller.inputs.move_dir = Vec2::zero(); - controller.inputs.secondary.set_state(true); + controller.actions.push(ControlAction::StartInput { + input: InputKind::Secondary, + target: None, + }); + // controller.inputs.secondary.set_state(true); } else if dist_sqrd < (5.0 * min_attack_dist * self.scale).powi(2) { controller.inputs.ability3.set_state(true); } else if dist_sqrd < MAX_CHASE_DIST.powi(2) { @@ -1792,7 +1859,11 @@ impl<'a> AgentData<'a> { if dist_sqrd < (min_attack_dist * self.scale).powi(2) { controller.inputs.move_dir = Vec2::zero(); if agent.action_timer < 2.0 { - controller.inputs.secondary.set_state(true); + controller.actions.push(ControlAction::StartInput { + input: InputKind::Secondary, + target: None, + }); + // controller.inputs.secondary.set_state(true); agent.action_timer += dt.0; } else if agent.action_timer < 3.0 { controller.actions.push(ControlAction::StartInput { @@ -1827,7 +1898,11 @@ impl<'a> AgentData<'a> { Tactic::Lavadrake | Tactic::QuadLowBeam => { if dist_sqrd < (2.5 * min_attack_dist * self.scale).powi(2) { controller.inputs.move_dir = Vec2::zero(); - controller.inputs.secondary.set_state(true); + controller.actions.push(ControlAction::StartInput { + input: InputKind::Secondary, + target: None, + }); + // controller.inputs.secondary.set_state(true); } else if dist_sqrd < (7.0 * min_attack_dist * self.scale).powi(2) { if agent.action_timer < 2.0 { controller.inputs.move_dir = (tgt_pos.0 - self.pos.0) diff --git a/voxygen/src/session.rs b/voxygen/src/session.rs index 17ab13b253..e8561cb88a 100644 --- a/voxygen/src/session.rs +++ b/voxygen/src/session.rs @@ -372,7 +372,7 @@ impl PlayState for SessionState { } }, GameInput::Secondary => { - self.inputs.secondary.set_state(false); // To be changed later on + // self.inputs.secondary.set_state(false); // To be changed later on let mut client = self.client.borrow_mut(); @@ -381,7 +381,8 @@ impl PlayState for SessionState { client.place_block(build_pos, self.selected_block); } } else { - self.inputs.secondary.set_state(state); + client.handle_input(InputKind::Secondary, state); + // self.inputs.secondary.set_state(state); } }, GameInput::Roll => { From be27289a7f5753f79e8177ac101144cfe9a9f139 Mon Sep 17 00:00:00 2001 From: Sam Date: Sun, 14 Mar 2021 11:19:22 -0400 Subject: [PATCH 5/7] Inputs remain in queue while active, allowing interrupts and queued inputs to be more cleanly handled --- common/src/comp/ability.rs | 10 ---------- common/src/states/basic_beam.rs | 19 ++----------------- common/src/states/basic_melee.rs | 25 ++++--------------------- common/src/states/basic_ranged.rs | 25 ++++--------------------- common/src/states/boost.rs | 23 ++++------------------- common/src/states/charged_melee.rs | 21 +++------------------ common/src/states/charged_ranged.rs | 25 +++++-------------------- common/src/states/combo_melee.rs | 25 ++++--------------------- common/src/states/dash_melee.rs | 21 +++------------------ common/src/states/healing_beam.rs | 19 ++----------------- common/src/states/idle.rs | 15 +-------------- common/src/states/spin_melee.rs | 19 ++----------------- common/src/states/utils.rs | 14 ++++++++++++++ common/src/states/wielding.rs | 10 ++-------- 14 files changed, 50 insertions(+), 221 deletions(-) diff --git a/common/src/comp/ability.rs b/common/src/comp/ability.rs index eb887ebf43..f347eec68b 100644 --- a/common/src/comp/ability.rs +++ b/common/src/comp/ability.rs @@ -1120,7 +1120,6 @@ impl From<(&CharacterAbility, AbilityInfo)> for CharacterState { timer: Duration::default(), stage_section: StageSection::Buildup, exhausted: false, - end: false, }), CharacterAbility::BasicRanged { buildup_duration, @@ -1145,7 +1144,6 @@ impl From<(&CharacterAbility, AbilityInfo)> for CharacterState { timer: Duration::default(), stage_section: StageSection::Buildup, exhausted: false, - end: false, }), CharacterAbility::Boost { movement_duration, @@ -1157,7 +1155,6 @@ impl From<(&CharacterAbility, AbilityInfo)> for CharacterState { ability_info, }, timer: Duration::default(), - end: false, }), CharacterAbility::DashMelee { energy_cost: _, @@ -1202,7 +1199,6 @@ impl From<(&CharacterAbility, AbilityInfo)> for CharacterState { refresh_distance: 0.0, stage_section: StageSection::Buildup, exhausted: false, - end: false, }), CharacterAbility::BasicBlock => CharacterState::BasicBlock, CharacterAbility::Roll { @@ -1251,7 +1247,6 @@ impl From<(&CharacterAbility, AbilityInfo)> for CharacterState { stage: 1, timer: Duration::default(), stage_section: StageSection::Buildup, - end: false, }), CharacterAbility::LeapMelee { energy_cost: _, @@ -1320,7 +1315,6 @@ impl From<(&CharacterAbility, AbilityInfo)> for CharacterState { spins_remaining: *num_spins - 1, stage_section: StageSection::Buildup, exhausted: false, - end: false, }), CharacterAbility::ChargedMelee { energy_cost, @@ -1361,7 +1355,6 @@ impl From<(&CharacterAbility, AbilityInfo)> for CharacterState { timer: Duration::default(), exhausted: false, charge_amount: 0.0, - end: false, }), CharacterAbility::ChargedRanged { energy_cost: _, @@ -1402,7 +1395,6 @@ impl From<(&CharacterAbility, AbilityInfo)> for CharacterState { timer: Duration::default(), stage_section: StageSection::Buildup, exhausted: false, - end: false, }), CharacterAbility::RepeaterRanged { energy_cost: _, @@ -1499,7 +1491,6 @@ impl From<(&CharacterAbility, AbilityInfo)> for CharacterState { }, timer: Duration::default(), stage_section: StageSection::Buildup, - end: false, }), CharacterAbility::BasicAura { buildup_duration, @@ -1549,7 +1540,6 @@ impl From<(&CharacterAbility, AbilityInfo)> for CharacterState { }, timer: Duration::default(), stage_section: StageSection::Buildup, - end: false, }), } } diff --git a/common/src/states/basic_beam.rs b/common/src/states/basic_beam.rs index 6a52c6ecaf..c75da30133 100644 --- a/common/src/states/basic_beam.rs +++ b/common/src/states/basic_beam.rs @@ -3,7 +3,7 @@ use crate::{ Attack, AttackDamage, AttackEffect, CombatEffect, CombatRequirement, Damage, DamageSource, GroupTarget, }, - comp::{beam, CharacterState, EnergyChange, EnergySource, InputKind, Ori, Pos, StateUpdate}, + comp::{beam, CharacterState, EnergyChange, EnergySource, Ori, Pos, StateUpdate}, event::ServerEvent, states::{ behavior::{CharacterBehavior, JoinData}, @@ -56,8 +56,6 @@ pub struct Data { pub timer: Duration, /// What section the character stage is in pub stage_section: StageSection, - /// Whether or not the state should end - pub end: bool, } impl CharacterBehavior for Data { @@ -112,7 +110,7 @@ impl CharacterBehavior for Data { StageSection::Cast => { if /* ability_key_is_pressed(data, self.static_data.ability_info.key) */ - !self.end + input_is_pressed(data, self.static_data.ability_info) && (self.static_data.energy_drain <= f32::EPSILON || update.energy.current() > 0) { @@ -209,19 +207,6 @@ impl CharacterBehavior for Data { update } - - fn cancel_input(&self, data: &JoinData, input: InputKind) -> StateUpdate { - let mut update = StateUpdate::from(data); - update.removed_inputs.push(input); - - if Some(input) == self.static_data.ability_info.input { - if let CharacterState::BasicBeam(c) = &mut update.character { - c.end = true; - } - } - - update - } } #[derive(Copy, Clone, Debug, PartialEq, Serialize, Deserialize)] diff --git a/common/src/states/basic_melee.rs b/common/src/states/basic_melee.rs index 16c01b3191..66c02b28df 100644 --- a/common/src/states/basic_melee.rs +++ b/common/src/states/basic_melee.rs @@ -1,6 +1,6 @@ use crate::{ combat::{Attack, AttackDamage, AttackEffect, CombatBuff, CombatEffect, CombatRequirement}, - comp::{CharacterState, InputKind, Melee, StateUpdate}, + comp::{CharacterState, Melee, StateUpdate}, states::{ behavior::{CharacterBehavior, JoinData}, utils::*, @@ -44,8 +44,6 @@ pub struct Data { pub stage_section: StageSection, /// Whether the attack can deal more damage pub exhausted: bool, - /// Whether or not the state should end - pub end: bool, } impl CharacterBehavior for Data { @@ -164,12 +162,10 @@ impl CharacterBehavior for Data { }); } else { // Done - if self.end || self.static_data.ability_info.input.is_none() { - update.character = CharacterState::Wielding; - // Make sure attack component is removed - data.updater.remove::(data.entity); - } else { + if input_is_pressed(data, self.static_data.ability_info) { reset_state(self, data, &mut update); + } else { + update.character = CharacterState::Wielding; } } }, @@ -183,19 +179,6 @@ impl CharacterBehavior for Data { update } - - fn cancel_input(&self, data: &JoinData, input: InputKind) -> StateUpdate { - let mut update = StateUpdate::from(data); - update.removed_inputs.push(input); - - if Some(input) == self.static_data.ability_info.input { - if let CharacterState::BasicMelee(c) = &mut update.character { - c.end = true; - } - } - - update - } } fn reset_state(data: &Data, join: &JoinData, update: &mut StateUpdate) { diff --git a/common/src/states/basic_ranged.rs b/common/src/states/basic_ranged.rs index 128a017804..806bbf6b64 100644 --- a/common/src/states/basic_ranged.rs +++ b/common/src/states/basic_ranged.rs @@ -1,7 +1,5 @@ use crate::{ - comp::{ - Body, CharacterState, Gravity, InputKind, LightEmitter, ProjectileConstructor, StateUpdate, - }, + comp::{Body, CharacterState, Gravity, LightEmitter, ProjectileConstructor, StateUpdate}, event::ServerEvent, states::{ behavior::{CharacterBehavior, JoinData}, @@ -39,8 +37,6 @@ pub struct Data { pub stage_section: StageSection, /// Whether the attack fired already pub exhausted: bool, - /// Whether or not the state should end - pub end: bool, } impl CharacterBehavior for Data { @@ -115,10 +111,10 @@ impl CharacterBehavior for Data { }); } else { // Done - if self.end || self.static_data.ability_info.input.is_none() { - update.character = CharacterState::Wielding; - } else { + if input_is_pressed(data, self.static_data.ability_info) { reset_state(self, data, &mut update); + } else { + update.character = CharacterState::Wielding; } } }, @@ -130,19 +126,6 @@ impl CharacterBehavior for Data { update } - - fn cancel_input(&self, data: &JoinData, input: InputKind) -> StateUpdate { - let mut update = StateUpdate::from(data); - update.removed_inputs.push(input); - - if Some(input) == self.static_data.ability_info.input { - if let CharacterState::BasicRanged(c) = &mut update.character { - c.end = true; - } - } - - update - } } fn reset_state(data: &Data, join: &JoinData, update: &mut StateUpdate) { diff --git a/common/src/states/boost.rs b/common/src/states/boost.rs index 5dbd911b15..76f5b32b78 100644 --- a/common/src/states/boost.rs +++ b/common/src/states/boost.rs @@ -1,5 +1,5 @@ use crate::{ - comp::{CharacterState, InputKind, StateUpdate}, + comp::{CharacterState, StateUpdate}, states::{ behavior::{CharacterBehavior, JoinData}, utils::*, @@ -23,8 +23,6 @@ pub struct Data { pub static_data: StaticData, /// Timer for each stage pub timer: Duration, - /// Whether or not the state should end - pub end: bool, } impl CharacterBehavior for Data { @@ -49,23 +47,10 @@ impl CharacterBehavior for Data { }); } else { // Done - if self.end || self.static_data.ability_info.input.is_none() { - update.character = CharacterState::Wielding; - } else { + if input_is_pressed(data, self.static_data.ability_info) { reset_state(self, data, &mut update); - } - } - - update - } - - fn cancel_input(&self, data: &JoinData, input: InputKind) -> StateUpdate { - let mut update = StateUpdate::from(data); - update.removed_inputs.push(input); - - if Some(input) == self.static_data.ability_info.input { - if let CharacterState::Boost(c) = &mut update.character { - c.end = true; + } else { + update.character = CharacterState::Wielding; } } diff --git a/common/src/states/charged_melee.rs b/common/src/states/charged_melee.rs index 7720e17a3b..c350052a02 100644 --- a/common/src/states/charged_melee.rs +++ b/common/src/states/charged_melee.rs @@ -1,6 +1,6 @@ use crate::{ combat::{Attack, AttackDamage, AttackEffect, CombatBuff, CombatEffect, CombatRequirement}, - comp::{CharacterState, EnergyChange, EnergySource, InputKind, Melee, StateUpdate}, + comp::{CharacterState, EnergyChange, EnergySource, Melee, StateUpdate}, states::{ behavior::{CharacterBehavior, JoinData}, utils::{StageSection, *}, @@ -60,8 +60,6 @@ pub struct Data { pub exhausted: bool, /// How much the attack charged by pub charge_amount: f32, - /// Whether or not the state should end - pub end: bool, } impl CharacterBehavior for Data { @@ -84,7 +82,7 @@ impl CharacterBehavior for Data { StageSection::Charge => { if /* ability_key_is_pressed(data, self.static_data.ability_info.key) */ - !self.end + input_is_pressed(data, self.static_data.ability_info) && update.energy.current() as f32 >= self.static_data.energy_cost && self.timer < self.static_data.charge_duration { @@ -113,7 +111,7 @@ impl CharacterBehavior for Data { }); } else if /* ability_key_is_pressed(data, self.static_data.ability_info.key) */ - !self.end + input_is_pressed(data, self.static_data.ability_info) && update.energy.current() as f32 >= self.static_data.energy_cost { // Maintains charge @@ -248,17 +246,4 @@ impl CharacterBehavior for Data { update } - - fn cancel_input(&self, data: &JoinData, input: InputKind) -> StateUpdate { - let mut update = StateUpdate::from(data); - update.removed_inputs.push(input); - - if Some(input) == self.static_data.ability_info.input { - if let CharacterState::ChargedMelee(c) = &mut update.character { - c.end = true; - } - } - - update - } } diff --git a/common/src/states/charged_ranged.rs b/common/src/states/charged_ranged.rs index 68198a843e..9a27eb4a7b 100644 --- a/common/src/states/charged_ranged.rs +++ b/common/src/states/charged_ranged.rs @@ -4,8 +4,8 @@ use crate::{ DamageSource, GroupTarget, Knockback, KnockbackDir, }, comp::{ - projectile, Body, CharacterState, EnergyChange, EnergySource, Gravity, InputKind, - LightEmitter, Projectile, StateUpdate, + projectile, Body, CharacterState, EnergyChange, EnergySource, Gravity, LightEmitter, + Projectile, StateUpdate, }, event::ServerEvent, states::{ @@ -60,8 +60,6 @@ pub struct Data { pub stage_section: StageSection, /// Whether the attack fired already pub exhausted: bool, - /// Whether or not the state should end - pub end: bool, } impl CharacterBehavior for Data { @@ -103,7 +101,7 @@ impl CharacterBehavior for Data { StageSection::Charge => { if /* \!ability_key_is_pressed(data, self.static_data.ability_info.key) */ - self.end && !self.exhausted { + !input_is_pressed(data, self.static_data.ability_info) && !self.exhausted { let charge_frac = (self.timer.as_secs_f32() / self.static_data.charge_duration.as_secs_f32()) .min(1.0); @@ -164,7 +162,7 @@ impl CharacterBehavior for Data { ..*self }); } else if self.timer < self.static_data.charge_duration - && /*ability_key_is_pressed(data, self.static_data.ability_info.key)*/ !self.end + && /*ability_key_is_pressed(data, self.static_data.ability_info.key)*/ input_is_pressed(data, self.static_data.ability_info) { // Charges update.character = CharacterState::ChargedRanged(Data { @@ -186,7 +184,7 @@ impl CharacterBehavior for Data { }); } else if /* ability_key_is_pressed(data, self.static_data.ability_info.key) */ - !self.end { + input_is_pressed(data, self.static_data.ability_info) { // Holds charge update.character = CharacterState::ChargedRanged(Data { timer: self @@ -231,17 +229,4 @@ impl CharacterBehavior for Data { update } - - fn cancel_input(&self, data: &JoinData, input: InputKind) -> StateUpdate { - let mut update = StateUpdate::from(data); - update.removed_inputs.push(input); - - if Some(input) == self.static_data.ability_info.input { - if let CharacterState::ChargedRanged(c) = &mut update.character { - c.end = true; - } - } - - update - } } diff --git a/common/src/states/combo_melee.rs b/common/src/states/combo_melee.rs index 9696503e43..6bcb8f2881 100644 --- a/common/src/states/combo_melee.rs +++ b/common/src/states/combo_melee.rs @@ -1,6 +1,6 @@ use crate::{ combat::{Attack, AttackDamage, AttackEffect, CombatBuff, CombatEffect, CombatRequirement}, - comp::{CharacterState, InputKind, Melee, StateUpdate}, + comp::{CharacterState, Melee, StateUpdate}, states::{ behavior::{CharacterBehavior, JoinData}, utils::*, @@ -113,8 +113,6 @@ pub struct Data { pub timer: Duration, /// Checks what section a stage is in pub stage_section: StageSection, - /// Whether or not the state should end - pub end: bool, } impl CharacterBehavior for Data { @@ -271,12 +269,10 @@ impl CharacterBehavior for Data { }); } else { // Done - if self.end || self.static_data.ability_info.input.is_none() { - update.character = CharacterState::Wielding; - // Make sure attack component is removed - data.updater.remove::(data.entity); - } else { + if input_is_pressed(data, self.static_data.ability_info) { reset_state(self, data, &mut update); + } else { + update.character = CharacterState::Wielding; } } }, @@ -290,19 +286,6 @@ impl CharacterBehavior for Data { update } - - fn cancel_input(&self, data: &JoinData, input: InputKind) -> StateUpdate { - let mut update = StateUpdate::from(data); - update.removed_inputs.push(input); - - if Some(input) == self.static_data.ability_info.input { - if let CharacterState::ComboMelee(c) = &mut update.character { - c.end = true; - } - } - - update - } } fn reset_state(data: &Data, join: &JoinData, update: &mut StateUpdate) { diff --git a/common/src/states/dash_melee.rs b/common/src/states/dash_melee.rs index f487215510..753e17889b 100644 --- a/common/src/states/dash_melee.rs +++ b/common/src/states/dash_melee.rs @@ -1,6 +1,6 @@ use crate::{ combat::{Attack, AttackDamage, AttackEffect, CombatBuff, CombatEffect, CombatRequirement}, - comp::{CharacterState, EnergyChange, EnergySource, InputKind, Melee, StateUpdate}, + comp::{CharacterState, EnergyChange, EnergySource, Melee, StateUpdate}, states::{ behavior::{CharacterBehavior, JoinData}, utils::*, @@ -66,8 +66,6 @@ pub struct Data { pub stage_section: StageSection, /// Whether the state should attempt attacking again pub exhausted: bool, - /// Whether or not the state should end - pub end: bool, } impl CharacterBehavior for Data { @@ -103,7 +101,7 @@ impl CharacterBehavior for Data { auto_charge: /*\!ability_key_is_pressed( data, self.static_data.ability_info.key, - )*/self.end, + )*/input_is_pressed(data, self.static_data.ability_info), timer: Duration::default(), stage_section: StageSection::Charge, ..*self @@ -113,7 +111,7 @@ impl CharacterBehavior for Data { StageSection::Charge => { if (self.static_data.infinite_charge || self.timer < self.static_data.charge_duration) - && (/* ability_key_is_pressed(data, self.static_data.ability_info.key) */!self.end + && (/* ability_key_is_pressed(data, self.static_data.ability_info.key) */input_is_pressed(data, self.static_data.ability_info) || (self.auto_charge && self.timer < self.static_data.charge_duration)) && update.energy.current() > 0 { @@ -270,17 +268,4 @@ impl CharacterBehavior for Data { update } - - fn cancel_input(&self, data: &JoinData, input: InputKind) -> StateUpdate { - let mut update = StateUpdate::from(data); - update.removed_inputs.push(input); - - if Some(input) == self.static_data.ability_info.input { - if let CharacterState::DashMelee(c) = &mut update.character { - c.end = true; - } - } - - update - } } diff --git a/common/src/states/healing_beam.rs b/common/src/states/healing_beam.rs index fe7e2764d1..24216967c6 100644 --- a/common/src/states/healing_beam.rs +++ b/common/src/states/healing_beam.rs @@ -1,6 +1,6 @@ use crate::{ combat::{Attack, AttackEffect, CombatEffect, CombatRequirement, GroupTarget}, - comp::{beam, CharacterState, InputKind, Ori, Pos, StateUpdate}, + comp::{beam, CharacterState, Ori, Pos, StateUpdate}, event::ServerEvent, states::{ behavior::{CharacterBehavior, JoinData}, @@ -46,8 +46,6 @@ pub struct Data { pub timer: Duration, /// What section the character stage is in pub stage_section: StageSection, - /// Whether or not the state should end - pub end: bool, } impl CharacterBehavior for Data { @@ -95,7 +93,7 @@ impl CharacterBehavior for Data { StageSection::Cast => { if /* ability_key_is_pressed(data, self.static_data.ability_info.key) */ - !self.end { + input_is_pressed(data, self.static_data.ability_info) { let speed = self.static_data.range / self.static_data.beam_duration.as_secs_f32(); let heal = AttackEffect::new( @@ -168,17 +166,4 @@ impl CharacterBehavior for Data { update } - - fn cancel_input(&self, data: &JoinData, input: InputKind) -> StateUpdate { - let mut update = StateUpdate::from(data); - update.removed_inputs.push(input); - - if Some(input) == self.static_data.ability_info.input { - if let CharacterState::HealingBeam(c) = &mut update.character { - c.end = true; - } - } - - update - } } diff --git a/common/src/states/idle.rs b/common/src/states/idle.rs index 89ef55d98b..a32728844e 100644 --- a/common/src/states/idle.rs +++ b/common/src/states/idle.rs @@ -1,8 +1,7 @@ use super::utils::*; use crate::{ - comp::{CharacterState, InputKind, InventoryAction, StateUpdate}, + comp::{InventoryAction, StateUpdate}, states::behavior::{CharacterBehavior, JoinData}, - uid::Uid, }; pub struct Data; @@ -20,18 +19,6 @@ impl CharacterBehavior for Data { update } - fn handle_input( - &self, - data: &JoinData, - _input: InputKind, - _target: Option, - ) -> StateUpdate { - let mut update = StateUpdate::from(data); - update.character = CharacterState::Wielding; - - update - } - fn wield(&self, data: &JoinData) -> StateUpdate { let mut update = StateUpdate::from(data); attempt_wield(data, &mut update); diff --git a/common/src/states/spin_melee.rs b/common/src/states/spin_melee.rs index 2fe51f18dd..1a3b511311 100644 --- a/common/src/states/spin_melee.rs +++ b/common/src/states/spin_melee.rs @@ -1,6 +1,6 @@ use crate::{ combat::{Attack, AttackDamage, AttackEffect, CombatBuff, CombatEffect, CombatRequirement}, - comp::{CharacterState, EnergyChange, EnergySource, InputKind, Melee, StateUpdate}, + comp::{CharacterState, EnergyChange, EnergySource, Melee, StateUpdate}, consts::GRAVITY, states::{ behavior::{CharacterBehavior, JoinData}, @@ -58,8 +58,6 @@ pub struct Data { pub stage_section: StageSection, /// Whether the state can deal damage pub exhausted: bool, - /// Whether or not the state should end - pub end: bool, } impl CharacterBehavior for Data { @@ -181,7 +179,7 @@ impl CharacterBehavior for Data { } else if update.energy.current() as f32 >= self.static_data.energy_cost && (self.spins_remaining != 0 || (self.static_data.is_infinite - && /*ability_key_is_pressed(data, self.static_data.ability_info.key)*/ !self.end)) + && /*ability_key_is_pressed(data, self.static_data.ability_info.key)*/ input_is_pressed(data, self.static_data.ability_info))) { let new_spins_remaining = if self.static_data.is_infinite { self.spins_remaining @@ -235,19 +233,6 @@ impl CharacterBehavior for Data { update } - - fn cancel_input(&self, data: &JoinData, input: InputKind) -> StateUpdate { - let mut update = StateUpdate::from(data); - update.removed_inputs.push(input); - - if Some(input) == self.static_data.ability_info.input { - if let CharacterState::SpinMelee(c) = &mut update.character { - c.end = true; - } - } - - update - } } #[derive(Copy, Clone, Debug, PartialEq, Serialize, Deserialize)] diff --git a/common/src/states/utils.rs b/common/src/states/utils.rs index 5a42c05cf5..a37a66ce21 100644 --- a/common/src/states/utils.rs +++ b/common/src/states/utils.rs @@ -506,6 +506,13 @@ pub fn handle_input(data: &JoinData, update: &mut StateUpdate, input: InputKind) } } +pub fn attempt_input(data: &JoinData, update: &mut StateUpdate) { + // TODO: look into using first() when it becomes stable + if let Some(input) = data.controller.queued_inputs.iter().next() { + handle_input(data, update, *input); + } +} + /*pub fn handle_ability1_input(data: &JoinData, update: &mut StateUpdate) { if data.inputs.primary.is_pressed() { handle_ability_pressed(data, update, AbilityKey::Mouse1); @@ -620,6 +627,13 @@ pub fn handle_interrupt(data: &JoinData, update: &mut StateUpdate, attacks_inter handle_dodge_input(data, update); } +pub fn input_is_pressed(data: &JoinData, ability_info: AbilityInfo) -> bool { + //data.controller.queued_inputs.contains(ability_info.input) + ability_info + .input + .map_or(false, |i| data.controller.queued_inputs.contains(&i)) +} + pub fn ability_key_is_pressed(data: &JoinData, ability_key: AbilityKey) -> bool { match ability_key { AbilityKey::Mouse1 => diff --git a/common/src/states/wielding.rs b/common/src/states/wielding.rs index cba173261a..7accb19de3 100644 --- a/common/src/states/wielding.rs +++ b/common/src/states/wielding.rs @@ -2,10 +2,9 @@ use super::utils::*; use crate::{ comp::{ slot::{EquipSlot, Slot}, - CharacterState, InputKind, InventoryAction, StateUpdate, + CharacterState, InventoryAction, StateUpdate, }, states::behavior::{CharacterBehavior, JoinData}, - uid::Uid, }; pub struct Data; @@ -23,12 +22,7 @@ impl CharacterBehavior for Data { handle_ability4_input(&data, &mut update); handle_dodge_input(&data, &mut update); - update - } - - fn handle_input(&self, data: &JoinData, input: InputKind, _target: Option) -> StateUpdate { - let mut update = StateUpdate::from(data); - handle_input(&data, &mut update, input); + attempt_input(&data, &mut update); update } From ac6e192db458a89e64f04111c19fee82fa317a22 Mon Sep 17 00:00:00 2001 From: Sam Date: Sun, 14 Mar 2021 14:42:39 -0400 Subject: [PATCH 6/7] Completely purged old method of inputs --- common/src/comp/controller.rs | 171 +---------- common/src/comp/mod.rs | 4 +- common/src/states/basic_aura.rs | 18 +- common/src/states/basic_beam.rs | 20 +- common/src/states/basic_melee.rs | 22 +- common/src/states/basic_ranged.rs | 22 +- common/src/states/boost.rs | 4 +- common/src/states/charged_melee.rs | 22 +- common/src/states/charged_ranged.rs | 24 +- common/src/states/climb.rs | 11 +- common/src/states/combo_melee.rs | 22 +- common/src/states/dash_melee.rs | 22 +- common/src/states/healing_beam.rs | 20 +- common/src/states/leap_melee.rs | 18 +- common/src/states/repeater_ranged.rs | 18 +- common/src/states/roll.rs | 28 +- common/src/states/shockwave.rs | 18 +- common/src/states/spin_melee.rs | 20 +- common/src/states/utils.rs | 149 +++------- common/src/states/wielding.rs | 4 +- common/sys/src/controller.rs | 9 - server/src/sys/agent.rs | 412 +++++++++++++++++++++++---- voxygen/src/controller.rs | 6 - voxygen/src/session.rs | 29 +- voxygen/src/settings.rs | 5 - voxygen/src/window.rs | 4 - 26 files changed, 592 insertions(+), 510 deletions(-) diff --git a/common/src/comp/controller.rs b/common/src/comp/controller.rs index 89e84ef011..339e25ffc3 100644 --- a/common/src/comp/controller.rs +++ b/common/src/comp/controller.rs @@ -11,12 +11,9 @@ use crate::{ use serde::{Deserialize, Serialize}; use specs::{Component, DerefFlaggedStorage}; use specs_idvs::IdvStorage; -use std::{collections::BTreeSet, time::Duration}; +use std::collections::BTreeSet; use vek::*; -/// Default duration before an input is considered 'held'. -pub const DEFAULT_HOLD_DURATION: Duration = Duration::from_millis(200); - #[derive(Clone, Debug, PartialEq, Serialize, Deserialize)] pub enum InventoryEvent { Pickup(Uid), @@ -123,115 +120,11 @@ pub enum ControlAction { pub enum InputKind { Primary = 0, Secondary = 1, - /* Ability(usize) = 2, - * Jump = 3, - * Roll = 4, - * Glide = 5, - * Fly = 6, - * WallLeap = 7, */ -} - -#[derive(Copy, Clone, Debug, PartialEq, Serialize, Deserialize)] -enum Freshness { - New, - TickedOnce, - Old, -} - -/// Whether a key is pressed or unpressed -/// and how long it has been in that state -#[derive(Copy, Clone, Debug, PartialEq, Serialize, Deserialize)] -pub struct Input { - /// Should not be pub because duration should - /// always be reset when state is updated - pressed: bool, - /// Should only be updated by npc agents - /// through appropriate fn - duration: Duration, - /// How fresh is the last change to the input state - freshness: Freshness, -} - -impl Input { - fn tick(&mut self, dt: Duration) { - // Increase how long input has been in current state - self.duration = self.duration.checked_add(dt).unwrap_or_default(); - self.tick_freshness(); - } - - fn tick_freshness(&mut self) { - self.freshness = match self.freshness { - Freshness::New => Freshness::TickedOnce, - Freshness::TickedOnce => Freshness::Old, - Freshness::Old => Freshness::Old, - }; - } - - /// Update input with newer version - /// Used to update inputs with input received from clients - pub fn update_with_new(&mut self, new: Self) { - if self.pressed != new.pressed { - self.freshness = Freshness::New; - } - - self.pressed = new.pressed; - self.duration = new.duration; - } - - /// Whether input is being pressed down - pub fn is_pressed(&self) -> bool { self.pressed } - - /// Whether it's the first frame this input has been pressed - pub fn is_just_pressed(&self) -> bool { self.is_pressed() && self.freshness != Freshness::Old } - - /// Whether it's the first frame this input has been unpressed - pub fn is_just_unpressed(&self) -> bool { - !self.is_pressed() && self.freshness != Freshness::Old - } - - /// Whether input has been pressed longer than - /// `DEFAULT_HOLD_DURATION` - pub fn is_held_down(&self) -> bool { - self.is_pressed() && self.duration >= DEFAULT_HOLD_DURATION - } - - /// Whether input has been unpressed longer than - /// `DEFAULT_HOLD_DURATION` - pub fn is_held_up(&self) -> bool { - !self.is_pressed() && self.duration >= DEFAULT_HOLD_DURATION - } - - /// Whether input has been pressed for longer than `threshold` duration - pub fn held_for_dur(&self, threshold: Duration) -> bool { - self.is_pressed() && self.duration >= threshold - } - - /// Handles logic of updating state of Input - pub fn set_state(&mut self, pressed: bool) { - if self.pressed != pressed { - self.pressed = pressed; - self.duration = Duration::default(); - self.freshness = Freshness::New; - } - } - - /// Increases `input.duration` by `dur` - pub fn inc_dur(&mut self, dur: Duration) { - self.duration = self.duration.checked_add(dur).unwrap_or_default(); - } - - /// Returns `input.duration` - pub fn get_dur(&self) -> Duration { self.duration } -} - -impl Default for Input { - fn default() -> Self { - Self { - pressed: false, - duration: Duration::default(), - freshness: Freshness::New, - } - } + Ability(usize) = 2, + Roll = 3, + Jump = 4, + Glide = 5, + Fly = 6, } #[derive(Clone, Copy, Debug, PartialEq, Serialize, Deserialize)] @@ -243,16 +136,6 @@ pub enum Climb { #[derive(Clone, Debug, Default, PartialEq, Serialize, Deserialize)] pub struct ControllerInputs { - //pub primary: Input, - //pub secondary: Input, - pub ability3: Input, - pub ability4: Input, - pub jump: Input, - pub roll: Input, - pub glide: Input, - pub fly: Input, // Flying entities only - pub wall_leap: Input, - pub charge: Input, pub climb: Option, pub move_dir: Vec2, pub move_z: f32, /* z axis (not combined with move_dir because they may have independent @@ -270,55 +153,13 @@ pub struct Controller { } impl ControllerInputs { - /// Updates all inputs, accounting for delta time - pub fn tick(&mut self, dt: Duration) { - //self.primary.tick(dt); - // self.secondary.tick(dt); - self.ability3.tick(dt); - self.ability4.tick(dt); - self.jump.tick(dt); - self.roll.tick(dt); - self.glide.tick(dt); - self.fly.tick(dt); - self.wall_leap.tick(dt); - self.charge.tick(dt); - } - - pub fn tick_freshness(&mut self) { - //self.primary.tick_freshness(); - // self.secondary.tick_freshness(); - self.ability3.tick_freshness(); - self.ability4.tick_freshness(); - self.jump.tick_freshness(); - self.roll.tick_freshness(); - self.glide.tick_freshness(); - self.fly.tick_freshness(); - self.wall_leap.tick_freshness(); - self.charge.tick_freshness(); - } - /// Updates Controller inputs with new version received from the client pub fn update_with_new(&mut self, new: Self) { - //self.primary.update_with_new(new.primary); - // self.secondary.update_with_new(new.secondary); - self.ability3.update_with_new(new.ability3); - self.ability4.update_with_new(new.ability4); - self.jump.update_with_new(new.jump); - self.roll.update_with_new(new.roll); - self.glide.update_with_new(new.glide); - self.fly.update_with_new(new.fly); - self.wall_leap.update_with_new(new.wall_leap); - self.charge.update_with_new(new.charge); self.climb = new.climb; self.move_dir = new.move_dir; self.move_z = new.move_z; self.look_dir = new.look_dir; } - - pub fn holding_ability_key(&self) -> bool { - //self.primary.is_pressed() || self.secondary.is_pressed() || - self.ability3.is_pressed() || self.ability4.is_pressed() - } } impl Controller { diff --git a/common/src/comp/mod.rs b/common/src/comp/mod.rs index e586e851ed..e493a527c9 100644 --- a/common/src/comp/mod.rs +++ b/common/src/comp/mod.rs @@ -61,8 +61,8 @@ pub use self::{ }, combo::Combo, controller::{ - Climb, ControlAction, ControlEvent, Controller, ControllerInputs, GroupManip, Input, - InputKind, InventoryAction, InventoryEvent, InventoryManip, MountState, Mounting, + Climb, ControlAction, ControlEvent, Controller, ControllerInputs, GroupManip, InputKind, + InventoryAction, InventoryEvent, InventoryManip, MountState, Mounting, }, energy::{Energy, EnergyChange, EnergySource}, group::Group, diff --git a/common/src/states/basic_aura.rs b/common/src/states/basic_aura.rs index 47f3268a19..a30d458870 100644 --- a/common/src/states/basic_aura.rs +++ b/common/src/states/basic_aura.rs @@ -51,15 +51,15 @@ impl CharacterBehavior for Data { handle_move(data, &mut update, 0.8); handle_jump(data, &mut update); - if !ability_key_is_pressed(data, self.static_data.ability_info.key) { - handle_interrupt(data, &mut update, false); - match update.character { - CharacterState::BasicAura(_) => {}, - _ => { - return update; - }, - } - } + // if !ability_key_is_pressed(data, self.static_data.ability_info.key) { + // handle_interrupt(data, &mut update, false); + // match update.character { + // CharacterState::BasicAura(_) => {}, + // _ => { + // return update; + // }, + // } + // } match self.stage_section { StageSection::Buildup => { diff --git a/common/src/states/basic_beam.rs b/common/src/states/basic_beam.rs index c75da30133..ea6d323f8d 100644 --- a/common/src/states/basic_beam.rs +++ b/common/src/states/basic_beam.rs @@ -71,15 +71,15 @@ impl CharacterBehavior for Data { handle_move(data, &mut update, 0.4); handle_jump(data, &mut update); - if !ability_key_is_pressed(data, self.static_data.ability_info.key) { - handle_interrupt(data, &mut update, false); - match update.character { - CharacterState::BasicBeam(_) => {}, - _ => { - return update; - }, - } - } + // if !ability_key_is_pressed(data, self.static_data.ability_info.key) { + // handle_interrupt(data, &mut update, false); + // match update.character { + // CharacterState::BasicBeam(_) => {}, + // _ => { + // return update; + // }, + // } + // } match self.stage_section { StageSection::Buildup => { @@ -110,7 +110,7 @@ impl CharacterBehavior for Data { StageSection::Cast => { if /* ability_key_is_pressed(data, self.static_data.ability_info.key) */ - input_is_pressed(data, self.static_data.ability_info) + input_is_pressed(data, self.static_data.ability_info.input) && (self.static_data.energy_drain <= f32::EPSILON || update.energy.current() > 0) { diff --git a/common/src/states/basic_melee.rs b/common/src/states/basic_melee.rs index 66c02b28df..85a816b997 100644 --- a/common/src/states/basic_melee.rs +++ b/common/src/states/basic_melee.rs @@ -52,15 +52,15 @@ impl CharacterBehavior for Data { handle_move(data, &mut update, 0.7); handle_jump(data, &mut update); - if !ability_key_is_pressed(data, self.static_data.ability_info.key) { - handle_interrupt(data, &mut update, false); - match update.character { - CharacterState::BasicMelee(_) => {}, - _ => { - return update; - }, - } - } + // if !ability_key_is_pressed(data, self.static_data.ability_info.key) { + // handle_interrupt(data, &mut update, false); + // match update.character { + // CharacterState::BasicMelee(_) => {}, + // _ => { + // return update; + // }, + // } + // } match self.stage_section { StageSection::Buildup => { @@ -162,7 +162,7 @@ impl CharacterBehavior for Data { }); } else { // Done - if input_is_pressed(data, self.static_data.ability_info) { + if input_is_pressed(data, self.static_data.ability_info.input) { reset_state(self, data, &mut update); } else { update.character = CharacterState::Wielding; @@ -182,5 +182,5 @@ impl CharacterBehavior for Data { } fn reset_state(data: &Data, join: &JoinData, update: &mut StateUpdate) { - handle_input(join, update, data.static_data.ability_info.input.unwrap()); + handle_input(join, update, data.static_data.ability_info.input); } diff --git a/common/src/states/basic_ranged.rs b/common/src/states/basic_ranged.rs index 806bbf6b64..d4c4a47bc8 100644 --- a/common/src/states/basic_ranged.rs +++ b/common/src/states/basic_ranged.rs @@ -45,15 +45,15 @@ impl CharacterBehavior for Data { handle_move(data, &mut update, 0.3); handle_jump(data, &mut update); - if !ability_key_is_pressed(data, self.static_data.ability_info.key) { - handle_interrupt(data, &mut update, false); - match update.character { - CharacterState::BasicRanged(_) => {}, - _ => { - return update; - }, - } - } + // if !ability_key_is_pressed(data, self.static_data.ability_info.key) { + // handle_interrupt(data, &mut update, false); + // match update.character { + // CharacterState::BasicRanged(_) => {}, + // _ => { + // return update; + // }, + // } + // } match self.stage_section { StageSection::Buildup => { @@ -111,7 +111,7 @@ impl CharacterBehavior for Data { }); } else { // Done - if input_is_pressed(data, self.static_data.ability_info) { + if input_is_pressed(data, self.static_data.ability_info.input) { reset_state(self, data, &mut update); } else { update.character = CharacterState::Wielding; @@ -129,5 +129,5 @@ impl CharacterBehavior for Data { } fn reset_state(data: &Data, join: &JoinData, update: &mut StateUpdate) { - handle_input(join, update, data.static_data.ability_info.input.unwrap()); + handle_input(join, update, data.static_data.ability_info.input); } diff --git a/common/src/states/boost.rs b/common/src/states/boost.rs index 76f5b32b78..415e4c9d6b 100644 --- a/common/src/states/boost.rs +++ b/common/src/states/boost.rs @@ -47,7 +47,7 @@ impl CharacterBehavior for Data { }); } else { // Done - if input_is_pressed(data, self.static_data.ability_info) { + if input_is_pressed(data, self.static_data.ability_info.input) { reset_state(self, data, &mut update); } else { update.character = CharacterState::Wielding; @@ -59,5 +59,5 @@ impl CharacterBehavior for Data { } fn reset_state(data: &Data, join: &JoinData, update: &mut StateUpdate) { - handle_input(join, update, data.static_data.ability_info.input.unwrap()); + handle_input(join, update, data.static_data.ability_info.input); } diff --git a/common/src/states/charged_melee.rs b/common/src/states/charged_melee.rs index c350052a02..b3fecff907 100644 --- a/common/src/states/charged_melee.rs +++ b/common/src/states/charged_melee.rs @@ -68,21 +68,21 @@ impl CharacterBehavior for Data { handle_move(data, &mut update, 0.7); handle_jump(data, &mut update); - if !ability_key_is_pressed(data, self.static_data.ability_info.key) { - handle_interrupt(data, &mut update, false); - match update.character { - CharacterState::ChargedMelee(_) => {}, - _ => { - return update; - }, - } - } + // if !ability_key_is_pressed(data, self.static_data.ability_info.key) { + // handle_interrupt(data, &mut update, false); + // match update.character { + // CharacterState::ChargedMelee(_) => {}, + // _ => { + // return update; + // }, + // } + // } match self.stage_section { StageSection::Charge => { if /* ability_key_is_pressed(data, self.static_data.ability_info.key) */ - input_is_pressed(data, self.static_data.ability_info) + input_is_pressed(data, self.static_data.ability_info.input) && update.energy.current() as f32 >= self.static_data.energy_cost && self.timer < self.static_data.charge_duration { @@ -111,7 +111,7 @@ impl CharacterBehavior for Data { }); } else if /* ability_key_is_pressed(data, self.static_data.ability_info.key) */ - input_is_pressed(data, self.static_data.ability_info) + input_is_pressed(data, self.static_data.ability_info.input) && update.energy.current() as f32 >= self.static_data.energy_cost { // Maintains charge diff --git a/common/src/states/charged_ranged.rs b/common/src/states/charged_ranged.rs index 9a27eb4a7b..65fdfd34d6 100644 --- a/common/src/states/charged_ranged.rs +++ b/common/src/states/charged_ranged.rs @@ -68,15 +68,15 @@ impl CharacterBehavior for Data { handle_move(data, &mut update, self.static_data.move_speed); handle_jump(data, &mut update); - if !ability_key_is_pressed(data, self.static_data.ability_info.key) { - handle_interrupt(data, &mut update, false); - match update.character { - CharacterState::ChargedRanged(_) => {}, - _ => { - return update; - }, - } - } + // if !ability_key_is_pressed(data, self.static_data.ability_info.key) { + // handle_interrupt(data, &mut update, false); + // match update.character { + // CharacterState::ChargedRanged(_) => {}, + // _ => { + // return update; + // }, + // } + // } match self.stage_section { StageSection::Buildup => { @@ -101,7 +101,7 @@ impl CharacterBehavior for Data { StageSection::Charge => { if /* \!ability_key_is_pressed(data, self.static_data.ability_info.key) */ - !input_is_pressed(data, self.static_data.ability_info) && !self.exhausted { + !input_is_pressed(data, self.static_data.ability_info.input) && !self.exhausted { let charge_frac = (self.timer.as_secs_f32() / self.static_data.charge_duration.as_secs_f32()) .min(1.0); @@ -162,7 +162,7 @@ impl CharacterBehavior for Data { ..*self }); } else if self.timer < self.static_data.charge_duration - && /*ability_key_is_pressed(data, self.static_data.ability_info.key)*/ input_is_pressed(data, self.static_data.ability_info) + && /*ability_key_is_pressed(data, self.static_data.ability_info.key)*/ input_is_pressed(data, self.static_data.ability_info.input) { // Charges update.character = CharacterState::ChargedRanged(Data { @@ -184,7 +184,7 @@ impl CharacterBehavior for Data { }); } else if /* ability_key_is_pressed(data, self.static_data.ability_info.key) */ - input_is_pressed(data, self.static_data.ability_info) { + input_is_pressed(data, self.static_data.ability_info.input) { // Holds charge update.character = CharacterState::ChargedRanged(Data { timer: self diff --git a/common/src/states/climb.rs b/common/src/states/climb.rs index 2b2c5c25a3..b169e115aa 100644 --- a/common/src/states/climb.rs +++ b/common/src/states/climb.rs @@ -1,8 +1,11 @@ use crate::{ - comp::{CharacterState, Climb, EnergySource, Ori, StateUpdate}, + comp::{CharacterState, Climb, EnergySource, InputKind, Ori, StateUpdate}, consts::GRAVITY, event::LocalEvent, - states::behavior::{CharacterBehavior, JoinData}, + states::{ + behavior::{CharacterBehavior, JoinData}, + utils::*, + }, util::Dir, }; use serde::{Deserialize, Serialize}; @@ -29,7 +32,9 @@ impl CharacterBehavior for Data { ) { (wall_dir, climb) } else { - if data.inputs.jump.is_pressed() { + if + /* data.inputs.jump.is_pressed() */ + input_is_pressed(data, InputKind::Jump) { // They've climbed atop something, give them a boost update .local_events diff --git a/common/src/states/combo_melee.rs b/common/src/states/combo_melee.rs index 6bcb8f2881..aadbcad172 100644 --- a/common/src/states/combo_melee.rs +++ b/common/src/states/combo_melee.rs @@ -121,15 +121,15 @@ impl CharacterBehavior for Data { handle_orientation(data, &mut update, 1.0); handle_move(data, &mut update, 0.3); - if !ability_key_is_pressed(data, self.static_data.ability_info.key) { - handle_interrupt(data, &mut update, self.static_data.is_interruptible); - match update.character { - CharacterState::ComboMelee(_) => {}, - _ => { - return update; - }, - } - } + // if !ability_key_is_pressed(data, self.static_data.ability_info.key) { + // handle_interrupt(data, &mut update, self.static_data.is_interruptible); + // match update.character { + // CharacterState::ComboMelee(_) => {}, + // _ => { + // return update; + // }, + // } + // } let stage_index = (self.stage - 1) as usize; @@ -269,7 +269,7 @@ impl CharacterBehavior for Data { }); } else { // Done - if input_is_pressed(data, self.static_data.ability_info) { + if input_is_pressed(data, self.static_data.ability_info.input) { reset_state(self, data, &mut update); } else { update.character = CharacterState::Wielding; @@ -289,7 +289,7 @@ impl CharacterBehavior for Data { } fn reset_state(data: &Data, join: &JoinData, update: &mut StateUpdate) { - handle_input(join, update, data.static_data.ability_info.input.unwrap()); + handle_input(join, update, data.static_data.ability_info.input); if let CharacterState::ComboMelee(c) = &mut update.character { c.stage = (data.stage % data.static_data.num_stages) + 1; diff --git a/common/src/states/dash_melee.rs b/common/src/states/dash_melee.rs index 753e17889b..c78b9d7ee4 100644 --- a/common/src/states/dash_melee.rs +++ b/common/src/states/dash_melee.rs @@ -74,15 +74,15 @@ impl CharacterBehavior for Data { handle_orientation(data, &mut update, 1.0); handle_move(data, &mut update, 0.1); - if !ability_key_is_pressed(data, self.static_data.ability_info.key) { - handle_interrupt(data, &mut update, self.static_data.is_interruptible); - match update.character { - CharacterState::DashMelee(_) => {}, - _ => { - return update; - }, - } - } + // if !ability_key_is_pressed(data, self.static_data.ability_info.key) { + // handle_interrupt(data, &mut update, self.static_data.is_interruptible); + // match update.character { + // CharacterState::DashMelee(_) => {}, + // _ => { + // return update; + // }, + // } + // } match self.stage_section { StageSection::Buildup => { @@ -101,7 +101,7 @@ impl CharacterBehavior for Data { auto_charge: /*\!ability_key_is_pressed( data, self.static_data.ability_info.key, - )*/input_is_pressed(data, self.static_data.ability_info), + )*/input_is_pressed(data, self.static_data.ability_info.input), timer: Duration::default(), stage_section: StageSection::Charge, ..*self @@ -111,7 +111,7 @@ impl CharacterBehavior for Data { StageSection::Charge => { if (self.static_data.infinite_charge || self.timer < self.static_data.charge_duration) - && (/* ability_key_is_pressed(data, self.static_data.ability_info.key) */input_is_pressed(data, self.static_data.ability_info) + && (/* ability_key_is_pressed(data, self.static_data.ability_info.key) */input_is_pressed(data, self.static_data.ability_info.input) || (self.auto_charge && self.timer < self.static_data.charge_duration)) && update.energy.current() > 0 { diff --git a/common/src/states/healing_beam.rs b/common/src/states/healing_beam.rs index 24216967c6..941c35d72e 100644 --- a/common/src/states/healing_beam.rs +++ b/common/src/states/healing_beam.rs @@ -54,15 +54,15 @@ impl CharacterBehavior for Data { handle_move(data, &mut update, 0.4); handle_jump(data, &mut update); - if !ability_key_is_pressed(data, self.static_data.ability_info.key) { - handle_interrupt(data, &mut update, false); - match update.character { - CharacterState::HealingBeam(_) => {}, - _ => { - return update; - }, - } - } + // if !ability_key_is_pressed(data, self.static_data.ability_info.key) { + // handle_interrupt(data, &mut update, false); + // match update.character { + // CharacterState::HealingBeam(_) => {}, + // _ => { + // return update; + // }, + // } + // } match self.stage_section { StageSection::Buildup => { @@ -93,7 +93,7 @@ impl CharacterBehavior for Data { StageSection::Cast => { if /* ability_key_is_pressed(data, self.static_data.ability_info.key) */ - input_is_pressed(data, self.static_data.ability_info) { + input_is_pressed(data, self.static_data.ability_info.input) { let speed = self.static_data.range / self.static_data.beam_duration.as_secs_f32(); let heal = AttackEffect::new( diff --git a/common/src/states/leap_melee.rs b/common/src/states/leap_melee.rs index 31b7daff7f..9f152adfff 100644 --- a/common/src/states/leap_melee.rs +++ b/common/src/states/leap_melee.rs @@ -58,15 +58,15 @@ impl CharacterBehavior for Data { handle_move(data, &mut update, 0.3); handle_jump(data, &mut update); - if !ability_key_is_pressed(data, self.static_data.ability_info.key) { - handle_interrupt(data, &mut update, false); - match update.character { - CharacterState::LeapMelee(_) => {}, - _ => { - return update; - }, - } - } + // if !ability_key_is_pressed(data, self.static_data.ability_info.key) { + // handle_interrupt(data, &mut update, false); + // match update.character { + // CharacterState::LeapMelee(_) => {}, + // _ => { + // return update; + // }, + // } + // } match self.stage_section { // Delay before leaping into the air diff --git a/common/src/states/repeater_ranged.rs b/common/src/states/repeater_ranged.rs index a9904efc12..b912c162ab 100644 --- a/common/src/states/repeater_ranged.rs +++ b/common/src/states/repeater_ranged.rs @@ -53,15 +53,15 @@ impl CharacterBehavior for Data { handle_move(data, &mut update, 1.0); handle_jump(data, &mut update); - if !ability_key_is_pressed(data, self.static_data.ability_info.key) { - handle_interrupt(data, &mut update, false); - match update.character { - CharacterState::RepeaterRanged(_) => {}, - _ => { - return update; - }, - } - } + // if !ability_key_is_pressed(data, self.static_data.ability_info.key) { + // handle_interrupt(data, &mut update, false); + // match update.character { + // CharacterState::RepeaterRanged(_) => {}, + // _ => { + // return update; + // }, + // } + // } match self.stage_section { StageSection::Movement => { diff --git a/common/src/states/roll.rs b/common/src/states/roll.rs index 3392219782..094d8e7da0 100644 --- a/common/src/states/roll.rs +++ b/common/src/states/roll.rs @@ -1,5 +1,5 @@ use crate::{ - comp::{CharacterState, StateUpdate}, + comp::{CharacterState, InputKind, StateUpdate}, states::{ behavior::{CharacterBehavior, JoinData}, utils::*, @@ -37,7 +37,7 @@ pub struct Data { /// Was sneaking pub was_sneak: bool, /// Was in state with combo - pub was_combo: Option<(AbilityKey, u32)>, + pub was_combo: Option<(InputKind, u32)>, } impl CharacterBehavior for Data { @@ -114,17 +114,19 @@ impl CharacterBehavior for Data { }); } else { // Done - if let Some((key, stage)) = self.was_combo { - if ability_key_is_pressed(data, key) { - handle_interrupt(data, &mut update, true); - // If other states are introduced that progress through stages, add them - // here - if let CharacterState::ComboMelee(c) = &mut update.character { - c.stage = stage; - } - } else { - update.character = CharacterState::Wielding; - } + if let Some((input, stage)) = self.was_combo { + // if ability_key_is_pressed(data, key) { + // handle_interrupt(data, &mut update, true); + // // If other states are introduced that progress + // through stages, add them + // // here + // if let CharacterState::ComboMelee(c) = &mut + // update.character { + // c.stage = stage; + // } + // } else { + // update.character = CharacterState::Wielding; + // } } else if self.was_wielded { update.character = CharacterState::Wielding; } else if self.was_sneak { diff --git a/common/src/states/shockwave.rs b/common/src/states/shockwave.rs index 6d2647236a..6ce64d9c04 100644 --- a/common/src/states/shockwave.rs +++ b/common/src/states/shockwave.rs @@ -60,15 +60,15 @@ impl CharacterBehavior for Data { let mut update = StateUpdate::from(data); handle_move(data, &mut update, self.static_data.move_efficiency); - if !ability_key_is_pressed(data, self.static_data.ability_info.key) { - handle_interrupt(data, &mut update, false); - match update.character { - CharacterState::Shockwave(_) => {}, - _ => { - return update; - }, - } - } + // if !ability_key_is_pressed(data, self.static_data.ability_info.key) { + // handle_interrupt(data, &mut update, false); + // match update.character { + // CharacterState::Shockwave(_) => {}, + // _ => { + // return update; + // }, + // } + // } match self.stage_section { StageSection::Buildup => { diff --git a/common/src/states/spin_melee.rs b/common/src/states/spin_melee.rs index 1a3b511311..b45ac76360 100644 --- a/common/src/states/spin_melee.rs +++ b/common/src/states/spin_melee.rs @@ -75,15 +75,15 @@ impl CharacterBehavior for Data { }, } - if !ability_key_is_pressed(data, self.static_data.ability_info.key) { - handle_interrupt(data, &mut update, self.static_data.is_interruptible); - match update.character { - CharacterState::SpinMelee(_) => {}, - _ => { - return update; - }, - } - } + // if !ability_key_is_pressed(data, self.static_data.ability_info.key) { + // handle_interrupt(data, &mut update, self.static_data.is_interruptible); + // match update.character { + // CharacterState::SpinMelee(_) => {}, + // _ => { + // return update; + // }, + // } + // } match self.stage_section { StageSection::Buildup => { @@ -179,7 +179,7 @@ impl CharacterBehavior for Data { } else if update.energy.current() as f32 >= self.static_data.energy_cost && (self.spins_remaining != 0 || (self.static_data.is_infinite - && /*ability_key_is_pressed(data, self.static_data.ability_info.key)*/ input_is_pressed(data, self.static_data.ability_info))) + && /*ability_key_is_pressed(data, self.static_data.ability_info.key)*/ input_is_pressed(data, self.static_data.ability_info.input))) { let new_spins_remaining = if self.static_data.is_infinite { self.spins_remaining diff --git a/common/src/states/utils.rs b/common/src/states/utils.rs index a37a66ce21..175f8e7482 100644 --- a/common/src/states/utils.rs +++ b/common/src/states/utils.rs @@ -180,7 +180,12 @@ impl Body { pub fn handle_move(data: &JoinData, update: &mut StateUpdate, efficiency: f32) { if let Some(depth) = data.physics.in_liquid { swim_move(data, update, efficiency, depth); - } else if data.inputs.fly.is_pressed() && !data.physics.on_ground && data.body.can_fly() { + } else if + /* data.inputs.fly.is_pressed() */ + input_is_pressed(data, InputKind::Fly) + && !data.physics.on_ground + && data.body.can_fly() + { fly_move(data, update, efficiency); } else { basic_move(data, update, efficiency); @@ -314,11 +319,11 @@ fn fly_move(data: &JoinData, update: &mut StateUpdate, efficiency: f32) { /// First checks whether `primary`, `secondary`, `ability3`, or `ability4` input /// is pressed, then attempts to go into Equipping state, otherwise Idle pub fn handle_wield(data: &JoinData, update: &mut StateUpdate) { - if - // data.inputs.primary.is_pressed() || data.inputs.secondary.is_pressed() || - data.inputs.ability3.is_pressed() || data.inputs.ability4.is_pressed() { - attempt_wield(data, update); - } + // if + // // data.inputs.primary.is_pressed() || data.inputs.secondary.is_pressed() + // || data.inputs.ability3.is_pressed() || + // data.inputs.ability4.is_pressed() { attempt_wield(data, update); + // } } /// If a tool is equipped, goes into Equipping state, otherwise goes to Idle @@ -416,7 +421,9 @@ pub fn attempt_glide_wield(data: &JoinData, update: &mut StateUpdate) { /// Checks that player can jump and sends jump event if so pub fn handle_jump(data: &JoinData, update: &mut StateUpdate) { - if data.inputs.jump.is_pressed() + if + /* data.inputs.jump.is_pressed() */ + input_is_pressed(data, InputKind::Jump) && data.physics.on_ground && !data .physics @@ -430,19 +437,14 @@ pub fn handle_jump(data: &JoinData, update: &mut StateUpdate) { } } -fn handle_ability_pressed( - data: &JoinData, - update: &mut StateUpdate, - ability_key: AbilityKey, - input: Option, -) { +fn handle_ability_pressed(data: &JoinData, update: &mut StateUpdate, input: InputKind) { let hands = |equip_slot| match data.inventory.equipped(equip_slot).map(|i| i.kind()) { Some(ItemKind::Tool(tool)) => Some(tool.hands), _ => None, }; // Mouse1 and Skill1 always use the MainHand slot - let always_main_hand = matches!(ability_key, AbilityKey::Mouse1 | AbilityKey::Skill1); + let always_main_hand = matches!(input, InputKind::Primary | InputKind::Ability(0)); // skill_index used to select ability for the AbilityKey::Skill2 input let (equip_slot, skill_index) = if always_main_hand { (Some(EquipSlot::Mainhand), 0) @@ -466,16 +468,16 @@ fn handle_ability_pressed( .inventory .equipped(equip_slot) .map(|i| &i.item_config_expect().abilities) - .and_then(|abilities| match ability_key { - AbilityKey::Mouse1 => Some(abilities.primary.clone()), - AbilityKey::Mouse2 => Some(abilities.secondary.clone()), - AbilityKey::Skill1 => abilities.abilities.get(0).cloned().and_then(unlocked), - AbilityKey::Skill2 => abilities + .and_then(|abilities| match input { + InputKind::Primary => Some(abilities.primary.clone()), + InputKind::Secondary => Some(abilities.secondary.clone()), + InputKind::Ability(0) => abilities.abilities.get(0).cloned().and_then(unlocked), + InputKind::Ability(_) => abilities .abilities .get(skill_index) .cloned() .and_then(unlocked), - AbilityKey::Dodge => None, + InputKind::Roll | InputKind::Jump | InputKind::Glide | InputKind::Fly => None, }) .map(|a| { let tool = unwrap_tool_data(data, equip_slot).map(|t| t.kind); @@ -485,12 +487,7 @@ fn handle_ability_pressed( { update.character = ( &ability, - AbilityInfo::from_key( - data, - ability_key, - matches!(equip_slot, EquipSlot::Offhand), - input, - ), + AbilityInfo::from_input(data, matches!(equip_slot, EquipSlot::Offhand), input), ) .into(); } @@ -499,10 +496,13 @@ fn handle_ability_pressed( pub fn handle_input(data: &JoinData, update: &mut StateUpdate, input: InputKind) { match input { - InputKind::Primary => handle_ability_pressed(data, update, AbilityKey::Mouse1, Some(input)), - InputKind::Secondary => { - handle_ability_pressed(data, update, AbilityKey::Mouse2, Some(input)) + InputKind::Primary | InputKind::Secondary | InputKind::Ability(_) => { + handle_ability_pressed(data, update, input) }, + InputKind::Roll => handle_dodge_input(data, update), + InputKind::Jump => handle_jump(data, update), + InputKind::Glide => attempt_glide_wield(data, update), + InputKind::Fly => {}, } } @@ -513,34 +513,10 @@ pub fn attempt_input(data: &JoinData, update: &mut StateUpdate) { } } -/*pub fn handle_ability1_input(data: &JoinData, update: &mut StateUpdate) { - if data.inputs.primary.is_pressed() { - handle_ability_pressed(data, update, AbilityKey::Mouse1); - } -}*/ - -// pub fn handle_ability2_input(data: &JoinData, update: &mut StateUpdate) { -// if data.inputs.secondary.is_pressed() { -// handle_ability_pressed(data, update, AbilityKey::Mouse2, None); -// } -// } - -pub fn handle_ability3_input(data: &JoinData, update: &mut StateUpdate) { - if data.inputs.ability3.is_pressed() { - handle_ability_pressed(data, update, AbilityKey::Skill1, None); - } -} - -pub fn handle_ability4_input(data: &JoinData, update: &mut StateUpdate) { - if data.inputs.ability4.is_pressed() { - handle_ability_pressed(data, update, AbilityKey::Skill2, None); - } -} - /// Checks that player can perform a dodge, then /// attempts to perform their dodge ability pub fn handle_dodge_input(data: &JoinData, update: &mut StateUpdate) { - if data.inputs.roll.is_pressed() && data.body.is_humanoid() { + if input_is_pressed(data, InputKind::Roll) && data.body.is_humanoid() { if let Some(ability) = data .inventory .equipped(EquipSlot::Mainhand) @@ -555,17 +531,17 @@ pub fn handle_dodge_input(data: &JoinData, update: &mut StateUpdate) { if let CharacterState::ComboMelee(c) = data.character { update.character = ( &ability, - AbilityInfo::from_key(data, AbilityKey::Dodge, false, None), + AbilityInfo::from_input(data, false, InputKind::Roll), ) .into(); if let CharacterState::Roll(roll) = &mut update.character { - roll.was_combo = Some((c.static_data.ability_info.key, c.stage)); + roll.was_combo = Some((c.static_data.ability_info.input, c.stage)); roll.was_wielded = true; } } else if data.character.is_wield() { update.character = ( &ability, - AbilityInfo::from_key(data, AbilityKey::Dodge, false, None), + AbilityInfo::from_input(data, false, InputKind::Roll), ) .into(); if let CharacterState::Roll(roll) = &mut update.character { @@ -574,7 +550,7 @@ pub fn handle_dodge_input(data: &JoinData, update: &mut StateUpdate) { } else if data.character.is_stealthy() { update.character = ( &ability, - AbilityInfo::from_key(data, AbilityKey::Dodge, false, None), + AbilityInfo::from_input(data, false, InputKind::Roll), ) .into(); if let CharacterState::Roll(roll) = &mut update.character { @@ -583,7 +559,7 @@ pub fn handle_dodge_input(data: &JoinData, update: &mut StateUpdate) { } else { update.character = ( &ability, - AbilityInfo::from_key(data, AbilityKey::Dodge, false, None), + AbilityInfo::from_input(data, false, InputKind::Roll), ) .into(); } @@ -621,35 +597,14 @@ pub fn handle_interrupt(data: &JoinData, update: &mut StateUpdate, attacks_inter if attacks_interrupt { //handle_ability1_input(data, update); // handle_ability2_input(data, update); - handle_ability3_input(data, update); - handle_ability4_input(data, update); + // handle_ability3_input(data, update); + // handle_ability4_input(data, update); } handle_dodge_input(data, update); } -pub fn input_is_pressed(data: &JoinData, ability_info: AbilityInfo) -> bool { - //data.controller.queued_inputs.contains(ability_info.input) - ability_info - .input - .map_or(false, |i| data.controller.queued_inputs.contains(&i)) -} - -pub fn ability_key_is_pressed(data: &JoinData, ability_key: AbilityKey) -> bool { - match ability_key { - AbilityKey::Mouse1 => - /* data.inputs.primary.is_pressed() */ - { - false - }, - AbilityKey::Mouse2 => - /* data.inputs.secondary.is_pressed() */ - { - false - }, - AbilityKey::Skill1 => data.inputs.ability3.is_pressed(), - AbilityKey::Skill2 => data.inputs.ability4.is_pressed(), - AbilityKey::Dodge => data.inputs.roll.is_pressed(), - } +pub fn input_is_pressed(data: &JoinData, input: InputKind) -> bool { + data.controller.queued_inputs.contains(&input) } /// Determines what portion a state is in. Used in all attacks (eventually). Is @@ -666,15 +621,6 @@ pub enum StageSection { Movement, } -#[derive(Clone, Copy, Debug, Eq, Hash, PartialEq, Serialize, Deserialize)] -pub enum AbilityKey { - Mouse1, - Mouse2, - Skill1, - Skill2, - Dodge, -} - #[derive(Clone, Copy, Debug, PartialEq, Serialize, Deserialize)] pub enum ForcedMovement { Forward { @@ -713,17 +659,11 @@ impl MovementDirection { pub struct AbilityInfo { pub tool: Option, pub hand: Option, - pub key: AbilityKey, - pub input: Option, + pub input: InputKind, } impl AbilityInfo { - pub fn from_key( - data: &JoinData, - key: AbilityKey, - from_offhand: bool, - input: Option, - ) -> Self { + pub fn from_input(data: &JoinData, from_offhand: bool, input: InputKind) -> Self { let tool_data = if from_offhand { unwrap_tool_data(data, EquipSlot::Offhand) } else { @@ -738,12 +678,7 @@ impl AbilityInfo { ) }; - Self { - tool, - hand, - key, - input, - } + Self { tool, hand, input } } } diff --git a/common/src/states/wielding.rs b/common/src/states/wielding.rs index 7accb19de3..d5fb29ab23 100644 --- a/common/src/states/wielding.rs +++ b/common/src/states/wielding.rs @@ -18,8 +18,8 @@ impl CharacterBehavior for Data { handle_climb(&data, &mut update); //handle_ability1_input(&data, &mut update); // handle_ability2_input(&data, &mut update); - handle_ability3_input(&data, &mut update); - handle_ability4_input(&data, &mut update); + // handle_ability3_input(&data, &mut update); + // handle_ability4_input(&data, &mut update); handle_dodge_input(&data, &mut update); attempt_input(&data, &mut update); diff --git a/common/sys/src/controller.rs b/common/sys/src/controller.rs index e920445c37..42b448ad80 100644 --- a/common/sys/src/controller.rs +++ b/common/sys/src/controller.rs @@ -34,15 +34,6 @@ impl<'a> System<'a> for Sys { for (entity, controller) in (&read_data.entities, &mut controllers).join() { let mut inputs = &mut controller.inputs; - // Note(imbris): I avoided incrementing the duration with inputs.tick() because - // this is being done manually in voxygen right now so it would double up on - // speed of time. - // Perhaphs the duration aspects of inputs could be - // calculated exclusively on the server (since the client can't be - // trusted anyway). It needs to be considered if these calculations - // being on the client are critical for responsiveness/client-side prediction. - inputs.tick_freshness(); - // Update `inputs.move_dir`. inputs.move_dir = if inputs.move_dir.magnitude_squared() > 1.0 { // Cap move_dir to 1 diff --git a/server/src/sys/agent.rs b/server/src/sys/agent.rs index 1d6cac847e..3473a4252f 100644 --- a/server/src/sys/agent.rs +++ b/server/src/sys/agent.rs @@ -571,16 +571,34 @@ impl<'a> AgentData<'a> { if let Some((travel_to, _destination)) = &agent.rtsim_controller.travel_to { // if it has an rtsim destination and can fly then it should // if it is flying and bumps something above it then it should move down - controller.inputs.fly.set_state( - self.traversal_config.can_fly - && !read_data - .terrain - .ray(self.pos.0, self.pos.0 + (Vec3::unit_z() * 3.0)) - .until(Block::is_solid) - .cast() - .1 - .map_or(true, |b| b.is_some()), - ); + if self.traversal_config.can_fly + && !read_data + .terrain + .ray(self.pos.0, self.pos.0 + (Vec3::unit_z() * 3.0)) + .until(Block::is_solid) + .cast() + .1 + .map_or(true, |b| b.is_some()) + { + controller.actions.push(ControlAction::StartInput { + input: InputKind::Fly, + target: None, + }); + } else { + controller + .actions + .push(ControlAction::CancelInput(InputKind::Fly)) + } + // controller.inputs.fly.set_state( + // self.traversal_config.can_fly + // && !read_data + // .terrain + // .ray(self.pos.0, self.pos.0 + (Vec3::unit_z() * 3.0)) + // .until(Block::is_solid) + // .cast() + // .1 + // .map_or(true, |b| b.is_some()), + // ); if let Some((bearing, speed)) = agent.chaser.chase( &*read_data.terrain, self.pos.0, @@ -594,10 +612,22 @@ impl<'a> AgentData<'a> { controller.inputs.move_dir = bearing.xy().try_normalized().unwrap_or_else(Vec2::zero) * speed.min(agent.rtsim_controller.speed_factor); - controller.inputs.jump.set_state( - bearing.z > 1.5 - || self.traversal_config.can_fly && self.traversal_config.on_ground, - ); + if bearing.z > 1.5 + || self.traversal_config.can_fly && self.traversal_config.on_ground + { + controller.actions.push(ControlAction::StartInput { + input: InputKind::Jump, + target: None, + }); + } else { + controller + .actions + .push(ControlAction::CancelInput(InputKind::Jump)) + } + // controller.inputs.jump.set_state( + // bearing.z > 1.5 + // || self.traversal_config.can_fly && self.traversal_config.on_ground, + // ); controller.inputs.climb = Some(comp::Climb::Up); //.filter(|_| bearing.z > 0.1 || self.physics_state.in_liquid.is_some()); @@ -925,7 +955,17 @@ impl<'a> AgentData<'a> { ) { controller.inputs.move_dir = bearing.xy().try_normalized().unwrap_or_else(Vec2::zero) * speed; - controller.inputs.jump.set_state(bearing.z > 1.5); + if bearing.z > 1.5 { + controller.actions.push(ControlAction::StartInput { + input: InputKind::Jump, + target: None, + }); + } else { + controller + .actions + .push(ControlAction::CancelInput(InputKind::Jump)) + } + // controller.inputs.jump.set_state(bearing.z > 1.5); controller.inputs.move_z = bearing.z; } agent.action_timer += dt.0; @@ -1100,7 +1140,17 @@ impl<'a> AgentData<'a> { ) { controller.inputs.move_dir = bearing.xy().try_normalized().unwrap_or_else(Vec2::zero) * speed; - controller.inputs.jump.set_state(bearing.z > 1.5); + if bearing.z > 1.5 { + controller.actions.push(ControlAction::StartInput { + input: InputKind::Jump, + target: None, + }); + } else { + controller + .actions + .push(ControlAction::CancelInput(InputKind::Jump)) + } + // controller.inputs.jump.set_state(bearing.z > 1.5); controller.inputs.move_z = bearing.z; } @@ -1108,7 +1158,11 @@ impl<'a> AgentData<'a> { && dist_sqrd < 16.0f32.powi(2) && thread_rng().gen::() < 0.02 { - controller.inputs.roll.set_state(true); + controller.actions.push(ControlAction::StartInput { + input: InputKind::Roll, + target: None, + }); + // controller.inputs.roll.set_state(true); } } else { agent.target = None; @@ -1137,7 +1191,11 @@ impl<'a> AgentData<'a> { && self.energy.current() > 800 && thread_rng().gen_bool(0.5) { - controller.inputs.ability3.set_state(true); + controller.actions.push(ControlAction::StartInput { + input: InputKind::Ability(0), + target: None, + }); + // controller.inputs.ability3.set_state(true); agent.action_timer += dt.0; } else { controller.actions.push(ControlAction::StartInput { @@ -1160,14 +1218,28 @@ impl<'a> AgentData<'a> { ) { controller.inputs.move_dir = bearing.xy().try_normalized().unwrap_or_else(Vec2::zero) * speed; - controller.inputs.jump.set_state(bearing.z > 1.5); + if bearing.z > 1.5 { + controller.actions.push(ControlAction::StartInput { + input: InputKind::Jump, + target: None, + }); + } else { + controller + .actions + .push(ControlAction::CancelInput(InputKind::Jump)) + } + // controller.inputs.jump.set_state(bearing.z > 1.5); controller.inputs.move_z = bearing.z; } if self.body.map(|b| b.is_humanoid()).unwrap_or(false) && dist_sqrd < 16.0f32.powi(2) && thread_rng().gen::() < 0.02 { - controller.inputs.roll.set_state(true); + controller.actions.push(ControlAction::StartInput { + input: InputKind::Roll, + target: None, + }); + // controller.inputs.roll.set_state(true); } } else { agent.target = None; @@ -1196,7 +1268,11 @@ impl<'a> AgentData<'a> { && self.energy.current() > 700 && thread_rng().gen_bool(0.9) { - controller.inputs.ability3.set_state(true); + controller.actions.push(ControlAction::StartInput { + input: InputKind::Ability(0), + target: None, + }); + // controller.inputs.ability3.set_state(true); agent.action_timer += dt.0; } else { controller.actions.push(ControlAction::StartInput { @@ -1226,7 +1302,11 @@ impl<'a> AgentData<'a> { .has_skill(Skill::Hammer(HammerSkill::UnlockLeap)) && agent.action_timer > 5.0 { - controller.inputs.ability3.set_state(true); + controller.actions.push(ControlAction::StartInput { + input: InputKind::Ability(0), + target: None, + }); + // controller.inputs.ability3.set_state(true); agent.action_timer = 0.0; } else { agent.action_timer += dt.0; @@ -1234,7 +1314,17 @@ impl<'a> AgentData<'a> { } else { controller.inputs.move_dir = bearing.xy().try_normalized().unwrap_or_else(Vec2::zero) * speed; - controller.inputs.jump.set_state(bearing.z > 1.5); + if bearing.z > 1.5 { + controller.actions.push(ControlAction::StartInput { + input: InputKind::Jump, + target: None, + }); + } else { + controller + .actions + .push(ControlAction::CancelInput(InputKind::Jump)) + } + // controller.inputs.jump.set_state(bearing.z > 1.5); controller.inputs.move_z = bearing.z; } } @@ -1242,7 +1332,11 @@ impl<'a> AgentData<'a> { && dist_sqrd < 16.0f32.powi(2) && thread_rng().gen::() < 0.02 { - controller.inputs.roll.set_state(true); + controller.actions.push(ControlAction::StartInput { + input: InputKind::Roll, + target: None, + }); + // controller.inputs.roll.set_state(true); } } else { agent.target = None; @@ -1258,7 +1352,11 @@ impl<'a> AgentData<'a> { && agent.action_timer < 2.0 && self.energy.current() > 600 { - controller.inputs.ability3.set_state(true); + controller.actions.push(ControlAction::StartInput { + input: InputKind::Ability(0), + target: None, + }); + // controller.inputs.ability3.set_state(true); agent.action_timer += dt.0; } else if agent.action_timer > 2.0 { agent.action_timer = 0.0; @@ -1297,7 +1395,17 @@ impl<'a> AgentData<'a> { } else { controller.inputs.move_dir = bearing.xy().try_normalized().unwrap_or_else(Vec2::zero) * speed; - controller.inputs.jump.set_state(bearing.z > 1.5); + if bearing.z > 1.5 { + controller.actions.push(ControlAction::StartInput { + input: InputKind::Jump, + target: None, + }); + } else { + controller + .actions + .push(ControlAction::CancelInput(InputKind::Jump)) + } + // controller.inputs.jump.set_state(bearing.z > 1.5); controller.inputs.move_z = bearing.z; } } @@ -1305,7 +1413,11 @@ impl<'a> AgentData<'a> { && dist_sqrd < 16.0f32.powi(2) && thread_rng().gen::() < 0.02 { - controller.inputs.roll.set_state(true); + controller.actions.push(ControlAction::StartInput { + input: InputKind::Roll, + target: None, + }); + // controller.inputs.roll.set_state(true); } } else { agent.target = None; @@ -1315,7 +1427,11 @@ impl<'a> AgentData<'a> { if self.body.map(|b| b.is_humanoid()).unwrap_or(false) && dist_sqrd < (2.0 * min_attack_dist * self.scale).powi(2) { - controller.inputs.roll.set_state(true); + controller.actions.push(ControlAction::StartInput { + input: InputKind::Roll, + target: None, + }); + // controller.inputs.roll.set_state(true); } else if dist_sqrd < MAX_CHASE_DIST.powi(2) { if let Some((bearing, speed)) = agent.chaser.chase( &*terrain, @@ -1358,7 +1474,11 @@ impl<'a> AgentData<'a> { .actions .push(ControlAction::CancelInput(InputKind::Secondary)); // controller.inputs.secondary.set_state(false); - controller.inputs.ability3.set_state(true); + controller.actions.push(ControlAction::StartInput { + input: InputKind::Ability(0), + target: None, + }); + // controller.inputs.ability3.set_state(true); agent.action_timer += dt.0; } else { controller @@ -1375,7 +1495,17 @@ impl<'a> AgentData<'a> { } else { controller.inputs.move_dir = bearing.xy().try_normalized().unwrap_or_else(Vec2::zero) * speed; - controller.inputs.jump.set_state(bearing.z > 1.5); + if bearing.z > 1.5 { + controller.actions.push(ControlAction::StartInput { + input: InputKind::Jump, + target: None, + }); + } else { + controller + .actions + .push(ControlAction::CancelInput(InputKind::Jump)) + } + // controller.inputs.jump.set_state(bearing.z > 1.5); controller.inputs.move_z = bearing.z; } } @@ -1383,7 +1513,11 @@ impl<'a> AgentData<'a> { && dist_sqrd < 16.0f32.powi(2) && thread_rng().gen::() < 0.02 { - controller.inputs.roll.set_state(true); + controller.actions.push(ControlAction::StartInput { + input: InputKind::Roll, + target: None, + }); + // controller.inputs.roll.set_state(true); } } else if can_see_tgt(&*terrain, self.pos, tgt_pos, dist_sqrd) { if let Some((bearing, speed)) = agent.chaser.chase( @@ -1398,7 +1532,17 @@ impl<'a> AgentData<'a> { ) { controller.inputs.move_dir = bearing.xy().try_normalized().unwrap_or_else(Vec2::zero) * speed; - controller.inputs.jump.set_state(bearing.z > 1.5); + if bearing.z > 1.5 { + controller.actions.push(ControlAction::StartInput { + input: InputKind::Jump, + target: None, + }); + } else { + controller + .actions + .push(ControlAction::CancelInput(InputKind::Jump)) + } + // controller.inputs.jump.set_state(bearing.z > 1.5); controller.inputs.move_z = bearing.z; } } else { @@ -1409,7 +1553,11 @@ impl<'a> AgentData<'a> { if self.body.map(|b| b.is_humanoid()).unwrap_or(false) && dist_sqrd < (min_attack_dist * self.scale).powi(2) { - controller.inputs.roll.set_state(true); + controller.actions.push(ControlAction::StartInput { + input: InputKind::Roll, + target: None, + }); + // controller.inputs.roll.set_state(true); } else if dist_sqrd < (5.0 * min_attack_dist * self.scale).powi(2) { if agent.action_timer < 1.5 { controller.inputs.move_dir = (tgt_pos.0 - self.pos.0) @@ -1435,7 +1583,11 @@ impl<'a> AgentData<'a> { && self.energy.current() > 800 && thread_rng().gen::() > 0.8 { - controller.inputs.ability3.set_state(true); + controller.actions.push(ControlAction::StartInput { + input: InputKind::Ability(0), + target: None, + }); + // controller.inputs.ability3.set_state(true); } else if self.energy.current() > 10 { controller.actions.push(ControlAction::StartInput { input: InputKind::Secondary, @@ -1475,7 +1627,17 @@ impl<'a> AgentData<'a> { } else { controller.inputs.move_dir = bearing.xy().try_normalized().unwrap_or_else(Vec2::zero) * speed; - controller.inputs.jump.set_state(bearing.z > 1.5); + if bearing.z > 1.5 { + controller.actions.push(ControlAction::StartInput { + input: InputKind::Jump, + target: None, + }); + } else { + controller + .actions + .push(ControlAction::CancelInput(InputKind::Jump)) + } + // controller.inputs.jump.set_state(bearing.z > 1.5); controller.inputs.move_z = bearing.z; } } @@ -1483,7 +1645,11 @@ impl<'a> AgentData<'a> { && dist_sqrd < 16.0f32.powi(2) && thread_rng().gen::() < 0.02 { - controller.inputs.roll.set_state(true); + controller.actions.push(ControlAction::StartInput { + input: InputKind::Roll, + target: None, + }); + // controller.inputs.roll.set_state(true); } } else if can_see_tgt(&*terrain, self.pos, tgt_pos, dist_sqrd) { if let Some((bearing, speed)) = agent.chaser.chase( @@ -1498,7 +1664,17 @@ impl<'a> AgentData<'a> { ) { controller.inputs.move_dir = bearing.xy().try_normalized().unwrap_or_else(Vec2::zero) * speed; - controller.inputs.jump.set_state(bearing.z > 1.5); + if bearing.z > 1.5 { + controller.actions.push(ControlAction::StartInput { + input: InputKind::Jump, + target: None, + }); + } else { + controller + .actions + .push(ControlAction::CancelInput(InputKind::Jump)) + } + // controller.inputs.jump.set_state(bearing.z > 1.5); controller.inputs.move_z = bearing.z; } } else { @@ -1517,7 +1693,11 @@ impl<'a> AgentData<'a> { //controller.inputs.primary.set_state(true); } else if dist_sqrd < MAX_CHASE_DIST.powi(2) { if self.vel.0.is_approx_zero() { - controller.inputs.ability3.set_state(true); + controller.actions.push(ControlAction::StartInput { + input: InputKind::Ability(0), + target: None, + }); + // controller.inputs.ability3.set_state(true); } if let Some((bearing, speed)) = agent.chaser.chase( &*terrain, @@ -1545,7 +1725,17 @@ impl<'a> AgentData<'a> { } else { controller.inputs.move_dir = bearing.xy().try_normalized().unwrap_or_else(Vec2::zero) * speed; - controller.inputs.jump.set_state(bearing.z > 1.5); + if bearing.z > 1.5 { + controller.actions.push(ControlAction::StartInput { + input: InputKind::Jump, + target: None, + }); + } else { + controller + .actions + .push(ControlAction::CancelInput(InputKind::Jump)) + } + // controller.inputs.jump.set_state(bearing.z > 1.5); controller.inputs.move_z = bearing.z; } } @@ -1617,7 +1807,17 @@ impl<'a> AgentData<'a> { ) { controller.inputs.move_dir = bearing.xy().try_normalized().unwrap_or_else(Vec2::zero) * speed; - controller.inputs.jump.set_state(bearing.z > 1.5); + if bearing.z > 1.5 { + controller.actions.push(ControlAction::StartInput { + input: InputKind::Jump, + target: None, + }); + } else { + controller + .actions + .push(ControlAction::CancelInput(InputKind::Jump)) + } + // controller.inputs.jump.set_state(bearing.z > 1.5); controller.inputs.move_z = bearing.z; } } else { @@ -1671,12 +1871,32 @@ impl<'a> AgentData<'a> { target: None, }); // controller.inputs.secondary.set_state(true); - controller.inputs.jump.set_state(bearing.z > 1.5); + if bearing.z > 1.5 { + controller.actions.push(ControlAction::StartInput { + input: InputKind::Jump, + target: None, + }); + } else { + controller + .actions + .push(ControlAction::CancelInput(InputKind::Jump)) + } + // controller.inputs.jump.set_state(bearing.z > 1.5); controller.inputs.move_z = bearing.z; } else { controller.inputs.move_dir = bearing.xy().try_normalized().unwrap_or_else(Vec2::zero) * speed; - controller.inputs.jump.set_state(bearing.z > 1.5); + if bearing.z > 1.5 { + controller.actions.push(ControlAction::StartInput { + input: InputKind::Jump, + target: None, + }); + } else { + controller + .actions + .push(ControlAction::CancelInput(InputKind::Jump)) + } + // controller.inputs.jump.set_state(bearing.z > 1.5); controller.inputs.move_z = bearing.z; } } else { @@ -1727,7 +1947,17 @@ impl<'a> AgentData<'a> { ) { controller.inputs.move_dir = bearing.xy().try_normalized().unwrap_or_else(Vec2::zero) * speed; - controller.inputs.jump.set_state(bearing.z > 1.5); + if bearing.z > 1.5 { + controller.actions.push(ControlAction::StartInput { + input: InputKind::Jump, + target: None, + }); + } else { + controller + .actions + .push(ControlAction::CancelInput(InputKind::Jump)) + } + // controller.inputs.jump.set_state(bearing.z > 1.5); controller.inputs.move_z = bearing.z; } } else { @@ -1768,7 +1998,17 @@ impl<'a> AgentData<'a> { ) { controller.inputs.move_dir = bearing.xy().try_normalized().unwrap_or_else(Vec2::zero) * speed; - controller.inputs.jump.set_state(bearing.z > 1.5); + if bearing.z > 1.5 { + controller.actions.push(ControlAction::StartInput { + input: InputKind::Jump, + target: None, + }); + } else { + controller + .actions + .push(ControlAction::CancelInput(InputKind::Jump)) + } + // controller.inputs.jump.set_state(bearing.z > 1.5); controller.inputs.move_z = bearing.z; } } else { @@ -1808,7 +2048,17 @@ impl<'a> AgentData<'a> { ) { controller.inputs.move_dir = bearing.xy().try_normalized().unwrap_or_else(Vec2::zero) * speed; - controller.inputs.jump.set_state(bearing.z > 1.5); + if bearing.z > 1.5 { + controller.actions.push(ControlAction::StartInput { + input: InputKind::Jump, + target: None, + }); + } else { + controller + .actions + .push(ControlAction::CancelInput(InputKind::Jump)) + } + // controller.inputs.jump.set_state(bearing.z > 1.5); controller.inputs.move_z = bearing.z; } } else { @@ -1824,7 +2074,11 @@ impl<'a> AgentData<'a> { }); // controller.inputs.secondary.set_state(true); } else if dist_sqrd < (5.0 * min_attack_dist * self.scale).powi(2) { - controller.inputs.ability3.set_state(true); + controller.actions.push(ControlAction::StartInput { + input: InputKind::Ability(0), + target: None, + }); + // controller.inputs.ability3.set_state(true); } else if dist_sqrd < MAX_CHASE_DIST.powi(2) { if let Some((bearing, speed)) = agent.chaser.chase( &*terrain, @@ -1847,7 +2101,17 @@ impl<'a> AgentData<'a> { } else { controller.inputs.move_dir = bearing.xy().try_normalized().unwrap_or_else(Vec2::zero) * speed; - controller.inputs.jump.set_state(bearing.z > 1.5); + if bearing.z > 1.5 { + controller.actions.push(ControlAction::StartInput { + input: InputKind::Jump, + target: None, + }); + } else { + controller + .actions + .push(ControlAction::CancelInput(InputKind::Jump)) + } + // controller.inputs.jump.set_state(bearing.z > 1.5); controller.inputs.move_z = bearing.z; } } @@ -1888,7 +2152,17 @@ impl<'a> AgentData<'a> { ) { controller.inputs.move_dir = bearing.xy().try_normalized().unwrap_or_else(Vec2::zero) * speed; - controller.inputs.jump.set_state(bearing.z > 1.5); + if bearing.z > 1.5 { + controller.actions.push(ControlAction::StartInput { + input: InputKind::Jump, + target: None, + }); + } else { + controller + .actions + .push(ControlAction::CancelInput(InputKind::Jump)) + } + // controller.inputs.jump.set_state(bearing.z > 1.5); controller.inputs.move_z = bearing.z; } } else { @@ -1929,7 +2203,11 @@ impl<'a> AgentData<'a> { //controller.inputs.primary.set_state(true); agent.action_timer += dt.0; } else if agent.action_timer < 6.0 { - controller.inputs.ability3.set_state(true); + controller.actions.push(ControlAction::StartInput { + input: InputKind::Ability(0), + target: None, + }); + // controller.inputs.ability3.set_state(true); agent.action_timer += dt.0; } else { agent.action_timer = 0.0; @@ -1947,7 +2225,17 @@ impl<'a> AgentData<'a> { ) { controller.inputs.move_dir = bearing.xy().try_normalized().unwrap_or_else(Vec2::zero) * speed; - controller.inputs.jump.set_state(bearing.z > 1.5); + if bearing.z > 1.5 { + controller.actions.push(ControlAction::StartInput { + input: InputKind::Jump, + target: None, + }); + } else { + controller + .actions + .push(ControlAction::CancelInput(InputKind::Jump)) + } + // controller.inputs.jump.set_state(bearing.z > 1.5); controller.inputs.move_z = bearing.z; } } else { @@ -1975,7 +2263,17 @@ impl<'a> AgentData<'a> { ) { controller.inputs.move_dir = bearing.xy().try_normalized().unwrap_or_else(Vec2::zero) * speed; - controller.inputs.jump.set_state(bearing.z > 1.5); + if bearing.z > 1.5 { + controller.actions.push(ControlAction::StartInput { + input: InputKind::Jump, + target: None, + }); + } else { + controller + .actions + .push(ControlAction::CancelInput(InputKind::Jump)) + } + // controller.inputs.jump.set_state(bearing.z > 1.5); controller.inputs.move_z = bearing.z; } } else { @@ -2046,7 +2344,17 @@ impl<'a> AgentData<'a> { let dist_sqrd = self.pos.0.distance_squared(tgt_pos.0); controller.inputs.move_dir = bearing.xy().try_normalized().unwrap_or_else(Vec2::zero) * speed.min(0.2 + (dist_sqrd - AVG_FOLLOW_DIST.powi(2)) / 8.0); - controller.inputs.jump.set_state(bearing.z > 1.5); + if bearing.z > 1.5 { + controller.actions.push(ControlAction::StartInput { + input: InputKind::Jump, + target: None, + }); + } else { + controller + .actions + .push(ControlAction::CancelInput(InputKind::Jump)) + } + // controller.inputs.jump.set_state(bearing.z > 1.5); controller.inputs.move_z = bearing.z; } } diff --git a/voxygen/src/controller.rs b/voxygen/src/controller.rs index a426ea3ee8..0fdbfcc2c4 100644 --- a/voxygen/src/controller.rs +++ b/voxygen/src/controller.rs @@ -117,9 +117,6 @@ impl From<&crate::settings::GamepadSettings> for ControllerSettings { map.entry(settings.game_buttons.sneak) .or_default() .push(GameInput::Sneak); - /*map.entry(settings.game_buttons.wall_leap) - .or_default() - .push(GameInput::WallLeap);*/ map.entry(settings.game_buttons.toggle_lantern) .or_default() .push(GameInput::ToggleLantern); @@ -177,9 +174,6 @@ impl From<&crate::settings::GamepadSettings> for ControllerSettings { map.entry(settings.game_buttons.swap_loadout) .or_default() .push(GameInput::SwapLoadout); - /*map.entry(settings.game_buttons.charge) - .or_default() - .push(GameInput::Charge);*/ map }, menu_button_map: { diff --git a/voxygen/src/session.rs b/voxygen/src/session.rs index e8561cb88a..8c26fa2fa1 100644 --- a/voxygen/src/session.rs +++ b/voxygen/src/session.rs @@ -126,7 +126,6 @@ impl SessionState { outcomes: &mut Vec, ) -> Result { span!(_guard, "tick", "Session::tick"); - self.inputs.tick(dt); let mut client = self.client.borrow_mut(); for event in client.tick(self.inputs.clone(), dt, crate::ecs::sys::add_local_systems)? { @@ -386,7 +385,7 @@ impl PlayState for SessionState { } }, GameInput::Roll => { - let client = self.client.borrow(); + let mut client = self.client.borrow_mut(); if can_build { if state { if let Some(block) = select_pos.and_then(|sp| { @@ -396,7 +395,8 @@ impl PlayState for SessionState { } } } else { - self.inputs.roll.set_state(state); + client.handle_input(InputKind::Roll, state); + // self.inputs.roll.set_state(state); } }, GameInput::Respawn => { @@ -406,7 +406,8 @@ impl PlayState for SessionState { } }, GameInput::Jump => { - self.inputs.jump.set_state(state); + let mut client = self.client.borrow_mut(); + client.handle_input(InputKind::Jump, state); }, GameInput::SwimUp => { self.key_state.swim_up = state; @@ -462,7 +463,14 @@ impl PlayState for SessionState { } }, GameInput::Fly => { + // Not sure where to put comment, but I noticed when testing flight + // Syncing of inputs between mounter and mountee broke with + // controller change self.key_state.fly ^= state; + let mut client = self.client.borrow_mut(); + client.handle_input(InputKind::Fly, self.key_state.fly); + // self.inputs.fly.set_state(self.key_state. + // fly); }, GameInput::Climb => { self.key_state.climb_up = state; @@ -726,7 +734,6 @@ impl PlayState for SessionState { }; self.inputs.climb = self.key_state.climb(); - self.inputs.fly.set_state(self.key_state.fly); self.inputs.move_z = self.key_state.swim_up as i32 as f32 - self.key_state.swim_down as i32 as f32; @@ -1219,8 +1226,16 @@ impl PlayState for SessionState { let mut client = self.client.borrow_mut(); client.perform_trade_action(action); }, - HudEvent::Ability3(state) => self.inputs.ability3.set_state(state), - HudEvent::Ability4(state) => self.inputs.ability4.set_state(state), + HudEvent::Ability3(state) => { + let mut client = self.client.borrow_mut(); + client.handle_input(InputKind::Ability(0), state); + // self.inputs.ability3.set_state(state); + }, + HudEvent::Ability4(state) => { + let mut client = self.client.borrow_mut(); + client.handle_input(InputKind::Ability(1), state); + // self.inputs.ability4.set_state(state); + }, HudEvent::ChangeFOV(new_fov) => { global_state.settings.graphics.fov = new_fov; global_state.settings.save_to_file_warn(); diff --git a/voxygen/src/settings.rs b/voxygen/src/settings.rs index 4217044003..4db88fafe5 100644 --- a/voxygen/src/settings.rs +++ b/voxygen/src/settings.rs @@ -138,7 +138,6 @@ impl ControlSettings { GameInput::SwimDown => KeyMouse::Key(VirtualKeyCode::LShift), GameInput::Fly => KeyMouse::Key(VirtualKeyCode::H), GameInput::Sneak => KeyMouse::Key(VirtualKeyCode::LControl), - //GameInput::WallLeap => MIDDLE_CLICK_KEY, GameInput::ToggleLantern => KeyMouse::Key(VirtualKeyCode::G), GameInput::Mount => KeyMouse::Key(VirtualKeyCode::F), GameInput::Map => KeyMouse::Key(VirtualKeyCode::M), @@ -158,7 +157,6 @@ impl ControlSettings { GameInput::Respawn => KeyMouse::Key(VirtualKeyCode::Space), GameInput::Interact => KeyMouse::Key(VirtualKeyCode::E), GameInput::ToggleWield => KeyMouse::Key(VirtualKeyCode::T), - //GameInput::Charge => KeyMouse::Key(VirtualKeyCode::Key1), GameInput::FreeLook => KeyMouse::Key(VirtualKeyCode::L), GameInput::AutoWalk => KeyMouse::Key(VirtualKeyCode::Period), GameInput::CycleCamera => KeyMouse::Key(VirtualKeyCode::Key0), @@ -257,7 +255,6 @@ pub mod con_settings { pub swimup: Button, pub swimdown: Button, pub sneak: Button, - //pub wall_leap: Button, pub toggle_lantern: Button, pub mount: Button, pub map: Button, @@ -349,7 +346,6 @@ pub mod con_settings { swimup: Button::Simple(GilButton::South), swimdown: Button::Simple(GilButton::East), sneak: Button::Simple(GilButton::East), - //wall_leap: Button::Simple(GilButton::Unknown), toggle_lantern: Button::Simple(GilButton::DPadLeft), mount: Button::Simple(GilButton::North), map: Button::Simple(GilButton::Select), @@ -371,7 +367,6 @@ pub mod con_settings { interact: Button::Simple(GilButton::North), toggle_wield: Button::Simple(GilButton::West), swap_loadout: Button::Simple(GilButton::LeftThumb), - //charge: Button::Simple(GilButton::Unknown), } } } diff --git a/voxygen/src/window.rs b/voxygen/src/window.rs index ab59174d32..8751865867 100644 --- a/voxygen/src/window.rs +++ b/voxygen/src/window.rs @@ -46,7 +46,6 @@ pub enum GameInput { SwimDown, Fly, Sneak, - //WallLeap, ToggleLantern, Mount, Chat, @@ -69,7 +68,6 @@ pub enum GameInput { Respawn, Interact, ToggleWield, - //Charge, SwapLoadout, FreeLook, AutoWalk, @@ -99,7 +97,6 @@ impl GameInput { GameInput::SwimDown => "gameinput.swimdown", GameInput::Fly => "gameinput.fly", GameInput::Sneak => "gameinput.sneak", - //GameInput::WallLeap => "gameinput.wallleap", GameInput::ToggleLantern => "gameinput.togglelantern", GameInput::Mount => "gameinput.mount", GameInput::Chat => "gameinput.chat", @@ -123,7 +120,6 @@ impl GameInput { GameInput::Respawn => "gameinput.respawn", GameInput::Interact => "gameinput.interact", GameInput::ToggleWield => "gameinput.togglewield", - //GameInput::Charge => "gameinput.charge", GameInput::FreeLook => "gameinput.freelook", GameInput::AutoWalk => "gameinput.autowalk", GameInput::Slot1 => "gameinput.slot1", From ecff675cc4e286b17cea46d86ab1c83d78c0ad19 Mon Sep 17 00:00:00 2001 From: Sam Date: Sun, 14 Mar 2021 16:35:28 -0400 Subject: [PATCH 7/7] Wielding now works again Rolling now resumes combo states correctly again Cleanup --- common/src/comp/controller.rs | 9 +- common/src/states/basic_aura.rs | 14 +-- common/src/states/basic_beam.rs | 18 ++-- common/src/states/basic_melee.rs | 14 +-- common/src/states/basic_ranged.rs | 14 +-- common/src/states/behavior.rs | 4 +- common/src/states/charged_melee.rs | 22 ++--- common/src/states/charged_ranged.rs | 24 ++--- common/src/states/climb.rs | 4 +- common/src/states/combo_melee.rs | 14 +-- common/src/states/dash_melee.rs | 21 ++--- common/src/states/healing_beam.rs | 18 ++-- common/src/states/leap_melee.rs | 14 +-- common/src/states/repeater_ranged.rs | 14 +-- common/src/states/roll.rs | 22 ++--- common/src/states/shockwave.rs | 14 +-- common/src/states/spin_melee.rs | 17 ++-- common/src/states/utils.rs | 45 ++++----- common/src/states/wielding.rs | 7 -- common/sys/src/character_behavior.rs | 5 - server/src/sys/agent.rs | 93 ------------------- .../audio/sfx/event_mapper/combat/tests.rs | 6 +- voxygen/src/session.rs | 9 -- voxygen/src/settings.rs | 1 - 24 files changed, 120 insertions(+), 303 deletions(-) diff --git a/common/src/comp/controller.rs b/common/src/comp/controller.rs index 339e25ffc3..1240026baa 100644 --- a/common/src/comp/controller.rs +++ b/common/src/comp/controller.rs @@ -123,8 +123,13 @@ pub enum InputKind { Ability(usize) = 2, Roll = 3, Jump = 4, - Glide = 5, - Fly = 6, + Fly = 5, +} + +impl InputKind { + pub fn is_ability(self) -> bool { + matches!(self, Self::Primary | Self::Secondary | Self::Ability(_)) + } } #[derive(Clone, Copy, Debug, PartialEq, Serialize, Deserialize)] diff --git a/common/src/states/basic_aura.rs b/common/src/states/basic_aura.rs index a30d458870..d106b74578 100644 --- a/common/src/states/basic_aura.rs +++ b/common/src/states/basic_aura.rs @@ -51,15 +51,6 @@ impl CharacterBehavior for Data { handle_move(data, &mut update, 0.8); handle_jump(data, &mut update); - // if !ability_key_is_pressed(data, self.static_data.ability_info.key) { - // handle_interrupt(data, &mut update, false); - // match update.character { - // CharacterState::BasicAura(_) => {}, - // _ => { - // return update; - // }, - // } - // } match self.stage_section { StageSection::Buildup => { @@ -132,6 +123,11 @@ impl CharacterBehavior for Data { }, } + // At end of state logic so an interrupt isn't overwritten + if !input_is_pressed(data, self.static_data.ability_info.input) { + handle_state_interrupt(data, &mut update, false); + } + update } } diff --git a/common/src/states/basic_beam.rs b/common/src/states/basic_beam.rs index ea6d323f8d..93c3c877cc 100644 --- a/common/src/states/basic_beam.rs +++ b/common/src/states/basic_beam.rs @@ -71,15 +71,6 @@ impl CharacterBehavior for Data { handle_move(data, &mut update, 0.4); handle_jump(data, &mut update); - // if !ability_key_is_pressed(data, self.static_data.ability_info.key) { - // handle_interrupt(data, &mut update, false); - // match update.character { - // CharacterState::BasicBeam(_) => {}, - // _ => { - // return update; - // }, - // } - // } match self.stage_section { StageSection::Buildup => { @@ -108,9 +99,7 @@ impl CharacterBehavior for Data { } }, StageSection::Cast => { - if - /* ability_key_is_pressed(data, self.static_data.ability_info.key) */ - input_is_pressed(data, self.static_data.ability_info.input) + if input_is_pressed(data, self.static_data.ability_info.input) && (self.static_data.energy_drain <= f32::EPSILON || update.energy.current() > 0) { @@ -205,6 +194,11 @@ impl CharacterBehavior for Data { }, } + // At end of state logic so an interrupt isn't overwritten + if !input_is_pressed(data, self.static_data.ability_info.input) { + handle_state_interrupt(data, &mut update, false); + } + update } } diff --git a/common/src/states/basic_melee.rs b/common/src/states/basic_melee.rs index 85a816b997..6b2da86fc3 100644 --- a/common/src/states/basic_melee.rs +++ b/common/src/states/basic_melee.rs @@ -52,15 +52,6 @@ impl CharacterBehavior for Data { handle_move(data, &mut update, 0.7); handle_jump(data, &mut update); - // if !ability_key_is_pressed(data, self.static_data.ability_info.key) { - // handle_interrupt(data, &mut update, false); - // match update.character { - // CharacterState::BasicMelee(_) => {}, - // _ => { - // return update; - // }, - // } - // } match self.stage_section { StageSection::Buildup => { @@ -177,6 +168,11 @@ impl CharacterBehavior for Data { }, } + // At end of state logic so an interrupt isn't overwritten + if !input_is_pressed(data, self.static_data.ability_info.input) { + handle_state_interrupt(data, &mut update, false); + } + update } } diff --git a/common/src/states/basic_ranged.rs b/common/src/states/basic_ranged.rs index d4c4a47bc8..501f92d3a6 100644 --- a/common/src/states/basic_ranged.rs +++ b/common/src/states/basic_ranged.rs @@ -45,15 +45,6 @@ impl CharacterBehavior for Data { handle_move(data, &mut update, 0.3); handle_jump(data, &mut update); - // if !ability_key_is_pressed(data, self.static_data.ability_info.key) { - // handle_interrupt(data, &mut update, false); - // match update.character { - // CharacterState::BasicRanged(_) => {}, - // _ => { - // return update; - // }, - // } - // } match self.stage_section { StageSection::Buildup => { @@ -124,6 +115,11 @@ impl CharacterBehavior for Data { }, } + // At end of state logic so an interrupt isn't overwritten + if !input_is_pressed(data, self.static_data.ability_info.input) { + handle_state_interrupt(data, &mut update, false); + } + update } } diff --git a/common/src/states/behavior.rs b/common/src/states/behavior.rs index c0722ba0e3..1dd4074a5e 100644 --- a/common/src/states/behavior.rs +++ b/common/src/states/behavior.rs @@ -29,7 +29,7 @@ pub trait CharacterBehavior { fn sneak(&self, data: &JoinData) -> StateUpdate { StateUpdate::from(data) } fn stand(&self, data: &JoinData) -> StateUpdate { StateUpdate::from(data) } fn talk(&self, data: &JoinData) -> StateUpdate { StateUpdate::from(data) } - fn handle_input(&self, data: &JoinData, input: InputKind, _target: Option) -> StateUpdate { + fn start_input(&self, data: &JoinData, input: InputKind, _target: Option) -> StateUpdate { let mut update = StateUpdate::from(data); update.queued_inputs.insert(input); update @@ -51,7 +51,7 @@ pub trait CharacterBehavior { ControlAction::Sneak => self.sneak(data), ControlAction::Stand => self.stand(data), ControlAction::Talk => self.talk(data), - ControlAction::StartInput { input, target } => self.handle_input(data, input, target), + ControlAction::StartInput { input, target } => self.start_input(data, input, target), ControlAction::CancelInput(input) => self.cancel_input(data, input), } } diff --git a/common/src/states/charged_melee.rs b/common/src/states/charged_melee.rs index b3fecff907..a2c360bb07 100644 --- a/common/src/states/charged_melee.rs +++ b/common/src/states/charged_melee.rs @@ -68,21 +68,10 @@ impl CharacterBehavior for Data { handle_move(data, &mut update, 0.7); handle_jump(data, &mut update); - // if !ability_key_is_pressed(data, self.static_data.ability_info.key) { - // handle_interrupt(data, &mut update, false); - // match update.character { - // CharacterState::ChargedMelee(_) => {}, - // _ => { - // return update; - // }, - // } - // } match self.stage_section { StageSection::Charge => { - if - /* ability_key_is_pressed(data, self.static_data.ability_info.key) */ - input_is_pressed(data, self.static_data.ability_info.input) + if input_is_pressed(data, self.static_data.ability_info.input) && update.energy.current() as f32 >= self.static_data.energy_cost && self.timer < self.static_data.charge_duration { @@ -109,9 +98,7 @@ impl CharacterBehavior for Data { * self.static_data.speed) as i32, source: EnergySource::Ability, }); - } else if - /* ability_key_is_pressed(data, self.static_data.ability_info.key) */ - input_is_pressed(data, self.static_data.ability_info.input) + } else if input_is_pressed(data, self.static_data.ability_info.input) && update.energy.current() as f32 >= self.static_data.energy_cost { // Maintains charge @@ -244,6 +231,11 @@ impl CharacterBehavior for Data { }, } + // At end of state logic so an interrupt isn't overwritten + if !input_is_pressed(data, self.static_data.ability_info.input) { + handle_state_interrupt(data, &mut update, false); + } + update } } diff --git a/common/src/states/charged_ranged.rs b/common/src/states/charged_ranged.rs index 65fdfd34d6..909f5056f6 100644 --- a/common/src/states/charged_ranged.rs +++ b/common/src/states/charged_ranged.rs @@ -68,15 +68,6 @@ impl CharacterBehavior for Data { handle_move(data, &mut update, self.static_data.move_speed); handle_jump(data, &mut update); - // if !ability_key_is_pressed(data, self.static_data.ability_info.key) { - // handle_interrupt(data, &mut update, false); - // match update.character { - // CharacterState::ChargedRanged(_) => {}, - // _ => { - // return update; - // }, - // } - // } match self.stage_section { StageSection::Buildup => { @@ -99,9 +90,7 @@ impl CharacterBehavior for Data { } }, StageSection::Charge => { - if - /* \!ability_key_is_pressed(data, self.static_data.ability_info.key) */ - !input_is_pressed(data, self.static_data.ability_info.input) && !self.exhausted { + if !input_is_pressed(data, self.static_data.ability_info.input) && !self.exhausted { let charge_frac = (self.timer.as_secs_f32() / self.static_data.charge_duration.as_secs_f32()) .min(1.0); @@ -162,7 +151,7 @@ impl CharacterBehavior for Data { ..*self }); } else if self.timer < self.static_data.charge_duration - && /*ability_key_is_pressed(data, self.static_data.ability_info.key)*/ input_is_pressed(data, self.static_data.ability_info.input) + && input_is_pressed(data, self.static_data.ability_info.input) { // Charges update.character = CharacterState::ChargedRanged(Data { @@ -182,9 +171,7 @@ impl CharacterBehavior for Data { * self.static_data.speed) as i32, source: EnergySource::Ability, }); - } else if - /* ability_key_is_pressed(data, self.static_data.ability_info.key) */ - input_is_pressed(data, self.static_data.ability_info.input) { + } else if input_is_pressed(data, self.static_data.ability_info.input) { // Holds charge update.character = CharacterState::ChargedRanged(Data { timer: self @@ -227,6 +214,11 @@ impl CharacterBehavior for Data { }, } + // At end of state logic so an interrupt isn't overwritten + if !input_is_pressed(data, self.static_data.ability_info.input) { + handle_state_interrupt(data, &mut update, false); + } + update } } diff --git a/common/src/states/climb.rs b/common/src/states/climb.rs index b169e115aa..51a5a176d5 100644 --- a/common/src/states/climb.rs +++ b/common/src/states/climb.rs @@ -32,9 +32,7 @@ impl CharacterBehavior for Data { ) { (wall_dir, climb) } else { - if - /* data.inputs.jump.is_pressed() */ - input_is_pressed(data, InputKind::Jump) { + if input_is_pressed(data, InputKind::Jump) { // They've climbed atop something, give them a boost update .local_events diff --git a/common/src/states/combo_melee.rs b/common/src/states/combo_melee.rs index aadbcad172..e3ff93f0cf 100644 --- a/common/src/states/combo_melee.rs +++ b/common/src/states/combo_melee.rs @@ -121,15 +121,6 @@ impl CharacterBehavior for Data { handle_orientation(data, &mut update, 1.0); handle_move(data, &mut update, 0.3); - // if !ability_key_is_pressed(data, self.static_data.ability_info.key) { - // handle_interrupt(data, &mut update, self.static_data.is_interruptible); - // match update.character { - // CharacterState::ComboMelee(_) => {}, - // _ => { - // return update; - // }, - // } - // } let stage_index = (self.stage - 1) as usize; @@ -284,6 +275,11 @@ impl CharacterBehavior for Data { }, } + // At end of state logic so an interrupt isn't overwritten + if !input_is_pressed(data, self.static_data.ability_info.input) { + handle_state_interrupt(data, &mut update, self.static_data.is_interruptible); + } + update } } diff --git a/common/src/states/dash_melee.rs b/common/src/states/dash_melee.rs index c78b9d7ee4..ce8a051f7e 100644 --- a/common/src/states/dash_melee.rs +++ b/common/src/states/dash_melee.rs @@ -74,15 +74,6 @@ impl CharacterBehavior for Data { handle_orientation(data, &mut update, 1.0); handle_move(data, &mut update, 0.1); - // if !ability_key_is_pressed(data, self.static_data.ability_info.key) { - // handle_interrupt(data, &mut update, self.static_data.is_interruptible); - // match update.character { - // CharacterState::DashMelee(_) => {}, - // _ => { - // return update; - // }, - // } - // } match self.stage_section { StageSection::Buildup => { @@ -98,10 +89,7 @@ impl CharacterBehavior for Data { } else { // Transitions to charge section of stage update.character = CharacterState::DashMelee(Data { - auto_charge: /*\!ability_key_is_pressed( - data, - self.static_data.ability_info.key, - )*/input_is_pressed(data, self.static_data.ability_info.input), + auto_charge: !input_is_pressed(data, self.static_data.ability_info.input), timer: Duration::default(), stage_section: StageSection::Charge, ..*self @@ -111,7 +99,7 @@ impl CharacterBehavior for Data { StageSection::Charge => { if (self.static_data.infinite_charge || self.timer < self.static_data.charge_duration) - && (/* ability_key_is_pressed(data, self.static_data.ability_info.key) */input_is_pressed(data, self.static_data.ability_info.input) + && (input_is_pressed(data, self.static_data.ability_info.input) || (self.auto_charge && self.timer < self.static_data.charge_duration)) && update.energy.current() > 0 { @@ -266,6 +254,11 @@ impl CharacterBehavior for Data { }, } + // At end of state logic so an interrupt isn't overwritten + if !input_is_pressed(data, self.static_data.ability_info.input) { + handle_state_interrupt(data, &mut update, self.static_data.is_interruptible); + } + update } } diff --git a/common/src/states/healing_beam.rs b/common/src/states/healing_beam.rs index 941c35d72e..bfaae55b08 100644 --- a/common/src/states/healing_beam.rs +++ b/common/src/states/healing_beam.rs @@ -54,15 +54,6 @@ impl CharacterBehavior for Data { handle_move(data, &mut update, 0.4); handle_jump(data, &mut update); - // if !ability_key_is_pressed(data, self.static_data.ability_info.key) { - // handle_interrupt(data, &mut update, false); - // match update.character { - // CharacterState::HealingBeam(_) => {}, - // _ => { - // return update; - // }, - // } - // } match self.stage_section { StageSection::Buildup => { @@ -91,9 +82,7 @@ impl CharacterBehavior for Data { } }, StageSection::Cast => { - if - /* ability_key_is_pressed(data, self.static_data.ability_info.key) */ - input_is_pressed(data, self.static_data.ability_info.input) { + if input_is_pressed(data, self.static_data.ability_info.input) { let speed = self.static_data.range / self.static_data.beam_duration.as_secs_f32(); let heal = AttackEffect::new( @@ -164,6 +153,11 @@ impl CharacterBehavior for Data { }, } + // At end of state logic so an interrupt isn't overwritten + if !input_is_pressed(data, self.static_data.ability_info.input) { + handle_state_interrupt(data, &mut update, false); + } + update } } diff --git a/common/src/states/leap_melee.rs b/common/src/states/leap_melee.rs index 9f152adfff..daf9575b7f 100644 --- a/common/src/states/leap_melee.rs +++ b/common/src/states/leap_melee.rs @@ -58,15 +58,6 @@ impl CharacterBehavior for Data { handle_move(data, &mut update, 0.3); handle_jump(data, &mut update); - // if !ability_key_is_pressed(data, self.static_data.ability_info.key) { - // handle_interrupt(data, &mut update, false); - // match update.character { - // CharacterState::LeapMelee(_) => {}, - // _ => { - // return update; - // }, - // } - // } match self.stage_section { // Delay before leaping into the air @@ -220,6 +211,11 @@ impl CharacterBehavior for Data { }, } + // At end of state logic so an interrupt isn't overwritten + if !input_is_pressed(data, self.static_data.ability_info.input) { + handle_state_interrupt(data, &mut update, false); + } + update } } diff --git a/common/src/states/repeater_ranged.rs b/common/src/states/repeater_ranged.rs index b912c162ab..ad7280d651 100644 --- a/common/src/states/repeater_ranged.rs +++ b/common/src/states/repeater_ranged.rs @@ -53,15 +53,6 @@ impl CharacterBehavior for Data { handle_move(data, &mut update, 1.0); handle_jump(data, &mut update); - // if !ability_key_is_pressed(data, self.static_data.ability_info.key) { - // handle_interrupt(data, &mut update, false); - // match update.character { - // CharacterState::RepeaterRanged(_) => {}, - // _ => { - // return update; - // }, - // } - // } match self.stage_section { StageSection::Movement => { @@ -220,6 +211,11 @@ impl CharacterBehavior for Data { }, } + // At end of state logic so an interrupt isn't overwritten + if !input_is_pressed(data, self.static_data.ability_info.input) { + handle_state_interrupt(data, &mut update, false); + } + update } } diff --git a/common/src/states/roll.rs b/common/src/states/roll.rs index 094d8e7da0..d96cdddee1 100644 --- a/common/src/states/roll.rs +++ b/common/src/states/roll.rs @@ -115,18 +115,16 @@ impl CharacterBehavior for Data { } else { // Done if let Some((input, stage)) = self.was_combo { - // if ability_key_is_pressed(data, key) { - // handle_interrupt(data, &mut update, true); - // // If other states are introduced that progress - // through stages, add them - // // here - // if let CharacterState::ComboMelee(c) = &mut - // update.character { - // c.stage = stage; - // } - // } else { - // update.character = CharacterState::Wielding; - // } + if input_is_pressed(data, input) { + handle_input(data, &mut update, input); + // If other states are introduced that progress through stages, add them + // here + if let CharacterState::ComboMelee(c) = &mut update.character { + c.stage = stage; + } + } else { + update.character = CharacterState::Wielding; + } } else if self.was_wielded { update.character = CharacterState::Wielding; } else if self.was_sneak { diff --git a/common/src/states/shockwave.rs b/common/src/states/shockwave.rs index 6ce64d9c04..aeae37c351 100644 --- a/common/src/states/shockwave.rs +++ b/common/src/states/shockwave.rs @@ -60,15 +60,6 @@ impl CharacterBehavior for Data { let mut update = StateUpdate::from(data); handle_move(data, &mut update, self.static_data.move_efficiency); - // if !ability_key_is_pressed(data, self.static_data.ability_info.key) { - // handle_interrupt(data, &mut update, false); - // match update.character { - // CharacterState::Shockwave(_) => {}, - // _ => { - // return update; - // }, - // } - // } match self.stage_section { StageSection::Buildup => { @@ -171,6 +162,11 @@ impl CharacterBehavior for Data { }, } + // At end of state logic so an interrupt isn't overwritten + if !input_is_pressed(data, self.static_data.ability_info.input) { + handle_state_interrupt(data, &mut update, false); + } + update } } diff --git a/common/src/states/spin_melee.rs b/common/src/states/spin_melee.rs index b45ac76360..d6e494cebe 100644 --- a/common/src/states/spin_melee.rs +++ b/common/src/states/spin_melee.rs @@ -75,16 +75,6 @@ impl CharacterBehavior for Data { }, } - // if !ability_key_is_pressed(data, self.static_data.ability_info.key) { - // handle_interrupt(data, &mut update, self.static_data.is_interruptible); - // match update.character { - // CharacterState::SpinMelee(_) => {}, - // _ => { - // return update; - // }, - // } - // } - match self.stage_section { StageSection::Buildup => { if self.timer < self.static_data.buildup_duration { @@ -179,7 +169,7 @@ impl CharacterBehavior for Data { } else if update.energy.current() as f32 >= self.static_data.energy_cost && (self.spins_remaining != 0 || (self.static_data.is_infinite - && /*ability_key_is_pressed(data, self.static_data.ability_info.key)*/ input_is_pressed(data, self.static_data.ability_info.input))) + && input_is_pressed(data, self.static_data.ability_info.input))) { let new_spins_remaining = if self.static_data.is_infinite { self.spins_remaining @@ -231,6 +221,11 @@ impl CharacterBehavior for Data { }, } + // At end of state logic so an interrupt isn't overwritten + if !input_is_pressed(data, self.static_data.ability_info.input) { + handle_state_interrupt(data, &mut update, self.static_data.is_interruptible); + } + update } } diff --git a/common/src/states/utils.rs b/common/src/states/utils.rs index 175f8e7482..6b0f013e24 100644 --- a/common/src/states/utils.rs +++ b/common/src/states/utils.rs @@ -180,9 +180,7 @@ impl Body { pub fn handle_move(data: &JoinData, update: &mut StateUpdate, efficiency: f32) { if let Some(depth) = data.physics.in_liquid { swim_move(data, update, efficiency, depth); - } else if - /* data.inputs.fly.is_pressed() */ - input_is_pressed(data, InputKind::Fly) + } else if input_is_pressed(data, InputKind::Fly) && !data.physics.on_ground && data.body.can_fly() { @@ -316,14 +314,12 @@ fn fly_move(data: &JoinData, update: &mut StateUpdate, efficiency: f32) { handle_orientation(data, update, 1.0); } -/// First checks whether `primary`, `secondary`, `ability3`, or `ability4` input -/// is pressed, then attempts to go into Equipping state, otherwise Idle +/// Checks if an input related to an attack is held. If one is, moves entity +/// into wielding state pub fn handle_wield(data: &JoinData, update: &mut StateUpdate) { - // if - // // data.inputs.primary.is_pressed() || data.inputs.secondary.is_pressed() - // || data.inputs.ability3.is_pressed() || - // data.inputs.ability4.is_pressed() { attempt_wield(data, update); - // } + if data.controller.queued_inputs.iter().any(|i| i.is_ability()) { + attempt_wield(data, update); + } } /// If a tool is equipped, goes into Equipping state, otherwise goes to Idle @@ -421,9 +417,7 @@ pub fn attempt_glide_wield(data: &JoinData, update: &mut StateUpdate) { /// Checks that player can jump and sends jump event if so pub fn handle_jump(data: &JoinData, update: &mut StateUpdate) { - if - /* data.inputs.jump.is_pressed() */ - input_is_pressed(data, InputKind::Jump) + if input_is_pressed(data, InputKind::Jump) && data.physics.on_ground && !data .physics @@ -437,7 +431,7 @@ pub fn handle_jump(data: &JoinData, update: &mut StateUpdate) { } } -fn handle_ability_pressed(data: &JoinData, update: &mut StateUpdate, input: InputKind) { +fn handle_ability(data: &JoinData, update: &mut StateUpdate, input: InputKind) { let hands = |equip_slot| match data.inventory.equipped(equip_slot).map(|i| i.kind()) { Some(ItemKind::Tool(tool)) => Some(tool.hands), _ => None, @@ -477,7 +471,7 @@ fn handle_ability_pressed(data: &JoinData, update: &mut StateUpdate, input: Inpu .get(skill_index) .cloned() .and_then(unlocked), - InputKind::Roll | InputKind::Jump | InputKind::Glide | InputKind::Fly => None, + InputKind::Roll | InputKind::Jump | InputKind::Fly => None, }) .map(|a| { let tool = unwrap_tool_data(data, equip_slot).map(|t| t.kind); @@ -494,14 +488,24 @@ fn handle_ability_pressed(data: &JoinData, update: &mut StateUpdate, input: Inpu } } +pub fn handle_ability_input(data: &JoinData, update: &mut StateUpdate) { + if let Some(input) = data + .controller + .queued_inputs + .iter() + .find(|i| i.is_ability()) + { + handle_ability(data, update, *input); + } +} + pub fn handle_input(data: &JoinData, update: &mut StateUpdate, input: InputKind) { match input { InputKind::Primary | InputKind::Secondary | InputKind::Ability(_) => { - handle_ability_pressed(data, update, input) + handle_ability(data, update, input) }, InputKind::Roll => handle_dodge_input(data, update), InputKind::Jump => handle_jump(data, update), - InputKind::Glide => attempt_glide_wield(data, update), InputKind::Fly => {}, } } @@ -593,12 +597,9 @@ pub fn get_crit_data(data: &JoinData, ai: AbilityInfo) -> (f32, f32) { DEFAULT_CRIT_DATA } -pub fn handle_interrupt(data: &JoinData, update: &mut StateUpdate, attacks_interrupt: bool) { +pub fn handle_state_interrupt(data: &JoinData, update: &mut StateUpdate, attacks_interrupt: bool) { if attacks_interrupt { - //handle_ability1_input(data, update); - // handle_ability2_input(data, update); - // handle_ability3_input(data, update); - // handle_ability4_input(data, update); + handle_ability_input(data, update); } handle_dodge_input(data, update); } diff --git a/common/src/states/wielding.rs b/common/src/states/wielding.rs index d5fb29ab23..d0457f7a27 100644 --- a/common/src/states/wielding.rs +++ b/common/src/states/wielding.rs @@ -14,14 +14,7 @@ impl CharacterBehavior for Data { let mut update = StateUpdate::from(data); handle_move(&data, &mut update, 1.0); - handle_jump(&data, &mut update); handle_climb(&data, &mut update); - //handle_ability1_input(&data, &mut update); - // handle_ability2_input(&data, &mut update); - // handle_ability3_input(&data, &mut update); - // handle_ability4_input(&data, &mut update); - handle_dodge_input(&data, &mut update); - attempt_input(&data, &mut update); update diff --git a/common/sys/src/character_behavior.rs b/common/sys/src/character_behavior.rs index 61e0445c51..ac7d8a15be 100644 --- a/common/sys/src/character_behavior.rs +++ b/common/sys/src/character_behavior.rs @@ -356,11 +356,6 @@ impl<'a> System<'a> for Sys { local_emitter.append(&mut state_update.local_events); server_emitter.append(&mut state_update.server_events); - // join_struct - // .controller - // .queued_inputs - // .append(&mut state_update.queued_inputs); - // join_struct.controller.queued_inputs. incorporate_update(&mut join_struct, state_update); } } diff --git a/server/src/sys/agent.rs b/server/src/sys/agent.rs index 3473a4252f..64b4535dd4 100644 --- a/server/src/sys/agent.rs +++ b/server/src/sys/agent.rs @@ -589,16 +589,6 @@ impl<'a> AgentData<'a> { .actions .push(ControlAction::CancelInput(InputKind::Fly)) } - // controller.inputs.fly.set_state( - // self.traversal_config.can_fly - // && !read_data - // .terrain - // .ray(self.pos.0, self.pos.0 + (Vec3::unit_z() * 3.0)) - // .until(Block::is_solid) - // .cast() - // .1 - // .map_or(true, |b| b.is_some()), - // ); if let Some((bearing, speed)) = agent.chaser.chase( &*read_data.terrain, self.pos.0, @@ -624,10 +614,6 @@ impl<'a> AgentData<'a> { .actions .push(ControlAction::CancelInput(InputKind::Jump)) } - // controller.inputs.jump.set_state( - // bearing.z > 1.5 - // || self.traversal_config.can_fly && self.traversal_config.on_ground, - // ); controller.inputs.climb = Some(comp::Climb::Up); //.filter(|_| bearing.z > 0.1 || self.physics_state.in_liquid.is_some()); @@ -965,7 +951,6 @@ impl<'a> AgentData<'a> { .actions .push(ControlAction::CancelInput(InputKind::Jump)) } - // controller.inputs.jump.set_state(bearing.z > 1.5); controller.inputs.move_z = bearing.z; } agent.action_timer += dt.0; @@ -1125,7 +1110,6 @@ impl<'a> AgentData<'a> { input: InputKind::Primary, target: None, }); - //controller.inputs.primary.set_state(true); controller.inputs.move_dir = Vec2::zero(); } else if dist_sqrd < MAX_CHASE_DIST.powi(2) { if let Some((bearing, speed)) = agent.chaser.chase( @@ -1150,7 +1134,6 @@ impl<'a> AgentData<'a> { .actions .push(ControlAction::CancelInput(InputKind::Jump)) } - // controller.inputs.jump.set_state(bearing.z > 1.5); controller.inputs.move_z = bearing.z; } @@ -1162,7 +1145,6 @@ impl<'a> AgentData<'a> { input: InputKind::Roll, target: None, }); - // controller.inputs.roll.set_state(true); } } else { agent.target = None; @@ -1175,14 +1157,12 @@ impl<'a> AgentData<'a> { controller .actions .push(ControlAction::CancelInput(InputKind::Secondary)); - // controller.inputs.secondary.set_state(false); agent.action_timer = 0.0; } else if agent.action_timer > 4.0 && self.energy.current() > 10 { controller.actions.push(ControlAction::StartInput { input: InputKind::Secondary, target: None, }); - // controller.inputs.secondary.set_state(true); agent.action_timer += dt.0; } else if self .stats @@ -1195,14 +1175,12 @@ impl<'a> AgentData<'a> { input: InputKind::Ability(0), target: None, }); - // controller.inputs.ability3.set_state(true); agent.action_timer += dt.0; } else { controller.actions.push(ControlAction::StartInput { input: InputKind::Primary, target: None, }); - //controller.inputs.primary.set_state(true); agent.action_timer += dt.0; } } else if dist_sqrd < MAX_CHASE_DIST.powi(2) { @@ -1228,7 +1206,6 @@ impl<'a> AgentData<'a> { .actions .push(ControlAction::CancelInput(InputKind::Jump)) } - // controller.inputs.jump.set_state(bearing.z > 1.5); controller.inputs.move_z = bearing.z; } if self.body.map(|b| b.is_humanoid()).unwrap_or(false) @@ -1239,7 +1216,6 @@ impl<'a> AgentData<'a> { input: InputKind::Roll, target: None, }); - // controller.inputs.roll.set_state(true); } } else { agent.target = None; @@ -1252,14 +1228,12 @@ impl<'a> AgentData<'a> { controller .actions .push(ControlAction::CancelInput(InputKind::Secondary)); - // controller.inputs.secondary.set_state(false); agent.action_timer = 0.0; } else if agent.action_timer > 2.0 { controller.actions.push(ControlAction::StartInput { input: InputKind::Secondary, target: None, }); - // controller.inputs.secondary.set_state(true); agent.action_timer += dt.0; } else if self .stats @@ -1272,14 +1246,12 @@ impl<'a> AgentData<'a> { input: InputKind::Ability(0), target: None, }); - // controller.inputs.ability3.set_state(true); agent.action_timer += dt.0; } else { controller.actions.push(ControlAction::StartInput { input: InputKind::Primary, target: None, }); - //controller.inputs.primary.set_state(true); agent.action_timer += dt.0; } } else if dist_sqrd < MAX_CHASE_DIST.powi(2) { @@ -1306,7 +1278,6 @@ impl<'a> AgentData<'a> { input: InputKind::Ability(0), target: None, }); - // controller.inputs.ability3.set_state(true); agent.action_timer = 0.0; } else { agent.action_timer += dt.0; @@ -1324,7 +1295,6 @@ impl<'a> AgentData<'a> { .actions .push(ControlAction::CancelInput(InputKind::Jump)) } - // controller.inputs.jump.set_state(bearing.z > 1.5); controller.inputs.move_z = bearing.z; } } @@ -1336,7 +1306,6 @@ impl<'a> AgentData<'a> { input: InputKind::Roll, target: None, }); - // controller.inputs.roll.set_state(true); } } else { agent.target = None; @@ -1356,7 +1325,6 @@ impl<'a> AgentData<'a> { input: InputKind::Ability(0), target: None, }); - // controller.inputs.ability3.set_state(true); agent.action_timer += dt.0; } else if agent.action_timer > 2.0 { agent.action_timer = 0.0; @@ -1365,7 +1333,6 @@ impl<'a> AgentData<'a> { input: InputKind::Primary, target: None, }); - //controller.inputs.primary.set_state(true); agent.action_timer += dt.0; } } else if dist_sqrd < MAX_CHASE_DIST.powi(2) { @@ -1387,7 +1354,6 @@ impl<'a> AgentData<'a> { input: InputKind::Secondary, target: None, }); - // controller.inputs.secondary.set_state(true); agent.action_timer = 0.0; } else { agent.action_timer += dt.0; @@ -1405,7 +1371,6 @@ impl<'a> AgentData<'a> { .actions .push(ControlAction::CancelInput(InputKind::Jump)) } - // controller.inputs.jump.set_state(bearing.z > 1.5); controller.inputs.move_z = bearing.z; } } @@ -1417,7 +1382,6 @@ impl<'a> AgentData<'a> { input: InputKind::Roll, target: None, }); - // controller.inputs.roll.set_state(true); } } else { agent.target = None; @@ -1431,7 +1395,6 @@ impl<'a> AgentData<'a> { input: InputKind::Roll, target: None, }); - // controller.inputs.roll.set_state(true); } else if dist_sqrd < MAX_CHASE_DIST.powi(2) { if let Some((bearing, speed)) = agent.chaser.chase( &*terrain, @@ -1454,14 +1417,12 @@ impl<'a> AgentData<'a> { controller .actions .push(ControlAction::CancelInput(InputKind::Secondary)); - // controller.inputs.secondary.set_state(false); agent.action_timer = 0.0; } else if agent.action_timer > 2.0 && self.energy.current() > 300 { controller.actions.push(ControlAction::StartInput { input: InputKind::Secondary, target: None, }); - // controller.inputs.secondary.set_state(true); agent.action_timer += dt.0; } else if self .stats @@ -1473,23 +1434,19 @@ impl<'a> AgentData<'a> { controller .actions .push(ControlAction::CancelInput(InputKind::Secondary)); - // controller.inputs.secondary.set_state(false); controller.actions.push(ControlAction::StartInput { input: InputKind::Ability(0), target: None, }); - // controller.inputs.ability3.set_state(true); agent.action_timer += dt.0; } else { controller .actions .push(ControlAction::CancelInput(InputKind::Secondary)); - // controller.inputs.secondary.set_state(false); controller.actions.push(ControlAction::StartInput { input: InputKind::Primary, target: None, }); - //controller.inputs.primary.set_state(true); agent.action_timer += dt.0; } } else { @@ -1505,7 +1462,6 @@ impl<'a> AgentData<'a> { .actions .push(ControlAction::CancelInput(InputKind::Jump)) } - // controller.inputs.jump.set_state(bearing.z > 1.5); controller.inputs.move_z = bearing.z; } } @@ -1517,7 +1473,6 @@ impl<'a> AgentData<'a> { input: InputKind::Roll, target: None, }); - // controller.inputs.roll.set_state(true); } } else if can_see_tgt(&*terrain, self.pos, tgt_pos, dist_sqrd) { if let Some((bearing, speed)) = agent.chaser.chase( @@ -1542,7 +1497,6 @@ impl<'a> AgentData<'a> { .actions .push(ControlAction::CancelInput(InputKind::Jump)) } - // controller.inputs.jump.set_state(bearing.z > 1.5); controller.inputs.move_z = bearing.z; } } else { @@ -1557,7 +1511,6 @@ impl<'a> AgentData<'a> { input: InputKind::Roll, target: None, }); - // controller.inputs.roll.set_state(true); } else if dist_sqrd < (5.0 * min_attack_dist * self.scale).powi(2) { if agent.action_timer < 1.5 { controller.inputs.move_dir = (tgt_pos.0 - self.pos.0) @@ -1587,19 +1540,16 @@ impl<'a> AgentData<'a> { input: InputKind::Ability(0), target: None, }); - // controller.inputs.ability3.set_state(true); } else if self.energy.current() > 10 { controller.actions.push(ControlAction::StartInput { input: InputKind::Secondary, target: None, }); - // controller.inputs.secondary.set_state(true); } else { controller.actions.push(ControlAction::StartInput { input: InputKind::Primary, target: None, }); - //controller.inputs.primary.set_state(true); } } else if dist_sqrd < MAX_CHASE_DIST.powi(2) { if let Some((bearing, speed)) = agent.chaser.chase( @@ -1623,7 +1573,6 @@ impl<'a> AgentData<'a> { input: InputKind::Primary, target: None, }); - //controller.inputs.primary.set_state(true); } else { controller.inputs.move_dir = bearing.xy().try_normalized().unwrap_or_else(Vec2::zero) * speed; @@ -1637,7 +1586,6 @@ impl<'a> AgentData<'a> { .actions .push(ControlAction::CancelInput(InputKind::Jump)) } - // controller.inputs.jump.set_state(bearing.z > 1.5); controller.inputs.move_z = bearing.z; } } @@ -1649,7 +1597,6 @@ impl<'a> AgentData<'a> { input: InputKind::Roll, target: None, }); - // controller.inputs.roll.set_state(true); } } else if can_see_tgt(&*terrain, self.pos, tgt_pos, dist_sqrd) { if let Some((bearing, speed)) = agent.chaser.chase( @@ -1674,7 +1621,6 @@ impl<'a> AgentData<'a> { .actions .push(ControlAction::CancelInput(InputKind::Jump)) } - // controller.inputs.jump.set_state(bearing.z > 1.5); controller.inputs.move_z = bearing.z; } } else { @@ -1697,7 +1643,6 @@ impl<'a> AgentData<'a> { input: InputKind::Ability(0), target: None, }); - // controller.inputs.ability3.set_state(true); } if let Some((bearing, speed)) = agent.chaser.chase( &*terrain, @@ -1717,7 +1662,6 @@ impl<'a> AgentData<'a> { input: InputKind::Secondary, target: None, }); - // controller.inputs.secondary.set_state(true); agent.action_timer = 0.0; } else { agent.action_timer += dt.0; @@ -1735,7 +1679,6 @@ impl<'a> AgentData<'a> { .actions .push(ControlAction::CancelInput(InputKind::Jump)) } - // controller.inputs.jump.set_state(bearing.z > 1.5); controller.inputs.move_z = bearing.z; } } @@ -1754,7 +1697,6 @@ impl<'a> AgentData<'a> { input: InputKind::Primary, target: None, }); - //controller.inputs.primary.set_state(true); } else if dist_sqrd < (radius as f32 * min_attack_dist * self.scale).powi(2) { controller.inputs.move_dir = (self.pos.0 - tgt_pos.0) .xy() @@ -1775,7 +1717,6 @@ impl<'a> AgentData<'a> { input: InputKind::Secondary, target: None, }); - // controller.inputs.secondary.set_state(true); agent.action_timer += dt.0; } else if agent.action_timer < 2.0 * circle_time as f32 + 0.5 { controller.inputs.move_dir = (tgt_pos.0 - self.pos.0) @@ -1789,7 +1730,6 @@ impl<'a> AgentData<'a> { input: InputKind::Secondary, target: None, }); - // controller.inputs.secondary.set_state(true); agent.action_timer += dt.0; } else { agent.action_timer = 0.0; @@ -1817,7 +1757,6 @@ impl<'a> AgentData<'a> { .actions .push(ControlAction::CancelInput(InputKind::Jump)) } - // controller.inputs.jump.set_state(bearing.z > 1.5); controller.inputs.move_z = bearing.z; } } else { @@ -1834,7 +1773,6 @@ impl<'a> AgentData<'a> { input: InputKind::Primary, target: None, }); - //controller.inputs.primary.set_state(true); } else if dist_sqrd < MAX_CHASE_DIST.powi(2) { if let Some((bearing, speed)) = agent.chaser.chase( &*terrain, @@ -1870,7 +1808,6 @@ impl<'a> AgentData<'a> { input: InputKind::Secondary, target: None, }); - // controller.inputs.secondary.set_state(true); if bearing.z > 1.5 { controller.actions.push(ControlAction::StartInput { input: InputKind::Jump, @@ -1881,7 +1818,6 @@ impl<'a> AgentData<'a> { .actions .push(ControlAction::CancelInput(InputKind::Jump)) } - // controller.inputs.jump.set_state(bearing.z > 1.5); controller.inputs.move_z = bearing.z; } else { controller.inputs.move_dir = @@ -1896,7 +1832,6 @@ impl<'a> AgentData<'a> { .actions .push(ControlAction::CancelInput(InputKind::Jump)) } - // controller.inputs.jump.set_state(bearing.z > 1.5); controller.inputs.move_z = bearing.z; } } else { @@ -1912,21 +1847,18 @@ impl<'a> AgentData<'a> { controller .actions .push(ControlAction::CancelInput(InputKind::Primary)); - //controller.inputs.primary.set_state(false); agent.action_timer = 0.0; } else if agent.action_timer > 1.0 { controller.actions.push(ControlAction::StartInput { input: InputKind::Primary, target: None, }); - //controller.inputs.primary.set_state(true); agent.action_timer += dt.0; } else { controller.actions.push(ControlAction::StartInput { input: InputKind::Secondary, target: None, }); - // controller.inputs.secondary.set_state(true); agent.action_timer += dt.0; } controller.inputs.move_dir = (tgt_pos.0 - self.pos.0) @@ -1957,7 +1889,6 @@ impl<'a> AgentData<'a> { .actions .push(ControlAction::CancelInput(InputKind::Jump)) } - // controller.inputs.jump.set_state(bearing.z > 1.5); controller.inputs.move_z = bearing.z; } } else { @@ -1971,7 +1902,6 @@ impl<'a> AgentData<'a> { input: InputKind::Secondary, target: None, }); - // controller.inputs.secondary.set_state(true); } else if dist_sqrd < (3.0 * min_attack_dist * self.scale).powi(2) && dist_sqrd > (2.0 * min_attack_dist * self.scale).powi(2) { @@ -1979,7 +1909,6 @@ impl<'a> AgentData<'a> { input: InputKind::Primary, target: None, }); - //controller.inputs.primary.set_state(true); controller.inputs.move_dir = (tgt_pos.0 - self.pos.0) .xy() .rotated_z(-0.47 * PI) @@ -2008,7 +1937,6 @@ impl<'a> AgentData<'a> { .actions .push(ControlAction::CancelInput(InputKind::Jump)) } - // controller.inputs.jump.set_state(bearing.z > 1.5); controller.inputs.move_z = bearing.z; } } else { @@ -2025,14 +1953,12 @@ impl<'a> AgentData<'a> { input: InputKind::Secondary, target: None, }); - // controller.inputs.secondary.set_state(true); agent.action_timer += dt.0; } else { controller.actions.push(ControlAction::StartInput { input: InputKind::Primary, target: None, }); - //controller.inputs.primary.set_state(true); agent.action_timer += dt.0; } } else if dist_sqrd < MAX_CHASE_DIST.powi(2) { @@ -2058,7 +1984,6 @@ impl<'a> AgentData<'a> { .actions .push(ControlAction::CancelInput(InputKind::Jump)) } - // controller.inputs.jump.set_state(bearing.z > 1.5); controller.inputs.move_z = bearing.z; } } else { @@ -2072,13 +1997,11 @@ impl<'a> AgentData<'a> { input: InputKind::Secondary, target: None, }); - // controller.inputs.secondary.set_state(true); } else if dist_sqrd < (5.0 * min_attack_dist * self.scale).powi(2) { controller.actions.push(ControlAction::StartInput { input: InputKind::Ability(0), target: None, }); - // controller.inputs.ability3.set_state(true); } else if dist_sqrd < MAX_CHASE_DIST.powi(2) { if let Some((bearing, speed)) = agent.chaser.chase( &*terrain, @@ -2095,7 +2018,6 @@ impl<'a> AgentData<'a> { input: InputKind::Primary, target: None, }); - //controller.inputs.primary.set_state(true); controller.inputs.move_dir = bearing.xy().try_normalized().unwrap_or_else(Vec2::zero) * speed; } else { @@ -2111,7 +2033,6 @@ impl<'a> AgentData<'a> { .actions .push(ControlAction::CancelInput(InputKind::Jump)) } - // controller.inputs.jump.set_state(bearing.z > 1.5); controller.inputs.move_z = bearing.z; } } @@ -2127,14 +2048,12 @@ impl<'a> AgentData<'a> { input: InputKind::Secondary, target: None, }); - // controller.inputs.secondary.set_state(true); agent.action_timer += dt.0; } else if agent.action_timer < 3.0 { controller.actions.push(ControlAction::StartInput { input: InputKind::Primary, target: None, }); - //controller.inputs.primary.set_state(true); agent.action_timer += dt.0; } else { agent.action_timer = 0.0; @@ -2162,7 +2081,6 @@ impl<'a> AgentData<'a> { .actions .push(ControlAction::CancelInput(InputKind::Jump)) } - // controller.inputs.jump.set_state(bearing.z > 1.5); controller.inputs.move_z = bearing.z; } } else { @@ -2176,7 +2094,6 @@ impl<'a> AgentData<'a> { input: InputKind::Secondary, target: None, }); - // controller.inputs.secondary.set_state(true); } else if dist_sqrd < (7.0 * min_attack_dist * self.scale).powi(2) { if agent.action_timer < 2.0 { controller.inputs.move_dir = (tgt_pos.0 - self.pos.0) @@ -2188,7 +2105,6 @@ impl<'a> AgentData<'a> { input: InputKind::Primary, target: None, }); - //controller.inputs.primary.set_state(true); agent.action_timer += dt.0; } else if agent.action_timer < 4.0 { controller.inputs.move_dir = (tgt_pos.0 - self.pos.0) @@ -2200,14 +2116,12 @@ impl<'a> AgentData<'a> { input: InputKind::Primary, target: None, }); - //controller.inputs.primary.set_state(true); agent.action_timer += dt.0; } else if agent.action_timer < 6.0 { controller.actions.push(ControlAction::StartInput { input: InputKind::Ability(0), target: None, }); - // controller.inputs.ability3.set_state(true); agent.action_timer += dt.0; } else { agent.action_timer = 0.0; @@ -2235,7 +2149,6 @@ impl<'a> AgentData<'a> { .actions .push(ControlAction::CancelInput(InputKind::Jump)) } - // controller.inputs.jump.set_state(bearing.z > 1.5); controller.inputs.move_z = bearing.z; } } else { @@ -2249,7 +2162,6 @@ impl<'a> AgentData<'a> { input: InputKind::Primary, target: None, }); - //controller.inputs.primary.set_state(true); } else if dist_sqrd < MAX_CHASE_DIST.powi(2) { if let Some((bearing, speed)) = agent.chaser.chase( &*terrain, @@ -2273,7 +2185,6 @@ impl<'a> AgentData<'a> { .actions .push(ControlAction::CancelInput(InputKind::Jump)) } - // controller.inputs.jump.set_state(bearing.z > 1.5); controller.inputs.move_z = bearing.z; } } else { @@ -2286,7 +2197,6 @@ impl<'a> AgentData<'a> { input: InputKind::Primary, target: None, }); - //controller.inputs.primary.set_state(true); } else { agent.target = None; } @@ -2298,7 +2208,6 @@ impl<'a> AgentData<'a> { input: InputKind::Primary, target: None, }); - //controller.inputs.primary.set_state(true); } else { agent.target = None; } @@ -2316,7 +2225,6 @@ impl<'a> AgentData<'a> { input: InputKind::Primary, target: None, }); - //controller.inputs.primary.set_state(true); } else { agent.target = None; } @@ -2354,7 +2262,6 @@ impl<'a> AgentData<'a> { .actions .push(ControlAction::CancelInput(InputKind::Jump)) } - // controller.inputs.jump.set_state(bearing.z > 1.5); controller.inputs.move_z = bearing.z; } } diff --git a/voxygen/src/audio/sfx/event_mapper/combat/tests.rs b/voxygen/src/audio/sfx/event_mapper/combat/tests.rs index c80195f90d..acc53817ca 100644 --- a/voxygen/src/audio/sfx/event_mapper/combat/tests.rs +++ b/voxygen/src/audio/sfx/event_mapper/combat/tests.rs @@ -3,7 +3,7 @@ use crate::audio::sfx::SfxEvent; use common::{ comp::{ inventory::loadout_builder::LoadoutBuilder, item::tool::ToolKind, CharacterAbilityType, - CharacterState, Item, + CharacterState, InputKind, Item, }, states, }; @@ -137,7 +137,6 @@ fn matches_ability_stage() { stage: 1, timer: Duration::default(), stage_section: states::utils::StageSection::Swing, - next_stage: false, }), &PreviousEntityState { event: SfxEvent::Idle, @@ -195,7 +194,6 @@ fn ignores_different_ability_stage() { stage: 1, timer: Duration::default(), stage_section: states::utils::StageSection::Swing, - next_stage: false, }), &PreviousEntityState { event: SfxEvent::Idle, @@ -218,6 +216,6 @@ fn empty_ability_info() -> states::utils::AbilityInfo { states::utils::AbilityInfo { tool: None, hand: None, - key: states::utils::AbilityKey::Mouse1, + input: InputKind::Primary, } } diff --git a/voxygen/src/session.rs b/voxygen/src/session.rs index 8c26fa2fa1..822b3d6156 100644 --- a/voxygen/src/session.rs +++ b/voxygen/src/session.rs @@ -367,12 +367,9 @@ impl PlayState for SessionState { } } else { client.handle_input(InputKind::Primary, state); - //self.inputs.primary.set_state(state); } }, GameInput::Secondary => { - // self.inputs.secondary.set_state(false); // To be changed later on - let mut client = self.client.borrow_mut(); if state && can_build { @@ -381,7 +378,6 @@ impl PlayState for SessionState { } } else { client.handle_input(InputKind::Secondary, state); - // self.inputs.secondary.set_state(state); } }, GameInput::Roll => { @@ -396,7 +392,6 @@ impl PlayState for SessionState { } } else { client.handle_input(InputKind::Roll, state); - // self.inputs.roll.set_state(state); } }, GameInput::Respawn => { @@ -469,8 +464,6 @@ impl PlayState for SessionState { self.key_state.fly ^= state; let mut client = self.client.borrow_mut(); client.handle_input(InputKind::Fly, self.key_state.fly); - // self.inputs.fly.set_state(self.key_state. - // fly); }, GameInput::Climb => { self.key_state.climb_up = state; @@ -1229,12 +1222,10 @@ impl PlayState for SessionState { HudEvent::Ability3(state) => { let mut client = self.client.borrow_mut(); client.handle_input(InputKind::Ability(0), state); - // self.inputs.ability3.set_state(state); }, HudEvent::Ability4(state) => { let mut client = self.client.borrow_mut(); client.handle_input(InputKind::Ability(1), state); - // self.inputs.ability4.set_state(state); }, HudEvent::ChangeFOV(new_fov) => { global_state.settings.graphics.fov = new_fov; diff --git a/voxygen/src/settings.rs b/voxygen/src/settings.rs index 4db88fafe5..72b8f5fce7 100644 --- a/voxygen/src/settings.rs +++ b/voxygen/src/settings.rs @@ -276,7 +276,6 @@ pub mod con_settings { pub interact: Button, pub toggle_wield: Button, pub swap_loadout: Button, - //pub charge: Button, } #[derive(Clone, Debug, Serialize, Deserialize)]