From 0ea194bbafef1e48281fd7875372dfb65353c25f Mon Sep 17 00:00:00 2001 From: DEATHB4DEFEAT Date: Sat, 16 Dec 2023 23:24:23 -0800 Subject: [PATCH] system no longer infinitely adds functions infinitely adding entity queries which freezes the game --- .../Speech/Systems/RandomBarkSystem.cs | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/Content.Server/SimpleStation14/Speech/Systems/RandomBarkSystem.cs b/Content.Server/SimpleStation14/Speech/Systems/RandomBarkSystem.cs index da39bc92be..0d42a0deb2 100644 --- a/Content.Server/SimpleStation14/Speech/Systems/RandomBarkSystem.cs +++ b/Content.Server/SimpleStation14/Speech/Systems/RandomBarkSystem.cs @@ -9,7 +9,8 @@ public sealed class RandomBarkSystem : EntitySystem { [Dependency] private readonly IRobustRandom _random = default!; [Dependency] private readonly ChatSystem _chat = default!; - [Dependency] private readonly EntityManager _entities = default!; + [Dependency] private readonly EntityManager _entity = default!; + public override void Initialize() { @@ -18,7 +19,8 @@ public override void Initialize() SubscribeLocalEvent(OnInit); } - public void OnInit(EntityUid uid, RandomBarkComponent barker, ComponentInit args) + + private void OnInit(EntityUid uid, RandomBarkComponent barker, ComponentInit args) { barker.BarkAccumulator = _random.NextFloat(barker.MinTime, barker.MaxTime)*barker.BarkMultiplier; } @@ -27,18 +29,19 @@ public override void Update(float frameTime) { base.Update(frameTime); - while (EntityQueryEnumerator().MoveNext(out var uid, out var barker)) + var query = EntityQueryEnumerator(); + while (query.MoveNext(out var uid, out var barker)) { barker.BarkAccumulator -= frameTime; if (barker.BarkAccumulator > 0) continue; - barker.BarkAccumulator = _random.NextFloat(barker.MinTime, barker.MaxTime)*barker.BarkMultiplier; - if (_entities.TryGetComponent(uid, out var actComp) && + barker.BarkAccumulator = _random.NextFloat(barker.MinTime, barker.MaxTime) * barker.BarkMultiplier; + if (_entity.TryGetComponent(uid, out var actComp) && actComp.HasMind) continue; - _chat.TrySendInGameICMessage(uid, _random.Pick(barker.Barks), InGameICChatType.Speak, barker.Chatlog ? ChatTransmitRange.Normal : ChatTransmitRange.HideChat); + _chat.TrySendInGameICMessage(uid, _random.Pick(barker.Barks), InGameICChatType.Speak, barker.ChatLog ? ChatTransmitRange.Normal : ChatTransmitRange.HideChat); } } }