Untitled
unknown
c_cpp
a year ago
1.7 kB
6
Indexable
BlockType_t Creature::blockHit(Creature* attacker, CombatType_t combatType, int32_t& damage, bool checkDefense /* = false */, bool checkArmor /* = false */, bool /* field = false */, bool /* ignoreResistances = false */) { BlockType_t blockType = BLOCK_NONE; // Immune if (isImmune(combatType)) { damage = 0; blockType = BLOCK_IMMUNITY; // Block chance } else { if (uniform_random(1, 100) <= getBlockChance()) { damage -= getBlockAmount(); if (damage <= 0) { damage = 0; std::cout << "Block" << std::endl; blockType = BLOCK_SHIELD; checkDefense = false; checkArmor = false; } } // Defense if (checkDefense && blockCount > 0) { --blockCount; bool hasDefense = true; if (hasDefense && canUseDefense) { int32_t defense = getDefense(); damage -= uniform_random(defense / 2, defense); if (damage <= 0) { damage = 0; std::cout << "Defense" << std::endl; blockType = BLOCK_DEFENSE; checkArmor = false; } } } // Armor if (checkArmor) { int32_t armor = getArmor(); if (armor > 3) { damage -= uniform_random(armor / 2, armor - (armor % 2 + 1)); std::cout << "Armor" << std::endl; } else if (armor > 0) { --damage; } if (damage <= 0) { damage = 0; std::cout << "No Damage" << std::endl; blockType = BLOCK_ARMOR; } } if (blockType != BLOCK_NONE) { onBlockHit(); } } if (attacker) { attacker->onAttackedCreature(this); attacker->onAttackedCreatureBlockHit(blockType); } onAttacked(); return blockType; }
Editor is loading...
Leave a Comment