2023-12-29 04:47:43 -08:00
|
|
|
using Content.Server.Chemistry.Containers.EntitySystems;
|
2023-02-05 23:07:51 +03:00
|
|
|
using Content.Server.Explosion.EntitySystems;
|
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-02-01 07:29:01 -06:00
|
|
|
using Content.Shared.Explosion.Components;
|
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;
|
|
|
|
|
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
|
|
|
{
|
2023-02-05 23:07:51 +03:00
|
|
|
[Dependency] private readonly SolutionContainerSystem _solutions = default!;
|
2023-04-10 15:37:03 +10:00
|
|
|
[Dependency] private readonly PuddleSystem _puddle = default!;
|
2023-02-05 23:07:51 +03:00
|
|
|
[Dependency] private readonly ItemSlotsSystem _itemSlots = default!;
|
|
|
|
|
[Dependency] private readonly TriggerSystem _trigger = default!;
|
|
|
|
|
[Dependency] private readonly SharedAudioSystem _audio = default!;
|
|
|
|
|
[Dependency] private readonly PopupSystem _popup = 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);
|
|
|
|
|
}
|
|
|
|
|
|
2021-08-21 09:18:23 +02:00
|
|
|
protected override void SplattedCreamPie(EntityUid uid, CreamPieComponent creamPie)
|
|
|
|
|
{
|
2023-11-27 22:12:34 +11:00
|
|
|
_audio.PlayPvs(_audio.GetSound(creamPie.Sound), uid, AudioParams.Default.WithVariation(0.125f));
|
2021-08-21 09:18:23 +02:00
|
|
|
|
2023-08-24 03:10:55 -07:00
|
|
|
if (EntityManager.TryGetComponent(uid, out FoodComponent? foodComp))
|
2021-08-21 09:18:23 +02:00
|
|
|
{
|
2023-12-29 04:47:43 -08:00
|
|
|
if (_solutions.TryGetSolution(uid, foodComp.Solution, out _, out var solution))
|
2023-02-05 23:07:51 +03:00
|
|
|
{
|
2023-04-10 15:37:03 +10:00
|
|
|
_puddle.TrySpillAt(uid, solution, out _, false);
|
2023-02-05 23:07:51 +03:00
|
|
|
}
|
2023-10-10 20:06:24 -07:00
|
|
|
if (!string.IsNullOrEmpty(foodComp.Trash))
|
2023-02-05 23:07:51 +03:00
|
|
|
{
|
2023-10-10 20:06:24 -07:00
|
|
|
EntityManager.SpawnEntity(foodComp.Trash, Transform(uid).Coordinates);
|
2023-02-05 23:07:51 +03:00
|
|
|
}
|
2021-08-21 09:18:23 +02:00
|
|
|
}
|
2023-02-05 23:07:51 +03:00
|
|
|
ActivatePayload(uid);
|
2022-05-17 02:56:17 -07:00
|
|
|
|
|
|
|
|
EntityManager.QueueDeleteEntity(uid);
|
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
|
|
|
{
|
|
|
|
|
if (TryComp<OnUseTimerTriggerComponent>(item.Value, out var timerTrigger))
|
|
|
|
|
{
|
|
|
|
|
_trigger.HandleTimerTrigger(
|
|
|
|
|
item.Value,
|
|
|
|
|
null,
|
|
|
|
|
timerTrigger.Delay,
|
|
|
|
|
timerTrigger.BeepInterval,
|
|
|
|
|
timerTrigger.InitialBeepDelay,
|
2023-05-02 18:13:39 +03:00
|
|
|
timerTrigger.BeepSound);
|
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)
|
|
|
|
|
{
|
2023-08-02 12:30:04 +03:00
|
|
|
_popup.PopupEntity(Loc.GetString("cream-pied-component-on-hit-by-message", ("thrower", args.Thrown)), uid, args.Target);
|
2023-02-05 23:07:51 +03:00
|
|
|
var otherPlayers = Filter.Empty().AddPlayersByPvs(uid);
|
2023-04-10 15:37:03 +10:00
|
|
|
if (TryComp<ActorComponent>(args.Target, out var actor))
|
2023-02-05 23:07:51 +03:00
|
|
|
{
|
|
|
|
|
otherPlayers.RemovePlayer(actor.PlayerSession);
|
|
|
|
|
}
|
2023-12-29 04:47:43 -08:00
|
|
|
_popup.PopupEntity(Loc.GetString("cream-pied-component-on-hit-by-message-others", ("owner", uid), ("thrower", args.Thrown)), 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
|
|
|
}
|
|
|
|
|
}
|