Refactors throw events, makes cream pies ECS (#4500)
This commit is contained in:
committed by
GitHub
parent
140682f92b
commit
ea4ce1c6fc
27
Content.Shared/Nutrition/Components/CreamPieComponent.cs
Normal file
27
Content.Shared/Nutrition/Components/CreamPieComponent.cs
Normal file
@@ -0,0 +1,27 @@
|
||||
using Content.Shared.Nutrition.EntitySystems;
|
||||
using Content.Shared.Sound;
|
||||
using Robust.Shared.Analyzers;
|
||||
using Robust.Shared.GameObjects;
|
||||
using Robust.Shared.Serialization.Manager.Attributes;
|
||||
using Robust.Shared.ViewVariables;
|
||||
|
||||
namespace Content.Shared.Nutrition.Components
|
||||
{
|
||||
[Friend(typeof(SharedCreamPieSystem))]
|
||||
[RegisterComponent]
|
||||
public class CreamPieComponent : Component
|
||||
{
|
||||
public override string Name => "CreamPie";
|
||||
|
||||
[ViewVariables]
|
||||
[DataField("paralyzeTime")]
|
||||
public float ParalyzeTime { get; } = 1f;
|
||||
|
||||
[ViewVariables]
|
||||
[DataField("sound")]
|
||||
public SoundSpecifier Sound { get; } = new SoundCollectionSpecifier("desecration");
|
||||
|
||||
[ViewVariables]
|
||||
public bool Splatted { get; set; } = false;
|
||||
}
|
||||
}
|
||||
25
Content.Shared/Nutrition/Components/CreamPiedComponent.cs
Normal file
25
Content.Shared/Nutrition/Components/CreamPiedComponent.cs
Normal file
@@ -0,0 +1,25 @@
|
||||
using System;
|
||||
using Content.Shared.Nutrition.EntitySystems;
|
||||
using Robust.Shared.Analyzers;
|
||||
using Robust.Shared.GameObjects;
|
||||
using Robust.Shared.Serialization;
|
||||
using Robust.Shared.ViewVariables;
|
||||
|
||||
namespace Content.Shared.Nutrition.Components
|
||||
{
|
||||
[Friend(typeof(SharedCreamPieSystem))]
|
||||
[RegisterComponent]
|
||||
public class CreamPiedComponent : Component
|
||||
{
|
||||
public override string Name => "CreamPied";
|
||||
|
||||
[ViewVariables]
|
||||
public bool CreamPied { get; set; } = false;
|
||||
}
|
||||
|
||||
[Serializable, NetSerializable]
|
||||
public enum CreamPiedVisuals
|
||||
{
|
||||
Creamed,
|
||||
}
|
||||
}
|
||||
@@ -1,17 +0,0 @@
|
||||
using System;
|
||||
using Robust.Shared.GameObjects;
|
||||
using Robust.Shared.Serialization;
|
||||
|
||||
namespace Content.Shared.Nutrition.Components
|
||||
{
|
||||
public class SharedCreamPiedComponent : Component
|
||||
{
|
||||
public override string Name => "CreamPied";
|
||||
}
|
||||
|
||||
[Serializable, NetSerializable]
|
||||
public enum CreamPiedVisuals
|
||||
{
|
||||
Creamed,
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,75 @@
|
||||
using Content.Shared.Nutrition.Components;
|
||||
using Content.Shared.Stunnable;
|
||||
using Content.Shared.Throwing;
|
||||
using JetBrains.Annotations;
|
||||
using Robust.Shared.GameObjects;
|
||||
|
||||
namespace Content.Shared.Nutrition.EntitySystems
|
||||
{
|
||||
[UsedImplicitly]
|
||||
public abstract class SharedCreamPieSystem : EntitySystem
|
||||
{
|
||||
public override void Initialize()
|
||||
{
|
||||
base.Initialize();
|
||||
|
||||
SubscribeLocalEvent<CreamPieComponent, ThrowDoHitEvent>(OnCreamPieHit);
|
||||
SubscribeLocalEvent<CreamPieComponent, LandEvent>(OnCreamPieLand);
|
||||
SubscribeLocalEvent<CreamPiedComponent, ThrowHitByEvent>(OnCreamPiedHitBy);
|
||||
}
|
||||
|
||||
public void SplatCreamPie(EntityUid uid, CreamPieComponent creamPie)
|
||||
{
|
||||
// Already splatted! Do nothing.
|
||||
if (creamPie.Splatted)
|
||||
return;
|
||||
|
||||
creamPie.Splatted = true;
|
||||
|
||||
SplattedCreamPie(uid, creamPie);
|
||||
|
||||
EntityManager.QueueDeleteEntity(uid);
|
||||
}
|
||||
|
||||
protected virtual void SplattedCreamPie(EntityUid uid, CreamPieComponent creamPie) {}
|
||||
|
||||
public void SetCreamPied(EntityUid uid, CreamPiedComponent creamPied, bool value)
|
||||
{
|
||||
if (value == creamPied.CreamPied)
|
||||
return;
|
||||
|
||||
creamPied.CreamPied = value;
|
||||
|
||||
if (ComponentManager.TryGetComponent(uid, out SharedAppearanceComponent? appearance))
|
||||
{
|
||||
appearance.SetData(CreamPiedVisuals.Creamed, value);
|
||||
}
|
||||
}
|
||||
|
||||
private void OnCreamPieLand(EntityUid uid, CreamPieComponent component, LandEvent args)
|
||||
{
|
||||
SplatCreamPie(uid, component);
|
||||
}
|
||||
|
||||
private void OnCreamPieHit(EntityUid uid, CreamPieComponent component, ThrowDoHitEvent args)
|
||||
{
|
||||
SplatCreamPie(uid, component);
|
||||
}
|
||||
|
||||
private void OnCreamPiedHitBy(EntityUid uid, CreamPiedComponent creamPied, ThrowHitByEvent args)
|
||||
{
|
||||
if (args.Thrown.Deleted || !args.Thrown.TryGetComponent(out CreamPieComponent? creamPie)) return;
|
||||
|
||||
SetCreamPied(uid, creamPied, true);
|
||||
|
||||
CreamedEntity(uid, creamPied, args);
|
||||
|
||||
if (ComponentManager.TryGetComponent(uid, out SharedStunnableComponent? stun))
|
||||
{
|
||||
stun.Paralyze(creamPie.ParalyzeTime);
|
||||
}
|
||||
}
|
||||
|
||||
protected virtual void CreamedEntity(EntityUid uid, CreamPiedComponent creamPied, ThrowHitByEvent args) {}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user