Пример #1
0
 public void AttackTarget(Creature target)
 {
     OnAttack(target);
     Stealth = false;
     target.OnAttacked(this);
     target.TakeDamage(CalculatedDamage, AttackDamageType, this);
 }
Пример #2
0
        /// <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;
        }
Пример #3
0
        public bool Play(Creature target = null)
        {
            OnPlayed(this);
            if (CancelPlay) return false;
            switch (Type)
            {
                case CardType.Creature:
                    Game.Board.Summon(Owner, Game.Creatures[CreatureID]);
                    break;
                case CardType.Spell:
                    Game.Board.Cast(Owner, Game.Spells[SpellID], target);
                    break;
                default:
                    throw new ArgumentOutOfRangeException();
            }

            return true;
        }
Пример #4
0
        // Use a template model ?
        //  -> Load creature data externally
        //  -> Create an instance of this creature class for each creature in database
        //  -> Set appropriate attributes and add effects (based on data)
        //  -> Create deep clone using this function when we want to make a usable copy
        public Creature CreateInstance(Player owner, bool commander, int team)
        {
            var newCreature = new Creature
            {
                ID = ID,
                Description = Description,
                Name = Name,
                BaseHealth = BaseHealth,
                Damage = Damage,
                Team = team,
                Commander = commander,
                SleepSickness = SleepSickness,
                CanAttack = CanAttack,
                Taunt = Taunt,
                MagicImmune = MagicImmune,
                PhysicalImmune = PhysicalImmune,
                Stealth = Stealth,
                AttackDamageType = AttackDamageType,
                Owner = owner,
                Image = Image,
                UID = SID.New()
            };

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

            return newCreature;
        }
Пример #5
0
 protected virtual void OnTargetted(bool arg1, Creature arg2)
 {
     var handler = Targetted;
     handler?.Invoke(arg1, arg2);
 }
Пример #6
0
 protected virtual void OnKilled(Creature obj)
 {
     var handler = Killed;
     handler?.Invoke(obj);
 }
Пример #7
0
 protected virtual void OnDamageTaken(int arg1, DamageType arg2, Creature arg3)
 {
     var handler = DamageTaken;
     handler?.Invoke(arg1, arg2, arg3);
 }
Пример #8
0
 protected virtual void OnAttacked(Creature obj)
 {
     var handler = Attacked;
     handler?.Invoke(obj);
 }
Пример #9
0
        public void TakeDamage(int damage, DamageType type, Creature source)
        {
            if (MagicImmune && type == DamageType.Magic)
            {
                OnDamageTaken(0, type, source);
                return;
            }
            if (PhysicalImmune && type == DamageType.Physical)
            {
                OnDamageTaken(0, type, source);
                return;
            }

            var calcDamage = damage - CalculatedArmor;
            DamageTokens += calcDamage < 0 ? 0 : calcDamage;
            OnDamageTaken(calcDamage, type, source);

            if (CalculatedCurrentHealth <= 0)
            {
                Kill(source);
            }
        }
Пример #10
0
 public void Kill(Creature source)
 {
     Dead = true;
     // Call this after setting Dead to true
     // incase the callback wants to keep the creature alive!
     OnKilled(this);
 }
Пример #11
0
 /// <summary>
 /// Generates a list of targets from the spell and player data, 
 ///  then casts the spell on them.
 /// </summary>
 /// <param name="player">Player who is casting spell</param>
 /// <param name="spell">Spell to cast</param>
 /// <param name="pickedTarget">The creature/commander to target with spell, if needed.</param>
 /// <returns>True if spell cast started (even if spell was blocked), false if invalid target given.</returns>
 public bool Cast(Player player, Spell spell, Creature pickedTarget = null)
 {
     var targets = GetPossibleTargets(player, spell);
     switch (spell.TargetType)
     {
         case TargetType.Random:
             Cast(spell, new List<Creature> { targets[ServerRandom.Generator.Next(targets.Count)] });
             return true;
         case TargetType.Single:
             if (targets.Contains(pickedTarget))
             {
                 Cast(spell, new List<Creature> { pickedTarget });
                 return true;
             }
             return false;
         case TargetType.None:
             Cast(spell, targets);
             return true;
         default:
             throw new ArgumentOutOfRangeException();
     }
 }
Пример #12
0
 // TODO: Finish the actual game logic!
 public void Summon(Player owner, Creature creature)
 {
     Console.WriteLine("SUMMONING: " + creature.Name);
 }