Behavior for the Umbrella card. On reveal it toggles the card between open and closed umbrella states, plays the matching sound effect and shakes the card, with an early exit when the revealed pair are both umbrellas.
using Sandbox;
using System.Threading.Tasks;
public class CardUmbrella : Card
{
public override bool ShouldHandleEvent( EventType eventType )
{
return eventType == EventType.Reveal && Manager.Instance.RevealedCard == this;
}
public override async Task HandleEventAsync( EventType eventType )
{
if(Manager.Instance.Cards.Count == 2 && Manager.Instance.ChosenCards.Count == 2 && Manager.Instance.ChosenCards[1] == this )
{
var otherCard = Manager.Instance.ChosenCards[0];
if ( otherCard.CardType == this.CardType )
return;
}
Manager.Instance.PushEventMessage( this, eventType );
await Task.DelayRealtime( 200 );
if ( CardType == CardType.Umbrella )
{
SetCardType( CardType.UmbrellaClosed );
Manager.Instance.PlayCardSfx( "umbrella_close", this, volume: 1.1f, pitch: Game.Random.Float( 0.9f, 1.1f ) );
}
else
{
SetCardType( CardType.Umbrella );
Manager.Instance.PlayCardSfx( "umbrella_open", this, volume: 1.5f, pitch: Game.Random.Float( 0.9f, 1.1f ) );
}
await Manager.Instance.ShakeCard( this, time: 0.2f, easingType: EasingType.QuadOut, playSfx: false );
await Task.DelayRealtime( 400 );
Manager.Instance.PopEventMessage();
}
public override string GetEventText( EventType eventType )
{
return GetCardDescription( CardType.Umbrella );
}
}