diff --git a/Content.Server/Weapons/Melee/Vampire/VampireHealComponent.cs b/Content.Server/Weapons/Melee/Vampire/VampireHealComponent.cs new file mode 100644 index 0000000000000..a52c8ad9ab407 --- /dev/null +++ b/Content.Server/Weapons/Melee/Vampire/VampireHealComponent.cs @@ -0,0 +1,12 @@ +using Robust.Shared.GameObjects; +using Robust.Shared.Serialization.TypeSerializers.Implementations.Custom; +using Content.Shared.FixedPoint; + +namespace Content.Server.Weapons.Melee.Vampire; + +[RegisterComponent] +public sealed partial class VampireHealComponent : Component +{ + [DataField("healMultiplier")] + public FixedPoint2 HealMultiplier = 0.5f; +} \ No newline at end of file diff --git a/Content.Server/Weapons/Melee/Vampire/VampireHealSystem.cs b/Content.Server/Weapons/Melee/Vampire/VampireHealSystem.cs new file mode 100644 index 0000000000000..52487cc27187d --- /dev/null +++ b/Content.Server/Weapons/Melee/Vampire/VampireHealSystem.cs @@ -0,0 +1,88 @@ +using Content.Shared.Damage; +using Content.Shared.Damage.Events; +using Content.Shared.Damage.Components; +using Content.Shared.Hands.EntitySystems; +using Content.Shared.Mobs.Components; +using Content.Shared.Mobs; +using Content.Server.Damage.Systems; +using Content.Shared.FixedPoint; +using Robust.Shared.GameObjects; + +namespace Content.Server.Weapons.Melee.Vampire; + +public sealed class VampireHealSystem : EntitySystem +{ + [Dependency] private readonly DamageableSystem _damageable = default!; + [Dependency] private readonly SharedHandsSystem _hands = default!; + + public override void Initialize() + { + + SubscribeLocalEvent(OnDamageChanged); + } + + private void OnDamageChanged(EntityUid target, DamageableComponent comp, ref DamageChangedEvent args) + { + + if (args.DamageDelta == null) + return; + + + if (args.Origin == null) + return; + + var attacker = args.Origin.Value; + + + var totalDamage = args.DamageDelta.GetTotal(); + if (totalDamage <= FixedPoint2.Zero) + return; + + + if (attacker == target) + return; + + + if (!TryComp(target, out var mobState)) + return; + + + if (mobState.CurrentState == MobState.Dead) + return; + + + if (!_hands.TryGetActiveItem(attacker, out var weapon)) + return; + + + if (!TryComp(weapon.Value, out var vampire)) + return; + + + + var healAmount = totalDamage * vampire.HealMultiplier; + + if (healAmount <= FixedPoint2.Zero) + return; + + + + if (!TryComp(attacker, out var attackerDamage)) + return; + + var healSpecifier = new DamageSpecifier(); + + foreach (var (type, amount) in attackerDamage.Damage.DamageDict) + { + if (amount > FixedPoint2.Zero) + { + healSpecifier.DamageDict[type] = -healAmount; + } + } + + if (healSpecifier.DamageDict.Count == 0) + return; + + _damageable.TryChangeDamage(attacker, healSpecifier, origin: weapon.Value); + } +} \ No newline at end of file diff --git a/Resources/Prototypes/Entities/Objects/Weapons/Melee/vampire_sword.yml b/Resources/Prototypes/Entities/Objects/Weapons/Melee/vampire_sword.yml new file mode 100644 index 0000000000000..d2397b7b2ec28 --- /dev/null +++ b/Resources/Prototypes/Entities/Objects/Weapons/Melee/vampire_sword.yml @@ -0,0 +1,15 @@ +- type: entity + id: VampireSword + parent: BaseItem + name: vampire sword + description: It thirsts for blood. + components: + - type: Sprite + sprite: Objects/Weapons/Melee/captain_sabre.rsi + state: icon + - type: MeleeWeapon + damage: + types: + Slash: 15 + - type: VampireHeal + healMultiplier: 0.5 \ No newline at end of file