A legendary perk class that triggers when the player dashes. It may grant +1 max HP on a percent chance and alerts all enemies to target the player, plays sound and shows floater text, and sets visual highlight properties.
using System;
using Sandbox;
[Perk( Rarity.Legendary, disabled: true, alwaysOfferDebug: false )]
public class PerkDashAlertEnemies : Perk
{
private enum Mod { Chance };
private int _hpAdded;
static PerkDashAlertEnemies()
{
//Register<PerkDashAlertEnemies>(
// name: "Grandiose",
// imagePath: "textures/icons/vector/dash_alert_enemies.png",
// description: level => $"On dash, all enemies target you, and {GetValue( level, Mod.Chance, true )}% chance for +1 max hp",
// upgradeDescription: level => $"On dash, all enemies target you, and {GetValue( level - 1, Mod.Chance, true )}%→{GetValue( level, Mod.Chance, true )}% chance for +1 max hp"
//);
}
public override void Start()
{
base.Start();
HighlightColor = new Color( 0.5f, 0.75f, 1f );
HighlightDuration = 0.5f;
HighlightOpacity = 4f;
}
public override void Refresh()
{
base.Refresh();
}
public override void OnDashStarted( Vector2 dir )
{
base.OnDashStarted( dir );
if ( Game.Random.Float( 0f, 1f ) < GetValue( Level, Mod.Chance ) )
{
_hpAdded++;
Player.Modify( this, PlayerStat.MaxHp, _hpAdded, ModifierType.Add );
Manager.Instance.SpawnFloaterTextRpc( Player.WorldPosition.WithZ( 65f ), "+1 MAX HP!", new Color( 0f, 0.8f, 0f ), size: 1.2f, floaterType: FloaterType.PositiveMessage );
Manager.Instance.PlaySfxNearbyRpc( "heal", Player.Position2D, pitch: Game.Random.Float( 3.2f, 3.4f ), volume: 1.1f, maxDist: 300f );
Highlight();
}
// todo: change to a different downside
Manager.Instance.AlertAllEnemies( Player );
}
private static float GetValue( int level, Mod mod, bool isPercent = false )
{
switch ( mod )
{
case Mod.Chance:
default:
return isPercent
? 4f + 8f * level
: 0.04f + 0.08f * level;
}
}
}