Secondary input now fully functional

This commit is contained in:
Sam
2021-03-12 19:38:20 -05:00
parent 21e6f4797c
commit b5d501199d
13 changed files with 234 additions and 67 deletions

View File

@ -1202,6 +1202,7 @@ impl From<(&CharacterAbility, AbilityInfo)> for CharacterState {
refresh_distance: 0.0, refresh_distance: 0.0,
stage_section: StageSection::Buildup, stage_section: StageSection::Buildup,
exhausted: false, exhausted: false,
end: false,
}), }),
CharacterAbility::BasicBlock => CharacterState::BasicBlock, CharacterAbility::BasicBlock => CharacterState::BasicBlock,
CharacterAbility::Roll { CharacterAbility::Roll {
@ -1319,6 +1320,7 @@ impl From<(&CharacterAbility, AbilityInfo)> for CharacterState {
spins_remaining: *num_spins - 1, spins_remaining: *num_spins - 1,
stage_section: StageSection::Buildup, stage_section: StageSection::Buildup,
exhausted: false, exhausted: false,
end: false,
}), }),
CharacterAbility::ChargedMelee { CharacterAbility::ChargedMelee {
energy_cost, energy_cost,
@ -1359,6 +1361,7 @@ impl From<(&CharacterAbility, AbilityInfo)> for CharacterState {
timer: Duration::default(), timer: Duration::default(),
exhausted: false, exhausted: false,
charge_amount: 0.0, charge_amount: 0.0,
end: false,
}), }),
CharacterAbility::ChargedRanged { CharacterAbility::ChargedRanged {
energy_cost: _, energy_cost: _,
@ -1399,6 +1402,7 @@ impl From<(&CharacterAbility, AbilityInfo)> for CharacterState {
timer: Duration::default(), timer: Duration::default(),
stage_section: StageSection::Buildup, stage_section: StageSection::Buildup,
exhausted: false, exhausted: false,
end: false,
}), }),
CharacterAbility::RepeaterRanged { CharacterAbility::RepeaterRanged {
energy_cost: _, energy_cost: _,
@ -1545,6 +1549,7 @@ impl From<(&CharacterAbility, AbilityInfo)> for CharacterState {
}, },
timer: Duration::default(), timer: Duration::default(),
stage_section: StageSection::Buildup, stage_section: StageSection::Buildup,
end: false,
}), }),
} }
} }

View File

@ -122,8 +122,8 @@ pub enum ControlAction {
#[repr(u32)] #[repr(u32)]
pub enum InputKind { pub enum InputKind {
Primary = 0, Primary = 0,
/* Secondary = 1, Secondary = 1,
* Ability(usize) = 2, /* Ability(usize) = 2,
* Jump = 3, * Jump = 3,
* Roll = 4, * Roll = 4,
* Glide = 5, * Glide = 5,
@ -244,7 +244,7 @@ pub enum Climb {
#[derive(Clone, Debug, Default, PartialEq, Serialize, Deserialize)] #[derive(Clone, Debug, Default, PartialEq, Serialize, Deserialize)]
pub struct ControllerInputs { pub struct ControllerInputs {
//pub primary: Input, //pub primary: Input,
pub secondary: Input, //pub secondary: Input,
pub ability3: Input, pub ability3: Input,
pub ability4: Input, pub ability4: Input,
pub jump: Input, pub jump: Input,
@ -273,7 +273,7 @@ impl ControllerInputs {
/// Updates all inputs, accounting for delta time /// Updates all inputs, accounting for delta time
pub fn tick(&mut self, dt: Duration) { pub fn tick(&mut self, dt: Duration) {
//self.primary.tick(dt); //self.primary.tick(dt);
self.secondary.tick(dt); // self.secondary.tick(dt);
self.ability3.tick(dt); self.ability3.tick(dt);
self.ability4.tick(dt); self.ability4.tick(dt);
self.jump.tick(dt); self.jump.tick(dt);
@ -286,7 +286,7 @@ impl ControllerInputs {
pub fn tick_freshness(&mut self) { pub fn tick_freshness(&mut self) {
//self.primary.tick_freshness(); //self.primary.tick_freshness();
self.secondary.tick_freshness(); // self.secondary.tick_freshness();
self.ability3.tick_freshness(); self.ability3.tick_freshness();
self.ability4.tick_freshness(); self.ability4.tick_freshness();
self.jump.tick_freshness(); self.jump.tick_freshness();
@ -300,7 +300,7 @@ impl ControllerInputs {
/// Updates Controller inputs with new version received from the client /// Updates Controller inputs with new version received from the client
pub fn update_with_new(&mut self, new: Self) { 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.secondary.update_with_new(new.secondary);
self.ability3.update_with_new(new.ability3); self.ability3.update_with_new(new.ability3);
self.ability4.update_with_new(new.ability4); self.ability4.update_with_new(new.ability4);
self.jump.update_with_new(new.jump); self.jump.update_with_new(new.jump);
@ -316,8 +316,8 @@ impl ControllerInputs {
} }
pub fn holding_ability_key(&self) -> bool { pub fn holding_ability_key(&self) -> bool {
//self.primary.is_pressed() || //self.primary.is_pressed() || self.secondary.is_pressed() ||
self.secondary.is_pressed() || self.ability3.is_pressed() || self.ability4.is_pressed() self.ability3.is_pressed() || self.ability4.is_pressed()
} }
} }

View File

@ -215,7 +215,9 @@ impl CharacterBehavior for Data {
update.removed_inputs.push(input); update.removed_inputs.push(input);
if Some(input) == self.static_data.ability_info.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 update

View File

@ -17,9 +17,6 @@ impl CharacterBehavior for Data {
handle_move(&data, &mut update, 0.4); handle_move(&data, &mut update, 0.4);
if !data.physics.on_ground || !data.inputs.secondary.is_pressed() {
attempt_wield(data, &mut update);
}
update update
} }
} }

View File

@ -1,6 +1,6 @@
use crate::{ use crate::{
combat::{Attack, AttackDamage, AttackEffect, CombatBuff, CombatEffect, CombatRequirement}, combat::{Attack, AttackDamage, AttackEffect, CombatBuff, CombatEffect, CombatRequirement},
comp::{CharacterState, EnergyChange, EnergySource, Melee, StateUpdate}, comp::{CharacterState, EnergyChange, EnergySource, InputKind, Melee, StateUpdate},
states::{ states::{
behavior::{CharacterBehavior, JoinData}, behavior::{CharacterBehavior, JoinData},
utils::{StageSection, *}, utils::{StageSection, *},
@ -60,6 +60,8 @@ pub struct Data {
pub exhausted: bool, pub exhausted: bool,
/// How much the attack charged by /// How much the attack charged by
pub charge_amount: f32, pub charge_amount: f32,
/// Whether or not the state should end
pub end: bool,
} }
impl CharacterBehavior for Data { impl CharacterBehavior for Data {
@ -80,7 +82,9 @@ impl CharacterBehavior for Data {
match self.stage_section { match self.stage_section {
StageSection::Charge => { 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 && update.energy.current() as f32 >= self.static_data.energy_cost
&& self.timer < self.static_data.charge_duration && self.timer < self.static_data.charge_duration
{ {
@ -107,7 +111,9 @@ impl CharacterBehavior for Data {
* self.static_data.speed) as i32, * self.static_data.speed) as i32,
source: EnergySource::Ability, 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 && update.energy.current() as f32 >= self.static_data.energy_cost
{ {
// Maintains charge // Maintains charge
@ -242,4 +248,17 @@ impl CharacterBehavior for Data {
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::ChargedMelee(c) = &mut update.character {
c.end = true;
}
}
update
}
} }

View File

@ -4,8 +4,8 @@ use crate::{
DamageSource, GroupTarget, Knockback, KnockbackDir, DamageSource, GroupTarget, Knockback, KnockbackDir,
}, },
comp::{ comp::{
projectile, Body, CharacterState, EnergyChange, EnergySource, Gravity, LightEmitter, projectile, Body, CharacterState, EnergyChange, EnergySource, Gravity, InputKind,
Projectile, StateUpdate, LightEmitter, Projectile, StateUpdate,
}, },
event::ServerEvent, event::ServerEvent,
states::{ states::{
@ -60,6 +60,8 @@ pub struct Data {
pub stage_section: StageSection, pub stage_section: StageSection,
/// Whether the attack fired already /// Whether the attack fired already
pub exhausted: bool, pub exhausted: bool,
/// Whether or not the state should end
pub end: bool,
} }
impl CharacterBehavior for Data { impl CharacterBehavior for Data {
@ -99,9 +101,9 @@ impl CharacterBehavior for Data {
} }
}, },
StageSection::Charge => { StageSection::Charge => {
if !ability_key_is_pressed(data, self.static_data.ability_info.key) if
&& !self.exhausted /* \!ability_key_is_pressed(data, self.static_data.ability_info.key) */
{ self.end && !self.exhausted {
let charge_frac = (self.timer.as_secs_f32() let charge_frac = (self.timer.as_secs_f32()
/ self.static_data.charge_duration.as_secs_f32()) / self.static_data.charge_duration.as_secs_f32())
.min(1.0); .min(1.0);
@ -162,7 +164,7 @@ impl CharacterBehavior for Data {
..*self ..*self
}); });
} else if self.timer < self.static_data.charge_duration } 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 // Charges
update.character = CharacterState::ChargedRanged(Data { update.character = CharacterState::ChargedRanged(Data {
@ -182,7 +184,9 @@ impl CharacterBehavior for Data {
* self.static_data.speed) as i32, * self.static_data.speed) as i32,
source: EnergySource::Ability, 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 // Holds charge
update.character = CharacterState::ChargedRanged(Data { update.character = CharacterState::ChargedRanged(Data {
timer: self timer: self
@ -227,4 +231,17 @@ impl CharacterBehavior for Data {
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::ChargedRanged(c) = &mut update.character {
c.end = true;
}
}
update
}
} }

View File

@ -1,6 +1,6 @@
use crate::{ use crate::{
combat::{Attack, AttackDamage, AttackEffect, CombatBuff, CombatEffect, CombatRequirement}, combat::{Attack, AttackDamage, AttackEffect, CombatBuff, CombatEffect, CombatRequirement},
comp::{CharacterState, EnergyChange, EnergySource, Melee, StateUpdate}, comp::{CharacterState, EnergyChange, EnergySource, InputKind, Melee, StateUpdate},
states::{ states::{
behavior::{CharacterBehavior, JoinData}, behavior::{CharacterBehavior, JoinData},
utils::*, utils::*,
@ -55,7 +55,8 @@ pub struct Data {
/// Struct containing data that does not change over the course of the /// Struct containing data that does not change over the course of the
/// character state /// character state
pub static_data: StaticData, 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, pub auto_charge: bool,
/// Timer for each stage /// Timer for each stage
pub timer: Duration, pub timer: Duration,
@ -65,6 +66,8 @@ pub struct Data {
pub stage_section: StageSection, pub stage_section: StageSection,
/// Whether the state should attempt attacking again /// Whether the state should attempt attacking again
pub exhausted: bool, pub exhausted: bool,
/// Whether or not the state should end
pub end: bool,
} }
impl CharacterBehavior for Data { impl CharacterBehavior for Data {
@ -97,10 +100,10 @@ impl CharacterBehavior for Data {
} else { } else {
// Transitions to charge section of stage // Transitions to charge section of stage
update.character = CharacterState::DashMelee(Data { update.character = CharacterState::DashMelee(Data {
auto_charge: !ability_key_is_pressed( auto_charge: /*\!ability_key_is_pressed(
data, data,
self.static_data.ability_info.key, self.static_data.ability_info.key,
), )*/self.end,
timer: Duration::default(), timer: Duration::default(),
stage_section: StageSection::Charge, stage_section: StageSection::Charge,
..*self ..*self
@ -110,7 +113,7 @@ impl CharacterBehavior for Data {
StageSection::Charge => { StageSection::Charge => {
if (self.static_data.infinite_charge if (self.static_data.infinite_charge
|| self.timer < self.static_data.charge_duration) || 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)) || (self.auto_charge && self.timer < self.static_data.charge_duration))
&& update.energy.current() > 0 && update.energy.current() > 0
{ {
@ -267,4 +270,17 @@ impl CharacterBehavior for Data {
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::DashMelee(c) = &mut update.character {
c.end = true;
}
}
update
}
} }

View File

@ -1,6 +1,6 @@
use crate::{ use crate::{
combat::{Attack, AttackEffect, CombatEffect, CombatRequirement, GroupTarget}, combat::{Attack, AttackEffect, CombatEffect, CombatRequirement, GroupTarget},
comp::{beam, CharacterState, Ori, Pos, StateUpdate}, comp::{beam, CharacterState, InputKind, Ori, Pos, StateUpdate},
event::ServerEvent, event::ServerEvent,
states::{ states::{
behavior::{CharacterBehavior, JoinData}, behavior::{CharacterBehavior, JoinData},
@ -46,6 +46,8 @@ pub struct Data {
pub timer: Duration, pub timer: Duration,
/// What section the character stage is in /// What section the character stage is in
pub stage_section: StageSection, pub stage_section: StageSection,
/// Whether or not the state should end
pub end: bool,
} }
impl CharacterBehavior for Data { impl CharacterBehavior for Data {
@ -91,7 +93,9 @@ impl CharacterBehavior for Data {
} }
}, },
StageSection::Cast => { 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 = let speed =
self.static_data.range / self.static_data.beam_duration.as_secs_f32(); self.static_data.range / self.static_data.beam_duration.as_secs_f32();
let heal = AttackEffect::new( let heal = AttackEffect::new(
@ -164,4 +168,17 @@ impl CharacterBehavior for Data {
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::HealingBeam(c) = &mut update.character {
c.end = true;
}
}
update
}
} }

View File

@ -1,6 +1,6 @@
use crate::{ use crate::{
combat::{Attack, AttackDamage, AttackEffect, CombatBuff, CombatEffect, CombatRequirement}, combat::{Attack, AttackDamage, AttackEffect, CombatBuff, CombatEffect, CombatRequirement},
comp::{CharacterState, EnergyChange, EnergySource, Melee, StateUpdate}, comp::{CharacterState, EnergyChange, EnergySource, InputKind, Melee, StateUpdate},
consts::GRAVITY, consts::GRAVITY,
states::{ states::{
behavior::{CharacterBehavior, JoinData}, behavior::{CharacterBehavior, JoinData},
@ -58,6 +58,8 @@ pub struct Data {
pub stage_section: StageSection, pub stage_section: StageSection,
/// Whether the state can deal damage /// Whether the state can deal damage
pub exhausted: bool, pub exhausted: bool,
/// Whether or not the state should end
pub end: bool,
} }
impl CharacterBehavior for Data { impl CharacterBehavior for Data {
@ -179,7 +181,7 @@ impl CharacterBehavior for Data {
} else if update.energy.current() as f32 >= self.static_data.energy_cost } else if update.energy.current() as f32 >= self.static_data.energy_cost
&& (self.spins_remaining != 0 && (self.spins_remaining != 0
|| (self.static_data.is_infinite || (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 { let new_spins_remaining = if self.static_data.is_infinite {
self.spins_remaining self.spins_remaining
@ -233,6 +235,19 @@ impl CharacterBehavior for Data {
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::SpinMelee(c) = &mut update.character {
c.end = true;
}
}
update
}
} }
#[derive(Copy, Clone, Debug, PartialEq, Serialize, Deserialize)] #[derive(Copy, Clone, Debug, PartialEq, Serialize, Deserialize)]

View File

@ -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 /// is pressed, then attempts to go into Equipping state, otherwise Idle
pub fn handle_wield(data: &JoinData, update: &mut StateUpdate) { pub fn handle_wield(data: &JoinData, update: &mut StateUpdate) {
if if
/*data.inputs.primary.is_pressed() // data.inputs.primary.is_pressed() || data.inputs.secondary.is_pressed() ||
|| */ data.inputs.ability3.is_pressed() || data.inputs.ability4.is_pressed() {
data.inputs.secondary.is_pressed()
|| data.inputs.ability3.is_pressed()
|| data.inputs.ability4.is_pressed()
{
attempt_wield(data, update); attempt_wield(data, update);
} }
} }
@ -504,6 +500,9 @@ fn handle_ability_pressed(
pub fn handle_input(data: &JoinData, update: &mut StateUpdate, input: InputKind) { pub fn handle_input(data: &JoinData, update: &mut StateUpdate, input: InputKind) {
match input { match input {
InputKind::Primary => handle_ability_pressed(data, update, AbilityKey::Mouse1, Some(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) { // pub fn handle_ability2_input(data: &JoinData, update: &mut StateUpdate) {
if data.inputs.secondary.is_pressed() { // if data.inputs.secondary.is_pressed() {
handle_ability_pressed(data, update, AbilityKey::Mouse2, None); // handle_ability_pressed(data, update, AbilityKey::Mouse2, None);
} // }
} // }
pub fn handle_ability3_input(data: &JoinData, update: &mut StateUpdate) { pub fn handle_ability3_input(data: &JoinData, update: &mut StateUpdate) {
if data.inputs.ability3.is_pressed() { 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) { pub fn handle_interrupt(data: &JoinData, update: &mut StateUpdate, attacks_interrupt: bool) {
if attacks_interrupt { if attacks_interrupt {
//handle_ability1_input(data, update); //handle_ability1_input(data, update);
handle_ability2_input(data, update); // handle_ability2_input(data, update);
handle_ability3_input(data, update); handle_ability3_input(data, update);
handle_ability4_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 false
}, },
AbilityKey::Mouse2 => data.inputs.secondary.is_pressed(), AbilityKey::Mouse2 =>
/* data.inputs.secondary.is_pressed() */
{
false
},
AbilityKey::Skill1 => data.inputs.ability3.is_pressed(), AbilityKey::Skill1 => data.inputs.ability3.is_pressed(),
AbilityKey::Skill2 => data.inputs.ability4.is_pressed(), AbilityKey::Skill2 => data.inputs.ability4.is_pressed(),
AbilityKey::Dodge => data.inputs.roll.is_pressed(), AbilityKey::Dodge => data.inputs.roll.is_pressed(),

View File

@ -18,7 +18,7 @@ impl CharacterBehavior for Data {
handle_jump(&data, &mut update); handle_jump(&data, &mut update);
handle_climb(&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_ability2_input(&data, &mut update);
handle_ability3_input(&data, &mut update); handle_ability3_input(&data, &mut update);
handle_ability4_input(&data, &mut update); handle_ability4_input(&data, &mut update);
handle_dodge_input(&data, &mut update); handle_dodge_input(&data, &mut update);

View File

@ -1118,10 +1118,17 @@ impl<'a> AgentData<'a> {
if dist_sqrd < (min_attack_dist * self.scale).powi(2) { if dist_sqrd < (min_attack_dist * self.scale).powi(2) {
controller.inputs.move_dir = Vec2::zero(); controller.inputs.move_dir = Vec2::zero();
if agent.action_timer > 6.0 { 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; agent.action_timer = 0.0;
} else if agent.action_timer > 4.0 && self.energy.current() > 10 { } 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; agent.action_timer += dt.0;
} else if self } else if self
.stats .stats
@ -1170,10 +1177,17 @@ impl<'a> AgentData<'a> {
if dist_sqrd < (min_attack_dist * self.scale).powi(2) { if dist_sqrd < (min_attack_dist * self.scale).powi(2) {
controller.inputs.move_dir = Vec2::zero(); controller.inputs.move_dir = Vec2::zero();
if agent.action_timer > 4.0 { 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; agent.action_timer = 0.0;
} else if agent.action_timer > 2.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; agent.action_timer += dt.0;
} else if self } else if self
.stats .stats
@ -1271,7 +1285,11 @@ impl<'a> AgentData<'a> {
controller.inputs.move_dir = controller.inputs.move_dir =
bearing.xy().try_normalized().unwrap_or_else(Vec2::zero) * speed; bearing.xy().try_normalized().unwrap_or_else(Vec2::zero) * speed;
if agent.action_timer > 4.0 { 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; agent.action_timer = 0.0;
} else { } else {
agent.action_timer += dt.0; agent.action_timer += dt.0;
@ -1317,10 +1335,17 @@ impl<'a> AgentData<'a> {
.unwrap_or_else(Vec2::zero) .unwrap_or_else(Vec2::zero)
* speed; * speed;
if agent.action_timer > 4.0 { 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; agent.action_timer = 0.0;
} else if agent.action_timer > 2.0 && self.energy.current() > 300 { } 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; agent.action_timer += dt.0;
} else if self } else if self
.stats .stats
@ -1329,11 +1354,17 @@ impl<'a> AgentData<'a> {
&& self.energy.current() > 400 && self.energy.current() > 400
&& thread_rng().gen_bool(0.8) && 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); controller.inputs.ability3.set_state(true);
agent.action_timer += dt.0; agent.action_timer += dt.0;
} else { } 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 { controller.actions.push(ControlAction::StartInput {
input: InputKind::Primary, input: InputKind::Primary,
target: None, target: None,
@ -1406,7 +1437,11 @@ impl<'a> AgentData<'a> {
{ {
controller.inputs.ability3.set_state(true); controller.inputs.ability3.set_state(true);
} else if self.energy.current() > 10 { } 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 { } else {
controller.actions.push(ControlAction::StartInput { controller.actions.push(ControlAction::StartInput {
input: InputKind::Primary, input: InputKind::Primary,
@ -1498,7 +1533,11 @@ impl<'a> AgentData<'a> {
controller.inputs.move_dir = controller.inputs.move_dir =
bearing.xy().try_normalized().unwrap_or_else(Vec2::zero) * speed; bearing.xy().try_normalized().unwrap_or_else(Vec2::zero) * speed;
if agent.action_timer > 5.0 { 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; agent.action_timer = 0.0;
} else { } else {
agent.action_timer += dt.0; agent.action_timer += dt.0;
@ -1542,7 +1581,11 @@ impl<'a> AgentData<'a> {
.unwrap_or_else(Vec2::unit_y); .unwrap_or_else(Vec2::unit_y);
agent.action_timer += dt.0; agent.action_timer += dt.0;
} else if agent.action_timer < circle_time as f32 + 0.5 { } 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; agent.action_timer += dt.0;
} else if agent.action_timer < 2.0 * circle_time as f32 + 0.5 { } else if agent.action_timer < 2.0 * circle_time as f32 + 0.5 {
controller.inputs.move_dir = (tgt_pos.0 - self.pos.0) controller.inputs.move_dir = (tgt_pos.0 - self.pos.0)
@ -1552,7 +1595,11 @@ impl<'a> AgentData<'a> {
.unwrap_or_else(Vec2::unit_y); .unwrap_or_else(Vec2::unit_y);
agent.action_timer += dt.0; agent.action_timer += dt.0;
} else if agent.action_timer < 2.0 * circle_time as f32 + 1.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; agent.action_timer += dt.0;
} else { } else {
agent.action_timer = 0.0; agent.action_timer = 0.0;
@ -1619,7 +1666,11 @@ impl<'a> AgentData<'a> {
* speed; * speed;
agent.action_timer += dt.0; 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.jump.set_state(bearing.z > 1.5);
controller.inputs.move_z = bearing.z; controller.inputs.move_z = bearing.z;
} else { } else {
@ -1651,7 +1702,11 @@ impl<'a> AgentData<'a> {
//controller.inputs.primary.set_state(true); //controller.inputs.primary.set_state(true);
agent.action_timer += dt.0; agent.action_timer += dt.0;
} else { } 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; agent.action_timer += dt.0;
} }
controller.inputs.move_dir = (tgt_pos.0 - self.pos.0) controller.inputs.move_dir = (tgt_pos.0 - self.pos.0)
@ -1682,7 +1737,11 @@ impl<'a> AgentData<'a> {
Tactic::QuadLowQuick => { Tactic::QuadLowQuick => {
if dist_sqrd < (1.5 * min_attack_dist * self.scale).powi(2) { if dist_sqrd < (1.5 * min_attack_dist * self.scale).powi(2) {
controller.inputs.move_dir = Vec2::zero(); 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) } else if dist_sqrd < (3.0 * min_attack_dist * self.scale).powi(2)
&& dist_sqrd > (2.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 { if agent.action_timer > 5.0 {
agent.action_timer = 0.0; agent.action_timer = 0.0;
} else if agent.action_timer > 2.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; agent.action_timer += dt.0;
} else { } else {
controller.actions.push(ControlAction::StartInput { controller.actions.push(ControlAction::StartInput {
@ -1755,7 +1818,11 @@ impl<'a> AgentData<'a> {
Tactic::QuadMedJump => { Tactic::QuadMedJump => {
if dist_sqrd < (1.5 * min_attack_dist * self.scale).powi(2) { if dist_sqrd < (1.5 * min_attack_dist * self.scale).powi(2) {
controller.inputs.move_dir = Vec2::zero(); 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) { } else if dist_sqrd < (5.0 * min_attack_dist * self.scale).powi(2) {
controller.inputs.ability3.set_state(true); controller.inputs.ability3.set_state(true);
} else if dist_sqrd < MAX_CHASE_DIST.powi(2) { } 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) { if dist_sqrd < (min_attack_dist * self.scale).powi(2) {
controller.inputs.move_dir = Vec2::zero(); controller.inputs.move_dir = Vec2::zero();
if agent.action_timer < 2.0 { 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; agent.action_timer += dt.0;
} else if agent.action_timer < 3.0 { } else if agent.action_timer < 3.0 {
controller.actions.push(ControlAction::StartInput { controller.actions.push(ControlAction::StartInput {
@ -1827,7 +1898,11 @@ impl<'a> AgentData<'a> {
Tactic::Lavadrake | Tactic::QuadLowBeam => { Tactic::Lavadrake | Tactic::QuadLowBeam => {
if dist_sqrd < (2.5 * min_attack_dist * self.scale).powi(2) { if dist_sqrd < (2.5 * min_attack_dist * self.scale).powi(2) {
controller.inputs.move_dir = Vec2::zero(); 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) { } else if dist_sqrd < (7.0 * min_attack_dist * self.scale).powi(2) {
if agent.action_timer < 2.0 { if agent.action_timer < 2.0 {
controller.inputs.move_dir = (tgt_pos.0 - self.pos.0) controller.inputs.move_dir = (tgt_pos.0 - self.pos.0)

View File

@ -372,7 +372,7 @@ impl PlayState for SessionState {
} }
}, },
GameInput::Secondary => { 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(); let mut client = self.client.borrow_mut();
@ -381,7 +381,8 @@ impl PlayState for SessionState {
client.place_block(build_pos, self.selected_block); client.place_block(build_pos, self.selected_block);
} }
} else { } else {
self.inputs.secondary.set_state(state); client.handle_input(InputKind::Secondary, state);
// self.inputs.secondary.set_state(state);
} }
}, },
GameInput::Roll => { GameInput::Roll => {