Instructions Jenkins Doxygen

[Added] PetFollowCommand and PetStoreCommand classes 82/1282/2
authorIvojedi <ivojedi@swgemu.com>
Thu, 19 Dec 2013 21:34:36 +0000 (13:34 -0800)
committerIvojedi <ivojedi@swgemu.com>
Thu, 19 Dec 2013 22:32:35 +0000 (14:32 -0800)
[Moved] follow, follow other, and store pet commands to use creo queue
command framework
[Fixed] chat from other players will no longer interrupt pet training

Change-Id: I983b9909c5ab63a39df3e0e2fb7a427a7b7fa6b0

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

index 7da8196..cb1c0df 100644 (file)
@@ -48,9 +48,11 @@ which carries forward this exception.
 #include "server/zone/objects/creature/commands/effect/DotEffect.h"
 #include "server/zone/objects/creature/commands/effect/CommandEffect.h"
 
+#include "server/zone/objects/creature/commands/pet/PetFollowCommand.h"
 #include "server/zone/objects/creature/commands/pet/PetGroupCommand.h"
 #include "server/zone/objects/creature/commands/pet/PetRechargeOtherCommand.h"
 #include "server/zone/objects/creature/commands/pet/PetStayCommand.h"
+#include "server/zone/objects/creature/commands/pet/PetStoreCommand.h"
 #include "server/zone/objects/creature/commands/pet/PetTrickCommand.h"
 #include "server/zone/objects/creature/commands/pet/PetTransferCommand.h"
 
@@ -343,9 +345,11 @@ void CommandConfigManager::registerSpecialCommands(CommandList* sCommands) {
        createCommand(String("defaultDroidAttack").toLowerCase())->setCommandGroup(0xe1c9a54a);
 
        //Pet commands
+       createCommand(String("petFollow").toLowerCase())->setCommandGroup(0xe1c9a54a);
        createCommand(String("petGroup").toLowerCase())->setCommandGroup(0xe1c9a54a);
        createCommand(String("petRechargeOther").toLowerCase())->setCommandGroup(0xe1c9a54a);
        createCommand(String("petStay").toLowerCase())->setCommandGroup(0xe1c9a54a);
+       createCommand(String("petStore").toLowerCase())->setCommandGroup(0xe1c9a54a);
        createCommand(String("petTransfer").toLowerCase())->setCommandGroup(0xe1c9a54a);
        createCommand(String("petTrick").toLowerCase())->setCommandGroup(0xe1c9a54a);
 }
@@ -1503,9 +1507,11 @@ void CommandConfigManager::registerCommands() {
        commandFactory.registerCommand<RequestSpaceTrainerCommand>(String("requestSpaceTrainer").toLowerCase());
 
        //pet commands
+       commandFactory.registerCommand<PetFollowCommand>(String("petFollow").toLowerCase());
        commandFactory.registerCommand<PetGroupCommand>(String("petGroup").toLowerCase());
        commandFactory.registerCommand<PetRechargeOtherCommand>(String("petRechargeOther").toLowerCase());
        commandFactory.registerCommand<PetStayCommand>(String("petStay").toLowerCase());
+       commandFactory.registerCommand<PetStoreCommand>(String("petStore").toLowerCase());
        commandFactory.registerCommand<PetTransferCommand>(String("petTransfer").toLowerCase());
        commandFactory.registerCommand<PetTrickCommand>(String("petTrick").toLowerCase());
 }
diff --git a/MMOCoreORB/src/server/zone/objects/creature/commands/pet/PetFollowCommand.h b/MMOCoreORB/src/server/zone/objects/creature/commands/pet/PetFollowCommand.h
new file mode 100644 (file)
index 0000000..0925e6d
--- /dev/null
@@ -0,0 +1,52 @@
+
+#ifndef PETFOLLOWCOMMAND_H_
+#define PETFOLLOWCOMMAND_H_
+
+#include "server/zone/objects/creature/commands/QueueCommand.h"
+#include "server/zone/objects/creature/AiAgent.h"
+#include "server/zone/objects/creature/DroidObject.h"
+
+class PetFollowCommand : public QueueCommand {
+public:
+       PetFollowCommand(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;
+
+               ManagedReference<AiAgent*> pet = cast<AiAgent*>(creature);
+               if( pet == NULL )
+                       return GENERALERROR;
+
+               ManagedReference<SceneObject*> targetObject = server->getZoneServer()->getObject(target, true);
+               if (targetObject == NULL || !targetObject->isPlayerCreature() ) {
+                       pet->showFlyText("npc_reaction/flytext","confused", 204, 0, 0);  // "?!!?!?!"
+                       return GENERALERROR;
+               }
+
+               // Check if droid has power
+               if( controlDevice->getPetType() == PetControlDevice::DROIDPET ){
+                       ManagedReference<DroidObject*> droidPet = cast<DroidObject*>(pet.get());
+                       if( droidPet == NULL )
+                               return GENERALERROR;
+
+                       if( !droidPet->hasPower() ){
+                               pet->showFlyText("npc_reaction/flytext","low_power", 204, 0, 0);  // "*Low Power*"
+                               return GENERALERROR;
+                       }
+               }
+
+               pet->setFollowObject(targetObject);
+
+               return SUCCESS;
+       }
+
+};
+
+
+#endif /* PETFOLLOWCOMMAND_H_ */
diff --git a/MMOCoreORB/src/server/zone/objects/creature/commands/pet/PetStoreCommand.h b/MMOCoreORB/src/server/zone/objects/creature/commands/pet/PetStoreCommand.h
new file mode 100644 (file)
index 0000000..856eea7
--- /dev/null
@@ -0,0 +1,40 @@
+
+#ifndef PETSTORECOMMAND_H_
+#define PETSTORECOMMAND_H_
+
+#include "server/zone/objects/creature/commands/QueueCommand.h"
+#include "server/zone/objects/creature/AiAgent.h"
+
+class PetStoreCommand : public QueueCommand {
+public:
+       PetStoreCommand(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;
+
+               ManagedReference<AiAgent*> pet = cast<AiAgent*>(creature);
+               if( pet == NULL )
+                       return GENERALERROR;
+
+               ManagedReference<CreatureObject*> player = pet->getLinkedCreature().get();
+               if (player == NULL || !player->isPlayerCreature() ) {
+                       return GENERALERROR;
+               }
+
+               Locker clocker(player, pet);
+
+               controlDevice->storeObject(player);
+
+               return SUCCESS;
+       }
+
+};
+
+
+#endif /* PETSTORECOMMAND_H_ */
index 5327f02..dc2e208 100644 (file)
@@ -211,24 +211,6 @@ class PetControlDevice extends ControlDevice {
         */
        @local
        public native void handleChat(CreatureObject speaker, final string message);
-       
-       /**
-        * Handles follow command
-        * @pre { }
-        * @post { }
-        * @param object player creature commanding
-        */
-       @local
-       public native void follow(CreatureObject player);
-       
-       /**
-        * Handles followother command
-        * @pre { }
-        * @post { }
-        * @param object player creature commanding
-        */
-       @local
-       public native void followOther(CreatureObject player);  
 
        /**
         * Enqueues a pet command
@@ -237,9 +219,10 @@ class PetControlDevice extends ControlDevice {
         * @param object player creature commanding
         * @param unsigned long command CRC
         * @param const string arguments
+        * @param boolean if true, uses player as target, if false uses player's target
         */
        @local
-       public native void enqueuePetCommand(CreatureObject player, unsigned int command, final string args);
+       public native void enqueuePetCommand(CreatureObject player, unsigned int command, final string args, boolean selfTarget = false);
 
        /**
         * Enqueues a pet command, player must be the pet's owner
@@ -274,9 +257,10 @@ class PetControlDevice extends ControlDevice {
         * @post { }
         * @param object player creature speaking
         * @param string chat message
+        * @return returns true if chat came from pet's owner
         */
        @local
-       protected native void handleCommandTraining(CreatureObject speaker, final string message);
+       protected native boolean handleCommandTraining(CreatureObject speaker, final string message);
        
        public boolean isPetControlDevice() {
                return true;
index 785c484..38bc993 100644 (file)
@@ -682,8 +682,10 @@ void PetControlDeviceImplementation::handleChat(CreatureObject* speaker, const S
 
        // Handle command training
        if( trainingCommand > 0 ){
-               handleCommandTraining( speaker, message );
-               trainingCommand = 0; // no longer training
+               bool ownerChat = handleCommandTraining( speaker, message );
+               if (ownerChat)
+                       trainingCommand = 0; // no longer training
+
                return;
        }
 
@@ -715,10 +717,10 @@ void PetControlDeviceImplementation::handleChat(CreatureObject* speaker, const S
                enqueuePetCommand(speaker, String("petStay").toLowerCase().hashCode(), "");
        }
        else if( trainedCommands.contains(FOLLOW) && trainedCommands.get(FOLLOW) == message ){
-               follow( speaker );
+               enqueuePetCommand(speaker, String("petFollow").toLowerCase().hashCode(), "", true);
        }
        else if( trainedCommands.contains(STORE) && trainedCommands.get(STORE) == message ){
-               storeObject( linkedCreature.get() ); // storeObject expects pet owner to be passed
+               enqueueOwnerOnlyPetCommand(speaker, String("petStore").toLowerCase().hashCode(), "");
        }
        else if( trainedCommands.contains(ATTACK) && trainedCommands.get(ATTACK) == message ){
                speaker->sendSystemMessage("ATTACK pet command is not yet implemented.");
@@ -730,7 +732,7 @@ void PetControlDeviceImplementation::handleChat(CreatureObject* speaker, const S
                speaker->sendSystemMessage("FRIEND pet command is not yet implemented.");
        }
        else if( trainedCommands.contains(FOLLOWOTHER) && trainedCommands.get(FOLLOWOTHER) == message ){
-               followOther(speaker);
+               enqueuePetCommand(speaker, String("petFollow").toLowerCase().hashCode(), "");
        }
        else if( trainedCommands.contains(TRICK1) && trainedCommands.get(TRICK1) == message ){
                enqueuePetCommand(speaker, String("petTrick").toLowerCase().hashCode(), "1");
@@ -768,35 +770,35 @@ void PetControlDeviceImplementation::handleChat(CreatureObject* speaker, const S
 
 }
 
-void PetControlDeviceImplementation::handleCommandTraining(CreatureObject* speaker, const String& message){
+bool PetControlDeviceImplementation::handleCommandTraining(CreatureObject* speaker, const String& message){
 
        if( speaker == NULL )
-               return;
+               return false;
 
        if( message.isEmpty() )
-               return;
+               return false;
 
        ManagedReference<TangibleObject*> controlledObject = this->controlledObject.get();
        if (controlledObject == NULL || !controlledObject->isAiAgent())
-               return;
+               return false;
 
        ManagedReference<AiAgent*> pet = cast<AiAgent*>(controlledObject.get());
        if( pet == NULL )
-               return;
+               return false;
 
        ManagedWeakReference< CreatureObject*> linkedCreature = pet->getLinkedCreature();
        if( linkedCreature == NULL )
-               return;
+               return false;
 
        // Only owner may train
        if( linkedCreature != speaker)
-               return;
+               return false;
 
        // Check if command string already exists
        for( int i = 0; i < trainedCommands.size(); i++ ){
                if( trainedCommands.get(i) == message ){
                        pet->showFlyText("npc_reaction/flytext","confused", 204, 0, 0);  // "?!!?!?!"
-                       return;
+                       return true;
                }
        }
 
@@ -816,7 +818,7 @@ void PetControlDeviceImplementation::handleCommandTraining(CreatureObject* speak
                        if (!success) {
                                pet->showFlyText("npc_reaction/flytext","confused", 204, 0, 0);  // "?!!?!?!"
                                speaker->sendSystemMessage("@pet/pet_menu:pet_nolearn"); // Your pet doesn't seem to understand you.
-                               return;
+                               return true;
                        }
                }
 
@@ -829,7 +831,7 @@ void PetControlDeviceImplementation::handleCommandTraining(CreatureObject* speak
                        CreatureTemplate* creatureTemplate = pet->getCreatureTemplate();
 
                        if (creatureTemplate == NULL)
-                               return;
+                               return true;
 
                        ZoneServer* zoneServer = speaker->getZoneServer();
                        PlayerManager* playerManager = zoneServer->getPlayerManager();
@@ -844,7 +846,7 @@ void PetControlDeviceImplementation::handleCommandTraining(CreatureObject* speak
 
        // No renaming of faction pets
        if (petType == FACTIONPET)
-               return;
+               return true;
 
        // Check for naming string
        StringTokenizer tokenizer(message);
@@ -867,7 +869,7 @@ void PetControlDeviceImplementation::handleCommandTraining(CreatureObject* speak
                NameManager* nameManager = zps->getNameManager();
 
                if (nameManager->validateName(parsedName, -1) != NameManagerResult::ACCEPTED) {
-                       return;
+                       return true;
                }
 
                if (futureName == parsedName)
@@ -875,12 +877,12 @@ void PetControlDeviceImplementation::handleCommandTraining(CreatureObject* speak
                else {
                        namingProgress = 1;
                        futureName = parsedName;
-                       return;
+                       return true;
                }
        } else {
                namingProgress = 0;
                futureName = "";
-               return;
+               return true;
        }
 
        // Set name, if applicable
@@ -890,6 +892,7 @@ void PetControlDeviceImplementation::handleCommandTraining(CreatureObject* speak
                pet->setCustomObjectName(newName, true);
        }
 
+       return true;
 }
 
 void PetControlDeviceImplementation::setDefaultCommands(){
@@ -936,71 +939,7 @@ void PetControlDeviceImplementation::setTrainingCommand( unsigned int commandID
 
 }
 
-void PetControlDeviceImplementation::follow(CreatureObject* player){
-
-       ManagedReference<TangibleObject*> controlledObject = this->controlledObject.get();
-       if (controlledObject == NULL || !controlledObject->isAiAgent())
-               return;
-
-       AiAgent* pet = cast<AiAgent*>(controlledObject.get());
-       if( pet == NULL )
-               return;
-
-       // Check if droid has power
-       if( petType == DROIDPET ){
-               DroidObject* droidPet = cast<DroidObject*>(pet);
-               if( droidPet == NULL )
-                       return;
-
-               if( !droidPet->hasPower() ){
-                       pet->showFlyText("npc_reaction/flytext","low_power", 204, 0, 0);  // "*Low Power*"
-                       return;
-               }
-       }
-
-       pet->setFollowObject(player);
-
-}
-
-void PetControlDeviceImplementation::followOther(CreatureObject* player){
-
-       ManagedReference<TangibleObject*> controlledObject = this->controlledObject.get();
-       if (controlledObject == NULL || !controlledObject->isAiAgent())
-               return;
-
-       AiAgent* pet = cast<AiAgent*>(controlledObject.get());
-       if( pet == NULL )
-               return;
-
-       uint64 targetID = player->getTargetID();
-       ZoneServer* server = player->getZoneServer();
-       if (server == NULL)
-               return;
-
-       // Target must be a player
-       Reference<SceneObject*> target = server->getObject(targetID, true).castTo<SceneObject*>();
-       if (target == NULL || !target->isPlayerCreature() ) {
-               pet->showFlyText("npc_reaction/flytext","confused", 204, 0, 0);  // "?!!?!?!"
-               return;
-       }
-
-       // Check if droid has power
-       if( petType == DROIDPET ){
-               DroidObject* droidPet = cast<DroidObject*>(pet);
-               if( droidPet == NULL )
-                       return;
-
-               if( !droidPet->hasPower() ){
-                       pet->showFlyText("npc_reaction/flytext","low_power", 204, 0, 0);  // "*Low Power*"
-                       return;
-               }
-       }
-
-       pet->setFollowObject(target);
-
-}
-
-void PetControlDeviceImplementation::enqueuePetCommand(CreatureObject* player, uint32 command, const String& args){
+void PetControlDeviceImplementation::enqueuePetCommand(CreatureObject* player, uint32 command, const String& args, bool selfTarget){
 
        ManagedReference<TangibleObject*> controlledObject = this->controlledObject.get();
        if (controlledObject == NULL || !controlledObject->isAiAgent())
@@ -1010,8 +949,14 @@ void PetControlDeviceImplementation::enqueuePetCommand(CreatureObject* player, u
        if( pet == NULL )
                return;
 
+       uint64 targetID;
+       if (selfTarget)
+               targetID = player->getObjectID();
+       else
+               targetID = player->getTargetID();
+
        //CreatureObject* pet, uint32 command, const String& args, uint64 target, int priority = -1
-       EnqueuePetCommand* enqueueCommand = new EnqueuePetCommand(pet, command, args, player->getTargetID());
+       EnqueuePetCommand* enqueueCommand = new EnqueuePetCommand(pet, command, args, targetID);
        enqueueCommand->execute();
 }