* Update RobustToolbox * Transition direct type usages * More updates * Fix invalid use of to map * Update RobustToolbox * Fix dropping items * Rename name usages of "GridCoordinates" to "EntityCoordinates" * Revert "Update RobustToolbox" This reverts commit 9f334a17c5908ded0043a63158bb671e4aa3f346. * Revert "Update RobustToolbox" This reverts commit 3a9c8cfa3606fa501aa84407796d2ad920853a09. # Conflicts: # RobustToolbox * Fix cursed IMapGrid method usage. * GridTileLookupTest now uses EntityCoordinates Co-authored-by: Víctor Aguilera Puerto <6766154+Zumorica@users.noreply.github.com> Co-authored-by: Víctor Aguilera Puerto <zddm@outlook.es>
40 lines
1.2 KiB
C#
40 lines
1.2 KiB
C#
using System.Collections.Generic;
|
|
using Content.Server.GameObjects.Components.Movement;
|
|
using Content.Shared.GameObjects.Components.Damage;
|
|
using JetBrains.Annotations;
|
|
using Robust.Server.Interfaces.Player;
|
|
using Robust.Shared.Interfaces.GameObjects;
|
|
using Robust.Shared.IoC;
|
|
|
|
namespace Content.Server.AI.WorldState.States.Mobs
|
|
{
|
|
[UsedImplicitly]
|
|
public sealed class NearbyPlayersState : CachedStateData<List<IEntity>>
|
|
{
|
|
public override string Name => "NearbyPlayers";
|
|
|
|
protected override List<IEntity> GetTrueValue()
|
|
{
|
|
var result = new List<IEntity>();
|
|
|
|
if (!Owner.TryGetComponent(out AiControllerComponent controller))
|
|
{
|
|
return result;
|
|
}
|
|
|
|
var playerManager = IoCManager.Resolve<IPlayerManager>();
|
|
var nearbyPlayers = playerManager.GetPlayersInRange(Owner.Transform.Coordinates, (int) controller.VisionRadius);
|
|
|
|
foreach (var player in nearbyPlayers)
|
|
{
|
|
if (player.AttachedEntity != Owner && player.AttachedEntity.HasComponent<IDamageableComponent>())
|
|
{
|
|
result.Add(player.AttachedEntity);
|
|
}
|
|
}
|
|
|
|
return result;
|
|
}
|
|
}
|
|
}
|