perks/PerkRandomFavorite.cs

A disabled legendary Perk class that occasionally grants the player one of their favorite perks. It tracks a counter and a cooldown, gives a random favorite perk item, and posts a local chat message when granting.

Networking
using System;
using Sandbox;

[Perk( Rarity.Legendary, disabled: true, alwaysOfferDebug: false )]
public class PerkRandomFavorite : Perk
{
	// todo: does this perk still work as intended?

	private int _perkCount;
	private TimeSince _timeSincePerk;

	public override float ImportanceMultiplier => 0.7f;

	static PerkRandomFavorite()
	{
		//Register<PerkRandomFavorite>(
		//	name: "Comfort Zone",
		//	imagePath: "textures/icons/vector/random_favorite.png",
		//	description: level => $"+1 of your favorite perks",
		//	upgradeDescription: level => $"+1 of your favorite perks"
		//);
	}

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

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

		ShouldUpdate = true;
		_perkCount++;
		_timeSincePerk = 0f;
	}

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

	}

	public override void Update( float dt )
	{
		base.Update( dt );

		if ( _perkCount > 0 && _timeSincePerk > 0.2f )
		{
			if( Player.FavoritePerks.Count > 0 )
			{
				var perkType = Player.FavoritePerks[Game.Random.Int( 0, Player.FavoritePerks.Count - 1 )];
				Player.GivePerkItem( perkType, -Player.FacingDir );

				Manager.Instance.Chat.AddLocalChatMessage( $"{Perk.GetRichTextToken( GetType() )} Got one of your favorite perks: {Perk.GetRichTextToken( perkType )}", from: "" );
			}

			_perkCount--;

			if ( _perkCount <= 0 )
				ShouldUpdate = false;
		}
	}
}