Esempio n. 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;
 }
Esempio n. 2
0
 internal List<DamageObject> PlayerAttack(Player player, GameTime gameTime)
 {
     List<DamageObject> DamagedMonsters = new List<DamageObject>();
     int currentTime = (int)gameTime.TotalGameTime.TotalMilliseconds;
     if (player.TargetID != -1)
     {
         Creature target = GetCreatureByID(player.TargetID);
         if (target.Name != "null")
         {
             // TODO: Fix below so it works with the new coordinate system (which is screen coordinates / 32)
             if (CanAttack(player, target) && DistanceToDiagonal(player.Position, target.Position) < 2) // < 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);
                 DamagedMonsters.Add(new DamageObject(target, dmgDealt, DamageObject.Text_Damage, currentTime, currentTime + DamageObject.DamageDuration));
                 if (target.Health < 1)
                 {
                     int experience = CreatureDie(target, player);
                     DamagedMonsters.Add(new DamageObject(player, experience, DamageObject.Text_Experience, currentTime, currentTime + DamageObject.DamageDuration));
                 }
             }
         }
     }
     return DamagedMonsters;
 }