Instructions Jenkins Doxygen

[Added] possibility to set a radius on the active area around the 71/1471/1
authorLoshult <loshult@swgemu.com>
Sun, 9 Mar 2014 07:22:40 +0000 (07:22 +0000)
committerLoshult <loshult@swgemu.com>
Sun, 9 Mar 2014 07:22:40 +0000 (07:22 +0000)
theater in the go_to_theater module.
[Added] onEntered event to the active area in the go_to_theater module.
It will call the onEnteredActiveArea method.

Change-Id: Ibba6622ee6f5b8f2914d9e669fd90907ce0aed62

MMOCoreORB/bin/scripts/managers/jedi/village/sith_shadow_intro_theater.lua
MMOCoreORB/bin/scripts/quest/tasks/go_to_theater.lua
MMOCoreORB/bin/scripts/quest/tasks/tests/go_to_theater_Test.lua

index 1fb2945..d12d0e2 100644 (file)
@@ -14,8 +14,10 @@ SithShadowIntroTheater = GoToTheater:new {
                { template = "sith_shadow", minimumDistance = 12, maximumDistance = 24, referencePoint = 0 }
        },
        despawnTime = 2 * 60* 60* 1000, -- 2 hours
+       activeAreaRadius = 64,
        onFailedSpawn = nil,
-       onSuccessfulSpawn = nil
+       onSuccessfulSpawn = nil,
+       onEnteredActiveArea = nil
 }
 
 return SithShadowIntroTheater
index 525cb95..457200e 100644 (file)
@@ -33,10 +33,44 @@ GoToTheater = Task:new {
        waypointDescription = "",
        mobileList = {},
        despawnTime = 0,
+       activeAreaRadius = 0,
        onFailedSpawn = nil,
        onSuccessfulSpawn = nil
 }
 
+-- Setup the active area around the theater.
+-- @param pCreatureObject pointer to the creature object for whom the theater is created for.
+-- @param spawnPoint the coordinates to spawn the active area at.
+-- @return true if setup was successful, false otherwise.
+function GoToTheater:setupActiveArea(pCreatureObject, spawnPoint)
+       return ObjectManager.withCreatureObject(pCreatureObject, function(creatureObject)
+               local pActiveArea = spawnSceneObject(creatureObject:getZoneName(), ACTIVE_AREA_IFF, spawnPoint[1], 0, spawnPoint[3], 0, 0)
+
+               return ObjectManager.withActiveArea(pActiveArea, function(activeArea)
+                       writeData(creatureObject:getObjectID() .. self.taskName .. ACTIVE_AREA_ID_STRING, activeArea:getObjectID())
+                       activeArea:setRadius(self.activeAreaRadius)
+                       createObserver(ENTEREDAREA, self.taskName, "handleEnteredAreaEvent", pActiveArea)
+                       return true
+               end) == true
+       end) == true
+end
+
+-- Handle the entered active area event.
+-- @param pActiveArea pointer to the active area that is entered.
+-- @param pCreatureObject pointer to the creature who is entering the active area.
+-- @param nothing not used.
+function GoToTheater:handleEnteredAreaEvent(pActiveArea, pCreatureObject, nothing)
+       ObjectManager.withCreatureObject(pCreatureObject, function(creatureObject)
+               local storedActiveAreaId = readData(creatureObject:getObjectID() .. self.taskName .. ACTIVE_AREA_ID_STRING)
+               ObjectManager.withSceneObject(pActiveArea, function(activeArea)
+                       if storedActiveAreaId == activeArea:getObjectID() then
+                               local spawnedObjects = SpawnMobiles.getSpawnedMobiles(pCreatureObject, self.taskName)
+                               self:callFunctionIfNotNil(self.onEnteredActiveArea, nil, pCreatureObject, spawnedObjects)
+                       end
+               end)
+       end)
+end
+
 -- Start the GoToTheater.
 -- @param pCreatureObject pointer to the creature object of the player.
 function GoToTheater:taskStart(pCreatureObject)
@@ -55,13 +89,7 @@ function GoToTheater:taskStart(pCreatureObject)
                                local spawnedMobilesList = SpawnMobiles.spawnMobiles(pTheater, self.taskName, self.mobileList)
 
                                if spawnedMobilesList ~= nil then
-                                       local pActiveArea = spawnSceneObject(creatureObject:getZoneName(), ACTIVE_AREA_IFF, spawnPoint[1], 0, spawnPoint[3], 0, 0)
-
-                                       if pActiveArea ~= nil then
-                                               ObjectManager.withSceneObject(pActiveArea, function(activeArea)
-                                                       writeData(creatureObject:getObjectID() .. self.taskName .. ACTIVE_AREA_ID_STRING, activeArea:getObjectID())
-                                               end)
-
+                                       if self:setupActiveArea(pCreatureObject, spawnPoint) then
                                                local waypointId = ObjectManager.withPlayerObject(creatureObject:getPlayerObject(), function(playerObject)
                                                        return playerObject:addWaypoint(creatureObject:getZoneName(), self.waypointDescription, "", spawnPoint[1], spawnPoint[3], WAYPOINTWHITE, true, true)
                                                end)
@@ -95,8 +123,7 @@ function GoToTheater:taskFinish(pCreatureObject)
                playerObject:removeWaypoint(waypointId, true)
 
                local activeAreaId = readData(creatureObject:getObjectID() .. self.taskName .. ACTIVE_AREA_ID_STRING)
-               local pActiveArea = getSceneObject(activeAreaId)
-               ObjectManager.withSceneObject(pActiveArea, function(activeArea)
+               ObjectManager.withSceneObjectFromId(activeAreaId, function(activeArea)
                        activeArea:destroyObjectFromWorld()
                end)
 
index ead8d97..310cada 100644 (file)
@@ -17,8 +17,10 @@ local testGoToTheater = GoToTheater:new {
        waypointDescription = "waypointDescription",
        mobileList = { "mobileList" },
        despawnTime = 10,
+       activeAreaRadius = 20,
        onFailedSpawn = nil,
-       onSuccessfulSpawn = nil
+       onSuccessfulSpawn = nil,
+       onEnteredActiveArea = nil
 }
 
 describe("GoToTheater", function()
@@ -42,6 +44,9 @@ describe("GoToTheater", function()
        local waypointId = 1234
        local activeArea
        local activeAreaId = 34567890
+       local pSpawnedMobile1 = { "spawnedMobilePointer1" }
+       local pSpawnedMobile2 = { "spawnedMobilePointer2" }
+       local spawnedMobiles = { pSpawnedMobile1, pSpawnedMobile2 }
 
        setup(function()
                DirectorManagerMocks.mocks.setup()
@@ -59,6 +64,7 @@ describe("GoToTheater", function()
 
                testGoToTheater.onFailedSpawn = spy.new(function() end)
                testGoToTheater.onSuccessfulSpawn = spy.new(function() end)
+               testGoToTheater.onEnteredActiveArea = spy.new(function() end)
 
                creatureObject = {}
                creatureObject.getObjectID = spy.new(function() return playerObjectId end)
@@ -84,7 +90,10 @@ describe("GoToTheater", function()
                activeArea = {}
                activeArea.getObjectID = spy.new(function() return activeAreaId end)
                activeArea.destroyObjectFromWorld = spy.new(function() end)
+               activeArea.setRadius = spy.new(function() end)
                DirectorManagerMocks.sceneObjects[pActiveArea] = activeArea
+               DirectorManagerMocks.activeAreas[pActiveArea] = activeArea
+
        end)
 
        describe("start", function()
@@ -146,8 +155,21 @@ describe("GoToTheater", function()
                                        end)
 
                                        describe("and the mobiles was spawned", function()
+                                               local spawnSceneObjectTimes
+
                                                before_each(function()
+                                                       spawnSceneObjectTimes = 0
+
                                                        SpawnMobilesMocks.spawnMobiles = spy.new(function() return spawnedMobilesList end)
+
+                                                       spawnSceneObject = spy.new(function()
+                                                               spawnSceneObjectTimes = spawnSceneObjectTimes + 1
+                                                               if spawnSceneObjectTimes == 1 then
+                                                                       return pTheater
+                                                               else
+                                                                       return pActiveArea
+                                                               end
+                                                       end)
                                                end)
 
                                                it("Should setup and active area at the spawn point.", function()
@@ -157,21 +179,11 @@ describe("GoToTheater", function()
                                                end)
 
                                                describe("and the active area was spawned", function()
-                                                       local spawnSceneObjectTimes = 0
-                                                       local writeDataTimes = 0
+                                                       local writeDataTimes
 
                                                        before_each(function()
-                                                               spawnSceneObjectTimes = 0
                                                                writeDataTimes = 0
 
-                                                               spawnSceneObject = spy.new(function()
-                                                                       spawnSceneObjectTimes = spawnSceneObjectTimes + 1
-                                                                       if spawnSceneObjectTimes == 1 then
-                                                                               return pTheater
-                                                                       else
-                                                                               return pActiveArea
-                                                                       end
-                                                               end)
                                                                writeData = spy.new(function(string, value)
                                                                        writeDataTimes = writeDataTimes + 1
                                                                        if writeDataTimes == 2 then
@@ -185,6 +197,18 @@ describe("GoToTheater", function()
                                                                end)
                                                        end)
 
+                                                       it("Should set the radius of the active area.", function()
+                                                               testGoToTheater:start(pCreatureObject)
+
+                                                               assert.spy(activeArea.setRadius).was.called_with(activeArea, testGoToTheater.activeAreaRadius)
+                                                       end)
+
+                                                       it("Should create an observer for entering the active area.", function()
+                                                               testGoToTheater:start(pCreatureObject)
+
+                                                               assert.spy(createObserver).was.called_with(ENTEREDAREA, testGoToTheater.taskName, "handleEnteredAreaEvent", pActiveArea)
+                                                       end)
+
                                                        it("Should save the id of the active area on the player.", function()
                                                                testGoToTheater:start(pCreatureObject)
 
@@ -436,4 +460,35 @@ describe("GoToTheater", function()
                        end)
                end)
        end)
+
+       describe("handleEnteredAreaEvent", function()
+               describe("When called with an active area and a pointer to the player", function()
+                       it("Should check if the theater is for the player", function()
+                               testGoToTheater:handleEnteredAreaEvent(pActiveArea, pCreatureObject, 0)
+
+                               assert.spy(readData).was.called_with(playerObjectId .. testGoToTheater.taskName .. ACTIVE_AREA_ID_STRING)
+                       end)
+
+                       describe("and the theater is for the player", function()
+                               before_each(function()
+                                       readData = spy.new(function() return activeAreaId end)
+                                       SpawnMobilesMocks.getSpawnedMobiles = spy.new(function() return spawnedMobiles end)
+                               end)
+
+                               it("Should call the onEnteredActiveArea function.", function()
+                                       testGoToTheater:handleEnteredAreaEvent(pActiveArea, pCreatureObject, 0)
+
+                                       assert.spy(testGoToTheater.onEnteredActiveArea).was.called_with(testGoToTheater, pCreatureObject, spawnedMobiles)
+                               end)
+                       end)
+
+                       describe("and the theater isn't for the player", function()
+                               it("Should not call the onEnteredActiveArea function.", function()
+                                       testGoToTheater:handleEnteredAreaEvent(pActiveArea, pCreatureObject, 0)
+
+                                       assert.spy(testGoToTheater.onEnteredActiveArea).was.not_called()
+                               end)
+                       end)
+               end)
+       end)
 end)