void PetControlDeviceImplementation::arrestGrowth() {
	if (petType != PetManager::CREATUREPET)
		return;

	if (growthStage <= 0 || growthStage >= 10)
		return;

	ManagedReference<TangibleObject*> controlledObject = this->controlledObject.get();

	if (controlledObject == NULL || !controlledObject->isCreature())
		return;

	ManagedReference<Creature*> pet = cast<Creature*>(controlledObject.get());

	ManagedReference<CreatureTemplate*> creatureTemplate = pet->getCreatureTemplate();

	if (creatureTemplate == NULL)
		return;

	PetManager* petManager = pet->getZoneServer()->getPetManager();
	if (petManager == NULL)
		return;

	int newStage = growthStage;

	for (int i = (growthStage + 1); i < 11; i++) {
		float newHeight = creatureTemplate->getScale() * (0.46 + ((float)i * 0.06));

		short mountEligibility = petManager->checkMountEligibility(_this.getReferenceUnsafeStaticCast(), newHeight);

		if (mountEligibility == PetManager::TOOLARGE)
			break;
		else if (mountEligibility == PetManager::CANBEMOUNTTRAINED)
			newStage = i;
	}

	if (newStage > growthStage) {
		float newLevel = ((float)pet->getAdultLevel() / 10.0) * (float)newStage;
		if (newLevel < 1)
			newLevel = 1;

		float newHeight = creatureTemplate->getScale() * (0.46 + ((float)newStage * 0.06));

		pet->setHeight(newHeight, false);
		pet->setPetLevel(newLevel);
	}

	setVitality(getVitality());

	growthStage = 10;
	lastGrowth.updateToCurrentTime();
}
void DroidHarvestModuleDataComponent::handlePetCommand(String cmd, CreatureObject* speaker){

	ManagedReference<DroidObject*> droid = getDroidObject();
	if( droid == NULL ){
		return;
	}

	ManagedReference<PetControlDevice*> pcd = droid->getControlDevice().get().castTo<PetControlDevice*>();
	if( pcd == NULL ) {
		return;
	}

	PetManager* petManager = droid->getZoneServer()->getPetManager();
	if( petManager == NULL ) {
		return;
	}

	// Owner-only command
	if( droid->getLinkedCreature().get() != speaker ) {
		return;
	}

	if( petManager->isTrainedCommand( pcd, PetManager::HARVEST, cmd ) ){
		Locker dlock(droid);
		uint64 targetID = speaker->getTargetID();
		Reference<CreatureObject*> target = droid->getZoneServer()->getObject(targetID, true).castTo<CreatureObject*>();

		if (target != NULL) {
			// this check should occur in the pet speaking handling.
			if(!target->isInRange(droid,64)) {
				speaker->sendSystemMessage("@pet/droid_modules:corpse_too_far");
				return;
			}

			harvestTargets.add(targetID);
		}
		for(int i=0;i<harvestTargets.size();i++){
			if (harvestTargets.get(i) == targetID)
				return;
		}
		harvestTargets.add(targetID);
	}
}
void DroidRepairModuleDataComponent::handlePetCommand(String cmd, CreatureObject* speaker){

	ManagedReference<DroidObject*> droid = getDroidObject();
	if( droid == NULL )
		return;

	ManagedReference<PetControlDevice*> pcd = droid->getControlDevice().get().castTo<PetControlDevice*>();
	if( pcd == NULL )
		return;

	PetManager* petManager = droid->getZoneServer()->getPetManager();
	if( petManager == NULL )
		return;

	// Owner-only command
	if( droid->getLinkedCreature() != speaker )
		return;

	if( petManager->isTrainedCommand( pcd, PetManager::REPAIR, cmd ) ){
		petManager->enqueuePetCommand(speaker, droid, String("petRepair").toLowerCase().hashCode(), "");
	}
}
void PetControlDeviceImplementation::trainAsMount(CreatureObject* player) {
	if (isTrainedAsMount())
		return;

	PetManager* petManager = player->getZoneServer()->getPetManager();
	if (petManager == NULL)
		return;

	if (petManager->checkMountEligibility(_this.get()) != PetManager::CANBEMOUNTTRAINED)
		return;

	ManagedReference<TangibleObject*> controlledObject = this->controlledObject.get();
	if (controlledObject == NULL || !controlledObject->isAiAgent())
		return;

	AiAgent* pet = cast<AiAgent*>(controlledObject.get());
	if( pet == NULL )
		return;

	trainedAsMount = true;
	pet->setOptionsBitmask(0x1080);
}
void PetControlDeviceImplementation::trainAsMount(CreatureObject* player) {
	if (isTrainedAsMount() || !player->hasSkill("outdoors_creaturehandler_support_04"))
		return;

	PetManager* petManager = player->getZoneServer()->getPetManager();
	if (petManager == NULL)
		return;

	if (petManager->checkMountEligibility(_this.getReferenceUnsafeStaticCast()) != PetManager::CANBEMOUNTTRAINED)
		return;

	ManagedReference<TangibleObject*> controlledObject = this->controlledObject.get();
	if (controlledObject == NULL || !controlledObject->isAiAgent())
		return;

	AiAgent* pet = cast<AiAgent*>(controlledObject.get());
	if( pet == NULL )
		return;

	assert(pet->isLockedByCurrentThread());

	trainedAsMount = true;
	pet->setOptionBit(0x1000);
}
int DroidRepairModuleDataComponent::handleObjectMenuSelect(CreatureObject* player, byte selectedID, PetControlDevice* controller) {

	// Handle repair request
	if( selectedID == REPAIR_MODULE_ACTIVATE ){

		PetManager* petManager = player->getZoneServer()->getPetManager();
		if( petManager == NULL )
			return 0;

		petManager->enqueuePetCommand(player, getDroidObject(), String("petRepair").toLowerCase().hashCode(), "");

	}
	// Handle command training
	else if( selectedID == REPAIR_MODULE_TRAIN ){

		if( controller == NULL )
			return 0;

		controller->setTrainingCommand( PetManager::REPAIR );

	}

	return 0;
}
Exemplo n.º 7
0
int PetMenuComponent::handleObjectMenuSelect(SceneObject* sceneObject, CreatureObject* player, byte selectedID) {
	if (!sceneObject->isPet() || player == NULL)
		return 0;

	AiAgent* pet = cast<AiAgent*>(sceneObject);

	if (!player->getPlayerObject()->isPrivileged() && pet->getLinkedCreature().get() != player)
		return 0;

	Locker crossLocker(pet, player);

	ManagedReference<PetControlDevice*> petControlDevice = pet->getControlDevice().get().castTo<PetControlDevice*>();

	if (petControlDevice == NULL)
		return 0;

	PetManager* petManager = pet->getZoneServer()->getPetManager();
	if (petManager == NULL)
		return 0;

	Locker locker(petControlDevice);

	// Store
	if (selectedID == 59) {
		if (pet->getLinkedCreature() != player) {
			ManagedReference<CreatureObject*> owner = pet->getLinkedCreature().get();
			if (owner != NULL) {
				Reference<PetControlDeviceStoreObjectTask*> task = new PetControlDeviceStoreObjectTask(petControlDevice, owner, true);
				task->execute();
			}
		} else {
			petControlDevice->storeObject(player);
		}
		return 0;
	}

	if (pet->getLinkedCreature().get() != player)
		return 0;

	switch(selectedID) {
	case 142: // Train Command: Follow
		petControlDevice->setTrainingCommand( PetManager::FOLLOW );
		break;
	case 143: // Train Command: Stay
		petControlDevice->setTrainingCommand( PetManager::STAY );
		break;
	case 144: // Train Command: Guard
		petControlDevice->setTrainingCommand( PetManager::GUARD );
		break;
	case 145: // Train Command: Friend
		petControlDevice->setTrainingCommand( PetManager::FRIEND );
		break;
	case 146: // Train Command: Attack
		petControlDevice->setTrainingCommand( PetManager::ATTACK );
		break;
	case 147: // Train Command: Patrol
		petControlDevice->setTrainingCommand( PetManager::PATROL );
		break;
	case 148: // Train Command: Get Patrol Point
		petControlDevice->setTrainingCommand( PetManager::GETPATROLPOINT );
		break;
	case 149: // Train Command: Clear Patrol Points
		petControlDevice->setTrainingCommand( PetManager::CLEARPATROLPOINTS );
		break;
	case 150: // Train Command: Wedge Formation
		petControlDevice->setTrainingCommand( PetManager::FORMATION1 );
		break;
	case 151: // Train Command: Column Formation
		petControlDevice->setTrainingCommand( PetManager::FORMATION2 );
		break;
	case 152: // Train Command: Transfer
		petControlDevice->setTrainingCommand( PetManager::TRANSFER );
		break;
	case 154: // Train Command: Trick 1
		petControlDevice->setTrainingCommand( PetManager::TRICK1 );
		break;
	case 155: // Train Command: Trick 2
		petControlDevice->setTrainingCommand( PetManager::TRICK2 );
		break;
	case 158: // Train Command: Group
		petControlDevice->setTrainingCommand( PetManager::GROUP );
		break;
	case 161: // Train Command: Special Attack 1
		petControlDevice->setTrainingCommand( PetManager::SPECIAL_ATTACK1 );
		break;
	case 162: // Train Command: Special Attack 2
		petControlDevice->setTrainingCommand( PetManager::SPECIAL_ATTACK2 );
		break;
	case 163: // Train Command: Ranged Attack
		petControlDevice->setTrainingCommand( PetManager::RANGED_ATTACK );
		break;
	case 164: // Train Command: Store
		petControlDevice->setTrainingCommand( PetManager::STORE );
		break;
	case 165: // Train Command: Follow Other
		petControlDevice->setTrainingCommand( PetManager::FOLLOWOTHER );
		break;
	case 166: // Incapacitation Recovery
		petManager->enqueueOwnerOnlyPetCommand(player, pet, String("petRecover").toLowerCase().hashCode(), "");
		break;
	case 207: // Train Pet As A Mount
		if (petControlDevice->getPetType() != PetManager::CREATUREPET) {
			return 0;
		}
		petControlDevice->trainAsMount(player);
		break;
	case 234: // Recharge/Feed
		if (petControlDevice->getPetType() == PetManager::DROIDPET) {
			petManager->enqueueOwnerOnlyPetCommand(player, pet, String("petRecharge").toLowerCase().hashCode(), "");
		} else if (petControlDevice->getPetType() == PetManager::CREATUREPET) {
			petManager->enqueueOwnerOnlyPetCommand(player, pet, String("petFeed").toLowerCase().hashCode(), "");
		}
		break;
	case 235: // Train Command: Recharge Other
		petControlDevice->setTrainingCommand( PetManager::RECHARGEOTHER );
		break;
	default:
		break;
	}

	return 0;
}
Exemplo n.º 8
0
void PetMenuComponent::fillObjectMenuResponse(SceneObject* sceneObject, ObjectMenuResponse* menuResponse, CreatureObject* player) {
	if (!sceneObject->isPet())
		return;

	AiAgent* pet = cast<AiAgent*>(sceneObject);

	if (pet->getGroup() != NULL) {
		ManagedReference<GroupObject*> group = player->getGroup();

		if (group == pet->getGroup()) {
			if (group->getLeader() == player) {
				menuResponse->addRadialMenuItem(40, 3, "@ui_radial:group_kick"); // Kick from Group
				menuResponse->addRadialMenuItemToRadialID(40, 41, 3, "@ui_radial:group_disband" ); // Disband Group
			} else {
				menuResponse->addRadialMenuItem(39, 3, "@ui_radial:group_leave"); // Leave Group
			}

		}
	}

	if (pet->isIncapacitated() && pet->isAttackableBy(player))
		menuResponse->addRadialMenuItem(6, 3, "@ui_radial:combat_death_blow"); // Death Blow

	if (!player->getPlayerObject()->isPrivileged() && pet->getLinkedCreature() != player) {
		return;
	}

	menuResponse->addRadialMenuItem(59, 3, "@pet/pet_menu:menu_store"); // Store

	if (pet->getLinkedCreature().get() != player)
		return;

	ManagedReference<PetControlDevice*> controlDevice = pet->getControlDevice().get().castTo<PetControlDevice*>();
	if( controlDevice == NULL )
		return;

	PetManager* petManager = pet->getZoneServer()->getPetManager();
	if (petManager == NULL)
		return;

	// DROIDS
	if( controlDevice->getPetType() == PetManager::DROIDPET ){
		ManagedReference<DroidObject*> droidObject = dynamic_cast<DroidObject*>(controlDevice->getControlledObject());
		bool conversingDroid = (pet->getOptionsBitmask() & OptionBitmask::CONVERSE);
		if(conversingDroid) {
			menuResponse->addRadialMenuItem(132, 3, "@pet/pet_menu:droid_options"); // SERVER_ITEM_OPTIONS
			menuResponse->addRadialMenuItemToRadialID(132, 234, 3, "@pet/pet_menu:menu_recharge" ); // PET_FEED
			// convsering droids have less re-programmable commands
		} else {
			menuResponse->addRadialMenuItem(132, 3, "@pet/pet_menu:droid_options"); // SERVER_ITEM_OPTIONS
			menuResponse->addRadialMenuItemToRadialID(132, 234, 3, "@pet/pet_menu:menu_recharge" ); // PET_FEED
			menuResponse->addRadialMenuItem(141, 3, "@pet/pet_menu:menu_command_droid"); // PET_COMMAND
			menuResponse->addRadialMenuItemToRadialID(141, 142, 3, "@pet/pet_menu:menu_follow" ); // PET_FOLLOW
			menuResponse->addRadialMenuItemToRadialID(141, 143, 3, "@pet/pet_menu:menu_stay" ); // PET_STAY
			if (droidObject != NULL && droidObject->isCombatDroid())
				menuResponse->addRadialMenuItemToRadialID(141, 144, 3, "@pet/pet_menu:menu_guard" ); // PET_GUARD
			menuResponse->addRadialMenuItemToRadialID(141, 145, 3, "@pet/pet_menu:menu_friend" ); // PET_FRIEND
			if (droidObject != NULL && droidObject->isCombatDroid())
				menuResponse->addRadialMenuItemToRadialID(141, 146, 3, "@pet/pet_menu:menu_attack" ); // PET_ATTACK
			menuResponse->addRadialMenuItemToRadialID(141, 147, 3, "@pet/pet_menu:menu_patrol" ); // PET_PATROL
			menuResponse->addRadialMenuItemToRadialID(141, 148, 3, "@pet/pet_menu:menu_get_patrol_point" ); // PET_GET_PATROL_POINT
			menuResponse->addRadialMenuItemToRadialID(141, 149, 3, "@pet/pet_menu:menu_clear_patrol_points" ); // PET_CLEAR_PATROL_POINTS
			menuResponse->addRadialMenuItemToRadialID(141, 150, 3, "@pet/pet_menu:menu_assume_formation_1" ); // PET_ASSUME_FORMATION_1
			menuResponse->addRadialMenuItemToRadialID(141, 151, 3, "@pet/pet_menu:menu_assume_formation_2" ); // PET_ASSUME_FORMATION_2
			menuResponse->addRadialMenuItemToRadialID(141, 158, 3, "@pet/pet_menu:menu_group" ); // PET_GROUP
			if (droidObject != NULL && droidObject->isCombatDroid() && droidObject->hasRangedWeapon())
				menuResponse->addRadialMenuItemToRadialID(141, 163, 3, "@pet/pet_menu:menu_ranged_attack" );
			menuResponse->addRadialMenuItemToRadialID(141, 164, 3, "@pet/pet_menu:menu_store" );
			menuResponse->addRadialMenuItemToRadialID(141, 165, 3, "@pet/pet_menu:menu_follow_other" );

			if( droidObject != NULL && droidObject->isPowerDroid() ){
				menuResponse->addRadialMenuItemToRadialID(141, 235, 3, "@pet/pet_menu:menu_recharge_other" );
			}
		}
		if( pet->isIncapacitated() ){
			menuResponse->addRadialMenuItem(166, 3, "@pet/pet_menu:awaken" );
		}

	}
	// FACTION
	else if( controlDevice->getPetType() == PetManager::FACTIONPET ){

		// future, if conversion do as droid objects above and not add this menu at all.
		//bool conversingPet = (pet->getOptionsBitmask() & OptionBitmask::CONVERSE);

		menuResponse->addRadialMenuItem(141, 3, "@pet/pet_menu:menu_command"); // PET_COMMAND
		menuResponse->addRadialMenuItemToRadialID(141, 142, 3, "@pet/pet_menu:menu_follow" ); // PET_FOLLOW
		menuResponse->addRadialMenuItemToRadialID(141, 143, 3, "@pet/pet_menu:menu_stay" ); // PET_STAY
		menuResponse->addRadialMenuItemToRadialID(141, 144, 3, "@pet/pet_menu:menu_guard" ); // PET_GUARD
		menuResponse->addRadialMenuItemToRadialID(141, 145, 3, "@pet/pet_menu:menu_friend" ); // PET_FRIEND
		menuResponse->addRadialMenuItemToRadialID(141, 146, 3, "@pet/pet_menu:menu_attack" ); // PET_ATTACK
		menuResponse->addRadialMenuItemToRadialID(141, 147, 3, "@pet/pet_menu:menu_patrol" ); // PET_PATROL
		menuResponse->addRadialMenuItemToRadialID(141, 148, 3, "@pet/pet_menu:menu_get_patrol_point" ); // PET_GET_PATROL_POINT
		menuResponse->addRadialMenuItemToRadialID(141, 149, 3, "@pet/pet_menu:menu_clear_patrol_points" ); // PET_CLEAR_PATROL_POINTS
		menuResponse->addRadialMenuItemToRadialID(141, 150, 3, "@pet/pet_menu:menu_assume_formation_1" ); // PET_ASSUME_FORMATION_1
		menuResponse->addRadialMenuItemToRadialID(141, 151, 3, "@pet/pet_menu:menu_assume_formation_2" ); // PET_ASSUME_FORMATION_2
		menuResponse->addRadialMenuItemToRadialID(141, 158, 3, "@pet/pet_menu:menu_group" ); // PET_GROUP
		menuResponse->addRadialMenuItemToRadialID(141, 163, 3, "@pet/pet_menu:menu_ranged_attack" );
		menuResponse->addRadialMenuItemToRadialID(141, 164, 3, "@pet/pet_menu:menu_store" );
		menuResponse->addRadialMenuItemToRadialID(141, 165, 3, "@pet/pet_menu:menu_follow_other" );

		if( pet->isIncapacitated() ){
			menuResponse->addRadialMenuItem(166, 3, "@pet/pet_menu:awaken" );
		}

	}
	// CREATURES
	else if( controlDevice->getPetType() == PetManager::CREATUREPET ){

		menuResponse->addRadialMenuItem(234, 3, "@pet/pet_menu:menu_feed" ); // PET_FEED

		menuResponse->addRadialMenuItem(141, 3, "@pet/pet_menu:menu_command"); // PET_COMMAND

		if( player->hasSkill( "outdoors_creaturehandler_novice" ) ){
			menuResponse->addRadialMenuItemToRadialID(141, 142, 3, "@pet/pet_menu:menu_follow" ); // PET_FOLLOW
			menuResponse->addRadialMenuItemToRadialID(141, 146, 3, "@pet/pet_menu:menu_attack" ); // PET_ATTACK
			menuResponse->addRadialMenuItemToRadialID(141, 164, 3, "@pet/pet_menu:menu_store" );
		}

		if( player->hasSkill( "outdoors_creaturehandler_training_01" ) ){
			menuResponse->addRadialMenuItemToRadialID(141, 143, 3, "@pet/pet_menu:menu_stay" ); // PET_STAY
		}

		if( player->hasSkill( "outdoors_creaturehandler_training_02" ) ){
			menuResponse->addRadialMenuItemToRadialID(141, 144, 3, "@pet/pet_menu:menu_guard" ); // PET_GUARD
		}

		if( player->hasSkill( "outdoors_creaturehandler_training_03" ) ){
			menuResponse->addRadialMenuItemToRadialID(141, 147, 3, "@pet/pet_menu:menu_patrol" ); // PET_PATROL
			menuResponse->addRadialMenuItemToRadialID(141, 148, 3, "@pet/pet_menu:menu_get_patrol_point" ); // PET_GET_PATROL_POINT
			menuResponse->addRadialMenuItemToRadialID(141, 149, 3, "@pet/pet_menu:menu_clear_patrol_points" ); // PET_CLEAR_PATROL_POINTS
		}

		if( player->hasSkill( "outdoors_creaturehandler_training_04" ) ){
			menuResponse->addRadialMenuItemToRadialID(141, 150, 3, "@pet/pet_menu:menu_assume_formation_1" ); // PET_ASSUME_FORMATION_1
			menuResponse->addRadialMenuItemToRadialID(141, 151, 3, "@pet/pet_menu:menu_assume_formation_2" ); // PET_ASSUME_FORMATION_2
		}

		if( player->hasSkill( "outdoors_creaturehandler_healing_01" ) ){
			menuResponse->addRadialMenuItemToRadialID(141, 154, 3, "@pet/pet_menu:menu_trick_1" ); // PET_TRICK_1
		}

		if( player->hasSkill( "outdoors_creaturehandler_healing_03" ) ){
			menuResponse->addRadialMenuItemToRadialID(141, 155, 3, "@pet/pet_menu:menu_trick_2" ); // PET_TRICK_2
		}

		if( player->hasSkill( "outdoors_creaturehandler_support_01" ) ){
			menuResponse->addRadialMenuItemToRadialID(141, 158, 3, "@pet/pet_menu:menu_group" ); // PET_GROUP
		}

		if( player->hasSkill( "outdoors_creaturehandler_support_02" ) ){
			menuResponse->addRadialMenuItemToRadialID(141, 165, 3, "@pet/pet_menu:menu_follow_other" );
		}

		if( player->hasSkill( "outdoors_creaturehandler_support_03" ) ){
			menuResponse->addRadialMenuItemToRadialID(141, 145, 3, "@pet/pet_menu:menu_friend" ); // PET_FRIEND
		}

		if( player->hasSkill( "outdoors_creaturehandler_taming_03" ) && pet->hasSpecialAttack(1) ){
			menuResponse->addRadialMenuItemToRadialID(141, 161, 3, "@pet/pet_menu:menu_specialattack_one" ); // PET_SPECIAL_ATTACK_ONE
		}

		if( player->hasSkill( "outdoors_creaturehandler_taming_04" ) && pet->hasSpecialAttack(2) ){
			menuResponse->addRadialMenuItemToRadialID(141, 162, 3, "@pet/pet_menu:menu_specialattack_two" ); // PET_SPECIAL_ATTACK_TWO
		}

		if( player->hasSkill( "outdoors_creaturehandler_master" ) ){
			if (pet->hasRangedWeapon()) {
				menuResponse->addRadialMenuItemToRadialID(141, 163, 3, "@pet/pet_menu:menu_ranged_attack" );
			}

			menuResponse->addRadialMenuItemToRadialID(141, 152, 3, "@pet/pet_menu:menu_transfer" ); // PET_TRANSFER
		}

		if( player->hasSkill( "outdoors_creaturehandler_support_04") && !controlDevice->isTrainedAsMount() && petManager->checkMountEligibility(controlDevice) == PetManager::CANBEMOUNTTRAINED){
			menuResponse->addRadialMenuItemToRadialID(141, 207, 3, "@pet/pet_menu:menu_train_mount" ); // Train Pet As A Mount
		}

		if( pet->isIncapacitated() ){
			menuResponse->addRadialMenuItem(166, 3, "@pet/pet_menu:awaken" );
		}

		if (controlDevice->isTrainedAsMount() && !pet->isDead() && !pet->isIncapacitated()) {
			Reference<SceneObject*> rider = pet->getSlottedObject("rider");

			if (rider == NULL) {
				menuResponse->addRadialMenuItem(205, 3, "@pet/pet_menu:menu_mount"); // Climb Aboard Pet
			} else {
				menuResponse->addRadialMenuItem(206, 3, "@pet/pet_menu:menu_dismount"); // Climb Off Of Pet
			}
		}

	}

}
void ChatManagerImplementation::broadcastMessage(CreatureObject* player, const UnicodeString& message,  uint64 target, uint32 moodid, uint32 mood2) {
	Zone* zone = player->getZone();
	PlayerObject* myGhost = NULL;
	bool godMode = false;

	if (zone == NULL)
		return;

	int language = 0;
	String firstName;

	if (player->isPlayerCreature() /*|| !((Player *)player)->isChatMuted() */) {
		CreatureObject* playerCreature = cast<CreatureObject*>(player);
		if (playerCreature)
		{
			firstName = playerCreature->getFirstName().toLowerCase();
			myGhost = playerCreature->getPlayerObject();
		}

		if (myGhost)
			language = myGhost->getLanguageID();
	}

	if (myGhost)
	{
		if (myGhost->hasGodMode())
			godMode = true;
	}

	StringIdChatParameter* param = NULL;

	if (message[0] == '@' && message.indexOf(":") != -1) {
		param = new StringIdChatParameter(message.toString());
	}

	CloseObjectsVector* closeObjects = (CloseObjectsVector*) player->getCloseObjects();

	SortedVector<QuadTreeEntry*> closeEntryObjects(200, 50);

	if (closeObjects != NULL) {
		closeObjects->safeCopyTo(closeEntryObjects);
	} else {
		player->info("Null closeobjects vector in ChatManager::broadcastMessage", true);
		zone->getInRangeObjects(player->getWorldPositionX(), player->getWorldPositionY(), 128, &closeEntryObjects, true);
	}

	float range = defaultSpatialChatDistance;

	float specialRange = spatialChatDistances.get(mood2);
	if (specialRange != -1) {
		range = specialRange;
	}

	try {
		for (int i = 0; i < closeEntryObjects.size(); ++i) {
			SceneObject* object = cast<SceneObject*>(closeEntryObjects.get(i));

			if (player->isInRange(object, range)) {

				//Notify observers that are expecting spatial chat.
				if (object->getObserverCount(ObserverEventType::SPATIALCHATRECEIVED)) {
					ManagedReference<ChatMessage*> chatMessage = new ChatMessage();
					chatMessage->setString(message.toString());

					EXECUTE_TASK_3(object, chatMessage, player, {
						if (player_p == NULL || object_p == NULL)
							return;

						Locker locker(object_p);

						SortedVector<ManagedReference<Observer*> > observers = object_p->getObservers(ObserverEventType::SPATIALCHATRECEIVED);
						for (int oc = 0; oc < observers.size(); oc++) {
							Observer* observer = observers.get(oc);
							Locker clocker(observer, object_p);
							if (observer->notifyObserverEvent(ObserverEventType::SPATIALCHATRECEIVED, object_p, chatMessage_p, player_p->getObjectID()) == 1)
								object_p->dropObserver(ObserverEventType::SPATIALCHATRECEIVED, observer);
						}
					});
				}

				if (object->isPlayerCreature()) {
					CreatureObject* creature = cast<CreatureObject*>(object);
					PlayerObject* ghost = creature->getPlayerObject();

					if (ghost == NULL)
						continue;

					if (!ghost->isIgnoring(firstName) || godMode) {
						SpatialChat* cmsg = NULL;

						if (param == NULL) {
							cmsg = new SpatialChat(player->getObjectID(), creature->getObjectID(), message, target, moodid, mood2, language);
						} else {
							cmsg = new SpatialChat(player->getObjectID(), creature->getObjectID(), *param, target, moodid, mood2);
						}

						creature->sendMessage(cmsg);
					}
				}
				else if( object->isPet() ){
					AiAgent* pet = cast<AiAgent*>(object);

					if (pet == NULL )
						continue;

					if( pet->isDead() || pet->isIncapacitated() )
						continue;

					PetManager* petManager = server->getPetManager();
					Locker clocker(pet, player);
					petManager->handleChat( player, pet, message.toString() );

				}
			}
		}
bool PetControlDeviceImplementation::growPet(CreatureObject* player, bool force, bool adult) {
	if (petType != PetManager::CREATUREPET)
		return true;

	if (growthStage <= 0 || growthStage >= 10)
		return true;

	ManagedReference<TangibleObject*> controlledObject = this->controlledObject.get();

	if (controlledObject == NULL || !controlledObject->isCreature())
		return true;
	ManagedReference<Creature*> pet = cast<Creature*>(controlledObject.get());

	ManagedReference<CreatureTemplate*> creatureTemplate = pet->getCreatureTemplate();

	if (creatureTemplate == NULL)
		return true;

	PetManager* petManager = pet->getZoneServer()->getPetManager();
	if (petManager == NULL)
		return true;

	Time currentTime;
	uint32 timeDelta = currentTime.getTime() - lastGrowth.getTime();
	int stagesToGrow = timeDelta / 43200; // 12 hour

	if (adult)
		stagesToGrow = 10;

	if (stagesToGrow == 0 && !force)
		return true;

	int newStage = growthStage + stagesToGrow;
	if (newStage > 10)
		newStage = 10;

	float newLevel = ((float)pet->getAdultLevel() / 10.0) * (float)newStage;
	if (newLevel < 1)
		newLevel = 1;

	float newHeight = creatureTemplate->getScale() * (0.46 + ((float)newStage * 0.06));

	short preEligibility = petManager->checkMountEligibility(_this.getReferenceUnsafeStaticCast());
	short postEligibility = petManager->checkMountEligibility(_this.getReferenceUnsafeStaticCast(), newHeight);

	assert(pet->isLockedByCurrentThread());

	if (preEligibility == PetManager::CANBEMOUNTTRAINED && postEligibility == PetManager::TOOLARGE && !force) {
		if (isTrainedAsMount()) {
			arrestGrowth();
			return true;
		}

		PlayerObject* ghost = player->getPlayerObject();

		if (ghost == NULL){
			return true;
		}

		ManagedReference<SuiListBox*> box = new SuiListBox(player, SuiWindowType::MOUNT_GROWTH_ARREST);
		box->setPromptTitle("@pet/pet_menu:mount_growth_title"); // Pet Growth Arrest
		box->setPromptText("@pet/pet_menu:mount_growth_prompt"); // Your pet could be trained as a mount, but is about to grow too large to serve as one. If you ever plan on training this pet as a mount you must arrest it's growth now. Stop pet's growth?
		box->setUsingObject(_this.getReferenceUnsafeStaticCast());
		box->setCancelButton(true, "@cancel");
		box->setOkButton(true, "@yes");
		box->setOtherButton(true, "@no");
		box->setCallback(new MountGrowthArrestSuiCallback(player->getZoneServer(), _this.getReferenceUnsafeStaticCast()));

		ghost->addSuiBox(box);
		player->sendMessage(box->generateMessage());
		return false;
	}

	if (adult)
		pet->setHeight(newHeight, true);
	else
		pet->setHeight(newHeight, false);

	pet->setPetLevel(newLevel);

	growthStage = newStage;
	lastGrowth.updateToCurrentTime();

	setVitality(getVitality());

	return true;
}
Exemplo n.º 11
0
int PetMenuComponent::handleObjectMenuSelect(SceneObject* sceneObject, CreatureObject* player, byte selectedID) {
	if (!sceneObject->isPet())
		return 0;

	AiAgent* pet = cast<AiAgent*>(sceneObject);

	if (!player->getPlayerObject()->isPrivileged() && pet->getLinkedCreature() != player)
		return 0;

	if (pet->getLinkedCreature() != player) {
		player = pet->getLinkedCreature().get();
	}

	ManagedReference<PetControlDevice*> petControlDevice = pet->getControlDevice().get().castTo<PetControlDevice*>();

	if (petControlDevice == NULL || player == NULL)
		return 0;

	PetManager* petManager = pet->getZoneServer()->getPetManager();
	if (petManager == NULL)
		return 0;

	// Store
	if (selectedID == 59) {
		petControlDevice->storeObject(player);
		return 0;
	}

	// Recharge
	if (selectedID == 234 && petControlDevice->getPetType() == PetManager::DROIDPET ){
		petManager->enqueueOwnerOnlyPetCommand(player, pet, String("petRecharge").toLowerCase().hashCode(), "");
	}

	// Feed
	if (selectedID == 234 && petControlDevice->getPetType() == PetManager::CREATUREPET ){
		petManager->enqueueOwnerOnlyPetCommand(player, pet, String("petFeed").toLowerCase().hashCode(), "");
	}

	// Trained Command: Recharge Other
	if (selectedID == 235 ){
		petControlDevice->setTrainingCommand( PetManager::RECHARGEOTHER );
	}

	// Train Command: Follow
	if (selectedID == 142 ){ // PET_FOLLOW
		petControlDevice->setTrainingCommand( PetManager::FOLLOW );
	}

	// Train Command: Stay
	if (selectedID == 143 ){ // PET_STAY
		petControlDevice->setTrainingCommand( PetManager::STAY );
	}

	// Train Command: Guard
	if (selectedID == 144 ){ // PET_GUARD
		petControlDevice->setTrainingCommand( PetManager::GUARD );
	}

	// Train Command: Friend
	if (selectedID == 145 ){ // PET_FRIEND
		petControlDevice->setTrainingCommand( PetManager::FRIEND );
	}

	// Train Command: Attack
	if (selectedID == 146 ){ // PET_ATTACK
		petControlDevice->setTrainingCommand( PetManager::ATTACK );
	}

	// Train Command: Patrol
	if (selectedID == 147 ){ // PET_PATROL
		petControlDevice->setTrainingCommand( PetManager::PATROL );
	}

	// Get Patrol Point
	if (selectedID == 148 ){ // PET_GET_PATROL_POINT
		// TODO Handle setting patrol point
		player->sendSystemMessage("PET_GET_PATROL_POINT pet command is not yet implemented.");
	}

	// Clear Patrol Points
	if (selectedID == 149 ){ // PET_CLEAR_PATROL_POINTS
		// TODO Handle clearing patrol points
		player->sendSystemMessage("PET_CLEAR_PATROL_POINTS pet command is not yet implemented.");
	}

	// Train Command: Wedge Formation
	if (selectedID == 150 ){ // PET_ASSUME_FORMATION_1
		petControlDevice->setTrainingCommand( PetManager::FORMATION1 );
	}

	// Train Command: Column Formation
	if (selectedID == 151 ){ // PET_ASSUME_FORMATION_2
		petControlDevice->setTrainingCommand( PetManager::FORMATION2 );
	}

	// Train Command: Transfer
	if (selectedID == 152 ){ // PET_TRANSFER
		petControlDevice->setTrainingCommand( PetManager::TRANSFER );
	}

	// Train Command: Trick 1
	if (selectedID == 154 ){ // PET_TRICK_1
		petControlDevice->setTrainingCommand( PetManager::TRICK1 );
	}

	// Train Command: Trick 2
	if (selectedID == 155 ){ // PET_TRICK_2
		petControlDevice->setTrainingCommand( PetManager::TRICK2 );
	}

	// Train Command: Group
	if (selectedID == 158 ){ // PET_GROUP
		petControlDevice->setTrainingCommand( PetManager::GROUP );
	}

	// Train Command: Special Attack 1
	if (selectedID == 161 ){ // PET_SPECIAL_ATTACK_ONE
		petControlDevice->setTrainingCommand( PetManager::SPECIAL_ATTACK1 );
	}

	// Train Command: Special Attack 2
	if (selectedID == 162 ){ // PET_SPECIAL_ATTACK_TWO
		petControlDevice->setTrainingCommand( PetManager::SPECIAL_ATTACK2 );
	}

	// Train Command: Ranged Attack
	if (selectedID == 163 ){
		petControlDevice->setTrainingCommand( PetManager::RANGED_ATTACK );
	}

	// Train Command: Store
	if (selectedID == 164 ){
		petControlDevice->setTrainingCommand( PetManager::STORE );
	}

	// Train Command: Follow Other
	if (selectedID == 165 ){
		petControlDevice->setTrainingCommand( PetManager::FOLLOWOTHER );
	}

	if (selectedID == 166 ){
		petManager->enqueueOwnerOnlyPetCommand(player, pet, String("petRecover").toLowerCase().hashCode(), "");
	}

	// Train Pet As A Mount
	if (selectedID == 207 ){
		petControlDevice->trainAsMount(player);
	}

	return TangibleObjectMenuComponent::handleObjectMenuSelect(sceneObject, player, selectedID);
}
Exemplo n.º 12
0
BOOL Obj_Pet::Init( const _OBJ_INIT *pInit )
{
__ENTER_FUNCTION

	BOOL bResult = Obj_Character::Init( pInit );
	if ( !bResult )
		return FALSE;

	const _OBJ_PET_INIT *pPetInit  = NULL;
	pPetInit = (const _OBJ_PET_INIT*)pInit;
	if ( pPetInit == NULL )
	{
		Assert( FALSE &&  "Error Obj_Pet::Init, pPetInit = NULL" );
		return FALSE;
	}

	m_GUID				= pPetInit->m_GUID;
	m_CreatorID			= pPetInit->m_CreatorID;
	m_pCreator			= NULL;
	m_nIndex			= pPetInit->m_nIndex;
	m_iLevel			= pPetInit->m_PetDB.m_nLevel;
	if ( m_CreatorID != INVALID_ID )
	{
		Obj_Character *pCreator	= (Obj_Character*)(getScene()->GetObjManager()->GetObj(m_CreatorID) );
		if (pCreator != NULL && pCreator->GetObjType() == OBJ_TYPE_HUMAN)
			m_pCreator = (Obj_Human*)pCreator;
	}

	if ( m_pCreator == NULL )
	{
		m_PetDB = pPetInit->m_PetDB;
		return FALSE;
	}

	m_PetDB.m_nDataID	= pPetInit->m_PetDB.m_nDataID;
	m_RespawnTime		= pPetInit->m_RespawnTime;

	m_RespawnPos		= pPetInit->m_Pos;
	m_OwnerID			= pPetInit->m_CreatorID;

	m_HappinessTimer.BeginTimer( g_Config.m_ConfigInfo.m_PetHappinessInterval, g_pTimeManager->CurrentTime() );
	SetDataID( m_pCreator->GetMonsterPetDataID() );

	MONSTER_EXT_ATTR *pPetAttr = g_MonsterAttrExTbl.GetExtAttr( GetDataID() );
	if(pPetAttr)
	{
		m_iLevel = pPetAttr->m_Level;
	}
	else
	{
		m_iLevel = 0;
	}

	PetManager* pPetManager = getScene()->GetPetManager();
	if(pPetManager)
	{
		m_oInit = pPetManager->GetInitData();
	}
		
	//初始化技能相关内容
	InitLife();


	SetHP( GetMaxHP() );

	// 使AI进入IDLE状态
	GetAIObj()->ChangeState(ESTATE_IDLE);

    InitBackupAttr();
	//附加效果数据
	Impact_InitList();

	return TRUE;

	__LEAVE_FUNCTION

	return FALSE;
}