SharedKitchenSpikeSystem bugfixes (#39959)

* Fixes

* Update

* Update
This commit is contained in:
Winkarst-cpu
2025-08-30 19:52:34 +03:00
committed by GitHub
parent 5a40913beb
commit 4a6fc71d07

View File

@@ -17,11 +17,11 @@ using Content.Shared.Mobs.Systems;
using Content.Shared.Movement.Events;
using Content.Shared.Nutrition.Components;
using Content.Shared.Popups;
using Content.Shared.Random.Helpers;
using Content.Shared.Throwing;
using Content.Shared.Verbs;
using Robust.Shared.Audio.Systems;
using Robust.Shared.Containers;
using Robust.Shared.Random;
using Robust.Shared.Serialization;
using Robust.Shared.Timing;
@@ -44,7 +44,6 @@ public sealed class SharedKitchenSpikeSystem : EntitySystem
[Dependency] private readonly SharedAudioSystem _audioSystem = default!;
[Dependency] private readonly SharedBodySystem _bodySystem = default!;
[Dependency] private readonly IGameTiming _gameTiming = default!;
[Dependency] private readonly IRobustRandom _random = default!;
public override void Initialize()
{
@@ -81,7 +80,7 @@ public sealed class SharedKitchenSpikeSystem : EntitySystem
private void OnInit(Entity<KitchenSpikeComponent> ent, ref ComponentInit args)
{
ent.Comp.BodyContainer = _containerSystem.EnsureContainer<ContainerSlot>(ent, ent.Comp.ContainerId);
ent.Comp.BodyContainer = _containerSystem.EnsureContainer<ContainerSlot>(ent, ent.Comp.ContainerId);
}
private void OnInsertAttempt(Entity<KitchenSpikeComponent> ent, ref ContainerIsInsertingAttemptEvent args)
@@ -94,15 +93,24 @@ public sealed class SharedKitchenSpikeSystem : EntitySystem
private void OnEntInsertedIntoContainer(Entity<KitchenSpikeComponent> ent, ref EntInsertedIntoContainerMessage args)
{
if (_gameTiming.ApplyingState)
return;
EnsureComp<KitchenSpikeHookedComponent>(args.Entity);
_damageableSystem.TryChangeDamage(args.Entity, ent.Comp.SpikeDamage, true);
ent.Comp.NextDamage = _gameTiming.CurTime + ent.Comp.DamageInterval;
Dirty(ent);
// TODO: Add sprites for different species.
_appearanceSystem.SetData(ent.Owner, KitchenSpikeVisuals.Status, KitchenSpikeStatus.Bloody);
}
private void OnEntRemovedFromContainer(Entity<KitchenSpikeComponent> ent, ref EntRemovedFromContainerMessage args)
{
if (_gameTiming.ApplyingState)
return;
RemComp<KitchenSpikeHookedComponent>(args.Entity);
_damageableSystem.TryChangeDamage(args.Entity, ent.Comp.SpikeDamage, true);
@@ -263,7 +271,7 @@ public sealed class SharedKitchenSpikeSystem : EntitySystem
private void OnSpikeButcherDoAfter(Entity<KitchenSpikeComponent> ent, ref SpikeButcherDoAfterEvent args)
{
if (args.Handled || args.Cancelled || !args.Target.HasValue || !args.Used.HasValue || !TryComp<ButcherableComponent>(args.Target, out var butcherable) )
if (args.Handled || args.Cancelled || !args.Target.HasValue || !args.Used.HasValue || !TryComp<ButcherableComponent>(args.Target, out var butcherable))
return;
var victimIdentity = Identity.Entity(args.Target.Value, EntityManager);
@@ -275,7 +283,11 @@ public sealed class SharedKitchenSpikeSystem : EntitySystem
PopupType.MediumCaution);
// Get a random entry to spawn.
var index = _random.Next(butcherable.SpawnedEntities.Count);
// TODO: Replace with RandomPredicted once the engine PR is merged
var seed = SharedRandomExtensions.HashCodeCombine(new() { (int)_gameTiming.CurTick.Value, GetNetEntity(ent).Id });
var rand = new System.Random(seed);
var index = rand.Next(butcherable.SpawnedEntities.Count);
var entry = butcherable.SpawnedEntities[index];
var uid = PredictedSpawnNextToOrDrop(entry.PrototypeId, ent);
@@ -378,13 +390,18 @@ public sealed class SharedKitchenSpikeSystem : EntitySystem
while (query.MoveNext(out var uid, out var kitchenSpike))
{
var contained = kitchenSpike.BodyContainer.ContainedEntity;
if (!contained.HasValue)
continue;
if (kitchenSpike.NextDamage > _gameTiming.CurTime)
continue;
kitchenSpike.NextDamage += kitchenSpike.DamageInterval;
Dirty(uid, kitchenSpike);
_damageableSystem.TryChangeDamage(kitchenSpike.BodyContainer.ContainedEntity, kitchenSpike.TimeDamage, true);
_damageableSystem.TryChangeDamage(contained, kitchenSpike.TimeDamage, true);
}
}