Instructions Jenkins Doxygen

[Fixed] name of spawn and despawn tasks in encounter. 96/1296/2
authorLoshult <loshult@swgemu.com>
Thu, 26 Dec 2013 20:47:26 +0000 (20:47 +0000)
committerLoshult <loshult@swgemu.com>
Thu, 26 Dec 2013 21:00:18 +0000 (21:00 +0000)
[Fixed] finishing of spawn and despawn tasks in encounter.
[Fixed] call to despawn function in old man encounter.
[Added] isEncounterFinished function to the old man encounter.
[Added] Sith Shadow encounter.
[Added] linking of old man encounter and sith shadown encounter.
[Added] nil protection in a few functions.

Change-Id: Id00a6ff1da7acece57591bbe8e2952c4ed27e193

MMOCoreORB/bin/scripts/managers/jedi/village/old_man_encounter.lua
MMOCoreORB/bin/scripts/managers/jedi/village/sith_shadow_encounter.lua [new file with mode: 0644]
MMOCoreORB/bin/scripts/managers/jedi/village/tests/old_man_encounter_Test.lua
MMOCoreORB/bin/scripts/quest/tasks/encounter.lua
MMOCoreORB/bin/scripts/utils/spawn_mobiles.lua

index 1904bf4..edda14d 100644 (file)
@@ -3,6 +3,7 @@ local QuestManager = require("managers.quest.quest_manager")
 local ObjectManager = require("managers.object.object_manager")
 local SpawnMobiles = require("utils.spawn_mobiles")
 local VillageJediManagerCommon = require("managers.jedi.village.village_jedi_manager_common")
+local SithShadowEncounter = require("managers.jedi.village.sith_shadow_encounter")
 
 local OLD_MAN_GREETING_STRING = "@quest/force_sensitive/intro:oldman_greeting"
 local OLD_MAN_DESPAWN_TIME = 10 * 1000
@@ -66,7 +67,7 @@ end
 -- Event handler for the scheduled despawn of the old man when the player has finished the conversation.
 -- @param pCreatureObject pointer to the creatureObject of the player.
 function OldManEncounter:handleScheduledDespawn(pCreatureObject)
-       self:despawnEncounter(pCreatureObject)
+       self:handleDespawnEvent(pCreatureObject)
 end
 
 -- Schedule despawn of old man due to player conversation has ended.
@@ -110,4 +111,17 @@ function OldManEncounter:doesOldManBelongToThePlayer(pConversingPlayer, pConvers
        end
 end
 
+-- Check if the old man encounter is finished or not.
+-- @param pCreatureObject pointer to the creature object of the player.
+-- @return true if the encounter is finished. I.e. the player has the crystal.
+function OldManEncounter:isEncounterFinished(pCreatureObject)
+       return QuestManager.hasCompletedQuest(pCreatureObject, QuestManager.quests.OLD_MAN_FORCE_CRYSTAL)
+end
+
+-- Handling of finishing the encounter.
+-- @param pCreatureObject pointer to the creature object of the player.
+function OldManEncounter:taskFinish(pCreatureObject)
+       SithShadowEncounter:start(pCreatureObject)
+end
+
 return OldManEncounter
diff --git a/MMOCoreORB/bin/scripts/managers/jedi/village/sith_shadow_encounter.lua b/MMOCoreORB/bin/scripts/managers/jedi/village/sith_shadow_encounter.lua
new file mode 100644 (file)
index 0000000..9d208b2
--- /dev/null
@@ -0,0 +1,26 @@
+local Encounter = require("quest.tasks.encounter")
+local QuestManager = require("managers.quest.quest_manager")
+local ObjectManager = require("managers.object.object_manager")
+local SpawnMobiles = require("utils.spawn_mobiles")
+
+SithShadowEncounter = Encounter:new {
+       -- Task properties
+       taskName = "SithShadowEncounter",
+       -- Encounter properties
+       --minimumTimeUntilEncounter = 12 * 60 * 60 * 1000, -- 12 hours
+       --maximumTimeUntilEncounter = 24 * 60 * 60 * 1000, -- 24 hours
+       minimumTimeUntilEncounter = 12 * 1000, -- 12 hours
+       maximumTimeUntilEncounter = 24 * 1000, -- 24 hours
+       --encounterDespawnTime = 5 * 60 * 1000, -- 5 minutes
+       encounterDespawnTime = 60 * 1000, -- 5 minutes
+       spawnObjectList = {
+               { template = "sith_shadow_pirate", minimumDistance = 32, maximumDistance = 64, referencePoint = 0, followPlayer = true },
+               { template = "sith_shadow_pirate", minimumDistance = 4, maximumDistance = 8, referencePoint = 1, followPlayer = true }
+       },
+       onEncounterSpawned = nil,
+       isEncounterFinished = nil,
+       onEncounterClosingIn = nil,
+       onEncounterAtPlayer = nil
+}
+
+return SithShadowEncounter
index 796c1a6..c89bcb6 100644 (file)
@@ -218,24 +218,24 @@ describe("OldManEncounter", function()
        describe("Events", function()
                describe("handleScheduledDespawn", function()
                        describe("When called with a pointer to a player", function()
-                               local realDespawnEncounter
+                               local realHandleDespawnEncounter
 
                                setup(function()
-                                       realDespawnEncounter = OldManEncounter.despawnEncounter
+                                       realHandleDespawnEncounter = OldManEncounter.handleDespawnEvent
                                end)
 
                                setup(function()
-                                       OldManEncounter.despawnEncounter = realDespawnEncounter
+                                       OldManEncounter.handleDespawnEvent = realHandleDespawnEncounter
                                end)
 
                                setup(function()
-                                       OldManEncounter.despawnEncounter = spy.new(function() end)
+                                       OldManEncounter.handleDespawnEvent = spy.new(function() end)
                                end)
 
                                it("Should despawn the old man.", function()
                                        OldManEncounter:handleScheduledDespawn(pCreatureObject)
 
-                                       assert.spy(OldManEncounter.despawnEncounter).was.called_with(OldManEncounter, pCreatureObject)
+                                       assert.spy(OldManEncounter.handleDespawnEvent).was.called_with(OldManEncounter, pCreatureObject)
                                end)
                        end)
                end)
index 125503c..1e7b4ec 100644 (file)
@@ -53,7 +53,7 @@ function Encounter:setupSpawnAndDespawnEvents()
        if self.spawnTask == nil then
                self.spawnTask = PersistentEvent:new {
                        -- Task properties
-                       taskName = "encounter_spawn_task",
+                       taskName = self.taskName .. "_spawn_task",
                        taskFinish = nil,
                        -- PersistentEvent properties
                        minimumTimeUntilEvent = self.minimumTimeUntilEncounter,
@@ -68,7 +68,7 @@ function Encounter:setupSpawnAndDespawnEvents()
        if self.despawnTask == nil then
                self.despawnTask = PersistentEvent:new {
                        -- Task properties
-                       taskName = "encounter_despawn_task",
+                       taskName = self.taskName .. "_despawn_task",
                        taskFinish = nil,
                        -- PersistentEvent properties
                        minimumTimeUntilEvent = self.encounterDespawnTime,
@@ -84,6 +84,7 @@ end
 -- Start the encounter.
 -- @param pCreatureObject pointer to the creature object of the player.
 function Encounter:taskStart(pCreatureObject)
+       Logger:log("Starting spawn task in " .. self.taskName, LT_INFO)
        self:setupSpawnAndDespawnEvents()
        self.spawnTask:start(pCreatureObject)
 end
@@ -155,11 +156,13 @@ end
 -- @param spawnedObjects list with pointers to the spawned objects.
 -- @param objectToFollow pointer to the object to follow.
 function Encounter:setSpawnedObjectsToFollow(spawnedObjects, objectToFollow)
-       for i = 1, table.getn(spawnedObjects), 1 do
-               if self.spawnObjectList[i]["followPlayer"] then
-                       ObjectManager.withCreatureAiAgent(spawnedObjects[i], function(aiAgent)
-                               aiAgent:setFollowObject(objectToFollow)
-                       end)
+       if spawnedObjects ~= nil then
+               for i = 1, table.getn(spawnedObjects), 1 do
+                       if self.spawnObjectList[i]["followPlayer"] then
+                               ObjectManager.withCreatureAiAgent(spawnedObjects[i], function(aiAgent)
+                                       aiAgent:setFollowObject(objectToFollow)
+                               end)
+                       end
                end
        end
 end
@@ -183,10 +186,13 @@ end
 -- @param pCreatureObject pointer to the creature object of the player.
 function Encounter:handleSpawnEvent(pCreatureObject)
        Logger:log("Spawn encounter in " .. self.taskName .. " triggered.", LT_INFO)
+       self:setupSpawnAndDespawnEvents()
+       self.spawnTask:finish(pCreatureObject)
+
        if self:isPlayerInPositionForEncounter(pCreatureObject) then
                self:createEncounter(pCreatureObject)
        end
-       self:setupSpawnAndDespawnEvents()
+
        self.despawnTask:start(pCreatureObject)
 end
 
@@ -195,11 +201,13 @@ end
 -- @param pCreatureObject pointer to the creature object of the player.
 function Encounter:handleDespawnEvent(pCreatureObject)
        Logger:log("Despawning mobiles in encounter " .. self.taskName .. ".", LT_INFO)
+       self:setupSpawnAndDespawnEvents()
+       self.despawnTask:finish(pCreatureObject)
+
        SpawnMobiles.despawnMobiles(pCreatureObject, self.taskName)
 
        if not self:callFunctionIfNotNil(self.isEncounterFinished, pCreatureObject) then
                Logger:log("Restarting encounter " .. self.taskName .. ".", LT_INFO)
-               self:setupSpawnAndDespawnEvents()
                self.spawnTask:start(pCreatureObject)
        else
                self:finish(pCreatureObject)
index 8d42d04..8e17feb 100644 (file)
@@ -232,10 +232,12 @@ end
 -- Despawn the mobiles.
 -- @param spawnedMobilesList a list of pointers to the spawned mobiles.
 function SpawnMobiles.despawnMobilesInList(spawnedMobilesList)
-       for i = 1, table.getn(spawnedMobilesList), 1 do
-               ObjectManager.withSceneObject(spawnedMobilesList[i], function(sceneObject)
-                       sceneObject:destroyObjectFromWorld()
-               end)
+       if spawnedMobilesList ~= nil then
+               for i = 1, table.getn(spawnedMobilesList), 1 do
+                       ObjectManager.withSceneObject(spawnedMobilesList[i], function(sceneObject)
+                               sceneObject:destroyObjectFromWorld()
+                       end)
+               end
        end
 end