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; }
void HealthComponent::damage(float damage, Entity* damager) { /*if (isImmune()){ mImmuneTimer = sf::Time::Zero; return; }*/ if (isImmune()) damage = 0.f; mDamagedFunc(damage, damager); mCurrentHealth -= std::abs(damage); mWasHealthChanged = true; if (damager != mOwnerEntity && damage > 0.f && mOwnerEntity->hasComp<SpriteComponent>()) mOwnerEntity->comp<SpriteComponent>()->beganBlink(); EntityGotDamagedEvent::Ptr eventBase(new EntityGotDamagedEvent(mOwnerEntity)); EventManager::getInstance()->queueEvent(std::move(eventBase)); }
bool Creature::addCondition(Condition* condition) { if(condition == NULL || isImmune(condition)){ delete condition; return false; } for(ConditionList::const_iterator it = conditions.begin(); it != conditions.end(); ++it){ if((*it)->onUpdate(this, condition)){ delete condition; return true; } } if(condition->onBegin(this)){ onAddCondition(condition); conditions.push_back(condition); condition->setAttached(true); onAddCondition(condition, false); return true; } return false; }
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; }
bool AntiCheat::_DoAntiCheatCheck(AntiCheatCheck checktype) { m_currentConfig = _FindConfig(checktype); if (!m_currentConfig) return true; AntiCheatCheckEntry* _check = _FindCheck(checktype); if (!_check) return true; bool checkpassed = true; if (_check->active && CheckTimer(checktype) && CheckNeeded(checktype)) { if (m_counters.find(checktype) == m_counters.end()) m_counters.insert(std::make_pair(checktype, 0)); if (!(this->*(_check->Handler))() && !isImmune()) { if (m_currentConfig->disableOperation) checkpassed = false; ++m_counters[checktype]; if (m_lastalarmtime.find(checktype) == m_lastalarmtime.end()) m_lastalarmtime.insert(std::make_pair(checktype, 0)); m_lastalarmtime[checktype] = WorldTimer::getMSTime(); if (m_counters[checktype] >= m_currentConfig->alarmsCount) { m_currentCheckResult.insert(0,m_currentConfig->description.c_str()); DoAntiCheatAction(checktype, m_currentCheckResult); m_counters[checktype] = 0; m_currentCheckResult.clear(); } } else { if (WorldTimer::getMSTimeDiff(m_lastalarmtime[checktype],WorldTimer::getMSTime()) > sWorld.getConfig(CONFIG_UINT32_ANTICHEAT_ACTION_DELAY) || (m_currentConfig->checkParam[0] > 0 && m_currentConfig->alarmsCount > 1 && WorldTimer::getMSTimeDiff(m_lastalarmtime[checktype],WorldTimer::getMSTime()) > m_currentConfig->checkParam[0])) { m_counters[checktype] = 0; } } m_oldCheckTime[checktype] = WorldTimer::getMSTime(); } // Subchecks, if exist if (checktype < 100 && _check->active && CheckNeeded(checktype)) { for (int i=1; i < 99; ++i ) { uint32 subcheck = checktype * 100 + i; if (AntiCheatConfig const* config = _FindConfig(AntiCheatCheck(subcheck))) { checkpassed |= _DoAntiCheatCheck(AntiCheatCheck(subcheck)); } else break; } } // If any of checks fail, return false return checkpassed; };
bool Creature::isImmune(const Condition* condition) const { return isImmune(condition->getMechanicType()) || isImmune(condition->getCombatType()); }