NPC wake / sleep cleanup (#5679)

This commit is contained in:
metalgearsloth
2021-12-05 14:08:35 +11:00
committed by GitHub
parent ae65418c52
commit 5d63411113
10 changed files with 175 additions and 217 deletions

View File

@@ -3,6 +3,7 @@ using System.Collections.Generic;
using System.Runtime.ExceptionServices;
using System.Threading;
using Content.Server.AI.Components;
using Content.Server.AI.EntitySystems;
using Content.Server.AI.LoadBalancer;
using Content.Server.AI.Operators;
using Content.Server.AI.Utility.Actions;
@@ -59,33 +60,13 @@ namespace Content.Server.AI.Utility.AiLogic
private CancellationTokenSource? _actionCancellation;
/// <summary>
/// If we can't do anything then stop thinking; should probably use ActionBlocker instead
/// </summary>
private bool _isDead;
/*public void AfterDeserialization()
{
if (BehaviorSets.Count > 0)
{
var behaviorManager = IoCManager.Resolve<INpcBehaviorManager>();
foreach (var bSet in BehaviorSets)
{
behaviorManager.AddBehaviorSet(this, bSet, false);
}
behaviorManager.RebuildActions(this);
}
}*/
protected override void Initialize()
{
if (BehaviorSets.Count > 0)
{
var behaviorManager = IoCManager.Resolve<INpcBehaviorManager>();
behaviorManager.RebuildActions(this);
Owner.EntityManager.EventBus.RaiseEvent(EventSource.Local, new SleepAiMessage(this, false));
EntitySystem.Get<NPCSystem>().WakeNPC(this);
}
base.Initialize();
@@ -103,27 +84,6 @@ namespace Content.Server.AI.Utility.AiLogic
CurrentAction = null;
}
public void MobStateChanged(MobStateChangedMessage message)
{
var oldDeadState = _isDead;
_isDead = message.Component.IsIncapacitated();
if (oldDeadState != _isDead)
{
var entityManager = IoCManager.Resolve<IEntityManager>();
switch (_isDead)
{
case true:
entityManager.EventBus.RaiseEvent(EventSource.Local, new SleepAiMessage(this, true));
break;
case false:
entityManager.EventBus.RaiseEvent(EventSource.Local, new SleepAiMessage(this, false));
break;
}
}
}
private void ReceivedAction()
{
if (_actionRequest == null)

View File

@@ -84,9 +84,9 @@ namespace Content.Server.AI.Utility
if (rebuild)
RebuildActions(npc);
if (npc.BehaviorSets.Count == 1 && !EntitySystem.Get<AiSystem>().IsAwake(npc))
if (npc.BehaviorSets.Count == 1 && !npc.Awake)
{
_entityManager.EventBus.RaiseEvent(EventSource.Local, new SleepAiMessage(npc, false));
EntitySystem.Get<NPCSystem>().WakeNPC(npc);
}
}
@@ -113,9 +113,9 @@ namespace Content.Server.AI.Utility
if (rebuild)
RebuildActions(npc);
if (npc.BehaviorSets.Count == 0 && EntitySystem.Get<AiSystem>().IsAwake(npc))
if (npc.BehaviorSets.Count == 0 && npc.Awake)
{
_entityManager.EventBus.RaiseEvent(EventSource.Local, new SleepAiMessage(npc, true));
EntitySystem.Get<NPCSystem>().SleepNPC(npc);
}
}