A status effect class named KillHealStatus (titled "Vampire") that heals the player a small amount when they kill a nearby enemy and applies a constant HP drain modifier based on status level. It sets title and icon, computes heal and drain amounts by level, refreshes modifier application, and handles OnKill proximity check and healing.
using System;
using System.Collections.Generic;
using System.Linq;
using Sandbox;
[Status(5, 3, 1f, 0, false )]
public class KillHealStatus : Status
{
public KillHealStatus()
{
Title = "Vampire";
IconPath = "textures/icons/kill_heal.png";
}
public override void Init(Player player)
{
base.Init(player);
}
public override void Refresh()
{
Description = GetDescription(Level);
Player.Modify(this, PlayerStat.HealthRegen, -GetHpDrainAmountForLevel(Level), ModifierType.Add);
}
public override string GetDescription(int newLevel)
{
return string.Format("Heal for {0} whenever you kill an enemy within 2 meters but lose {1} HP/s", GetPrintAmountForLevel(Level), GetHpDrainPrintAmountForLevel(Level));
}
public override string GetUpgradeDescription(int newLevel)
{
return newLevel > 1 ? string.Format( "Heal for {0}→{1} whenever you kill an enemy within 2 meters but lose {2}→{3} HP/s", GetPrintAmountForLevel(newLevel - 1), GetPrintAmountForLevel(newLevel), GetHpDrainPrintAmountForLevel(newLevel - 1), GetHpDrainPrintAmountForLevel(newLevel)) : GetDescription(newLevel);
}
public override void OnKill(Enemy enemy)
{
var distSqr = (enemy.Position2D - Player.Position2D).LengthSquared;
if ( distSqr > 2f * 2f )
return;
var amount = GetAmountForLevel( Level );
if ( Player.Health < Player.Stats[PlayerStat.MaxHp] )
Player.TimeSinceChangeHP = 0f;
Player.RegenHealth( amount );
//DamageNumbersLegacy.Create( amount, Player.Position2D + new Vector2( 0.2f + Game.Random.Float( -0.1f, 0.1f ), Player.Radius * 3f + Game.Random.Float( -0.2f, 0.3f ) ), color: Color.Green, sizeMultiplier: 0.7f );
}
public float GetAmountForLevel(int level)
{
return 0.1f + level * 0.5f + (level == 5 ? 0.05f : 0f);
}
public string GetPrintAmountForLevel(int level)
{
return string.Format("{0:0.00}", GetAmountForLevel(level));
}
public float GetHpDrainAmountForLevel(int level)
{
return level * 0.4f;
}
public string GetHpDrainPrintAmountForLevel(int level)
{
return string.Format("{0:0.00}", GetHpDrainAmountForLevel(level));
}
}