status/DashCharmStatus.cs
using System;
using System.Collections.Generic;
using System.Linq;
using Sandbox;
[Status( 5, 0, 1f, 0, false )]
public class DashCharmStatus : Status
{
private List<Thing> _touched = new();
public DashCharmStatus()
{
Title = "Quick Kiss";
IconPath = "textures/icons/dash_charm.png";
}
public override void Init( Player player )
{
base.Init( player );
Player.Stats[PlayerStat.DashCharm] = 1f;
}
public override void Refresh()
{
Description = GetDescription( Level );
}
public override string GetDescription( int newLevel )
{
return string.Format( "{0}% chance to charm enemies you touch while dashing", GetPercentForLevel( Level ) );
}
public override string GetUpgradeDescription( int newLevel )
{
return newLevel > 1 ? string.Format( "{0}%→{1}% chance to charm enemies you touch while dashing", GetPercentForLevel( newLevel - 1 ), GetPercentForLevel( newLevel ) ) : GetDescription( newLevel );
}
public override void OnDashStarted()
{
base.OnDashStarted();
_touched.Clear();
}
public override void Colliding( Thing other, float percent, float dt )
{
base.Colliding( other, percent, dt );
if ( !Player.IsDashing || _touched.Contains(other) || other is Boss )
return;
if(other is Enemy enemy && !enemy.IsCharmed)
{
if( Game.Random.Float( 0f, 1f ) < GetChanceForLevel( Level ) )
{
enemy.Charm();
Manager.Instance.PlaySfxNearby( "charm", enemy.Position2D, pitch: Game.Random.Float(0.9f, 1.1f), volume: 1.3f, maxDist: 5f );
}
else
{
enemy.Flash( 0.1f, new Color( 1f, 0.1f, 1f ) );
}
_touched.Add( other );
}
}
public override void OnDashFinished()
{
base.OnDashFinished();
}
public float GetChanceForLevel( int level )
{
return 0.18f + level * 0.08f + (level == 5 ? 0.04f : 0f);
}
public float GetPercentForLevel( int level )
{
return 18 + level * 8 + (level == 5 ? 4 : 0);
}
}