Convert suicide to ecs (#8091)

Co-authored-by: metalgearsloth <comedian_vs_clown@hotmail.com>
This commit is contained in:
wrexbe
2022-05-12 05:05:16 -07:00
committed by GitHub
parent 6903209a31
commit 089e40a061
15 changed files with 362 additions and 282 deletions

View File

@@ -1,19 +1,11 @@
using Content.Server.Act;
using Content.Server.Chat.Managers;
using Content.Server.Kitchen.EntitySystems;
using Content.Server.Popups;
using Content.Shared.DragDrop;
using Content.Shared.Kitchen.Components;
using Content.Shared.Popups;
using Robust.Shared.Analyzers;
using Robust.Shared.GameObjects;
using Robust.Shared.Localization;
using System.Threading;
namespace Content.Server.Kitchen.Components
{
[RegisterComponent, Friend(typeof(KitchenSpikeSystem))]
public sealed class KitchenSpikeComponent : SharedKitchenSpikeComponent, ISuicideAct
public sealed class KitchenSpikeComponent : SharedKitchenSpikeComponent
{
public List<string>? PrototypesToSpawn;
@@ -30,17 +22,5 @@ namespace Content.Server.Kitchen.Components
{
return true;
}
// ECS this out!, Handleable SuicideEvent?
SuicideKind ISuicideAct.Suicide(EntityUid victim, IChatManager chat)
{
var othersMessage = Loc.GetString("comp-kitchen-spike-suicide-other", ("victim", victim));
victim.PopupMessageOtherClients(othersMessage);
var selfMessage = Loc.GetString("comp-kitchen-spike-suicide-self");
victim.PopupMessage(selfMessage);
return SuicideKind.Piercing;
}
}
}

View File

@@ -25,7 +25,7 @@ using Robust.Shared.Player;
namespace Content.Server.Kitchen.Components
{
[RegisterComponent]
public sealed class MicrowaveComponent : SharedMicrowaveComponent, ISuicideAct
public sealed class MicrowaveComponent : SharedMicrowaveComponent
{
[Dependency] private readonly IEntityManager _entities = default!;
@@ -98,6 +98,12 @@ namespace Content.Server.Kitchen.Components
}
}
public void SetCookTime(uint cookTime)
{
_currentCookTimerTime = cookTime;
UIDirty = true;
}
private void UserInterfaceOnReceiveMessage(ServerBoundUserInterfaceMessage message)
{
if (!Powered || _busy)
@@ -193,7 +199,7 @@ namespace Content.Server.Kitchen.Components
// ReSharper disable once InconsistentNaming
// ReSharper disable once IdentifierTypo
private void Wzhzhzh()
public void Wzhzhzh()
{
if (!HasContents)
{
@@ -439,60 +445,10 @@ namespace Content.Server.Kitchen.Components
return true;
}
private void ClickSound()
public void ClickSound()
{
SoundSystem.Play(Filter.Pvs(Owner), _clickSound.GetSound(), Owner, AudioParams.Default.WithVolume(-2f));
}
SuicideKind ISuicideAct.Suicide(EntityUid victim, IChatManager chat)
{
var headCount = 0;
if (_entities.TryGetComponent<SharedBodyComponent?>(victim, out var body))
{
var headSlots = body.GetSlotsOfType(BodyPartType.Head);
foreach (var slot in headSlots)
{
var part = slot.Part;
if (part == null ||
!body.TryDropPart(slot, out var dropped))
{
continue;
}
foreach (var droppedPart in dropped.Values)
{
if (droppedPart.PartType != BodyPartType.Head)
{
continue;
}
Storage.Insert(droppedPart.Owner);
headCount++;
}
}
}
var othersMessage = headCount > 1
? Loc.GetString("microwave-component-suicide-multi-head-others-message", ("victim", victim))
: Loc.GetString("microwave-component-suicide-others-message", ("victim", victim));
victim.PopupMessageOtherClients(othersMessage);
var selfMessage = headCount > 1
? Loc.GetString("microwave-component-suicide-multi-head-message")
: Loc.GetString("microwave-component-suicide-message");
victim.PopupMessage(selfMessage);
_currentCookTimerTime = 10;
ClickSound();
UIDirty = true;
Wzhzhzh();
return SuicideKind.Heat;
}
}
public sealed class BeingMicrowavedEvent : HandledEntityEventArgs

View File

@@ -15,6 +15,8 @@ using System;
using Content.Shared.Storage;
using Robust.Shared.Random;
using static Content.Shared.Kitchen.Components.SharedKitchenSpikeComponent;
using Content.Shared.Interaction.Events;
using Content.Shared.Popups;
namespace Content.Server.Kitchen.EntitySystems
{
@@ -35,6 +37,20 @@ namespace Content.Server.Kitchen.EntitySystems
//DoAfter
SubscribeLocalEvent<KitchenSpikeComponent, SpikingFinishedEvent>(OnSpikingFinished);
SubscribeLocalEvent<KitchenSpikeComponent, SpikingFailEvent>(OnSpikingFail);
SubscribeLocalEvent<KitchenSpikeComponent, SuicideEvent>(OnSuicide);
}
private void OnSuicide(EntityUid uid, KitchenSpikeComponent component, SuicideEvent args)
{
if (args.Handled) return;
args.SetHandled(SuicideKind.Piercing);
var victim = args.Victim;
var othersMessage = Loc.GetString("comp-kitchen-spike-suicide-other", ("victim", victim));
victim.PopupMessageOtherClients(othersMessage);
var selfMessage = Loc.GetString("comp-kitchen-spike-suicide-self");
victim.PopupMessage(selfMessage);
}
private void OnSpikingFail(EntityUid uid, KitchenSpikeComponent component, SpikingFailEvent args)

View File

@@ -7,6 +7,10 @@ using Content.Shared.Item;
using Content.Shared.Kitchen.Components;
using Robust.Shared.Player;
using JetBrains.Annotations;
using Content.Shared.Interaction.Events;
using Content.Shared.Body.Components;
using Content.Shared.Body.Part;
using Content.Shared.Popups;
namespace Content.Server.Kitchen.EntitySystems
{
@@ -21,6 +25,56 @@ namespace Content.Server.Kitchen.EntitySystems
SubscribeLocalEvent<MicrowaveComponent, SolutionChangedEvent>(OnSolutionChange);
SubscribeLocalEvent<MicrowaveComponent, InteractUsingEvent>(OnInteractUsing);
SubscribeLocalEvent<MicrowaveComponent, BreakageEventArgs>(OnBreak);
SubscribeLocalEvent<MicrowaveComponent, SuicideEvent>(OnSuicide);
}
private void OnSuicide(EntityUid uid, MicrowaveComponent component, SuicideEvent args)
{
if (args.Handled) return;
args.SetHandled(SuicideKind.Heat);
var victim = args.Victim;
var headCount = 0;
if (TryComp<SharedBodyComponent?>(victim, out var body))
{
var headSlots = body.GetSlotsOfType(BodyPartType.Head);
foreach (var slot in headSlots)
{
var part = slot.Part;
if (part == null ||
!body.TryDropPart(slot, out var dropped))
{
continue;
}
foreach (var droppedPart in dropped.Values)
{
if (droppedPart.PartType != BodyPartType.Head)
{
continue;
}
component.Storage.Insert(droppedPart.Owner);
headCount++;
}
}
}
var othersMessage = headCount > 1
? Loc.GetString("microwave-component-suicide-multi-head-others-message", ("victim", victim))
: Loc.GetString("microwave-component-suicide-others-message", ("victim", victim));
victim.PopupMessageOtherClients(othersMessage);
var selfMessage = headCount > 1
? Loc.GetString("microwave-component-suicide-multi-head-message")
: Loc.GetString("microwave-component-suicide-message");
victim.PopupMessage(selfMessage);
component.ClickSound();
component.SetCookTime(10);
component.Wzhzhzh();
}
private void OnSolutionChange(EntityUid uid, MicrowaveComponent component, SolutionChangedEvent args)