From f47184df85fc5c50668519bfbba9788f3f5afdd8 Mon Sep 17 00:00:00 2001 From: "Dr. Dystopia" Date: Wed, 26 Jan 2022 19:40:18 +0100 Subject: [PATCH 1/8] Use 'push_event' function in more places --- server/src/sys/agent.rs | 25 +++++++++---------------- server/src/sys/msg/in_game.rs | 2 +- 2 files changed, 10 insertions(+), 17 deletions(-) diff --git a/server/src/sys/agent.rs b/server/src/sys/agent.rs index 8e4235bc34..017f334647 100644 --- a/server/src/sys/agent.rs +++ b/server/src/sys/agent.rs @@ -715,11 +715,11 @@ impl<'a> AgentData<'a> { // nighttime and keep them on // Only emit event for agents that sill need to // turn on their lantern - controller.events.push(ControlEvent::EnableLantern) + controller.push_event(ControlEvent::EnableLantern) } else if lantern_turned_on && day_period.is_light() { // agents with turned on lanterns turn them off randomly once it's // daytime and keep them off - controller.events.push(ControlEvent::DisableLantern) + controller.push_event(ControlEvent::DisableLantern) } }; @@ -962,12 +962,10 @@ impl<'a> AgentData<'a> { // // Clear agent comp // //*agent = Agent::default(); // controller - // .events - // .push(ControlEvent::InviteResponse(InviteResponse::Accept)); + // .push_event(ControlEvent::InviteResponse(InviteResponse::Accept)); // } else { // controller - // .events - // .push(ControlEvent::InviteResponse(InviteResponse::Decline)); + // .push_event(ControlEvent::InviteResponse(InviteResponse::Decline)); // } agent.action_state.timer += read_data.dt.0; @@ -1025,7 +1023,7 @@ impl<'a> AgentData<'a> { self.chat_npc(msg, event_emitter); } else if agent.behavior.can_trade() { if !agent.behavior.is(BehaviorState::TRADING) { - controller.events.push(ControlEvent::InitiateInvite( + controller.push_event(ControlEvent::InitiateInvite( by, InviteKind::Trade, )); @@ -1046,7 +1044,7 @@ impl<'a> AgentData<'a> { Subject::Trade => { if agent.behavior.can_trade() { if !agent.behavior.is(BehaviorState::TRADING) { - controller.events.push(ControlEvent::InitiateInvite( + controller.push_event(ControlEvent::InitiateInvite( by, InviteKind::Trade, )); @@ -1183,15 +1181,12 @@ impl<'a> AgentData<'a> { agent.target = Some(Target::new(target, false, read_data.time.0, false)); } - controller - .events - .push(ControlEvent::InviteResponse(InviteResponse::Accept)); + controller.push_event(ControlEvent::InviteResponse(InviteResponse::Accept)); agent.behavior.unset(BehaviorState::TRADING_ISSUER); agent.behavior.set(BehaviorState::TRADING); } else { controller - .events - .push(ControlEvent::InviteResponse(InviteResponse::Decline)); + .push_event(ControlEvent::InviteResponse(InviteResponse::Decline)); self.chat_npc_if_allowed_to_speak( "npc.speech.merchant_busy", agent, @@ -1200,9 +1195,7 @@ impl<'a> AgentData<'a> { } } else { // TODO: Provide a hint where to find the closest merchant? - controller - .events - .push(ControlEvent::InviteResponse(InviteResponse::Decline)); + controller.push_event(ControlEvent::InviteResponse(InviteResponse::Decline)); self.chat_npc_if_allowed_to_speak( "npc.speech.villager_decline_trade", agent, diff --git a/server/src/sys/msg/in_game.rs b/server/src/sys/msg/in_game.rs index f8be0042bb..72989a7f45 100644 --- a/server/src/sys/msg/in_game.rs +++ b/server/src/sys/msg/in_game.rs @@ -100,7 +100,7 @@ impl Sys { } } if let Some(controller) = controllers.get_mut(entity) { - controller.events.push(event); + controller.push_event(event); } } }, From bc0a8c77044ed431f7cf2db9f19963629938c455 Mon Sep 17 00:00:00 2001 From: "Dr. Dystopia" Date: Wed, 26 Jan 2022 19:52:19 +0100 Subject: [PATCH 2/8] Create 'push_action' function --- client/src/lib.rs | 2 +- common/src/comp/controller.rs | 2 + server/src/sys/agent.rs | 58 ++-- server/src/sys/agent/attack.rs | 540 +++++++++------------------------ server/src/sys/msg/in_game.rs | 2 +- 5 files changed, 162 insertions(+), 442 deletions(-) diff --git a/client/src/lib.rs b/client/src/lib.rs index faa68a93ba..27eace9afe 100644 --- a/client/src/lib.rs +++ b/client/src/lib.rs @@ -1301,7 +1301,7 @@ impl Client { .write_storage::() .get_mut(self.entity()) { - controller.actions.push(control_action); + controller.push_action(control_action); } self.send_msg(ClientGeneral::ControlAction(control_action)); } diff --git a/common/src/comp/controller.rs b/common/src/comp/controller.rs index 2a1ba9789b..473210c05a 100644 --- a/common/src/comp/controller.rs +++ b/common/src/comp/controller.rs @@ -279,6 +279,8 @@ impl Controller { pub fn clear_events(&mut self) { self.events.clear(); } pub fn push_event(&mut self, event: ControlEvent) { self.events.push(event); } + + pub fn push_action(&mut self, action: ControlAction) { self.actions.push(action); } } impl Component for Controller { diff --git a/server/src/sys/agent.rs b/server/src/sys/agent.rs index 017f334647..0e0c138a3e 100644 --- a/server/src/sys/agent.rs +++ b/server/src/sys/agent.rs @@ -208,9 +208,7 @@ impl<'a> System<'a> for Sys { // // TODO: look into `controller.reset()` line above // and see if it fixes it - controller - .actions - .push(ControlAction::basic_input(InputKind::Fly)); + controller.push_action(ControlAction::basic_input(InputKind::Fly)); } // Package all this agent's data into a convenient struct @@ -547,13 +545,13 @@ impl<'a> AgentData<'a> { // Look toward the interacting entity for a while if let Some(Target { target, .. }) = &agent.target { self.look_toward(controller, read_data, *target); - controller.actions.push(ControlAction::Talk); + controller.push_action(ControlAction::Talk); } }, Some(just_ended) => { if just_ended { agent.target = None; - controller.actions.push(ControlAction::Stand); + controller.push_action(ControlAction::Stand); } if rng.gen::() < 0.1 { @@ -666,7 +664,7 @@ impl<'a> AgentData<'a> { //////////////////////////////////////// fn glider_fall(&self, controller: &mut Controller) { - controller.actions.push(ControlAction::GlideWield); + controller.push_action(ControlAction::GlideWield); let flight_direction = Vec3::from(self.vel.0.xy().try_normalized().unwrap_or_else(Vec2::zero)); @@ -684,9 +682,7 @@ impl<'a> AgentData<'a> { } fn fly_upward(&self, controller: &mut Controller) { - controller - .actions - .push(ControlAction::basic_input(InputKind::Fly)); + controller.push_action(ControlAction::basic_input(InputKind::Fly)); controller.inputs.move_z = 1.0; } @@ -741,13 +737,9 @@ impl<'a> AgentData<'a> { .1 .map_or(true, |b| b.is_some()) { - controller - .actions - .push(ControlAction::basic_input(InputKind::Fly)); + controller.push_action(ControlAction::basic_input(InputKind::Fly)); } else { - controller - .actions - .push(ControlAction::CancelInput(InputKind::Fly)) + controller.push_action(ControlAction::CancelInput(InputKind::Fly)) } if let Some((bearing, speed)) = agent.chaser.chase( @@ -846,7 +838,7 @@ impl<'a> AgentData<'a> { Some(CharacterState::Wielding(_)) ) { - controller.actions.push(ControlAction::Unwield); + controller.push_action(ControlAction::Unwield); } } } else { @@ -909,7 +901,7 @@ impl<'a> AgentData<'a> { Some(CharacterState::Wielding(_)) ) { - controller.actions.push(ControlAction::Unwield); + controller.push_action(ControlAction::Unwield); } if rng.gen::() < 0.0015 { @@ -918,7 +910,7 @@ impl<'a> AgentData<'a> { // Sit if rng.gen::() < 0.0035 { - controller.actions.push(ControlAction::Sit); + controller.push_action(ControlAction::Sit); } } } @@ -977,8 +969,8 @@ impl<'a> AgentData<'a> { agent.target = Some(Target::new(target, false, read_data.time.0, false)); if self.look_toward(controller, read_data, target) { - controller.actions.push(ControlAction::Stand); - controller.actions.push(ControlAction::Talk); + controller.push_action(ControlAction::Stand); + controller.push_action(ControlAction::Talk); controller.push_event(ControlEvent::Utterance(UtteranceKind::Greeting)); match subject { @@ -1175,8 +1167,8 @@ impl<'a> AgentData<'a> { if agent.behavior.can_trade() { if !agent.behavior.is(BehaviorState::TRADING) { // stand still and looking towards the trading player - controller.actions.push(ControlAction::Stand); - controller.actions.push(ControlAction::Talk); + controller.push_action(ControlAction::Stand); + controller.push_action(ControlAction::Talk); if let Some(target) = get_entity_by_id(with.id(), read_data) { agent.target = Some(Target::new(target, false, read_data.time.0, false)); @@ -1328,7 +1320,7 @@ impl<'a> AgentData<'a> { let small_chance = rng.gen::() < read_data.dt.0 * 0.25; self.look_toward(controller, read_data, target); - controller.actions.push(ControlAction::Wield); + controller.push_action(ControlAction::Wield); if move_dir_mag > max_move { controller.inputs.move_dir = max_move * move_dir / move_dir_mag; @@ -1349,7 +1341,7 @@ impl<'a> AgentData<'a> { ) { if let Some(body) = self.body { if body.can_strafe() && !self.is_gliding { - controller.actions.push(ControlAction::Unwield); + controller.push_action(ControlAction::Unwield); } } if let Some((bearing, speed)) = agent.chaser.chase( @@ -1423,11 +1415,9 @@ impl<'a> AgentData<'a> { if let Some((id, _)) = item { use comp::inventory::slot::Slot; - controller - .actions - .push(ControlAction::InventoryAction(InventoryAction::Use( - Slot::Inventory(id), - ))); + controller.push_action(ControlAction::InventoryAction(InventoryAction::Use( + Slot::Inventory(id), + ))); true } else { false @@ -1736,7 +1726,7 @@ impl<'a> AgentData<'a> { .unwrap_or(Tactic::Melee); // Wield the weapon as running towards the target - controller.actions.push(ControlAction::Wield); + controller.push_action(ControlAction::Wield); let min_attack_dist = (self.body.map_or(0.5, |b| b.max_radius()) + DEFAULT_ATTACK_RANGE) * self.scale @@ -2284,13 +2274,9 @@ impl<'a> AgentData<'a> { fn jump_if(&self, controller: &mut Controller, condition: bool) { if condition { - controller - .actions - .push(ControlAction::basic_input(InputKind::Jump)); + controller.push_action(ControlAction::basic_input(InputKind::Jump)); } else { - controller - .actions - .push(ControlAction::CancelInput(InputKind::Jump)) + controller.push_action(ControlAction::CancelInput(InputKind::Jump)) } } diff --git a/server/src/sys/agent/attack.rs b/server/src/sys/agent/attack.rs index 9e3fc0e1aa..3459584917 100644 --- a/server/src/sys/agent/attack.rs +++ b/server/src/sys/agent/attack.rs @@ -29,9 +29,7 @@ impl<'a> AgentData<'a> { rng: &mut impl Rng, ) { if attack_data.in_min_range() && attack_data.angle < 45.0 { - controller - .actions - .push(ControlAction::basic_input(InputKind::Primary)); + controller.push_action(ControlAction::basic_input(InputKind::Primary)); controller.inputs.move_dir = Vec2::zero(); } else if attack_data.dist_sqrd < MAX_PATH_DIST.powi(2) { self.path_toward_target(agent, controller, tgt_data, read_data, true, true, None); @@ -40,9 +38,7 @@ impl<'a> AgentData<'a> { && attack_data.dist_sqrd < 16.0f32.powi(2) && rng.gen::() < 0.02 { - controller - .actions - .push(ControlAction::basic_input(InputKind::Roll)); + controller.push_action(ControlAction::basic_input(InputKind::Roll)); } } else { self.path_toward_target(agent, controller, tgt_data, read_data, false, true, None); @@ -63,31 +59,21 @@ impl<'a> AgentData<'a> { let has_energy = |need| self.energy.current() > need; let use_leap = |controller: &mut Controller| { - controller - .actions - .push(ControlAction::basic_input(InputKind::Ability(0))); + controller.push_action(ControlAction::basic_input(InputKind::Ability(0))); }; if attack_data.in_min_range() && attack_data.angle < 45.0 { controller.inputs.move_dir = Vec2::zero(); if agent.action_state.timer > 5.0 { - controller - .actions - .push(ControlAction::CancelInput(InputKind::Secondary)); + controller.push_action(ControlAction::CancelInput(InputKind::Secondary)); agent.action_state.timer = 0.0; } else if agent.action_state.timer > 2.5 && has_energy(10.0) { - controller - .actions - .push(ControlAction::basic_input(InputKind::Secondary)); + controller.push_action(ControlAction::basic_input(InputKind::Secondary)); agent.action_state.timer += read_data.dt.0; } else if has_leap() && has_energy(45.0) && rng.gen_bool(0.5) { - controller - .actions - .push(ControlAction::basic_input(InputKind::Ability(0))); + controller.push_action(ControlAction::basic_input(InputKind::Ability(0))); agent.action_state.timer += read_data.dt.0; } else { - controller - .actions - .push(ControlAction::basic_input(InputKind::Primary)); + controller.push_action(ControlAction::basic_input(InputKind::Primary)); agent.action_state.timer += read_data.dt.0; } } else if attack_data.dist_sqrd < MAX_PATH_DIST.powi(2) { @@ -108,9 +94,7 @@ impl<'a> AgentData<'a> { && attack_data.dist_sqrd < 16.0f32.powi(2) && rng.gen::() < 0.02 { - controller - .actions - .push(ControlAction::basic_input(InputKind::Roll)); + controller.push_action(ControlAction::basic_input(InputKind::Roll)); } } else { self.path_toward_target(agent, controller, tgt_data, read_data, false, false, None); @@ -134,30 +118,22 @@ impl<'a> AgentData<'a> { let has_energy = |need| self.energy.current() > need; let use_leap = |controller: &mut Controller| { - controller - .actions - .push(ControlAction::basic_input(InputKind::Ability(0))); + controller.push_action(ControlAction::basic_input(InputKind::Ability(0))); }; if attack_data.in_min_range() && attack_data.angle < 45.0 { controller.inputs.move_dir = Vec2::zero(); if agent.action_state.timer > 4.0 { - controller - .actions - .push(ControlAction::CancelInput(InputKind::Secondary)); + controller.push_action(ControlAction::CancelInput(InputKind::Secondary)); agent.action_state.timer = 0.0; } else if agent.action_state.timer > 3.0 { - controller - .actions - .push(ControlAction::basic_input(InputKind::Secondary)); + controller.push_action(ControlAction::basic_input(InputKind::Secondary)); agent.action_state.timer += read_data.dt.0; } else if has_leap() && has_energy(50.0) && rng.gen_bool(0.9) { use_leap(controller); agent.action_state.timer += read_data.dt.0; } else { - controller - .actions - .push(ControlAction::basic_input(InputKind::Primary)); + controller.push_action(ControlAction::basic_input(InputKind::Primary)); agent.action_state.timer += read_data.dt.0; } } else if attack_data.dist_sqrd < MAX_PATH_DIST.powi(2) { @@ -178,9 +154,7 @@ impl<'a> AgentData<'a> { && attack_data.dist_sqrd < 16.0f32.powi(2) && rng.gen::() < 0.02 { - controller - .actions - .push(ControlAction::basic_input(InputKind::Roll)); + controller.push_action(ControlAction::basic_input(InputKind::Roll)); } } else { self.path_toward_target(agent, controller, tgt_data, read_data, false, false, None); @@ -204,16 +178,12 @@ impl<'a> AgentData<'a> { && agent.action_state.timer < 2.0 && self.energy.current() > 60.0 { - controller - .actions - .push(ControlAction::basic_input(InputKind::Ability(0))); + controller.push_action(ControlAction::basic_input(InputKind::Ability(0))); agent.action_state.timer += read_data.dt.0; } else if agent.action_state.timer > 2.0 { agent.action_state.timer = 0.0; } else { - controller - .actions - .push(ControlAction::basic_input(InputKind::Primary)); + controller.push_action(ControlAction::basic_input(InputKind::Primary)); agent.action_state.timer += read_data.dt.0; } } else if attack_data.dist_sqrd < MAX_PATH_DIST.powi(2) { @@ -226,9 +196,7 @@ impl<'a> AgentData<'a> { ) { if agent.action_state.timer > 4.0 && attack_data.angle < 45.0 { - controller - .actions - .push(ControlAction::basic_input(InputKind::Secondary)); + controller.push_action(ControlAction::basic_input(InputKind::Secondary)); agent.action_state.timer = 0.0; } else { agent.action_state.timer += read_data.dt.0; @@ -238,9 +206,7 @@ impl<'a> AgentData<'a> { && attack_data.dist_sqrd < 16.0f32.powi(2) && rng.gen::() < 0.02 { - controller - .actions - .push(ControlAction::basic_input(InputKind::Roll)); + controller.push_action(ControlAction::basic_input(InputKind::Roll)); } } else { self.path_toward_target(agent, controller, tgt_data, read_data, false, false, None); @@ -274,9 +240,7 @@ impl<'a> AgentData<'a> { { // If haven't charged to desired level, or target is moving too fast and haven't // fully charged, keep charging - controller - .actions - .push(ControlAction::basic_input(InputKind::Primary)); + controller.push_action(ControlAction::basic_input(InputKind::Primary)); } // Else don't send primary input to release the shot } @@ -293,9 +257,7 @@ impl<'a> AgentData<'a> { ) { // Only keep firing if not in melee range or if can see target - controller - .actions - .push(ControlAction::basic_input(InputKind::Secondary)); + controller.push_action(ControlAction::basic_input(InputKind::Secondary)); } } else if attack_data.dist_sqrd < (2.0 * attack_data.min_attack_dist).powi(2) { if self @@ -305,24 +267,18 @@ impl<'a> AgentData<'a> { && rng.gen_bool(0.5) { // Use shotgun if target close and have sufficient energy - controller - .actions - .push(ControlAction::basic_input(InputKind::Ability(0))); + controller.push_action(ControlAction::basic_input(InputKind::Ability(0))); } else if self.body.map(|b| b.is_humanoid()).unwrap_or(false) && self.energy.current() > CharacterAbility::default_roll().get_energy_cost() && !matches!(self.char_state, CharacterState::BasicRanged(c) if !matches!(c.stage_section, StageSection::Recover)) { // Else roll away if can roll and have enough energy, and not using shotgun // (other 2 attacks have interrupt handled above) unless in recover - controller - .actions - .push(ControlAction::basic_input(InputKind::Roll)); + controller.push_action(ControlAction::basic_input(InputKind::Roll)); } else { self.path_toward_target(agent, controller, tgt_data, read_data, true, false, None); if attack_data.angle < 15.0 { - controller - .actions - .push(ControlAction::basic_input(InputKind::Primary)); + controller.push_action(ControlAction::basic_input(InputKind::Primary)); } } } else if attack_data.dist_sqrd < MAX_PATH_DIST.powi(2) @@ -336,14 +292,10 @@ impl<'a> AgentData<'a> { // If not really far, and can see target, attempt to shoot bow if self.energy.current() < DESIRED_ENERGY_LEVEL { // If low on energy, use primary to attempt to regen energy - controller - .actions - .push(ControlAction::basic_input(InputKind::Primary)); + controller.push_action(ControlAction::basic_input(InputKind::Primary)); } else { // Else we have enough energy, use repeater - controller - .actions - .push(ControlAction::basic_input(InputKind::Secondary)); + controller.push_action(ControlAction::basic_input(InputKind::Secondary)); } } // Logic to move. Intentionally kept separate from ability logic so duplicated @@ -401,9 +353,7 @@ impl<'a> AgentData<'a> { && attack_data.dist_sqrd < 16.0f32.powi(2) && rng.gen::() < 0.01 { - controller - .actions - .push(ControlAction::basic_input(InputKind::Roll)); + controller.push_action(ControlAction::basic_input(InputKind::Roll)); } } else { // If too far, move towards target @@ -442,17 +392,13 @@ impl<'a> AgentData<'a> { { // if a humanoid, have enough stamina, not in shockwave, and in melee range, // emergency roll - controller - .actions - .push(ControlAction::basic_input(InputKind::Roll)); + controller.push_action(ControlAction::basic_input(InputKind::Roll)); } else if matches!(self.char_state, CharacterState::Shockwave(_)) { agent.action_state.condition = false; } else if agent.action_state.condition && matches!(self.char_state, CharacterState::Wielding(_)) { - controller - .actions - .push(ControlAction::basic_input(InputKind::Ability(0))); + controller.push_action(ControlAction::basic_input(InputKind::Ability(0))); } else if !matches!(self.char_state, CharacterState::Shockwave(c) if !matches!(c.stage_section, StageSection::Recover)) { // only try to use another ability unless in shockwave or recover @@ -470,9 +416,7 @@ impl<'a> AgentData<'a> { { // if enemy is closing distance quickly, use shockwave to knock back if matches!(self.char_state, CharacterState::Wielding(_)) { - controller - .actions - .push(ControlAction::basic_input(InputKind::Ability(0))); + controller.push_action(ControlAction::basic_input(InputKind::Ability(0))); } else { agent.action_state.condition = true; } @@ -480,13 +424,9 @@ impl<'a> AgentData<'a> { > shockwave_cost + CharacterAbility::default_roll().get_energy_cost() && attack_data.dist_sqrd < flamethrower_range.powi(2) { - controller - .actions - .push(ControlAction::basic_input(InputKind::Secondary)); + controller.push_action(ControlAction::basic_input(InputKind::Secondary)); } else { - controller - .actions - .push(ControlAction::basic_input(InputKind::Primary)); + controller.push_action(ControlAction::basic_input(InputKind::Primary)); } } // Logic to move. Intentionally kept separate from ability logic so duplicated @@ -545,9 +485,7 @@ impl<'a> AgentData<'a> { && !matches!(self.char_state, CharacterState::Shockwave(_)) && rng.gen::() < 0.02 { - controller - .actions - .push(ControlAction::basic_input(InputKind::Roll)); + controller.push_action(ControlAction::basic_input(InputKind::Roll)); } } else { // If too far, move towards target @@ -590,9 +528,7 @@ impl<'a> AgentData<'a> { }) { // If have enough energy and combo to use healing aura, do so - controller - .actions - .push(ControlAction::basic_input(InputKind::Secondary)); + controller.push_action(ControlAction::basic_input(InputKind::Secondary)); } else if self .skill_set .has_skill(Skill::Sceptre(SceptreSkill::UnlockAura)) @@ -606,15 +542,11 @@ impl<'a> AgentData<'a> { { // Use ward if target is far enough away, self is not buffed, and have // sufficient energy - controller - .actions - .push(ControlAction::basic_input(InputKind::Ability(0))); + controller.push_action(ControlAction::basic_input(InputKind::Ability(0))); } else { // If low on energy, use primary to attempt to regen energy // Or if at desired energy level but not able/willing to ward, just attack - controller - .actions - .push(ControlAction::basic_input(InputKind::Primary)); + controller.push_action(ControlAction::basic_input(InputKind::Primary)); } } else if attack_data.dist_sqrd < (2.0 * attack_data.min_attack_dist).powi(2) { if self.body.map_or(false, |b| b.is_humanoid()) @@ -623,13 +555,9 @@ impl<'a> AgentData<'a> { { // Else roll away if can roll and have enough energy, and not using aura or in // recover - controller - .actions - .push(ControlAction::basic_input(InputKind::Roll)); + controller.push_action(ControlAction::basic_input(InputKind::Roll)); } else if attack_data.angle < 15.0 { - controller - .actions - .push(ControlAction::basic_input(InputKind::Primary)); + controller.push_action(ControlAction::basic_input(InputKind::Primary)); } } // Logic to move. Intentionally kept separate from ability logic where possible @@ -688,9 +616,7 @@ impl<'a> AgentData<'a> { && attack_data.dist_sqrd < 16.0f32.powi(2) && rng.gen::() < 0.01 { - controller - .actions - .push(ControlAction::basic_input(InputKind::Roll)); + controller.push_action(ControlAction::basic_input(InputKind::Roll)); } } else { // If too far, move towards target @@ -708,15 +634,11 @@ impl<'a> AgentData<'a> { ) { if attack_data.in_min_range() && attack_data.angle < 90.0 { controller.inputs.move_dir = Vec2::zero(); - controller - .actions - .push(ControlAction::basic_input(InputKind::Primary)); + controller.push_action(ControlAction::basic_input(InputKind::Primary)); //controller.inputs.primary.set_state(true); } else if attack_data.dist_sqrd < MAX_PATH_DIST.powi(2) { if self.vel.0.is_approx_zero() { - controller - .actions - .push(ControlAction::basic_input(InputKind::Ability(0))); + controller.push_action(ControlAction::basic_input(InputKind::Ability(0))); } if self.path_toward_target(agent, controller, tgt_data, read_data, true, false, None) && can_see_tgt( @@ -728,9 +650,7 @@ impl<'a> AgentData<'a> { && attack_data.angle < 90.0 { if agent.action_state.timer > 5.0 { - controller - .actions - .push(ControlAction::basic_input(InputKind::Secondary)); + controller.push_action(ControlAction::basic_input(InputKind::Secondary)); agent.action_state.timer = 0.0; } else { agent.action_state.timer += read_data.dt.0; @@ -755,9 +675,7 @@ impl<'a> AgentData<'a> { ) { if agent.action_state.counter >= circle_time as f32 { // if circle charge is in progress and time hasn't expired, continue charging - controller - .actions - .push(ControlAction::basic_input(InputKind::Secondary)); + controller.push_action(ControlAction::basic_input(InputKind::Secondary)); } if attack_data.in_min_range() { if agent.action_state.counter > 0.0 { @@ -766,9 +684,7 @@ impl<'a> AgentData<'a> { agent.action_state.int_counter = 0; } else { // melee attack - controller - .actions - .push(ControlAction::basic_input(InputKind::Primary)); + controller.push_action(ControlAction::basic_input(InputKind::Primary)); controller.inputs.move_dir = Vec2::zero(); } } else if attack_data.dist_sqrd < (radius as f32 + attack_data.min_attack_dist).powi(2) { @@ -846,9 +762,7 @@ impl<'a> AgentData<'a> { .xy() .try_normalized() .unwrap_or_else(Vec2::unit_y); - controller - .actions - .push(ControlAction::basic_input(InputKind::Primary)); + controller.push_action(ControlAction::basic_input(InputKind::Primary)); } else if attack_data.dist_sqrd < MAX_PATH_DIST.powi(2) { if let Some((bearing, speed)) = agent.chaser.chase( &*read_data.terrain, @@ -887,9 +801,7 @@ impl<'a> AgentData<'a> { * speed; agent.action_state.timer += read_data.dt.0; } - controller - .actions - .push(ControlAction::basic_input(InputKind::Secondary)); + controller.push_action(ControlAction::basic_input(InputKind::Secondary)); self.jump_if(controller, bearing.z > 1.5); controller.inputs.move_z = bearing.z; } else { @@ -918,19 +830,13 @@ impl<'a> AgentData<'a> { && attack_data.dist_sqrd < (1.5 * attack_data.min_attack_dist).powi(2) { if agent.action_state.timer > 4.0 { - controller - .actions - .push(ControlAction::CancelInput(InputKind::Primary)); + controller.push_action(ControlAction::CancelInput(InputKind::Primary)); agent.action_state.timer = 0.0; } else if agent.action_state.timer > 1.0 { - controller - .actions - .push(ControlAction::basic_input(InputKind::Primary)); + controller.push_action(ControlAction::basic_input(InputKind::Primary)); agent.action_state.timer += read_data.dt.0; } else { - controller - .actions - .push(ControlAction::basic_input(InputKind::Secondary)); + controller.push_action(ControlAction::basic_input(InputKind::Secondary)); agent.action_state.timer += read_data.dt.0; } controller.inputs.move_dir = (tgt_data.pos.0 - self.pos.0) @@ -957,16 +863,12 @@ impl<'a> AgentData<'a> { && attack_data.dist_sqrd < (1.5 * attack_data.min_attack_dist).powi(2) { controller.inputs.move_dir = Vec2::zero(); - controller - .actions - .push(ControlAction::basic_input(InputKind::Secondary)); + controller.push_action(ControlAction::basic_input(InputKind::Secondary)); } else if attack_data.dist_sqrd < (3.0 * attack_data.min_attack_dist).powi(2) && attack_data.dist_sqrd > (2.0 * attack_data.min_attack_dist).powi(2) && attack_data.angle < 90.0 { - controller - .actions - .push(ControlAction::basic_input(InputKind::Primary)); + controller.push_action(ControlAction::basic_input(InputKind::Primary)); controller.inputs.move_dir = (tgt_data.pos.0 - self.pos.0) .xy() .rotated_z(-0.47 * PI) @@ -994,14 +896,10 @@ impl<'a> AgentData<'a> { if agent.action_state.timer > 5.0 { agent.action_state.timer = 0.0; } else if agent.action_state.timer > 2.0 { - controller - .actions - .push(ControlAction::basic_input(InputKind::Secondary)); + controller.push_action(ControlAction::basic_input(InputKind::Secondary)); agent.action_state.timer += read_data.dt.0; } else { - controller - .actions - .push(ControlAction::basic_input(InputKind::Primary)); + controller.push_action(ControlAction::basic_input(InputKind::Primary)); agent.action_state.timer += read_data.dt.0; } } else if attack_data.dist_sqrd < MAX_PATH_DIST.powi(2) { @@ -1023,15 +921,11 @@ impl<'a> AgentData<'a> { && attack_data.dist_sqrd < (1.5 * attack_data.min_attack_dist).powi(2) { controller.inputs.move_dir = Vec2::zero(); - controller - .actions - .push(ControlAction::basic_input(InputKind::Secondary)); + controller.push_action(ControlAction::basic_input(InputKind::Secondary)); } else if attack_data.angle < 15.0 && attack_data.dist_sqrd < (5.0 * attack_data.min_attack_dist).powi(2) { - controller - .actions - .push(ControlAction::basic_input(InputKind::Ability(0))); + controller.push_action(ControlAction::basic_input(InputKind::Ability(0))); } else if attack_data.dist_sqrd < MAX_PATH_DIST.powi(2) { if self.path_toward_target(agent, controller, tgt_data, read_data, true, false, None) && attack_data.angle < 15.0 @@ -1042,9 +936,7 @@ impl<'a> AgentData<'a> { attack_data.dist_sqrd, ) { - controller - .actions - .push(ControlAction::basic_input(InputKind::Primary)); + controller.push_action(ControlAction::basic_input(InputKind::Primary)); } } else { self.path_toward_target(agent, controller, tgt_data, read_data, false, false, None); @@ -1062,14 +954,10 @@ impl<'a> AgentData<'a> { if attack_data.angle < 90.0 && attack_data.in_min_range() { controller.inputs.move_dir = Vec2::zero(); if agent.action_state.timer < 2.0 { - controller - .actions - .push(ControlAction::basic_input(InputKind::Secondary)); + controller.push_action(ControlAction::basic_input(InputKind::Secondary)); agent.action_state.timer += read_data.dt.0; } else if agent.action_state.timer < 3.0 { - controller - .actions - .push(ControlAction::basic_input(InputKind::Primary)); + controller.push_action(ControlAction::basic_input(InputKind::Primary)); agent.action_state.timer += read_data.dt.0; } else { agent.action_state.timer = 0.0; @@ -1093,9 +981,7 @@ impl<'a> AgentData<'a> { && attack_data.dist_sqrd < (2.5 * attack_data.min_attack_dist).powi(2) { controller.inputs.move_dir = Vec2::zero(); - controller - .actions - .push(ControlAction::basic_input(InputKind::Secondary)); + controller.push_action(ControlAction::basic_input(InputKind::Secondary)); } else if attack_data.dist_sqrd < (7.0 * attack_data.min_attack_dist).powi(2) && attack_data.angle < 15.0 { @@ -1105,9 +991,7 @@ impl<'a> AgentData<'a> { .rotated_z(0.47 * PI) .try_normalized() .unwrap_or_else(Vec2::unit_y); - controller - .actions - .push(ControlAction::basic_input(InputKind::Primary)); + controller.push_action(ControlAction::basic_input(InputKind::Primary)); agent.action_state.timer += read_data.dt.0; } else if agent.action_state.timer < 4.0 && attack_data.angle < 15.0 { controller.inputs.move_dir = (tgt_data.pos.0 - self.pos.0) @@ -1115,14 +999,10 @@ impl<'a> AgentData<'a> { .rotated_z(-0.47 * PI) .try_normalized() .unwrap_or_else(Vec2::unit_y); - controller - .actions - .push(ControlAction::basic_input(InputKind::Primary)); + controller.push_action(ControlAction::basic_input(InputKind::Primary)); agent.action_state.timer += read_data.dt.0; } else if agent.action_state.timer < 6.0 && attack_data.angle < 15.0 { - controller - .actions - .push(ControlAction::basic_input(InputKind::Ability(0))); + controller.push_action(ControlAction::basic_input(InputKind::Ability(0))); agent.action_state.timer += read_data.dt.0; } else { agent.action_state.timer = 0.0; @@ -1144,9 +1024,7 @@ impl<'a> AgentData<'a> { ) { if attack_data.angle < 90.0 && attack_data.in_min_range() { controller.inputs.move_dir = Vec2::zero(); - controller - .actions - .push(ControlAction::basic_input(InputKind::Primary)); + controller.push_action(ControlAction::basic_input(InputKind::Primary)); } else if attack_data.dist_sqrd < MAX_PATH_DIST.powi(2) { self.path_toward_target(agent, controller, tgt_data, read_data, true, false, None); } else { @@ -1169,9 +1047,7 @@ impl<'a> AgentData<'a> { attack_data.dist_sqrd, ) && attack_data.angle < 15.0 { - controller - .actions - .push(ControlAction::basic_input(InputKind::Primary)); + controller.push_action(ControlAction::basic_input(InputKind::Primary)); } else { agent.target = None; } @@ -1193,9 +1069,7 @@ impl<'a> AgentData<'a> { attack_data.dist_sqrd, ) && attack_data.angle < 15.0 { - controller - .actions - .push(ControlAction::basic_input(InputKind::Primary)); + controller.push_action(ControlAction::basic_input(InputKind::Primary)); } else { agent.target = None; } @@ -1222,9 +1096,7 @@ impl<'a> AgentData<'a> { tgt_data.pos, attack_data.dist_sqrd, ) { - controller - .actions - .push(ControlAction::basic_input(InputKind::Primary)); + controller.push_action(ControlAction::basic_input(InputKind::Primary)); } else { agent.target = None; } @@ -1244,16 +1116,12 @@ impl<'a> AgentData<'a> { tgt_data.pos, attack_data.dist_sqrd, ) { - controller - .actions - .push(ControlAction::basic_input(InputKind::Primary)); + controller.push_action(ControlAction::basic_input(InputKind::Primary)); } } pub fn handle_tornado_attack(&self, controller: &mut Controller) { - controller - .actions - .push(ControlAction::basic_input(InputKind::Primary)); + controller.push_action(ControlAction::basic_input(InputKind::Primary)); } pub fn handle_mindflayer_attack( @@ -1277,9 +1145,7 @@ impl<'a> AgentData<'a> { if agent.action_state.counter > health_fraction { // Summon minions at particular thresholds of health - controller - .actions - .push(ControlAction::basic_input(InputKind::Ability(2))); + controller.push_action(ControlAction::basic_input(InputKind::Ability(2))); if matches!(self.char_state, CharacterState::BasicSummon(c) if matches!(c.stage_section, StageSection::Recover)) { @@ -1296,26 +1162,18 @@ impl<'a> AgentData<'a> { if matches!(self.char_state, CharacterState::BasicBeam(c) if c.timer < Duration::from_secs(10) && !matches!(c.stage_section, StageSection::Recover)) { // If already using primary, keep using primary until 10 consecutive seconds - controller - .actions - .push(ControlAction::basic_input(InputKind::Primary)); + controller.push_action(ControlAction::basic_input(InputKind::Primary)); } else if matches!(self.char_state, CharacterState::SpinMelee(c) if c.consecutive_spins < 50 && !matches!(c.stage_section, StageSection::Recover)) { // If already using secondary, keep using secondary until 10 consecutive // seconds - controller - .actions - .push(ControlAction::basic_input(InputKind::Secondary)); + controller.push_action(ControlAction::basic_input(InputKind::Secondary)); } else if rng.gen_bool(health_fraction.into()) { // Else if at high health, use primary - controller - .actions - .push(ControlAction::basic_input(InputKind::Primary)); + controller.push_action(ControlAction::basic_input(InputKind::Primary)); } else { // Else use secondary - controller - .actions - .push(ControlAction::basic_input(InputKind::Secondary)); + controller.push_action(ControlAction::basic_input(InputKind::Secondary)); } } else { self.path_toward_target(agent, controller, tgt_data, read_data, true, false, None); @@ -1325,7 +1183,7 @@ impl<'a> AgentData<'a> { // then blink to them. let num_fireballs = &mut agent.action_state.int_counter; if *num_fireballs == 0 { - controller.actions.push(ControlAction::StartInput { + controller.push_action(ControlAction::StartInput { input: InputKind::Ability(0), target_entity: agent .target @@ -1339,7 +1197,7 @@ impl<'a> AgentData<'a> { } } else if matches!(self.char_state, CharacterState::Wielding(_)) { *num_fireballs -= 1; - controller.actions.push(ControlAction::StartInput { + controller.push_action(ControlAction::StartInput { input: InputKind::Ability(1), target_entity: agent .target @@ -1377,9 +1235,7 @@ impl<'a> AgentData<'a> { && attack_data.angle < 15.0 { // Fireball - controller - .actions - .push(ControlAction::basic_input(InputKind::Primary)); + controller.push_action(ControlAction::basic_input(InputKind::Primary)); } // If some target if let Some((bearing, speed)) = agent.chaser.chase( @@ -1398,9 +1254,7 @@ impl<'a> AgentData<'a> { // If less than 20 blocks higher than target if (self.pos.0.z - tgt_data.pos.0.z) < 20.0 { // Fly upward - controller - .actions - .push(ControlAction::basic_input(InputKind::Fly)); + controller.push_action(ControlAction::basic_input(InputKind::Fly)); controller.inputs.move_z = 1.0; } else { // Jump @@ -1422,9 +1276,7 @@ impl<'a> AgentData<'a> { // The next stage shouldn't trigger until the entity // is on the ground // Fly to target - controller - .actions - .push(ControlAction::basic_input(InputKind::Fly)); + controller.push_action(ControlAction::basic_input(InputKind::Fly)); let move_dir = tgt_data.pos.0 - self.pos.0; controller.inputs.move_dir = move_dir.xy().try_normalized().unwrap_or_else(Vec2::zero) * 2.0; @@ -1435,9 +1287,7 @@ impl<'a> AgentData<'a> { && attack_data.angle < 15.0 { // Fireball - controller - .actions - .push(ControlAction::basic_input(InputKind::Primary)); + controller.push_action(ControlAction::basic_input(InputKind::Primary)); } } // If further than 4 blocks and random chance @@ -1446,9 +1296,7 @@ impl<'a> AgentData<'a> { && attack_data.angle < 15.0 { // Fireball - controller - .actions - .push(ControlAction::basic_input(InputKind::Primary)); + controller.push_action(ControlAction::basic_input(InputKind::Primary)); } // If random chance and less than 20 blocks higher than target and further than 4 // blocks @@ -1456,9 +1304,7 @@ impl<'a> AgentData<'a> { && (self.pos.0.z - tgt_data.pos.0.z) < 15.0 && attack_data.dist_sqrd > (4.0 * attack_data.min_attack_dist).powi(2) { - controller - .actions - .push(ControlAction::basic_input(InputKind::Fly)); + controller.push_action(ControlAction::basic_input(InputKind::Fly)); controller.inputs.move_z = 1.0; } // If further than 2.5 blocks and random chance @@ -1469,14 +1315,10 @@ impl<'a> AgentData<'a> { // If energy higher than 600 and random chance else if self.energy.current() > 60.0 && rng.gen_bool(0.4) { // Shockwave - controller - .actions - .push(ControlAction::basic_input(InputKind::Ability(0))); + controller.push_action(ControlAction::basic_input(InputKind::Ability(0))); } else if attack_data.angle < 90.0 { // Triple strike - controller - .actions - .push(ControlAction::basic_input(InputKind::Secondary)); + controller.push_action(ControlAction::basic_input(InputKind::Secondary)); } else { // Target is behind us. Turn around and chase target self.path_toward_target(agent, controller, tgt_data, read_data, true, false, None); @@ -1493,9 +1335,7 @@ impl<'a> AgentData<'a> { rng: &mut impl Rng, ) { // Set fly to false - controller - .actions - .push(ControlAction::CancelInput(InputKind::Fly)); + controller.push_action(ControlAction::CancelInput(InputKind::Fly)); if attack_data.dist_sqrd > 30.0_f32.powi(2) { if rng.gen_bool(0.05) && can_see_tgt( @@ -1506,9 +1346,7 @@ impl<'a> AgentData<'a> { ) && attack_data.angle < 15.0 { - controller - .actions - .push(ControlAction::basic_input(InputKind::Primary)); + controller.push_action(ControlAction::basic_input(InputKind::Primary)); } if let Some((bearing, speed)) = agent.chaser.chase( &*read_data.terrain, @@ -1523,9 +1361,7 @@ impl<'a> AgentData<'a> { controller.inputs.move_dir = bearing.xy().try_normalized().unwrap_or_else(Vec2::zero) * speed; if (self.pos.0.z - tgt_data.pos.0.z) < 20.0 { - controller - .actions - .push(ControlAction::basic_input(InputKind::Fly)); + controller.push_action(ControlAction::basic_input(InputKind::Fly)); controller.inputs.move_z = 1.0; } else { self.jump_if(controller, bearing.z > 1.5); @@ -1543,9 +1379,7 @@ impl<'a> AgentData<'a> { // Do not increment the timer during this movement // The next stage shouldn't trigger until the entity // is on the ground - controller - .actions - .push(ControlAction::basic_input(InputKind::Fly)); + controller.push_action(ControlAction::basic_input(InputKind::Fly)); let move_dir = tgt_data.pos.0 - self.pos.0; controller.inputs.move_dir = move_dir.xy().try_normalized().unwrap_or_else(Vec2::zero) * 2.0; @@ -1554,24 +1388,18 @@ impl<'a> AgentData<'a> { && attack_data.dist_sqrd > (4.0 * attack_data.min_attack_dist).powi(2) && attack_data.angle < 15.0 { - controller - .actions - .push(ControlAction::basic_input(InputKind::Primary)); + controller.push_action(ControlAction::basic_input(InputKind::Primary)); } } else if rng.gen_bool(0.05) && attack_data.dist_sqrd > (4.0 * attack_data.min_attack_dist).powi(2) && attack_data.angle < 15.0 { - controller - .actions - .push(ControlAction::basic_input(InputKind::Primary)); + controller.push_action(ControlAction::basic_input(InputKind::Primary)); } else if rng.gen_bool(0.5) && (self.pos.0.z - tgt_data.pos.0.z) < 15.0 && attack_data.dist_sqrd > (4.0 * attack_data.min_attack_dist).powi(2) { - controller - .actions - .push(ControlAction::basic_input(InputKind::Fly)); + controller.push_action(ControlAction::basic_input(InputKind::Fly)); controller.inputs.move_z = 1.0; } else if attack_data.dist_sqrd > (3.0 * attack_data.min_attack_dist).powi(2) { self.path_toward_target(agent, controller, tgt_data, read_data, true, false, None); @@ -1580,9 +1408,7 @@ impl<'a> AgentData<'a> { && attack_data.angle < 15.0 { // Fire breath attack - controller - .actions - .push(ControlAction::basic_input(InputKind::Ability(0))); + controller.push_action(ControlAction::basic_input(InputKind::Ability(0))); // Move towards the target slowly self.path_toward_target( agent, @@ -1599,9 +1425,7 @@ impl<'a> AgentData<'a> { && attack_data.in_min_range() { // Triplestrike - controller - .actions - .push(ControlAction::basic_input(InputKind::Secondary)); + controller.push_action(ControlAction::basic_input(InputKind::Secondary)); agent.action_state.timer += read_data.dt.0; } else { // Reset timer @@ -1634,18 +1458,14 @@ impl<'a> AgentData<'a> { .map_or(true, |b| b.is_some()) { // Fly to target and land - controller - .actions - .push(ControlAction::basic_input(InputKind::Fly)); + controller.push_action(ControlAction::basic_input(InputKind::Fly)); let move_dir = tgt_data.pos.0 - self.pos.0; controller.inputs.move_dir = move_dir.xy().try_normalized().unwrap_or_else(Vec2::zero) * 2.0; controller.inputs.move_z = move_dir.z - 0.5; } else if agent.action_state.timer > 8.0 { // If action timer higher than 8, make bird summon tornadoes - controller - .actions - .push(ControlAction::basic_input(InputKind::Secondary)); + controller.push_action(ControlAction::basic_input(InputKind::Secondary)); if matches!(self.char_state, CharacterState::BasicSummon(c) if matches!(c.stage_section, StageSection::Recover)) { // Reset timer @@ -1654,27 +1474,19 @@ impl<'a> AgentData<'a> { } else if matches!(self.char_state, CharacterState::DashMelee(c) if !matches!(c.stage_section, StageSection::Recover)) { // If already in dash, keep dashing if not in recover - controller - .actions - .push(ControlAction::basic_input(InputKind::Ability(0))); + controller.push_action(ControlAction::basic_input(InputKind::Ability(0))); } else if matches!(self.char_state, CharacterState::ComboMelee(c) if matches!(c.stage_section, StageSection::Recover)) { // If already in combo keep comboing if not in recover - controller - .actions - .push(ControlAction::basic_input(InputKind::Primary)); + controller.push_action(ControlAction::basic_input(InputKind::Primary)); } else if attack_data.dist_sqrd > BIRD_CHARGE_DISTANCE.powi(2) { // Charges at target if they are far enough away if attack_data.angle < 60.0 { - controller - .actions - .push(ControlAction::basic_input(InputKind::Ability(0))); + controller.push_action(ControlAction::basic_input(InputKind::Ability(0))); } } else if attack_data.dist_sqrd < bird_attack_distance.powi(2) { // Combo melee target - controller - .actions - .push(ControlAction::basic_input(InputKind::Primary)); + controller.push_action(ControlAction::basic_input(InputKind::Primary)); agent.action_state.condition = true; } // Make bird move towards target @@ -1694,9 +1506,7 @@ impl<'a> AgentData<'a> { && attack_data.dist_sqrd < (2.0 * attack_data.min_attack_dist).powi(2) { controller.inputs.move_dir = Vec2::zero(); - controller - .actions - .push(ControlAction::basic_input(InputKind::Secondary)); + controller.push_action(ControlAction::basic_input(InputKind::Secondary)); // Reset timer if matches!(self.char_state, CharacterState::SpriteSummon(c) if matches!(c.stage_section, StageSection::Recover)) { @@ -1706,9 +1516,7 @@ impl<'a> AgentData<'a> { && attack_data.dist_sqrd < (1.5 * attack_data.min_attack_dist).powi(2) { controller.inputs.move_dir = Vec2::zero(); - controller - .actions - .push(ControlAction::basic_input(InputKind::Primary)); + controller.push_action(ControlAction::basic_input(InputKind::Primary)); } else { self.path_toward_target(agent, controller, tgt_data, read_data, false, false, None); } @@ -1727,9 +1535,7 @@ impl<'a> AgentData<'a> { && attack_data.dist_sqrd < (2.0 * attack_data.min_attack_dist).powi(2) { controller.inputs.move_dir = Vec2::zero(); - controller - .actions - .push(ControlAction::basic_input(InputKind::Secondary)); + controller.push_action(ControlAction::basic_input(InputKind::Secondary)); // Reset timer if matches!(self.char_state, CharacterState::SpriteSummon(c) if matches!(c.stage_section, StageSection::Recover)) { @@ -1742,9 +1548,7 @@ impl<'a> AgentData<'a> { .xy() .try_normalized() .unwrap_or_else(Vec2::unit_y); - controller - .actions - .push(ControlAction::basic_input(InputKind::Primary)); + controller.push_action(ControlAction::basic_input(InputKind::Primary)); } else if attack_data.dist_sqrd < MAX_PATH_DIST.powi(2) { if let Some((bearing, speed)) = agent.chaser.chase( &*read_data.terrain, @@ -1783,9 +1587,7 @@ impl<'a> AgentData<'a> { * speed; agent.action_state.timer += read_data.dt.0; } - controller - .actions - .push(ControlAction::basic_input(InputKind::Ability(0))); + controller.push_action(ControlAction::basic_input(InputKind::Ability(0))); self.jump_if(controller, bearing.z > 1.5); controller.inputs.move_z = bearing.z; } else { @@ -1816,9 +1618,7 @@ impl<'a> AgentData<'a> { && attack_data.dist_sqrd < (1.5 * attack_data.min_attack_dist).powi(2) { controller.inputs.move_dir = Vec2::zero(); - controller - .actions - .push(ControlAction::basic_input(InputKind::Secondary)); + controller.push_action(ControlAction::basic_input(InputKind::Secondary)); // Reset timer if matches!(self.char_state, CharacterState::SpriteSummon(c) if matches!(c.stage_section, StageSection::Recover)) { @@ -1828,16 +1628,12 @@ impl<'a> AgentData<'a> { && attack_data.dist_sqrd < (1.5 * attack_data.min_attack_dist).powi(2) { controller.inputs.move_dir = Vec2::zero(); - controller - .actions - .push(ControlAction::basic_input(InputKind::Primary)); + controller.push_action(ControlAction::basic_input(InputKind::Primary)); } else if rng.gen_bool(0.01) && attack_data.angle < 15.0 && attack_data.dist_sqrd < (6.0 * attack_data.min_attack_dist).powi(2) { - controller - .actions - .push(ControlAction::basic_input(InputKind::Ability(0))); + controller.push_action(ControlAction::basic_input(InputKind::Ability(0))); } else { self.path_toward_target(agent, controller, tgt_data, read_data, false, false, None); } @@ -1855,23 +1651,17 @@ impl<'a> AgentData<'a> { if matches!(self.char_state, CharacterState::DashMelee(c) if !matches!(c.stage_section, StageSection::Recover)) { // If already charging, keep charging if not in recover - controller - .actions - .push(ControlAction::basic_input(InputKind::Secondary)); + controller.push_action(ControlAction::basic_input(InputKind::Secondary)); } else if attack_data.dist_sqrd > (5.0 * attack_data.min_attack_dist).powi(2) { // Charges at target if they are far enough away if attack_data.angle < 60.0 { - controller - .actions - .push(ControlAction::basic_input(InputKind::Secondary)); + controller.push_action(ControlAction::basic_input(InputKind::Secondary)); } } else if attack_data.angle < 90.0 && attack_data.dist_sqrd < (1.5 * attack_data.min_attack_dist).powi(2) { controller.inputs.move_dir = Vec2::zero(); - controller - .actions - .push(ControlAction::basic_input(InputKind::Primary)); + controller.push_action(ControlAction::basic_input(InputKind::Primary)); } else { self.path_toward_target(agent, controller, tgt_data, read_data, false, false, None); } @@ -1899,9 +1689,7 @@ impl<'a> AgentData<'a> { } if health_fraction < agent.action_state.counter { // Makes minotaur buff itself with frenzy - controller - .actions - .push(ControlAction::basic_input(InputKind::Ability(1))); + controller.push_action(ControlAction::basic_input(InputKind::Ability(1))); if matches!(self.char_state, CharacterState::SelfBuff(c) if matches!(c.stage_section, StageSection::Recover)) { agent.action_state.counter = 0.0; @@ -1909,34 +1697,24 @@ impl<'a> AgentData<'a> { } else if matches!(self.char_state, CharacterState::DashMelee(c) if !matches!(c.stage_section, StageSection::Recover)) { // If already charging, keep charging if not in recover - controller - .actions - .push(ControlAction::basic_input(InputKind::Ability(0))); + controller.push_action(ControlAction::basic_input(InputKind::Ability(0))); } else if matches!(self.char_state, CharacterState::ChargedMelee(c) if matches!(c.stage_section, StageSection::Charge) && c.timer < c.static_data.charge_duration) { // If already charging a melee attack, keep charging it if charging - controller - .actions - .push(ControlAction::basic_input(InputKind::Primary)); + controller.push_action(ControlAction::basic_input(InputKind::Primary)); } else if attack_data.dist_sqrd > MINOTAUR_CHARGE_DISTANCE.powi(2) { // Charges at target if they are far enough away if attack_data.angle < 60.0 { - controller - .actions - .push(ControlAction::basic_input(InputKind::Ability(0))); + controller.push_action(ControlAction::basic_input(InputKind::Ability(0))); } } else if attack_data.dist_sqrd < minotaur_attack_distance.powi(2) { if agent.action_state.condition && !self.char_state.is_attack() { // Cripple target if not just used cripple - controller - .actions - .push(ControlAction::basic_input(InputKind::Secondary)); + controller.push_action(ControlAction::basic_input(InputKind::Secondary)); agent.action_state.condition = false; } else if !self.char_state.is_attack() { // Cleave target if not just used cleave - controller - .actions - .push(ControlAction::basic_input(InputKind::Primary)); + controller.push_action(ControlAction::basic_input(InputKind::Primary)); agent.action_state.condition = true; } } @@ -1970,15 +1748,11 @@ impl<'a> AgentData<'a> { if attack_data.dist_sqrd < golem_melee_range.powi(2) { if agent.action_state.counter < 7.5 { // If target is close, whack them - controller - .actions - .push(ControlAction::basic_input(InputKind::Primary)); + controller.push_action(ControlAction::basic_input(InputKind::Primary)); agent.action_state.counter += read_data.dt.0; } else { // If whacked for too long, nuke them - controller - .actions - .push(ControlAction::basic_input(InputKind::Ability(1))); + controller.push_action(ControlAction::basic_input(InputKind::Ability(1))); if matches!(self.char_state, CharacterState::BasicRanged(c) if matches!(c.stage_section, StageSection::Recover)) { agent.action_state.counter = 0.0; @@ -1997,15 +1771,11 @@ impl<'a> AgentData<'a> { { // If target in range threshold and haven't been lasering for more than 5 // seconds already or if target is moving slow-ish, laser them - controller - .actions - .push(ControlAction::basic_input(InputKind::Secondary)); + controller.push_action(ControlAction::basic_input(InputKind::Secondary)); } else if health_fraction < 0.7 { // Else target moving too fast for laser, shockwave time. // But only if damaged enough - controller - .actions - .push(ControlAction::basic_input(InputKind::Ability(0))); + controller.push_action(ControlAction::basic_input(InputKind::Ability(0))); } } else if attack_data.dist_sqrd < GOLEM_LONG_RANGE.powi(2) { if target_speed_cross_sqd < GOLEM_TARGET_SPEED.powi(2) @@ -2017,15 +1787,11 @@ impl<'a> AgentData<'a> { ) { // If target is far-ish and moving slow-ish, rocket them - controller - .actions - .push(ControlAction::basic_input(InputKind::Ability(1))); + controller.push_action(ControlAction::basic_input(InputKind::Ability(1))); } else if health_fraction < 0.7 { // Else target moving too fast for laser, shockwave time. // But only if damaged enough - controller - .actions - .push(ControlAction::basic_input(InputKind::Ability(0))); + controller.push_action(ControlAction::basic_input(InputKind::Ability(0))); } } // Make clay golem move towards target @@ -2053,9 +1819,7 @@ impl<'a> AgentData<'a> { if agent.action_state.counter > health_fraction { // Summon minions at particular thresholds of health - controller - .actions - .push(ControlAction::basic_input(InputKind::Ability(1))); + controller.push_action(ControlAction::basic_input(InputKind::Ability(1))); if matches!(self.char_state, CharacterState::BasicSummon(c) if matches!(c.stage_section, StageSection::Recover)) { @@ -2065,22 +1829,16 @@ impl<'a> AgentData<'a> { if matches!(self.char_state, CharacterState::DashMelee(c) if !matches!(c.stage_section, StageSection::Recover)) { // Keep scuttling if already in dash melee and not in recover - controller - .actions - .push(ControlAction::basic_input(InputKind::Secondary)); + controller.push_action(ControlAction::basic_input(InputKind::Secondary)); } else if attack_data.dist_sqrd < BUBBLE_RANGE.powi(2) { if matches!(self.char_state, CharacterState::BasicBeam(c) if !matches!(c.stage_section, StageSection::Recover) && c.timer < Duration::from_secs(10)) { // Keep shooting bubbles at them if already in basic beam and not in recover and // have not been bubbling too long - controller - .actions - .push(ControlAction::basic_input(InputKind::Ability(0))); + controller.push_action(ControlAction::basic_input(InputKind::Ability(0))); } else if attack_data.in_min_range() && attack_data.angle < 60.0 { // Pincer them if they're in range and angle - controller - .actions - .push(ControlAction::basic_input(InputKind::Primary)); + controller.push_action(ControlAction::basic_input(InputKind::Primary)); } else if attack_data.angle < 30.0 && can_see_tgt( &*read_data.terrain, @@ -2091,9 +1849,7 @@ impl<'a> AgentData<'a> { { // Start bubbling them if not close enough to do something else and in angle and // can see target - controller - .actions - .push(ControlAction::basic_input(InputKind::Ability(0))); + controller.push_action(ControlAction::basic_input(InputKind::Ability(0))); } } else if attack_data.angle < 90.0 && can_see_tgt( @@ -2105,9 +1861,7 @@ impl<'a> AgentData<'a> { { // Start scuttling if not close enough to do something else and in angle and can // see target - controller - .actions - .push(ControlAction::basic_input(InputKind::Secondary)); + controller.push_action(ControlAction::basic_input(InputKind::Secondary)); } } // Always attempt to path towards target @@ -2133,14 +1887,10 @@ impl<'a> AgentData<'a> { if matches!(self.char_state, CharacterState::BasicBeam(c) if c.timer < Duration::from_secs(2)) { // Keep using ice breath for 2 second - controller - .actions - .push(ControlAction::basic_input(InputKind::Ability(0))); + controller.push_action(ControlAction::basic_input(InputKind::Ability(0))); } else if agent.action_state.counter > ICE_BREATH_TIMER { // Use ice breath if timer has gone for long enough - controller - .actions - .push(ControlAction::basic_input(InputKind::Ability(0))); + controller.push_action(ControlAction::basic_input(InputKind::Ability(0))); if matches!(self.char_state, CharacterState::BasicBeam(_)) { // Resets action counter when using beam @@ -2148,25 +1898,17 @@ impl<'a> AgentData<'a> { } } else if attack_data.in_min_range() { // Basic attack if on top of them - controller - .actions - .push(ControlAction::basic_input(InputKind::Primary)); + controller.push_action(ControlAction::basic_input(InputKind::Primary)); } else { // Use ice spikes if too far for other abilities - controller - .actions - .push(ControlAction::basic_input(InputKind::Secondary)); + controller.push_action(ControlAction::basic_input(InputKind::Secondary)); } } else if attack_data.dist_sqrd < ICE_SPIKES_RANGE.powi(2) && attack_data.angle < 60.0 { // Use ice spikes if in range - controller - .actions - .push(ControlAction::basic_input(InputKind::Secondary)); + controller.push_action(ControlAction::basic_input(InputKind::Secondary)); } else if attack_data.dist_sqrd < SNOWBALL_MAX_RANGE.powi(2) && attack_data.angle < 60.0 { // Otherwise, chuck all the snowballs - controller - .actions - .push(ControlAction::basic_input(InputKind::Ability(1))); + controller.push_action(ControlAction::basic_input(InputKind::Ability(1))); } // Always attempt to path towards target @@ -2188,9 +1930,7 @@ impl<'a> AgentData<'a> { if health_fraction < VINE_CREATION_THRESHOLD && !agent.action_state.condition { // Summon vines when reach threshold of health - controller - .actions - .push(ControlAction::basic_input(InputKind::Ability(0))); + controller.push_action(ControlAction::basic_input(InputKind::Ability(0))); if matches!(self.char_state, CharacterState::SpriteSummon(c) if matches!(c.stage_section, StageSection::Recover)) { @@ -2207,14 +1947,10 @@ impl<'a> AgentData<'a> { { // Keep breathing fire if close enough, can see target, and have not been // breathing for more than 5 seconds - controller - .actions - .push(ControlAction::basic_input(InputKind::Secondary)); + controller.push_action(ControlAction::basic_input(InputKind::Secondary)); } else if attack_data.in_min_range() && attack_data.angle < 60.0 { // Scythe them if they're in range and angle - controller - .actions - .push(ControlAction::basic_input(InputKind::Primary)); + controller.push_action(ControlAction::basic_input(InputKind::Primary)); } else if attack_data.angle < 30.0 && can_see_tgt( &*read_data.terrain, @@ -2224,9 +1960,7 @@ impl<'a> AgentData<'a> { ) { // Start breathing fire at them if close enough, in angle, and can see target - controller - .actions - .push(ControlAction::basic_input(InputKind::Secondary)); + controller.push_action(ControlAction::basic_input(InputKind::Secondary)); } } else if attack_data.dist_sqrd < MAX_PUMPKIN_RANGE.powi(2) && can_see_tgt( @@ -2237,9 +1971,7 @@ impl<'a> AgentData<'a> { ) { // Throw a pumpkin at them if close enough and can see them - controller - .actions - .push(ControlAction::basic_input(InputKind::Ability(1))); + controller.push_action(ControlAction::basic_input(InputKind::Ability(1))); } // Always attempt to path towards target self.path_toward_target(agent, controller, tgt_data, read_data, false, false, None); diff --git a/server/src/sys/msg/in_game.rs b/server/src/sys/msg/in_game.rs index 72989a7f45..1cfde3744c 100644 --- a/server/src/sys/msg/in_game.rs +++ b/server/src/sys/msg/in_game.rs @@ -107,7 +107,7 @@ impl Sys { ClientGeneral::ControlAction(event) => { if matches!(presence.kind, PresenceKind::Character(_)) { if let Some(controller) = controllers.get_mut(entity) { - controller.actions.push(event); + controller.push_action(event); } } }, From b2b208687c8622d627ce619d3661359daa64c0d7 Mon Sep 17 00:00:00 2001 From: "Dr. Dystopia" Date: Wed, 26 Jan 2022 20:09:59 +0100 Subject: [PATCH 3/8] Create 'push_basic_input' function --- common/src/comp/controller.rs | 4 + server/src/sys/agent.rs | 8 +- server/src/sys/agent/attack.rs | 260 ++++++++++++++++----------------- 3 files changed, 138 insertions(+), 134 deletions(-) diff --git a/common/src/comp/controller.rs b/common/src/comp/controller.rs index 473210c05a..3c440f0cec 100644 --- a/common/src/comp/controller.rs +++ b/common/src/comp/controller.rs @@ -281,6 +281,10 @@ impl Controller { pub fn push_event(&mut self, event: ControlEvent) { self.events.push(event); } pub fn push_action(&mut self, action: ControlAction) { self.actions.push(action); } + + pub fn push_basic_input(&mut self, input: InputKind) { + self.push_action(ControlAction::basic_input(input)); + } } impl Component for Controller { diff --git a/server/src/sys/agent.rs b/server/src/sys/agent.rs index 0e0c138a3e..2df62b0e84 100644 --- a/server/src/sys/agent.rs +++ b/server/src/sys/agent.rs @@ -208,7 +208,7 @@ impl<'a> System<'a> for Sys { // // TODO: look into `controller.reset()` line above // and see if it fixes it - controller.push_action(ControlAction::basic_input(InputKind::Fly)); + controller.push_basic_input(InputKind::Fly); } // Package all this agent's data into a convenient struct @@ -682,7 +682,7 @@ impl<'a> AgentData<'a> { } fn fly_upward(&self, controller: &mut Controller) { - controller.push_action(ControlAction::basic_input(InputKind::Fly)); + controller.push_basic_input(InputKind::Fly); controller.inputs.move_z = 1.0; } @@ -737,7 +737,7 @@ impl<'a> AgentData<'a> { .1 .map_or(true, |b| b.is_some()) { - controller.push_action(ControlAction::basic_input(InputKind::Fly)); + controller.push_basic_input(InputKind::Fly); } else { controller.push_action(ControlAction::CancelInput(InputKind::Fly)) } @@ -2274,7 +2274,7 @@ impl<'a> AgentData<'a> { fn jump_if(&self, controller: &mut Controller, condition: bool) { if condition { - controller.push_action(ControlAction::basic_input(InputKind::Jump)); + controller.push_basic_input(InputKind::Jump); } else { controller.push_action(ControlAction::CancelInput(InputKind::Jump)) } diff --git a/server/src/sys/agent/attack.rs b/server/src/sys/agent/attack.rs index 3459584917..bc20b9670b 100644 --- a/server/src/sys/agent/attack.rs +++ b/server/src/sys/agent/attack.rs @@ -29,7 +29,7 @@ impl<'a> AgentData<'a> { rng: &mut impl Rng, ) { if attack_data.in_min_range() && attack_data.angle < 45.0 { - controller.push_action(ControlAction::basic_input(InputKind::Primary)); + controller.push_basic_input(InputKind::Primary); controller.inputs.move_dir = Vec2::zero(); } else if attack_data.dist_sqrd < MAX_PATH_DIST.powi(2) { self.path_toward_target(agent, controller, tgt_data, read_data, true, true, None); @@ -38,7 +38,7 @@ impl<'a> AgentData<'a> { && attack_data.dist_sqrd < 16.0f32.powi(2) && rng.gen::() < 0.02 { - controller.push_action(ControlAction::basic_input(InputKind::Roll)); + controller.push_basic_input(InputKind::Roll); } } else { self.path_toward_target(agent, controller, tgt_data, read_data, false, true, None); @@ -59,7 +59,7 @@ impl<'a> AgentData<'a> { let has_energy = |need| self.energy.current() > need; let use_leap = |controller: &mut Controller| { - controller.push_action(ControlAction::basic_input(InputKind::Ability(0))); + controller.push_basic_input(InputKind::Ability(0)); }; if attack_data.in_min_range() && attack_data.angle < 45.0 { controller.inputs.move_dir = Vec2::zero(); @@ -67,13 +67,13 @@ impl<'a> AgentData<'a> { controller.push_action(ControlAction::CancelInput(InputKind::Secondary)); agent.action_state.timer = 0.0; } else if agent.action_state.timer > 2.5 && has_energy(10.0) { - controller.push_action(ControlAction::basic_input(InputKind::Secondary)); + controller.push_basic_input(InputKind::Secondary); agent.action_state.timer += read_data.dt.0; } else if has_leap() && has_energy(45.0) && rng.gen_bool(0.5) { - controller.push_action(ControlAction::basic_input(InputKind::Ability(0))); + controller.push_basic_input(InputKind::Ability(0)); agent.action_state.timer += read_data.dt.0; } else { - controller.push_action(ControlAction::basic_input(InputKind::Primary)); + controller.push_basic_input(InputKind::Primary); agent.action_state.timer += read_data.dt.0; } } else if attack_data.dist_sqrd < MAX_PATH_DIST.powi(2) { @@ -94,7 +94,7 @@ impl<'a> AgentData<'a> { && attack_data.dist_sqrd < 16.0f32.powi(2) && rng.gen::() < 0.02 { - controller.push_action(ControlAction::basic_input(InputKind::Roll)); + controller.push_basic_input(InputKind::Roll); } } else { self.path_toward_target(agent, controller, tgt_data, read_data, false, false, None); @@ -118,7 +118,7 @@ impl<'a> AgentData<'a> { let has_energy = |need| self.energy.current() > need; let use_leap = |controller: &mut Controller| { - controller.push_action(ControlAction::basic_input(InputKind::Ability(0))); + controller.push_basic_input(InputKind::Ability(0)); }; if attack_data.in_min_range() && attack_data.angle < 45.0 { @@ -127,13 +127,13 @@ impl<'a> AgentData<'a> { controller.push_action(ControlAction::CancelInput(InputKind::Secondary)); agent.action_state.timer = 0.0; } else if agent.action_state.timer > 3.0 { - controller.push_action(ControlAction::basic_input(InputKind::Secondary)); + controller.push_basic_input(InputKind::Secondary); agent.action_state.timer += read_data.dt.0; } else if has_leap() && has_energy(50.0) && rng.gen_bool(0.9) { use_leap(controller); agent.action_state.timer += read_data.dt.0; } else { - controller.push_action(ControlAction::basic_input(InputKind::Primary)); + controller.push_basic_input(InputKind::Primary); agent.action_state.timer += read_data.dt.0; } } else if attack_data.dist_sqrd < MAX_PATH_DIST.powi(2) { @@ -154,7 +154,7 @@ impl<'a> AgentData<'a> { && attack_data.dist_sqrd < 16.0f32.powi(2) && rng.gen::() < 0.02 { - controller.push_action(ControlAction::basic_input(InputKind::Roll)); + controller.push_basic_input(InputKind::Roll); } } else { self.path_toward_target(agent, controller, tgt_data, read_data, false, false, None); @@ -178,12 +178,12 @@ impl<'a> AgentData<'a> { && agent.action_state.timer < 2.0 && self.energy.current() > 60.0 { - controller.push_action(ControlAction::basic_input(InputKind::Ability(0))); + controller.push_basic_input(InputKind::Ability(0)); agent.action_state.timer += read_data.dt.0; } else if agent.action_state.timer > 2.0 { agent.action_state.timer = 0.0; } else { - controller.push_action(ControlAction::basic_input(InputKind::Primary)); + controller.push_basic_input(InputKind::Primary); agent.action_state.timer += read_data.dt.0; } } else if attack_data.dist_sqrd < MAX_PATH_DIST.powi(2) { @@ -196,7 +196,7 @@ impl<'a> AgentData<'a> { ) { if agent.action_state.timer > 4.0 && attack_data.angle < 45.0 { - controller.push_action(ControlAction::basic_input(InputKind::Secondary)); + controller.push_basic_input(InputKind::Secondary); agent.action_state.timer = 0.0; } else { agent.action_state.timer += read_data.dt.0; @@ -206,7 +206,7 @@ impl<'a> AgentData<'a> { && attack_data.dist_sqrd < 16.0f32.powi(2) && rng.gen::() < 0.02 { - controller.push_action(ControlAction::basic_input(InputKind::Roll)); + controller.push_basic_input(InputKind::Roll); } } else { self.path_toward_target(agent, controller, tgt_data, read_data, false, false, None); @@ -240,7 +240,7 @@ impl<'a> AgentData<'a> { { // If haven't charged to desired level, or target is moving too fast and haven't // fully charged, keep charging - controller.push_action(ControlAction::basic_input(InputKind::Primary)); + controller.push_basic_input(InputKind::Primary); } // Else don't send primary input to release the shot } @@ -257,7 +257,7 @@ impl<'a> AgentData<'a> { ) { // Only keep firing if not in melee range or if can see target - controller.push_action(ControlAction::basic_input(InputKind::Secondary)); + controller.push_basic_input(InputKind::Secondary); } } else if attack_data.dist_sqrd < (2.0 * attack_data.min_attack_dist).powi(2) { if self @@ -267,18 +267,18 @@ impl<'a> AgentData<'a> { && rng.gen_bool(0.5) { // Use shotgun if target close and have sufficient energy - controller.push_action(ControlAction::basic_input(InputKind::Ability(0))); + controller.push_basic_input(InputKind::Ability(0)); } else if self.body.map(|b| b.is_humanoid()).unwrap_or(false) && self.energy.current() > CharacterAbility::default_roll().get_energy_cost() && !matches!(self.char_state, CharacterState::BasicRanged(c) if !matches!(c.stage_section, StageSection::Recover)) { // Else roll away if can roll and have enough energy, and not using shotgun // (other 2 attacks have interrupt handled above) unless in recover - controller.push_action(ControlAction::basic_input(InputKind::Roll)); + controller.push_basic_input(InputKind::Roll); } else { self.path_toward_target(agent, controller, tgt_data, read_data, true, false, None); if attack_data.angle < 15.0 { - controller.push_action(ControlAction::basic_input(InputKind::Primary)); + controller.push_basic_input(InputKind::Primary); } } } else if attack_data.dist_sqrd < MAX_PATH_DIST.powi(2) @@ -292,10 +292,10 @@ impl<'a> AgentData<'a> { // If not really far, and can see target, attempt to shoot bow if self.energy.current() < DESIRED_ENERGY_LEVEL { // If low on energy, use primary to attempt to regen energy - controller.push_action(ControlAction::basic_input(InputKind::Primary)); + controller.push_basic_input(InputKind::Primary); } else { // Else we have enough energy, use repeater - controller.push_action(ControlAction::basic_input(InputKind::Secondary)); + controller.push_basic_input(InputKind::Secondary); } } // Logic to move. Intentionally kept separate from ability logic so duplicated @@ -353,7 +353,7 @@ impl<'a> AgentData<'a> { && attack_data.dist_sqrd < 16.0f32.powi(2) && rng.gen::() < 0.01 { - controller.push_action(ControlAction::basic_input(InputKind::Roll)); + controller.push_basic_input(InputKind::Roll); } } else { // If too far, move towards target @@ -392,13 +392,13 @@ impl<'a> AgentData<'a> { { // if a humanoid, have enough stamina, not in shockwave, and in melee range, // emergency roll - controller.push_action(ControlAction::basic_input(InputKind::Roll)); + controller.push_basic_input(InputKind::Roll); } else if matches!(self.char_state, CharacterState::Shockwave(_)) { agent.action_state.condition = false; } else if agent.action_state.condition && matches!(self.char_state, CharacterState::Wielding(_)) { - controller.push_action(ControlAction::basic_input(InputKind::Ability(0))); + controller.push_basic_input(InputKind::Ability(0)); } else if !matches!(self.char_state, CharacterState::Shockwave(c) if !matches!(c.stage_section, StageSection::Recover)) { // only try to use another ability unless in shockwave or recover @@ -416,7 +416,7 @@ impl<'a> AgentData<'a> { { // if enemy is closing distance quickly, use shockwave to knock back if matches!(self.char_state, CharacterState::Wielding(_)) { - controller.push_action(ControlAction::basic_input(InputKind::Ability(0))); + controller.push_basic_input(InputKind::Ability(0)); } else { agent.action_state.condition = true; } @@ -424,9 +424,9 @@ impl<'a> AgentData<'a> { > shockwave_cost + CharacterAbility::default_roll().get_energy_cost() && attack_data.dist_sqrd < flamethrower_range.powi(2) { - controller.push_action(ControlAction::basic_input(InputKind::Secondary)); + controller.push_basic_input(InputKind::Secondary); } else { - controller.push_action(ControlAction::basic_input(InputKind::Primary)); + controller.push_basic_input(InputKind::Primary); } } // Logic to move. Intentionally kept separate from ability logic so duplicated @@ -485,7 +485,7 @@ impl<'a> AgentData<'a> { && !matches!(self.char_state, CharacterState::Shockwave(_)) && rng.gen::() < 0.02 { - controller.push_action(ControlAction::basic_input(InputKind::Roll)); + controller.push_basic_input(InputKind::Roll); } } else { // If too far, move towards target @@ -528,7 +528,7 @@ impl<'a> AgentData<'a> { }) { // If have enough energy and combo to use healing aura, do so - controller.push_action(ControlAction::basic_input(InputKind::Secondary)); + controller.push_basic_input(InputKind::Secondary); } else if self .skill_set .has_skill(Skill::Sceptre(SceptreSkill::UnlockAura)) @@ -542,11 +542,11 @@ impl<'a> AgentData<'a> { { // Use ward if target is far enough away, self is not buffed, and have // sufficient energy - controller.push_action(ControlAction::basic_input(InputKind::Ability(0))); + controller.push_basic_input(InputKind::Ability(0)); } else { // If low on energy, use primary to attempt to regen energy // Or if at desired energy level but not able/willing to ward, just attack - controller.push_action(ControlAction::basic_input(InputKind::Primary)); + controller.push_basic_input(InputKind::Primary); } } else if attack_data.dist_sqrd < (2.0 * attack_data.min_attack_dist).powi(2) { if self.body.map_or(false, |b| b.is_humanoid()) @@ -555,9 +555,9 @@ impl<'a> AgentData<'a> { { // Else roll away if can roll and have enough energy, and not using aura or in // recover - controller.push_action(ControlAction::basic_input(InputKind::Roll)); + controller.push_basic_input(InputKind::Roll); } else if attack_data.angle < 15.0 { - controller.push_action(ControlAction::basic_input(InputKind::Primary)); + controller.push_basic_input(InputKind::Primary); } } // Logic to move. Intentionally kept separate from ability logic where possible @@ -616,7 +616,7 @@ impl<'a> AgentData<'a> { && attack_data.dist_sqrd < 16.0f32.powi(2) && rng.gen::() < 0.01 { - controller.push_action(ControlAction::basic_input(InputKind::Roll)); + controller.push_basic_input(InputKind::Roll); } } else { // If too far, move towards target @@ -634,11 +634,11 @@ impl<'a> AgentData<'a> { ) { if attack_data.in_min_range() && attack_data.angle < 90.0 { controller.inputs.move_dir = Vec2::zero(); - controller.push_action(ControlAction::basic_input(InputKind::Primary)); + controller.push_basic_input(InputKind::Primary); //controller.inputs.primary.set_state(true); } else if attack_data.dist_sqrd < MAX_PATH_DIST.powi(2) { if self.vel.0.is_approx_zero() { - controller.push_action(ControlAction::basic_input(InputKind::Ability(0))); + controller.push_basic_input(InputKind::Ability(0)); } if self.path_toward_target(agent, controller, tgt_data, read_data, true, false, None) && can_see_tgt( @@ -650,7 +650,7 @@ impl<'a> AgentData<'a> { && attack_data.angle < 90.0 { if agent.action_state.timer > 5.0 { - controller.push_action(ControlAction::basic_input(InputKind::Secondary)); + controller.push_basic_input(InputKind::Secondary); agent.action_state.timer = 0.0; } else { agent.action_state.timer += read_data.dt.0; @@ -675,7 +675,7 @@ impl<'a> AgentData<'a> { ) { if agent.action_state.counter >= circle_time as f32 { // if circle charge is in progress and time hasn't expired, continue charging - controller.push_action(ControlAction::basic_input(InputKind::Secondary)); + controller.push_basic_input(InputKind::Secondary); } if attack_data.in_min_range() { if agent.action_state.counter > 0.0 { @@ -684,7 +684,7 @@ impl<'a> AgentData<'a> { agent.action_state.int_counter = 0; } else { // melee attack - controller.push_action(ControlAction::basic_input(InputKind::Primary)); + controller.push_basic_input(InputKind::Primary); controller.inputs.move_dir = Vec2::zero(); } } else if attack_data.dist_sqrd < (radius as f32 + attack_data.min_attack_dist).powi(2) { @@ -762,7 +762,7 @@ impl<'a> AgentData<'a> { .xy() .try_normalized() .unwrap_or_else(Vec2::unit_y); - controller.push_action(ControlAction::basic_input(InputKind::Primary)); + controller.push_basic_input(InputKind::Primary); } else if attack_data.dist_sqrd < MAX_PATH_DIST.powi(2) { if let Some((bearing, speed)) = agent.chaser.chase( &*read_data.terrain, @@ -801,7 +801,7 @@ impl<'a> AgentData<'a> { * speed; agent.action_state.timer += read_data.dt.0; } - controller.push_action(ControlAction::basic_input(InputKind::Secondary)); + controller.push_basic_input(InputKind::Secondary); self.jump_if(controller, bearing.z > 1.5); controller.inputs.move_z = bearing.z; } else { @@ -833,10 +833,10 @@ impl<'a> AgentData<'a> { controller.push_action(ControlAction::CancelInput(InputKind::Primary)); agent.action_state.timer = 0.0; } else if agent.action_state.timer > 1.0 { - controller.push_action(ControlAction::basic_input(InputKind::Primary)); + controller.push_basic_input(InputKind::Primary); agent.action_state.timer += read_data.dt.0; } else { - controller.push_action(ControlAction::basic_input(InputKind::Secondary)); + controller.push_basic_input(InputKind::Secondary); agent.action_state.timer += read_data.dt.0; } controller.inputs.move_dir = (tgt_data.pos.0 - self.pos.0) @@ -863,12 +863,12 @@ impl<'a> AgentData<'a> { && attack_data.dist_sqrd < (1.5 * attack_data.min_attack_dist).powi(2) { controller.inputs.move_dir = Vec2::zero(); - controller.push_action(ControlAction::basic_input(InputKind::Secondary)); + controller.push_basic_input(InputKind::Secondary); } else if attack_data.dist_sqrd < (3.0 * attack_data.min_attack_dist).powi(2) && attack_data.dist_sqrd > (2.0 * attack_data.min_attack_dist).powi(2) && attack_data.angle < 90.0 { - controller.push_action(ControlAction::basic_input(InputKind::Primary)); + controller.push_basic_input(InputKind::Primary); controller.inputs.move_dir = (tgt_data.pos.0 - self.pos.0) .xy() .rotated_z(-0.47 * PI) @@ -896,10 +896,10 @@ impl<'a> AgentData<'a> { if agent.action_state.timer > 5.0 { agent.action_state.timer = 0.0; } else if agent.action_state.timer > 2.0 { - controller.push_action(ControlAction::basic_input(InputKind::Secondary)); + controller.push_basic_input(InputKind::Secondary); agent.action_state.timer += read_data.dt.0; } else { - controller.push_action(ControlAction::basic_input(InputKind::Primary)); + controller.push_basic_input(InputKind::Primary); agent.action_state.timer += read_data.dt.0; } } else if attack_data.dist_sqrd < MAX_PATH_DIST.powi(2) { @@ -921,11 +921,11 @@ impl<'a> AgentData<'a> { && attack_data.dist_sqrd < (1.5 * attack_data.min_attack_dist).powi(2) { controller.inputs.move_dir = Vec2::zero(); - controller.push_action(ControlAction::basic_input(InputKind::Secondary)); + controller.push_basic_input(InputKind::Secondary); } else if attack_data.angle < 15.0 && attack_data.dist_sqrd < (5.0 * attack_data.min_attack_dist).powi(2) { - controller.push_action(ControlAction::basic_input(InputKind::Ability(0))); + controller.push_basic_input(InputKind::Ability(0)); } else if attack_data.dist_sqrd < MAX_PATH_DIST.powi(2) { if self.path_toward_target(agent, controller, tgt_data, read_data, true, false, None) && attack_data.angle < 15.0 @@ -936,7 +936,7 @@ impl<'a> AgentData<'a> { attack_data.dist_sqrd, ) { - controller.push_action(ControlAction::basic_input(InputKind::Primary)); + controller.push_basic_input(InputKind::Primary); } } else { self.path_toward_target(agent, controller, tgt_data, read_data, false, false, None); @@ -954,10 +954,10 @@ impl<'a> AgentData<'a> { if attack_data.angle < 90.0 && attack_data.in_min_range() { controller.inputs.move_dir = Vec2::zero(); if agent.action_state.timer < 2.0 { - controller.push_action(ControlAction::basic_input(InputKind::Secondary)); + controller.push_basic_input(InputKind::Secondary); agent.action_state.timer += read_data.dt.0; } else if agent.action_state.timer < 3.0 { - controller.push_action(ControlAction::basic_input(InputKind::Primary)); + controller.push_basic_input(InputKind::Primary); agent.action_state.timer += read_data.dt.0; } else { agent.action_state.timer = 0.0; @@ -981,7 +981,7 @@ impl<'a> AgentData<'a> { && attack_data.dist_sqrd < (2.5 * attack_data.min_attack_dist).powi(2) { controller.inputs.move_dir = Vec2::zero(); - controller.push_action(ControlAction::basic_input(InputKind::Secondary)); + controller.push_basic_input(InputKind::Secondary); } else if attack_data.dist_sqrd < (7.0 * attack_data.min_attack_dist).powi(2) && attack_data.angle < 15.0 { @@ -991,7 +991,7 @@ impl<'a> AgentData<'a> { .rotated_z(0.47 * PI) .try_normalized() .unwrap_or_else(Vec2::unit_y); - controller.push_action(ControlAction::basic_input(InputKind::Primary)); + controller.push_basic_input(InputKind::Primary); agent.action_state.timer += read_data.dt.0; } else if agent.action_state.timer < 4.0 && attack_data.angle < 15.0 { controller.inputs.move_dir = (tgt_data.pos.0 - self.pos.0) @@ -999,10 +999,10 @@ impl<'a> AgentData<'a> { .rotated_z(-0.47 * PI) .try_normalized() .unwrap_or_else(Vec2::unit_y); - controller.push_action(ControlAction::basic_input(InputKind::Primary)); + controller.push_basic_input(InputKind::Primary); agent.action_state.timer += read_data.dt.0; } else if agent.action_state.timer < 6.0 && attack_data.angle < 15.0 { - controller.push_action(ControlAction::basic_input(InputKind::Ability(0))); + controller.push_basic_input(InputKind::Ability(0)); agent.action_state.timer += read_data.dt.0; } else { agent.action_state.timer = 0.0; @@ -1024,7 +1024,7 @@ impl<'a> AgentData<'a> { ) { if attack_data.angle < 90.0 && attack_data.in_min_range() { controller.inputs.move_dir = Vec2::zero(); - controller.push_action(ControlAction::basic_input(InputKind::Primary)); + controller.push_basic_input(InputKind::Primary); } else if attack_data.dist_sqrd < MAX_PATH_DIST.powi(2) { self.path_toward_target(agent, controller, tgt_data, read_data, true, false, None); } else { @@ -1047,7 +1047,7 @@ impl<'a> AgentData<'a> { attack_data.dist_sqrd, ) && attack_data.angle < 15.0 { - controller.push_action(ControlAction::basic_input(InputKind::Primary)); + controller.push_basic_input(InputKind::Primary); } else { agent.target = None; } @@ -1069,7 +1069,7 @@ impl<'a> AgentData<'a> { attack_data.dist_sqrd, ) && attack_data.angle < 15.0 { - controller.push_action(ControlAction::basic_input(InputKind::Primary)); + controller.push_basic_input(InputKind::Primary); } else { agent.target = None; } @@ -1096,7 +1096,7 @@ impl<'a> AgentData<'a> { tgt_data.pos, attack_data.dist_sqrd, ) { - controller.push_action(ControlAction::basic_input(InputKind::Primary)); + controller.push_basic_input(InputKind::Primary); } else { agent.target = None; } @@ -1116,12 +1116,12 @@ impl<'a> AgentData<'a> { tgt_data.pos, attack_data.dist_sqrd, ) { - controller.push_action(ControlAction::basic_input(InputKind::Primary)); + controller.push_basic_input(InputKind::Primary); } } pub fn handle_tornado_attack(&self, controller: &mut Controller) { - controller.push_action(ControlAction::basic_input(InputKind::Primary)); + controller.push_basic_input(InputKind::Primary); } pub fn handle_mindflayer_attack( @@ -1145,7 +1145,7 @@ impl<'a> AgentData<'a> { if agent.action_state.counter > health_fraction { // Summon minions at particular thresholds of health - controller.push_action(ControlAction::basic_input(InputKind::Ability(2))); + controller.push_basic_input(InputKind::Ability(2)); if matches!(self.char_state, CharacterState::BasicSummon(c) if matches!(c.stage_section, StageSection::Recover)) { @@ -1162,18 +1162,18 @@ impl<'a> AgentData<'a> { if matches!(self.char_state, CharacterState::BasicBeam(c) if c.timer < Duration::from_secs(10) && !matches!(c.stage_section, StageSection::Recover)) { // If already using primary, keep using primary until 10 consecutive seconds - controller.push_action(ControlAction::basic_input(InputKind::Primary)); + controller.push_basic_input(InputKind::Primary); } else if matches!(self.char_state, CharacterState::SpinMelee(c) if c.consecutive_spins < 50 && !matches!(c.stage_section, StageSection::Recover)) { // If already using secondary, keep using secondary until 10 consecutive // seconds - controller.push_action(ControlAction::basic_input(InputKind::Secondary)); + controller.push_basic_input(InputKind::Secondary); } else if rng.gen_bool(health_fraction.into()) { // Else if at high health, use primary - controller.push_action(ControlAction::basic_input(InputKind::Primary)); + controller.push_basic_input(InputKind::Primary); } else { // Else use secondary - controller.push_action(ControlAction::basic_input(InputKind::Secondary)); + controller.push_basic_input(InputKind::Secondary); } } else { self.path_toward_target(agent, controller, tgt_data, read_data, true, false, None); @@ -1235,7 +1235,7 @@ impl<'a> AgentData<'a> { && attack_data.angle < 15.0 { // Fireball - controller.push_action(ControlAction::basic_input(InputKind::Primary)); + controller.push_basic_input(InputKind::Primary); } // If some target if let Some((bearing, speed)) = agent.chaser.chase( @@ -1254,7 +1254,7 @@ impl<'a> AgentData<'a> { // If less than 20 blocks higher than target if (self.pos.0.z - tgt_data.pos.0.z) < 20.0 { // Fly upward - controller.push_action(ControlAction::basic_input(InputKind::Fly)); + controller.push_basic_input(InputKind::Fly); controller.inputs.move_z = 1.0; } else { // Jump @@ -1276,7 +1276,7 @@ impl<'a> AgentData<'a> { // The next stage shouldn't trigger until the entity // is on the ground // Fly to target - controller.push_action(ControlAction::basic_input(InputKind::Fly)); + controller.push_basic_input(InputKind::Fly); let move_dir = tgt_data.pos.0 - self.pos.0; controller.inputs.move_dir = move_dir.xy().try_normalized().unwrap_or_else(Vec2::zero) * 2.0; @@ -1287,7 +1287,7 @@ impl<'a> AgentData<'a> { && attack_data.angle < 15.0 { // Fireball - controller.push_action(ControlAction::basic_input(InputKind::Primary)); + controller.push_basic_input(InputKind::Primary); } } // If further than 4 blocks and random chance @@ -1296,7 +1296,7 @@ impl<'a> AgentData<'a> { && attack_data.angle < 15.0 { // Fireball - controller.push_action(ControlAction::basic_input(InputKind::Primary)); + controller.push_basic_input(InputKind::Primary); } // If random chance and less than 20 blocks higher than target and further than 4 // blocks @@ -1304,7 +1304,7 @@ impl<'a> AgentData<'a> { && (self.pos.0.z - tgt_data.pos.0.z) < 15.0 && attack_data.dist_sqrd > (4.0 * attack_data.min_attack_dist).powi(2) { - controller.push_action(ControlAction::basic_input(InputKind::Fly)); + controller.push_basic_input(InputKind::Fly); controller.inputs.move_z = 1.0; } // If further than 2.5 blocks and random chance @@ -1315,10 +1315,10 @@ impl<'a> AgentData<'a> { // If energy higher than 600 and random chance else if self.energy.current() > 60.0 && rng.gen_bool(0.4) { // Shockwave - controller.push_action(ControlAction::basic_input(InputKind::Ability(0))); + controller.push_basic_input(InputKind::Ability(0)); } else if attack_data.angle < 90.0 { // Triple strike - controller.push_action(ControlAction::basic_input(InputKind::Secondary)); + controller.push_basic_input(InputKind::Secondary); } else { // Target is behind us. Turn around and chase target self.path_toward_target(agent, controller, tgt_data, read_data, true, false, None); @@ -1346,7 +1346,7 @@ impl<'a> AgentData<'a> { ) && attack_data.angle < 15.0 { - controller.push_action(ControlAction::basic_input(InputKind::Primary)); + controller.push_basic_input(InputKind::Primary); } if let Some((bearing, speed)) = agent.chaser.chase( &*read_data.terrain, @@ -1361,7 +1361,7 @@ impl<'a> AgentData<'a> { controller.inputs.move_dir = bearing.xy().try_normalized().unwrap_or_else(Vec2::zero) * speed; if (self.pos.0.z - tgt_data.pos.0.z) < 20.0 { - controller.push_action(ControlAction::basic_input(InputKind::Fly)); + controller.push_basic_input(InputKind::Fly); controller.inputs.move_z = 1.0; } else { self.jump_if(controller, bearing.z > 1.5); @@ -1379,7 +1379,7 @@ impl<'a> AgentData<'a> { // Do not increment the timer during this movement // The next stage shouldn't trigger until the entity // is on the ground - controller.push_action(ControlAction::basic_input(InputKind::Fly)); + controller.push_basic_input(InputKind::Fly); let move_dir = tgt_data.pos.0 - self.pos.0; controller.inputs.move_dir = move_dir.xy().try_normalized().unwrap_or_else(Vec2::zero) * 2.0; @@ -1388,18 +1388,18 @@ impl<'a> AgentData<'a> { && attack_data.dist_sqrd > (4.0 * attack_data.min_attack_dist).powi(2) && attack_data.angle < 15.0 { - controller.push_action(ControlAction::basic_input(InputKind::Primary)); + controller.push_basic_input(InputKind::Primary); } } else if rng.gen_bool(0.05) && attack_data.dist_sqrd > (4.0 * attack_data.min_attack_dist).powi(2) && attack_data.angle < 15.0 { - controller.push_action(ControlAction::basic_input(InputKind::Primary)); + controller.push_basic_input(InputKind::Primary); } else if rng.gen_bool(0.5) && (self.pos.0.z - tgt_data.pos.0.z) < 15.0 && attack_data.dist_sqrd > (4.0 * attack_data.min_attack_dist).powi(2) { - controller.push_action(ControlAction::basic_input(InputKind::Fly)); + controller.push_basic_input(InputKind::Fly); controller.inputs.move_z = 1.0; } else if attack_data.dist_sqrd > (3.0 * attack_data.min_attack_dist).powi(2) { self.path_toward_target(agent, controller, tgt_data, read_data, true, false, None); @@ -1408,7 +1408,7 @@ impl<'a> AgentData<'a> { && attack_data.angle < 15.0 { // Fire breath attack - controller.push_action(ControlAction::basic_input(InputKind::Ability(0))); + controller.push_basic_input(InputKind::Ability(0)); // Move towards the target slowly self.path_toward_target( agent, @@ -1425,7 +1425,7 @@ impl<'a> AgentData<'a> { && attack_data.in_min_range() { // Triplestrike - controller.push_action(ControlAction::basic_input(InputKind::Secondary)); + controller.push_basic_input(InputKind::Secondary); agent.action_state.timer += read_data.dt.0; } else { // Reset timer @@ -1458,14 +1458,14 @@ impl<'a> AgentData<'a> { .map_or(true, |b| b.is_some()) { // Fly to target and land - controller.push_action(ControlAction::basic_input(InputKind::Fly)); + controller.push_basic_input(InputKind::Fly); let move_dir = tgt_data.pos.0 - self.pos.0; controller.inputs.move_dir = move_dir.xy().try_normalized().unwrap_or_else(Vec2::zero) * 2.0; controller.inputs.move_z = move_dir.z - 0.5; } else if agent.action_state.timer > 8.0 { // If action timer higher than 8, make bird summon tornadoes - controller.push_action(ControlAction::basic_input(InputKind::Secondary)); + controller.push_basic_input(InputKind::Secondary); if matches!(self.char_state, CharacterState::BasicSummon(c) if matches!(c.stage_section, StageSection::Recover)) { // Reset timer @@ -1474,19 +1474,19 @@ impl<'a> AgentData<'a> { } else if matches!(self.char_state, CharacterState::DashMelee(c) if !matches!(c.stage_section, StageSection::Recover)) { // If already in dash, keep dashing if not in recover - controller.push_action(ControlAction::basic_input(InputKind::Ability(0))); + controller.push_basic_input(InputKind::Ability(0)); } else if matches!(self.char_state, CharacterState::ComboMelee(c) if matches!(c.stage_section, StageSection::Recover)) { // If already in combo keep comboing if not in recover - controller.push_action(ControlAction::basic_input(InputKind::Primary)); + controller.push_basic_input(InputKind::Primary); } else if attack_data.dist_sqrd > BIRD_CHARGE_DISTANCE.powi(2) { // Charges at target if they are far enough away if attack_data.angle < 60.0 { - controller.push_action(ControlAction::basic_input(InputKind::Ability(0))); + controller.push_basic_input(InputKind::Ability(0)); } } else if attack_data.dist_sqrd < bird_attack_distance.powi(2) { // Combo melee target - controller.push_action(ControlAction::basic_input(InputKind::Primary)); + controller.push_basic_input(InputKind::Primary); agent.action_state.condition = true; } // Make bird move towards target @@ -1506,7 +1506,7 @@ impl<'a> AgentData<'a> { && attack_data.dist_sqrd < (2.0 * attack_data.min_attack_dist).powi(2) { controller.inputs.move_dir = Vec2::zero(); - controller.push_action(ControlAction::basic_input(InputKind::Secondary)); + controller.push_basic_input(InputKind::Secondary); // Reset timer if matches!(self.char_state, CharacterState::SpriteSummon(c) if matches!(c.stage_section, StageSection::Recover)) { @@ -1516,7 +1516,7 @@ impl<'a> AgentData<'a> { && attack_data.dist_sqrd < (1.5 * attack_data.min_attack_dist).powi(2) { controller.inputs.move_dir = Vec2::zero(); - controller.push_action(ControlAction::basic_input(InputKind::Primary)); + controller.push_basic_input(InputKind::Primary); } else { self.path_toward_target(agent, controller, tgt_data, read_data, false, false, None); } @@ -1535,7 +1535,7 @@ impl<'a> AgentData<'a> { && attack_data.dist_sqrd < (2.0 * attack_data.min_attack_dist).powi(2) { controller.inputs.move_dir = Vec2::zero(); - controller.push_action(ControlAction::basic_input(InputKind::Secondary)); + controller.push_basic_input(InputKind::Secondary); // Reset timer if matches!(self.char_state, CharacterState::SpriteSummon(c) if matches!(c.stage_section, StageSection::Recover)) { @@ -1548,7 +1548,7 @@ impl<'a> AgentData<'a> { .xy() .try_normalized() .unwrap_or_else(Vec2::unit_y); - controller.push_action(ControlAction::basic_input(InputKind::Primary)); + controller.push_basic_input(InputKind::Primary); } else if attack_data.dist_sqrd < MAX_PATH_DIST.powi(2) { if let Some((bearing, speed)) = agent.chaser.chase( &*read_data.terrain, @@ -1587,7 +1587,7 @@ impl<'a> AgentData<'a> { * speed; agent.action_state.timer += read_data.dt.0; } - controller.push_action(ControlAction::basic_input(InputKind::Ability(0))); + controller.push_basic_input(InputKind::Ability(0)); self.jump_if(controller, bearing.z > 1.5); controller.inputs.move_z = bearing.z; } else { @@ -1618,7 +1618,7 @@ impl<'a> AgentData<'a> { && attack_data.dist_sqrd < (1.5 * attack_data.min_attack_dist).powi(2) { controller.inputs.move_dir = Vec2::zero(); - controller.push_action(ControlAction::basic_input(InputKind::Secondary)); + controller.push_basic_input(InputKind::Secondary); // Reset timer if matches!(self.char_state, CharacterState::SpriteSummon(c) if matches!(c.stage_section, StageSection::Recover)) { @@ -1628,12 +1628,12 @@ impl<'a> AgentData<'a> { && attack_data.dist_sqrd < (1.5 * attack_data.min_attack_dist).powi(2) { controller.inputs.move_dir = Vec2::zero(); - controller.push_action(ControlAction::basic_input(InputKind::Primary)); + controller.push_basic_input(InputKind::Primary); } else if rng.gen_bool(0.01) && attack_data.angle < 15.0 && attack_data.dist_sqrd < (6.0 * attack_data.min_attack_dist).powi(2) { - controller.push_action(ControlAction::basic_input(InputKind::Ability(0))); + controller.push_basic_input(InputKind::Ability(0)); } else { self.path_toward_target(agent, controller, tgt_data, read_data, false, false, None); } @@ -1651,17 +1651,17 @@ impl<'a> AgentData<'a> { if matches!(self.char_state, CharacterState::DashMelee(c) if !matches!(c.stage_section, StageSection::Recover)) { // If already charging, keep charging if not in recover - controller.push_action(ControlAction::basic_input(InputKind::Secondary)); + controller.push_basic_input(InputKind::Secondary); } else if attack_data.dist_sqrd > (5.0 * attack_data.min_attack_dist).powi(2) { // Charges at target if they are far enough away if attack_data.angle < 60.0 { - controller.push_action(ControlAction::basic_input(InputKind::Secondary)); + controller.push_basic_input(InputKind::Secondary); } } else if attack_data.angle < 90.0 && attack_data.dist_sqrd < (1.5 * attack_data.min_attack_dist).powi(2) { controller.inputs.move_dir = Vec2::zero(); - controller.push_action(ControlAction::basic_input(InputKind::Primary)); + controller.push_basic_input(InputKind::Primary); } else { self.path_toward_target(agent, controller, tgt_data, read_data, false, false, None); } @@ -1689,7 +1689,7 @@ impl<'a> AgentData<'a> { } if health_fraction < agent.action_state.counter { // Makes minotaur buff itself with frenzy - controller.push_action(ControlAction::basic_input(InputKind::Ability(1))); + controller.push_basic_input(InputKind::Ability(1)); if matches!(self.char_state, CharacterState::SelfBuff(c) if matches!(c.stage_section, StageSection::Recover)) { agent.action_state.counter = 0.0; @@ -1697,24 +1697,24 @@ impl<'a> AgentData<'a> { } else if matches!(self.char_state, CharacterState::DashMelee(c) if !matches!(c.stage_section, StageSection::Recover)) { // If already charging, keep charging if not in recover - controller.push_action(ControlAction::basic_input(InputKind::Ability(0))); + controller.push_basic_input(InputKind::Ability(0)); } else if matches!(self.char_state, CharacterState::ChargedMelee(c) if matches!(c.stage_section, StageSection::Charge) && c.timer < c.static_data.charge_duration) { // If already charging a melee attack, keep charging it if charging - controller.push_action(ControlAction::basic_input(InputKind::Primary)); + controller.push_basic_input(InputKind::Primary); } else if attack_data.dist_sqrd > MINOTAUR_CHARGE_DISTANCE.powi(2) { // Charges at target if they are far enough away if attack_data.angle < 60.0 { - controller.push_action(ControlAction::basic_input(InputKind::Ability(0))); + controller.push_basic_input(InputKind::Ability(0)); } } else if attack_data.dist_sqrd < minotaur_attack_distance.powi(2) { if agent.action_state.condition && !self.char_state.is_attack() { // Cripple target if not just used cripple - controller.push_action(ControlAction::basic_input(InputKind::Secondary)); + controller.push_basic_input(InputKind::Secondary); agent.action_state.condition = false; } else if !self.char_state.is_attack() { // Cleave target if not just used cleave - controller.push_action(ControlAction::basic_input(InputKind::Primary)); + controller.push_basic_input(InputKind::Primary); agent.action_state.condition = true; } } @@ -1748,11 +1748,11 @@ impl<'a> AgentData<'a> { if attack_data.dist_sqrd < golem_melee_range.powi(2) { if agent.action_state.counter < 7.5 { // If target is close, whack them - controller.push_action(ControlAction::basic_input(InputKind::Primary)); + controller.push_basic_input(InputKind::Primary); agent.action_state.counter += read_data.dt.0; } else { // If whacked for too long, nuke them - controller.push_action(ControlAction::basic_input(InputKind::Ability(1))); + controller.push_basic_input(InputKind::Ability(1)); if matches!(self.char_state, CharacterState::BasicRanged(c) if matches!(c.stage_section, StageSection::Recover)) { agent.action_state.counter = 0.0; @@ -1771,11 +1771,11 @@ impl<'a> AgentData<'a> { { // If target in range threshold and haven't been lasering for more than 5 // seconds already or if target is moving slow-ish, laser them - controller.push_action(ControlAction::basic_input(InputKind::Secondary)); + controller.push_basic_input(InputKind::Secondary); } else if health_fraction < 0.7 { // Else target moving too fast for laser, shockwave time. // But only if damaged enough - controller.push_action(ControlAction::basic_input(InputKind::Ability(0))); + controller.push_basic_input(InputKind::Ability(0)); } } else if attack_data.dist_sqrd < GOLEM_LONG_RANGE.powi(2) { if target_speed_cross_sqd < GOLEM_TARGET_SPEED.powi(2) @@ -1787,11 +1787,11 @@ impl<'a> AgentData<'a> { ) { // If target is far-ish and moving slow-ish, rocket them - controller.push_action(ControlAction::basic_input(InputKind::Ability(1))); + controller.push_basic_input(InputKind::Ability(1)); } else if health_fraction < 0.7 { // Else target moving too fast for laser, shockwave time. // But only if damaged enough - controller.push_action(ControlAction::basic_input(InputKind::Ability(0))); + controller.push_basic_input(InputKind::Ability(0)); } } // Make clay golem move towards target @@ -1819,7 +1819,7 @@ impl<'a> AgentData<'a> { if agent.action_state.counter > health_fraction { // Summon minions at particular thresholds of health - controller.push_action(ControlAction::basic_input(InputKind::Ability(1))); + controller.push_basic_input(InputKind::Ability(1)); if matches!(self.char_state, CharacterState::BasicSummon(c) if matches!(c.stage_section, StageSection::Recover)) { @@ -1829,16 +1829,16 @@ impl<'a> AgentData<'a> { if matches!(self.char_state, CharacterState::DashMelee(c) if !matches!(c.stage_section, StageSection::Recover)) { // Keep scuttling if already in dash melee and not in recover - controller.push_action(ControlAction::basic_input(InputKind::Secondary)); + controller.push_basic_input(InputKind::Secondary); } else if attack_data.dist_sqrd < BUBBLE_RANGE.powi(2) { if matches!(self.char_state, CharacterState::BasicBeam(c) if !matches!(c.stage_section, StageSection::Recover) && c.timer < Duration::from_secs(10)) { // Keep shooting bubbles at them if already in basic beam and not in recover and // have not been bubbling too long - controller.push_action(ControlAction::basic_input(InputKind::Ability(0))); + controller.push_basic_input(InputKind::Ability(0)); } else if attack_data.in_min_range() && attack_data.angle < 60.0 { // Pincer them if they're in range and angle - controller.push_action(ControlAction::basic_input(InputKind::Primary)); + controller.push_basic_input(InputKind::Primary); } else if attack_data.angle < 30.0 && can_see_tgt( &*read_data.terrain, @@ -1849,7 +1849,7 @@ impl<'a> AgentData<'a> { { // Start bubbling them if not close enough to do something else and in angle and // can see target - controller.push_action(ControlAction::basic_input(InputKind::Ability(0))); + controller.push_basic_input(InputKind::Ability(0)); } } else if attack_data.angle < 90.0 && can_see_tgt( @@ -1861,7 +1861,7 @@ impl<'a> AgentData<'a> { { // Start scuttling if not close enough to do something else and in angle and can // see target - controller.push_action(ControlAction::basic_input(InputKind::Secondary)); + controller.push_basic_input(InputKind::Secondary); } } // Always attempt to path towards target @@ -1887,10 +1887,10 @@ impl<'a> AgentData<'a> { if matches!(self.char_state, CharacterState::BasicBeam(c) if c.timer < Duration::from_secs(2)) { // Keep using ice breath for 2 second - controller.push_action(ControlAction::basic_input(InputKind::Ability(0))); + controller.push_basic_input(InputKind::Ability(0)); } else if agent.action_state.counter > ICE_BREATH_TIMER { // Use ice breath if timer has gone for long enough - controller.push_action(ControlAction::basic_input(InputKind::Ability(0))); + controller.push_basic_input(InputKind::Ability(0)); if matches!(self.char_state, CharacterState::BasicBeam(_)) { // Resets action counter when using beam @@ -1898,17 +1898,17 @@ impl<'a> AgentData<'a> { } } else if attack_data.in_min_range() { // Basic attack if on top of them - controller.push_action(ControlAction::basic_input(InputKind::Primary)); + controller.push_basic_input(InputKind::Primary); } else { // Use ice spikes if too far for other abilities - controller.push_action(ControlAction::basic_input(InputKind::Secondary)); + controller.push_basic_input(InputKind::Secondary); } } else if attack_data.dist_sqrd < ICE_SPIKES_RANGE.powi(2) && attack_data.angle < 60.0 { // Use ice spikes if in range - controller.push_action(ControlAction::basic_input(InputKind::Secondary)); + controller.push_basic_input(InputKind::Secondary); } else if attack_data.dist_sqrd < SNOWBALL_MAX_RANGE.powi(2) && attack_data.angle < 60.0 { // Otherwise, chuck all the snowballs - controller.push_action(ControlAction::basic_input(InputKind::Ability(1))); + controller.push_basic_input(InputKind::Ability(1)); } // Always attempt to path towards target @@ -1930,7 +1930,7 @@ impl<'a> AgentData<'a> { if health_fraction < VINE_CREATION_THRESHOLD && !agent.action_state.condition { // Summon vines when reach threshold of health - controller.push_action(ControlAction::basic_input(InputKind::Ability(0))); + controller.push_basic_input(InputKind::Ability(0)); if matches!(self.char_state, CharacterState::SpriteSummon(c) if matches!(c.stage_section, StageSection::Recover)) { @@ -1947,10 +1947,10 @@ impl<'a> AgentData<'a> { { // Keep breathing fire if close enough, can see target, and have not been // breathing for more than 5 seconds - controller.push_action(ControlAction::basic_input(InputKind::Secondary)); + controller.push_basic_input(InputKind::Secondary); } else if attack_data.in_min_range() && attack_data.angle < 60.0 { // Scythe them if they're in range and angle - controller.push_action(ControlAction::basic_input(InputKind::Primary)); + controller.push_basic_input(InputKind::Primary); } else if attack_data.angle < 30.0 && can_see_tgt( &*read_data.terrain, @@ -1960,7 +1960,7 @@ impl<'a> AgentData<'a> { ) { // Start breathing fire at them if close enough, in angle, and can see target - controller.push_action(ControlAction::basic_input(InputKind::Secondary)); + controller.push_basic_input(InputKind::Secondary); } } else if attack_data.dist_sqrd < MAX_PUMPKIN_RANGE.powi(2) && can_see_tgt( @@ -1971,7 +1971,7 @@ impl<'a> AgentData<'a> { ) { // Throw a pumpkin at them if close enough and can see them - controller.push_action(ControlAction::basic_input(InputKind::Ability(1))); + controller.push_basic_input(InputKind::Ability(1)); } // Always attempt to path towards target self.path_toward_target(agent, controller, tgt_data, read_data, false, false, None); From a1a9c0f4f2ca2bca436da5791f09d1eeb5563425 Mon Sep 17 00:00:00 2001 From: "Dr. Dystopia" Date: Wed, 26 Jan 2022 20:15:40 +0100 Subject: [PATCH 4/8] Create 'push_cancel_input' function --- client/src/lib.rs | 2 +- common/src/comp/controller.rs | 4 ++++ server/src/sys/agent.rs | 4 ++-- server/src/sys/agent/attack.rs | 8 ++++---- 4 files changed, 11 insertions(+), 7 deletions(-) diff --git a/client/src/lib.rs b/client/src/lib.rs index 27eace9afe..31860c6290 100644 --- a/client/src/lib.rs +++ b/client/src/lib.rs @@ -1290,7 +1290,7 @@ impl Client { select_pos, }); } else { - self.control_action(ControlAction::CancelInput(input)); + self.push_cancel_input(input); } } diff --git a/common/src/comp/controller.rs b/common/src/comp/controller.rs index 3c440f0cec..68cb99e281 100644 --- a/common/src/comp/controller.rs +++ b/common/src/comp/controller.rs @@ -285,6 +285,10 @@ impl Controller { pub fn push_basic_input(&mut self, input: InputKind) { self.push_action(ControlAction::basic_input(input)); } + + pub fn push_cancel_input(&mut self, input: InputKind) { + self.push_action(ControlAction::CancelInput(input)); + } } impl Component for Controller { diff --git a/server/src/sys/agent.rs b/server/src/sys/agent.rs index 2df62b0e84..2f78695f91 100644 --- a/server/src/sys/agent.rs +++ b/server/src/sys/agent.rs @@ -739,7 +739,7 @@ impl<'a> AgentData<'a> { { controller.push_basic_input(InputKind::Fly); } else { - controller.push_action(ControlAction::CancelInput(InputKind::Fly)) + controller.push_cancel_input(InputKind::Fly) } if let Some((bearing, speed)) = agent.chaser.chase( @@ -2276,7 +2276,7 @@ impl<'a> AgentData<'a> { if condition { controller.push_basic_input(InputKind::Jump); } else { - controller.push_action(ControlAction::CancelInput(InputKind::Jump)) + controller.push_cancel_input(InputKind::Jump) } } diff --git a/server/src/sys/agent/attack.rs b/server/src/sys/agent/attack.rs index bc20b9670b..9c89a30f8b 100644 --- a/server/src/sys/agent/attack.rs +++ b/server/src/sys/agent/attack.rs @@ -64,7 +64,7 @@ impl<'a> AgentData<'a> { if attack_data.in_min_range() && attack_data.angle < 45.0 { controller.inputs.move_dir = Vec2::zero(); if agent.action_state.timer > 5.0 { - controller.push_action(ControlAction::CancelInput(InputKind::Secondary)); + controller.push_cancel_input(InputKind::Secondary); agent.action_state.timer = 0.0; } else if agent.action_state.timer > 2.5 && has_energy(10.0) { controller.push_basic_input(InputKind::Secondary); @@ -124,7 +124,7 @@ impl<'a> AgentData<'a> { if attack_data.in_min_range() && attack_data.angle < 45.0 { controller.inputs.move_dir = Vec2::zero(); if agent.action_state.timer > 4.0 { - controller.push_action(ControlAction::CancelInput(InputKind::Secondary)); + controller.push_cancel_input(InputKind::Secondary); agent.action_state.timer = 0.0; } else if agent.action_state.timer > 3.0 { controller.push_basic_input(InputKind::Secondary); @@ -830,7 +830,7 @@ impl<'a> AgentData<'a> { && attack_data.dist_sqrd < (1.5 * attack_data.min_attack_dist).powi(2) { if agent.action_state.timer > 4.0 { - controller.push_action(ControlAction::CancelInput(InputKind::Primary)); + controller.push_cancel_input(InputKind::Primary); agent.action_state.timer = 0.0; } else if agent.action_state.timer > 1.0 { controller.push_basic_input(InputKind::Primary); @@ -1335,7 +1335,7 @@ impl<'a> AgentData<'a> { rng: &mut impl Rng, ) { // Set fly to false - controller.push_action(ControlAction::CancelInput(InputKind::Fly)); + controller.push_cancel_input(InputKind::Fly); if attack_data.dist_sqrd > 30.0_f32.powi(2) { if rng.gen_bool(0.05) && can_see_tgt( From 765e858c19074416d8a597955b3ad50b1d5d17cf Mon Sep 17 00:00:00 2001 From: "Dr. Dystopia" Date: Wed, 26 Jan 2022 20:15:40 +0100 Subject: [PATCH 5/8] Create 'push_cancel_input' function --- common/src/comp/controller.rs | 4 ++++ server/src/sys/agent.rs | 4 ++-- server/src/sys/agent/attack.rs | 8 ++++---- 3 files changed, 10 insertions(+), 6 deletions(-) diff --git a/common/src/comp/controller.rs b/common/src/comp/controller.rs index 3c440f0cec..68cb99e281 100644 --- a/common/src/comp/controller.rs +++ b/common/src/comp/controller.rs @@ -285,6 +285,10 @@ impl Controller { pub fn push_basic_input(&mut self, input: InputKind) { self.push_action(ControlAction::basic_input(input)); } + + pub fn push_cancel_input(&mut self, input: InputKind) { + self.push_action(ControlAction::CancelInput(input)); + } } impl Component for Controller { diff --git a/server/src/sys/agent.rs b/server/src/sys/agent.rs index 2df62b0e84..2f78695f91 100644 --- a/server/src/sys/agent.rs +++ b/server/src/sys/agent.rs @@ -739,7 +739,7 @@ impl<'a> AgentData<'a> { { controller.push_basic_input(InputKind::Fly); } else { - controller.push_action(ControlAction::CancelInput(InputKind::Fly)) + controller.push_cancel_input(InputKind::Fly) } if let Some((bearing, speed)) = agent.chaser.chase( @@ -2276,7 +2276,7 @@ impl<'a> AgentData<'a> { if condition { controller.push_basic_input(InputKind::Jump); } else { - controller.push_action(ControlAction::CancelInput(InputKind::Jump)) + controller.push_cancel_input(InputKind::Jump) } } diff --git a/server/src/sys/agent/attack.rs b/server/src/sys/agent/attack.rs index bc20b9670b..9c89a30f8b 100644 --- a/server/src/sys/agent/attack.rs +++ b/server/src/sys/agent/attack.rs @@ -64,7 +64,7 @@ impl<'a> AgentData<'a> { if attack_data.in_min_range() && attack_data.angle < 45.0 { controller.inputs.move_dir = Vec2::zero(); if agent.action_state.timer > 5.0 { - controller.push_action(ControlAction::CancelInput(InputKind::Secondary)); + controller.push_cancel_input(InputKind::Secondary); agent.action_state.timer = 0.0; } else if agent.action_state.timer > 2.5 && has_energy(10.0) { controller.push_basic_input(InputKind::Secondary); @@ -124,7 +124,7 @@ impl<'a> AgentData<'a> { if attack_data.in_min_range() && attack_data.angle < 45.0 { controller.inputs.move_dir = Vec2::zero(); if agent.action_state.timer > 4.0 { - controller.push_action(ControlAction::CancelInput(InputKind::Secondary)); + controller.push_cancel_input(InputKind::Secondary); agent.action_state.timer = 0.0; } else if agent.action_state.timer > 3.0 { controller.push_basic_input(InputKind::Secondary); @@ -830,7 +830,7 @@ impl<'a> AgentData<'a> { && attack_data.dist_sqrd < (1.5 * attack_data.min_attack_dist).powi(2) { if agent.action_state.timer > 4.0 { - controller.push_action(ControlAction::CancelInput(InputKind::Primary)); + controller.push_cancel_input(InputKind::Primary); agent.action_state.timer = 0.0; } else if agent.action_state.timer > 1.0 { controller.push_basic_input(InputKind::Primary); @@ -1335,7 +1335,7 @@ impl<'a> AgentData<'a> { rng: &mut impl Rng, ) { // Set fly to false - controller.push_action(ControlAction::CancelInput(InputKind::Fly)); + controller.push_cancel_input(InputKind::Fly); if attack_data.dist_sqrd > 30.0_f32.powi(2) { if rng.gen_bool(0.05) && can_see_tgt( From 051652698533dc8832d1edb4f1f6eff11bd96398 Mon Sep 17 00:00:00 2001 From: "Dr. Dystopia" Date: Wed, 26 Jan 2022 21:12:19 +0100 Subject: [PATCH 6/8] Create 'push_utterance' function --- common/src/comp/controller.rs | 4 ++++ server/src/sys/agent.rs | 14 +++++++------- 2 files changed, 11 insertions(+), 7 deletions(-) diff --git a/common/src/comp/controller.rs b/common/src/comp/controller.rs index 68cb99e281..25ac92a17d 100644 --- a/common/src/comp/controller.rs +++ b/common/src/comp/controller.rs @@ -280,6 +280,10 @@ impl Controller { pub fn push_event(&mut self, event: ControlEvent) { self.events.push(event); } + pub fn push_utterance(&mut self, utterance: UtteranceKind) { + self.push_event(ControlEvent::Utterance(utterance)); + } + pub fn push_action(&mut self, action: ControlAction) { self.actions.push(action); } pub fn push_basic_input(&mut self, input: InputKind) { diff --git a/server/src/sys/agent.rs b/server/src/sys/agent.rs index 2f78695f91..4ace5ebd7f 100644 --- a/server/src/sys/agent.rs +++ b/server/src/sys/agent.rs @@ -513,7 +513,7 @@ impl<'a> AgentData<'a> { Some(AgentEvent::Hurt) => { // Hurt utterances at random upon receiving damage if rng.gen::() < 0.4 { - controller.push_event(ControlEvent::Utterance(UtteranceKind::Hurt)); + controller.push_utterance(UtteranceKind::Hurt); } }, //Note: this should be unreachable @@ -581,7 +581,7 @@ impl<'a> AgentData<'a> { if let Some(AgentEvent::Hurt) = agent.inbox.pop_front() { // Hurt utterances at random upon receiving damage if rng.gen::() < 0.4 { - controller.push_event(ControlEvent::Utterance(UtteranceKind::Hurt)); + controller.push_utterance(UtteranceKind::Hurt); } } @@ -905,7 +905,7 @@ impl<'a> AgentData<'a> { } if rng.gen::() < 0.0015 { - controller.push_event(ControlEvent::Utterance(UtteranceKind::Calm)); + controller.push_utterance(UtteranceKind::Calm); } // Sit @@ -971,7 +971,7 @@ impl<'a> AgentData<'a> { if self.look_toward(controller, read_data, target) { controller.push_action(ControlAction::Stand); controller.push_action(ControlAction::Talk); - controller.push_event(ControlEvent::Utterance(UtteranceKind::Greeting)); + controller.push_utterance(UtteranceKind::Greeting); match subject { Subject::Regular => { @@ -1328,7 +1328,7 @@ impl<'a> AgentData<'a> { if small_chance { self.chat_npc_if_allowed_to_speak("npc.speech.menacing", agent, event_emitter); - controller.push_event(ControlEvent::Utterance(UtteranceKind::Angry)); + controller.push_utterance(UtteranceKind::Angry); } } @@ -1634,7 +1634,7 @@ impl<'a> AgentData<'a> { .map(|(e, _)| e); if agent.target.is_none() && target.is_some() { - controller.push_event(ControlEvent::Utterance(UtteranceKind::Angry)); + controller.push_utterance(UtteranceKind::Angry); } agent.target = target.map(|target| Target { @@ -2147,7 +2147,7 @@ impl<'a> AgentData<'a> { if let Some(by) = tgt_health.last_change.damage_by() { if let Some(attacker) = get_entity_by_id(by.uid().0, read_data) { if agent.target.is_none() { - controller.push_event(ControlEvent::Utterance(UtteranceKind::Angry)); + controller.push_utterance(UtteranceKind::Angry); } agent.target = Some(Target::new(attacker, true, read_data.time.0, true)); From 027154a5be9b7a21724c5abe4b259f8a41a35c9e Mon Sep 17 00:00:00 2001 From: "Dr. Dystopia" Date: Wed, 26 Jan 2022 21:16:29 +0100 Subject: [PATCH 7/8] Create 'push_invite_response' function --- common/src/comp/controller.rs | 4 ++++ server/src/sys/agent.rs | 7 +++---- 2 files changed, 7 insertions(+), 4 deletions(-) diff --git a/common/src/comp/controller.rs b/common/src/comp/controller.rs index 25ac92a17d..542b66f9f5 100644 --- a/common/src/comp/controller.rs +++ b/common/src/comp/controller.rs @@ -284,6 +284,10 @@ impl Controller { self.push_event(ControlEvent::Utterance(utterance)); } + pub fn push_invite_response(&mut self, invite_response: InviteResponse) { + self.push_event(ControlEvent::InviteResponse(invite_response)); + } + pub fn push_action(&mut self, action: ControlAction) { self.actions.push(action); } pub fn push_basic_input(&mut self, input: InputKind) { diff --git a/server/src/sys/agent.rs b/server/src/sys/agent.rs index 4ace5ebd7f..787e41faa7 100644 --- a/server/src/sys/agent.rs +++ b/server/src/sys/agent.rs @@ -1173,12 +1173,11 @@ impl<'a> AgentData<'a> { agent.target = Some(Target::new(target, false, read_data.time.0, false)); } - controller.push_event(ControlEvent::InviteResponse(InviteResponse::Accept)); + controller.push_invite_response(InviteResponse::Accept); agent.behavior.unset(BehaviorState::TRADING_ISSUER); agent.behavior.set(BehaviorState::TRADING); } else { - controller - .push_event(ControlEvent::InviteResponse(InviteResponse::Decline)); + controller.push_invite_response(InviteResponse::Decline); self.chat_npc_if_allowed_to_speak( "npc.speech.merchant_busy", agent, @@ -1187,7 +1186,7 @@ impl<'a> AgentData<'a> { } } else { // TODO: Provide a hint where to find the closest merchant? - controller.push_event(ControlEvent::InviteResponse(InviteResponse::Decline)); + controller.push_invite_response(InviteResponse::Decline); self.chat_npc_if_allowed_to_speak( "npc.speech.villager_decline_trade", agent, From b0d6a68e8ca8491ecf990fbc6f4c1fac2d14d23c Mon Sep 17 00:00:00 2001 From: "Dr. Dystopia" Date: Wed, 26 Jan 2022 21:23:37 +0100 Subject: [PATCH 8/8] Create 'push_initiate_invite' function --- common/src/comp/controller.rs | 4 ++++ server/src/sys/agent.rs | 10 ++-------- 2 files changed, 6 insertions(+), 8 deletions(-) diff --git a/common/src/comp/controller.rs b/common/src/comp/controller.rs index 542b66f9f5..59425332d7 100644 --- a/common/src/comp/controller.rs +++ b/common/src/comp/controller.rs @@ -288,6 +288,10 @@ impl Controller { self.push_event(ControlEvent::InviteResponse(invite_response)); } + pub fn push_initiate_invite(&mut self, uid: Uid, invite: InviteKind) { + self.push_event(ControlEvent::InitiateInvite(uid, invite)); + } + pub fn push_action(&mut self, action: ControlAction) { self.actions.push(action); } pub fn push_basic_input(&mut self, input: InputKind) { diff --git a/server/src/sys/agent.rs b/server/src/sys/agent.rs index 787e41faa7..7db3f71df8 100644 --- a/server/src/sys/agent.rs +++ b/server/src/sys/agent.rs @@ -1015,10 +1015,7 @@ impl<'a> AgentData<'a> { self.chat_npc(msg, event_emitter); } else if agent.behavior.can_trade() { if !agent.behavior.is(BehaviorState::TRADING) { - controller.push_event(ControlEvent::InitiateInvite( - by, - InviteKind::Trade, - )); + controller.push_initiate_invite(by, InviteKind::Trade); self.chat_npc( "npc.speech.merchant_advertisement", event_emitter, @@ -1036,10 +1033,7 @@ impl<'a> AgentData<'a> { Subject::Trade => { if agent.behavior.can_trade() { if !agent.behavior.is(BehaviorState::TRADING) { - controller.push_event(ControlEvent::InitiateInvite( - by, - InviteKind::Trade, - )); + controller.push_initiate_invite(by, InviteKind::Trade); self.chat_npc( "npc.speech.merchant_advertisement", event_emitter,