Files
OldThink/Content.Server/Nutrition/EntitySystems/CreamPieSystem.cs

108 lines
4.3 KiB
C#
Raw Normal View History

using Content.Server.Chemistry.Containers.EntitySystems;
using Content.Server.Explosion.EntitySystems;
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;
Move grenade components to shared (#22691) * Moves FlashComponent.cs, FlashOnTriggerComponent.cs, and SmokeOnTriggerComponent.cs to Shared * Moves ExplodeOnTriggerComponent.cs, OnUseTimerTriggerComponent.cs, ActiveTimerTriggerComponent.cs, and SmokeOnTriggerComponent.cs to Shared * Delete .run/Content Server+Client.run.xml HOW DID THIS GET IN HERE ITS NOT AHHHH * Update Content.Client/Explosion/SmokeOnTriggerSystem.cs Co-authored-by: DrSmugleaf <DrSmugleaf@users.noreply.github.com> * Update Content.Shared/Explosion/Components/ActiveTimerTriggerComponent.cs Co-authored-by: DrSmugleaf <DrSmugleaf@users.noreply.github.com> * Update Content.Shared/Explosion/Components/OnUseTimerTriggerComponent.cs Co-authored-by: DrSmugleaf <DrSmugleaf@users.noreply.github.com> * Update Content.Shared/Explosion/Components/OnUseTimerTriggerComponent.cs Co-authored-by: DrSmugleaf <DrSmugleaf@users.noreply.github.com> * Update Content.Shared/Explosion/EntitySystems/SharedTriggerSystem.cs Co-authored-by: DrSmugleaf <DrSmugleaf@users.noreply.github.com> * Update Content.Shared/Explosion/EntitySystems/SharedSmokeOnTriggerSystem.cs Co-authored-by: DrSmugleaf <DrSmugleaf@users.noreply.github.com> * Update ExplodeOnTriggerComponent.cs * Revert "Delete .run/Content Server+Client.run.xml" This reverts commit 29ee05f57de60eab5c92158d8eba5e3acba483c2. * Fix? * cannot figure out how to get this to go back please forgive * Fixes a network issue * leftovers * Fixes --------- Co-authored-by: DrSmugleaf <DrSmugleaf@users.noreply.github.com> Co-authored-by: metalgearsloth <comedian_vs_clown@hotmail.com>
2024-02-01 07:29:01 -06:00
using Content.Shared.Explosion.Components;
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;
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 SolutionContainerSystem _solutions = default!;
2023-04-10 15:37:03 +10:00
[Dependency] private readonly PuddleSystem _puddle = default!;
[Dependency] private readonly ItemSlotsSystem _itemSlots = default!;
[Dependency] private readonly TriggerSystem _trigger = default!;
[Dependency] private readonly SharedAudioSystem _audio = default!;
[Dependency] private readonly PopupSystem _popup = 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(EntityUid uid, CreamPieComponent creamPie)
{
_audio.PlayPvs(_audio.GetSound(creamPie.Sound), uid, AudioParams.Default.WithVariation(0.125f));
if (EntityManager.TryGetComponent(uid, out FoodComponent? foodComp))
{
if (_solutions.TryGetSolution(uid, foodComp.Solution, out _, out var solution))
{
2023-04-10 15:37:03 +10:00
_puddle.TrySpillAt(uid, solution, out _, false);
}
if (!string.IsNullOrEmpty(foodComp.Trash))
{
EntityManager.SpawnEntity(foodComp.Trash, Transform(uid).Coordinates);
}
}
ActivatePayload(uid);
EntityManager.QueueDeleteEntity(uid);
}
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))
{
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);
}
}
}
}
protected override void CreamedEntity(EntityUid uid, CreamPiedComponent creamPied, ThrowHitByEvent args)
{
_popup.PopupEntity(Loc.GetString("cream-pied-component-on-hit-by-message", ("thrower", args.Thrown)), uid, args.Target);
var otherPlayers = Filter.Empty().AddPlayersByPvs(uid);
2023-04-10 15:37:03 +10:00
if (TryComp<ActorComponent>(args.Target, out var actor))
{
otherPlayers.RemovePlayer(actor.PlayerSession);
}
_popup.PopupEntity(Loc.GetString("cream-pied-component-on-hit-by-message-others", ("owner", uid), ("thrower", args.Thrown)), 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
}
}
}