protected void CopyValuesTo(BaseCard otherCard) { otherCard.Owner = this.Owner; otherCard.Name = this.Name; otherCard.internalValues = new Dictionary <int, int>(this.internalValues); otherCard.valueModifiers = new Dictionary <int, int>(this.valueModifiers); }
/// <summary> /// Creates a random deck from a set of available card instances. /// /// The Deck property must be initialized before calling this method. /// </summary> /// <param name="availCards">List of available card instances.</param> /// <param name="maxCount">Number of card instances in the resulting deck. Must be equal or smaller to the number of elements in availCardTypes</param> /// <param name="rnd">Pseudo-RNG instance. The method will create its own instance if rnd is null.</param> public void CreateRandomDeck(IEnumerable <BaseCard> availCards, int maxCount, Random rnd = null) { if (Deck == null) { throw new InvalidOperationException("Deck cannot be null"); } if (rnd == null) { rnd = new Random(); } List <BaseCard> remainingAvailCards = new List <BaseCard>(availCards); if (maxCount > remainingAvailCards.Count) { maxCount = remainingAvailCards.Count; } List <BaseCard> newDeck = new List <BaseCard>(maxCount); for (int i = 0; i < maxCount; i++) { int idx = rnd.Next(remainingAvailCards.Count); BaseCard newCard = remainingAvailCards[idx].CreateCopy(); newCard.Owner = this; newDeck.Add(newCard); remainingAvailCards.RemoveAt(idx); } Deck.SetDeck(newDeck); }
/// <summary> /// Removes the card from hand. /// </summary> /// <returns>The card from hand or null if index is invalid</returns> /// <param name="index">Index.</param> public bool RemoveCard(BaseCard card) { if (Cards.Contains(card)) { Cards.Remove(card); return(true); } return(false); }
/// <summary> /// Add a card to the hand. Calls the ApplyAddToHandEffect event on the card. /// </summary> /// <param name="card"></param> public void AddCardToHand(BaseCard card) { if (card == null) { throw new ArgumentNullException(nameof(card)); } Cards.Add(card); card.ApplyAddToHandEffect(); }
/// <summary> /// Removes the card from hand. /// </summary> /// <returns>The card from hand or null if index is invalid</returns> /// <param name="index">Index.</param> public BaseCard PopCard(int index) { BaseCard card = PeekCard(index); if (card == null) { return(null); } Cards.Remove(card); return(card); }
public BaseCard DrawCard() { if (Deck.Count == 0) { return(null); } BaseCard card = Deck[0]; Deck.RemoveAt(0); // Apply possible draw effect card.ApplyDrawEffect(); return(card); }
/// <summary> /// Creates a random deck from a set of available card types. The types in the collection must be derived from <see cref="T:MyTCGLib.BaseCard"/>, /// otherwise the method will create an exception. /// /// The Deck property must be initialized before calling this method. /// </summary> /// <param name="availCardTypes">List of available card types.</param> /// <param name="maxCount">Number of card instances in the resulting deck. Must be equal or smaller to the number of elements in availCardTypes</param> /// <param name="rnd">Pseudo-RNG instance. The method will create its own instance if rnd is null.</param> public void CreateRandomDeckFromTypes(IEnumerable <Type> availCardTypes, int maxCount, Random rnd = null) { if (Deck == null) { throw new InvalidOperationException("Deck cannot be null"); } List <BaseCard> availCards = new List <BaseCard>(); foreach (Type t in availCardTypes) { BaseCard card = (BaseCard)Activator.CreateInstance(t); availCards.Add(card); } CreateRandomDeck(availCards, maxCount, rnd); }
/// <summary> /// Draws a card from the deck. /// </summary> /// <returns><c>true</c>, if card was drawn, <c>false</c> otherwise.</returns> public virtual bool DrawCard() { if (Hand == null) { throw new InvalidOperationException("Hand cannot be null"); } // Draw a card (if available) and apply draw effect BaseCard drawnCard = Deck.DrawCard(); if (drawnCard == null) { // Can't draw any more cards return(false); } Logger.Log("Player " + this + " has drawn card " + drawnCard); Hand.AddCardToHand(drawnCard); return(true); }
/// <summary> /// Used to apply an effect when this card is targeted by another card (or effect). Like damage or heal spells. /// /// Invoked AFTER the target effect has happened and any modifications have been applied (e.g. damage) /// </summary> public virtual void ApplyPostTargetEffect(BaseCard instigator) { Logger.Log(this + ".ApplyPostTargetEffect(instigator: " + instigator + ")"); }
/// <summary> /// Used to apply an effect when this card is targeted by another card (or effect). Like damage or heal spells. /// /// Invoked BEFORE the target effect has happened and any modifications have been applied (e.g. damage) /// /// Return false to indicate an abort of the game flow. /// </summary> public virtual bool ApplyPreTargetEffect(BaseCard instigator) { Logger.Log(this + ".ApplyPreTargetEffect(instigator: " + instigator + ")"); return(true); }