Files
wwdpublic/Content.Server/Nutrition/EntitySystems/CreamPieSystem.cs
SimpleStation14 68aa211c39 Mirror: Fix Cream Pie Bomb when Eaten or Sliced (#172)
## Mirror of PR #25928: [Fix cream pie bomb when eaten or
sliced](https://github.com/space-wizards/space-station-14/pull/25928)
from <img src="https://avatars.githubusercontent.com/u/10567778?v=4"
alt="space-wizards" width="22"/>
[space-wizards](https://github.com/space-wizards)/[space-station-14](https://github.com/space-wizards/space-station-14)

###### `0d0edbba4a1c2af7ecef3318b5f9fe287a63fab5`

PR opened by <img
src="https://avatars.githubusercontent.com/u/40753025?v=4"
width="16"/><a href="https://github.com/Slava0135"> Slava0135</a> at
2024-03-08 13:16:38 UTC
PR merged by <img
src="https://avatars.githubusercontent.com/u/19864447?v=4"
width="16"/><a href="https://github.com/web-flow"> web-flow</a> at
2024-03-13 08:36:08 UTC

---

PR changed 4 files with 22 additions and 4 deletions.

The PR had the following labels:


---

<details open="true"><summary><h1>Original Body</h1></summary>

> <!-- Please read these guidelines before opening your PR:
https://docs.spacestation14.io/en/getting-started/pr-guideline -->
> <!-- The text between the arrows are comments - they will not be
visible on your PR. -->
> 
> ## About the PR
> <!-- What did you change in this PR? -->
> 
> ## Why / Balance
> <!-- Why was it changed? Link any discussions or issues here. Please
discuss how this would affect game balance. -->
> 
> ## Technical details
> <!-- If this is a code change, summarize at high level how your new
code works. This makes it easier to review. -->
> 
> ## Media
> <!-- 
> PRs which make ingame changes (adding clothing, items, new features,
etc) are required to have media attached that showcase the changes.
> Small fixes/refactors are exempt.
> Any media may be used in SS14 progress reports, with clear credit
given.
> 
> If you're unsure whether your PR will require media, ask a maintainer.
> 
> Check the box below to confirm that you have in fact seen this (put an
X in the brackets, like [X]):
> -->
> 
> ![Peek 2024-03-08
15-48](https://github.com/space-wizards/space-station-14/assets/40753025/f7d8aeef-9aca-4b39-a4fe-967b41b26b7f)
> 
> ## Breaking changes
> <!--
> List any breaking changes, including namespace, public
class/method/field changes, prototype renames; and provide instructions
for fixing them. This will be pasted in #codebase-changes.
> -->
> 
> **Changelog**
> <!--
> Make players aware of new features and changes that could affect how
they play the game by adding a Changelog entry. Please read the
Changelog guidelines located at:
https://docs.spacestation14.io/en/getting-started/pr-guideline#changelog
> -->
> 
> 🆑
> - fix: Fixed pie bomb not detonating when eaten or sliced (remember to
keep hungry mice away from it)!
> - tweak: Pie bomb now cannot be ejected or swapped (just hope there is
no bomb inside)
> 


</details>

---------

Co-authored-by: Vyacheslav Kovalevsky <40753025+Slava0135@users.noreply.github.com>
Co-authored-by: VMSolidus <evilexecutive@gmail.com>
Co-authored-by: Danger Revolution! <142105406+DangerRevolution@users.noreply.github.com>
2024-07-09 20:35:11 -04:00

108 lines
4.3 KiB
C#

using Content.Server.Chemistry.Containers.EntitySystems;
using Content.Server.Explosion.EntitySystems;
using Content.Server.Fluids.EntitySystems;
using Content.Server.Nutrition.Components;
using Content.Server.Popups;
using Content.Shared.Containers.ItemSlots;
using Content.Shared.Explosion.Components;
using Content.Shared.Nutrition;
using Content.Shared.Nutrition.Components;
using Content.Shared.Nutrition.EntitySystems;
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!;
[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!;
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);
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))
{
_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)
{
if (_itemSlots.TryGetSlot(uid, CreamPieComponent.PayloadSlotName, out var itemSlot))
{
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,
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);
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);
}
private void OnRejuvenate(Entity<CreamPiedComponent> entity, ref RejuvenateEvent args)
{
SetCreamPied(entity, entity.Comp, false);
}
}
}