Meat kudzu (from anomoly) more killable, telegraphs better (#16107)
This commit is contained in:
@@ -1,3 +1,4 @@
|
||||
using Content.Shared.Damage;
|
||||
using Content.Shared.Spreader;
|
||||
using Robust.Shared.Random;
|
||||
using Robust.Shared.Timing;
|
||||
@@ -9,6 +10,7 @@ public sealed class KudzuSystem : EntitySystem
|
||||
[Dependency] private readonly IGameTiming _timing = default!;
|
||||
[Dependency] private readonly IRobustRandom _robustRandom = default!;
|
||||
[Dependency] private readonly SharedAppearanceSystem _appearance = default!;
|
||||
[Dependency] private readonly DamageableSystem _damageable = default!;
|
||||
|
||||
private const string KudzuGroup = "kudzu";
|
||||
|
||||
@@ -19,6 +21,28 @@ public sealed class KudzuSystem : EntitySystem
|
||||
SubscribeLocalEvent<KudzuComponent, SpreadNeighborsEvent>(OnKudzuSpread);
|
||||
SubscribeLocalEvent<GrowingKudzuComponent, EntityUnpausedEvent>(OnKudzuUnpaused);
|
||||
SubscribeLocalEvent<SpreadGroupUpdateRate>(OnKudzuUpdateRate);
|
||||
SubscribeLocalEvent<KudzuComponent, DamageChangedEvent>(OnDamageChanged);
|
||||
}
|
||||
|
||||
private void OnDamageChanged(EntityUid uid, KudzuComponent component, DamageChangedEvent args)
|
||||
{
|
||||
// Every time we take any damage, we reduce growth depending on all damage over the growth impact
|
||||
// So the kudzu gets slower growing the more it is hurt.
|
||||
int growthDamage = (int) (args.Damageable.TotalDamage / component.GrowthHealth);
|
||||
if (growthDamage > 0)
|
||||
{
|
||||
GrowingKudzuComponent? growing;
|
||||
if (!TryComp<GrowingKudzuComponent>(uid, out growing))
|
||||
{
|
||||
growing = AddComp<GrowingKudzuComponent>(uid);
|
||||
growing.GrowthLevel = 3;
|
||||
}
|
||||
growing.GrowthLevel = Math.Max(1, growing.GrowthLevel - growthDamage);
|
||||
if (EntityManager.TryGetComponent<AppearanceComponent>(uid, out var appearance))
|
||||
{
|
||||
_appearance.SetData(uid, KudzuVisuals.GrowthLevel, growing.GrowthLevel, appearance);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void OnKudzuSpread(EntityUid uid, KudzuComponent component, ref SpreadNeighborsEvent args)
|
||||
@@ -83,32 +107,55 @@ public sealed class KudzuSystem : EntitySystem
|
||||
/// <inheritdoc/>
|
||||
public override void Update(float frameTime)
|
||||
{
|
||||
var query = EntityQueryEnumerator<GrowingKudzuComponent, AppearanceComponent>();
|
||||
var query = EntityQueryEnumerator<GrowingKudzuComponent, KudzuComponent>();
|
||||
var curTime = _timing.CurTime;
|
||||
|
||||
while (query.MoveNext(out var uid, out var kudzu, out var appearance))
|
||||
while (query.MoveNext(out var uid, out var grow, out var kudzu))
|
||||
{
|
||||
if (kudzu.NextTick > curTime)
|
||||
if (grow.NextTick > curTime)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
kudzu.NextTick = curTime + TimeSpan.FromSeconds(0.5);
|
||||
grow.NextTick = curTime + TimeSpan.FromSeconds(0.5);
|
||||
|
||||
if (!_robustRandom.Prob(kudzu.GrowthTickChance))
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
kudzu.GrowthLevel += 1;
|
||||
if (TryComp<DamageableComponent>(uid, out var damage))
|
||||
{
|
||||
if (damage.TotalDamage > 1.0)
|
||||
{
|
||||
if (kudzu.DamageRecovery != null)
|
||||
{
|
||||
// This kudzu features healing, so Gradually heal
|
||||
_damageable.TryChangeDamage(uid, kudzu.DamageRecovery, true);
|
||||
}
|
||||
if (damage.TotalDamage >= kudzu.GrowthBlock)
|
||||
{
|
||||
// Don't grow when quite damaged
|
||||
if (_robustRandom.Prob(0.95f))
|
||||
{
|
||||
continue;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (kudzu.GrowthLevel >= 3)
|
||||
grow.GrowthLevel += 1;
|
||||
|
||||
if (grow.GrowthLevel >= 3)
|
||||
{
|
||||
// why cache when you can simply cease to be? Also saves a bit of memory/time.
|
||||
RemCompDeferred<GrowingKudzuComponent>(uid);
|
||||
}
|
||||
|
||||
_appearance.SetData(uid, KudzuVisuals.GrowthLevel, kudzu.GrowthLevel, appearance);
|
||||
if (EntityManager.TryGetComponent<AppearanceComponent>(uid, out var appearance))
|
||||
{
|
||||
_appearance.SetData(uid, KudzuVisuals.GrowthLevel, grow.GrowthLevel, appearance);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user