Remove SpreaderNodeGroup (#20230)
* Remove SpreaderNodeGroup * Fix airtight updates * more smoke stuff * more smoke fixes * wtf is smoke code * Fix merge * Fix divide by zero
This commit is contained in:
@@ -2,6 +2,7 @@ using Content.Shared.Damage;
|
||||
using Content.Shared.Spreader;
|
||||
using Robust.Shared.Random;
|
||||
using Robust.Shared.Timing;
|
||||
using Robust.Shared.Utility;
|
||||
|
||||
namespace Content.Server.Spreader;
|
||||
|
||||
@@ -13,7 +14,7 @@ public sealed class KudzuSystem : EntitySystem
|
||||
[Dependency] private readonly DamageableSystem _damageable = default!;
|
||||
|
||||
[ValidatePrototypeId<EdgeSpreaderPrototype>]
|
||||
private const string KudzuGroup = "kudzu";
|
||||
private const string KudzuGroup = "Kudzu";
|
||||
|
||||
/// <inheritdoc/>
|
||||
public override void Initialize()
|
||||
@@ -21,7 +22,6 @@ public sealed class KudzuSystem : EntitySystem
|
||||
SubscribeLocalEvent<KudzuComponent, ComponentStartup>(SetupKudzu);
|
||||
SubscribeLocalEvent<KudzuComponent, SpreadNeighborsEvent>(OnKudzuSpread);
|
||||
SubscribeLocalEvent<GrowingKudzuComponent, EntityUnpausedEvent>(OnKudzuUnpaused);
|
||||
SubscribeLocalEvent<SpreadGroupUpdateRate>(OnKudzuUpdateRate);
|
||||
SubscribeLocalEvent<KudzuComponent, DamageChangedEvent>(OnDamageChanged);
|
||||
}
|
||||
|
||||
@@ -36,59 +36,50 @@ public sealed class KudzuSystem : EntitySystem
|
||||
if (!TryComp(uid, out growing))
|
||||
{
|
||||
growing = AddComp<GrowingKudzuComponent>(uid);
|
||||
growing.GrowthLevel = 3;
|
||||
component.GrowthLevel = 3;
|
||||
}
|
||||
growing.GrowthLevel = Math.Max(1, growing.GrowthLevel - growthDamage);
|
||||
component.GrowthLevel = Math.Max(1, component.GrowthLevel - growthDamage);
|
||||
if (EntityManager.TryGetComponent<AppearanceComponent>(uid, out var appearance))
|
||||
{
|
||||
_appearance.SetData(uid, KudzuVisuals.GrowthLevel, growing.GrowthLevel, appearance);
|
||||
_appearance.SetData(uid, KudzuVisuals.GrowthLevel, component.GrowthLevel, appearance);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void OnKudzuSpread(EntityUid uid, KudzuComponent component, ref SpreadNeighborsEvent args)
|
||||
{
|
||||
if (TryComp<GrowingKudzuComponent>(uid, out var growing) && growing.GrowthLevel < 3)
|
||||
{
|
||||
if (component.GrowthLevel < 3)
|
||||
return;
|
||||
}
|
||||
|
||||
if (args.NeighborFreeTiles.Count == 0)
|
||||
{
|
||||
RemCompDeferred<EdgeSpreaderComponent>(uid);
|
||||
return;
|
||||
}
|
||||
|
||||
var prototype = MetaData(uid).EntityPrototype?.ID;
|
||||
|
||||
if (prototype == null)
|
||||
{
|
||||
RemCompDeferred<EdgeSpreaderComponent>(uid);
|
||||
RemCompDeferred<ActiveEdgeSpreaderComponent>(uid);
|
||||
return;
|
||||
}
|
||||
|
||||
if (!_robustRandom.Prob(component.SpreadChance))
|
||||
return;
|
||||
|
||||
var prototype = MetaData(uid).EntityPrototype?.ID;
|
||||
|
||||
if (prototype == null)
|
||||
{
|
||||
RemCompDeferred<ActiveEdgeSpreaderComponent>(uid);
|
||||
return;
|
||||
}
|
||||
|
||||
foreach (var neighbor in args.NeighborFreeTiles)
|
||||
{
|
||||
var neighborUid = Spawn(prototype, neighbor.Grid.GridTileToLocal(neighbor.Tile));
|
||||
EnsureComp<EdgeSpreaderComponent>(neighborUid);
|
||||
DebugTools.Assert(HasComp<EdgeSpreaderComponent>(neighborUid));
|
||||
DebugTools.Assert(HasComp<ActiveEdgeSpreaderComponent>(neighborUid));
|
||||
DebugTools.Assert(Comp<EdgeSpreaderComponent>(neighborUid).Id == KudzuGroup);
|
||||
args.Updates--;
|
||||
|
||||
if (args.Updates <= 0)
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
private void OnKudzuUpdateRate(ref SpreadGroupUpdateRate args)
|
||||
{
|
||||
if (args.Name != KudzuGroup)
|
||||
return;
|
||||
|
||||
args.UpdatesPerSecond = 1;
|
||||
}
|
||||
|
||||
private void OnKudzuUnpaused(EntityUid uid, GrowingKudzuComponent component, ref EntityUnpausedEvent args)
|
||||
{
|
||||
component.NextTick += args.PausedTime;
|
||||
@@ -109,24 +100,30 @@ public sealed class KudzuSystem : EntitySystem
|
||||
public override void Update(float frameTime)
|
||||
{
|
||||
var appearanceQuery = GetEntityQuery<AppearanceComponent>();
|
||||
var query = EntityQueryEnumerator<GrowingKudzuComponent, KudzuComponent>();
|
||||
var query = EntityQueryEnumerator<GrowingKudzuComponent>();
|
||||
var kudzuQuery = GetEntityQuery<KudzuComponent>();
|
||||
var damageableQuery = GetEntityQuery<DamageableComponent>();
|
||||
var curTime = _timing.CurTime;
|
||||
|
||||
while (query.MoveNext(out var uid, out var grow, out var kudzu))
|
||||
while (query.MoveNext(out var uid, out var grow))
|
||||
{
|
||||
if (grow.NextTick > curTime)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
grow.NextTick = curTime + TimeSpan.FromSeconds(0.5);
|
||||
|
||||
if (!kudzuQuery.TryGetComponent(uid, out var kudzu))
|
||||
{
|
||||
RemCompDeferred(uid, grow);
|
||||
continue;
|
||||
}
|
||||
|
||||
if (!_robustRandom.Prob(kudzu.GrowthTickChance))
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
if (TryComp<DamageableComponent>(uid, out var damage))
|
||||
if (damageableQuery.TryGetComponent(uid, out var damage))
|
||||
{
|
||||
if (damage.TotalDamage > 1.0)
|
||||
{
|
||||
@@ -146,17 +143,17 @@ public sealed class KudzuSystem : EntitySystem
|
||||
}
|
||||
}
|
||||
|
||||
grow.GrowthLevel += 1;
|
||||
kudzu.GrowthLevel += 1;
|
||||
|
||||
if (grow.GrowthLevel >= 3)
|
||||
if (kudzu.GrowthLevel >= 3)
|
||||
{
|
||||
// why cache when you can simply cease to be? Also saves a bit of memory/time.
|
||||
RemCompDeferred<GrowingKudzuComponent>(uid);
|
||||
RemCompDeferred(uid, grow);
|
||||
}
|
||||
|
||||
if (appearanceQuery.TryGetComponent(uid, out var appearance))
|
||||
{
|
||||
_appearance.SetData(uid, KudzuVisuals.GrowthLevel, grow.GrowthLevel, appearance);
|
||||
_appearance.SetData(uid, KudzuVisuals.GrowthLevel, kudzu.GrowthLevel, appearance);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user