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