Files

106 lines
4.3 KiB
C#
Raw Permalink Normal View History

2021-12-05 04:18:30 +01:00
using Content.Server.Fluids.EntitySystems;
using Content.Server.Nutrition.Components;
2021-09-26 15:18:45 +02:00
using Content.Server.Popups;
using Content.Shared.Containers.ItemSlots;
using Content.Shared.IdentityManagement;
using Content.Shared.Nutrition;
using Content.Shared.Nutrition.Components;
using Content.Shared.Nutrition.EntitySystems;
2022-09-14 19:30:56 +02:00
using Content.Shared.Rejuvenate;
using Content.Shared.Throwing;
2025-08-03 21:20:37 +02:00
using Content.Shared.Trigger.Components;
using Content.Shared.Trigger.Systems;
using Content.Shared.Chemistry.EntitySystems;
using JetBrains.Annotations;
using Robust.Shared.Audio;
using Robust.Shared.Audio.Systems;
using Robust.Shared.Player;
namespace Content.Server.Nutrition.EntitySystems
{
[UsedImplicitly]
public sealed class CreamPieSystem : SharedCreamPieSystem
{
[Dependency] private readonly IngestionSystem _ingestion = default!;
[Dependency] private readonly ItemSlotsSystem _itemSlots = default!;
[Dependency] private readonly PopupSystem _popup = default!;
[Dependency] private readonly PuddleSystem _puddle = default!;
[Dependency] private readonly SharedAudioSystem _audio = default!;
[Dependency] private readonly SharedSolutionContainerSystem _solutions = default!;
[Dependency] private readonly TriggerSystem _trigger = default!;
2022-09-14 19:30:56 +02:00
public override void Initialize()
{
base.Initialize();
// activate BEFORE entity is deleted and trash is spawned
SubscribeLocalEvent<CreamPieComponent, ConsumeDoAfterEvent>(OnConsume, before: [typeof(FoodSystem)]);
SubscribeLocalEvent<CreamPieComponent, SliceFoodEvent>(OnSlice);
2022-09-14 19:30:56 +02:00
SubscribeLocalEvent<CreamPiedComponent, RejuvenateEvent>(OnRejuvenate);
}
protected override void SplattedCreamPie(Entity<CreamPieComponent, EdibleComponent?> entity)
{
// The entity is deleted, so play the sound at its position rather than parenting
var coordinates = Transform(entity).Coordinates;
_audio.PlayPvs(_audio.ResolveSound(entity.Comp1.Sound), coordinates, AudioParams.Default.WithVariation(0.125f));
if (Resolve(entity, ref entity.Comp2, false))
{
if (_solutions.TryGetSolution(entity.Owner, entity.Comp2.Solution, out _, out var solution))
_puddle.TrySpillAt(entity.Owner, solution, out _, false);
_ingestion.SpawnTrash((entity, entity.Comp2));
}
ActivatePayload(entity);
QueueDel(entity);
}
private void OnConsume(Entity<CreamPieComponent> entity, ref ConsumeDoAfterEvent args)
{
ActivatePayload(entity);
}
private void OnSlice(Entity<CreamPieComponent> entity, ref SliceFoodEvent args)
{
ActivatePayload(entity);
}
private void ActivatePayload(EntityUid uid)
{
2023-04-10 15:37:03 +10:00
if (_itemSlots.TryGetSlot(uid, CreamPieComponent.PayloadSlotName, out var itemSlot))
{
2023-04-10 15:37:03 +10:00
if (_itemSlots.TryEject(uid, itemSlot, user: null, out var item))
{
2025-08-03 21:20:37 +02:00
if (TryComp<TimerTriggerComponent>(item.Value, out var timerTrigger))
{
2025-08-03 21:20:37 +02:00
_trigger.ActivateTimerTrigger((item.Value, timerTrigger));
}
}
}
}
protected override void CreamedEntity(EntityUid uid, CreamPiedComponent creamPied, ThrowHitByEvent args)
{
_popup.PopupEntity(Loc.GetString("cream-pied-component-on-hit-by-message",
("thrown", Identity.Entity(args.Thrown, EntityManager))),
uid, args.Target);
var otherPlayers = Filter.PvsExcept(uid);
_popup.PopupEntity(Loc.GetString("cream-pied-component-on-hit-by-message-others",
("owner", Identity.Entity(uid, EntityManager)),
("thrown", Identity.Entity(args.Thrown, EntityManager))),
uid, otherPlayers, false);
}
2022-09-14 19:30:56 +02:00
private void OnRejuvenate(Entity<CreamPiedComponent> entity, ref RejuvenateEvent args)
2022-09-14 19:30:56 +02:00
{
SetCreamPied(entity, entity.Comp, false);
2022-09-14 19:30:56 +02:00
}
}
}