Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions Content.Server/Weapons/Melee/Vampire/VampireHealComponent.cs
Original file line number Diff line number Diff line change
@@ -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;
}
88 changes: 88 additions & 0 deletions Content.Server/Weapons/Melee/Vampire/VampireHealSystem.cs
Original file line number Diff line number Diff line change
@@ -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<DamageableComponent, DamageChangedEvent>(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<MobStateComponent>(target, out var mobState))
return;


if (mobState.CurrentState == MobState.Dead)
return;


if (!_hands.TryGetActiveItem(attacker, out var weapon))
return;


if (!TryComp<VampireHealComponent>(weapon.Value, out var vampire))
return;



var healAmount = totalDamage * vampire.HealMultiplier;

if (healAmount <= FixedPoint2.Zero)
return;



if (!TryComp<DamageableComponent>(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);
}
}
Original file line number Diff line number Diff line change
@@ -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
Loading