status/XpHealStatus.cs

A Status subclass named XpHealStatus that heals the player when they gain XP. It sets UI title and icon, describes the heal percent per level, and applies health regeneration when OnGainExperience is called.

File Access
using System;
using System.Collections.Generic;
using System.Linq;
using Sandbox;
using static Sandbox.VertexLayout;

[Status(7, 0, 1f, 0, false )]
public class XpHealStatus : Status
{
	public XpHealStatus()
    {
		Title = "XP Recovery";
		IconPath = "textures/icons/xp_heal.png";
	}

	public override void Init(Player player)
	{
		base.Init(player);
	}

	public override void Refresh()
    {
		Description = GetDescription(Level);
    }

	public override string GetDescription(int newLevel)
	{
		return string.Format("When you gain XP, heal for {0}% of the amount", GetPercentForLevel(Level));
	}

	public override string GetUpgradeDescription(int newLevel)
	{
		return newLevel > 1 ? string.Format( "When you gain XP, heal for {0}%→{1}% of the amount", GetPercentForLevel( newLevel - 1), GetPercentForLevel( newLevel)) : GetDescription(newLevel);
	}

    public override void OnGainExperience(int xp)
    {
		float amount = xp * GetAmountForLevel( Level );
		
		if( Player.Health < Player.Stats[PlayerStat.MaxHp] )
			Player.TimeSinceChangeHP = 0f;

		Player.RegenHealth( amount );
	}

	public float GetAmountForLevel(int level)
	{
		return 0.15f + level * 0.20f + (level == 7 ? 0.2f : 0f);
	}

	public float GetPercentForLevel( int level )
	{
		return 15f + level * 20f + (level == 7 ? 20f : 0f);
	}

	//public string GetPrintAmountForLevel(int level)
 //   {
 //       return string.Format("{0:0.0}", GetAmountForLevel(level));
 //   }
}