One card type in a card-matching game. When the card is the second card of a match it plays a sound, spawns a money floater at its world position and adds money to the player, with a bigger payout on the last match of the round.
using Sandbox;
using System.Threading.Tasks;
public class CardDiamondRing : Card
{
public override bool ShouldHandleEvent( EventType eventType )
{
switch ( eventType )
{
case EventType.Match:
return Manager.Instance.ChosenCards[1] == this;
}
return false;
}
public override async Task HandleEventAsync( EventType eventType )
{
Manager.Instance.PushEventMessage( this, eventType );
switch ( eventType )
{
case EventType.Match:
await Task.DelayRealtime( 50 );
Manager.Instance.PlayCardSfxBetween( "diamond_ring", Manager.Instance.ChosenCards[0], Manager.Instance.ChosenCards[1], volume: 1.25f, pitch: Game.Random.Float( 1f, 1.05f ) );
await Task.DelayRealtime( 350 );
bool isLastMatch = Manager.Instance.Cards.Count <= 2;
int moneyAmount = (isLastMatch ? 3 : 1) + (int)Manager.Instance.Stats[StatType.EarnExtraMoney];
Manager.Instance.SpawnGainMoneyFloater( moneyAmount, WorldPosition );
await Manager.Instance.GainMoney( moneyAmount );
await Task.DelayRealtime( 800 );
break;
}
Manager.Instance.PopEventMessage();
}
}