worldboss_aggro_fix

This commit is contained in:
flo 2024-06-03 06:52:13 +00:00
parent a168ea8dcd
commit 8863ea53c4
4 changed files with 31 additions and 14 deletions

View File

@ -274,6 +274,10 @@ pub struct Psyche {
/// wandering behavior in the idle state, and scaling `aggro_dist` in /// wandering behavior in the idle state, and scaling `aggro_dist` in
/// certain situations. /// certain situations.
pub aggro_range_multiplier: f32, pub aggro_range_multiplier: f32,
/// Whether this entity should *intelligently* decide to loose aggro based
/// on distance from agent home and health, this is not suitable for world
/// bosses and roaming entities
pub should_stop_pursuing: bool,
} }
impl<'a> From<&'a Body> for Psyche { impl<'a> From<&'a Body> for Psyche {
@ -425,6 +429,13 @@ impl<'a> From<&'a Body> for Psyche {
}, },
idle_wander_factor: 1.0, idle_wander_factor: 1.0,
aggro_range_multiplier: 1.0, aggro_range_multiplier: 1.0,
should_stop_pursuing: match body {
Body::BirdLarge(_) => false,
Body::BipedLarge(biped_large) => {
!matches!(biped_large.species, biped_large::Species::Gigasfrost)
},
_ => true,
},
} }
} }
} }

View File

@ -994,14 +994,15 @@ impl<'a> AgentData<'a> {
controller.push_utterance(UtteranceKind::Surprised); controller.push_utterance(UtteranceKind::Surprised);
} }
} }
if agent.psyche.should_stop_pursuing || target.is_some() {
agent.target = target.map(|(entity, attack_target)| Target { agent.target = target.map(|(entity, attack_target)| Target {
target: entity, target: entity,
hostile: attack_target, hostile: attack_target,
selected_at: read_data.time.0, selected_at: read_data.time.0,
aggro_on, aggro_on,
last_known_pos: get_pos(entity).map(|pos| pos.0), last_known_pos: get_pos(entity).map(|pos| pos.0),
}) })
}
} }
pub fn attack( pub fn attack(

View File

@ -80,11 +80,12 @@ pub fn stop_pursuing(
dur_since_last_attacked: f64, dur_since_last_attacked: f64,
psyche: &Psyche, psyche: &Psyche,
) -> bool { ) -> bool {
should_let_target_escape( psyche.should_stop_pursuing
dist_to_home_sqrd, && should_let_target_escape(
dur_since_last_attacked, dist_to_home_sqrd,
own_health_fraction, dur_since_last_attacked,
) > should_continue_to_pursue(dist_to_target_sqrd, psyche, target_health_fraction) own_health_fraction,
) > should_continue_to_pursue(dist_to_target_sqrd, psyche, target_health_fraction)
} }
/// Scores the benefit of continuing the pursue in value from 0 to infinity. /// Scores the benefit of continuing the pursue in value from 0 to infinity.

View File

@ -855,7 +855,7 @@ fn do_combat(bdata: &mut BehaviorData) -> bool {
let is_time_to_retarget = let is_time_to_retarget =
read_data.time.0 - selected_at > RETARGETING_THRESHOLD_SECONDS; read_data.time.0 - selected_at > RETARGETING_THRESHOLD_SECONDS;
if !in_aggro_range && is_time_to_retarget { if (!agent.psyche.should_stop_pursuing || !in_aggro_range) && is_time_to_retarget {
agent_data.choose_target( agent_data.choose_target(
agent, agent,
controller, controller,
@ -889,6 +889,10 @@ fn do_combat(bdata: &mut BehaviorData) -> bool {
} }
} }
} }
// make sure world bosses and roaming entities stay aware, to continue pursuit
if !agent.psyche.should_stop_pursuing {
bdata.agent.awareness.set_maximally_aware();
}
} }
false false
} }