<commit_before>
#ifndef PETTRANSFERCOMMAND_H_
#define PETTRANSFERCOMMAND_H_

#include "server/zone/objects/creature/commands/QueueCommand.h"
#include "server/zone/objects/scene/SceneObject.h"
#include "server/zone/objects/creature/AiAgent.h"

class PetTransferCommand : public QueueCommand {
public:
	PetTransferCommand(const String& name, ZoneProcessServer* server)
		: QueueCommand(name, server) {
	}


	int doQueueCommand(CreatureObject* creature, const uint64& target, const UnicodeString& arguments) {

		ManagedReference<PetControlDevice*> controlDevice = creature->getControlDevice().castTo<PetControlDevice*>();

		if (controlDevice == NULL)
			return GENERALERROR;

		// Creature specific command
		if( controlDevice->getPetType() != PetManager::CREATUREPET )
			return GENERALERROR;

		if (!creature->isAiAgent())
			return GENERALERROR;

		ManagedReference<AiAgent*> pet = cast<AiAgent*>(creature);
		if( pet == NULL )
			return GENERALERROR;

		ManagedReference< CreatureObject*> player = pet->getLinkedCreature().get();
		if( player == NULL )
			return GENERALERROR;

		ManagedReference<SceneObject*> commandTarget = server->getZoneServer()->getObject(target);

		if (commandTarget == NULL || !commandTarget->isPlayerCreature()) {
			player->sendSystemMessage("Your target must be a player to transfer a pet.");
			return GENERALERROR;
		}

		ManagedReference<CreatureObject*> targetPlayer = cast<CreatureObject*>(commandTarget.get());

		Locker targetCrosslocker(targetPlayer, creature);

		if (!targetPlayer->hasSkill("outdoors_creaturehandler_novice")) {
			player->sendSystemMessage("@pet/pet_menu:pet_nothandler"); // You cannot transfer a creature to someone who is not a trained Creature Handler.
			return GENERALERROR;
		}

		if (!player->isInRange(targetPlayer, 15)) {
			player->sendSystemMessage("@error_message:target_out_of_range"); // Your target is out of range for this action.
			return GENERALERROR;
		}

		if (!controlDevice->canBeTradedTo(player, targetPlayer, 0))
			return GENERALERROR;

		if (pet->isInCombat() || player->isInCombat() || targetPlayer->isInCombat())
			return GENERALERROR;

		if (pet->hasRidingCreature())
			return GENERALERROR;

		ManagedReference<PlayerObject*> targetGhost = targetPlayer->getPlayerObject();
		ManagedReference<PlayerObject*> ghost = player->getPlayerObject();

		if (targetGhost == NULL || ghost == NULL)
			return GENERALERROR;

		int activePets = 0;
		int petLevel = 0;

		for (int i = 0; i < targetGhost->getActivePetsSize(); i++) {
			ManagedReference<AiAgent*> targetPet = targetGhost->getActivePet(i);

			ManagedReference<PetControlDevice*> device = targetPet->getControlDevice().get().castTo<PetControlDevice*>();

			if (device == NULL)
				continue;

			if (device->getPetType() == PetManager::CREATUREPET) {
				activePets++;
				petLevel += targetPet->getLevel();
			}
		}

		if (activePets >= targetPlayer->getSkillMod("keep_creature")) {
			player->sendSystemMessage("@pet/pet_menu:targ_too_many"); // That person has too many pets. Transfer failed.
			targetPlayer->sendSystemMessage("@pet/pet_menu:too_many"); // You can't control any more pets. Store one first.
			return GENERALERROR;
		}

		if ((petLevel + pet->getLevel()) > targetPlayer->getSkillMod("tame_level")) {<commit_msg>[Fixed] Can't transfer level 10 pet to Non-Ch toon Mantis #5820<commit_after>
#ifndef PETTRANSFERCOMMAND_H_
#define PETTRANSFERCOMMAND_H_

#include "server/zone/objects/creature/commands/QueueCommand.h"
#include "server/zone/objects/scene/SceneObject.h"
#include "server/zone/objects/creature/AiAgent.h"

class PetTransferCommand : public QueueCommand {
public:
	PetTransferCommand(const String& name, ZoneProcessServer* server)
		: QueueCommand(name, server) {
	}


	int doQueueCommand(CreatureObject* creature, const uint64& target, const UnicodeString& arguments) {

		ManagedReference<PetControlDevice*> controlDevice = creature->getControlDevice().castTo<PetControlDevice*>();

		if (controlDevice == NULL)
			return GENERALERROR;

		// Creature specific command
		if( controlDevice->getPetType() != PetManager::CREATUREPET )
			return GENERALERROR;

		if (!creature->isAiAgent())
			return GENERALERROR;

		ManagedReference<AiAgent*> pet = cast<AiAgent*>(creature);
		if( pet == NULL )
			return GENERALERROR;

		ManagedReference< CreatureObject*> player = pet->getLinkedCreature().get();
		if( player == NULL )
			return GENERALERROR;

		ManagedReference<SceneObject*> commandTarget = server->getZoneServer()->getObject(target);

		if (commandTarget == NULL || !commandTarget->isPlayerCreature()) {
			player->sendSystemMessage("Your target must be a player to transfer a pet.");
			return GENERALERROR;
		}

		ManagedReference<CreatureObject*> targetPlayer = cast<CreatureObject*>(commandTarget.get());

		Locker targetCrosslocker(targetPlayer, creature);

		if (!player->isInRange(targetPlayer, 15)) {
			player->sendSystemMessage("@error_message:target_out_of_range"); // Your target is out of range for this action.
			return GENERALERROR;
		}

		if (!controlDevice->canBeTradedTo(player, targetPlayer, 0))
			return GENERALERROR;

		if (pet->isInCombat() || player->isInCombat() || targetPlayer->isInCombat())
			return GENERALERROR;

		if (pet->hasRidingCreature())
			return GENERALERROR;

		ManagedReference<PlayerObject*> targetGhost = targetPlayer->getPlayerObject();
		ManagedReference<PlayerObject*> ghost = player->getPlayerObject();

		if (targetGhost == NULL || ghost == NULL)
			return GENERALERROR;

		int activePets = 0;
		int petLevel = 0;

		for (int i = 0; i < targetGhost->getActivePetsSize(); i++) {
			ManagedReference<AiAgent*> targetPet = targetGhost->getActivePet(i);

			ManagedReference<PetControlDevice*> device = targetPet->getControlDevice().get().castTo<PetControlDevice*>();

			if (device == NULL)
				continue;

			if (device->getPetType() == PetManager::CREATUREPET) {
				activePets++;
				petLevel += targetPet->getLevel();
			}
		}

		//none ch doesn't seem to have keep_creature, effectively returns 0/
		if (activePets != 0 && activePets >= targetPlayer->getSkillMod("keep_creature")) {
			player->sendSystemMessage("@pet/pet_menu:targ_too_many"); // That person has too many pets. Transfer failed.
			targetPlayer->sendSystemMessage("@pet/pet_menu:too_many"); // You can't control any more pets. Store one first.
			return GENERALERROR;
		}

		//None CH can only have 1 active pet.
		if(targetPlayer->hasSkill("outdoors_creaturehandler_novice") && ((petLevel + pet->getLevel()) > targetPlayer->getSkillMod("tame_level")))
		{
{'fraction_non_alphanumeric': 0.1282638570774164, 'fraction_numerical': 0.003817376698732631, 'mean_word_length': 5.2920268972142175, 'pattern_counts': {'":': 0, '<': 31, '<?xml version=': 0, '>': 90, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6891943', 'n_tokens_mistral': 2222, 'n_tokens_neox': 1944, 'n_words': 440}