Mercurial > mm7
comparison 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 |
comparison
equal
deleted
inserted
replaced
1549:5a3afcaa6717 | 1550:cdb7fafede0c |
---|---|
1862 result = v6; | 1862 result = v6; |
1863 return result; | 1863 return result; |
1864 } | 1864 } |
1865 | 1865 |
1866 //----- (0048CDDB) -------------------------------------------------------- | 1866 //----- (0048CDDB) -------------------------------------------------------- |
1867 int Player::CalculateMeleeDamageTo(int a2, int a3, unsigned int uTargetActorID) | 1867 int Player::CalculateMeleeDamageTo( bool ignoreSkillBonus, bool ignoreOffhand, unsigned int uTargetActorID ) |
1868 { | 1868 { |
1869 int v4; // esi@1 | 1869 int dmgSum; // esi@62 |
1870 Player *v5; // edi@1 | |
1871 ItemGen *v6; // ebx@4 | |
1872 unsigned int v7; // ebp@4 | |
1873 unsigned int v8; // esi@4 | |
1874 int v9; // eax@4 | |
1875 int v10; // eax@9 | |
1876 char v11; // zf@9 | |
1877 int v12; // esi@10 | |
1878 int v13; // eax@11 | |
1879 enum MONSTER_SUPERTYPE v14; // edx@24 | |
1880 ItemGen *v15; // ebx@35 | |
1881 unsigned int v16; // ebp@35 | |
1882 unsigned int v17; // esi@35 | |
1883 int v18; // edx@38 | |
1884 int v19; // eax@40 | |
1885 enum MONSTER_SUPERTYPE v20; // edx@53 | |
1886 int v21; // esi@62 | |
1887 int v22; // eax@63 | |
1888 int v23; // ebx@63 | |
1889 int v24; // ebx@63 | |
1890 signed int result; // eax@64 | 1870 signed int result; // eax@64 |
1891 MONSTER_SUPERTYPE v26; // [sp-4h] [bp-24h]@20 | 1871 int mainWpnDmg; // [sp+18h] [bp-8h]@1 |
1892 MONSTER_SUPERTYPE v27; // [sp-4h] [bp-24h]@49 | 1872 int offHndWpnDmg; // [sp+1Ch] [bp-4h]@1 |
1893 int v28; // [sp+10h] [bp-10h]@1 | 1873 |
1894 int v29; // [sp+10h] [bp-10h]@33 | 1874 offHndWpnDmg = 0; |
1895 signed int v30; // [sp+14h] [bp-Ch]@7 | 1875 mainWpnDmg = 0; |
1896 signed int v31; // [sp+14h] [bp-Ch]@36 | |
1897 int v32; // [sp+18h] [bp-8h]@1 | |
1898 int v33; // [sp+18h] [bp-8h]@8 | |
1899 int v34; // [sp+1Ch] [bp-4h]@1 | |
1900 int v35; // [sp+28h] [bp+8h]@37 | |
1901 | |
1902 v4 = 0; | |
1903 v5 = this; | |
1904 v34 = 0; | |
1905 v32 = 0; | |
1906 v28 = 0; | |
1907 if ( IsUnarmed() ) | 1876 if ( IsUnarmed() ) |
1908 { | 1877 { |
1909 v32 = rand() % 3 + 1; | 1878 mainWpnDmg = rand() % 3 + 1; |
1910 LABEL_61: | |
1911 v34 = v4; | |
1912 } | 1879 } |
1913 else | 1880 else |
1914 { | 1881 { |
1915 if ( HasItemEquipped(EQUIP_MAIN_HAND) ) | 1882 if ( HasItemEquipped(EQUIP_MAIN_HAND) ) |
1916 { | 1883 { |
1917 v6 = &this->pInventoryItemList[v5->pEquipment.uMainHand-1]; | 1884 ItemGen *mainHandItemGen = &this->pInventoryItemList[this->pEquipment.uMainHand-1]; |
1918 v7 = v6->uItemID; | 1885 int itemId = mainHandItemGen->uItemID; |
1919 v9 = pItemsTable->pItems[v7].uDamageDice; | 1886 bool addOneDice = false; |
1920 if ( pItemsTable->pItems[v7].uSkillType == PLAYER_SKILL_SPEAR && !v5->pEquipment.uShield ) | 1887 if ( pItemsTable->pItems[itemId].uSkillType == PLAYER_SKILL_SPEAR && !this->pEquipment.uShield ) |
1921 ++v9; | 1888 addOneDice = true; |
1922 v30 = pItemsTable->pItems[v7].uDamageRoll; | 1889 mainWpnDmg = CalculateMeleeDmgToEnemyWithWeapon(mainHandItemGen, uTargetActorID, addOneDice); |
1923 for (int i = 0; i < v9; i++) | 1890 } |
1924 { | 1891 if ( !ignoreOffhand ) |
1925 v10 = rand(); | 1892 { |
1926 v28 += v10 % v30 + 1; | 1893 if ( this->HasItemEquipped(EQUIP_OFF_HAND) ) |
1927 } | 1894 { |
1928 v12 = pItemsTable->pItems[v7].uDamageMod + v28; | 1895 ItemGen *offHandItemGen = (ItemGen *)&this->pInventoryItemList[this->pEquipment.uShield - 1]; |
1929 if ( uTargetActorID > 0) | 1896 int itemId = offHandItemGen->uItemID; |
1930 { | 1897 if ( pItemsTable->pItems[itemId].uEquipType != EQUIP_SHIELD ) |
1931 v13 = v6->uSpecEnchantmentType; | |
1932 if ( MonsterStats::BelongsToSupertype(uTargetActorID, MONSTER_SUPERTYPE_UNDEAD) && (v13 == 64 || v7 == ITEM_ARTIFACT_GHOULSBANE || v7 == ITEM_ARTIFACT_GIBBET || v7 == ITEM_RELIC_JUSTICE) ) | |
1933 { | 1898 { |
1934 v12 *= 2; | 1899 offHndWpnDmg = CalculateMeleeDmgToEnemyWithWeapon(offHandItemGen, uTargetActorID, false); |
1935 } | 1900 } |
1936 else if (MonsterStats::BelongsToSupertype(uTargetActorID, MONSTER_SUPERTYPE_KREEGAN) && ( v13 == 39 || v7 == ITEM_ARTIFACT_GIBBET)) | 1901 } |
1937 { | 1902 } |
1938 v12 *= 2; | 1903 } |
1939 } | 1904 dmgSum = mainWpnDmg + offHndWpnDmg; |
1940 else if (MonsterStats::BelongsToSupertype(uTargetActorID, MONSTER_SUPERTYPE_DRAGON) && ( v13 == 40 || v7 == ITEM_ARTIFACT_GIBBET)) | 1905 if ( !ignoreSkillBonus ) |
1941 { | 1906 { |
1942 v12 *= 2; | 1907 int might = GetActualMight(); |
1943 } | 1908 int mightBonus = GetParameterBonus(might); |
1944 else if (MonsterStats::BelongsToSupertype(uTargetActorID, MONSTER_SUPERTYPE_TITAN) && ( v13 == 65 )) | 1909 int mightAndSkillbonus = GetSkillBonus(CHARACTER_ATTRIBUTE_MELEE_DMG_BONUS) + mightBonus; |
1945 { | 1910 dmgSum += this->_melee_dmg_bonus + GetMagicalBonus(CHARACTER_ATTRIBUTE_MELEE_DMG_BONUS) + mightAndSkillbonus; |
1946 v12 *= 2; | |
1947 } | |
1948 } | |
1949 if ( (signed int)SkillToMastery(v5->pActiveSkills[2]) >= 3 | |
1950 && pItemsTable->pItems[v6->uItemID].uSkillType == 2 | |
1951 && rand() % 100 < 10 ) | |
1952 v12 *= 3; | |
1953 v32 = v12; | |
1954 } | |
1955 v29 = 0; | |
1956 if ( !a3 ) | |
1957 { | |
1958 if ( v5->HasItemEquipped(EQUIP_OFF_HAND) ) | |
1959 { | |
1960 v15 = (ItemGen *)&v5->pInventoryItemList[v5->pEquipment.uShield - 1]; | |
1961 v16 = v15->uItemID; | |
1962 if ( pItemsTable->pItems[v16].uEquipType != EQUIP_SHIELD ) | |
1963 { | |
1964 v31 = pItemsTable->pItems[v16].uDamageRoll; | |
1965 v35 = pItemsTable->pItems[v16].uDamageDice; | |
1966 for (int i = 0; i < v35; i++) | |
1967 { | |
1968 v10 = rand(); | |
1969 v29 += v10 % v31 + 1; | |
1970 } | |
1971 v4 = pItemsTable->pItems[v16].uDamageMod + v29; | |
1972 if ( uTargetActorID > 0) | |
1973 { | |
1974 v19 = v15->uSpecEnchantmentType; | |
1975 if ( MonsterStats::BelongsToSupertype(uTargetActorID, MONSTER_SUPERTYPE_UNDEAD) && (v19 == 64 || v16 == ITEM_ARTIFACT_GHOULSBANE || v16 == ITEM_ARTIFACT_GIBBET || v16 == ITEM_RELIC_JUSTICE) ) | |
1976 { | |
1977 v4 *= 2; | |
1978 } | |
1979 else if (MonsterStats::BelongsToSupertype(uTargetActorID, MONSTER_SUPERTYPE_KREEGAN) && ( v19 == 39 || v16 == ITEM_ARTIFACT_GIBBET)) | |
1980 { | |
1981 v4 *= 2; | |
1982 } | |
1983 else if (MonsterStats::BelongsToSupertype(uTargetActorID, MONSTER_SUPERTYPE_DRAGON) && ( v19 == 40 || v16 == ITEM_ARTIFACT_GIBBET)) | |
1984 { | |
1985 v4 *= 2; | |
1986 } | |
1987 else if (MonsterStats::BelongsToSupertype(uTargetActorID, MONSTER_SUPERTYPE_TITAN) && ( v19 == 65 )) | |
1988 { | |
1989 v4 *= 2; | |
1990 } | |
1991 } | |
1992 if ( pItemsTable->pItems[v15->uItemID].uSkillType == PLAYER_SKILL_DAGGER | |
1993 && SkillToMastery(v5->pActiveSkills[2] >= 3u) | |
1994 && rand() % 100 < 10 ) | |
1995 v4 *= 3; | |
1996 } | |
1997 } | |
1998 } | |
1999 } | |
2000 v21 = v32 + v34; | |
2001 if ( !a2 ) | |
2002 { | |
2003 v22 = GetActualMight(); | |
2004 v23 = GetParameterBonus(v22); | |
2005 v24 = GetSkillBonus(CHARACTER_ATTRIBUTE_MELEE_DMG_BONUS) + v23; | |
2006 v21 += v5->_melee_dmg_bonus + GetMagicalBonus(CHARACTER_ATTRIBUTE_MELEE_DMG_BONUS) + v24; | |
2007 } | 1911 } |
2008 result = 1; | 1912 result = 1; |
2009 if ( v21 >= 1 ) | 1913 if ( dmgSum >= 1 ) |
2010 result = v21; | 1914 result = dmgSum; |
2011 return result; | 1915 return result; |
2012 } | 1916 } |
1917 | |
1918 | |
1919 int Player::CalculateMeleeDmgToEnemyWithWeapon( ItemGen * weapon, unsigned int uTargetActorID , bool addOneDice ) | |
1920 { | |
1921 int itemId = weapon->uItemID; | |
1922 int diceCount = pItemsTable->pItems[itemId].uDamageDice; | |
1923 if (addOneDice) | |
1924 { | |
1925 diceCount++; | |
1926 } | |
1927 int diceSides = pItemsTable->pItems[itemId].uDamageRoll; | |
1928 int diceResult = 0; | |
1929 for (int i = 0; i < diceCount; i++) | |
1930 { | |
1931 diceResult += rand() % diceSides + 1; | |
1932 } | |
1933 int totalDmg = pItemsTable->pItems[itemId].uDamageMod + diceResult; | |
1934 if ( uTargetActorID > 0) | |
1935 { | |
1936 int enchType = weapon->uSpecEnchantmentType; | |
1937 if ( MonsterStats::BelongsToSupertype(uTargetActorID, MONSTER_SUPERTYPE_UNDEAD) && (enchType == 64 || itemId == ITEM_ARTIFACT_GHOULSBANE || itemId == ITEM_ARTIFACT_GIBBET || itemId == ITEM_RELIC_JUSTICE) ) | |
1938 { | |
1939 totalDmg *= 2; | |
1940 } | |
1941 else if (MonsterStats::BelongsToSupertype(uTargetActorID, MONSTER_SUPERTYPE_KREEGAN) && ( enchType == 39 || itemId == ITEM_ARTIFACT_GIBBET)) | |
1942 { | |
1943 totalDmg *= 2; | |
1944 } | |
1945 else if (MonsterStats::BelongsToSupertype(uTargetActorID, MONSTER_SUPERTYPE_DRAGON) && ( enchType == 40 || itemId == ITEM_ARTIFACT_GIBBET)) | |
1946 { | |
1947 totalDmg *= 2; | |
1948 } | |
1949 else if (MonsterStats::BelongsToSupertype(uTargetActorID, MONSTER_SUPERTYPE_TITAN) && ( enchType == 65 )) | |
1950 { | |
1951 totalDmg *= 2; | |
1952 } | |
1953 } | |
1954 if ( (signed int)SkillToMastery(this->pActiveSkills[2]) >= 3 | |
1955 && pItemsTable->pItems[itemId].uSkillType == 2 | |
1956 && rand() % 100 < 10 ) | |
1957 totalDmg *= 3; | |
1958 return totalDmg; | |
1959 } | |
1960 | |
2013 | 1961 |
2014 //----- (0048D0B9) -------------------------------------------------------- | 1962 //----- (0048D0B9) -------------------------------------------------------- |
2015 int Player::GetRangedAttack() | 1963 int Player::GetRangedAttack() |
2016 { | 1964 { |
2017 Player *v1; // esi@1 | 1965 Player *v1; // esi@1 |
2086 { | 2034 { |
2087 Player *v2; // ebx@1 | 2035 Player *v2; // ebx@1 |
2088 bool result; // eax@1 | 2036 bool result; // eax@1 |
2089 ItemGen *v4; // ebx@2 | 2037 ItemGen *v4; // ebx@2 |
2090 unsigned int v5; // edi@2 | 2038 unsigned int v5; // edi@2 |
2091 unsigned int v6; // esi@2 | |
2092 int v7; // edx@4 | 2039 int v7; // edx@4 |
2093 char v8; // zf@4 | 2040 char v8; // zf@4 |
2094 int v9; // esi@5 | 2041 int v9; // esi@5 |
2095 int v10; // ebx@6 | 2042 int v10; // ebx@6 |
2096 enum MONSTER_SUPERTYPE v11; // edx@7 | 2043 enum MONSTER_SUPERTYPE v11; // edx@7 |
2107 result = HasItemEquipped(EQUIP_BOW); | 2054 result = HasItemEquipped(EQUIP_BOW); |
2108 if ( !result ) | 2055 if ( !result ) |
2109 return result; | 2056 return result; |
2110 v4 = (ItemGen *)&v2->pInventoryItemList[v2->pEquipment.uBow-1]; | 2057 v4 = (ItemGen *)&v2->pInventoryItemList[v2->pEquipment.uBow-1]; |
2111 v5 = v4->uItemID; | 2058 v5 = v4->uItemID; |
2112 v6 = v4->uItemID; | 2059 v15 = pItemsTable->pItems[v5].uDamageRoll; |
2113 v15 = pItemsTable->pItems[v6].uDamageRoll; | 2060 if ( (signed int)pItemsTable->pItems[v5].uDamageDice > 0 ) |
2114 if ( (signed int)pItemsTable->pItems[v6].uDamageDice > 0 ) | 2061 { |
2115 { | 2062 for( int i = 0; i < pItemsTable->pItems[v5].uDamageDice; i++ ) |
2116 v16 = pItemsTable->pItems[v6].uDamageDice; | |
2117 do | |
2118 { | 2063 { |
2119 v7 = rand() % v15; | 2064 v7 = rand() % v15; |
2120 v8 = v16-- == 1; | |
2121 v17 += v7 + 1; | 2065 v17 += v7 + 1; |
2122 } | 2066 } |
2123 while ( !v8 ); | 2067 } |
2124 } | 2068 v9 = pItemsTable->pItems[v5].uDamageMod + v17; |
2125 v9 = pItemsTable->pItems[v6].uDamageMod + v17; | |
2126 if ( a2 ) | 2069 if ( a2 ) |
2127 { | 2070 { |
2128 v10 = v4->uSpecEnchantmentType; | 2071 v10 = v4->uSpecEnchantmentType; |
2129 if ( v10 == 64 ) | 2072 if ( v10 == 64 ) |
2130 { | 2073 { |
2131 v11 = (MONSTER_SUPERTYPE)1; | 2074 v11 = MONSTER_SUPERTYPE_UNDEAD; |
2132 goto LABEL_17; | 2075 goto LABEL_17; |
2133 } | 2076 } |
2134 if ( v10 == 39 || v5 == 508 ) | 2077 if ( v10 == 39 ) |
2135 { | 2078 { |
2136 v13 = MONSTER_SUPERTYPE_KREEGAN; | 2079 v13 = MONSTER_SUPERTYPE_KREEGAN; |
2137 goto LABEL_16; | 2080 goto LABEL_16; |
2138 } | 2081 } |
2139 if ( v10 == 40 ) | 2082 if ( v10 == 40 ) |
2140 { | 2083 { |
2141 v13 = MONSTER_SUPERTYPE_DRAGON; | 2084 v13 = MONSTER_SUPERTYPE_DRAGON; |
2142 goto LABEL_16; | 2085 goto LABEL_16; |
2143 } | 2086 } |
2144 if ( v10 == 63 || v5 == 517 ) | 2087 if ( v10 == 63 ) |
2145 { | 2088 { |
2146 v13 = MONSTER_SUPERTYPE_ELF; | 2089 v13 = MONSTER_SUPERTYPE_ELF; |
2147 LABEL_16: | 2090 LABEL_16: |
2148 v11 = v13; | 2091 v11 = v13; |
2149 LABEL_17: | 2092 LABEL_17: |
2151 v9 *= 2; | 2094 v9 *= 2; |
2152 goto LABEL_19; | 2095 goto LABEL_19; |
2153 } | 2096 } |
2154 } | 2097 } |
2155 LABEL_19: | 2098 LABEL_19: |
2156 v12 = v14->pActiveSkills[5]; | 2099 return v9 + this->GetSkillBonus(CHARACTER_ATTRIBUTE_RANGED_DMG_BONUS); |
2157 if ( v12 ) | |
2158 { | |
2159 if ( (signed int)SkillToMastery(v12) >= 4 ) | |
2160 v9 += v14->pActiveSkills[5] & 0x3F; | |
2161 } | |
2162 return v9; | |
2163 } | 2100 } |
2164 | 2101 |
2165 //----- (0048D2EA) -------------------------------------------------------- | 2102 //----- (0048D2EA) -------------------------------------------------------- |
2166 char *Player::GetMeleeDamageString() | 2103 char *Player::GetMeleeDamageString() |
2167 { | 2104 { |