Files
VMSolidus 4a64a31bd3 Variable NPC Juke Aggression (#935)
# Description

This PR un-hardcodes the JukeSystem timer, such that individual NPC HTN
Blackboards can directly state how often, and how far they wish to juke.
The effect of this is that NPCs are no longer completely impossible to
hit with left-clicks in melee combat, while also allowing for more
"Elite" enemies that juke more aggressively and more often to be
created.

Additionally, by introducing an exit condition based on this new "Juke
Cooldown", I have made the Juke Operator run a metric shitload of
expensive calculations 5000 times less often.

<details><summary><h1>Media</h1></summary>
<p>

Melee enemy with the new default juke settings, 0.5 second juke
duration, with 5 second juke Cooldown. The reagent slime will attempt to
close to melee with its enemy, but will now only attempt to evade melee
attacks once per 5 seconds. They will otherwise attempt to stay within
melee range.


https://github.com/user-attachments/assets/653e2064-e404-4be6-a958-da43096de502

</p>
</details>

# Changelog

🆑
- tweak: JukeOperator now allows for JukeDuration and JukeCooldown
arguments. JukeCooldown is a new feature where enemies must wait an
amount of time in seconds equal to the JukeCooldown, before they are
allowed to attempt to dodge a melee attack.
- tweak: By default, NPCs will only attempt to dodge attacks once every
5 seconds.
- fix: JukeOperator now performs extremely expensive math 5000 times
less often. EXIT CONDITIONS PEOPLE!
2024-10-19 13:12:12 +07:00

46 lines
1.4 KiB
C#

using Content.Server.NPC.Components;
namespace Content.Server.NPC.HTN.PrimitiveTasks.Operators.Combat;
public sealed partial class JukeOperator : HTNOperator, IHtnConditionalShutdown
{
[Dependency] private readonly IEntityManager _entManager = default!;
[DataField]
public JukeType JukeType = JukeType.AdjacentTile;
[DataField]
public HTNPlanState ShutdownState { get; private set; } = HTNPlanState.PlanFinished;
/// <summary>
/// Controls how long(in seconds) the NPC will move while juking.
/// </summary>
[DataField]
public float JukeDuration = 0.5f;
/// <summary>
/// Controls how often (in seconds) an NPC will try to juke.
/// </summary>
[DataField]
public float JukeCooldown = 3f;
public override void Startup(NPCBlackboard blackboard)
{
base.Startup(blackboard);
var juke = _entManager.EnsureComponent<NPCJukeComponent>(blackboard.GetValue<EntityUid>(NPCBlackboard.Owner));
juke.JukeType = JukeType;
juke.JukeDuration = JukeDuration;
juke.JukeCooldown = JukeCooldown;
}
public override HTNOperatorStatus Update(NPCBlackboard blackboard, float frameTime)
{
return HTNOperatorStatus.Finished;
}
public void ConditionalShutdown(NPCBlackboard blackboard)
{
_entManager.RemoveComponent<NPCJukeComponent>(blackboard.GetValue<EntityUid>(NPCBlackboard.Owner));
}
}