Instructions Jenkins Doxygen

[Added] transfer command for creature pets 63/1263/5
authorIvojedi <ivojedi@swgemu.com>
Wed, 18 Dec 2013 16:14:56 +0000 (08:14 -0800)
committerVictor Popovici <victorpopovici@gmail.com>
Thu, 19 Dec 2013 12:14:23 +0000 (13:14 +0100)
[Added] generic methods for enqueueing pet commands

Change-Id: Iff3d28f8ba9b4f83a2576700840d50da8a817175

MMOCoreORB/src/server/zone/managers/objectcontroller/command/CommandConfigManager.cpp
MMOCoreORB/src/server/zone/objects/creature/commands/pet/PetTransferCommand.h [new file with mode: 0644]
MMOCoreORB/src/server/zone/objects/creature/components/PetMenuComponent.cpp
MMOCoreORB/src/server/zone/objects/intangible/PetControlDevice.idl
MMOCoreORB/src/server/zone/objects/intangible/PetControlDeviceImplementation.cpp

index c55f55c..e8c061c 100644 (file)
@@ -49,6 +49,7 @@ which carries forward this exception.
 #include "server/zone/objects/creature/commands/effect/CommandEffect.h"
 
 #include "server/zone/objects/creature/commands/pet/PetTrickCommand.h"
+#include "server/zone/objects/creature/commands/pet/PetTransferCommand.h"
 
 #include "server/zone/objects/creature/CreatureState.h"
 #include "server/zone/objects/creature/CreaturePosture.h"
@@ -339,6 +340,7 @@ void CommandConfigManager::registerSpecialCommands(CommandList* sCommands) {
        createCommand(String("defaultDroidAttack").toLowerCase())->setCommandGroup(0xe1c9a54a);
 
        //Pet commands
+       createCommand(String("petTransfer").toLowerCase())->setCommandGroup(0xe1c9a54a);
        createCommand(String("petTrick").toLowerCase())->setCommandGroup(0xe1c9a54a);
 }
 
@@ -1495,5 +1497,6 @@ void CommandConfigManager::registerCommands() {
        commandFactory.registerCommand<RequestSpaceTrainerCommand>(String("requestSpaceTrainer").toLowerCase());
 
        //pet commands
+       commandFactory.registerCommand<PetTransferCommand>(String("petTransfer").toLowerCase());
        commandFactory.registerCommand<PetTrickCommand>(String("petTrick").toLowerCase());
 }
diff --git a/MMOCoreORB/src/server/zone/objects/creature/commands/pet/PetTransferCommand.h b/MMOCoreORB/src/server/zone/objects/creature/commands/pet/PetTransferCommand.h
new file mode 100644 (file)
index 0000000..3a496e7
--- /dev/null
@@ -0,0 +1,128 @@
+
+#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() != PetControlDevice::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;
+
+               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() == PetControlDevice::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")) {
+                       player->sendSystemMessage("@pet/pet_menu:no_chance"); // That person has no chance of controlling this creature. Transfer failed.
+                       return GENERALERROR;
+               }
+
+               ManagedReference<SceneObject*> targetDatapad = targetPlayer->getSlottedObject("datapad");
+
+               if (targetDatapad == NULL)
+                       return GENERALERROR;
+
+               pet->setCreatureLink(targetPlayer);
+               pet->setFaction(targetPlayer->getFaction());
+               pet->setFollowObject(targetPlayer);
+
+               if (targetPlayer->getPvpStatusBitmask() & CreatureFlag::PLAYER)
+                       pet->setPvpStatusBitmask(targetPlayer->getPvpStatusBitmask() - CreatureFlag::PLAYER, true);
+               else
+                       pet->setPvpStatusBitmask(targetPlayer->getPvpStatusBitmask(), true);
+
+               targetDatapad->transferObject(controlDevice, -1);
+               targetGhost->addToActivePets(pet);
+               targetDatapad->broadcastObject(controlDevice, true);
+
+               player->sendSystemMessage("@pet/pet_menu:pet_transfer_succeed"); // The pet has been successfully transferred
+
+               targetCrosslocker.release();
+
+               Locker clocker(player, pet);
+
+               ghost->removeFromActivePets(pet);
+
+               return SUCCESS;
+       }
+
+};
+
+
+#endif /* PETTRANSFERCOMMAND_H_ */
index b378fba..3643527 100644 (file)
@@ -147,6 +147,7 @@ void PetMenuComponent::fillObjectMenuResponse(SceneObject* sceneObject, ObjectMe
 
                if( player->hasSkill( "outdoors_creaturehandler_master" ) ){
                        menuResponse->addRadialMenuItemToRadialID(141, 163, 3, "@pet/pet_menu:menu_ranged_attack" );
+                       menuResponse->addRadialMenuItemToRadialID(141, 152, 3, "@pet/pet_menu:menu_transfer" ); // PET_TRANSFER
                }
 
        }
@@ -238,6 +239,11 @@ int PetMenuComponent::handleObjectMenuSelect(SceneObject* sceneObject, CreatureO
                petControlDevice->setTrainingCommand( PetControlDevice::FORMATION2 );
        }
 
+       // Train Command: Transfer
+       if (selectedID == 152 ){ // PET_TRANSFER
+               petControlDevice->setTrainingCommand( PetControlDevice::TRANSFER );
+       }
+
        // Train Command: Trick 1
        if (selectedID == 154 ){ // PET_TRICK_1
                petControlDevice->setTrainingCommand( PetControlDevice::TRICK1 );
index 82227f7..6d237c6 100644 (file)
@@ -90,6 +90,7 @@ class PetControlDevice extends ControlDevice {
        public static final unsigned int GROUP = 15;
        public static final unsigned int STAY = 16;
        public static final unsigned int RECHARGEOTHER = 17;
+       public static final unsigned int TRANSFER = 18;
        
        // Trained command strings <commandid, chatstring>
        @dereferenced 
@@ -257,13 +258,26 @@ class PetControlDevice extends ControlDevice {
        public native void rechargeOther(CreatureObject player);
        
        /**
-        * Performs a trick and heals mind
+        * Enqueues a pet command
         * @pre { }
         * @post { }
         * @param object player creature commanding
+        * @param unsigned long command CRC
+        * @param const string arguments
         */
        @local
-       public native void trick(CreatureObject player, int trickNumber);
+       public native void enqueuePetCommand(CreatureObject player, unsigned int command, final string args);
+
+       /**
+        * Enqueues a pet command, player must be the pet's owner
+        * @pre { }
+        * @post { }
+        * @param object player creature commanding
+        * @param unsigned long command CRC
+        * @param const string arguments
+        */
+       @local
+       public native void enqueueOwnerOnlyPetCommand(CreatureObject player, unsigned int command, final string args);
 
        /**
         * Sets default trained commands and command strings for the pet
index f4b86ee..8cf3e00 100644 (file)
@@ -457,11 +457,13 @@ bool PetControlDeviceImplementation::canBeTradedTo(CreatureObject* player, Creat
 
                if (level > maxLevelofPets) {
                        player->sendSystemMessage("@pet/pet_menu:no_chance"); // That person has no chance of controlling this creature. Transfer failed.
+                       receiver->sendSystemMessage("@pet/pet_menu:cannot_control"); // You have no chance of controlling that creature.
                        return false;
                }
 
                if (pet->isAggressiveTo(receiver) && (receiver->getSkillMod("tame_aggro") <= 0 || !ch)) {
                        player->sendSystemMessage("@pet/pet_menu:no_chance"); // That person has no chance of controlling this creature. Transfer failed.
+                       receiver->sendSystemMessage("@pet/pet_menu:cannot_control"); // You have no chance of controlling that creature.
                        return false;
                }
 
@@ -671,6 +673,9 @@ void PetControlDeviceImplementation::fillAttributeList(AttributeListMessage* alm
                alm->insertAttribute("@pet/pet_menu:menu_recharge_other", trainedCommands.get(RECHARGEOTHER) );
        }
 
+       if( trainedCommands.contains(TRANSFER) ){
+               alm->insertAttribute("pet_command_10", trainedCommands.get(TRANSFER) );
+       }
 }
 
 void PetControlDeviceImplementation::handleChat(CreatureObject* speaker, const String& message){
@@ -728,10 +733,10 @@ void PetControlDeviceImplementation::handleChat(CreatureObject* speaker, const S
                followOther(speaker);
        }
        else if( trainedCommands.contains(TRICK1) && trainedCommands.get(TRICK1) == message ){
-               trick(speaker, 1);
+               enqueuePetCommand(speaker, String("petTrick").toLowerCase().hashCode(), "1");
        }
        else if( trainedCommands.contains(TRICK2) && trainedCommands.get(TRICK2) == message ){
-               trick(speaker, 2);
+               enqueuePetCommand(speaker, String("petTrick").toLowerCase().hashCode(), "2");
        }
        else if( trainedCommands.contains(PATROL) && trainedCommands.get(PATROL) == message ){
                speaker->sendSystemMessage("PATROL pet command is not yet implemented.");
@@ -757,6 +762,9 @@ void PetControlDeviceImplementation::handleChat(CreatureObject* speaker, const S
        else if( trainedCommands.contains(RECHARGEOTHER) && trainedCommands.get(RECHARGEOTHER) == message ){
                rechargeOther(speaker);
        }
+       else if( trainedCommands.contains(TRANSFER) && trainedCommands.get(TRANSFER) == message ){
+               enqueueOwnerOnlyPetCommand(speaker, String("petTransfer").toLowerCase().hashCode(), "");
+       }
 
 }
 
@@ -1076,12 +1084,23 @@ void PetControlDeviceImplementation::rechargeOther(CreatureObject* player){
 
 }
 
-void PetControlDeviceImplementation::trick(CreatureObject* player, int trickNumber){
+void PetControlDeviceImplementation::enqueuePetCommand(CreatureObject* player, uint32 command, const String& args){
+
+       ManagedReference<TangibleObject*> controlledObject = this->controlledObject.get();
+       if (controlledObject == NULL || !controlledObject->isAiAgent())
+               return;
 
-       // Creature specific command
-       if( petType != CREATUREPET )
+       ManagedReference<AiAgent*> pet = cast<AiAgent*>(controlledObject.get());
+       if( pet == NULL )
                return;
 
+       //CreatureObject* pet, uint32 command, const String& args, uint64 target, int priority = -1
+       EnqueuePetCommand* enqueueCommand = new EnqueuePetCommand(pet, command, args, player->getTargetID());
+       enqueueCommand->execute();
+}
+
+void PetControlDeviceImplementation::enqueueOwnerOnlyPetCommand(CreatureObject* player, uint32 command, const String& args){
+
        ManagedReference<TangibleObject*> controlledObject = this->controlledObject.get();
        if (controlledObject == NULL || !controlledObject->isAiAgent())
                return;
@@ -1090,7 +1109,16 @@ void PetControlDeviceImplementation::trick(CreatureObject* player, int trickNumb
        if( pet == NULL )
                return;
 
+       ManagedReference< CreatureObject*> linkedCreature = pet->getLinkedCreature().get();
+       if( linkedCreature == NULL )
+               return;
+
+       // Player must be pet's owner
+       if( linkedCreature != player)
+               return;
+
        //CreatureObject* pet, uint32 command, const String& args, uint64 target, int priority = -1
-       EnqueuePetCommand* enqueueCommand = new EnqueuePetCommand(pet, String("petTrick").hashCode(), String::valueOf(trickNumber), player->getTargetID());
+       EnqueuePetCommand* enqueueCommand = new EnqueuePetCommand(pet, command, args, player->getTargetID());
        enqueueCommand->execute();
+
 }