Refactors throw events, makes cream pies ECS (#4500)
This commit is contained in:
committed by
GitHub
parent
140682f92b
commit
ea4ce1c6fc
@@ -1,7 +1,9 @@
|
||||
using System.Collections.Generic;
|
||||
using Content.Server.Nutrition.Components;
|
||||
using Content.Server.Nutrition.EntitySystems;
|
||||
using Content.Shared.Chemistry.Reagent;
|
||||
using Content.Shared.Chemistry.Solution;
|
||||
using Content.Shared.Nutrition.Components;
|
||||
using JetBrains.Annotations;
|
||||
using Robust.Shared.GameObjects;
|
||||
using Robust.Shared.Serialization.Manager.Attributes;
|
||||
@@ -20,7 +22,7 @@ namespace Content.Server.Chemistry.ReagentEntityReactions
|
||||
{
|
||||
if (!entity.TryGetComponent(out CreamPiedComponent? creamPied) || !_reagents.Contains(reagent.ID)) return;
|
||||
|
||||
creamPied.Wash();
|
||||
EntitySystem.Get<CreamPieSystem>().SetCreamPied(entity.Uid, creamPied, false);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,28 +1,23 @@
|
||||
using Content.Shared.Damage;
|
||||
using Content.Shared.Damage.Components;
|
||||
using Content.Shared.Throwing;
|
||||
using Robust.Shared.Analyzers;
|
||||
using Robust.Shared.GameObjects;
|
||||
using Robust.Shared.Serialization.Manager.Attributes;
|
||||
|
||||
namespace Content.Server.Damage.Components
|
||||
{
|
||||
[Friend(typeof(DamageOtherOnHitSystem))]
|
||||
[RegisterComponent]
|
||||
public class DamageOtherOnHitComponent : Component, IThrowCollide
|
||||
public class DamageOtherOnHitComponent : Component
|
||||
{
|
||||
public override string Name => "DamageOtherOnHit";
|
||||
|
||||
[DataField("damageType")]
|
||||
private DamageType _damageType = DamageType.Blunt;
|
||||
public DamageType DamageType { get; } = DamageType.Blunt;
|
||||
|
||||
[DataField("amount")]
|
||||
private int _amount = 1;
|
||||
public int Amount { get; } = 1;
|
||||
|
||||
[DataField("ignoreResistances")]
|
||||
private bool _ignoreResistances;
|
||||
|
||||
void IThrowCollide.DoHit(ThrowCollideEventArgs eventArgs)
|
||||
{
|
||||
if (!eventArgs.Target.TryGetComponent(out IDamageableComponent? damageable)) return;
|
||||
|
||||
damageable.ChangeDamage(_damageType, _amount, _ignoreResistances, eventArgs.User);
|
||||
}
|
||||
public bool IgnoreResistances { get; } = false;
|
||||
}
|
||||
}
|
||||
|
||||
23
Content.Server/Damage/DamageOtherOnHitSystem.cs
Normal file
23
Content.Server/Damage/DamageOtherOnHitSystem.cs
Normal file
@@ -0,0 +1,23 @@
|
||||
using Content.Server.Damage.Components;
|
||||
using Content.Shared.Damage.Components;
|
||||
using Content.Shared.Throwing;
|
||||
using Robust.Shared.GameObjects;
|
||||
|
||||
namespace Content.Server.Damage
|
||||
{
|
||||
public class DamageOtherOnHitSystem : EntitySystem
|
||||
{
|
||||
public override void Initialize()
|
||||
{
|
||||
SubscribeLocalEvent<DamageOtherOnHitComponent, ThrowDoHitEvent>(OnDoHit);
|
||||
}
|
||||
|
||||
private void OnDoHit(EntityUid uid, DamageOtherOnHitComponent component, ThrowDoHitEvent args)
|
||||
{
|
||||
if (!args.Target.TryGetComponent(out IDamageableComponent? damageable))
|
||||
return;
|
||||
|
||||
damageable.ChangeDamage(component.DamageType, component.Amount, component.IgnoreResistances, args.User);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,8 +1,10 @@
|
||||
using Content.Server.Atmos.Components;
|
||||
using Content.Server.Nutrition.Components;
|
||||
using Content.Server.Nutrition.EntitySystems;
|
||||
using Content.Server.Stunnable.Components;
|
||||
using Content.Shared.Damage.Components;
|
||||
using Content.Shared.MobState;
|
||||
using Content.Shared.Nutrition.Components;
|
||||
using Content.Shared.Verbs;
|
||||
using Robust.Server.Console;
|
||||
using Robust.Server.GameObjects;
|
||||
@@ -89,7 +91,7 @@ namespace Content.Server.Damage
|
||||
|
||||
if (target.TryGetComponent(out CreamPiedComponent? creamPied))
|
||||
{
|
||||
creamPied.Wash();
|
||||
EntitySystem.Get<CreamPieSystem>().SetCreamPied(target.Uid, creamPied, false);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -52,7 +52,7 @@ namespace Content.Server.Disposal.Unit.EntitySystems
|
||||
SubscribeLocalEvent<DisposalUnitComponent, ComponentInit>(HandleDisposalInit);
|
||||
SubscribeLocalEvent<DisposalUnitComponent, ComponentShutdown>(HandleDisposalShutdown);
|
||||
|
||||
SubscribeLocalEvent<DisposalUnitComponent, ThrowCollideEvent>(HandleThrowCollide);
|
||||
SubscribeLocalEvent<DisposalUnitComponent, ThrowHitByEvent>(HandleThrowCollide);
|
||||
|
||||
// Interactions
|
||||
SubscribeLocalEvent<DisposalUnitComponent, ActivateInWorldEvent>(HandleActivate);
|
||||
@@ -144,7 +144,7 @@ namespace Content.Server.Disposal.Unit.EntitySystems
|
||||
/// <summary>
|
||||
/// Thrown items have a chance of bouncing off the unit and not going in.
|
||||
/// </summary>
|
||||
private void HandleThrowCollide(EntityUid uid, DisposalUnitComponent component, ThrowCollideEvent args)
|
||||
private void HandleThrowCollide(EntityUid uid, DisposalUnitComponent component, ThrowHitByEvent args)
|
||||
{
|
||||
if (!CanInsert(component, args.Thrown) ||
|
||||
_robustRandom.NextDouble() > 0.75 ||
|
||||
|
||||
@@ -1,53 +0,0 @@
|
||||
using Content.Server.Chemistry.Components;
|
||||
using Content.Server.Fluids.Components;
|
||||
using Content.Shared.Audio;
|
||||
using Content.Shared.Sound;
|
||||
using Content.Shared.Throwing;
|
||||
using Robust.Shared.Audio;
|
||||
using Robust.Shared.GameObjects;
|
||||
using Robust.Shared.Player;
|
||||
using Robust.Shared.Serialization.Manager.Attributes;
|
||||
using Robust.Shared.ViewVariables;
|
||||
|
||||
namespace Content.Server.Nutrition.Components
|
||||
{
|
||||
[RegisterComponent]
|
||||
public class CreamPieComponent : Component, ILand, IThrowCollide
|
||||
{
|
||||
public override string Name => "CreamPie";
|
||||
|
||||
[ViewVariables(VVAccess.ReadWrite)]
|
||||
[DataField("paralyzeTime")]
|
||||
public float ParalyzeTime { get; set; } = 1f;
|
||||
|
||||
[DataField("sound")]
|
||||
private SoundSpecifier _sound = new SoundCollectionSpecifier("desecration");
|
||||
|
||||
public void PlaySound()
|
||||
{
|
||||
SoundSystem.Play(Filter.Pvs(Owner), _sound.GetSound(), Owner, AudioHelpers.WithVariation(0.125f));
|
||||
}
|
||||
|
||||
void IThrowCollide.DoHit(ThrowCollideEventArgs eventArgs)
|
||||
{
|
||||
Splat();
|
||||
}
|
||||
|
||||
void ILand.Land(LandEventArgs eventArgs)
|
||||
{
|
||||
Splat();
|
||||
}
|
||||
|
||||
public void Splat()
|
||||
{
|
||||
PlaySound();
|
||||
|
||||
if (Owner.TryGetComponent(out SolutionContainerComponent? solution))
|
||||
{
|
||||
solution.Solution.SpillAt(Owner, "PuddleSmear", false);
|
||||
}
|
||||
|
||||
Owner.QueueDelete();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,55 +0,0 @@
|
||||
using Content.Server.Notification;
|
||||
using Content.Server.Stunnable.Components;
|
||||
using Content.Shared.Notification;
|
||||
using Content.Shared.Notification.Managers;
|
||||
using Content.Shared.Nutrition.Components;
|
||||
using Content.Shared.Throwing;
|
||||
using Robust.Server.GameObjects;
|
||||
using Robust.Shared.GameObjects;
|
||||
using Robust.Shared.Localization;
|
||||
using Robust.Shared.ViewVariables;
|
||||
|
||||
namespace Content.Server.Nutrition.Components
|
||||
{
|
||||
[RegisterComponent]
|
||||
public class CreamPiedComponent : SharedCreamPiedComponent, IThrowCollide
|
||||
{
|
||||
private bool _creamPied;
|
||||
|
||||
[ViewVariables]
|
||||
public bool CreamPied
|
||||
{
|
||||
get => _creamPied;
|
||||
private set
|
||||
{
|
||||
if (value == _creamPied) return;
|
||||
|
||||
_creamPied = value;
|
||||
if (Owner.TryGetComponent(out AppearanceComponent? appearance))
|
||||
{
|
||||
appearance.SetData(CreamPiedVisuals.Creamed, CreamPied);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void Wash()
|
||||
{
|
||||
if(CreamPied)
|
||||
CreamPied = false;
|
||||
}
|
||||
|
||||
void IThrowCollide.HitBy(ThrowCollideEventArgs eventArgs)
|
||||
{
|
||||
if (eventArgs.Thrown.Deleted || !eventArgs.Thrown.TryGetComponent(out CreamPieComponent? creamPie)) return;
|
||||
|
||||
CreamPied = true;
|
||||
Owner.PopupMessage(Loc.GetString("cream-pied-component-on-hit-by-message",("thrower", eventArgs.Thrown)));
|
||||
Owner.PopupMessageOtherClients(Loc.GetString("cream-pied-component-on-hit-by-message-others", ("owner", Owner),("thrower", eventArgs.Thrown)));
|
||||
|
||||
if (Owner.TryGetComponent(out StunnableComponent? stun))
|
||||
{
|
||||
stun.Paralyze(creamPie.ParalyzeTime);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
36
Content.Server/Nutrition/EntitySystems/CreamPieSystem.cs
Normal file
36
Content.Server/Nutrition/EntitySystems/CreamPieSystem.cs
Normal file
@@ -0,0 +1,36 @@
|
||||
using Content.Server.Chemistry.Components;
|
||||
using Content.Server.Fluids.Components;
|
||||
using Content.Server.Notification;
|
||||
using Content.Shared.Audio;
|
||||
using Content.Shared.Notification.Managers;
|
||||
using Content.Shared.Nutrition.Components;
|
||||
using Content.Shared.Nutrition.EntitySystems;
|
||||
using Content.Shared.Throwing;
|
||||
using JetBrains.Annotations;
|
||||
using Robust.Shared.Audio;
|
||||
using Robust.Shared.GameObjects;
|
||||
using Robust.Shared.Localization;
|
||||
using Robust.Shared.Player;
|
||||
|
||||
namespace Content.Server.Nutrition.EntitySystems
|
||||
{
|
||||
[UsedImplicitly]
|
||||
public class CreamPieSystem : SharedCreamPieSystem
|
||||
{
|
||||
protected override void SplattedCreamPie(EntityUid uid, CreamPieComponent creamPie)
|
||||
{
|
||||
SoundSystem.Play(Filter.Pvs(creamPie.Owner), creamPie.Sound.GetSound(), creamPie.Owner, AudioHelpers.WithVariation(0.125f));
|
||||
|
||||
if (ComponentManager.TryGetComponent(uid, out SolutionContainerComponent? solution))
|
||||
{
|
||||
solution.Solution.SpillAt(creamPie.Owner, "PuddleSmear", false);
|
||||
}
|
||||
}
|
||||
|
||||
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)));
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -31,7 +31,7 @@ namespace Content.Server.Stunnable
|
||||
SubscribeLocalEvent<StunbatonComponent, MeleeHitEvent>(OnMeleeHit);
|
||||
SubscribeLocalEvent<StunbatonComponent, MeleeInteractEvent>(OnMeleeInteract);
|
||||
SubscribeLocalEvent<StunbatonComponent, UseInHandEvent>(OnUseInHand);
|
||||
SubscribeLocalEvent<StunbatonComponent, ThrowCollideEvent>(OnThrowCollide);
|
||||
SubscribeLocalEvent<StunbatonComponent, ThrowDoHitEvent>(OnThrowCollide);
|
||||
SubscribeLocalEvent<StunbatonComponent, PowerCellChangedEvent>(OnPowerCellChanged);
|
||||
SubscribeLocalEvent<StunbatonComponent, InteractUsingEvent>(OnInteractUsing);
|
||||
SubscribeLocalEvent<StunbatonComponent, ExaminedEvent>(OnExamined);
|
||||
@@ -81,7 +81,7 @@ namespace Content.Server.Stunnable
|
||||
}
|
||||
}
|
||||
|
||||
private void OnThrowCollide(EntityUid uid, StunbatonComponent comp, ThrowCollideEvent args)
|
||||
private void OnThrowCollide(EntityUid uid, StunbatonComponent comp, ThrowDoHitEvent args)
|
||||
{
|
||||
if (!ComponentManager.TryGetComponent<PowerCellSlotComponent>(uid, out var slot)) return;
|
||||
if (!comp.Activated || slot.Cell == null || !slot.Cell.TryUseCharge(comp.EnergyPerUse)) return;
|
||||
|
||||
Reference in New Issue
Block a user