Instructions Jenkins Doxygen

[Changed] changing a player's faction now chages faction on all active 97/1197/2
authorIvojedi <ivojedi@swgemu.com>
Fri, 29 Nov 2013 13:49:24 +0000 (05:49 -0800)
committerIvojedi <ivojedi@swgemu.com>
Fri, 29 Nov 2013 13:49:24 +0000 (05:49 -0800)
pets (any active faction pets are stored automatically)
[Changed] changing a player's faction status updates all active pet's
pvpStatusBitmask as well (any active faction pets are automatically
stored if changing to on leave status)

Change-Id: Iafe87e20bc682d9ba012a6eec4d261eeb020c534

13 files changed:
MMOCoreORB/src/server/zone/managers/player/PlayerManagerImplementation.cpp
MMOCoreORB/src/server/zone/objects/creature/CreatureObject.idl
MMOCoreORB/src/server/zone/objects/creature/CreatureObjectImplementation.cpp
MMOCoreORB/src/server/zone/objects/intangible/ControlDevice.idl
MMOCoreORB/src/server/zone/objects/intangible/PetControlDevice.idl
MMOCoreORB/src/server/zone/objects/intangible/PetControlDeviceImplementation.cpp
MMOCoreORB/src/server/zone/objects/intangible/ShipControlDevice.idl
MMOCoreORB/src/server/zone/objects/intangible/ShipControlDeviceImplementation.cpp
MMOCoreORB/src/server/zone/objects/intangible/VehicleControlDevice.idl
MMOCoreORB/src/server/zone/objects/intangible/VehicleControlDeviceImplementation.cpp
MMOCoreORB/src/server/zone/objects/player/PlayerObjectImplementation.cpp
MMOCoreORB/src/server/zone/objects/player/events/StoreSpawnedChildrenTask.h [new file with mode: 0644]
MMOCoreORB/src/server/zone/objects/tangible/TangibleObject.idl

index 996b3b1..ce61c49 100644 (file)
@@ -1306,7 +1306,7 @@ void PlayerManagerImplementation::handleAddItemToTradeWindow(CreatureObject* pla
        }
 
        if(objectToTrade->isControlDevice()) {
-               cast<ControlDevice*>(objectToTrade.get())->storeObject(player);
+               cast<ControlDevice*>(objectToTrade.get())->storeObject(player, true);
        }
 
        tradeContainer->addTradeItem(objectToTrade);
index a0c26a7..d265c50 100644 (file)
@@ -1723,5 +1723,5 @@ class CreatureObject extends TangibleObject {
 
        public native void updateSpeedAndAccelerationMods();
 
-
+       public native void setFaction(unsigned int crc);
 }
index 6209229..0cfca9b 100644 (file)
 #include "server/zone/managers/guild/GuildManager.h"
 #include "system/lang/ref/Reference.h"
 #include "server/zone/objects/player/events/LogoutTask.h"
+#include "server/zone/objects/player/events/StoreSpawnedChildrenTask.h"
 
 #include "server/zone/objects/creature/ai/AiActor.h"
 #include "server/zone/objects/tangible/threat/ThreatMap.h"
@@ -2757,3 +2758,44 @@ Reference<WeaponObject*> CreatureObjectImplementation::getWeapon() {
                return weapon;
 }
 
+void CreatureObjectImplementation::setFaction(unsigned int crc) {
+       faction = crc;
+
+       if (isPlayerCreature()) {
+               CreatureObject* player = _this.get().castTo<CreatureObject*>();
+
+               if (player == NULL)
+                       return;
+
+               PlayerObject* ghost = player->getPlayerObject();
+
+               if (ghost == NULL)
+                       return;
+
+               Vector<ManagedReference<CreatureObject*> > petsToStore;
+
+               for (int i = 0; i < ghost->getActivePetsSize(); i++) {
+                       ManagedReference<AiAgent*> pet = ghost->getActivePet(i);
+
+                       if (pet == NULL)
+                               continue;
+
+                       CreatureTemplate* creatureTemplate = pet->getCreatureTemplate();
+
+                       if (creatureTemplate != NULL) {
+                               String templateFaction = creatureTemplate->getFaction();
+
+                               if (!templateFaction.isEmpty() && (templateFaction.hashCode() != crc)) {
+                                       petsToStore.add(pet.castTo<CreatureObject*>());
+                                       player->sendSystemMessage("You're no longer the right faction for one of your pets, storing...");
+                                       continue;
+                               }
+                       }
+
+                       pet->setFaction(crc);
+               }
+
+               StoreSpawnedChildrenTask* task = new StoreSpawnedChildrenTask(player, petsToStore);
+               task->execute();
+       }
+}
index 442bf06..2ed8747 100644 (file)
@@ -92,7 +92,7 @@ class ControlDevice extends IntangibleObject {
                }
        }
        
-       public abstract void storeObject(CreatureObject player) {
+       public abstract void storeObject(CreatureObject player, boolean force = false) {
                Logger.error("called storeObject on an abstract method");
        }
        
index 21b4132..d11e342 100644 (file)
@@ -110,7 +110,7 @@ class PetControlDevice extends ControlDevice {
                trainedCommands.setNullValue("");
        }
 
-       public native void storeObject(CreatureObject player);
+       public native void storeObject(CreatureObject player, boolean force = false);
        
        public native void callObject(CreatureObject player);
 
index 51d02d4..6d5fcb5 100644 (file)
@@ -279,7 +279,7 @@ void PetControlDeviceImplementation::cancelSpawnObject(CreatureObject* player) {
                player->dropObserver(ObserverEventType::STARTCOMBAT, petControlObserver);
 }
 
-void PetControlDeviceImplementation::storeObject(CreatureObject* player) {
+void PetControlDeviceImplementation::storeObject(CreatureObject* player, bool force) {
        ManagedReference<TangibleObject*> controlledObject = this->controlledObject.get();
 
        if (controlledObject == NULL || !controlledObject->isAiAgent())
@@ -287,12 +287,12 @@ void PetControlDeviceImplementation::storeObject(CreatureObject* player) {
 
        ManagedReference<AiAgent*> pet = cast<AiAgent*>(controlledObject.get());
 
-       if (pet->isInCombat())
+       if (!force && pet->isInCombat())
                return;
 
        if (player->isRidingMount() && player->getParent() == pet) {
 
-               if (!player->checkCooldownRecovery("mount_dismount"))
+               if (!force && !player->checkCooldownRecovery("mount_dismount"))
                        return;
 
                player->executeObjectControllerAction(String("dismount").hashCode());
index c97c4e3..259a482 100644 (file)
@@ -54,7 +54,7 @@ class ShipControlDevice extends ControlDevice {
                Logger.setLoggingName("ShipControlDevice");
        }
        
-       public native void storeObject(CreatureObject player);
+       public native void storeObject(CreatureObject player, boolean force = false);
        
        public native void generateObject(CreatureObject player);
        
index bfb30a9..420ccc0 100644 (file)
@@ -76,7 +76,7 @@ void ShipControlDeviceImplementation::generateObject(CreatureObject* player) {
                ghost->setTeleporting(true);
 }
 
-void ShipControlDeviceImplementation::storeObject(CreatureObject* player) {
+void ShipControlDeviceImplementation::storeObject(CreatureObject* player, bool force) {
        player->clearState(CreatureState::PILOTINGSHIP);
 
        ManagedReference<TangibleObject*> controlledObject = this->controlledObject.get();
index 9144ba8..673473a 100644 (file)
@@ -69,7 +69,7 @@ class VehicleControlDevice extends ControlDevice {
                
        }
        
-       public native void storeObject(CreatureObject player);
+       public native void storeObject(CreatureObject player, boolean force = false);
        
        public native void generateObject(CreatureObject player);
        
index 85f7fc6..f837f65 100644 (file)
@@ -166,7 +166,7 @@ void VehicleControlDeviceImplementation::cancelSpawnObject(CreatureObject* playe
                player->dropObserver(ObserverEventType::STARTCOMBAT, vehicleControlObserver);
 }
 
-void VehicleControlDeviceImplementation::storeObject(CreatureObject* player) {
+void VehicleControlDeviceImplementation::storeObject(CreatureObject* player, bool force) {
        ManagedReference<TangibleObject*> controlledObject = this->controlledObject.get();
 
        if (controlledObject == NULL)
@@ -177,7 +177,7 @@ void VehicleControlDeviceImplementation::storeObject(CreatureObject* player) {
 
        if (player->isRidingMount() && player->getParent() == controlledObject) {
 
-               if (!player->checkCooldownRecovery("mount_dismount"))
+               if (!force && !player->checkCooldownRecovery("mount_dismount"))
                        return;
 
                player->executeObjectControllerAction(String("dismount").hashCode());
index b3ef582..1c5d96d 100644 (file)
@@ -91,6 +91,7 @@ which carries forward this exception.
 #include "server/zone/objects/building/BuildingObject.h"
 #include "server/zone/objects/group/GroupObject.h"
 #include "server/zone/objects/intangible/ControlDevice.h"
+#include "server/zone/objects/intangible/PetControlDevice.h"
 #include "server/zone/managers/player/PlayerManager.h"
 #include "server/zone/managers/planet/PlanetManager.h"
 #include "server/zone/objects/player/Races.h"
@@ -110,6 +111,7 @@ which carries forward this exception.
 #include "server/zone/managers/faction/FactionManager.h"
 #include "server/zone/templates/intangible/SharedPlayerObjectTemplate.h"
 #include "server/zone/objects/player/sessions/TradeSession.h"
+#include "server/zone/objects/player/events/StoreSpawnedChildrenTask.h"
 #include "server/zone/objects/player/events/BountyHunterTefRemovalTask.h"
 #include "server/zone/managers/visibility/VisibilityManager.h"
 #include "server/zone/managers/gcw/GCWManager.h"
@@ -179,15 +181,22 @@ void PlayerObjectImplementation::unloadSpawnedChildren() {
        if (datapad == NULL)
                return;
 
+       Vector<ManagedReference<CreatureObject*> > childrenToStore;
+
        for (int i = 0; i < datapad->getContainerObjectsSize(); ++i) {
                ManagedReference<SceneObject*> object = datapad->getContainerObject(i);
 
                if (object->isControlDevice()) {
                        ControlDevice* device = cast<ControlDevice*>( object.get());
 
-                       device->storeObject(creo);
+                       ManagedReference<CreatureObject*> child = cast<CreatureObject*>(device->getControlledObject());
+                       if (child != NULL)
+                               childrenToStore.add(child);
                }
        }
+
+       StoreSpawnedChildrenTask* task = new StoreSpawnedChildrenTask(creo, childrenToStore);
+       task->execute();
 }
 
 
@@ -501,6 +510,35 @@ void PlayerObjectImplementation::setFactionStatus(int status) {
                creature->setPvpStatusBitmask(pvpStatusBitmask);
        }
 
+       Vector<ManagedReference<CreatureObject*> > petsToStore;
+
+       for (int i = 0; i < getActivePetsSize(); i++) {
+               Reference<AiAgent*> pet = getActivePet(i);
+
+               if (pet == NULL)
+                       continue;
+
+               CreatureTemplate* creatureTemplate = pet->getCreatureTemplate();
+
+               if (creatureTemplate != NULL) {
+                       String templateFaction = creatureTemplate->getFaction();
+
+                       if (!templateFaction.isEmpty() && factionStatus == FactionStatus::ONLEAVE) {
+                               petsToStore.add(pet.castTo<CreatureObject*>());
+                               creature->sendSystemMessage("You're no longer the right faction status for one of your pets, storing...");
+                               continue;
+                       }
+               }
+
+               if (pvpStatusBitmask & CreatureFlag::PLAYER)
+                       pvpStatusBitmask &= ~CreatureFlag::PLAYER;
+
+               pet->setPvpStatusBitmask(pvpStatusBitmask);
+       }
+
+       StoreSpawnedChildrenTask* task = new StoreSpawnedChildrenTask(creature, petsToStore);
+       task->execute();
+
        ManagedReference<SceneObject*> parent = getParent();
 
        Zone* zone = parent->getZone();
diff --git a/MMOCoreORB/src/server/zone/objects/player/events/StoreSpawnedChildrenTask.h b/MMOCoreORB/src/server/zone/objects/player/events/StoreSpawnedChildrenTask.h
new file mode 100644 (file)
index 0000000..075769b
--- /dev/null
@@ -0,0 +1,37 @@
+
+#ifndef STORESPAWNEDCHILDRENTASK_H_
+#define STORESPAWNEDCHILDRENTASK_H_
+
+#include "server/zone/objects/creature/CreatureObject.h"
+
+class StoreSpawnedChildrenTask : public Task {
+       ManagedReference<CreatureObject*> player;
+       Vector<ManagedReference<CreatureObject*> > children;
+public:
+       StoreSpawnedChildrenTask(CreatureObject* creo, Vector<ManagedReference<CreatureObject*> >& ch) :
+               player(creo), children(ch) {
+
+       }
+
+       void run() {
+               Locker locker(player);
+
+               for (int i = 0; i < children.size(); ++i) {
+                       CreatureObject* child = children.get(i);
+
+                       if (child == NULL)
+                               continue;
+
+                       Locker clocker(child, player);
+
+                       ManagedReference<ControlDevice*> controlDevice = child->getControlDevice().get();
+
+                       controlDevice->storeObject(player, true);
+               }
+
+       }
+};
+
+
+
+#endif /* STORESPAWNEDCHILDRENTASK_H_ */
index ff26baf..2f09ee8 100644 (file)
@@ -493,7 +493,7 @@ class TangibleObject extends SceneObject {
                return conditionDamage >= maxCondition;
        }
        
-       public void setFaction(unsigned int crc) {
+       public abstract void setFaction(unsigned int crc) {
                faction = crc;
        }