CardATM is a card in a card-matching game, built on Card. On a Match event it plays an ATM sound and a coin sound between the two chosen cards, computes a money payout from the match count plus any EarnExtraMoney stat, spawns a money floater and adds the money to the player's total.
using Sandbox;
using System.Threading.Tasks;
public class CardATM : 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( "atm", Manager.Instance.ChosenCards[0], Manager.Instance.ChosenCards[1], volume: 1.85f, pitch: Game.Random.Float( 1.05f, 1.1f ) );
await Task.DelayRealtime( 950 );
Manager.Instance.PlayCardSfxBetween( "coin", Manager.Instance.ChosenCards[0], Manager.Instance.ChosenCards[1], volume: 1f, pitch: Game.Random.Float( 0.7f, 0.75f ) * Utils.Map( Manager.Instance.Stats[StatType.NumMatches], 1f, 5f, 1f, 1.4f) );
await Task.DelayRealtime( 50 );
int moneyAmount = Math.Min(MathX.FloorToInt(Manager.Instance.Stats[StatType.NumMatches] / 2f), 7) + (int)Manager.Instance.Stats[StatType.EarnExtraMoney];
Manager.Instance.SpawnGainMoneyFloater( moneyAmount, WorldPosition );
await Manager.Instance.GainMoney( moneyAmount );
await Task.DelayRealtime( 800 );
break;
}
Manager.Instance.PopEventMessage();
}
}