changeset 1559:1f3f01d39300

Player::CanTrainToNextLevel simplified, Player::GetExperienceDisplayColor shortened a bit Player::CalculateIncommingDamage + fixed resistances not working if no resistance bonus (ignored luck bonus)
author Grumpy7
date Sun, 08 Sep 2013 00:35:03 +0200
parents 30db6d265ceb
children a0cd6465ae0d
files Items.h Player.cpp
diffstat 2 files changed, 30 insertions(+), 54 deletions(-) [+]
line wrap: on
line diff
--- a/Items.h	Sat Sep 07 23:06:13 2013 +0200
+++ b/Items.h	Sun Sep 08 00:35:03 2013 +0200
@@ -6,7 +6,7 @@
     DMGT_FIRE   = 0,
     DMGT_ELECTR = 1,
     DMGT_COLD   = 2,
-    DMGT_3      = 3,
+    DMGT_EARTH      = 3,
     DMGT_PHISYCAL= 4,
     DMGT_5      = 5,
     DMGT_SPIRIT = 6,
--- a/Player.cpp	Sat Sep 07 23:06:13 2013 +0200
+++ b/Player.cpp	Sun Sep 08 00:35:03 2013 +0200
@@ -1890,98 +1890,74 @@
 //----- (0048D45A) --------------------------------------------------------
 bool Player::CanTrainToNextLevel()
 {
-  int v1; // edx@1
-  int v2; // eax@1
-  int i; // esi@1
-
-  v1 = this->uLevel;
-  v2 = 0;
-  for ( i = 0; i < v1; ++i )
-    v2 += i + 1;
-  return (signed __int64)this->uExperience >= 1000 * v2;
+  int lvl = this->uLevel;
+  int neededExp = ((lvl * (lvl - 1)) / 2 * 1000);
 }
 
 //----- (0048D498) --------------------------------------------------------
 unsigned int Player::GetExperienceDisplayColor()
 {
-  unsigned int result; // eax@2
-
   if ( CanTrainToNextLevel() )
-    result = ui_character_bonus_text_color;
+    return ui_character_bonus_text_color;
   else
-    result = ui_character_default_text_color;
-  return result;
+    return ui_character_default_text_color;
 }
 
 //----- (0048D4B3) --------------------------------------------------------
-int Player::CalculateIncommingDamage( DAMAGE_TYPE dmg_type, int amount )
+int Player::CalculateIncommingDamage( DAMAGE_TYPE dmg_type, int dmg )
     {
 
   int resist_value; // edi@8
   int player_luck; // eax@21
   signed int res_rand_divider; // ebx@2
   int armor_skill; // eax@29
-  enum CHARACTER_ATTRIBUTE_TYPE player_resist; // [sp-4h] [bp-10h]@9
-  signed int result_amount_dmg; // [sp+8h] [bp-4h]@17
-
-  player_resist=CHARACTER_ATTRIBUTE_STRENGTH;
+
+  resist_value = 0;
   switch(dmg_type)
       {
-      case DMGT_FIRE:   player_resist=CHARACTER_ATTRIBUTE_RESIST_FIRE; break;
-      case DMGT_ELECTR: player_resist=CHARACTER_ATTRIBUTE_RESIST_AIR;  break;
-      case DMGT_COLD:   player_resist=CHARACTER_ATTRIBUTE_RESIST_WATER; break;
-      case DMGT_3: player_resist=CHARACTER_ATTRIBUTE_RESIST_EARTH; break;
+      case DMGT_FIRE:   resist_value = GetActualResistance(CHARACTER_ATTRIBUTE_RESIST_FIRE); break;
+      case DMGT_ELECTR: resist_value = GetActualResistance(CHARACTER_ATTRIBUTE_RESIST_AIR);  break;
+      case DMGT_COLD:   resist_value = GetActualResistance(CHARACTER_ATTRIBUTE_RESIST_WATER); break;
+      case DMGT_EARTH:      resist_value = GetActualResistance(CHARACTER_ATTRIBUTE_RESIST_EARTH); break;
       
-      case DMGT_SPIRIT: player_resist=CHARACTER_ATTRIBUTE_RESIST_SPIRIT;break;
-      case DMGT_MIND: player_resist=CHARACTER_ATTRIBUTE_RESIST_MIND; break;
-      case DMGT_BODY: player_resist=CHARACTER_ATTRIBUTE_RESIST_BODY; break;
+      case DMGT_SPIRIT: resist_value = GetActualResistance(CHARACTER_ATTRIBUTE_RESIST_SPIRIT);break;
+      case DMGT_MIND:   resist_value = GetActualResistance(CHARACTER_ATTRIBUTE_RESIST_MIND); break;
+      case DMGT_BODY:   resist_value = GetActualResistance(CHARACTER_ATTRIBUTE_RESIST_BODY); break;
       }
-  if (player_resist)
-    resist_value = GetActualResistance(player_resist);
-  else
-    resist_value = 0;
-
-  result_amount_dmg = amount;
+
   if ( classType == PLAYER_CLASS_LICH && resist_value >= 200 )
     return 0;
   player_luck = GetActualLuck();
   res_rand_divider = GetParameterBonus(player_luck) + resist_value + 30;
 
-  if ( resist_value )
+  if ( GetParameterBonus(player_luck) + resist_value > 0 )
   { 
-    if ( rand() % res_rand_divider >= 30 )
-    {
-      result_amount_dmg = amount >> 1;
+    for (int i = 0; i < 4; i++)
+    {
       if ( rand() % res_rand_divider >= 30 )
-      {
-        result_amount_dmg = amount >> 2;
-        if ( rand() % res_rand_divider >= 30 )
-        {
-          result_amount_dmg = amount >> 3;
-          if ( rand() % res_rand_divider >= 30 )
-            result_amount_dmg = amount >> 4;
-        }
-      }
-    }
-  }
-  if (( dmg_type == DMGT_PHISYCAL )&&( pEquipment.uArmor ))
-  {
-      if (!pOwnItems[pEquipment.uArmor-1].Broken()) 
+        dmg >>= 1;
+      else
+        break;
+    }
+  }
+  if (( dmg_type == DMGT_PHISYCAL ) && ( pEquipment.uArmor ))
+  {
+      if (!pOwnItems[pEquipment.uArmor - 1].Broken()) 
       {
         armor_skill = GetEquippedItemSkillType(EQUIP_ARMOUR);
         if ( armor_skill==PLAYER_SKILL_PLATE )
         {
           if ( SkillToMastery(pActiveSkills[PLAYER_SKILL_PLATE]) >= 3 )
-              return (int)(double)result_amount_dmg * 0.5;
+              return dmg / 2;
         }
         if (armor_skill==PLAYER_SKILL_CHAIN )
         {
           if (SkillToMastery(pActiveSkills[PLAYER_SKILL_CHAIN]) == 4) 
-             return (int)(double)result_amount_dmg * 0.66670001;
+             return dmg * 2 / 3;
         }
       }
   }
-  return result_amount_dmg;
+  return dmg;
 }
 
 //----- (0048D62C) --------------------------------------------------------