mirror of
https://gitlab.com/veloren/veloren.git
synced 2024-08-30 18:12:32 +00:00
Completely purged old method of inputs
This commit is contained in:
parent
be27289a7f
commit
ac6e192db4
@ -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<Climb>,
|
||||
pub move_dir: Vec2<f32>,
|
||||
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 {
|
||||
|
@ -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,
|
||||
|
@ -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 => {
|
||||
|
@ -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)
|
||||
{
|
||||
|
@ -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);
|
||||
}
|
||||
|
@ -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);
|
||||
}
|
||||
|
@ -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);
|
||||
}
|
||||
|
@ -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
|
||||
|
@ -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
|
||||
|
@ -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
|
||||
|
@ -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;
|
||||
|
@ -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
|
||||
{
|
||||
|
@ -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(
|
||||
|
@ -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
|
||||
|
@ -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 => {
|
||||
|
@ -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 {
|
||||
|
@ -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 => {
|
||||
|
@ -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
|
||||
|
@ -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<InputKind>,
|
||||
) {
|
||||
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<ToolKind>,
|
||||
pub hand: Option<HandInfo>,
|
||||
pub key: AbilityKey,
|
||||
pub input: Option<InputKind>,
|
||||
pub input: InputKind,
|
||||
}
|
||||
|
||||
impl AbilityInfo {
|
||||
pub fn from_key(
|
||||
data: &JoinData,
|
||||
key: AbilityKey,
|
||||
from_offhand: bool,
|
||||
input: Option<InputKind>,
|
||||
) -> 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 }
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -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);
|
||||
|
@ -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
|
||||
|
@ -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::<f32>() < 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::<f32>() < 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::<f32>() < 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::<f32>() < 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::<f32>() < 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::<f32>() > 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::<f32>() < 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;
|
||||
}
|
||||
}
|
||||
|
@ -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: {
|
||||
|
@ -126,7 +126,6 @@ impl SessionState {
|
||||
outcomes: &mut Vec<Outcome>,
|
||||
) -> Result<TickAction, Error> {
|
||||
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();
|
||||
|
@ -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),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -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",
|
||||
|
Loading…
Reference in New Issue
Block a user