changeset 1593:5658d0f3b5ee

Player::GetAttackRecoveryTime removing label, fixing shield skill being ignored, fixing haste being ignored
author Grumpy7
date Sun, 08 Sep 2013 08:01:05 +0200
parents addae48bc203
children c0238b60d0f2
files Player.cpp Player.h
diffstat 2 files changed, 42 insertions(+), 47 deletions(-) [+]
line wrap: on
line diff
--- a/Player.cpp	Sun Sep 08 07:28:20 2013 +0200
+++ b/Player.cpp	Sun Sep 08 08:01:05 2013 +0200
@@ -2663,23 +2663,18 @@
   uint      weapon_recovery = base_recovery_times_per_weapon_type[0];
   if (bRangedAttack)
   {
-    if ( !HasItemEquipped(EQUIP_BOW) )
-      goto LABEL_17;
-    weapon = &pInventoryItemList[pEquipment.uBow - 1];
-    weapon_desc = &pItemsTable->pItems[weapon->uItemID];
-    weapon_recovery = base_recovery_times_per_weapon_type[weapon_desc->uSkillType];
-    goto LABEL_17;
-  }
-  else if ( IsUnarmed() == 1 )
-  {
-    if (GetActualSkillLevel(PLAYER_SKILL_UNARMED))
-    {
+    if ( HasItemEquipped(EQUIP_BOW) )
+    {
+      weapon = &pInventoryItemList[pEquipment.uBow - 1];
+      weapon_desc = &pItemsTable->pItems[weapon->uItemID];
+      weapon_recovery = base_recovery_times_per_weapon_type[weapon_desc->uSkillType];
+    }
+  }
+  else if ( IsUnarmed() == 1 && GetActualSkillLevel(PLAYER_SKILL_UNARMED) > 0)
+  {
       weapon_recovery = base_recovery_times_per_weapon_type[1];
-      goto LABEL_17;
-    }
-  }
-
-  if ( HasItemEquipped(EQUIP_MAIN_HAND) )
+  }
+  else if ( HasItemEquipped(EQUIP_MAIN_HAND) )
   {
     weapon = &pInventoryItemList[pEquipment.uMainHand - 1];
     weapon_desc = &pItemsTable->pItems[weapon->uItemID];
@@ -2705,58 +2700,43 @@
     }
   }
 
-LABEL_17:
   uint armour_recovery = 0;
   if ( HasItemEquipped(EQUIP_ARMOUR) )
   {
     auto armour_skill_type = pItemsTable->pItems[pInventoryItemList[pEquipment.uArmor - 1].uItemID].uSkillType;
     uint base_armour_recovery = base_recovery_times_per_weapon_type[armour_skill_type];
-
-    float armour_recovery_multipliers[4];
+    float multiplier;
+
     if (armour_skill_type == PLAYER_SKILL_LEATHER)
     {
-      armour_recovery_multipliers[0] = 1.0f;
-      armour_recovery_multipliers[1] = 0;
-      armour_recovery_multipliers[2] = 0;
-      armour_recovery_multipliers[3] = 0;
+      multiplier = GetArmorRecoveryMultiplierFromSkillLevel(armour_skill_type, 1.0f, 0, 0, 0);
     }
     else if (armour_skill_type == PLAYER_SKILL_CHAIN)
     {
-      armour_recovery_multipliers[0] = 1.0f;
-      armour_recovery_multipliers[1] = 0.5f;
-      armour_recovery_multipliers[2] = 0;
-      armour_recovery_multipliers[3] = 0;
+      multiplier = GetArmorRecoveryMultiplierFromSkillLevel(armour_skill_type, 1.0f, 0.5f, 0, 0);
     }
     else if (armour_skill_type == PLAYER_SKILL_PLATE)
     {
-      armour_recovery_multipliers[0] = 1.0f;
-      armour_recovery_multipliers[1] = 0.5f;
-      armour_recovery_multipliers[2] = 0.5f;
-      armour_recovery_multipliers[3] = 0;
+      multiplier = GetArmorRecoveryMultiplierFromSkillLevel(armour_skill_type, 1.0f, 0.5f, 0.5f, 0);
     }
     else
     {
       Error("Unknown armour type"); // what kind of armour is that?
-      armour_recovery_multipliers[0] = 1.0f;
-      armour_recovery_multipliers[1] = 1.0f;
-      armour_recovery_multipliers[2] = 1.0f;
-      armour_recovery_multipliers[3] = 1.0f;
-    }
-
-    uint skill_mastery = SkillToMastery(pActiveSkills[armour_skill_type]);
-    armour_recovery = base_armour_recovery * armour_recovery_multipliers[skill_mastery - 1];
+      multiplier = GetArmorRecoveryMultiplierFromSkillLevel(armour_skill_type, 1.0f, 1.0f, 1.0f, 1.0f);
+    }
+
+    armour_recovery = base_armour_recovery * multiplier;
   }
 
   uint shield_recovery = 0;
   if (HasItemEquipped(EQUIP_OFF_HAND) && GetEquippedItemEquipType(EQUIP_OFF_HAND) == EQUIP_SHIELD)
   {
-    float shield_recovery_multipliers[4] = {1, 0, 0, 0};
-
     auto shield = &pInventoryItemList[pEquipment.uShield - 1];
     auto skill_type = pItemsTable->pItems[shield->uItemID].uSkillType;
 
     uint shield_base_recovery = base_recovery_times_per_weapon_type[skill_type];
-    shield_recovery = shield_base_recovery * SkillToMastery(pActiveSkills[skill_type]);
+    float multiplier = GetArmorRecoveryMultiplierFromSkillLevel(skill_type, 1.0f, 0, 0, 0);
+    shield_recovery = shield_base_recovery * multiplier;
   }
 
   uint player_speed_recovery_reduction = GetParameterBonus(GetActualSpeed()),
@@ -2785,9 +2765,9 @@
     }
   }
 
-  uint v41 = 0;
-  if (pPlayerBuffs[PLAYER_BUFF_7].uExpireTime > 0)
-    v41 = 25;
+  uint hasteRecoveryReduction = 0;
+  if (pPlayerBuffs[PLAYER_BUFF_7].uExpireTime > 0 || pParty->pPartyBuffs[PARTY_BUFF_HASTE].uExpireTime > 0 )
+    hasteRecoveryReduction = 25;
 
   uint weapon_enchantment_recovery_reduction = 0;
   if ( weapon  )
@@ -2804,7 +2784,7 @@
                  shield_recovery
                  - armsmaster_recovery_reduction
                  - weapon_enchantment_recovery_reduction
-                 - v41
+                 - hasteRecoveryReduction
                  - sword_axe_bow_recovery_reduction
                  - player_speed_recovery_reduction;
 
@@ -2813,6 +2793,20 @@
   return recovery;
 }
 
+
+//----- new --------------------------------------------------------
+float Player::GetArmorRecoveryMultiplierFromSkillLevel( unsigned char armour_skill_type, float mult1, float mult2, float mult3, float mult4 )
+{
+  uint skill_mastery = SkillToMastery(pActiveSkills[armour_skill_type]);
+  switch (skill_mastery)
+  {
+    case 1: return mult1; break;
+    case 2: return mult2; break;
+    case 3: return mult3; break;
+    case 4: return mult4; break;
+  }
+}
+
 //----- (0048E4F8) --------------------------------------------------------
 int Player::GetMaxHealth()
 {
@@ -8991,4 +8985,4 @@
 void Player::SetCondUnconsciousWithBlockCheck( int blockable )
 {
   SetCondition(Condition_Dead, blockable);
-}
\ No newline at end of file
+}
--- a/Player.h	Sun Sep 08 07:28:20 2013 +0200
+++ b/Player.h	Sun Sep 08 08:01:05 2013 +0200
@@ -584,6 +584,7 @@
   unsigned int GetMultiplierForSkillLevel(unsigned int skillValue, int mult1, int mult2, int mult3, int mult4);
   int CalculateMeleeDmgToEnemyWithWeapon( ItemGen * weapon, unsigned int uTargetActorID , bool addOneDice);
   bool WearsItemAnyWhere(int item_id);
+  float GetArmorRecoveryMultiplierFromSkillLevel( unsigned char armour_skill_type, float param2, float param3, float param4, float param5 );
 
   bool IsWeak();
   bool IsDead();