From 11aece85196541c45bdae1fc853ca21e3d1be0fb Mon Sep 17 00:00:00 2001 From: Slava0135 <40753025+Slava0135@users.noreply.github.com> Date: Sun, 5 Feb 2023 23:07:51 +0300 Subject: [PATCH] Allow to put explosives with timer in cream pie (#13866) --- .../Nutrition/EntitySystems/CreamPieSystem.cs | 65 ++++++++++++++++--- .../Nutrition/Components/CreamPieComponent.cs | 2 + .../Objects/Consumable/Food/Baked/pie.yml | 13 ++++ 3 files changed, 71 insertions(+), 9 deletions(-) diff --git a/Content.Server/Nutrition/EntitySystems/CreamPieSystem.cs b/Content.Server/Nutrition/EntitySystems/CreamPieSystem.cs index 0130fb853b..d983b3e147 100644 --- a/Content.Server/Nutrition/EntitySystems/CreamPieSystem.cs +++ b/Content.Server/Nutrition/EntitySystems/CreamPieSystem.cs @@ -1,14 +1,17 @@ using Content.Server.Chemistry.EntitySystems; +using Content.Server.Explosion.Components; +using Content.Server.Explosion.EntitySystems; using Content.Server.Fluids.EntitySystems; using Content.Server.Nutrition.Components; using Content.Server.Popups; -using Content.Shared.Audio; +using Content.Shared.Containers.ItemSlots; +using Content.Shared.Interaction; using Content.Shared.Nutrition.Components; using Content.Shared.Nutrition.EntitySystems; -using Content.Shared.Popups; using Content.Shared.Rejuvenate; using Content.Shared.Throwing; using JetBrains.Annotations; +using Robust.Server.GameObjects; using Robust.Shared.Audio; using Robust.Shared.Player; @@ -17,32 +20,76 @@ namespace Content.Server.Nutrition.EntitySystems [UsedImplicitly] public sealed class CreamPieSystem : SharedCreamPieSystem { - [Dependency] private readonly SolutionContainerSystem _solutionsSystem = default!; - [Dependency] private readonly SpillableSystem _spillableSystem = default!; + [Dependency] private readonly SolutionContainerSystem _solutions = default!; + [Dependency] private readonly SpillableSystem _spillable = 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!; public override void Initialize() { base.Initialize(); + SubscribeLocalEvent(OnInteractUsing); SubscribeLocalEvent(OnRejuvenate); } protected override void SplattedCreamPie(EntityUid uid, CreamPieComponent creamPie) { - SoundSystem.Play(creamPie.Sound.GetSound(), Filter.Pvs(creamPie.Owner), creamPie.Owner, AudioHelpers.WithVariation(0.125f)); + _audio.Play(_audio.GetSound(creamPie.Sound), Filter.Pvs(uid), uid, false, new AudioParams().WithVariation(0.125f)); - if (EntityManager.TryGetComponent(creamPie.Owner, out var foodComp) && _solutionsSystem.TryGetSolution(creamPie.Owner, foodComp.SolutionName, out var solution)) + if (EntityManager.TryGetComponent(uid, out var foodComp)) { - _spillableSystem.SpillAt(creamPie.Owner, solution, "PuddleSmear", false); + if (_solutions.TryGetSolution(uid, foodComp.SolutionName, out var solution)) + { + _spillable.SpillAt(uid, solution, "PuddleSmear", false); + } + if (!string.IsNullOrEmpty(foodComp.TrashPrototype)) + { + EntityManager.SpawnEntity(foodComp.TrashPrototype, Transform(uid).Coordinates); + } } + ActivatePayload(uid); EntityManager.QueueDeleteEntity(uid); } + private void OnInteractUsing(EntityUid uid, CreamPieComponent component, InteractUsingEvent args) + { + ActivatePayload(uid); + } + + private void ActivatePayload(EntityUid uid) + { + if (_itemSlots.TryGetSlot(uid, CreamPieComponent.PayloadSlotName, out var itemSlot)) + { + if (_itemSlots.TryEject(uid, itemSlot, user: null, out var item)) + { + if (TryComp(item.Value, out var timerTrigger)) + { + _trigger.HandleTimerTrigger( + item.Value, + null, + timerTrigger.Delay, + timerTrigger.BeepInterval, + timerTrigger.InitialBeepDelay, + timerTrigger.BeepSound, + timerTrigger.BeepParams); + } + } + } + } + protected override void CreamedEntity(EntityUid uid, CreamPiedComponent creamPied, ThrowHitByEvent args) { - creamPied.Owner.PopupMessage(Loc.GetString("cream-pied-component-on-hit-by-message",("thrower", args.Thrown))); - creamPied.Owner.PopupMessageOtherClients(Loc.GetString("cream-pied-component-on-hit-by-message-others", ("owner", creamPied.Owner),("thrower", args.Thrown))); + _popup.PopupEntity(Loc.GetString("cream-pied-component-on-hit-by-message",("thrower", args.Thrown)), uid, args.Target); + var otherPlayers = Filter.Empty().AddPlayersByPvs(uid); + if (TryComp(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); } private void OnRejuvenate(EntityUid uid, CreamPiedComponent component, RejuvenateEvent args) diff --git a/Content.Shared/Nutrition/Components/CreamPieComponent.cs b/Content.Shared/Nutrition/Components/CreamPieComponent.cs index f38175df46..f209593964 100644 --- a/Content.Shared/Nutrition/Components/CreamPieComponent.cs +++ b/Content.Shared/Nutrition/Components/CreamPieComponent.cs @@ -15,5 +15,7 @@ namespace Content.Shared.Nutrition.Components [ViewVariables] public bool Splatted { get; set; } = false; + + public const string PayloadSlotName = "payloadSlot"; } } diff --git a/Resources/Prototypes/Entities/Objects/Consumable/Food/Baked/pie.yml b/Resources/Prototypes/Entities/Objects/Consumable/Food/Baked/pie.yml index 1e04cc812a..713fd6bb26 100644 --- a/Resources/Prototypes/Entities/Objects/Consumable/Food/Baked/pie.yml +++ b/Resources/Prototypes/Entities/Objects/Consumable/Food/Baked/pie.yml @@ -141,6 +141,19 @@ - state: tin - state: plain - type: CreamPie + - type: ContainerContainer + containers: + payloadSlot: !type:ContainerSlot + - type: ItemSlots + slots: + payloadSlot: + whitelist: + components: + - OnUseTimerTrigger + insertSound: + path: /Audio/Weapons/Guns/Empty/empty.ogg + ejectSound: + path: /Audio/Weapons/Guns/Empty/empty.ogg # Tastes like pie, cream, banana. - type: entity