using Content.Shared.Kudzu; using Robust.Server.GameObjects; using Robust.Shared.GameObjects; using Robust.Shared.IoC; using Robust.Shared.Log; using Robust.Shared.Random; namespace Content.Server.Kudzu; public sealed class GrowingKudzuSystem : EntitySystem { [Dependency] private readonly IRobustRandom _robustRandom = default!; private float _accumulatedFrameTime = 0.0f; public override void Initialize() { SubscribeLocalEvent(SetupKudzu); } private void SetupKudzu(EntityUid uid, GrowingKudzuComponent component, ComponentAdd args) { if (!EntityManager.TryGetComponent(uid, out var appearance)) { return; } appearance.SetData(KudzuVisuals.Variant, _robustRandom.Next(1, 3)); appearance.SetData(KudzuVisuals.GrowthLevel, 1); } public override void Update(float frameTime) { _accumulatedFrameTime += frameTime; if (!(_accumulatedFrameTime >= 0.5f)) return; _accumulatedFrameTime -= 0.5f; foreach (var (kudzu, appearance) in EntityManager.EntityQuery()) { if (kudzu.GrowthLevel >= 3 || !_robustRandom.Prob(kudzu.GrowthTickSkipChange)) continue; kudzu.GrowthLevel += 1; if (kudzu.GrowthLevel == 3 && EntityManager.TryGetComponent((kudzu).Owner, out var spreader)) { // why cache when you can simply cease to be? Also saves a bit of memory/time. EntityManager.RemoveComponent((kudzu).Owner); } appearance.SetData(KudzuVisuals.GrowthLevel, kudzu.GrowthLevel); } } }