Example #1
0
 public int PlayerAttack(Player player)
 {
     if (player.TargetID != -1)
     {
         Creature target = GetCreatureByID(player.TargetID);
         if (target.Name != "null")
         {
             if (CanAttack(player, target) && DistanceToDiagonal(player.Position, target.Position) < 46) // < 46 because when standing diagonal, the distance is 45, when standing directly in front, it is 32
             {
                 int dmgDealt = target.ReceiveDamage(player.TotalStrength(), target.Defense);
                 if (target.Health < 1)
                 {
                     player.ReceiveExperience(target.Experience);
                     player.TargetID = -1;
                 }
                 return dmgDealt;
             }
         }
     }
     return -1;
 }
Example #2
0
        public List<DamageObject> PlayerCastSpell(Player player, Spell spell, Creature target, GameTime gameTime)
        {
            List<DamageObject> DamagedMonsters = new List<DamageObject>();
            int currentTime = (int)gameTime.TotalGameTime.TotalMilliseconds;
            if (!spell.TargetSpell)
            {
                for (int i = 0; i < spell.Area.Length / 3; i++)
                {
                    for (int j = 0; j < spell.Area.Length / 3; j++)
                    {
                        if (spell.Area[i + j])
                        {
                            /* TODO: Make area spell healing possible! */
                            int creatureID = GetCreatureIDFromTile(new Coordinates(player.Position.X - Coordinates.Step + (i * Coordinates.Step), player.Position.Y - Coordinates.Step + (j * Coordinates.Step)));
                            if (creatureID != -1)
                            {
                                Creature creature = GetCreatureByID(creatureID);
                                if (creature.Health > 0)
                                {
                                    int DamageDealt = creature.ReceiveDamage(spell.Damage + (player.MagicStrength * 2), 0);
                                    DamagedMonsters.Add(new DamageObject(creature, DamageDealt, spell.HealSpell, currentTime, currentTime + DamageObject.DamageDuration));
                                    if (creature.Health < 1)
                                    {
                                        player.ReceiveExperience(creature.Experience);
                                    }
                                }
                            }
                        }
                    }
                }
            }
            else
            {
                if(spell.HealSpell)
                {
                    int damage = spell.Damage + (player.MagicStrength * 2);
                    if (player.Health + damage > player.MaxHealth)
                    {
                        damage = player.MaxHealth - player.Health;
                        player.Health = player.MaxHealth;
                    }
                    else
                    {
                        player.Health += damage;
                    }
                    DamagedMonsters.Add(new DamageObject(player, damage, spell.HealSpell, currentTime, currentTime + DamageObject.DamageDuration));
                }
                else
                {
                    int DamageDealt = target.ReceiveDamage(spell.Damage + (player.MagicStrength * 2), 0);
                    DamagedMonsters.Add(new DamageObject(target, DamageDealt, spell.HealSpell, currentTime, currentTime + DamageObject.DamageDuration));
                    if (target.Health < 1)
                    {
                        player.ReceiveExperience(target.Experience);
                    }
                }
            }

            return DamagedMonsters;
        }
Example #3
0
 internal int CreatureDie(Creature creature, Player killer)
 {
     killer.ReceiveExperience(creature.Experience);
     if (creature.LootList.Count > 0)
     {
         for (int i = 0; i < creature.LootList.Count; i++)
         {
             if (Roll(creature.LootList[i].LootChance))
             {
                 CreateWorldItemFromListItem(creature.LootList[i].RealID, creature.Position);
             }
         }
     }
     if (creature.ID == killer.TargetID)
     {
         killer.TargetID = -1;
     }
     return creature.Experience;
 }