relics/RelicRevolver.cs

A relic effect for the card game. On LevelStart it collects the player's cards that match an active bounty, shuffles them, then awaits the animation that shakes up to Level of them one by one with random delays between.

using Sandbox;
using System.Reflection.PortableExecutable;
using System.Runtime.Versioning;
using System.Threading.Tasks;

public class RelicRevolver : Relic
{
	public override bool ShouldHandleEvent( EventType eventType )
	{
		return eventType == EventType.LevelStart;
	}

	public override async Task HandleEventAsync(EventType eventType)
	{
		List<Card> validCards = new();

		foreach(var card in Manager.Instance.Cards)
		{
			if ( Manager.Instance.Bounties.ContainsKey( card.CardType ) )
				validCards.Add( card );
		}

		if ( validCards.Count == 0 )
			return;

		Manager.Instance.PushEventMessage( this, eventType );

		validCards.Shuffle();

		await Task.DelayRealtime( 400 );

		int numCardsToShake = Level;
		for ( int i = 0; i < Math.Min( numCardsToShake, validCards.Count ); i++ )
		{
			var card = validCards[i];
			await Manager.Instance.ShakeCard( card );
			await Task.DelayRealtime( Game.Random.Int( 150, 350 ) );
		}

		await Task.DelayRealtime( 500 );

		Manager.Instance.PopEventMessage();
	}
}