From c4a92fdfa306b5f9a239940ae54e029bce64bbd5 Mon Sep 17 00:00:00 2001 From: Nemanja <98561806+EmoGarbage404@users.noreply.github.com> Date: Sun, 12 Feb 2023 15:17:54 -0500 Subject: [PATCH] Meat Anomaly Tweaks (#14026) * Meat Anomaly Tweaks * 50% --- .../Components/FleshAnomalyComponent.cs | 4 +- .../Components/DamageContactsComponent.cs | 20 ++++++ .../Components/DamagedByContactComponent.cs | 14 ++++ .../Damage/Systems/DamageContactsSystem.cs | 72 +++++++++++++++++++ .../Entities/Objects/Misc/kudzu.yml | 13 +++- 5 files changed, 118 insertions(+), 5 deletions(-) create mode 100644 Content.Shared/Damage/Components/DamageContactsComponent.cs create mode 100644 Content.Shared/Damage/Components/DamagedByContactComponent.cs create mode 100644 Content.Shared/Damage/Systems/DamageContactsSystem.cs diff --git a/Content.Shared/Anomaly/Effects/Components/FleshAnomalyComponent.cs b/Content.Shared/Anomaly/Effects/Components/FleshAnomalyComponent.cs index abd0b01939..88b3ff061c 100644 --- a/Content.Shared/Anomaly/Effects/Components/FleshAnomalyComponent.cs +++ b/Content.Shared/Anomaly/Effects/Components/FleshAnomalyComponent.cs @@ -19,7 +19,7 @@ public sealed class FleshAnomalyComponent : Component /// scales with severity. /// [DataField("maxSpawnAmount"), ViewVariables(VVAccess.ReadWrite)] - public int MaxSpawnAmount = 8; + public int MaxSpawnAmount = 7; /// /// The maximum radius the entities will spawn in. @@ -27,7 +27,7 @@ public sealed class FleshAnomalyComponent : Component /// scales with stability /// [DataField("spawnRange"), ViewVariables(VVAccess.ReadWrite)] - public float SpawnRange = 4f; + public float SpawnRange = 5f; /// /// The tile that is spawned by the anomaly's effect diff --git a/Content.Shared/Damage/Components/DamageContactsComponent.cs b/Content.Shared/Damage/Components/DamageContactsComponent.cs new file mode 100644 index 0000000000..3eedda7fc6 --- /dev/null +++ b/Content.Shared/Damage/Components/DamageContactsComponent.cs @@ -0,0 +1,20 @@ +using Content.Shared.Whitelist; +using Robust.Shared.GameStates; + +namespace Content.Shared.Damage.Components; + +[NetworkedComponent, RegisterComponent] +public sealed class DamageContactsComponent : Component +{ + /// + /// The damage done each second to those touching this entity + /// + [DataField("damage", required: true)] + public DamageSpecifier Damage = new(); + + /// + /// Entities that aren't damaged by this entity + /// + [DataField("ignoreWhitelist")] + public EntityWhitelist? IgnoreWhitelist; +} diff --git a/Content.Shared/Damage/Components/DamagedByContactComponent.cs b/Content.Shared/Damage/Components/DamagedByContactComponent.cs new file mode 100644 index 0000000000..1b4c2999aa --- /dev/null +++ b/Content.Shared/Damage/Components/DamagedByContactComponent.cs @@ -0,0 +1,14 @@ +using Robust.Shared.GameStates; +using Robust.Shared.Serialization.TypeSerializers.Implementations.Custom; + +namespace Content.Shared.Damage.Components; + +[NetworkedComponent, RegisterComponent] +public sealed class DamagedByContactComponent : Component +{ + [DataField("nextSecond", customTypeSerializer: typeof(TimeOffsetSerializer)), ViewVariables(VVAccess.ReadWrite)] + public TimeSpan NextSecond = TimeSpan.Zero; + + [ViewVariables] + public DamageSpecifier? Damage; +} diff --git a/Content.Shared/Damage/Systems/DamageContactsSystem.cs b/Content.Shared/Damage/Systems/DamageContactsSystem.cs new file mode 100644 index 0000000000..891526bbb0 --- /dev/null +++ b/Content.Shared/Damage/Systems/DamageContactsSystem.cs @@ -0,0 +1,72 @@ +using Content.Shared.Damage.Components; +using Robust.Shared.Physics.Components; +using Robust.Shared.Physics.Events; +using Robust.Shared.Physics.Systems; +using Robust.Shared.Timing; + +namespace Content.Shared.Damage.Systems; + +public sealed class DamageContactsSystem : EntitySystem +{ + [Dependency] private readonly IGameTiming _timing = default!; + [Dependency] private readonly DamageableSystem _damageable = default!; + [Dependency] private readonly SharedPhysicsSystem _physics = default!; + + public override void Initialize() + { + base.Initialize(); + SubscribeLocalEvent(OnEntityEnter); + SubscribeLocalEvent(OnEntityExit); + } + + public override void Update(float frameTime) + { + base.Update(frameTime); + + foreach (var damaged in EntityQuery()) + { + var ent = damaged.Owner; + if (_timing.CurTime < damaged.NextSecond) + continue; + damaged.NextSecond = _timing.CurTime + TimeSpan.FromSeconds(1); + + if (damaged.Damage != null) + _damageable.TryChangeDamage(ent, damaged.Damage, interruptsDoAfters: false); + } + } + + private void OnEntityExit(EntityUid uid, DamageContactsComponent component, ref EndCollideEvent args) + { + var otherUid = args.OtherFixture.Body.Owner; + + if (!TryComp(uid, out var body)) + return; + + var damageQuery = GetEntityQuery(); + foreach (var contact in _physics.GetContactingEntities(body)) + { + var ent = contact.Owner; + if (ent == uid) + continue; + + if (damageQuery.HasComponent(ent)) + return; + } + + RemComp(otherUid); + } + + private void OnEntityEnter(EntityUid uid, DamageContactsComponent component, ref StartCollideEvent args) + { + var otherUid = args.OtherFixture.Body.Owner; + + if (HasComp(otherUid)) + return; + + if (component.IgnoreWhitelist?.IsValid(otherUid) ?? false) + return; + + var damagedByContact = EnsureComp(otherUid); + damagedByContact.Damage = component.Damage; + } +} diff --git a/Resources/Prototypes/Entities/Objects/Misc/kudzu.yml b/Resources/Prototypes/Entities/Objects/Misc/kudzu.yml index 96b6da1be0..4d141dceb5 100644 --- a/Resources/Prototypes/Entities/Objects/Misc/kudzu.yml +++ b/Resources/Prototypes/Entities/Objects/Misc/kudzu.yml @@ -122,10 +122,17 @@ acts: [ "Destruction" ] - type: Spreader growthResult: FleshKudzu - chance: 1 + chance: 0.5 + - type: DamageContacts + damage: + types: + Slash: 1.5 + ignoreWhitelist: + tags: + - Flesh - type: SlowContacts - walkSpeedModifier: 0.2 - sprintSpeedModifier: 0.2 + walkSpeedModifier: 0.3 + sprintSpeedModifier: 0.3 ignoreWhitelist: tags: - Flesh -- 2.52.0