perks/PerkBulletHurtSelfBounce.cs

Perk class that adds bullet bounce behavior and allows bullets to hurt the shooter. It registers a unique perk called "Reckless Bouncer", increases the number of bounces and sets a flag so bullets can hit the shooter.

Networking
using System;
using Sandbox;

[Perk( Rarity.Unique, locked: true, alwaysOfferDebug: false, IncludedCategories = new[] { PerkCategory.BulletBounce, PerkCategory.SelfDmg })]
public class PerkBulletHurtSelfBounce : Perk
{
	private enum Mod { NumBouncing, ReloadSpeed };


	static PerkBulletHurtSelfBounce()
	{
		Register<PerkBulletHurtSelfBounce>(
			name: "Reckless Bouncer",
			imagePath: "textures/icons/vector/bullet_hurt_self_bounce.png",
			description: level => $"+{(int)GetValue( level, Mod.NumBouncing )} bullet-icon bounces\nYour bullet-icon can hurt you"
		);
	}

	public override void Start()
	{
		base.Start();

	}

	public override void Refresh()
	{
		base.Refresh();

		Player.Modify( this, PlayerStat.BulletNumBouncing, GetValue( Level, Mod.NumBouncing ), ModifierType.Add );
		Player.Modify( this, PlayerStat.BulletCanHitShooter, 1f, ModifierType.Add );

		// todo: hurt you for X% instead of full dmg?
	}

	private static float GetValue( int level, Mod mod, bool isPercent = false )
	{
		switch ( mod )
		{
			case Mod.NumBouncing:
			default:
				return 3f;
		}
	}
}