Refactors throw events, makes cream pies ECS (#4500)
This commit is contained in:
committed by
GitHub
parent
140682f92b
commit
ea4ce1c6fc
@@ -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