A Skunk card type in a card game. It handles the Mismatch event when both chosen cards are skunks by pushing an event message, waiting 850ms in realtime, then popping the message. CanBeMatched checks that the adjacent cards are all skunks, and the card never dies (IsAlive is always true).
using Sandbox;
using System.Threading.Tasks;
public class CardSkunk : Card
{
public override bool IsAlive => true;
public override bool ShouldHandleEvent( EventType eventType )
{
return eventType == EventType.Mismatch && Manager.Instance.ChosenCards[0].CardType == CardType.Skunk && Manager.Instance.ChosenCards[1].CardType == CardType.Skunk && !IsLocked;
}
public override async Task HandleEventAsync( EventType eventType )
{
Manager.Instance.PushEventMessage( this, eventType );
// todo: sfx
await Task.DelayRealtime( 850 );
Manager.Instance.PopEventMessage();
}
public override bool CanBeMatched()
{
foreach(var card in Manager.Instance.GetNearbyCards(GridPos, adjacentOnly: true))
{
if ( card.CardType != CardType.Skunk )
return false;
}
return true;
}
}