A card type for a card matching game. When it is the second card of a match it plays cash and coin sounds, awards 3 money instead of 1 if the two matched cards are adjacent on the grid, adds the EarnExtraMoney stat bonus, and shows a floating money gain before crediting the player.
using Sandbox;
using System.Threading.Tasks;
public class CardCash : 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( "cash", Manager.Instance.ChosenCards[0], Manager.Instance.ChosenCards[1], volume: 1.3f, pitch: Game.Random.Float( 0.8f, 0.85f ) );
await Task.DelayRealtime( 550 );
bool isNearby = Manager.IsNearby( GridPos, Manager.Instance.ChosenCards[0].GridPos );
int moneyAmount = (isNearby ? 3 : 1) + (int)Manager.Instance.Stats[StatType.EarnExtraMoney];
Manager.Instance.PlayCardSfxBetween( "coin", Manager.Instance.ChosenCards[0], Manager.Instance.ChosenCards[1], volume: 1f, pitch: Game.Random.Float( 0.7f, 0.75f ) * (isNearby ? 1.3f : 0.9f) );
await Task.DelayRealtime( 50 );
Manager.Instance.SpawnGainMoneyFloater( moneyAmount, WorldPosition );
await Manager.Instance.GainMoney( moneyAmount );
await Task.DelayRealtime( 800 );
break;
}
Manager.Instance.PopEventMessage();
}
// todo: match text based on if +4 or +1
}