cards/CardCandle.cs

The CardCandle card effect. On a match, it picks up to two unrevealed cards near the candle and the second chosen card, plays flip sounds, reveals them briefly with staggered delays, then hides them again and clears the event message.

using Sandbox;
using System.Threading.Tasks;

public class CardCandle : Card
{
	public override bool ShouldHandleEvent( EventType eventType )
	{
		return eventType == EventType.Match && Manager.Instance.ChosenCards[0] == this;
	}

	public override async Task HandleEventAsync( EventType eventType )
	{
		Card cardToReveal0 = null;
		Card cardToReveal1 = null;

		// todo: when 2 candles are near 2 other cards, sometimes it only reveals 1 card (if candle A chooses the card that both candles are near, and the other card isn't near candle B)

		var nearbyCards0 = Manager.Instance.GetNearbyCards( GridPos ).Where(x => !x.IsRevealed).ToList();

		if(nearbyCards0.Count > 0)
			cardToReveal0 = nearbyCards0[Game.Random.Int(0, nearbyCards0.Count - 1)];

		var nearbyCards1 = Manager.Instance.GetNearbyCards( Manager.Instance.ChosenCards[1].GridPos ).Where( x => !x.IsRevealed ).ToList();

		if ( cardToReveal0 != null && nearbyCards1.Contains( cardToReveal0 ) )
			nearbyCards1.Remove( cardToReveal0 );

		if ( nearbyCards1.Count > 0 )
			cardToReveal1 = nearbyCards1[Game.Random.Int( 0, nearbyCards1.Count - 1 )];

		if ( cardToReveal0 == null && cardToReveal1 == null )
			return;

		Manager.Instance.PushEventMessage( this, eventType );

		await Task.DelayRealtime( 50 );

		Manager.Instance.PlayCardSfxBetween( "candle", this, Manager.Instance.ChosenCards[1], volume: 1f, pitch: Game.Random.Float(0.95f, 1.1f) );

		await Task.DelayRealtime( 100 );

		if ( cardToReveal0 != null )
		{
			Manager.Instance.PlayCardSfx( "card_flip", cardToReveal0, volume: 0.8f, pitch: Game.Random.Float( 1.15f, 1.2f ) );
			await Manager.Instance.RevealCard( cardToReveal0 );
			await Task.DelayRealtime( 200 );
		}

		if ( cardToReveal1 != null )
		{
			Manager.Instance.PlayCardSfx( "card_flip", cardToReveal1, volume: 0.8f, pitch: Game.Random.Float( 1.15f, 1.2f ) );
			await Manager.Instance.RevealCard( cardToReveal1 );
		}

		await Task.DelayRealtime( 1400 );

		if ( cardToReveal0 != null )
		{
			Manager.Instance.HideCard( cardToReveal0 );
			Manager.Instance.PlayCardSfx( "card_flip", cardToReveal0, volume: 0.7f, pitch: Game.Random.Float( 0.65f, 0.75f ) );

			await Task.DelayRealtime( 200 );
		}

		if ( cardToReveal1 != null )
		{
			Manager.Instance.HideCard( cardToReveal1 );
			Manager.Instance.PlayCardSfx( "card_flip", cardToReveal1, volume: 0.7f, pitch: Game.Random.Float( 0.65f, 0.75f ) );
		}
			
		await Task.DelayRealtime( 300 );

		Manager.Instance.PopEventMessage();
	}
}