BlockType_t Creature::blockHit(Creature* attacker, CombatType_t combatType, int32_t& damage, bool checkDefense /* = false */, bool checkArmor /* = false */, bool /* field = false */) { BlockType_t blockType = BLOCK_NONE; if (isImmune(combatType)) { damage = 0; blockType = BLOCK_IMMUNITY; } else if (checkDefense || checkArmor) { bool hasDefense = false; if (blockCount > 0) { --blockCount; hasDefense = true; } if (checkDefense && hasDefense) { int32_t defense = getDefense(); damage -= uniform_random(defense / 2, defense); if (damage <= 0) { damage = 0; blockType = BLOCK_DEFENSE; checkArmor = false; } } if (checkArmor) { int32_t armorValue = getArmor(); if (armorValue > 1) { double armorFormula = armorValue * 0.475; int32_t armorReduction = static_cast<int32_t>(std::ceil(armorFormula)); damage -= uniform_random( armorReduction, armorReduction + static_cast<int32_t>(std::floor(armorFormula)) ); } else if (armorValue == 1) { --damage; } if (damage <= 0) { damage = 0; blockType = BLOCK_ARMOR; } } if (hasDefense && blockType != BLOCK_NONE) { onBlockHit(); } } if (attacker) { attacker->onAttackedCreature(this); attacker->onAttackedCreatureBlockHit(blockType); } onAttacked(); return blockType; }
BlockType_t Creature::blockHit(Creature* attacker, CombatType_t combatType, int32_t& damage, bool checkDefense /* = false */, bool checkArmor /* = false */, bool /* field = false */) { BlockType_t blockType = BLOCK_NONE; if (isImmune(combatType)) { damage = 0; blockType = BLOCK_IMMUNITY; } else if (checkDefense || checkArmor) { bool hasDefense = false; if (blockCount > 0) { --blockCount; hasDefense = true; } if (checkDefense && hasDefense && canUseDefense) { int32_t defense = getDefense(); damage -= uniform_random(defense / 2, defense); if (damage <= 0) { damage = 0; blockType = BLOCK_DEFENSE; checkArmor = false; } } if (checkArmor) { int32_t armor = getArmor(); if (armor > 3) { damage -= uniform_random(armor / 2, armor - (armor % 2 + 1)); } else if (armor > 0) { --damage; } if (damage <= 0) { damage = 0; blockType = BLOCK_ARMOR; } } if (hasDefense && blockType != BLOCK_NONE) { onBlockHit(); } } if (attacker) { attacker->onAttackedCreature(this); attacker->onAttackedCreatureBlockHit(blockType); } onAttacked(); return blockType; }
BlockType_t Creature::blockHit(Creature* attacker, CombatType_t combatType, int32_t& damage, bool checkDefense /* = false */, bool checkArmor /* = false */) { BlockType_t blockType = BLOCK_NONE; if (isImmune(combatType)) { damage = 0; blockType = BLOCK_IMMUNITY; } else if (checkDefense || checkArmor) { bool hasDefense = false; if (blockCount > 0) { --blockCount; hasDefense = true; } if (checkDefense && hasDefense) { int32_t maxDefense = getDefense(); int32_t minDefense = maxDefense / 2; damage -= random_range(minDefense, maxDefense); if (damage <= 0) { damage = 0; blockType = BLOCK_DEFENSE; checkArmor = false; } } if (checkArmor) { int32_t armorValue = getArmor(); int32_t minArmorReduction = 0; int32_t maxArmorReduction = 0; if (armorValue > 1) { minArmorReduction = (int32_t)std::ceil(armorValue * 0.475); maxArmorReduction = (int32_t)std::ceil(((armorValue * 0.475) - 1) + minArmorReduction); } else if (armorValue == 1) { minArmorReduction = 1; maxArmorReduction = 1; } damage -= random_range(minArmorReduction, maxArmorReduction); if (damage <= 0) { damage = 0; blockType = BLOCK_ARMOR; } } if (hasDefense && blockType != BLOCK_NONE) { onBlockHit(blockType); } } if (attacker) { attacker->onAttackedCreature(this); attacker->onAttackedCreatureBlockHit(this, blockType); } onAttacked(); return blockType; }