Mercurial > mm7
diff Player.cpp @ 1550:cdb7fafede0c
Player::CalculateMeleeDamageTo extracted 2 almost identical sections to a separate function, variable cleanup, changed parameter types
author | Grumpy7 |
---|---|
date | Sat, 07 Sep 2013 09:45:09 +0200 |
parents | 5a3afcaa6717 |
children | a9e8d2a7abb5 |
line wrap: on
line diff
--- a/Player.cpp Sat Sep 07 09:16:55 2013 +0200 +++ b/Player.cpp Sat Sep 07 09:45:09 2013 +0200 @@ -1864,153 +1864,101 @@ } //----- (0048CDDB) -------------------------------------------------------- -int Player::CalculateMeleeDamageTo(int a2, int a3, unsigned int uTargetActorID) -{ - int v4; // esi@1 - Player *v5; // edi@1 - ItemGen *v6; // ebx@4 - unsigned int v7; // ebp@4 - unsigned int v8; // esi@4 - int v9; // eax@4 - int v10; // eax@9 - char v11; // zf@9 - int v12; // esi@10 - int v13; // eax@11 - enum MONSTER_SUPERTYPE v14; // edx@24 - ItemGen *v15; // ebx@35 - unsigned int v16; // ebp@35 - unsigned int v17; // esi@35 - int v18; // edx@38 - int v19; // eax@40 - enum MONSTER_SUPERTYPE v20; // edx@53 - int v21; // esi@62 - int v22; // eax@63 - int v23; // ebx@63 - int v24; // ebx@63 +int Player::CalculateMeleeDamageTo( bool ignoreSkillBonus, bool ignoreOffhand, unsigned int uTargetActorID ) +{ + int dmgSum; // esi@62 signed int result; // eax@64 - MONSTER_SUPERTYPE v26; // [sp-4h] [bp-24h]@20 - MONSTER_SUPERTYPE v27; // [sp-4h] [bp-24h]@49 - int v28; // [sp+10h] [bp-10h]@1 - int v29; // [sp+10h] [bp-10h]@33 - signed int v30; // [sp+14h] [bp-Ch]@7 - signed int v31; // [sp+14h] [bp-Ch]@36 - int v32; // [sp+18h] [bp-8h]@1 - int v33; // [sp+18h] [bp-8h]@8 - int v34; // [sp+1Ch] [bp-4h]@1 - int v35; // [sp+28h] [bp+8h]@37 - - v4 = 0; - v5 = this; - v34 = 0; - v32 = 0; - v28 = 0; + int mainWpnDmg; // [sp+18h] [bp-8h]@1 + int offHndWpnDmg; // [sp+1Ch] [bp-4h]@1 + + offHndWpnDmg = 0; + mainWpnDmg = 0; if ( IsUnarmed() ) { - v32 = rand() % 3 + 1; -LABEL_61: - v34 = v4; + mainWpnDmg = rand() % 3 + 1; } else { - if ( HasItemEquipped(EQUIP_MAIN_HAND) ) - { - v6 = &this->pInventoryItemList[v5->pEquipment.uMainHand-1]; - v7 = v6->uItemID; - v9 = pItemsTable->pItems[v7].uDamageDice; - if ( pItemsTable->pItems[v7].uSkillType == PLAYER_SKILL_SPEAR && !v5->pEquipment.uShield ) - ++v9; - v30 = pItemsTable->pItems[v7].uDamageRoll; - for (int i = 0; i < v9; i++) - { - v10 = rand(); - v28 += v10 % v30 + 1; - } - v12 = pItemsTable->pItems[v7].uDamageMod + v28; - if ( uTargetActorID > 0) + if ( HasItemEquipped(EQUIP_MAIN_HAND) ) + { + ItemGen *mainHandItemGen = &this->pInventoryItemList[this->pEquipment.uMainHand-1]; + int itemId = mainHandItemGen->uItemID; + bool addOneDice = false; + if ( pItemsTable->pItems[itemId].uSkillType == PLAYER_SKILL_SPEAR && !this->pEquipment.uShield ) + addOneDice = true; + mainWpnDmg = CalculateMeleeDmgToEnemyWithWeapon(mainHandItemGen, uTargetActorID, addOneDice); + } + if ( !ignoreOffhand ) + { + if ( this->HasItemEquipped(EQUIP_OFF_HAND) ) { - v13 = v6->uSpecEnchantmentType; - if ( MonsterStats::BelongsToSupertype(uTargetActorID, MONSTER_SUPERTYPE_UNDEAD) && (v13 == 64 || v7 == ITEM_ARTIFACT_GHOULSBANE || v7 == ITEM_ARTIFACT_GIBBET || v7 == ITEM_RELIC_JUSTICE) ) - { - v12 *= 2; - } - else if (MonsterStats::BelongsToSupertype(uTargetActorID, MONSTER_SUPERTYPE_KREEGAN) && ( v13 == 39 || v7 == ITEM_ARTIFACT_GIBBET)) + ItemGen *offHandItemGen = (ItemGen *)&this->pInventoryItemList[this->pEquipment.uShield - 1]; + int itemId = offHandItemGen->uItemID; + if ( pItemsTable->pItems[itemId].uEquipType != EQUIP_SHIELD ) { - v12 *= 2; - } - else if (MonsterStats::BelongsToSupertype(uTargetActorID, MONSTER_SUPERTYPE_DRAGON) && ( v13 == 40 || v7 == ITEM_ARTIFACT_GIBBET)) - { - v12 *= 2; - } - else if (MonsterStats::BelongsToSupertype(uTargetActorID, MONSTER_SUPERTYPE_TITAN) && ( v13 == 65 )) - { - v12 *= 2; + offHndWpnDmg = CalculateMeleeDmgToEnemyWithWeapon(offHandItemGen, uTargetActorID, false); } } - if ( (signed int)SkillToMastery(v5->pActiveSkills[2]) >= 3 - && pItemsTable->pItems[v6->uItemID].uSkillType == 2 - && rand() % 100 < 10 ) - v12 *= 3; - v32 = v12; - } - v29 = 0; - if ( !a3 ) - { - if ( v5->HasItemEquipped(EQUIP_OFF_HAND) ) - { - v15 = (ItemGen *)&v5->pInventoryItemList[v5->pEquipment.uShield - 1]; - v16 = v15->uItemID; - if ( pItemsTable->pItems[v16].uEquipType != EQUIP_SHIELD ) - { - v31 = pItemsTable->pItems[v16].uDamageRoll; - v35 = pItemsTable->pItems[v16].uDamageDice; - for (int i = 0; i < v35; i++) - { - v10 = rand(); - v29 += v10 % v31 + 1; - } - v4 = pItemsTable->pItems[v16].uDamageMod + v29; - if ( uTargetActorID > 0) - { - v19 = v15->uSpecEnchantmentType; - if ( MonsterStats::BelongsToSupertype(uTargetActorID, MONSTER_SUPERTYPE_UNDEAD) && (v19 == 64 || v16 == ITEM_ARTIFACT_GHOULSBANE || v16 == ITEM_ARTIFACT_GIBBET || v16 == ITEM_RELIC_JUSTICE) ) - { - v4 *= 2; - } - else if (MonsterStats::BelongsToSupertype(uTargetActorID, MONSTER_SUPERTYPE_KREEGAN) && ( v19 == 39 || v16 == ITEM_ARTIFACT_GIBBET)) - { - v4 *= 2; - } - else if (MonsterStats::BelongsToSupertype(uTargetActorID, MONSTER_SUPERTYPE_DRAGON) && ( v19 == 40 || v16 == ITEM_ARTIFACT_GIBBET)) - { - v4 *= 2; - } - else if (MonsterStats::BelongsToSupertype(uTargetActorID, MONSTER_SUPERTYPE_TITAN) && ( v19 == 65 )) - { - v4 *= 2; - } - } - if ( pItemsTable->pItems[v15->uItemID].uSkillType == PLAYER_SKILL_DAGGER - && SkillToMastery(v5->pActiveSkills[2] >= 3u) - && rand() % 100 < 10 ) - v4 *= 3; - } - } - } - } - v21 = v32 + v34; - if ( !a2 ) - { - v22 = GetActualMight(); - v23 = GetParameterBonus(v22); - v24 = GetSkillBonus(CHARACTER_ATTRIBUTE_MELEE_DMG_BONUS) + v23; - v21 += v5->_melee_dmg_bonus + GetMagicalBonus(CHARACTER_ATTRIBUTE_MELEE_DMG_BONUS) + v24; + } + } + dmgSum = mainWpnDmg + offHndWpnDmg; + if ( !ignoreSkillBonus ) + { + int might = GetActualMight(); + int mightBonus = GetParameterBonus(might); + int mightAndSkillbonus = GetSkillBonus(CHARACTER_ATTRIBUTE_MELEE_DMG_BONUS) + mightBonus; + dmgSum += this->_melee_dmg_bonus + GetMagicalBonus(CHARACTER_ATTRIBUTE_MELEE_DMG_BONUS) + mightAndSkillbonus; } result = 1; - if ( v21 >= 1 ) - result = v21; + if ( dmgSum >= 1 ) + result = dmgSum; return result; } + +int Player::CalculateMeleeDmgToEnemyWithWeapon( ItemGen * weapon, unsigned int uTargetActorID , bool addOneDice ) +{ + int itemId = weapon->uItemID; + int diceCount = pItemsTable->pItems[itemId].uDamageDice; + if (addOneDice) + { + diceCount++; + } + int diceSides = pItemsTable->pItems[itemId].uDamageRoll; + int diceResult = 0; + for (int i = 0; i < diceCount; i++) + { + diceResult += rand() % diceSides + 1; + } + int totalDmg = pItemsTable->pItems[itemId].uDamageMod + diceResult; + if ( uTargetActorID > 0) + { + int enchType = weapon->uSpecEnchantmentType; + if ( MonsterStats::BelongsToSupertype(uTargetActorID, MONSTER_SUPERTYPE_UNDEAD) && (enchType == 64 || itemId == ITEM_ARTIFACT_GHOULSBANE || itemId == ITEM_ARTIFACT_GIBBET || itemId == ITEM_RELIC_JUSTICE) ) + { + totalDmg *= 2; + } + else if (MonsterStats::BelongsToSupertype(uTargetActorID, MONSTER_SUPERTYPE_KREEGAN) && ( enchType == 39 || itemId == ITEM_ARTIFACT_GIBBET)) + { + totalDmg *= 2; + } + else if (MonsterStats::BelongsToSupertype(uTargetActorID, MONSTER_SUPERTYPE_DRAGON) && ( enchType == 40 || itemId == ITEM_ARTIFACT_GIBBET)) + { + totalDmg *= 2; + } + else if (MonsterStats::BelongsToSupertype(uTargetActorID, MONSTER_SUPERTYPE_TITAN) && ( enchType == 65 )) + { + totalDmg *= 2; + } + } + if ( (signed int)SkillToMastery(this->pActiveSkills[2]) >= 3 + && pItemsTable->pItems[itemId].uSkillType == 2 + && rand() % 100 < 10 ) + totalDmg *= 3; + return totalDmg; +} + + //----- (0048D0B9) -------------------------------------------------------- int Player::GetRangedAttack() { @@ -2088,7 +2036,6 @@ bool result; // eax@1 ItemGen *v4; // ebx@2 unsigned int v5; // edi@2 - unsigned int v6; // esi@2 int v7; // edx@4 char v8; // zf@4 int v9; // esi@5 @@ -2109,29 +2056,25 @@ return result; v4 = (ItemGen *)&v2->pInventoryItemList[v2->pEquipment.uBow-1]; v5 = v4->uItemID; - v6 = v4->uItemID; - v15 = pItemsTable->pItems[v6].uDamageRoll; - if ( (signed int)pItemsTable->pItems[v6].uDamageDice > 0 ) - { - v16 = pItemsTable->pItems[v6].uDamageDice; - do + v15 = pItemsTable->pItems[v5].uDamageRoll; + if ( (signed int)pItemsTable->pItems[v5].uDamageDice > 0 ) + { + for( int i = 0; i < pItemsTable->pItems[v5].uDamageDice; i++ ) { v7 = rand() % v15; - v8 = v16-- == 1; v17 += v7 + 1; } - while ( !v8 ); - } - v9 = pItemsTable->pItems[v6].uDamageMod + v17; + } + v9 = pItemsTable->pItems[v5].uDamageMod + v17; if ( a2 ) { v10 = v4->uSpecEnchantmentType; if ( v10 == 64 ) { - v11 = (MONSTER_SUPERTYPE)1; + v11 = MONSTER_SUPERTYPE_UNDEAD; goto LABEL_17; } - if ( v10 == 39 || v5 == 508 ) + if ( v10 == 39 ) { v13 = MONSTER_SUPERTYPE_KREEGAN; goto LABEL_16; @@ -2141,7 +2084,7 @@ v13 = MONSTER_SUPERTYPE_DRAGON; goto LABEL_16; } - if ( v10 == 63 || v5 == 517 ) + if ( v10 == 63 ) { v13 = MONSTER_SUPERTYPE_ELF; LABEL_16: @@ -2153,13 +2096,7 @@ } } LABEL_19: - v12 = v14->pActiveSkills[5]; - if ( v12 ) - { - if ( (signed int)SkillToMastery(v12) >= 4 ) - v9 += v14->pActiveSkills[5] & 0x3F; - } - return v9; + return v9 + this->GetSkillBonus(CHARACTER_ATTRIBUTE_RANGED_DMG_BONUS); } //----- (0048D2EA) --------------------------------------------------------