Refactors throw events, makes cream pies ECS (#4500)

This commit is contained in:
Vera Aguilera Puerto
2021-08-21 09:18:23 +02:00
committed by GitHub
parent 140682f92b
commit ea4ce1c6fc
19 changed files with 287 additions and 260 deletions

View File

@@ -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;
}
}

View 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);
}
}
}

View File

@@ -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);
}
}
}