Mercurial > mm7
changeset 1537:fed56133bf8a
Player:GetSkillBonus cleanup, multiplier evaluation moved to a separate function, variable clanup, renaming, scope reduction
author | Grumpy7 |
---|---|
date | Sat, 07 Sep 2013 05:01:12 +0200 |
parents | e264ce95f27d |
children | d6778b04c12a |
files | Player.cpp Player.h |
diffstat | 2 files changed, 165 insertions(+), 343 deletions(-) [+] |
line wrap: on
line diff
--- a/Player.cpp Sat Sep 07 04:15:06 2013 +0200 +++ b/Player.cpp Sat Sep 07 05:01:12 2013 +0200 @@ -4805,282 +4805,136 @@ //----- (0048FC00) -------------------------------------------------------- -int Player::GetSkillBonus(enum CHARACTER_ATTRIBUTE_TYPE a2) -{ - Player *v2; // esi@1 - int armmaster_skill; // eax@1 - char v4; // di@1 - signed int v5; // ebx@1 - unsigned int armaster_mastery; // eax@2 - unsigned __int8 v7; // sf@5 - unsigned __int8 v8; // of@5 - PlayerEquipment *v9; // ebx@19 - Player *v10; // ecx@20 - PLAYER_SKILL_TYPE v11; // edi@21 - int v12; // eax@21 - int v13; // edi@21 - signed int v15; // esi@25 - char v16; // al@32 - int v18; // eax@36 - unsigned int v19; // eax@37 - unsigned int v20; // edi@40 - int v21; // edx@41 - int v22; // eax@42 - PLAYER_SKILL_TYPE v23; // edi@45 - unsigned __int16 v24; // ax@45 - unsigned __int16 v25; // bx@45 - unsigned int v26; // eax@45 - unsigned __int8 v27; // sf@50 - unsigned __int8 v28; // of@50 - unsigned int v29; // eax@52 - int v30; // eax@55 - int v31; // eax@58 - unsigned int v32; // eax@59 - int v33; // eax@65 - char v34; // si@65 - ITEM_EQUIP_TYPE v35; // edi@69 - int v36; // edx@70 - int v37; // eax@71 - PLAYER_SKILL_TYPE v38; // edi@74 - int v39; // eax@74 - int v40; // eax@89 - char v41; // si@89 - int v42; // eax@96 - PLAYER_SKILL_TYPE v43; // edx@97 - int v44; // eax@97 - int v45; // eax@98 - int v46; // eax@99 - int v47; // eax@100 - int v48; // eax@101 - int v49; // eax@102 - unsigned __int16 v50; // ax@113 - char v51; // di@113 - unsigned int v52; // eax@113 - int v53; // edi@113 - signed int i; // ecx@113 - unsigned __int16 v55; // ax@118 - char v56; // si@118 - unsigned int v57; // eax@118 - int v58; // esi@121 - signed int j; // ecx@121 - int base_value; // edi@126 - int attrib_modif; // eax@126 - signed int v62; // [sp-4h] [bp-30h]@26 - signed int v63; // [sp-4h] [bp-30h]@80 - int v64; // [sp+Ch] [bp-20h]@104 - int v65; // [sp+10h] [bp-1Ch]@104 - int v66; // [sp+14h] [bp-18h]@104 - int v67; // [sp+18h] [bp-14h]@104 - int v68; // [sp+1Ch] [bp-10h]@69 - //PlayerEquipment *v69; // [sp+20h] [bp-Ch]@1 - int skill_bonus; // [sp+24h] [bp-8h]@1 - int v71; // [sp+28h] [bp-4h]@1 - int a1; // [sp+34h] [bp+8h]@21 - int a1a; // [sp+34h] [bp+8h]@74 - signed int a1b; // [sp+34h] [bp+8h]@94 - int multiplier; - int arm_bonus; - int lvl_avl[4]; - - v2 = this; - skill_bonus = 0; - //v69 = 0; - multiplier =0; - arm_bonus =0; - v71 = 0; - armmaster_skill = GetActualSkillLevel(PLAYER_SKILL_ARMSMASTER); - v4 = armmaster_skill; - v5 = 1; - if ( armmaster_skill ) - { - armaster_mastery = SkillToMastery(armmaster_skill); - if ( a2 == CHARACTER_ATTRIBUTE_MELEE_DMG_BONUS ) - { - if ( armaster_mastery == 4 ) - multiplier =2; - else if ( armaster_mastery == 3 ) - multiplier =1; - } - else if ( a2 == CHARACTER_ATTRIBUTE_ATTACK ) - { - if ( armaster_mastery == 4 ) - multiplier =2; - else if ( armaster_mastery >= 2 ) - multiplier =1; +int Player::GetSkillBonus(enum CHARACTER_ATTRIBUTE_TYPE inSkill) +{ + int armsMasterBonus; + + armsMasterBonus = 0; + int armmaster_skill = GetActualSkillLevel(PLAYER_SKILL_ARMSMASTER); + if ( armmaster_skill > 0 ) + { + int multiplier = 0; + if ( inSkill == CHARACTER_ATTRIBUTE_MELEE_DMG_BONUS ) + { + multiplier = GetMultiplierForMastery(armmaster_skill, 0, 0, 1, 2); + } + else if ( inSkill == CHARACTER_ATTRIBUTE_ATTACK ) + { + multiplier = GetMultiplierForMastery(armmaster_skill, 0, 1, 1, 2); } - arm_bonus=(armmaster_skill&0x3F)*multiplier; - } - - switch(a2) + armsMasterBonus = multiplier * (armmaster_skill & 0x3F); + } + + switch(inSkill) { case CHARACTER_ATTRIBUTE_HEALTH: { - base_value = pBaseHealthPerLevelByClass[classType]; - attrib_modif = GetBodybuilding(); + int base_value = pBaseHealthPerLevelByClass[classType]; + int attrib_modif = GetBodybuilding(); return base_value * attrib_modif; } break; case CHARACTER_ATTRIBUTE_MANA: { - base_value = pBaseManaPerLevelByClass[classType]; - attrib_modif = GetMeditation(); + int base_value = pBaseManaPerLevelByClass[classType]; + int attrib_modif = GetMeditation(); return base_value * attrib_modif; } break; case CHARACTER_ATTRIBUTE_AC_BONUS: { - a1b = 0; - v71 = 0; - - for (j=0; j<16; ++j) - { - if (pEquipment.pIndices[j]&&(!pOwnItems[ pEquipment.pIndices[j]].Broken())) + bool wearingArmor = false; + bool wearingLeather = false; + unsigned int ACSum = 0; + + for (int j = 0; j < 16; ++j) + { + if (pEquipment.pIndices[j] && (!pOwnItems[pEquipment.pIndices[j]].Broken())) { - int curr_item =pOwnItems[pEquipment.pIndices[j]].uItemID; - v44=pItemsTable->pItems[curr_item].uSkillType; - switch (v44) + int curr_item = pOwnItems[pEquipment.pIndices[j]].uItemID; + PLAYER_SKILL_TYPE itemSkillType = (PLAYER_SKILL_TYPE)pItemsTable->pItems[curr_item].uSkillType; + int currArmorSkillLevel = GetActualSkillLevel(itemSkillType); + int multiplier = 0; + switch (itemSkillType) { case PLAYER_SKILL_STAFF: - - lvl_avl[0]=0; - lvl_avl[1]=1; - lvl_avl[2]=0; - lvl_avl[3]=0; + multiplier = GetMultiplierForMastery(currArmorSkillLevel, 0, 1, 1, 1); break; case PLAYER_SKILL_SWORD: case PLAYER_SKILL_SPEAR: - lvl_avl[0]=0; - lvl_avl[1]=0; - lvl_avl[2]=0; - lvl_avl[3]=1; + multiplier = GetMultiplierForMastery(currArmorSkillLevel, 0, 0, 0, 1); break; case PLAYER_SKILL_SHIELD: - a1b = 1; - lvl_avl[0]=1; - lvl_avl[1]=0; - lvl_avl[2]=1; - lvl_avl[3]=0; + wearingArmor = true; + multiplier = GetMultiplierForMastery(currArmorSkillLevel, 1, 1, 2, 2); break; case PLAYER_SKILL_LEATHER: - v71 = 1; - lvl_avl[0]=1; - lvl_avl[1]=0; - lvl_avl[2]=1; - lvl_avl[3]=0; - + wearingLeather = true; + multiplier = GetMultiplierForMastery(currArmorSkillLevel, 1, 1, 2, 2); break; case PLAYER_SKILL_CHAIN: - a1b = 1; - lvl_avl[0]=1; - lvl_avl[1]=0; - lvl_avl[2]=0; - lvl_avl[3]=0; + wearingArmor = true; + multiplier = GetMultiplierForMastery(currArmorSkillLevel, 1, 1, 1, 1); break; case PLAYER_SKILL_PLATE: - a1b = 1; - lvl_avl[0]=1; - lvl_avl[1]=0; - lvl_avl[2]=0; - lvl_avl[3]=0; + wearingArmor = true; + multiplier = GetMultiplierForMastery(currArmorSkillLevel, 1, 1, 1, 1); break; - default: - continue; } - - v50= GetActualSkillLevel((PLAYER_SKILL_TYPE)v44); - v51 = v50; - v52 = SkillToMastery(v50); - v53 = v51 & 0x3F; - for ( i = 0; i < (signed int)v52; ++i ) - { - if ( lvl_avl[i] ) - skill_bonus += v53; - } + ACSum += multiplier * (currArmorSkillLevel & 0x3F); } } - lvl_avl[0]=1; - lvl_avl[1]=1; - lvl_avl[2]=1; - lvl_avl[3]=0; - - v55 = GetActualSkillLevel(PLAYER_SKILL_DODGE); - v56 = v55; - v57 = SkillToMastery(v55); - if ( !a1b && (!v71 || v57 == 4) ) - { - v58 = v56 & 0x3F; - for ( j = 0; j < (signed int)v57; ++j ) - { - if ( lvl_avl[j] ) - skill_bonus += v58; - } - } - return skill_bonus; + int dodgeSkillLevel = GetActualSkillLevel(PLAYER_SKILL_DODGE); + int dodgeMastery = SkillToMastery(dodgeSkillLevel); + int multiplier = GetMultiplierForMastery(dodgeSkillLevel, 1, 2, 3, 3); + if ( !wearingArmor && (!wearingLeather || dodgeMastery == 4) ) + { + ACSum += multiplier * (dodgeSkillLevel & 0x3F); + } + return ACSum; } break; case CHARACTER_ATTRIBUTE_ATTACK: { - if ( v2->IsUnarmed() == 1 ) - { - v33 = v2->GetActualSkillLevel(PLAYER_SKILL_UNARMED); - if (!v33) + if ( this->IsUnarmed() ) + { + int unarmedSkill = this->GetActualSkillLevel(PLAYER_SKILL_UNARMED); + if (!unarmedSkill) { return 0; } - v34 = SkillToMastery(v33); - if (v34 >= 3) - { - multiplier = 2; - } - else + int multiplier = GetMultiplierForMastery(unarmedSkill, 0, 1, 2, 2); + return armsMasterBonus + multiplier * (unarmedSkill & 0x3F); + } + for (int i = 0; i < 16; ++i) + { + if ( this->HasItemEquipped((ITEM_EQUIP_TYPE)i) ) { - multiplier = 1; - } - v30 = multiplier * (v33 & 0x3F); - return arm_bonus + v30; - } - v35 = (ITEM_EQUIP_TYPE)0; - v68 = 0; - for (i=0; i<16 ; ++i) - { - if ( v2->HasItemEquipped((ITEM_EQUIP_TYPE)i) ) - { - v37 = v2->pEquipment.pIndices[i]-1; - if ( pItemsTable->pItems[v37].uEquipType <= EQUIP_MAIN_HAND) - break; + int currItemIndex = this->pEquipment.pIndices[i] - 1; + if ( pItemsTable->pItems[currItemIndex].uEquipType <= EQUIP_MAIN_HAND) + { + PLAYER_SKILL_TYPE currItemSkillType = (PLAYER_SKILL_TYPE)pItemsTable->pItems[currItemIndex].uSkillType; + int currentItemSkillLevel = this->GetActualSkillLevel(currItemSkillType); + if (currItemSkillType == PLAYER_SKILL_BLASTER) + { + int multiplier = GetMultiplierForMastery(currentItemSkillLevel, 1, 2, 3, 5); + return multiplier * (currentItemSkillLevel & 0x3F); + } + else if (currItemSkillType == PLAYER_SKILL_STAFF && this->GetActualSkillLevel(PLAYER_SKILL_UNARMED) > 0) + { + int unarmedSkillLevel = this->GetActualSkillLevel(PLAYER_SKILL_UNARMED); + int multiplier = GetMultiplierForMastery(currentItemSkillLevel, 1, 1, 2, 2); + return multiplier * (unarmedSkillLevel & 0x3F) + armsMasterBonus + (currentItemSkillLevel & 0x3F); + } + else + { + return armsMasterBonus + (currentItemSkillLevel & 0x3F); + } + } } } - if ( i >= 16 ) - return 0; - - v38 = (PLAYER_SKILL_TYPE)pItemsTable->pItems[v37].uSkillType; - a1a = v2->GetActualSkillLevel(v38); - if (v38 == PLAYER_SKILL_BLASTER) - { - v39 = SkillToMastery(a1a); - switch (v39) - { - case 1: multiplier=1; break; - case 2: multiplier=2; break; - case 3: multiplier=3; break; - case 4: multiplier=5; break; - } - return multiplier * (a1a & 0x3F); - } - else if (v38 == PLAYER_SKILL_STAFF && v2->GetActualSkillLevel(PLAYER_SKILL_UNARMED) > 0) - { - v40 = v2->GetActualSkillLevel(PLAYER_SKILL_UNARMED); - if ( SkillToMastery(v40) >= 3 ) - multiplier = 2; - else - multiplier = 1; - return multiplier * (v40 & 0x3F) + arm_bonus + (a1a & 0x3F); - } - else - { - return arm_bonus + (a1a & 0x3F); - } + return 0; } break; @@ -5088,25 +4942,19 @@ { for (int i = 0; i < 16; i++) { - if ( v2->HasItemEquipped((ITEM_EQUIP_TYPE)v71) ) + if ( this->HasItemEquipped((ITEM_EQUIP_TYPE)i) ) { - v11 = (PLAYER_SKILL_TYPE)pItemsTable->pItems[v2->pInventoryItemList[v2->pEquipment.pIndices[v71] - 1].uItemID].uSkillType; - v12 = this->GetActualSkillLevel(v11); - if ( v11 == PLAYER_SKILL_BOW ) + PLAYER_SKILL_TYPE currentItemSkillType = (PLAYER_SKILL_TYPE)pItemsTable->pItems[this->pInventoryItemList[this->pEquipment.pIndices[i] - 1].uItemID].uSkillType; + int currentItemSkillLevel = this->GetActualSkillLevel(currentItemSkillType); + if ( currentItemSkillType == PLAYER_SKILL_BOW ) { - return v12 & 0x3F; + int multiplier = GetMultiplierForMastery(currentItemSkillLevel, 0, 0, 0, 0); + return multiplier * (currentItemSkillLevel & 0x3F); } - else if ( v11 == PLAYER_SKILL_BLASTER ) + else if ( currentItemSkillType == PLAYER_SKILL_BLASTER ) { - v39 = SkillToMastery(a1); - switch (v39) - { - case 1: multiplier=1; break; - case 2: multiplier=2; break; - case 3: multiplier=3; break; - case 4: multiplier=5; break; - } - return multiplier * (v11 & 0x3F); + int multiplier = GetMultiplierForMastery(currentItemSkillLevel, 1, 2, 3, 5); + return multiplier * (currentItemSkillLevel & 0x3F); } } } @@ -5116,114 +4964,87 @@ case CHARACTER_ATTRIBUTE_MELEE_DMG_BONUS: { - if ( v2->IsUnarmed() ) - { - v18 = v2->GetActualSkillLevel(PLAYER_SKILL_UNARMED); - if ( !v18 ) + if ( this->IsUnarmed() ) + { + int unarmedSkillLevel = this->GetActualSkillLevel(PLAYER_SKILL_UNARMED); + if ( !unarmedSkillLevel ) return 0; { - v39 = SkillToMastery(v18); - switch (v39) - { - case 1: multiplier=0; break; - case 2: multiplier=1; break; - case 3: multiplier=1; break; - case 4: multiplier=2; break; - } - return multiplier * (v18 & 0x3F); - } - } - v20 = 0; - while ( 1 ) - { - if ( v2->HasItemEquipped((ITEM_EQUIP_TYPE)v20) ) - { - v22 = this->pInventoryItemList[this->pEquipment.pIndices[v20]].uItemID; - if ( pItemsTable->pItems[v22].uEquipType <= 1u ) - break; + int multiplier = GetMultiplierForMastery(unarmedSkillLevel, 0, 1, 2, 2); + return multiplier * (unarmedSkillLevel & 0x3F); } - v20++; - if ( (signed int)v20 >= 16 ) - return 0; - } - v71 = 0; - v23 = (PLAYER_SKILL_TYPE)pItemsTable->pItems[v22].uSkillType; - LOBYTE(v24) = v2->GetActualSkillLevel(v23); - v25 = v24; - v26 = SkillToMastery(v24); - switch (v23) - { - case PLAYER_SKILL_STAFF: - if ( (signed int)SkillToMastery(v25) >= 4 && v2->GetActualSkillLevel(PLAYER_SKILL_UNARMED) > 0) + } + for (int i = 0; i < 16; i++) + { + if ( this->HasItemEquipped((ITEM_EQUIP_TYPE)i) ) + { + int currItemId = this->pInventoryItemList[this->pEquipment.pIndices[i]].uItemID; + if ( pItemsTable->pItems[currItemId].uEquipType == EQUIP_MAIN_HAND || pItemsTable->pItems[currItemId].uEquipType == EQUIP_OFF_HAND ) { - v31 = v2->GetActualSkillLevel(PLAYER_SKILL_UNARMED); - if ( v31 ) + PLAYER_SKILL_TYPE currItemSkillType = (PLAYER_SKILL_TYPE)pItemsTable->pItems[currItemId].uSkillType; + int currItemSkillLevel = this->GetActualSkillLevel(currItemSkillType); + int baseSkillBonus; + int multiplier; + switch (currItemSkillType) { - v32 = SkillToMastery(v31); - switch (v32) + case PLAYER_SKILL_STAFF: + if ( SkillToMastery(currItemSkillLevel) >= 4 && this->GetActualSkillLevel(PLAYER_SKILL_UNARMED) > 0) + { + int unarmedSkillLevel = this->GetActualSkillLevel(PLAYER_SKILL_UNARMED); + int multiplier = GetMultiplierForMastery(unarmedSkillLevel, 0, 1, 2, 2); + return multiplier * (unarmedSkillLevel & 0x3F); + } + else { - case 1: multiplier=0; break; - case 2: multiplier=1; break; - case 3: multiplier=2; break; - case 4: multiplier=2; break; + return armsMasterBonus; } - return multiplier * (v31 & 0x3F); + break; + + case PLAYER_SKILL_DAGGER: + multiplier = GetMultiplierForMastery(currItemSkillLevel, 0, 0, 0, 1); + baseSkillBonus = multiplier * (currItemSkillLevel & 0x3F); + return armsMasterBonus + baseSkillBonus; + break; + case PLAYER_SKILL_SWORD: + multiplier = GetMultiplierForMastery(currItemSkillLevel, 0, 0, 0, 0); + baseSkillBonus = multiplier * (currItemSkillLevel & 0x3F); + return armsMasterBonus + baseSkillBonus; + break; + case PLAYER_SKILL_MACE: + case PLAYER_SKILL_SPEAR: + multiplier = GetMultiplierForMastery(currItemSkillLevel, 0, 1, 1, 1); + baseSkillBonus = multiplier * (currItemSkillLevel & 0x3F); + return armsMasterBonus + baseSkillBonus; + break; + case PLAYER_SKILL_AXE: + multiplier = GetMultiplierForMastery(currItemSkillLevel, 0, 0, 1, 1); + baseSkillBonus = multiplier * (currItemSkillLevel & 0x3F); + return armsMasterBonus + baseSkillBonus; + break; } } - else - { - return arm_bonus; - } - break; - - case PLAYER_SKILL_DAGGER: - v29 = SkillToMastery(v25); - switch (v29) - { - case 1: multiplier=0; break; - case 2: multiplier=0; break; - case 3: multiplier=0; break; - case 4: multiplier=1; break; - } - v30 = multiplier * (v29 & 0x3F); - return arm_bonus + v30; - break; - case PLAYER_SKILL_SWORD: - return arm_bonus; - break; - case PLAYER_SKILL_MACE: - case PLAYER_SKILL_SPEAR: - v29 = SkillToMastery(v25); - switch (v29) - { - case 1: multiplier=0; break; - case 2: multiplier=1; break; - case 3: multiplier=1; break; - case 4: multiplier=1; break; - } - v30 = multiplier * (v29 & 0x3F); - return arm_bonus + v30; - break; - case PLAYER_SKILL_AXE: - v29 = SkillToMastery(v25); - switch (v29) - { - case 1: multiplier=0; break; - case 2: multiplier=0; break; - case 3: multiplier=1; break; - case 4: multiplier=1; break; - } - v30 = multiplier * (v29 & 0x3F); - return arm_bonus + v30; - break; - } + } + } + return 0; } default: return 0; } - -} - +} + +unsigned int Player::GetMultiplierForMastery(unsigned int skillValue, int mult1, int mult2, int mult3, int mult4) +{ + int masteryLvl = SkillToMastery(skillValue); + switch (masteryLvl) + { + case 1: return mult1; + case 2: return mult2; + case 3: return mult3; + case 4: return mult4; + } + assert(false); + return 0; +} //----- (00490109) -------------------------------------------------------- // faces are: 0 1 2 3 human males // 4 5 6 7 human females
--- a/Player.h Sat Sep 07 04:15:06 2013 +0200 +++ b/Player.h Sat Sep 07 05:01:12 2013 +0200 @@ -621,6 +621,7 @@ inline bool IsMale() { return GetSexByVoice() == SEX_MALE;} inline bool IsFemale() { return !IsMale();} + unsigned int GetMultiplierForMastery(unsigned int skillValue, int mult1, int mult2, int mult3, int mult4); __int64 pConditions[20]; unsigned __int64 uExperience; char pName[16];