From 1d1733185332c944104cc8aa67845c7beb632fe7 Mon Sep 17 00:00:00 2001 From: DrSmugleaf Date: Wed, 26 Aug 2020 03:50:26 +0200 Subject: [PATCH] (Re)add healing items (#1918) * (Re)add healing component * Do range check only when healing someone else --- .../Components/Medical/HealingComponent.cs | 71 +++++++++++++++++++ .../Entities/Objects/Specific/medical.yml | 14 ++-- 2 files changed, 78 insertions(+), 7 deletions(-) create mode 100644 Content.Server/GameObjects/Components/Medical/HealingComponent.cs diff --git a/Content.Server/GameObjects/Components/Medical/HealingComponent.cs b/Content.Server/GameObjects/Components/Medical/HealingComponent.cs new file mode 100644 index 0000000000..f89e4a5508 --- /dev/null +++ b/Content.Server/GameObjects/Components/Medical/HealingComponent.cs @@ -0,0 +1,71 @@ +using System.Collections.Generic; +using Content.Server.GameObjects.Components.Stack; +using Content.Shared.Damage; +using Content.Shared.GameObjects.Components.Body; +using Content.Shared.GameObjects.EntitySystems; +using Content.Shared.Interfaces.GameObjects.Components; +using Robust.Shared.GameObjects; +using Robust.Shared.GameObjects.Systems; +using Robust.Shared.Interfaces.GameObjects; +using Robust.Shared.Serialization; + +namespace Content.Server.GameObjects.Components.Medical +{ + [RegisterComponent] + public class HealingComponent : Component, IAfterInteract + { + public override string Name => "Healing"; + + public Dictionary Heal { get; private set; } + + public override void ExposeData(ObjectSerializer serializer) + { + base.ExposeData(serializer); + + serializer.DataField(this, h => h.Heal, "heal", new Dictionary()); + } + + public void AfterInteract(AfterInteractEventArgs eventArgs) + { + if (eventArgs.Target == null) + { + return; + } + + if (!eventArgs.Target.TryGetComponent(out IBodyManagerComponent body)) + { + return; + } + + if (!ActionBlockerSystem.CanInteract(eventArgs.User)) + { + return; + } + + if (eventArgs.User != eventArgs.Target) + { + var interactionSystem = EntitySystem.Get(); + var from = eventArgs.User.Transform.MapPosition; + var to = eventArgs.Target.Transform.MapPosition; + bool Ignored(IEntity entity) => entity == eventArgs.User || entity == eventArgs.Target; + var inRange = interactionSystem.InRangeUnobstructed(from, to, predicate: Ignored); + + if (!inRange) + { + return; + } + } + + if (Owner.TryGetComponent(out StackComponent stack) && + !stack.Use(1)) + { + return; + } + + foreach (var (type, amount) in Heal) + { + body.ChangeDamage(type, -amount, true); + } + } + } +} diff --git a/Resources/Prototypes/Entities/Objects/Specific/medical.yml b/Resources/Prototypes/Entities/Objects/Specific/medical.yml index 5e7b8af68c..cda45f9d67 100644 --- a/Resources/Prototypes/Entities/Objects/Specific/medical.yml +++ b/Resources/Prototypes/Entities/Objects/Specific/medical.yml @@ -27,7 +27,7 @@ components: - type: Stack - type: Item - #- type: Healing + - type: Healing - type: entity name: ointment @@ -39,9 +39,9 @@ texture: Objects/Specific/Medical/ointment.png - type: Icon texture: Objects/Specific/Medical/ointment.png - #- type: Healing - # heal: 10 - # damage: Heat + - type: Healing + heal: + Heat: 10 - type: Stack max: 5 count: 5 @@ -57,9 +57,9 @@ texture: Objects/Specific/Medical/brutepack.png - type: Icon texture: Objects/Specific/Medical/brutepack.png - #- type: Healing - # heal: 10 - # damage: Brute + - type: Healing + heal: + Blunt: 10 - type: Stack max: 5 count: 5