Remove HTN ComponentReference (#19480)
This commit is contained in:
@@ -1,13 +1,12 @@
|
|||||||
using Content.Shared.NPC;
|
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>
|
/// <summary>
|
||||||
/// Contains all of the world data for a particular NPC in terms of how it sees the world.
|
/// Contains all of the world data for a particular NPC in terms of how it sees the world.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
[DataField("blackboard", customTypeSerializer: typeof(NPCBlackboardSerializer))]
|
[DataField("blackboard", customTypeSerializer: typeof(NPCBlackboardSerializer))]
|
||||||
public NPCBlackboard Blackboard = new();
|
public NPCBlackboard Blackboard = new();
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -3,7 +3,7 @@ using Content.Server.NPC.Components;
|
|||||||
|
|
||||||
namespace Content.Server.NPC.HTN;
|
namespace Content.Server.NPC.HTN;
|
||||||
|
|
||||||
[RegisterComponent, ComponentReference(typeof(NPCComponent))]
|
[RegisterComponent]
|
||||||
public sealed partial class HTNComponent : NPCComponent
|
public sealed partial class HTNComponent : NPCComponent
|
||||||
{
|
{
|
||||||
/// <summary>
|
/// <summary>
|
||||||
|
|||||||
@@ -8,8 +8,10 @@ using Content.Server.NPC.Components;
|
|||||||
using Content.Server.NPC.HTN.PrimitiveTasks;
|
using Content.Server.NPC.HTN.PrimitiveTasks;
|
||||||
using Content.Server.NPC.Systems;
|
using Content.Server.NPC.Systems;
|
||||||
using Content.Shared.Administration;
|
using Content.Shared.Administration;
|
||||||
|
using Content.Shared.Mobs;
|
||||||
using Content.Shared.NPC;
|
using Content.Shared.NPC;
|
||||||
using JetBrains.Annotations;
|
using JetBrains.Annotations;
|
||||||
|
using Robust.Server.GameObjects;
|
||||||
using Robust.Server.Player;
|
using Robust.Server.Player;
|
||||||
using Robust.Shared.Players;
|
using Robust.Shared.Players;
|
||||||
using Robust.Shared.Prototypes;
|
using Robust.Shared.Prototypes;
|
||||||
@@ -32,6 +34,10 @@ public sealed class HTNSystem : EntitySystem
|
|||||||
public override void Initialize()
|
public override void Initialize()
|
||||||
{
|
{
|
||||||
base.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);
|
SubscribeLocalEvent<HTNComponent, ComponentShutdown>(OnHTNShutdown);
|
||||||
SubscribeNetworkEvent<RequestHTNMessage>(OnHTNMessage);
|
SubscribeNetworkEvent<RequestHTNMessage>(OnHTNMessage);
|
||||||
|
|
||||||
@@ -132,6 +138,7 @@ public sealed class HTNSystem : EntitySystem
|
|||||||
|
|
||||||
private void OnHTNShutdown(EntityUid uid, HTNComponent component, ComponentShutdown args)
|
private void OnHTNShutdown(EntityUid uid, HTNComponent component, ComponentShutdown args)
|
||||||
{
|
{
|
||||||
|
_npc.OnNPCShutdown(uid, component, args);
|
||||||
component.PlanningToken?.Cancel();
|
component.PlanningToken?.Cancel();
|
||||||
component.PlanningJob = null;
|
component.PlanningJob = null;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -12,7 +12,6 @@ namespace Content.Server.NPC.Systems
|
|||||||
/// <summary>
|
/// <summary>
|
||||||
/// Handles NPCs running every tick.
|
/// Handles NPCs running every tick.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
[UsedImplicitly]
|
|
||||||
public sealed partial class NPCSystem : EntitySystem
|
public sealed partial class NPCSystem : EntitySystem
|
||||||
{
|
{
|
||||||
[Dependency] private readonly IConfigurationManager _configurationManager = default!;
|
[Dependency] private readonly IConfigurationManager _configurationManager = default!;
|
||||||
@@ -33,21 +32,16 @@ namespace Content.Server.NPC.Systems
|
|||||||
{
|
{
|
||||||
base.Initialize();
|
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.NPCEnabled, SetEnabled, true);
|
||||||
_configurationManager.OnValueChanged(CCVars.NPCMaxUpdates, SetMaxUpdates, 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);
|
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))
|
if (_mobState.IsIncapacitated(uid) || TerminatingOrDeleted(uid))
|
||||||
return;
|
return;
|
||||||
@@ -65,13 +59,13 @@ namespace Content.Server.NPC.Systems
|
|||||||
_configurationManager.UnsubValueChanged(CCVars.NPCMaxUpdates, SetMaxUpdates);
|
_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);
|
component.Blackboard.SetValue(NPCBlackboard.Owner, uid);
|
||||||
WakeNPC(uid, component);
|
WakeNPC(uid, component);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void OnNPCShutdown(EntityUid uid, NPCComponent component, ComponentShutdown args)
|
public void OnNPCShutdown(EntityUid uid, NPCComponent component, ComponentShutdown args)
|
||||||
{
|
{
|
||||||
SleepNPC(uid, component);
|
SleepNPC(uid, component);
|
||||||
}
|
}
|
||||||
@@ -134,7 +128,7 @@ namespace Content.Server.NPC.Systems
|
|||||||
_htn.UpdateNPC(ref _count, _maxUpdates, frameTime);
|
_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))
|
if (HasComp<ActorComponent>(uid))
|
||||||
return;
|
return;
|
||||||
|
|||||||
Reference in New Issue
Block a user