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;
[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()
{
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)
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);
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);
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);
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);
}
}