/// <summary> /// This method removes a spell from the stack and puts it in its owner's graveyard. If the given spell is not on the stack, then this effect does nothing. /// </summary> /// <param name="card">This spell is the spell that is to be countered.</param> public void Counter(IResolvable obj) { if (Stack.Contains(obj)) { Stack <IResolvable> temp = new Stack <IResolvable>(Stack.Count); IResolvable topmost = null; do { topmost = Stack.Pop(); if (topmost == obj) { break; } temp.Push(topmost); topmost = null; } while (Stack.Count > 0); while (temp.Count > 0) { Stack.Push(temp.Pop()); } if (topmost != null) { if (topmost is Card) { (topmost as Card).Owner.Graveyard.Add(topmost as Card); CardHasChangedZones?.Invoke(this, topmost as Card, Common.Enums.Zone.Stack, Common.Enums.Zone.Graveyard); } } } CheckStateBasedActions(); }
/// <summary> /// /// </summary> /// <param name="permanent"></param> public void MoveFromBattlefieldToGraveyard(Card permanent) { RemovePermanentFromBattlefield(permanent); permanent.ClearCounters(); permanent.Owner.Graveyard.Add(permanent); CardHasChangedZones?.Invoke(this, permanent, Common.Enums.Zone.Battlefield, Common.Enums.Zone.Graveyard); }
/// <summary> /// /// </summary> /// <param name="action"></param> /// <param name="player"></param> /// <param name="playerCanCastSorceries"></param> private void PlayCard(PlayCardAction action, Player player, bool playerCanCastSorceries) { // If it's a land card, it bypasses the stack if (action.Card.IsALand) { // Only play the land if the player is allowed to play a turn right now if (playerCanCastSorceries && player.LandsPlayedThisTurn < player.MaxLandsPlayedThisTurn) { PlayLand(action.Card); player.LandsPlayedThisTurn++; CardHasChangedZones?.Invoke(this, action.Card, Common.Enums.Zone.Stack, Common.Enums.Zone.Battlefield); } } else { // Make player pay the cost of the Card if (action.Card.Cost.Pay()) { // Put the Card onto the stack action.Card.OnCast?.Invoke(this, action.Card); player.Hand.Remove(action.Card); PushOntoStack(action.Card, Common.Enums.Zone.Hand); } } CheckStateBasedActions(); }
/// <summary> /// /// </summary> /// <param name="permanent"></param> public void PutPermanentOnBattlefield(Card permanent) { permanent.Controller.Battlefield.Add(permanent); // Whenever a permanent enters the battlefield, it gets summoning sickness. This only affects whether creatures can attack or activate abilities that require them to tap/untap permanent.HasSummoningSickness = true; SubscribeToEvents(permanent); CardHasChangedZones?.Invoke(this, permanent, Common.Enums.Zone.Stack, Common.Enums.Zone.Battlefield); }