# HG changeset patch # User Grumpy7 # Date 1394993512 -3600 # Node ID 69661f22ff03e71ed34a4757effe08a9bb67dcb1 # Parent 60293358b4b381574dd9bfe0e4bb1d01b046e4d3 stru319::PlayerHitOrMiss moved to Player class, cleaned up a bit, stru319::ActorHitOrMiss moved to Actor class, cleaned up a bit diff -r 60293358b4b3 -r 69661f22ff03 Actor.cpp --- a/Actor.cpp Sun Mar 16 03:08:26 2014 +0100 +++ b/Actor.cpp Sun Mar 16 19:11:52 2014 +0100 @@ -3448,7 +3448,7 @@ } attackElement = DMGT_PHISYCAL; uDamageAmount = player->CalculateMeleeDamageTo(false, false, pMonster->pMonsterInfo.uID); - if ( !stru_50C198.PlayerHitOrMiss(player, pMonster, v61, a4) ) + if ( !player->PlayerHitOrMiss(pMonster, v61, a4) ) { player->PlaySound(SPEECH_52, 0); return; @@ -3477,11 +3477,11 @@ case SPELL_LASER_PROJECTILE: v16 = player->pActiveSkills[PLAYER_SKILL_BLASTER]; v61 = 1; - if ( (signed int)SkillToMastery(v16) >= 3 ) + if ( SkillToMastery(v16) >= 3 ) a4 = player->pActiveSkills[PLAYER_SKILL_BLASTER] & 0x3F; attackElement = DMGT_PHISYCAL; uDamageAmount = player->CalculateMeleeDamageTo(true, true, 0); - if ( !stru_50C198.PlayerHitOrMiss(player, pMonster, v61, a4) ) + if ( !player->PlayerHitOrMiss(pMonster, v61, a4) ) { player->PlaySound(SPEECH_52, 0); return; @@ -3493,7 +3493,7 @@ if ( pMonster->pActorBuffs[ACTOR_BUFF_SHIELD].uExpireTime > 0 ) uDamageAmount >>= 1; IsAdditionalDamagePossible = true; - if ( !stru_50C198.PlayerHitOrMiss(player, pMonster, v61, a4) ) + if ( !player->PlayerHitOrMiss(pMonster, v61, a4) ) { player->PlaySound(SPEECH_52, 0); return; @@ -3506,7 +3506,7 @@ if ( pMonster->pActorBuffs[ACTOR_BUFF_SHIELD].uExpireTime > 0 ) uDamageAmount >>= 1; IsAdditionalDamagePossible = false; - if ( !stru_50C198.PlayerHitOrMiss(player, pMonster, v61, a4) ) + if ( !player->PlayerHitOrMiss( pMonster, v61, a4) ) { player->PlaySound(SPEECH_52, 0); return; @@ -3516,7 +3516,7 @@ uDamageAmount = 0; attackElement = DMGT_PHISYCAL; hit_will_stun = 1; - if ( !stru_50C198.PlayerHitOrMiss(player, pMonster, v61, a4) ) + if ( !player->PlayerHitOrMiss( pMonster, v61, a4) ) { player->PlaySound(SPEECH_52, 0); return; @@ -3532,7 +3532,7 @@ { attackElement = DMGT_FIRE; } - else if ( !stru_50C198.PlayerHitOrMiss(player, pMonster, v61, a4) ) + else if ( !player->PlayerHitOrMiss( pMonster, v61, a4) ) { player->PlaySound(SPEECH_52, 0); return; @@ -4153,6 +4153,28 @@ return rand() % (armorSum + 2 * this->pMonsterInfo.uLevel + 10) + a2a + 1 > armorSum + 5; } +//----- (004274AD) -------------------------------------------------------- +bool Actor::ActorHitOrMiss(Player *pPlayer) +{ + signed int v3; // edi@1 + signed int v4; // esi@8 + int v5; // esi@8 + + v3 = 0; + if ( this->pActorBuffs[ACTOR_BUFF_HOUR_OF_POWER].uExpireTime > 0 ) + v3 = this->pActorBuffs[ACTOR_BUFF_HOUR_OF_POWER].uPower; + if ( this->pActorBuffs[ACTOR_BUFF_BLESS].uExpireTime > 0 && this->pActorBuffs[ACTOR_BUFF_BLESS].uPower > v3 ) + v3 = this->pActorBuffs[ACTOR_BUFF_BLESS].uPower; + if ( this->pActorBuffs[ACTOR_BUFF_FATE].uExpireTime > 0 ) + { + v3 += this->pActorBuffs[ACTOR_BUFF_FATE].uPower; + this->pActorBuffs[ACTOR_BUFF_FATE].Reset(); + } + v4 = pPlayer->GetActualAC() + 2 * this->pMonsterInfo.uLevel + 10; + v5 = rand() % v4 + 1; + return (v3 + v5 > pPlayer->GetActualAC() + 5); +} + //----- (00448A98) -------------------------------------------------------- void __fastcall ToggleActorGroupFlag(unsigned int uGroupID, unsigned int uFlag, unsigned int bToggle) { diff -r 60293358b4b3 -r 69661f22ff03 Actor.h --- a/Actor.h Sun Mar 16 03:08:26 2014 +0100 +++ b/Actor.h Sun Mar 16 19:11:52 2014 +0100 @@ -13,8 +13,6 @@ struct stru319 { int which_player_to_attack(struct Actor *pActor); - int PlayerHitOrMiss(struct Player *pPlayer, struct Actor *pActor, int a3, int a4); - bool ActorHitOrMiss(struct Actor *pActor, struct Player *pPlayer); int _427546(int a2); int CalcMagicalDamageToActor(struct Actor *pActor, int a2, signed int a3); bool GetMagicalResistance(struct Actor *pActor, unsigned int uType); @@ -238,6 +236,7 @@ bool _427102_IsOkToCastSpell(signed int a2); ABILITY_INDEX special_ability_use_check(int a2); bool _4273BB_DoesHitOtherActor(Actor *defender, int a3, int a4); + bool ActorHitOrMiss(Player *pPlayer); char pActorName[32]; signed __int16 sNPC_ID; diff -r 60293358b4b3 -r 69661f22ff03 Player.cpp --- a/Player.cpp Sun Mar 16 03:08:26 2014 +0100 +++ b/Player.cpp Sun Mar 16 19:11:52 2014 +0100 @@ -7242,7 +7242,7 @@ playerPtr = &pParty->pPlayers[a4]; actorPtr = &pActors[uActorID]; healthBeforeRecvdDamage = playerPtr->sHealth; - if ( PID_TYPE(uObjID) != 3 || !stru_50C198.ActorHitOrMiss(actorPtr, playerPtr) ) + if ( PID_TYPE(uObjID) != 3 || !actorPtr->ActorHitOrMiss(playerPtr) ) return; ItemGen* equippedArmor = playerPtr->GetArmorItem(); SoundID soundToPlay; @@ -7441,7 +7441,7 @@ || spriteType == 535 || spriteType == 540 ) { - if ( !stru_50C198.ActorHitOrMiss(actorPtr, playerPtr) ) + if ( !actorPtr->ActorHitOrMiss(playerPtr) ) return; if ( playerPtr->pPlayerBuffs[PLAYER_BUFF_SHIELD].uExpireTime > 0 ) dmgToReceive >>= 1; @@ -7913,4 +7913,48 @@ else Error("Unexpected player pointer"); return uPlayerIdx; +} + +//----- (004272F5) -------------------------------------------------------- +bool Player::PlayerHitOrMiss(Actor *pActor, int a3, int a4) +{ + signed int naturalArmor; // esi@1 + signed int armorBuff; // edi@1 + int effectiveActorArmor; // esi@8 + int attBonus; // eax@9 + int v9; // edx@11 + unsigned __int8 v12; // sf@13 + unsigned __int8 v13; // of@13 + int attPositiveMod; // edx@14 + int attNegativeMod; // eax@14 + signed int result; // eax@17 + + naturalArmor = pActor->pMonsterInfo.uAC; + armorBuff = 0; + if ( pActor->pActorBuffs[ACTOR_BUFF_SOMETHING_THAT_HALVES_AC].uExpireTime > 0 ) + naturalArmor /= 2; + if ( pActor->pActorBuffs[ACTOR_BUFF_HOUR_OF_POWER].uExpireTime > 0 ) + armorBuff = pActor->pActorBuffs[ACTOR_BUFF_SHIELD].uPower; + if ( pActor->pActorBuffs[ACTOR_BUFF_STONESKIN].uExpireTime > 0 && pActor->pActorBuffs[ACTOR_BUFF_STONESKIN].uPower > armorBuff ) + armorBuff = pActor->pActorBuffs[ACTOR_BUFF_STONESKIN].uPower; + effectiveActorArmor = armorBuff + naturalArmor; + if ( a3 ) + attBonus = this->GetRangedAttack(); + else + attBonus = this->GetActualAttack(false); + v9 = rand() % (effectiveActorArmor + 2 * attBonus + 30); + attPositiveMod = a4 + v9; + if ( a3 == 2 ) + { + attNegativeMod = ((effectiveActorArmor + 15) / 2) + effectiveActorArmor + 15; + } + else if ( a3 == 3 ) + { + attNegativeMod = 2 * effectiveActorArmor + 30; + } + else + { + attNegativeMod = effectiveActorArmor + 15; + } + return (attPositiveMod > attNegativeMod); } \ No newline at end of file diff -r 60293358b4b3 -r 69661f22ff03 Player.h --- a/Player.h Sun Mar 16 03:08:26 2014 +0100 +++ b/Player.h Sun Mar 16 19:11:52 2014 +0100 @@ -602,6 +602,8 @@ bool HasItem(unsigned int uItemID, bool checkHeldItem); void OnInventoryLeftClick(); + bool PlayerHitOrMiss(Actor *pActor, int a3, int a4); + 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); diff -r 60293358b4b3 -r 69661f22ff03 mm7_6.cpp --- a/mm7_6.cpp Sun Mar 16 03:08:26 2014 +0100 +++ b/mm7_6.cpp Sun Mar 16 19:11:52 2014 +0100 @@ -39,84 +39,6 @@ -//----- (004272F5) -------------------------------------------------------- -int stru319::PlayerHitOrMiss(Player *pPlayer, Actor *pActor, int a3, int a4) -{ - signed int v5; // esi@1 - signed int v6; // edi@1 - int v7; // esi@8 - int v8; // eax@9 - int v9; // edx@11 - unsigned __int8 v12; // sf@13 - unsigned __int8 v13; // of@13 - int v14; // edx@14 - int v15; // eax@14 - signed int result; // eax@17 - - v5 = pActor->pMonsterInfo.uAC; - v6 = 0; - if ( (signed __int64)pActor->pActorBuffs[ACTOR_BUFF_SOMETHING_THAT_HALVES_AC].uExpireTime > 0 ) - v5 /= 2; - if ( (signed __int64)pActor->pActorBuffs[ACTOR_BUFF_HOUR_OF_POWER].uExpireTime > 0 ) - v6 = pActor->pActorBuffs[ACTOR_BUFF_SHIELD].uPower; - if ( (signed __int64)pActor->pActorBuffs[ACTOR_BUFF_STONESKIN].uExpireTime > 0 && pActor->pActorBuffs[ACTOR_BUFF_STONESKIN].uPower > v6 ) - v6 = pActor->pActorBuffs[ACTOR_BUFF_STONESKIN].uPower; - v7 = v6 + v5; - if ( a3 ) - v8 = pPlayer->GetRangedAttack(); - else - v8 = pPlayer->GetActualAttack(false); - v9 = rand() % (v7 + 2 * v8 + 30); - if ( a3 == 2 ) - { - v14 = a4 + v9; - v15 = ((v7 + 15) / 2) + v7 + 15; - v13 = __OFSUB__(v14, v15); - v12 = v14 - v15 < 0; - } - else if ( a3 == 3 ) - { - v14 = a4 + v9; - v15 = 2 * v7 + 30; - v13 = __OFSUB__(v14, v15); - v12 = v14 - v15 < 0; - } - else - { - v14 = a4 + v9; - v15 = v7 + 15; - v13 = __OFSUB__(v14, v15); - v12 = v14 - v15 < 0; - } - - if ( v12 ^ v13 ) - result = 0; - else - result = 1; - return result; -} - -//----- (004274AD) -------------------------------------------------------- -bool stru319::ActorHitOrMiss(Actor *pActor, Player *pPlayer) -{ - signed int v3; // edi@1 - signed int v4; // esi@8 - int v5; // esi@8 - - v3 = 0; - if ( (signed __int64)pActor->pActorBuffs[ACTOR_BUFF_HOUR_OF_POWER].uExpireTime > 0 ) - v3 = pActor->pActorBuffs[ACTOR_BUFF_HOUR_OF_POWER].uPower; - if ( (signed __int64)pActor->pActorBuffs[ACTOR_BUFF_BLESS].uExpireTime > 0 && pActor->pActorBuffs[ACTOR_BUFF_BLESS].uPower > v3 ) - v3 = pActor->pActorBuffs[ACTOR_BUFF_BLESS].uPower; - if ( (signed __int64)pActor->pActorBuffs[ACTOR_BUFF_FATE].uExpireTime > 0 ) - { - v3 += pActor->pActorBuffs[ACTOR_BUFF_FATE].uPower; - pActor->pActorBuffs[ACTOR_BUFF_FATE].Reset(); - } - v4 = pPlayer->GetActualAC() + 2 * pActor->pMonsterInfo.uLevel + 10; - v5 = rand() % v4 + 1; - return v3 + v5 > pPlayer->GetActualAC() + 5; -} //----- (00427546) -------------------------------------------------------- int stru319::_427546(int a2)