comparison Player.cpp @ 1681:406872881eb6

DamagePlayerFromMonster reducing variable scope
author Grumpy7
date Thu, 19 Sep 2013 08:26:28 +0200
parents 51a74615d956
children 3c451fd02fcf
comparison
equal deleted inserted replaced
1672:f3986fd1a122 1681:406872881eb6
7465 } 7465 }
7466 7466
7467 7467
7468 7468
7469 //----- (00439FCB) -------------------------------------------------------- 7469 //----- (00439FCB) --------------------------------------------------------
7470 void __fastcall DamagePlayerFromMonster(unsigned int uObjID, int a2, Vec3_int_ *pPos, unsigned int a4) 7470 void __fastcall DamagePlayerFromMonster(unsigned int uObjID, int element, Vec3_int_ *pPos, unsigned int a4)
7471 { 7471 {
7472 signed int v4; // esi@1
7473 unsigned int v5; // ecx@1
7474 Player *playerPtr; // ebx@3 7472 Player *playerPtr; // ebx@3
7475 Actor *actorPtr; // esi@3 7473 Actor *actorPtr; // esi@3
7476 unsigned int v8; // eax@4 7474 unsigned int v8; // eax@4
7477 int v11; // edx@8
7478 int v14; // edx@16
7479 enum SoundID v17; // eax@24
7480 unsigned __int16 v21; // ax@29
7481 signed int v22; // edi@36 7475 signed int v22; // edi@36
7482 int v23; // eax@38 7476 int spellId; // eax@38
7483 signed int v24; // eax@44
7484 AIState v25; // cx@47
7485 signed int v26; // eax@49
7486 int v27; // eax@54
7487 int v34; // edi@61
7488 int v35; // eax@70
7489 int v36; // st7@70
7490 SpriteObject *v37; // ebx@77
7491 int v38; // edi@77
7492 int v39; // esi@77
7493 int v40; // eax@77
7494 int v41; // eax@77
7495 Player *v43; // eax@81
7496 //Actor *actorPtr; // esi@82
7497 Player *v45; // edi@84
7498 unsigned __int16 v46; // ax@84
7499 int v48; // eax@107
7500 unsigned __int16 v49; // ax@116
7501 int v50; // ebx@123
7502 unsigned __int16 v51; // ax@124
7503 int v53; // eax@128
7504 signed int v54; // eax@134
7505 unsigned __int16 v55; // cx@137
7506 signed int recvdMagicDmg; // eax@139 7477 signed int recvdMagicDmg; // eax@139
7507 int v57; // eax@144
7508 int v64; // ebx@151
7509 int v65; // eax@161
7510 int v66; // st7@161
7511 signed int v68; // eax@170
7512 int v69; // ecx@170
7513 int v70; // eax@171
7514 int v72[4]; // [sp+30h] [bp-24h]@164 7478 int v72[4]; // [sp+30h] [bp-24h]@164
7515 signed int v74; // [sp+44h] [bp-10h]@1
7516 int healthBeforeRecvdDamage; // [sp+48h] [bp-Ch]@3 7479 int healthBeforeRecvdDamage; // [sp+48h] [bp-Ch]@3
7517 unsigned int uActorID; // [sp+4Ch] [bp-8h]@1 7480 unsigned int uActorID; // [sp+4Ch] [bp-8h]@1
7518 int dmgToReceive; // [sp+50h] [bp-4h]@26 7481
7519 7482 uActorID = PID_ID(uObjID);
7520 v4 = PID_ID(uObjID); 7483 if ( PID_TYPE(uObjID) != 2)
7521 v5 = PID_TYPE(uObjID) - 2;
7522 v74 = a2;
7523 uActorID = v4;
7524 if ( v5 )
7525 { 7484 {
7526 playerPtr = &pParty->pPlayers[a4]; 7485 playerPtr = &pParty->pPlayers[a4];
7527 actorPtr = &pActors[v4]; 7486 actorPtr = &pActors[uActorID];
7528 healthBeforeRecvdDamage = playerPtr->sHealth; 7487 healthBeforeRecvdDamage = playerPtr->sHealth;
7529 if ( v5 != 1 || !stru_50C198.ActorHitOrMiss(actorPtr, playerPtr) ) 7488 if ( PID_TYPE(uObjID) != 3 || !stru_50C198.ActorHitOrMiss(actorPtr, playerPtr) )
7530 return; 7489 return;
7531 v8 = playerPtr->pEquipment.uArmor; 7490 v8 = playerPtr->pEquipment.uArmor;
7491 SoundID soundToPlay;
7532 if ( !v8 7492 if ( !v8
7533 || playerPtr->pInventoryItemList[v8 - 1].IsBroken() 7493 || playerPtr->pInventoryItemList[v8 - 1].IsBroken()
7534 || 7494 ||
7535 (pItemsTable->pItems[playerPtr->pInventoryItemList[v8 - 1].uItemID].uSkillType != PLAYER_SKILL_CHAIN 7495 (pItemsTable->pItems[playerPtr->pInventoryItemList[v8 - 1].uItemID].uSkillType != PLAYER_SKILL_CHAIN
7536 && pItemsTable->pItems[playerPtr->pInventoryItemList[v8 - 1].uItemID].uSkillType != PLAYER_SKILL_PLATE 7496 && pItemsTable->pItems[playerPtr->pInventoryItemList[v8 - 1].uItemID].uSkillType != PLAYER_SKILL_PLATE
7537 ) 7497 )
7538 ) 7498 )
7539 { 7499 {
7540 v14 = rand() % 4; 7500 int randVal = rand() % 4;
7541 switch (v14) 7501 switch (randVal)
7542 { 7502 {
7543 case 0 : v17 = (SoundID)108; break; 7503 case 0 : soundToPlay = (SoundID)108; break;
7544 case 1 : v17 = (SoundID)109; break; 7504 case 1 : soundToPlay = (SoundID)109; break;
7545 case 2 : v17 = (SoundID)110; break; 7505 case 2 : soundToPlay = (SoundID)110; break;
7546 case 3 : v17 = (SoundID)44; break; 7506 case 3 : soundToPlay = (SoundID)44; break;
7547 } 7507 }
7548 } 7508 }
7549 else 7509 else
7550 { 7510 {
7551 v11 = rand() % 4; 7511 int randVal = rand() % 4;
7552 switch (v11) 7512 switch (randVal)
7553 { 7513 {
7554 case 0 : v17 = (SoundID)105; break; 7514 case 0 : soundToPlay = (SoundID)105; break;
7555 case 1 : v17 = (SoundID)106; break; 7515 case 1 : soundToPlay = (SoundID)106; break;
7556 case 2 : v17 = (SoundID)107; break; 7516 case 2 : soundToPlay = (SoundID)107; break;
7557 case 3 : v17 = (SoundID)45; break; 7517 case 3 : soundToPlay = (SoundID)45; break;
7558 } 7518 }
7559 } 7519 }
7560 pAudioPlayer->PlaySound(v17, PID(OBJECT_Player,a4 + 80), 0, -1, 0, 0, 0, 0); 7520 pAudioPlayer->PlaySound(soundToPlay, PID(OBJECT_Player,a4 + 80), 0, -1, 0, 0, 0, 0);
7561 dmgToReceive = Actor::_43B3E0_CalcDamage(actorPtr, v74); 7521 int dmgToReceive = Actor::_43B3E0_CalcDamage(actorPtr, element);
7562 if ( actorPtr->pActorBuffs[3].uExpireTime > 0 ) 7522 if ( actorPtr->pActorBuffs[3].uExpireTime > 0 )
7563 { 7523 {
7564 v21 = actorPtr->pActorBuffs[3].uPower; 7524 __int16 spellPower = actorPtr->pActorBuffs[3].uPower;
7565 if ( v21 ) 7525 if ( spellPower )
7566 dmgToReceive /= (signed int)v21; 7526 dmgToReceive /= (signed int)spellPower;
7567 } 7527 }
7568 switch (v74) 7528 switch (element)
7569 { 7529 {
7570 case 0: v22 = actorPtr->pMonsterInfo.uAttack1Type; 7530 case 0: v22 = actorPtr->pMonsterInfo.uAttack1Type;
7571 break; 7531 break;
7572 case 1: v22 = actorPtr->pMonsterInfo.uAttack2Type; 7532 case 1: v22 = actorPtr->pMonsterInfo.uAttack2Type;
7573 break; 7533 break;
7574 case 2: v23 = actorPtr->pMonsterInfo.uSpell1ID; 7534 case 2: spellId = actorPtr->pMonsterInfo.uSpell1ID;
7575 v22 = LOBYTE(pSpellStats->pInfos[v23].uSchool); 7535 v22 = LOBYTE(pSpellStats->pInfos[spellId].uSchool);
7576 break; 7536 break;
7577 case 3: v23 = actorPtr->pMonsterInfo.uSpell2ID; 7537 case 3: spellId = actorPtr->pMonsterInfo.uSpell2ID;
7578 v22 = LOBYTE(pSpellStats->pInfos[v23].uSchool); 7538 v22 = LOBYTE(pSpellStats->pInfos[spellId].uSchool);
7579 break; 7539 break;
7580 case 4: v22 = actorPtr->pMonsterInfo.field_3C_some_special_attack; 7540 case 4: v22 = actorPtr->pMonsterInfo.field_3C_some_special_attack;
7581 break; 7541 break;
7582 default: 7542 default:
7583 case 5: v22 = 4; //yes, the original just assigned the value 4 7543 case 5: v22 = 4; //yes, the original just assigned the value 4
7584 break; 7544 break;
7585 } 7545 }
7586 if ( !(dword_6BE368_debug_settings_2 & 0x10) ) 7546 if ( !(dword_6BE368_debug_settings_2 & 0x10) )
7587 { 7547 {
7588 v24 = playerPtr->ReceiveDamage(dmgToReceive, (DAMAGE_TYPE)v22); 7548 dmgToReceive = playerPtr->ReceiveDamage(dmgToReceive, (DAMAGE_TYPE)v22);
7589 if ( playerPtr->pPlayerBuffs[10].uExpireTime > 0 ) 7549 if ( playerPtr->pPlayerBuffs[10].uExpireTime > 0 )
7590 { 7550 {
7591 v25 = actorPtr->uAIState; 7551 int actorState = actorPtr->uAIState;
7592 if ( v25 != Dying && v25 != Dead) 7552 if ( actorState != Dying && actorState != Dead)
7593 { 7553 {
7594 v26 = stru_50C198.CalcMagicalDamageToActor(actorPtr, v22, v24); 7554 int reflectedDamage = stru_50C198.CalcMagicalDamageToActor(actorPtr, v22, dmgToReceive);
7595 actorPtr->sCurrentHP -= v26; 7555 actorPtr->sCurrentHP -= reflectedDamage;
7596 if ( v26 >= 0 ) 7556 if ( reflectedDamage >= 0 )
7597 { 7557 {
7598 if ( actorPtr->sCurrentHP >= 1 ) 7558 if ( actorPtr->sCurrentHP >= 1 )
7599 { 7559 {
7600 Actor::AI_Stun(uActorID, PID(OBJECT_Player,a4), 0); 7560 Actor::AI_Stun(uActorID, PID(OBJECT_Player,a4), 0);
7601 Actor::AggroSurroundingPeasants(uActorID, 1); 7561 Actor::AggroSurroundingPeasants(uActorID, 1);
7602 } 7562 }
7603 else 7563 else
7604 { 7564 {
7605 if ( pMonsterStats->pInfos[actorPtr->pMonsterInfo.uID].bQuestMonster & 1 && pRenderer->pRenderD3D && pGame->uFlags2 & GAME_FLAGS_2_DRAW_BLOODSPLATS) 7565 if ( pMonsterStats->pInfos[actorPtr->pMonsterInfo.uID].bQuestMonster & 1 && pRenderer->pRenderD3D && pGame->uFlags2 & GAME_FLAGS_2_DRAW_BLOODSPLATS)
7606 { 7566 {
7607 v27 = byte_4D864C && BYTE2(pGame->uFlags) & 8 ? 10 * actorPtr->uActorRadius : actorPtr->uActorRadius; 7567 int splatRadius = byte_4D864C && BYTE2(pGame->uFlags) & 8 ? 10 * actorPtr->uActorRadius : actorPtr->uActorRadius;
7608 pDecalBuilder->AddBloodsplat(actorPtr->vPosition.x, actorPtr->vPosition.y, actorPtr->vPosition.z, 1.0, 0.0, 0.0, (float)v27, 0, 0); 7568 pDecalBuilder->AddBloodsplat(actorPtr->vPosition.x, actorPtr->vPosition.y, actorPtr->vPosition.z, 1.0, 0.0, 0.0, (float)splatRadius, 0, 0);
7609 } 7569 }
7610 Actor::Die(uActorID); 7570 Actor::Die(uActorID);
7611 Actor::ApplyFineForKillingPeasant(uActorID); 7571 Actor::ApplyFineForKillingPeasant(uActorID);
7612 Actor::AggroSurroundingPeasants(uActorID, 1); 7572 Actor::AggroSurroundingPeasants(uActorID, 1);
7613 if ( actorPtr->pMonsterInfo.uExp ) 7573 if ( actorPtr->pMonsterInfo.uExp )
7614 GivePartyExp(pMonsterStats->pInfos[actorPtr->pMonsterInfo.uID].uExp); 7574 GivePartyExp(pMonsterStats->pInfos[actorPtr->pMonsterInfo.uID].uExp);
7615 v34 = SPEECH_51; 7575 int speechToPlay = SPEECH_51;
7616 if ( rand() % 100 < 20 ) 7576 if ( rand() % 100 < 20 )
7617 v34 = ((signed int)actorPtr->pMonsterInfo.uHP >= 100) + 1; 7577 speechToPlay = actorPtr->pMonsterInfo.uHP >= 100 ? 2 : 1;
7618 playerPtr->PlaySound((PlayerSpeech)v34, 0); 7578 playerPtr->PlaySound((PlayerSpeech)speechToPlay, 0);
7619 } 7579 }
7620 } 7580 }
7621 } 7581 }
7622 } 7582 }
7623 if ( !(dword_6BE368_debug_settings_2 & 0x10) 7583 if ( !(dword_6BE368_debug_settings_2 & 0x10)
7627 playerPtr->_48DCF6(actorPtr->pMonsterInfo.uSpecialAttack, actorPtr); 7587 playerPtr->_48DCF6(actorPtr->pMonsterInfo.uSpecialAttack, actorPtr);
7628 } 7588 }
7629 } 7589 }
7630 if ( !pParty->bTurnBasedModeOn ) 7590 if ( !pParty->bTurnBasedModeOn )
7631 { 7591 {
7632 v35 = playerPtr->GetActualEndurance(); 7592 int actEndurance = playerPtr->GetActualEndurance();
7633 v36 = (int)((20 - playerPtr->GetParameterBonus(v35)) * flt_6BE3A4_debug_recmod1 * 2.133333333333333); 7593 int recoveryTime = (int)((20 - playerPtr->GetParameterBonus(actEndurance)) * flt_6BE3A4_debug_recmod1 * 2.133333333333333);
7634 playerPtr->SetRecoveryTime(v36); 7594 playerPtr->SetRecoveryTime(recoveryTime);
7635 } 7595 }
7636 int yellThreshold = playerPtr->GetMaxHealth() / 4; 7596 int yellThreshold = playerPtr->GetMaxHealth() / 4;
7637 if ( yellThreshold < playerPtr->sHealth && yellThreshold >= healthBeforeRecvdDamage && playerPtr->sHealth > 0 ) 7597 if ( yellThreshold < playerPtr->sHealth && yellThreshold >= healthBeforeRecvdDamage && playerPtr->sHealth > 0 )
7638 { 7598 {
7639 playerPtr->PlaySound(SPEECH_48, 0); 7599 playerPtr->PlaySound(SPEECH_48, 0);
7641 viewparams->bRedrawGameUI = 1; 7601 viewparams->bRedrawGameUI = 1;
7642 return; 7602 return;
7643 } 7603 }
7644 else 7604 else
7645 { 7605 {
7646 v37 = &pSpriteObjects[uActorID]; 7606 SpriteObject* v37 = &pSpriteObjects[uActorID];
7647 v38 = PID_TYPE(v37->spell_caster_pid); 7607 int uActorType = PID_TYPE(v37->spell_caster_pid);
7648 v39 = PID_ID(v37->spell_caster_pid); 7608 int uActorID = PID_ID(v37->spell_caster_pid);
7649 v40 = PID_TYPE(v37->spell_caster_pid); 7609 if ( uActorType == 2 )
7650 uActorID = PID_ID(v37->spell_caster_pid); 7610 {
7651 v41 = v40 - 2; 7611 Player *playerPtr; // eax@81
7652 if ( v40 == 2 )
7653 {
7654 if ( a4 != -1 ) 7612 if ( a4 != -1 )
7655 { 7613 {
7656 v43 = &pParty->pPlayers[a4]; 7614 playerPtr = &pParty->pPlayers[a4];
7657 } 7615 }
7658 else 7616 else
7659 { 7617 {
7660 v74 = 0; 7618 element = 0;
7661 for (int i = 1; i <= 4; i++) 7619 for (int i = 1; i <= 4; i++)
7662 { 7620 {
7663 v72[v74] = i; 7621 v72[element] = i;
7664 v74++; 7622 element++;
7665 } 7623 }
7666 if ( v74 ) 7624 if ( element )
7667 { 7625 {
7668 v43 = &pParty->pPlayers[v72[rand() % v74]];//&stru_AA1058[3].pSounds[6972 * *(&v72 + rand() % v74) + 40552]; 7626 playerPtr = &pParty->pPlayers[v72[rand() % element]];//&stru_AA1058[3].pSounds[6972 * *(&v72 + rand() % v74) + 40552];
7669 } 7627 }
7670 } 7628 }
7671 if ( v38 != OBJECT_Player || v37->spell_id != SPELL_BOW_ARROW) 7629 int v68;
7672 { 7630 int v69;
7673 v70 = v43->GetMaxHealth(); 7631 if ( uActorType != OBJECT_Player || v37->spell_id != SPELL_BOW_ARROW)
7674 v68 = _43AFE3_calc_spell_damage(v37->spell_id, v37->spell_level, v37->spell_skill, v70); 7632 {
7633 int playerMaxHp = playerPtr->GetMaxHealth();
7634 v68 = _43AFE3_calc_spell_damage(v37->spell_id, v37->spell_level, v37->spell_skill, playerMaxHp);
7675 v69 = LOBYTE(pSpellStats->pInfos[v37->spell_id].uSchool); 7635 v69 = LOBYTE(pSpellStats->pInfos[v37->spell_id].uSchool);
7676 } 7636 }
7677 else 7637 else
7678 { 7638 {
7679 v68 = pParty->pPlayers[uActorID].CalculateRangedDamageTo(0); 7639 v68 = pParty->pPlayers[uActorID].CalculateRangedDamageTo(0);
7680 v69 = 0; 7640 v69 = 0;
7681 } 7641 }
7682 v43->ReceiveDamage(v68, (DAMAGE_TYPE)v69); 7642 playerPtr->ReceiveDamage(v68, (DAMAGE_TYPE)v69);
7683 if ( v38 == OBJECT_Player && !qword_A750D8 ) 7643 if ( uActorType == OBJECT_Player && !qword_A750D8 )
7684 { 7644 {
7685 qword_A750D8 = 256i64; 7645 qword_A750D8 = 256i64;
7686 PlayerSpeechID = SPEECH_44; 7646 PlayerSpeechID = SPEECH_44;
7687 uSpeakingCharacter = uActorID + 1; 7647 uSpeakingCharacter = uActorID + 1;
7688 } 7648 }
7689 return; 7649 return;
7690 } 7650 }
7691 else if ( v40 == 3 ) 7651 else if ( uActorType == 3 )
7692 { 7652 {
7693 actorPtr = &pActors[v39]; 7653 Actor *actorPtr = &pActors[uActorID];
7694 if ( a4 == -1 ) 7654 if ( a4 == -1 )
7695 a4 = stru_50C198.which_player_would_attack(actorPtr); 7655 a4 = stru_50C198.which_player_would_attack(actorPtr);
7696 v45 = &pParty->pPlayers[a4]; 7656 Player *playerPtr = &pParty->pPlayers[a4];
7697 dmgToReceive = Actor::_43B3E0_CalcDamage(actorPtr, v74); 7657 int dmgToReceive = Actor::_43B3E0_CalcDamage(actorPtr, element);
7698 v46 = v37->uType; 7658 unsigned __int16 spriteType = v37->uType;
7699 if ( v37->uType == 545 ) 7659 if ( v37->uType == 545 )
7700 { 7660 {
7701 v51 = v45->GetActualSkillLevel(PLAYER_SKILL_UNARMED); 7661 __int16 skillLevel = playerPtr->GetActualSkillLevel(PLAYER_SKILL_UNARMED);
7702 if ( SkillToMastery(v51) >= 4 && rand() % 100 < (v51 & 0x3F) ) 7662 if ( SkillToMastery(skillLevel) >= 4 && rand() % 100 < (skillLevel & 0x3F) )
7703 { 7663 {
7704 sprintf(pTmpBuf.data(), pGlobalTXT_LocalizationStrings[637], v45->pName); 7664 sprintf(pTmpBuf.data(), pGlobalTXT_LocalizationStrings[637], playerPtr->pName);
7705 ShowStatusBarString(pTmpBuf.data(), 2u); 7665 ShowStatusBarString(pTmpBuf.data(), 2u);
7706 v45->PlaySound(SPEECH_6, 0); 7666 playerPtr->PlaySound(SPEECH_6, 0);
7707 return; 7667 return;
7708 } 7668 }
7709 } 7669 }
7710 else if ( v46 == 555 7670 else if ( spriteType == 555
7711 || v46 == 510 7671 || spriteType == 510
7712 || v46 == 500 7672 || spriteType == 500
7713 || v46 == 515 7673 || spriteType == 515
7714 || v46 == 505 7674 || spriteType == 505
7715 || v46 == 530 7675 || spriteType == 530
7716 || v46 == 525 7676 || spriteType == 525
7717 || v46 == 520 7677 || spriteType == 520
7718 || v46 == 535 7678 || spriteType == 535
7719 || v46 == 540 ) 7679 || spriteType == 540 )
7720 { 7680 {
7721 if ( !stru_50C198.ActorHitOrMiss(actorPtr, v45) ) 7681 if ( !stru_50C198.ActorHitOrMiss(actorPtr, playerPtr) )
7722 return; 7682 return;
7723 if ( (signed __int64)v45->pPlayerBuffs[13].uExpireTime > 0 ) 7683 if ( playerPtr->pPlayerBuffs[13].uExpireTime > 0 )
7724 dmgToReceive >>= 1; 7684 dmgToReceive >>= 1;
7725 if ( v45->HasEnchantedItemEquipped(36) ) 7685 if ( playerPtr->HasEnchantedItemEquipped(36) )
7726 dmgToReceive >>= 1; 7686 dmgToReceive >>= 1;
7727 if ( v45->HasEnchantedItemEquipped(69) ) 7687 if ( playerPtr->HasEnchantedItemEquipped(69) )
7728 dmgToReceive >>= 1; 7688 dmgToReceive >>= 1;
7729 if ( v45->HasItemEquipped(EQUIP_ARMOUR) 7689 if ( playerPtr->HasItemEquipped(EQUIP_ARMOUR)
7730 && v45->pInventoryItemList[v45->pEquipment.uArmor-1].uItemID == ITEM_ARTIFACT_GOVERNORS_ARMOR ) 7690 && playerPtr->pInventoryItemList[playerPtr->pEquipment.uArmor-1].uItemID == ITEM_ARTIFACT_GOVERNORS_ARMOR )
7731 dmgToReceive >>= 1; 7691 dmgToReceive >>= 1;
7732 if ( v45->HasItemEquipped(EQUIP_MAIN_HAND)) 7692 if ( playerPtr->HasItemEquipped(EQUIP_MAIN_HAND))
7733 { 7693 {
7734 v48 = v45->pInventoryItemList[v45->pEquipment.uMainHand - 1].uItemID; 7694 int itemId = playerPtr->pInventoryItemList[playerPtr->pEquipment.uMainHand - 1].uItemID;
7735 if ( v48 == ITEM_RELIC_KELEBRIM || v48 == ITEM_ARTIFACT_ELFBANE || (v45->GetEquippedItemEquipType(EQUIP_MAIN_HAND) == EQUIP_SHIELD && SkillToMastery(v45->pActiveSkills[PLAYER_SKILL_SHIELD]) == 4)) 7695 if ( itemId == ITEM_RELIC_KELEBRIM || itemId == ITEM_ARTIFACT_ELFBANE || (playerPtr->GetEquippedItemEquipType(EQUIP_MAIN_HAND) == EQUIP_SHIELD && SkillToMastery(playerPtr->pActiveSkills[PLAYER_SKILL_SHIELD]) == 4))
7736 dmgToReceive >>= 1; 7696 dmgToReceive >>= 1;
7737 } 7697 }
7738 if ( v45->HasItemEquipped(EQUIP_OFF_HAND)) 7698 if ( playerPtr->HasItemEquipped(EQUIP_OFF_HAND))
7739 { 7699 {
7740 v48 = v45->pInventoryItemList[v45->pEquipment.uShield - 1].uItemID; 7700 int itemId = playerPtr->pInventoryItemList[playerPtr->pEquipment.uShield - 1].uItemID;
7741 if ( v48 == ITEM_RELIC_KELEBRIM || v48 == ITEM_ARTIFACT_ELFBANE || (v45->GetEquippedItemEquipType(EQUIP_OFF_HAND) == EQUIP_SHIELD && SkillToMastery(v45->pActiveSkills[PLAYER_SKILL_SHIELD]) == 4)) 7701 if ( itemId == ITEM_RELIC_KELEBRIM || itemId == ITEM_ARTIFACT_ELFBANE || (playerPtr->GetEquippedItemEquipType(EQUIP_OFF_HAND) == EQUIP_SHIELD && SkillToMastery(playerPtr->pActiveSkills[PLAYER_SKILL_SHIELD]) == 4))
7742 dmgToReceive >>= 1; 7702 dmgToReceive >>= 1;
7743 } 7703 }
7744 } 7704 }
7745 if ( actorPtr->pActorBuffs[3].uExpireTime > 0 ) 7705 if ( actorPtr->pActorBuffs[3].uExpireTime > 0 )
7746 { 7706 {
7747 v49 = actorPtr->pActorBuffs[3].uPower; 7707 int spellPower = actorPtr->pActorBuffs[3].uPower;
7748 if ( v49 ) 7708 if ( spellPower )
7749 dmgToReceive /= (signed int)v49; 7709 dmgToReceive /= (signed int)spellPower;
7750 } 7710 }
7751 switch(v74) 7711 int damageType;
7712 switch(element)
7752 { 7713 {
7753 case 0: 7714 case 0:
7754 v50 = actorPtr->pMonsterInfo.uAttack1Type; 7715 damageType = actorPtr->pMonsterInfo.uAttack1Type;
7755 break; 7716 break;
7756 case 1: 7717 case 1:
7757 v50 = actorPtr->pMonsterInfo.uAttack2Type; 7718 damageType = actorPtr->pMonsterInfo.uAttack2Type;
7758 break; 7719 break;
7759 case 2: 7720 case 2:
7760 v53 = actorPtr->pMonsterInfo.uSpell1ID; 7721 spellId = actorPtr->pMonsterInfo.uSpell1ID;
7761 v50 = LOBYTE(pSpellStats->pInfos[v53].uSchool); 7722 damageType = LOBYTE(pSpellStats->pInfos[spellId].uSchool);
7762 break; 7723 break;
7763 case 3: 7724 case 3:
7764 v53 = actorPtr->pMonsterInfo.uSpell2ID; 7725 spellId = actorPtr->pMonsterInfo.uSpell2ID;
7765 v50 = LOBYTE(pSpellStats->pInfos[v53].uSchool); 7726 damageType = LOBYTE(pSpellStats->pInfos[spellId].uSchool);
7766 break; 7727 break;
7767 case 4: 7728 case 4:
7768 v50 = actorPtr->pMonsterInfo.field_3C_some_special_attack; 7729 damageType = actorPtr->pMonsterInfo.field_3C_some_special_attack;
7769 break; 7730 break;
7770 case 5: 7731 case 5:
7771 v50 = 4; 7732 damageType = 4;
7772 break; 7733 break;
7773 } 7734 }
7774 if ( !(dword_6BE368_debug_settings_2 & 0x10) ) 7735 if ( !(dword_6BE368_debug_settings_2 & 0x10) )
7775 { 7736 {
7776 v54 = v45->ReceiveDamage(dmgToReceive, (DAMAGE_TYPE)v50); 7737 int reflectedDmg = playerPtr->ReceiveDamage(dmgToReceive, (DAMAGE_TYPE)damageType);
7777 if ( v45->pPlayerBuffs[10].uExpireTime > 0 ) 7738 if ( playerPtr->pPlayerBuffs[10].uExpireTime > 0 )
7778 { 7739 {
7779 v55 = actorPtr->uAIState; 7740 unsigned __int16 actorState = actorPtr->uAIState;
7780 if ( v55 != Dying && v55 != Dead) 7741 if ( actorState != Dying && actorState != Dead)
7781 { 7742 {
7782 recvdMagicDmg = stru_50C198.CalcMagicalDamageToActor(actorPtr, v50, v54); 7743 recvdMagicDmg = stru_50C198.CalcMagicalDamageToActor(actorPtr, damageType, reflectedDmg);
7783 actorPtr->sCurrentHP -= recvdMagicDmg; 7744 actorPtr->sCurrentHP -= recvdMagicDmg;
7784 if ( recvdMagicDmg >= 0 ) 7745 if ( recvdMagicDmg >= 0 )
7785 { 7746 {
7786 if ( actorPtr->sCurrentHP >= 1 ) 7747 if ( actorPtr->sCurrentHP >= 1 )
7787 { 7748 {
7790 } 7751 }
7791 else 7752 else
7792 { 7753 {
7793 if ( pMonsterStats->pInfos[actorPtr->pMonsterInfo.uID].bQuestMonster & 1 && pRenderer->pRenderD3D && pGame->uFlags2 & GAME_FLAGS_2_DRAW_BLOODSPLATS ) 7754 if ( pMonsterStats->pInfos[actorPtr->pMonsterInfo.uID].bQuestMonster & 1 && pRenderer->pRenderD3D && pGame->uFlags2 & GAME_FLAGS_2_DRAW_BLOODSPLATS )
7794 { 7755 {
7795 v57 = byte_4D864C && BYTE2(pGame->uFlags) & 8 ? 10 * actorPtr->uActorRadius : actorPtr->uActorRadius; 7756 int splatRadius = byte_4D864C && BYTE2(pGame->uFlags) & 8 ? 10 * actorPtr->uActorRadius : actorPtr->uActorRadius;
7796 pDecalBuilder->AddBloodsplat(actorPtr->vPosition.x, actorPtr->vPosition.y, actorPtr->vPosition.z, 1.0, 0.0, 0.0, (float)v57, 0, 0); 7757 pDecalBuilder->AddBloodsplat(actorPtr->vPosition.x, actorPtr->vPosition.y, actorPtr->vPosition.z, 1.0, 0.0, 0.0, (float)splatRadius, 0, 0);
7797 } 7758 }
7798 Actor::Die(uActorID); 7759 Actor::Die(uActorID);
7799 Actor::ApplyFineForKillingPeasant(uActorID); 7760 Actor::ApplyFineForKillingPeasant(uActorID);
7800 Actor::AggroSurroundingPeasants(uActorID, 1); 7761 Actor::AggroSurroundingPeasants(uActorID, 1);
7801 if ( actorPtr->pMonsterInfo.uExp ) 7762 if ( actorPtr->pMonsterInfo.uExp )
7802 GivePartyExp(pMonsterStats->pInfos[actorPtr->pMonsterInfo.uID].uExp); 7763 GivePartyExp(pMonsterStats->pInfos[actorPtr->pMonsterInfo.uID].uExp);
7803 v64 = SPEECH_51; 7764 int speechToPlay = SPEECH_51;
7804 if ( rand() % 100 < 20 ) 7765 if ( rand() % 100 < 20 )
7805 v64 = ((signed int)actorPtr->pMonsterInfo.uHP >= 100) + 1; 7766 speechToPlay = actorPtr->pMonsterInfo.uHP >= 100 ? 2 : 1;
7806 v45->PlaySound((PlayerSpeech)v64, 0); 7767 playerPtr->PlaySound((PlayerSpeech)speechToPlay, 0);
7807 } 7768 }
7808 } 7769 }
7809 } 7770 }
7810 } 7771 }
7811 } 7772 }
7812 if ( !v74 7773 if ( !element
7813 && !(dword_6BE368_debug_settings_2 & 0x10) 7774 && !(dword_6BE368_debug_settings_2 & 0x10)
7814 && actorPtr->pMonsterInfo.uSpecialAttack 7775 && actorPtr->pMonsterInfo.uSpecialAttack
7815 && rand() % 100 < actorPtr->pMonsterInfo.uLevel * actorPtr->pMonsterInfo.uSpecialAttackType ) 7776 && rand() % 100 < actorPtr->pMonsterInfo.uLevel * actorPtr->pMonsterInfo.uSpecialAttackType )
7816 { 7777 {
7817 v45->_48DCF6(actorPtr->pMonsterInfo.uSpecialAttack, actorPtr); 7778 playerPtr->_48DCF6(actorPtr->pMonsterInfo.uSpecialAttack, actorPtr);
7818 } 7779 }
7819 if ( !pParty->bTurnBasedModeOn ) 7780 if ( !pParty->bTurnBasedModeOn )
7820 { 7781 {
7821 v65 = v45->GetActualEndurance(); 7782 int actEnd = playerPtr->GetActualEndurance();
7822 v66 = (int)((20 - v45->GetParameterBonus(v65)) 7783 int recTime = (int)((20 - playerPtr->GetParameterBonus(actEnd))
7823 * flt_6BE3A4_debug_recmod1 7784 * flt_6BE3A4_debug_recmod1
7824 * 2.133333333333333); 7785 * 2.133333333333333);
7825 v45->SetRecoveryTime(v66); 7786 playerPtr->SetRecoveryTime(recTime);
7826 } 7787 }
7827 return; 7788 return;
7828 } 7789 }
7829 else 7790 else
7830 { 7791 {