/// <summary>
        /// Loads in card data from the "cards.xml" resource.
        /// 
        /// TODO: Remove this & generate cards from the spell and creature data
        /// </summary>
        /// <returns>Dictionary mapping card names to Card class instance</returns>
        public static Dictionary<string, Card> LoadCards()
        {
            // Load in and parse our "cards.xml" resource file.
            var cardXmlDocument = new XmlDocument();
            cardXmlDocument.Load(GetResource("cards.xml"));

            var cards = new Dictionary<string, Card>();

            foreach (XmlNode cardData in cardXmlDocument.GetElementsByTagName("card"))
            {
                var name = cardData.Attributes["ID"].Value;

                // We load in the card's data, A card must have an
                //  ID, Cost, Type and related Creature or Spell ID.
                var card = new Card
                {
                    ID = name,
                    Type = Conversion.StringToEnum<CardType>(cardData["type"].InnerText),
                    CreatureID = cardData["creatureID"] == null ? null : cardData["creatureID"].InnerText,
                    SpellID = cardData["spellID"] == null ? null : cardData["spellID"].InnerText,
                    Cost = int.Parse(cardData["cost"].InnerText)
                };

                XmlNode effects = cardData["effects"];
                card.EffectData.AddRange(LoadEffects(effects, EffectType.card));

                cards.Add(name, card);
            }

            return cards;
        }
Example #2
0
        public Card CreateInstance()
        {
            var card = new Card
            {
                ID = ID, Type = Type, CreatureID = CreatureID, SpellID = SpellID, Cost = Cost, UID = SID.New()
            };

            foreach (var effect in EffectData)
            {
                // Need to create a new instance of effect for every creature!
                card.Effects.Add(Game.CardEffects.CreateInstance(effect.Name, effect.Attributes));
            }

            return card;
        }
Example #3
0
 protected virtual void OnPlayed(Card obj)
 {
     var handler = Played;
     handler?.Invoke(obj);
 }
Example #4
0
 /// <summary>
 /// Adds specified card into deck at random position.
 /// </summary>
 /// <param name="c"></param>
 public void PushRandom(Card c)
 {
     Push(c, ServerRandom.Generator.Next(0, Cards.Count));
 }
Example #5
0
 /// <summary>
 /// Adds a card into the deck at the specified position.
 /// If place is blank then card is added to the bottom of the deck.
 /// </summary>
 /// <param name="c">Card to push</param>
 /// <param name="place">Place where we want to insert card</param>
 public void Push(Card c, int place = -1)
 {
     Cards.Insert(place, c);
 }
        /// <summary>
        /// Loads in Creatures from the "creatures.xml" resource file.
        /// </summary>
        /// <returns>A dictionary mapping creature ID's to the actual Creature base instance.</returns>
        public static Dictionary<string, Creature> LoadCreatures(ref Dictionary<string, Card> cards)
        {
            // Parse the XML document.
            var creatureXmlDocument = new XmlDocument();
            creatureXmlDocument.Load(GetResource("creatures.xml"));

            var creatures = new Dictionary<string, Creature>();

            // Loop over each creature in the XML's base "creature" node.
            foreach (XmlNode creatureData in creatureXmlDocument.GetElementsByTagName("creature"))
            {
                var name = creatureData.Attributes["ID"].Value;

                // Load in all of the creature's base data
                // We load in booleans such as Taunt or MagicImmune
                //  by way of checking if that tag exists in the data.
                // All creatures need to have an ID, BaseHealth, Damage
                // Image value.
                var creature = new Creature
                {
                    ID = name,
                    Name = creatureData["name"].InnerText,
                    BaseHealth = int.Parse(creatureData["health"].InnerText),
                    Damage = int.Parse(creatureData["attack"].InnerText),
                    Taunt = creatureData.SelectSingleNode("taunt") != null,
                    SleepSickness = creatureData.SelectSingleNode("charge") == null,
                    Commander = creatureData.SelectSingleNode("commander") != null,
                    MagicImmune = creatureData.SelectSingleNode("magicimmune") != null,
                    PhysicalImmune = creatureData.SelectSingleNode("physicalimmune") != null,
                    MagicTargetable = creatureData.SelectSingleNode("magictargetable") != null,
                    PhysicalTargetable = creatureData.SelectSingleNode("physicaltargetable") != null,
                    Stealth = creatureData.SelectSingleNode("stealth") != null,
                    Image = creatureData.SelectSingleNode("image").InnerText,
                };

                // Load in any effects with our super handy generic effect loading method.
                XmlNode effects = creatureData["effects"];
                creature.EffectData.AddRange(LoadEffects(effects, EffectType.creature));
                creatures.Add(name, creature);

                //if (creatureData.SelectSingleNode("token") != null) continue;

                var card = new Card
                {
                    Cost = int.Parse(creatureData.SelectSingleNode("cost").InnerText),
                    CreatureID = name,
                    Type = CardType.Creature,
                    Token = creatureData.SelectSingleNode("token") != null,
                    ID = "summon_" + name
                };

                // Card effects, such as reducing cost each turn.
                XmlNode cardEffects = creatureData["cardeffects"];
                card.EffectData.AddRange(LoadEffects(cardEffects, EffectType.card));

                cards.Add(card.ID, card);
            }

            return creatures;
        }
        /// <summary>
        /// Loads in spells from the "spell.xml" resource file.
        /// </summary>
        /// <returns>A dictionary mapping spell names to the actual Spell class.</returns>
        public static Dictionary<string, Spell> LoadSpells(ref Dictionary<string, Card> cards)
        {
            // Load in and parse our "spell.xml" file
            var spellXmlDocument = new XmlDocument();
            spellXmlDocument.Load(GetResource("spells.xml"));

            var spells = new Dictionary<string, Spell>();

            // Loop over each node and add it to our dictionary
            foreach (XmlNode spellData in spellXmlDocument.GetElementsByTagName("spell"))
            {
                string name = spellData.Attributes["ID"].Value;
                var spell = GetSpell(spellData, name);

                spells.Add(name, spell);

                // Create a card for our spell
                var card = new Card
                {
                    Cost = int.Parse(spellData.SelectSingleNode("cost").InnerText),
                    SpellID = name,
                    Type = CardType.Spell,
                    Token = spellData.SelectSingleNode("token") != null,
                    ID = "cast_" + name
                };

                // Card effects, such as reducing cost each turn.
                XmlNode cardEffects = spellData["cardeffects"];
                card.EffectData.AddRange(LoadEffects(cardEffects, EffectType.card));

                cards.Add(card.ID, card);

            }
            return spells;
        }