Remove HTN ComponentReference (#19480)

This commit is contained in:
metalgearsloth
2023-08-25 17:05:21 +10:00
committed by GitHub
parent 2185a2bf45
commit b5afb96bbd
4 changed files with 21 additions and 21 deletions

View File

@@ -1,13 +1,12 @@
using Content.Shared.NPC;
namespace Content.Server.NPC.Components
namespace Content.Server.NPC.Components;
public abstract partial class NPCComponent : SharedNPCComponent
{
public abstract partial class NPCComponent : SharedNPCComponent
{
/// <summary>
/// Contains all of the world data for a particular NPC in terms of how it sees the world.
/// </summary>
[DataField("blackboard", customTypeSerializer: typeof(NPCBlackboardSerializer))]
public NPCBlackboard Blackboard = new();
}
/// <summary>
/// Contains all of the world data for a particular NPC in terms of how it sees the world.
/// </summary>
[DataField("blackboard", customTypeSerializer: typeof(NPCBlackboardSerializer))]
public NPCBlackboard Blackboard = new();
}

View File

@@ -3,7 +3,7 @@ using Content.Server.NPC.Components;
namespace Content.Server.NPC.HTN;
[RegisterComponent, ComponentReference(typeof(NPCComponent))]
[RegisterComponent]
public sealed partial class HTNComponent : NPCComponent
{
/// <summary>

View File

@@ -8,8 +8,10 @@ using Content.Server.NPC.Components;
using Content.Server.NPC.HTN.PrimitiveTasks;
using Content.Server.NPC.Systems;
using Content.Shared.Administration;
using Content.Shared.Mobs;
using Content.Shared.NPC;
using JetBrains.Annotations;
using Robust.Server.GameObjects;
using Robust.Server.Player;
using Robust.Shared.Players;
using Robust.Shared.Prototypes;
@@ -32,6 +34,10 @@ public sealed class HTNSystem : EntitySystem
public override void Initialize()
{
base.Initialize();
SubscribeLocalEvent<HTNComponent, MobStateChangedEvent>(_npc.OnMobStateChange);
SubscribeLocalEvent<HTNComponent, MapInitEvent>(_npc.OnNPCMapInit);
SubscribeLocalEvent<HTNComponent, PlayerAttachedEvent>(_npc.OnPlayerNPCAttach);
SubscribeLocalEvent<HTNComponent, PlayerDetachedEvent>(_npc.OnPlayerNPCDetach);
SubscribeLocalEvent<HTNComponent, ComponentShutdown>(OnHTNShutdown);
SubscribeNetworkEvent<RequestHTNMessage>(OnHTNMessage);
@@ -132,6 +138,7 @@ public sealed class HTNSystem : EntitySystem
private void OnHTNShutdown(EntityUid uid, HTNComponent component, ComponentShutdown args)
{
_npc.OnNPCShutdown(uid, component, args);
component.PlanningToken?.Cancel();
component.PlanningJob = null;
}

View File

@@ -12,7 +12,6 @@ namespace Content.Server.NPC.Systems
/// <summary>
/// Handles NPCs running every tick.
/// </summary>
[UsedImplicitly]
public sealed partial class NPCSystem : EntitySystem
{
[Dependency] private readonly IConfigurationManager _configurationManager = default!;
@@ -33,21 +32,16 @@ namespace Content.Server.NPC.Systems
{
base.Initialize();
SubscribeLocalEvent<NPCComponent, MobStateChangedEvent>(OnMobStateChange);
SubscribeLocalEvent<NPCComponent, MapInitEvent>(OnNPCMapInit);
SubscribeLocalEvent<NPCComponent, ComponentShutdown>(OnNPCShutdown);
SubscribeLocalEvent<NPCComponent, PlayerAttachedEvent>(OnPlayerNPCAttach);
SubscribeLocalEvent<NPCComponent, PlayerDetachedEvent>(OnPlayerNPCDetach);
_configurationManager.OnValueChanged(CCVars.NPCEnabled, SetEnabled, true);
_configurationManager.OnValueChanged(CCVars.NPCMaxUpdates, SetMaxUpdates, true);
}
private void OnPlayerNPCAttach(EntityUid uid, NPCComponent component, PlayerAttachedEvent args)
public void OnPlayerNPCAttach(EntityUid uid, NPCComponent component, PlayerAttachedEvent args)
{
SleepNPC(uid, component);
}
private void OnPlayerNPCDetach(EntityUid uid, NPCComponent component, PlayerDetachedEvent args)
public void OnPlayerNPCDetach(EntityUid uid, NPCComponent component, PlayerDetachedEvent args)
{
if (_mobState.IsIncapacitated(uid) || TerminatingOrDeleted(uid))
return;
@@ -65,13 +59,13 @@ namespace Content.Server.NPC.Systems
_configurationManager.UnsubValueChanged(CCVars.NPCMaxUpdates, SetMaxUpdates);
}
private void OnNPCMapInit(EntityUid uid, NPCComponent component, MapInitEvent args)
public void OnNPCMapInit(EntityUid uid, NPCComponent component, MapInitEvent args)
{
component.Blackboard.SetValue(NPCBlackboard.Owner, uid);
WakeNPC(uid, component);
}
private void OnNPCShutdown(EntityUid uid, NPCComponent component, ComponentShutdown args)
public void OnNPCShutdown(EntityUid uid, NPCComponent component, ComponentShutdown args)
{
SleepNPC(uid, component);
}
@@ -134,7 +128,7 @@ namespace Content.Server.NPC.Systems
_htn.UpdateNPC(ref _count, _maxUpdates, frameTime);
}
private void OnMobStateChange(EntityUid uid, NPCComponent component, MobStateChangedEvent args)
public void OnMobStateChange(EntityUid uid, NPCComponent component, MobStateChangedEvent args)
{
if (HasComp<ActorComponent>(uid))
return;