Instructions Jenkins Doxygen

[Changed] to use old man encounter. 94/1294/1
authorLoshult <loshult@swgemu.com>
Thu, 26 Dec 2013 15:09:26 +0000 (15:09 +0000)
committerLoshult <loshult@swgemu.com>
Thu, 26 Dec 2013 15:12:35 +0000 (15:12 +0000)
[Fixed] a few bugs in the encounter logic.
Full re-test of old man encounter needed.

Change-Id: I58b149db41fbbd0cfdc8c0b3fbb31532624de12d

15 files changed:
MMOCoreORB/bin/scripts/managers/jedi/village/glowing.lua
MMOCoreORB/bin/scripts/managers/jedi/village/mocks/old_man_encounter_mocks.lua [new file with mode: 0644]
MMOCoreORB/bin/scripts/managers/jedi/village/old_man_conv_handler.lua
MMOCoreORB/bin/scripts/managers/jedi/village/old_man_encounter.lua
MMOCoreORB/bin/scripts/managers/jedi/village/tests/glowing_Test.lua
MMOCoreORB/bin/scripts/quest/tasks/encounter.lua
MMOCoreORB/bin/scripts/quest/tasks/mocks/task_mocks.lua [new file with mode: 0644]
MMOCoreORB/bin/scripts/quest/tasks/persistent_event.lua
MMOCoreORB/bin/scripts/quest/tasks/task.lua
MMOCoreORB/bin/scripts/quest/tasks/tests/encounter_Test.lua
MMOCoreORB/bin/scripts/quest/tasks/tests/persistent_event_Test.lua
MMOCoreORB/bin/scripts/utils/logger.lua
MMOCoreORB/bin/scripts/utils/spawn_mobiles.lua
MMOCoreORB/bin/scripts/utils/tests/logger_Test.lua [new file with mode: 0644]
MMOCoreORB/bin/scripts/utils/tests/spawn_mobiles_Test.lua

index 9708536..da088f1 100755 (executable)
@@ -1,5 +1,5 @@
 local ObjectManager = require("managers.object.object_manager")
-local OldMan = require("managers.jedi.village.old_man")
+local OldManEncounter = require("managers.jedi.village.old_man_encounter")
 local VillageJediManagerCommon = require("managers.jedi.village.village_jedi_manager_common")
 
 Glowing = Object:new {}
@@ -165,7 +165,7 @@ end
 function Glowing:isGlowing(pCreatureObject)
        if self:countBadges(pCreatureObject) >= TOTALNUMBEROFBADGESREQUIRED then
                VillageJediManagerCommon.setJediProgressionScreenPlayState(pCreatureObject, VILLAGE_JEDI_PROGRESSION_GLOWING)
-               OldMan.createSpawnOldManEvent(pCreatureObject)
+               OldManEncounter:start(pCreatureObject)
        end
 end
 
diff --git a/MMOCoreORB/bin/scripts/managers/jedi/village/mocks/old_man_encounter_mocks.lua b/MMOCoreORB/bin/scripts/managers/jedi/village/mocks/old_man_encounter_mocks.lua
new file mode 100644 (file)
index 0000000..a52a7f7
--- /dev/null
@@ -0,0 +1,35 @@
+local OldManEncounter = require("managers.jedi.village.old_man_encounter")
+
+local realStart
+local realDoesOldManBelongToThePlayer
+local realScheduleDespawnOfOldMan
+local realGiveForceCrystalToPlayer
+
+local OldManMocks = OldManEncounter
+OldManMocks.mocks = {}
+
+function OldManMocks.mocks.setup()
+       realStart = OldManEncounter.createSpawnOldManEvent
+       realDoesOldManBelongToThePlayer = OldManEncounter.doesOldManBelongToThePlayer
+       realScheduleDespawnOfOldMan = OldManEncounter.scheduleDespawnOfOldMan
+       realGiveForceCrystalToPlayer = OldManEncounter.giveForceCrystalToPlayer
+end
+
+function OldManMocks.mocks.teardown()
+       OldManEncounter.createSpawnOldManEvent = realStart
+       OldManEncounter.doesOldManBelongToThePlayer = realDoesOldManBelongToThePlayer
+       OldManEncounter.scheduleDespawnOfOldMan = realScheduleDespawnOfOldMan
+       OldManEncounter.giveForceCrystalToPlayer = realGiveForceCrystalToPlayer
+end
+
+function OldManMocks.mocks.before_each()
+       OldManEncounter.start = spy.new(function() end)
+       OldManEncounter.doesOldManBelongToThePlayer = spy.new(function() return false end)
+       OldManEncounter.scheduleDespawnOfOldMan = spy.new(function() end)
+       OldManEncounter.giveForceCrystalToPlayer = spy.new(function() end)
+end
+
+function OldManMocks.mocks.after_each()
+end
+
+return OldManMocks
index d58432e..0cd15bd 100755 (executable)
@@ -1,7 +1,5 @@
 local VillageJediManagerCommon = require("managers.jedi.village.village_jedi_manager_common")
-local OldMan = require("managers.jedi.village.old_man")
-
-OLD_MAN_CONVERSATION_ENDED_DESPAWN_TIME = 10 * 1000 -- 10 seconds
+local OldManEncounter = require("managers.jedi.village.old_man_encounter")
 
 old_man_conv_handler = Object:new {
 }
@@ -48,10 +46,10 @@ function old_man_conv_handler:runScreenHandlers(pConversationTemplate, pConversi
        if screenID == "init" then
                pConversationScreen = old_man_conv_handler.handleInit(pConversationTemplate, pConversingPlayer, pConversingNpc, selectedOption, pConversationScreen)
        elseif screenID == "village_another_time" or screenID == "village_another_time2" or screenID == "mellichae_later" then
-               OldMan.scheduleDespawnOfOldMan(pConversingPlayer, OLD_MAN_CONVERSATION_ENDED_DESPAWN_TIME)
+               OldManEncounter:scheduleDespawnOfOldMan(pConversingPlayer)
        elseif screenID == "village_give_crystal" then
-               OldMan.scheduleDespawnOfOldMan(pConversingPlayer, OLD_MAN_CONVERSATION_ENDED_DESPAWN_TIME)
-               OldMan.giveForceCrystalToPlayer(pConversingPlayer)
+               OldManEncounter:scheduleDespawnOfOldMan(pConversingPlayer)
+               OldManEncounter:giveForceCrystalToPlayer(pConversingPlayer)
        end
 
        return pConversationScreen
@@ -61,7 +59,7 @@ function old_man_conv_handler.handleInit(pConversationTemplate, pConversingPlaye
        local conversationTemplate = LuaConversationTemplate(pConversationTemplate)
        local nextScreen = "not_you"
 
-       if OldMan.oldManBelongsToThePlayer(pConversingPlayer, pConversingNpc) then
+       if OldManEncounter:doesOldManBelongToThePlayer(pConversingPlayer, pConversingNpc) then
                if VillageJediManagerCommon.hasJediProgressionScreenPlayState(pConversingPlayer, VILLAGE_JEDI_PROGRESSION_COMPLETED_VILLAGE) then
                        nextScreen = "mellichae_intro"
                elseif VillageJediManagerCommon.hasJediProgressionScreenPlayState(pConversingPlayer, VILLAGE_JEDI_PROGRESSION_GLOWING) then
index 51e1a5d..1904bf4 100644 (file)
@@ -13,9 +13,12 @@ OldManEncounter = Encounter:new {
        -- Task properties
        taskName = "OldManEncounter",
        -- Encounter properties
-       minimumTimeUntilEncounter = 12 * 60 * 60 * 1000, -- 12 hours
-       maximumTimeUntilEncounter = 24 * 60 * 60 * 1000, -- 24 hours
-       encounterDespawnTime = 5 * 60 * 1000, -- 5 minutes
+       --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 = "old_man", minimumDistance = 32, maximumDistance = 64, referencePoint = 0, followPlayer = true }
        },
@@ -44,6 +47,7 @@ end
 -- @param pOldMan pointer to the old man.
 -- @param pCreatureObject pointer to the creature object of the player.
 function OldManEncounter:sendGreetingString(pOldMan, pCreatureObject)
+       Logger:log("Sending greeting string.", LT_INFO)
        local greetingString = LuaStringIdChatParameter(OLD_MAN_GREETING_STRING)
        local firstName = self:getPlayerFirstName(pCreatureObject)
        greetingString:setTT(firstName)
@@ -68,12 +72,14 @@ end
 -- Schedule despawn of old man due to player conversation has ended.
 -- @param pCreatureObject pointer to the creature object of the player.
 function OldManEncounter:scheduleDespawnOfOldMan(pCreatureObject)
+       Logger:log("Scheduling despawn of old man.", LT_INFO)
        createEvent(OLD_MAN_DESPAWN_TIME, "OldManEncounter", "handleScheduledDespawn", pCreatureObject)
 end
 
 -- Give the force crystal to the player.
 -- @param pCreatureObject pointer to the creature object of the player.
 function OldManEncounter:giveForceCrystalToPlayer(pCreatureObject)
+       Logger:log("Giving crystal to player.", LT_INFO)
        ObjectManager.withCreatureObject(pCreatureObject, function(creatureObject)
                local pInventory = creatureObject:getSlottedObject(OLD_MAN_INVENTORY_STRING)
 
index a465040..ccd3727 100755 (executable)
@@ -1,6 +1,6 @@
 local Glowing = require("managers.jedi.village.glowing")
 local DirectorManagerMocks = require("screenplays.mocks.director_manager_mocks")
-local OldManMocks = require("managers.jedi.village.mocks.old_man_mocks")
+local OldManEncounterMocks = require("managers.jedi.village.mocks.old_man_encounter_mocks")
 local VillageJediManagerCommonMocks = require("managers.jedi.village.mocks.village_jedi_manager_common_mocks")
 
 local testGlowing = Glowing:new {}
@@ -14,19 +14,19 @@ describe("Village Jedi Manager - Glowing", function()
        setup(function()
                DirectorManagerMocks.mocks.setup()
                VillageJediManagerCommonMocks.mocks.setup()
-               OldManMocks.mocks.setup()
+               OldManEncounterMocks.mocks.setup()
        end)
 
        teardown(function()
                DirectorManagerMocks.mocks.teardown()
                VillageJediManagerCommonMocks.mocks.teardown()
-               OldManMocks.mocks.teardown()
+               OldManEncounterMocks.mocks.teardown()
        end)
 
        before_each(function()
                DirectorManagerMocks.mocks.before_each()
                VillageJediManagerCommonMocks.mocks.before_each()
-               OldManMocks.mocks.before_each()
+               OldManEncounterMocks.mocks.before_each()
 
                creatureObject = {}
                creatureObject.getPlayerObject = spy.new(function() return pPlayerObject end)
@@ -268,26 +268,26 @@ describe("Village Jedi Manager - Glowing", function()
                                                testGlowing.countBadges = spy.new(function() return TOTALNUMBEROFBADGESREQUIRED end)
                                        end)
 
-                                       it("Should set the village jedi progression screen play state glowing on the player", function()
+                                       it("Should set the village jedi progression screen play state glowing on the player.", function()
                                                testGlowing:isGlowing(pCreatureObject)
 
                                                assert.spy(VillageJediManagerCommonMocks.setJediProgressionScreenPlayState).was.called_with(pCreatureObject, VILLAGE_JEDI_PROGRESSION_GLOWING)
                                        end)
 
-                                       it("Should create an event to spawn the old man", function()
+                                       it("Should start the old man encounter.", function()
                                                testGlowing:isGlowing(pCreatureObject)
 
-                                               assert.spy(OldManMocks.createSpawnOldManEvent).was.called_with(pCreatureObject)
+                                               assert.spy(OldManEncounterMocks.start).was.called_with(OldManEncounterMocks, pCreatureObject)
                                        end)
                                end)
 
                                describe("and the player does not have all the needed badges", function()
-                                       it("Should not create an event to spawn the old man", function()
+                                       it("Should not start the old man encounter.", function()
                                                testGlowing.countBadges = spy.new(function() return TOTALNUMBEROFBADGESREQUIRED - 1 end)
 
                                                testGlowing:isGlowing(pCreatureObject)
 
-                                               assert.spy(OldManMocks.createSpawnOldManEvent).was.not_called()
+                                               assert.spy(OldManEncounterMocks.start).was.not_called()
                                        end)
                                end)
                        end)
index 77ccaaa..125503c 100644 (file)
@@ -25,6 +25,7 @@ local Task = require("quest.tasks.task")
 local PersistentEvent = require("quest.tasks.persistent_event")
 local ObjectManager = require("managers.object.object_manager")
 local SpawnMobiles = require("utils.spawn_mobiles")
+local Logger = require("utils.logger")
 
 local NOTINABUILDING = 0
 local ENCOUNTER_OBJECTS_STRING = "encounter_objects"
@@ -42,32 +43,42 @@ Encounter = Task:new {
        onEncounterSpawned = nil,
        isEncounterFinished = nil,
        onEncounterClosingIn = nil,
-       onEncounterAtPlayer = nil
+       onEncounterAtPlayer = nil,
+       spawnTask = nil,
+       despawnTask = nil
 }
 
 -- Setup persistent events
 function Encounter:setupSpawnAndDespawnEvents()
-       self.spawnTask = PersistentEvent:new {
-               -- Task properties
-               taskName = "encounter_spawn_task",
-               taskFinish = function(self, pCreatureObject) self.encounter:spawnEncounter(pCreatureObject) end,
-               -- PersistentEvent properties
-               minimumTimeUntilEvent = self.minimumTimeUntilEncounter,
-               maximumTimeUntilEvent = self.maximumTimeUntilEncounter,
-               -- Spawn task properties
-               encounter = self
-       }
-
-       self.despawnTask = PersistentEvent:new {
-               -- Task properties
-               taskName = "encounter_despawn_task",
-               taskFinish = function(self, pCreatureObject) self.encounter:despawnEncounter(pCreatureObject) end,
-               -- PersistentEvent properties
-               minimumTimeUntilEvent = self.encounterDespawnTime,
-               maximumTimeUntilEvent = self.encounterDespawnTime,
-               -- Spawn task properties
-               encounter = self
-       }
+       if self.spawnTask == nil then
+               self.spawnTask = PersistentEvent:new {
+                       -- Task properties
+                       taskName = "encounter_spawn_task",
+                       taskFinish = nil,
+                       -- PersistentEvent properties
+                       minimumTimeUntilEvent = self.minimumTimeUntilEncounter,
+                       maximumTimeUntilEvent = self.maximumTimeUntilEncounter,
+                       handlerName = self.taskName,
+                       handlerFunction = "handleSpawnEvent",
+                       -- Spawn task properties
+                       encounter = self
+               }
+       end
+
+       if self.despawnTask == nil then
+               self.despawnTask = PersistentEvent:new {
+                       -- Task properties
+                       taskName = "encounter_despawn_task",
+                       taskFinish = nil,
+                       -- PersistentEvent properties
+                       minimumTimeUntilEvent = self.encounterDespawnTime,
+                       maximumTimeUntilEvent = self.encounterDespawnTime,
+                       handlerName = self.taskName,
+                       handlerFunction = "handleDespawnEvent",
+                       -- Spawn task properties
+                       encounter = self
+               }
+       end
 end
 
 -- Start the encounter.
@@ -117,6 +128,7 @@ end
 -- Empty handler for the handleEncounterClosingIn event.
 -- @param pCreatureObject pointer to the player object of the player.
 function Encounter:handleEncounterClosingIn(pCreatureObject)
+       Logger:log("Mobiles closing in in encounter " .. self.taskName .. ".", LT_INFO)
        local spawnedObjects = SpawnMobiles.getSpawnedMobiles(pCreatureObject, self.taskName)
        self:callFunctionIfNotNil(self.onEncounterClosingIn, pCreatureObject, spawnedObjects)
 end
@@ -124,6 +136,7 @@ end
 -- Empty handler for the handleEncounterAtPlayer event.
 -- @param pCreatureObject pointer to the player object of the player.
 function Encounter:handleEncounterAtPlayer(pCreatureObject)
+       Logger:log("Mobiles at player in encounter " .. self.taskName .. ".", LT_INFO)
        local spawnedObjects = SpawnMobiles.getSpawnedMobiles(pCreatureObject, self.taskName)
        self:setSpawnedObjectsToFollow(spawnedObjects, nil)
        self:callFunctionIfNotNil(self.onEncounterAtPlayer, pCreatureObject, spawnedObjects)
@@ -133,6 +146,7 @@ end
 -- @param pCreatureObject pointer to the creature object of the player.
 -- @param spawnedObjects list with pointers to the spawned objects.
 function Encounter:createEncounterEvents(pCreatureObject, spawnedObjects)
+       Logger:log("Creating encounter events in " .. self.taskName .. ".", LT_INFO)
        createEvent(ENCOUNTER_CLOSING_IN_TIME, self.taskName, "handleEncounterClosingIn", pCreatureObject)
        createEvent(ENCOUNTER_AT_PLAYER_TIME, self.taskName, "handleEncounterAtPlayer", pCreatureObject)
 end
@@ -153,9 +167,11 @@ end
 -- Create the encounter, spawn objects, setup observers and events.
 -- @param pCreatureObject pointer to the creature object of the player.
 function Encounter:createEncounter(pCreatureObject)
+       Logger:log("Spawning mobiles in encounter " .. self.taskName .. ".", LT_INFO)
        local spawnedObjects = SpawnMobiles.spawnMobiles(pCreatureObject, self.taskName, self.spawnObjectList)
 
        if spawnedObjects ~= nil then
+               Logger:log("Set spawned mobiles to follow in encounter " .. self.taskName .. ".", LT_INFO)
                self:setSpawnedObjectsToFollow(spawnedObjects, pCreatureObject)
                self:createEncounterEvents(pCreatureObject, spawnedObjects)
                self:callFunctionIfNotNil(self.onEncounterSpawned, pCreatureObject, spawnedObjects)
@@ -165,20 +181,25 @@ end
 -- Spawn encounter
 -- Function to call from the spawn event.
 -- @param pCreatureObject pointer to the creature object of the player.
-function Encounter:spawnEncounter(pCreatureObject)
+function Encounter:handleSpawnEvent(pCreatureObject)
+       Logger:log("Spawn encounter in " .. self.taskName .. " triggered.", LT_INFO)
        if self:isPlayerInPositionForEncounter(pCreatureObject) then
                self:createEncounter(pCreatureObject)
        end
+       self:setupSpawnAndDespawnEvents()
        self.despawnTask:start(pCreatureObject)
 end
 
 -- Despawn encounter
 -- Function to call from the despawn event.
 -- @param pCreatureObject pointer to the creature object of the player.
-function Encounter:despawnEncounter(pCreatureObject)
+function Encounter:handleDespawnEvent(pCreatureObject)
+       Logger:log("Despawning mobiles in encounter " .. self.taskName .. ".", LT_INFO)
        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)
diff --git a/MMOCoreORB/bin/scripts/quest/tasks/mocks/task_mocks.lua b/MMOCoreORB/bin/scripts/quest/tasks/mocks/task_mocks.lua
new file mode 100644 (file)
index 0000000..e69de29
index 95c176d..85f38d5 100644 (file)
@@ -1,18 +1,28 @@
 -- Handling of persistent events.
+-- The module ensures that only one event can be scheduled per creature object at the same time.
+-- The event will be scheduled at a random time between the specified interval.
+--
+-- Usage:
+-- Set the minimum and maximum time to the wanted values.
+-- Set the handler name and function.
+-- The handler should as last step always call finish on the persistent event.
+
 local Task = require("quest.tasks.task")
+local Logger = require("utils.logger")
 
 PersistentEvent = Task:new {
        -- Task properties
        taskName = "",
        -- PersistentEvent properties
        minimumTimeUntilEvent = 0,
-       maximumTimeUntilEvent = 0
+       maximumTimeUntilEvent = 0,
+       handlerName = "PersistentEvent",
+       handlerFunction = "handleEvent"
 }
 
--- Handler for the event.
--- @param pCreatureObject pointer to the creature object of the player.
+-- Default handler for the event. Generates error if triggered.
 function PersistentEvent:handleEvent(pCreatureObject)
-       self:finish(pCreatureObject)
+       error("No event handler for the persistent event " .. self.taskName .. " has been specified.")
 end
 
 -- Generate a random time for the persistent event.
@@ -29,14 +39,9 @@ end
 -- Start the event.
 -- @param pCreatureObject pointer to the creature object of the player.
 function PersistentEvent:taskStart(pCreatureObject)
-       createEvent(true, self:getTime(), self.taskName, "handleEvent", pCreatureObject)
-end
-
--- Finish the event.
--- @param pCreatureObject pointer to the creature object of the player.
-function PersistentEvent:taskFinish(pCreatureObject)
-       -- Should be overloaded by the module using this.
-       --error("taskFinish has not been overloaded for the persistent event '" .. PersistentEvent.taskName .. "'.")
+       local time = self:getTime()
+       Logger:log("Creating event with scheduled execution time in " .. time .. " for task " .. self.taskName, LT_INFO)
+       createEvent(true, time, self.handlerName, self.handlerFunction, pCreatureObject)
 end
 
 return PersistentEvent
index 2e01568..d99fe34 100644 (file)
@@ -1,5 +1,6 @@
 -- Base module for all tasks.
 local ObjectManager = require("managers.object.object_manager")
+local Logger = require("utils.logger")
 
 Task = Object:new {
        taskName = "",
@@ -41,7 +42,7 @@ function Task:callFunctionIfNotNil(theFunction, ...)
        if theFunction ~= nil then
                return theFunction(self, unpack(arg))
        else
-               error("The function to call is nil in " .. Task.taskName .. ".", 2)
+               Logger:log("The function to call is nil in " .. Task.taskName .. ".", LT_INFO)
                return nil
        end
 end
@@ -50,6 +51,7 @@ end
 -- @param pCreatureObject pointer to the creature object of the player who should get the task started.
 function Task:start(pCreatureObject)
        if not self:hasTaskStarted(pCreatureObject) then
+               Logger:log("Starting task " .. self.taskName, LT_INFO)
                self:setTaskStarted(pCreatureObject)
                self:callFunctionIfNotNil(self.taskStart, pCreatureObject)
        end
@@ -59,6 +61,7 @@ end
 -- @param pCreatureObject pointer to the creature object of the player who should get the task finished.
 function Task:finish(pCreatureObject)
        if self:hasTaskStarted(pCreatureObject) then
+               Logger:log("Finishing task " .. self.taskName, LT_INFO)
                self:callFunctionIfNotNil(self.taskFinish, pCreatureObject)
                self:setTaskFinished(pCreatureObject)
        end
index 36208cf..27efc93 100644 (file)
@@ -158,55 +158,124 @@ describe("Encounter", function()
        end)
 
        describe("Events", function()
-               describe("Spawn Task Handle Event", function()
+               describe("spawnEncounter", function()
                        describe("When called with a player", function()
-                               local realSpawnEncounter
+                               local realIsPlayerInPositionForEncounter
+                               local realStart
+                               local realCreateEncounter
 
                                setup(function()
-                                       realSpawnEncounter = testEncounter.spawnEncounter
+                                       testEncounter:setupSpawnAndDespawnEvents()
+                                       realIsPlayerInPositionForEncounter = testEncounter.isPlayerInPositionForEncounter
+                                       realStart = testEncounter.despawnTask.start
+                                       realCreateEncounter = testEncounter.createEncounter
                                end)
 
                                teardown(function()
-                                       testEncounter.spawnEncounter = realSpawnEncounter
+                                       testEncounter.isPlayerInPositionForEncounter = realIsPlayerInPositionForEncounter
+                                       testEncounter.despawnTask.start = realStart
+                                       testEncounter.createEncounter = realCreateEncounter
                                end)
 
                                before_each(function()
-                                       testEncounter:start(pCreatureObject)
-                                       testEncounter.spawnEncounter = spy.new(function() end)
+                                       testEncounter.isPlayerInPositionForEncounter = spy.new(function() return false end)
+                                       testEncounter.despawnTask.start = spy.new(function() end)
+                                       testEncounter.createEncounter = spy.new(function() end)
+                               end)
+
+                               it("Should check if the player is in a position where the encounter can happen.", function()
+                                       testEncounter:handleSpawnEvent(pCreatureObject)
+
+                                       assert.spy(testEncounter.isPlayerInPositionForEncounter).was.called_with(testEncounter, pCreatureObject)
+                               end)
+
+                               it("Should start the despawn task.", function()
+                                       testEncounter:handleSpawnEvent(pCreatureObject)
+
+                                       assert.spy(testEncounter.despawnTask.start).was.called_with(testEncounter.despawnTask, pCreatureObject)
+                               end)
 
-                                       creatureObject.getScreenPlayState = spy.new(function() return TASK_STARTED end)
+                               describe("and the player is in a position where the encounter can be spawned.", function()
+                                       before_each(function()
+                                               testEncounter.isPlayerInPositionForEncounter = spy.new(function() return true end)
+                                       end)
+
+                                       it("Should call the createEncounter function.", function()
+                                               testEncounter:handleSpawnEvent(pCreatureObject)
+
+                                               assert.spy(testEncounter.createEncounter).was.called_with(testEncounter, pCreatureObject)
+                                       end)
                                end)
 
-                               it("Should call the spawnEncounter function on the set encounter.", function()
-                                       testEncounter.spawnTask:handleEvent(pCreatureObject)
+                               describe("and the player is not in a position where the encounter can be spawned.", function()
+                                       it("Should not call the createEncounter function.", function()
+                                               testEncounter:handleSpawnEvent(pCreatureObject)
 
-                                       assert.spy(testEncounter.spawnEncounter).was.called_with(testEncounter, pCreatureObject)
+                                               assert.spy(testEncounter.createEncounter).was.not_called()
+                                       end)
                                end)
                        end)
                end)
-               describe("Despawn Task Handle Event", function()
+
+               describe("handleDespawnEvent", function()
                        describe("When called with a player", function()
-                               local realDespawnEncounter
+                               it("Should despawn the encounter objects.", function()
+                                       testEncounter:handleDespawnEvent(pCreatureObject)
 
-                               setup(function()
-                                       realDespawnEncounter = testEncounter.despawnEncounter
+                                       assert.spy(SpawnMobilesMocks.despawnMobiles).was.called_with(pCreatureObject, testEncounter.taskName)
                                end)
 
-                               teardown(function()
-                                       testEncounter.despawnEncounter = realDespawnEncounter
+                               it("Should call the isEncounterFinished function.", function()
+                                       testEncounter:handleDespawnEvent(pCreatureObject)
+
+                                       assert.spy(testEncounter.isEncounterFinished).was.called_with(testEncounter, pCreatureObject)
                                end)
 
-                               before_each(function()
-                                       testEncounter:start(pCreatureObject)
-                                       testEncounter.despawnEncounter = spy.new(function() end)
+                               describe("and the encounter is not finished yet", function()
+                                       local realSpawnTask
 
-                                       creatureObject.getScreenPlayState = spy.new(function() return TASK_STARTED end)
+                                       setup(function()
+                                               testEncounter:setupSpawnAndDespawnEvents()
+                                               realSpawnTask = testEncounter.spawnTask
+                                       end)
+
+                                       teardown(function()
+                                               testEncounter.spawnTask = realSpawnTask
+                                       end)
+
+                                       before_each(function()
+                                               testEncounter.spawnTask = {}
+                                               testEncounter.spawnTask.start = spy.new(function() end)
+                                       end)
+
+                                       it("Should start the spawn task.", function()
+                                               testEncounter:handleDespawnEvent(pCreatureObject)
+
+                                               assert.spy(testEncounter.spawnTask.start).was.called_with(testEncounter.spawnTask, pCreatureObject)
+                                       end)
                                end)
 
-                               it("Should call the despawnEncounter function on the set encounter.", function()
-                                       testEncounter.despawnTask:handleEvent(pCreatureObject)
+                               describe("and the encounter is finished", function()
+                                       local realFinish
+
+                                       setup(function()
+                                               realFinish = testEncounter.finish
+                                       end)
+
+                                       teardown(function()
+                                               testEncounter.finish = realFinish
+                                       end)
+
+                                       before_each(function()
+                                               testEncounter.isEncounterFinished = spy.new(function() return true end)
+                                               testEncounter.finish = spy.new(function() end)
+                                       end)
 
-                                       assert.spy(testEncounter.despawnEncounter).was.called_with(testEncounter, pCreatureObject)
+                                       it("Should call finish on the encounter.", function()
+                                               testEncounter:handleDespawnEvent(pCreatureObject)
+
+                                               assert.spy(testEncounter.finish).was.called_with(testEncounter, pCreatureObject)
+                                       end)
                                end)
                        end)
                end)
@@ -250,15 +319,6 @@ describe("Encounter", function()
 
                describe("setupSpawnAndDespawnEvents", function()
                        describe("When called with a player", function()
-                               before_each(function()
-                                       testEncounter.spawnTask.minimumTimeUntilEvent = 0
-                                       testEncounter.spawnTask.maximumTimeUntilEvent = 0
-                                       testEncounter.spawnTask.encounter = nil
-                                       testEncounter.despawnTask.minimumTimeUntilEvent = 0
-                                       testEncounter.despawnTask.maximumTimeUntilEvent = 0
-                                       testEncounter.despawnTask.encounter = nil
-                               end)
-
                                it("Should set the minimum event time on the spawn task to the minimum spawn time for the encounter.", function()
                                        testEncounter:taskStart(pCreatureObject)
 
@@ -297,64 +357,6 @@ describe("Encounter", function()
                        end)
                end)
 
-               describe("spawnEncounter", function()
-                       describe("When called with a player", function()
-                               local realIsPlayerInPositionForEncounter
-                               local realStart
-                               local realCreateEncounter
-
-                               setup(function()
-                                       realIsPlayerInPositionForEncounter = testEncounter.isPlayerInPositionForEncounter
-                                       realStart = testEncounter.despawnTask.start
-                                       realCreateEncounter = testEncounter.createEncounter
-                               end)
-
-                               teardown(function()
-                                       testEncounter.isPlayerInPositionForEncounter = realIsPlayerInPositionForEncounter
-                                       testEncounter.despawnTask.start = realStart
-                                       testEncounter.createEncounter = realCreateEncounter
-                               end)
-
-                               before_each(function()
-                                       testEncounter.isPlayerInPositionForEncounter = spy.new(function() return false end)
-                                       testEncounter.despawnTask.start = spy.new(function() end)
-                                       testEncounter.createEncounter = spy.new(function() end)
-                               end)
-
-                               it("Should check if the player is in a position where the encounter can happen.", function()
-                                       testEncounter:spawnEncounter(pCreatureObject)
-
-                                       assert.spy(testEncounter.isPlayerInPositionForEncounter).was.called_with(testEncounter, pCreatureObject)
-                               end)
-
-                               it("Should start the despawn task.", function()
-                                       testEncounter:spawnEncounter(pCreatureObject)
-
-                                       assert.spy(testEncounter.despawnTask.start).was.called_with(testEncounter.despawnTask, pCreatureObject)
-                               end)
-
-                               describe("and the player is in a position where the encounter can be spawned.", function()
-                                       before_each(function()
-                                               testEncounter.isPlayerInPositionForEncounter = spy.new(function() return true end)
-                                       end)
-
-                                       it("Should call the createEncounter function.", function()
-                                               testEncounter:spawnEncounter(pCreatureObject)
-
-                                               assert.spy(testEncounter.createEncounter).was.called_with(testEncounter, pCreatureObject)
-                                       end)
-                               end)
-
-                               describe("and the player is not in a position where the encounter can be spawned.", function()
-                                       it("Should not call the createEncounter function.", function()
-                                               testEncounter:spawnEncounter(pCreatureObject)
-
-                                               assert.spy(testEncounter.createEncounter).was.not_called()
-                                       end)
-                               end)
-                       end)
-               end)
-
                describe("isPlayerInPositionForEncounter", function()
                        describe("When called with the player as argument", function()
                                local realIsPlayerOnline
@@ -622,68 +624,6 @@ describe("Encounter", function()
                        end)
                end)
 
-               describe("despawnEncounter", function()
-                       describe("When called with a player", function()
-                               it("Should despawn the encounter objects.", function()
-                                       testEncounter:despawnEncounter(pCreatureObject)
-
-                                       assert.spy(SpawnMobilesMocks.despawnMobiles).was.called_with(pCreatureObject, testEncounter.taskName)
-                               end)
-
-                               it("Should call the isEncounterFinished function.", function()
-                                       testEncounter:despawnEncounter(pCreatureObject)
-
-                                       assert.spy(testEncounter.isEncounterFinished).was.called_with(testEncounter, pCreatureObject)
-                               end)
-
-                               describe("and the encounter is not finished yet", function()
-                                       local realSpawnTask
-
-                                       setup(function()
-                                               realSpawnTask = testEncounter.spawnTask
-                                       end)
-
-                                       teardown(function()
-                                               testEncounter.spawnTask = realSpawnTask
-                                       end)
-
-                                       before_each(function()
-                                               testEncounter.spawnTask = {}
-                                               testEncounter.spawnTask.start = spy.new(function() end)
-                                       end)
-
-                                       it("Should start the spawn task.", function()
-                                               testEncounter:despawnEncounter(pCreatureObject)
-
-                                               assert.spy(testEncounter.spawnTask.start).was.called_with(testEncounter.spawnTask, pCreatureObject)
-                                       end)
-                               end)
-
-                               describe("and the encounter is finished", function()
-                                       local realFinish
-
-                                       setup(function()
-                                               realFinish = testEncounter.finish
-                                       end)
-
-                                       teardown(function()
-                                               testEncounter.finish = realFinish
-                                       end)
-
-                                       before_each(function()
-                                               testEncounter.isEncounterFinished = spy.new(function() return true end)
-                                               testEncounter.finish = spy.new(function() end)
-                                       end)
-
-                                       it("Should call finish on the encounter.", function()
-                                               testEncounter:despawnEncounter(pCreatureObject)
-
-                                               assert.spy(testEncounter.finish).was.called_with(testEncounter, pCreatureObject)
-                                       end)
-                               end)
-                       end)
-               end)
-
                describe("handleEncounterClosingIn", function()
                        describe("When called", function()
                                before_each(function()
index 15b8750..6e71246 100644 (file)
@@ -7,7 +7,9 @@ local testPersistentEvent = PersistentEvent:new {
        taskFinish = spy.new(function() end),
        -- PersistentEvent properties
        minimumTimeUntilEvent = 10,
-       maximumTimeUntilEvent = 10
+       maximumTimeUntilEvent = 10,
+       handlerName = "TestPersistentEvent",
+       handlerFunction = "handleEventTest"
 }
 
 local TASK_STARTED = 0xABCD
@@ -86,26 +88,26 @@ describe("Persistent Event", function()
        end)
 
        describe("Event handlers", function()
-               describe("handleSpawnEvent", function()
+               describe("handleEvent", function()
                        describe("When called with a player", function()
-                               local realFinish
+                               local realError
 
                                setup(function()
-                                       realFinish = testPersistentEvent.finish
+                                       realError = error
                                end)
 
                                teardown(function()
-                                       testPersistentEvent.finish = realFinish
+                                       error = realError
                                end)
 
                                before_each(function()
-                                       testPersistentEvent.finish = spy.new(function() end)
+                                       error = spy.new(function() end)
                                end)
 
-                               it("Should check if the player is in a position where the encounter can happen.", function()
+                               it("Should generate an error.", function()
                                        testPersistentEvent:handleEvent(pCreatureObject)
 
-                                       assert.spy(testPersistentEvent.finish).was.called_with(testPersistentEvent, pCreatureObject)
+                                       assert.spy(error).was.called(1)
                                end)
                        end)
                end)
@@ -136,31 +138,7 @@ describe("Persistent Event", function()
                                it("Should create a spawn event.", function()
                                        testPersistentEvent:taskStart(pCreatureObject)
 
-                                       assert.spy(createEvent).was.called_with(true, eventTime, testPersistentEvent.taskName, "handleEvent", pCreatureObject)
-                               end)
-                       end)
-               end)
-
-               describe("taskFinish", function()
-                       describe("When called", function()
-                               --local realError
-
-                               setup(function()
-                                       --realError = error
-                               end)
-
-                               teardown(function()
-                                       --error = realError
-                               end)
-
-                               setup(function()
-                                       --error = spy.new(function() end)
-                               end)
-
-                               it("Should generate an error.", function()
-                                       testPersistentEvent:taskFinish(pCreatureObject)
-
-                                       --assert.spy(error).was.called(1)
+                                       assert.spy(createEvent).was.called_with(true, eventTime, testPersistentEvent.handlerName, testPersistentEvent.handlerFunction, pCreatureObject)
                                end)
                        end)
                end)
index 81adb50..eb857a2 100644 (file)
@@ -8,6 +8,8 @@ LT_TRACE = 1
 
 local MAX_NUMBER_OF_ENTRIES = 100
 
+local FORCE_PRINT = false
+
 Logger = {}
 Logger.logEntries = {}
 
@@ -18,7 +20,17 @@ function Logger:log(message, level)
        if table.getn(Logger.logEntries) > MAX_NUMBER_OF_ENTRIES then
                table.remove(Logger.logEntries, 1)
        end
-       table.insert(Logger.logEntries, { message = message, level = level, info = debug.getinfo(2) })
+
+       local info = debug.getinfo(2)
+       if info.name == nil then
+               info.name = "unknown function"
+       end
+
+       table.insert(Logger.logEntries, { message = message, level = level, info = info })
+
+       if not _TEST and FORCE_PRINT then
+               print(message .. " - " .. info.name .. ", " .. info.short_src .. ", " .. info.currentline)
+       end
 end
 
 -- Print the log and clear the log.
index 90b90fc..8d42d04 100644 (file)
@@ -22,6 +22,7 @@
 --                                                                     This value must be lower than the current list item number.
 
 local ObjectManager = require("managers.object.object_manager")
+local Logger = require("utils.logger")
 
 local SpawnMobiles = {}
 
@@ -140,18 +141,21 @@ function SpawnMobiles.spawnMobileObjects(pCreatureObject, mobileList, spawnPoint
        return spawnedObjects
 end
 
--- Save id of the spawned encounter objects on the player for later use.
+-- Save id of the spawned mobile objects on the player for later use.
 -- @param pCreatureObject pointer to the creature object of the player.
 -- @param prefix the prefix to use for storing information about the spawned mobiles.
 -- @param spawnedObjects list with pointers to the spawned objects.
-function SpawnMobiles.saveSpawnedEncounterObjects(pCreatureObject, prefix, spawnedObjects)
+function SpawnMobiles.saveSpawnedMobileObjects(pCreatureObject, prefix, spawnedObjects)
        ObjectManager.withSceneObject(pCreatureObject, function(playerSceneObject)
                writeData(playerSceneObject:getObjectID() .. prefix .. SPAWN_MOBILES_STRING .. IN_USE_STRING, PREFIX_IN_USE)
+               Logger:log(playerSceneObject:getObjectID() .. prefix .. SPAWN_MOBILES_STRING .. IN_USE_STRING .. " set to " .. PREFIX_IN_USE)
                writeData(playerSceneObject:getObjectID() .. prefix .. SPAWN_MOBILES_STRING .. NUMBER_OF_SPAWNS_STRING, table.getn(spawnedObjects))
+               Logger:log(playerSceneObject:getObjectID() .. prefix .. SPAWN_MOBILES_STRING .. NUMBER_OF_SPAWNS_STRING .. " set to " .. table.getn(spawnedObjects))
 
                for i = 1, table.getn(spawnedObjects), 1 do
                        ObjectManager.withSceneObject(spawnedObjects[i], function(sceneObject)
                                writeData(playerSceneObject:getObjectID() .. prefix .. SPAWN_MOBILES_STRING .. i, sceneObject:getObjectID())
+                               Logger:log(playerSceneObject:getObjectID() .. prefix .. SPAWN_MOBILES_STRING .. i .. " set to " .. sceneObject:getObjectID())
                        end)
                end
        end)
@@ -196,9 +200,11 @@ function SpawnMobiles.getSpawnedMobilePointersList(pCreatureObject, prefix)
 
        ObjectManager.withSceneObject(pCreatureObject, function(playerSceneObject)
                local numberOfSpawns = readData(playerSceneObject:getObjectID() .. prefix .. SPAWN_MOBILES_STRING .. NUMBER_OF_SPAWNS_STRING)
+               Logger:log(playerSceneObject:getObjectID() .. prefix .. SPAWN_MOBILES_STRING .. NUMBER_OF_SPAWNS_STRING .. " = " .. numberOfSpawns, LT_INFO)
 
                for i = 1, numberOfSpawns, 1 do
                        local mobileID = readData(playerSceneObject:getObjectID() .. prefix .. SPAWN_MOBILES_STRING .. i)
+                       Logger:log(playerSceneObject:getObjectID() .. prefix .. SPAWN_MOBILES_STRING .. i .. " = " .. mobileID, LT_INFO)
                        local mobile = getSceneObject(mobileID)
 
                        if mobile ~= nil then
@@ -215,6 +221,7 @@ end
 -- @param prefix the prefix to read the spawned mobiles from.
 -- @return a list with pointers to the spawned mobiles or nil if none have been spawned.
 function SpawnMobiles.getSpawnedMobiles(pCreatureObject, prefix)
+       Logger:log("Getting spawned mobiles for prefix '" .. prefix .. "'.", LT_INFO)
        if not SpawnMobiles.isPrefixFree(pCreatureObject, prefix) then
                return SpawnMobiles.getSpawnedMobilePointersList(pCreatureObject, prefix)
        else
diff --git a/MMOCoreORB/bin/scripts/utils/tests/logger_Test.lua b/MMOCoreORB/bin/scripts/utils/tests/logger_Test.lua
new file mode 100644 (file)
index 0000000..8b13789
--- /dev/null
@@ -0,0 +1 @@
+
index 23e8a93..976bce5 100644 (file)
@@ -733,7 +733,7 @@ describe("Spawn Mobile", function()
                                end)
 
                                it("Should save each object id on the player witht the encounter name as prefix and a running number", function()
-                                       SpawnMobiles.saveSpawnedEncounterObjects(pCreatureObject, prefix, spawnedMobilesList)
+                                       SpawnMobiles.saveSpawnedMobileObjects(pCreatureObject, prefix, spawnedMobilesList)
 
                                        assert.spy(writeData).was.called(7)
                                end)