Add TryGetNpc (#19553)

This commit is contained in:
metalgearsloth
2023-08-26 13:45:29 +10:00
committed by GitHub
parent d1eea3f6f6
commit 7dbd8f8b7a
3 changed files with 20 additions and 6 deletions

View File

@@ -641,7 +641,7 @@ public sealed partial class PathfindingSystem
} }
} }
// _sawmill.Debug($"Built breadcrumbs in {sw.Elapsed.TotalMilliseconds}ms"); // Log.Debug($"Built breadcrumbs in {sw.Elapsed.TotalMilliseconds}ms");
SendBreadcrumbs(chunk, grid.Owner); SendBreadcrumbs(chunk, grid.Owner);
} }
@@ -827,7 +827,7 @@ public sealed partial class PathfindingSystem
} }
} }
// _sawmill.Debug($"Built navmesh in {sw.Elapsed.TotalMilliseconds}ms"); // Log.Debug($"Built navmesh in {sw.Elapsed.TotalMilliseconds}ms");
SendPolys(chunk, component.Owner, chunkPolys); SendPolys(chunk, component.Owner, chunkPolys);
} }

View File

@@ -6,6 +6,7 @@ using System.Threading.Tasks;
using Content.Server.Administration.Managers; using Content.Server.Administration.Managers;
using Content.Server.Destructible; using Content.Server.Destructible;
using Content.Server.NPC.HTN; using Content.Server.NPC.HTN;
using Content.Server.NPC.Systems;
using Content.Shared.Administration; using Content.Shared.Administration;
using Content.Shared.NPC; using Content.Shared.NPC;
using Robust.Server.Player; using Robust.Server.Player;
@@ -44,10 +45,9 @@ namespace Content.Server.NPC.Pathfinding
[Dependency] private readonly DestructibleSystem _destructible = default!; [Dependency] private readonly DestructibleSystem _destructible = default!;
[Dependency] private readonly EntityLookupSystem _lookup = default!; [Dependency] private readonly EntityLookupSystem _lookup = default!;
[Dependency] private readonly FixtureSystem _fixtures = default!; [Dependency] private readonly FixtureSystem _fixtures = default!;
[Dependency] private readonly NPCSystem _npc = default!;
[Dependency] private readonly SharedPhysicsSystem _physics = default!; [Dependency] private readonly SharedPhysicsSystem _physics = default!;
private ISawmill _sawmill = default!;
private readonly Dictionary<ICommonSession, PathfindingDebugMode> _subscribedSessions = new(); private readonly Dictionary<ICommonSession, PathfindingDebugMode> _subscribedSessions = new();
[ViewVariables] [ViewVariables]
@@ -66,7 +66,6 @@ namespace Content.Server.NPC.Pathfinding
public override void Initialize() public override void Initialize()
{ {
base.Initialize(); base.Initialize();
_sawmill = Logger.GetSawmill("nav");
_playerManager.PlayerStatusChanged += OnPlayerChange; _playerManager.PlayerStatusChanged += OnPlayerChange;
InitializeGrid(); InitializeGrid();
SubscribeNetworkEvent<RequestPathfindingDebugMessage>(OnBreadcrumbs); SubscribeNetworkEvent<RequestPathfindingDebugMessage>(OnBreadcrumbs);
@@ -418,7 +417,7 @@ namespace Content.Server.NPC.Pathfinding
public PathFlags GetFlags(EntityUid uid) public PathFlags GetFlags(EntityUid uid)
{ {
if (!TryComp<HTNComponent>(uid, out var npc)) if (!_npc.TryGetNpc(uid, out var npc))
{ {
return PathFlags.None; return PathFlags.None;
} }

View File

@@ -1,3 +1,4 @@
using System.Diagnostics.CodeAnalysis;
using Content.Server.NPC.Components; using Content.Server.NPC.Components;
using Content.Server.NPC.HTN; using Content.Server.NPC.HTN;
using Content.Shared.CCVar; using Content.Shared.CCVar;
@@ -77,6 +78,20 @@ namespace Content.Server.NPC.Systems
return Resolve(uid, ref active, false); return Resolve(uid, ref active, false);
} }
public bool TryGetNpc(EntityUid uid, [NotNullWhen(true)] out NPCComponent? component)
{
// If you add your own NPC components then add them here.
if (TryComp<HTNComponent>(uid, out var htn))
{
component = htn;
return true;
}
component = null;
return false;
}
/// <summary> /// <summary>
/// Allows the NPC to actively be updated. /// Allows the NPC to actively be updated.
/// </summary> /// </summary>