Files
tbd-station-14/Content.Server/NPC/Systems/NPCImprintingOnSpawnBehaviourSystem.cs
Ed f3a97fc0c5 Killer tomatoes (#26053)
* make tomatoes

* many friends! many mommies

* finish

* renaming system

* fix

* Update miscellaneous.yml

* Update Content.Server/NPC/Systems/NPCImpritingBehaviourSystem.cs

Co-authored-by: faint <46868845+ficcialfaint@users.noreply.github.com>

* N

* deleete exception?

* merge conflict fix

* fix?

* fuck you

* sloth fixes

* fixess?

* fix

---------

Co-authored-by: faint <46868845+ficcialfaint@users.noreply.github.com>
Co-authored-by: metalgearsloth <comedian_vs_clown@hotmail.com>
2024-04-18 21:21:56 +10:00

50 lines
1.8 KiB
C#

using System.Numerics;
using Content.Shared.NPC.Components;
using Content.Shared.NPC.Systems;
using Robust.Shared.Collections;
using Robust.Shared.Map;
using Robust.Shared.Random;
using NPCImprintingOnSpawnBehaviourComponent = Content.Server.NPC.Components.NPCImprintingOnSpawnBehaviourComponent;
namespace Content.Server.NPC.Systems;
public sealed partial class NPCImprintingOnSpawnBehaviourSystem : SharedNPCImprintingOnSpawnBehaviourSystem
{
[Dependency] private readonly EntityLookupSystem _lookup = default!;
[Dependency] private readonly NPCSystem _npc = default!;
[Dependency] private readonly IRobustRandom _random = default!;
public override void Initialize()
{
base.Initialize();
SubscribeLocalEvent<NPCImprintingOnSpawnBehaviourComponent, MapInitEvent>(OnMapInit);
}
private void OnMapInit(Entity<NPCImprintingOnSpawnBehaviourComponent> imprinting, ref MapInitEvent args)
{
HashSet<EntityUid> friends = new();
_lookup.GetEntitiesInRange(imprinting, imprinting.Comp.SpawnFriendsSearchRadius, friends);
foreach (var friend in friends)
{
if (imprinting.Comp.Whitelist?.IsValid(friend) != false)
{
AddImprintingTarget(imprinting, friend, imprinting.Comp);
}
}
if (imprinting.Comp.Follow && imprinting.Comp.Friends.Count > 0)
{
var mommy = _random.Pick(imprinting.Comp.Friends);
_npc.SetBlackboard(imprinting, NPCBlackboard.FollowTarget, new EntityCoordinates(mommy, Vector2.Zero));
}
}
public void AddImprintingTarget(EntityUid entity, EntityUid friend, NPCImprintingOnSpawnBehaviourComponent component)
{
component.Friends.Add(friend);
var exception = EnsureComp<FactionExceptionComponent>(entity);
exception.Ignored.Add(friend);
}
}