ReturnValue Combat::canDoCombat(const Creature* attacker, const Creature* target) { if(attacker){ if(const Player* targetPlayer = target->getPlayer()){ if(targetPlayer->hasFlag(PlayerFlag_CannotBeAttacked)){ return RET_YOUMAYNOTATTACKTHISPLAYER; } if(const Player* attackerPlayer = attacker->getPlayer()){ if(attackerPlayer->hasFlag(PlayerFlag_CannotAttackPlayer)){ return RET_YOUMAYNOTATTACKTHISPLAYER; } } if(attacker->isSummon()){ if(const Player* masterAttackerPlayer = attacker->getMaster()->getPlayer()){ if(masterAttackerPlayer->hasFlag(PlayerFlag_CannotAttackPlayer)){ return RET_YOUMAYNOTATTACKTHISPLAYER; } } } } else if(target->getMonster()){ if(const Player* attackerPlayer = attacker->getPlayer()){ if(attackerPlayer->hasFlag(PlayerFlag_CannotAttackMonster)){ return RET_YOUMAYNOTATTACKTHISCREATURE; } } } if(attacker->getPlayer() || (attacker->isSummon() && attacker->getMaster()->getPlayer()) ){ //nopvp-zone if(target->getPlayer() && target->getTile()->hasFlag(TILESTATE_NOPVPZONE)){ return RET_ACTIONNOTPERMITTEDINANOPVPZONE; } if(g_game.getWorldType() == WORLD_TYPE_NO_PVP){ if(target->getPlayer()){ if(!isInPvpZone(attacker, target)){ return RET_YOUMAYNOTATTACKTHISPLAYER; } } if(target->isSummon() && target->getMaster()->getPlayer()){ if(!isInPvpZone(attacker, target)){ return RET_YOUMAYNOTATTACKTHISCREATURE; } } } } } return RET_NOERROR; }
ReturnValue Combat::canDoCombat(Creature* attacker, Creature* target) { if (attacker) { if (const Player* targetPlayer = target->getPlayer()) { if (targetPlayer->hasFlag(PlayerFlag_CannotBeAttacked)) { return RETURNVALUE_YOUMAYNOTATTACKTHISPLAYER; } if (const Player* attackerPlayer = attacker->getPlayer()) { if (attackerPlayer->hasFlag(PlayerFlag_CannotAttackPlayer)) { return RETURNVALUE_YOUMAYNOTATTACKTHISPLAYER; } if (isProtected(attackerPlayer, targetPlayer)) { return RETURNVALUE_YOUMAYNOTATTACKTHISPLAYER; } //nopvp-zone const Tile* targetPlayerTile = targetPlayer->getTile(); if (targetPlayerTile->hasFlag(TILESTATE_NOPVPZONE)) { return RETURNVALUE_ACTIONNOTPERMITTEDINANOPVPZONE; } else if (attackerPlayer->getTile()->hasFlag(TILESTATE_NOPVPZONE) && !targetPlayerTile->hasFlag(TILESTATE_NOPVPZONE) && !targetPlayerTile->hasFlag(TILESTATE_PROTECTIONZONE)) { return RETURNVALUE_ACTIONNOTPERMITTEDINANOPVPZONE; } } if (attacker->isSummon()) { if (const Player* masterAttackerPlayer = attacker->getMaster()->getPlayer()) { if (masterAttackerPlayer->hasFlag(PlayerFlag_CannotAttackPlayer)) { return RETURNVALUE_YOUMAYNOTATTACKTHISPLAYER; } if (targetPlayer->getTile()->hasFlag(TILESTATE_NOPVPZONE)) { return RETURNVALUE_ACTIONNOTPERMITTEDINANOPVPZONE; } if (isProtected(masterAttackerPlayer, targetPlayer)) { return RETURNVALUE_YOUMAYNOTATTACKTHISPLAYER; } } } } else if (target->getMonster()) { if (const Player* attackerPlayer = attacker->getPlayer()) { if (attackerPlayer->hasFlag(PlayerFlag_CannotAttackMonster)) { return RETURNVALUE_YOUMAYNOTATTACKTHISCREATURE; } if (target->isSummon() && target->getMaster()->getPlayer() && target->getZone() == ZONE_NOPVP) { return RETURNVALUE_ACTIONNOTPERMITTEDINANOPVPZONE; } } else if (attacker->getMonster()) { const Creature* targetMaster = target->getMaster(); if (!targetMaster || !targetMaster->getPlayer()) { const Creature* attackerMaster = attacker->getMaster(); if (!attackerMaster || !attackerMaster->getPlayer()) { return RETURNVALUE_YOUMAYNOTATTACKTHISCREATURE; } } } } if (g_game.getWorldType() == WORLD_TYPE_NO_PVP) { if (attacker->getPlayer() || (attacker->isSummon() && attacker->getMaster()->getPlayer())) { if (target->getPlayer()) { if (!isInPvpZone(attacker, target)) { return RETURNVALUE_YOUMAYNOTATTACKTHISPLAYER; } } if (target->isSummon() && target->getMaster()->getPlayer()) { if (!isInPvpZone(attacker, target)) { return RETURNVALUE_YOUMAYNOTATTACKTHISCREATURE; } } } } } return g_events->eventCreatureOnTargetCombat(attacker, target); }
ReturnValue Combat::checkPVPExtraRestrictions(const Creature* attacker, const Creature* target, bool isWalkCheck) { #ifdef __MIN_PVP_LEVEL_APPLIES_TO_SUMMONS__ const Player* targetPlayer; if (g_config.getNumber(ConfigManager::MIN_PVP_LEVEL_APPLIES_TO_SUMMONS)) { targetPlayer = target->getPlayerInCharge(); } else { targetPlayer = target->getPlayer(); } #else const Player* targetPlayer = target->getPlayer(); #endif const Player* attackerPlayer = attacker->getPlayerInCharge(); if (targetPlayer && attackerPlayer) { bool stopAttack = false; bool canPassThrough = g_config.getBoolean(ConfigManager::CAN_PASS_THROUGH); if (g_game.getWorldType() == WORLD_TYPE_OPTIONAL_PVP) { if (!targetPlayer->isGuildEnemy(attackerPlayer) || (!isWalkCheck && !isInPvpZone(attacker, target))) { stopAttack = true; } if (isWalkCheck && !canPassThrough) { stopAttack = true; } } else { if (!isWalkCheck || canPassThrough) { uint32_t p_level = g_config.getNumber(ConfigManager::MIN_PVP_LEVEL); uint32_t attackerLevel = attackerPlayer->getLevel(); uint32_t targetLevel = targetPlayer->getLevel(); if ((attackerLevel >= p_level && targetLevel < p_level && isWalkCheck) || (!isWalkCheck && (attackerLevel < p_level || targetLevel < p_level))) { stopAttack = true; } } } if (stopAttack) { if (target->getPlayer()) { return RET_YOUMAYNOTATTACKTHISPERSON; } else { return RET_YOUMAYNOTATTACKTHISCREATURE; } } } return RET_NOERROR; }