2021-10-29 13:40:15 +01:00
|
|
|
using Content.Server.Chemistry.EntitySystems;
|
2023-02-05 23:07:51 +03:00
|
|
|
using Content.Server.Explosion.Components;
|
|
|
|
|
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;
|
|
|
|
|
using Content.Shared.Interaction;
|
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;
|
2023-02-05 23:07:51 +03:00
|
|
|
using Robust.Server.GameObjects;
|
2021-08-21 09:18:23 +02:00
|
|
|
using Robust.Shared.Audio;
|
|
|
|
|
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();
|
|
|
|
|
|
2023-02-05 23:07:51 +03:00
|
|
|
SubscribeLocalEvent<CreamPieComponent, InteractUsingEvent>(OnInteractUsing);
|
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-02-05 23:07:51 +03:00
|
|
|
_audio.Play(_audio.GetSound(creamPie.Sound), Filter.Pvs(uid), uid, false, new AudioParams().WithVariation(0.125f));
|
2021-08-21 09:18:23 +02:00
|
|
|
|
2023-02-05 23:07:51 +03:00
|
|
|
if (EntityManager.TryGetComponent<FoodComponent?>(uid, out var foodComp))
|
2021-08-21 09:18:23 +02:00
|
|
|
{
|
2023-02-05 23:07:51 +03:00
|
|
|
if (_solutions.TryGetSolution(uid, foodComp.SolutionName, out var solution))
|
|
|
|
|
{
|
2023-04-10 15:37:03 +10:00
|
|
|
_puddle.TrySpillAt(uid, solution, out _, false);
|
2023-02-05 23:07:51 +03:00
|
|
|
}
|
|
|
|
|
if (!string.IsNullOrEmpty(foodComp.TrashPrototype))
|
|
|
|
|
{
|
|
|
|
|
EntityManager.SpawnEntity(foodComp.TrashPrototype, Transform(uid).Coordinates);
|
|
|
|
|
}
|
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
|
|
|
}
|
|
|
|
|
|
2023-02-05 23:07:51 +03:00
|
|
|
private void OnInteractUsing(EntityUid uid, CreamPieComponent component, InteractUsingEvent args)
|
|
|
|
|
{
|
|
|
|
|
ActivatePayload(uid);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
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);
|
|
|
|
|
}
|
|
|
|
|
_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
|
|
|
|
|
|
|
|
private void OnRejuvenate(EntityUid uid, CreamPiedComponent component, RejuvenateEvent args)
|
|
|
|
|
{
|
|
|
|
|
SetCreamPied(uid, component, false);
|
|
|
|
|
}
|
2021-08-21 09:18:23 +02:00
|
|
|
}
|
|
|
|
|
}
|