/// <summary> /// Starts a turn for the specified player /// </summary> /// <param name="player">The player who is starting their turn</param> public static void StartTurn(BasePlayer player) { GameEngine.GameState.CurrentPlayer = player; GameEngine.GameState.TurnNumber++; var currentPlayer = GameEngine.GameState.CurrentPlayer; // Increment their max mana currentPlayer.AddManaCrystal(); // Move any pending overload to active currentPlayer.Overload = currentPlayer.PendingOverload; currentPlayer.PendingOverload = 0; // Set the mana to max - overload currentPlayer.Mana = currentPlayer.MaxMana - currentPlayer.Overload; GameEventManager.TurnStart(player); // Draw a card currentPlayer.DrawCard(); }
/// <summary> /// Summons a minion onto the board /// </summary> /// <param name="minion">The minion to summon</param> /// <param name="subTarget">The sub target for this card, usually for targetting battle cry spells</param> /// <param name="gameboardPos">The position on the gameboard to place the card. A value of -1 means play it in the next available slot</param> /// <param name="cardEffect">The card effect to use</param> /// <param name="forceSummoned">Whether or not to force summon the minion, this means no battle cry effects</param> /// <param name="cardSource">Where, if any, should we remove the card from</param> public void SummonMinion(BaseMinion minion, IDamageableEntity subTarget, int gameboardPos = -1, CardEffect cardEffect = CardEffect.NONE, bool forceSummoned = false, ICollection <BaseCard> cardSource = null) { var gameState = GameEngine.GameState; if (cardSource != null) { if (!cardSource.Contains(minion)) { throw new InvalidOperationException(string.Format("Card source doesn't contain {0}", minion)); } cardSource.Remove(minion); } // Check if there are too many minions on the board var playZone = gameState.CurrentPlayerPlayZone; var playZoneCount = playZone.Count(slot => slot != null); if (playZoneCount >= Constants.MAX_CARDS_ON_BOARD) { throw new InvalidOperationException(string.Format("There are too many cards ({0}) in the playzone!", playZoneCount)); } int summonPosition = gameboardPos; if (gameboardPos == -1) { summonPosition = GameEngine.GameState.CurrentPlayerPlayZone.Count(card => card != null); } // If there is a card already in the target gameboard position, shift everything to the right and place it there if (playZone[summonPosition] != null) { for (int i = playZone.Count - 1; i > gameboardPos; i--) { playZone[i] = playZone[i - 1]; } } // Place the minion on the board playZone[summonPosition] = minion; // Set the time the card was played minion.TimePlayed = DateTime.Now; // Start the minion as exhausted unless it has charge if (!minion.HasCharge) { minion.ApplyStatusEffects(MinionStatusEffects.EXHAUSTED); } minion.ResetAttacksThisTurn(); // Remove mana from the player if (!forceSummoned) { this.Mana -= minion.CurrentManaCost; } // Call the card's card effect var multiCard = minion as IMultiCardEffectMinion; if (multiCard != null && !forceSummoned) { multiCard.UseCardEffect(cardEffect, subTarget); } // Fire minion placed event if (!forceSummoned) { GameEventManager.MinionPlaced(minion); } // Register deathrattle if applicable var deathrattleCard = minion as IDeathrattler; if (deathrattleCard != null) { deathrattleCard.RegisterDeathrattle(); } if (!forceSummoned) { // call the card's battlecry var battlecryCard = minion as IBattlecry; if (battlecryCard != null) { if (subTarget is BaseMinion && ((BaseMinion)subTarget).IsStealthed) { throw new InvalidOperationException("Can't target stealthed minions"); } battlecryCard.Battlecry(subTarget); } } // Fire card played event GameEventManager.MinionPlayed(minion); }