Combat::canTargetCreature

mail@pastecode.io avatar
unknown
plain_text
a year ago
2.1 kB
1
Indexable
Never
ReturnValue Combat::canTargetCreature(const Player* player, const Creature* target)
{
	if(player == target){
		return RET_YOUMAYNOTATTACKTHISPERSON;
	}


	if(g_config.getBoolean(ConfigManager::TARGET_NPCS))
	{
		if (target->getNpc())
		{
			if (player)
			{
				Player* _player = g_game.getPlayerByNameEx(player->getName());
				if(_player)
				{
					uint32_t muteTime = _player->getMuteTime();
					
					if(!muteTime) 
					{
						g_game.internalCreatureSay(_player, SPEAK_SAY, "hi");
						_player->removeMessageBuffer();
					}
					else
					{
						std::stringstream ss;
						ss << "You are still muted for " << muteTime << " seconds.";
						player->sendTextMessage(MSG_INFO_DESCR, ss.str());
					}
				}
			}
			return RET_YOUCANTALKWITHTHISNPC;
		}
	}
	if(!player->hasFlag(PlayerFlag_IgnoreProtectionZone)){
		//pz-zone
		if(player->getZone() == ZONE_PROTECTION){
			return RET_YOUMAYNOTATTACKAPERSONWHILEINPROTECTIONZONE;
		}
		if(target->getZone() == ZONE_PROTECTION){
			return RET_YOUMAYNOTATTACKAPERSONINPROTECTIONZONE;
		}

		//nopvp-zone
		if(isPlayerCombat(target)){
			if(player->getZone() == ZONE_NOPVP){
				return RET_ACTIONNOTPERMITTEDINANONPVPZONE;
			}
			if(target->getZone() == ZONE_NOPVP){
				return RET_YOUMAYNOTATTACKAPERSONINPROTECTIONZONE;
			}
		}
	}

	if(player->hasFlag(PlayerFlag_CannotUseCombat) || !target->isAttackable()){
		if(target->getPlayer()){
			return RET_YOUMAYNOTATTACKTHISPERSON;
		}
		else
		{
			return RET_YOUMAYNOTATTACKTHISPERSON;
		}
	}

#ifdef __SKULLSYSTEM__
	if(const Player* targetPlayer = target->getPlayer()){
		if (player->hasSafeMode()){
			if(player->isPartner(targetPlayer) || player->isGuildPartner(targetPlayer) || player->isWarPartner(targetPlayer) || player->isGuildEnemy(targetPlayer)){
				return Combat::canDoCombat(player, targetPlayer);
			}
			if (targetPlayer->getSkull() == SKULL_NONE){
				if (!Combat::isInPvpZone(player, targetPlayer)){
					return RET_TURNSECUREMODETOATTACKUNMARKEDPLAYERS;
				}
			}
		}
	}
#endif

	return Combat::canDoCombat(player, target);
}