Remove HTN ComponentReference (#19480)
This commit is contained in:
@@ -1,7 +1,7 @@
|
||||
using Content.Shared.NPC;
|
||||
|
||||
namespace Content.Server.NPC.Components
|
||||
{
|
||||
namespace Content.Server.NPC.Components;
|
||||
|
||||
public abstract partial class NPCComponent : SharedNPCComponent
|
||||
{
|
||||
/// <summary>
|
||||
@@ -10,4 +10,3 @@ namespace Content.Server.NPC.Components
|
||||
[DataField("blackboard", customTypeSerializer: typeof(NPCBlackboardSerializer))]
|
||||
public NPCBlackboard Blackboard = new();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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>
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
@@ -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;
|
||||
|
||||
Reference in New Issue
Block a user