Instructions Jenkins Doxygen

[Added] possiblity to return a value through the callFunctionIfNotNil 28/1228/2
authorLoshult <loshult@swgemu.com>
Fri, 6 Dec 2013 19:44:30 +0000 (19:44 +0000)
committerLoshult <loshult@swgemu.com>
Mon, 9 Dec 2013 12:03:57 +0000 (12:03 +0000)
function in quest task module.
[Added] error when calling a function that is nil through the
callFunctionIfNotNil function in the quest task module.
[Added] return value in mocks for SpawnMobiles.spawnMobile.
[Changed] getSpawnedMobiles to be an interface function of SpawnMobiles
module.
[Added] Quest encounter module.

Change-Id: I179df33c8a143c2b37fbebae556e0a287a5bc4d6

MMOCoreORB/bin/scripts/quest/tasks/encounter.lua [new file with mode: 0644]
MMOCoreORB/bin/scripts/quest/tasks/mocks/encounter_mocks.lua [new file with mode: 0644]
MMOCoreORB/bin/scripts/quest/tasks/task.lua
MMOCoreORB/bin/scripts/quest/tasks/tests/encounter_Test.lua [new file with mode: 0644]
MMOCoreORB/bin/scripts/quest/tasks/tests/task_Test.lua
MMOCoreORB/bin/scripts/utils/mocks/spawn_mobiles_mocks.lua
MMOCoreORB/bin/scripts/utils/spawn_mobiles.lua
MMOCoreORB/bin/scripts/utils/tests/spawn_mobiles_Test.lua

diff --git a/MMOCoreORB/bin/scripts/quest/tasks/encounter.lua b/MMOCoreORB/bin/scripts/quest/tasks/encounter.lua
new file mode 100644 (file)
index 0000000..77ccaaa
--- /dev/null
@@ -0,0 +1,188 @@
+-- This module handles an encounter in the quest system.
+-- An encounter is an event where the player should encounter something after a while.
+-- The module takes care of scheduling the event, tringgering the event, clean up etc.
+-- The user supplies the module with information about what the encounter is about.
+--
+-- Parameters
+-- taskName - need to be the name of the class inheriting the Encounter class to get the observers and events to work.
+-- minimumTimeUntilEncounter - the minimum time until the encounter should happen in ms.
+-- maximumTimeUntilEncounter - the maximum time until the encounter should happen in ms.
+-- encounterDespawnTime - time in ms from the moment the encounter is spawned until it should be despawned.
+-- customSpawnBehaviour - function that is called when the encounter has been spawned with the pCreatureObject
+--                        and a list of pointers to the creature objects of the spawned objects
+-- spawnObjectList - a list with one element per object that should be spawned in the encounter.
+--                                      It uses the format from the spawn mobile unit in utils.
+--                   Each element should define a table with the following parameters:
+--                    - template - the template of the mobile to spawn.
+--                                   - minimumDistance - the minimum distance for the mobile to spawn at from the center reference point.
+--                                   - maximumDistance - the maximum distance for the mobile to spawn at from the center reference point.
+--                                   - referencePoint - index of the spawned mobile to use as center reference point for this mobile.
+--                                                                          0 = use provided coordinates, 1 = use the spawn position of the first mobile in the mobileList, etc.
+--                                                                          This value must be lower than the current list item number.
+--                    - followPlayer - boolean value indicating if the spawned object should be set to follow the player or not.
+
+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 NOTINABUILDING = 0
+local ENCOUNTER_OBJECTS_STRING = "encounter_objects"
+local ENCOUNTER_CLOSING_IN_TIME = 10 * 1000
+local ENCOUNTER_AT_PLAYER_TIME = 30 * 1000
+
+Encounter = Task:new {
+       -- Task properties
+       taskName = "",
+       -- Encounter properties
+       minimumTimeUntilEncounter = 0,
+       maximumTimeUntilEncounter = 0,
+       encounterDespawnTime = 0,
+       spawnObjectList = {},
+       onEncounterSpawned = nil,
+       isEncounterFinished = nil,
+       onEncounterClosingIn = nil,
+       onEncounterAtPlayer = 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
+       }
+end
+
+-- Start the encounter.
+-- @param pCreatureObject pointer to the creature object of the player.
+function Encounter:taskStart(pCreatureObject)
+       self:setupSpawnAndDespawnEvents()
+       self.spawnTask:start(pCreatureObject)
+end
+
+-- Check if the player is online.
+-- @param pCreatureObject pointer to the creature object of the player who should be checked if online.
+-- @return true if the player is online.
+function Encounter:isPlayerOnline(pCreatureObject)
+       return ObjectManager.withCreaturePlayerObject(pCreatureObject, function(playerObject)
+               return playerObject:isOnline()
+       end) == true
+end
+
+-- Check if the player is in a building or not.
+-- @param pCreatureObject pointer to the creature object of the player that should be checked for being in a building or not.
+-- @return true if the player is in a building.
+function Encounter:isPlayerInABuilding(pCreatureObject)
+       return ObjectManager.withSceneObject(pCreatureObject, function(sceneObject)
+               return not (sceneObject:getParentID() == NOTINABUILDING)
+       end) == true
+end
+
+-- Check if the player is in a NPC city.
+-- @param pCreatureObject pointer to the creature object of the player who should be checked for being in a NPC city.
+-- return true if the player is within a NPC city.
+function Encounter:isPlayerInNpcCity(pCreatureObject)
+       return ObjectManager.withSceneObject(pCreatureObject, function(sceneObject)
+               local pCityRegion = getCityRegionAt(sceneObject:getZoneName(), sceneObject:getWorldPositionX(), sceneObject:getWorldPositionY())
+               local inNpcCity = ObjectManager.withCityRegion(pCityRegion, function(cityRegion)
+                       return not cityRegion:isClientRegion()
+               end)
+               return inNpcCity == true
+       end) == true
+end
+
+-- Check if the player is in a position where the encounter can be spawned.
+-- @param pCreatureObject pointer to the player object of the player.
+function Encounter:isPlayerInPositionForEncounter(pCreatureObject)
+       return (self:isPlayerOnline(pCreatureObject) and not self:isPlayerInABuilding(pCreatureObject) and not self:isPlayerInNpcCity(pCreatureObject))
+end
+
+-- Empty handler for the handleEncounterClosingIn event.
+-- @param pCreatureObject pointer to the player object of the player.
+function Encounter:handleEncounterClosingIn(pCreatureObject)
+       local spawnedObjects = SpawnMobiles.getSpawnedMobiles(pCreatureObject, self.taskName)
+       self:callFunctionIfNotNil(self.onEncounterClosingIn, pCreatureObject, spawnedObjects)
+end
+
+-- Empty handler for the handleEncounterAtPlayer event.
+-- @param pCreatureObject pointer to the player object of the player.
+function Encounter:handleEncounterAtPlayer(pCreatureObject)
+       local spawnedObjects = SpawnMobiles.getSpawnedMobiles(pCreatureObject, self.taskName)
+       self:setSpawnedObjectsToFollow(spawnedObjects, nil)
+       self:callFunctionIfNotNil(self.onEncounterAtPlayer, pCreatureObject, spawnedObjects)
+end
+
+-- Create the events for the encounter.
+-- @param pCreatureObject pointer to the creature object of the player.
+-- @param spawnedObjects list with pointers to the spawned objects.
+function Encounter:createEncounterEvents(pCreatureObject, spawnedObjects)
+       createEvent(ENCOUNTER_CLOSING_IN_TIME, self.taskName, "handleEncounterClosingIn", pCreatureObject)
+       createEvent(ENCOUNTER_AT_PLAYER_TIME, self.taskName, "handleEncounterAtPlayer", pCreatureObject)
+end
+
+-- Set all spawned objects to follow an object.
+-- @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)
+               end
+       end
+end
+
+-- Create the encounter, spawn objects, setup observers and events.
+-- @param pCreatureObject pointer to the creature object of the player.
+function Encounter:createEncounter(pCreatureObject)
+       local spawnedObjects = SpawnMobiles.spawnMobiles(pCreatureObject, self.taskName, self.spawnObjectList)
+
+       if spawnedObjects ~= nil then
+               self:setSpawnedObjectsToFollow(spawnedObjects, pCreatureObject)
+               self:createEncounterEvents(pCreatureObject, spawnedObjects)
+               self:callFunctionIfNotNil(self.onEncounterSpawned, pCreatureObject, spawnedObjects)
+       end
+end
+
+-- Spawn encounter
+-- Function to call from the spawn event.
+-- @param pCreatureObject pointer to the creature object of the player.
+function Encounter:spawnEncounter(pCreatureObject)
+       if self:isPlayerInPositionForEncounter(pCreatureObject) then
+               self:createEncounter(pCreatureObject)
+       end
+       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)
+       SpawnMobiles.despawnMobiles(pCreatureObject, self.taskName)
+
+       if not self:callFunctionIfNotNil(self.isEncounterFinished, pCreatureObject) then
+               self.spawnTask:start(pCreatureObject)
+       else
+               self:finish(pCreatureObject)
+       end
+end
+
+return Encounter
diff --git a/MMOCoreORB/bin/scripts/quest/tasks/mocks/encounter_mocks.lua b/MMOCoreORB/bin/scripts/quest/tasks/mocks/encounter_mocks.lua
new file mode 100644 (file)
index 0000000..e69de29
index b7272e5..2e01568 100644 (file)
@@ -37,11 +37,12 @@ end
 -- An error will be issued if the function is nil.
 -- @param theFunction the function to call.
 -- @param argument the argument to use for the function.
-function Task:callFunctionIfNotNil(theFunction,  argument)
+function Task:callFunctionIfNotNil(theFunction, ...)
        if theFunction ~= nil then
-               theFunction(self, argument)
+               return theFunction(self, unpack(arg))
        else
-               --error("The function to call is nil in " .. Task.taskName .. ".", 2)
+               error("The function to call is nil in " .. Task.taskName .. ".", 2)
+               return nil
        end
 end
 
diff --git a/MMOCoreORB/bin/scripts/quest/tasks/tests/encounter_Test.lua b/MMOCoreORB/bin/scripts/quest/tasks/tests/encounter_Test.lua
new file mode 100644 (file)
index 0000000..36208cf
--- /dev/null
@@ -0,0 +1,744 @@
+local DirectorManagerMocks = require("screenplays.mocks.director_manager_mocks")
+local Encounter = require("quest.tasks.encounter")
+local SpawnMobilesMocks = require("utils.mocks.spawn_mobiles_mocks")
+
+local testEncounter = Encounter:new {
+       -- Task properties
+       taskName = "testEncounter",
+       -- Encounter properties
+       minimumTimeUntilEncounter = 10,
+       maximumTimeUntilEncounter = 10,
+       encounterDespawnTime = 5
+}
+
+local TASK_STARTED = 0xABCD
+local CLOSING_IN_TIME = 10 * 1000
+local AT_PLAYER_TIME = 30 * 1000
+
+describe("Encounter", function()
+       local pCreatureObject = { "creatureObjectPointer" }
+       local pPlayerObject = { "playerObjectPointer" }
+       local pCityRegion = { "cityRegionPointer" }
+       local creatureObject
+       local playerObject
+       local sceneObjectPlayer
+       local cityRegion
+       local playerXCoordinate = 33
+       local playerYCoordinate = 22
+       local playerZoneName = "testzone"
+       local encounterTemplateName = "old_man"
+       local playerId = 12345678
+       local spawnPoints = {
+               { 1, 2, 3 },
+               { 4, 5, 6 },
+               { 7, 8, 9 }
+       }
+       local playerParentID = 0
+       local pSpawnedObject1 = { "spawnedObjectPointer1" }
+       local pSpawnedObject2 = { "spawnedObjectPointer2" }
+       local pSpawnedObject3 = { "spawnedObjectPointer3" }
+       local aiAgentObject1
+       local aiAgentObject2
+       local aiAgentObject3
+       local spawnedObjects = {
+               pSpawnedObject1,
+               pSpawnedObject2,
+               pSpawnedObject3
+       }
+
+       setup(function()
+               DirectorManagerMocks.mocks.setup()
+               SpawnMobilesMocks.mocks.setup()
+       end)
+
+       teardown(function()
+               DirectorManagerMocks.mocks.teardown()
+               SpawnMobilesMocks.mocks.teardown()
+       end)
+
+       before_each(function()
+               DirectorManagerMocks.mocks.before_each()
+               SpawnMobilesMocks.mocks.before_each()
+
+               creatureObject = {}
+               creatureObject.setScreenPlayState = spy.new(function() end)
+               creatureObject.getScreenPlayState = spy.new(function() return 0 end)
+               creatureObject.getPlayerObject = spy.new(function() return pPlayerObject end)
+               creatureObject.removeScreenPlayState = spy.new(function() end)
+               DirectorManagerMocks.creatureObjects[pCreatureObject] = creatureObject
+
+               sceneObjectPlayer = {}
+               sceneObjectPlayer.getParentID = spy.new(function() return playerParentID end)
+               sceneObjectPlayer.getObjectID = spy.new(function() return playerId end)
+               sceneObjectPlayer.getZoneName = spy.new(function() return playerZoneName end)
+               sceneObjectPlayer.getWorldPositionX = spy.new(function() return playerXCoordinate end)
+               sceneObjectPlayer.getWorldPositionY = spy.new(function() return playerYCoordinate end)
+               DirectorManagerMocks.sceneObjects[pCreatureObject] = sceneObjectPlayer
+
+               aiAgentObject1 = {}
+               aiAgentObject1.setFollowObject = spy.new(function() end)
+               DirectorManagerMocks.aiAgents[pSpawnedObject1] = aiAgentObject1
+
+               aiAgentObject2 = {}
+               aiAgentObject2.setFollowObject = spy.new(function() end)
+               DirectorManagerMocks.aiAgents[pSpawnedObject2] = aiAgentObject2
+
+               aiAgentObject3 = {}
+               aiAgentObject3.setFollowObject = spy.new(function() end)
+               DirectorManagerMocks.aiAgents[pSpawnedObject3] = aiAgentObject3
+
+               playerObject = {}
+               playerObject.isOnline = spy.new(function() return true end)
+               DirectorManagerMocks.playerObjects[pPlayerObject] = playerObject
+
+               cityRegion = {}
+               cityRegion.isClientRegion = spy.new(function() return false end)
+               DirectorManagerMocks.cityRegions[pCityRegion] = cityRegion
+
+               testEncounter.spawnObjectList = {
+                       { template = encounterTemplateName, referencePoint = 0, minimumDistance = 32, maximumDistance = 64, followPlayer = true },
+                       { template = encounterTemplateName, referencePoint = 0, minimumDistance = 3, maximumDistance = 6, followPlayer = false },
+                       { template = encounterTemplateName, referencePoint = 1, minimumDistance = 16, maximumDistance = 32, followPlayer = true }
+               }
+               testEncounter.onEncounterSpawned = spy.new(function() end)
+               testEncounter.isEncounterFinished = spy.new(function() return false end)
+               testEncounter.onEncounterClosingIn = spy.new(function() end)
+               testEncounter.onEncounterAtPlayer = spy.new(function() end)
+       end)
+
+       describe("Interface functions", function()
+               describe("start", function()
+                       local realTaskStart
+
+                       setup(function()
+                               realTaskStart = testEncounter.taskStart
+                       end)
+
+                       teardown(function()
+                               testEncounter.taskStart = realTaskStart
+                       end)
+
+                       before_each(function()
+                               testEncounter.taskStart = spy.new(function() end)
+                       end)
+
+                       describe("When called with a player", function()
+                               it("Should call the private taskStart function.", function()
+                                       testEncounter:start(pCreatureObject)
+
+                                       assert.spy(testEncounter.taskStart).was.called_with(testEncounter, pCreatureObject)
+                               end)
+                       end)
+               end)
+
+               describe("finish", function()
+                       local realTaskFinish
+
+                       setup(function()
+                               realTaskFinish = testEncounter.taskFinish
+                       end)
+
+                       teardown(function()
+                               testEncounter.taskFinish = realTaskFinish
+                       end)
+
+                       before_each(function()
+                               testEncounter.taskFinish = spy.new(function() end)
+                               creatureObject.getScreenPlayState = spy.new(function() return TASK_STARTED end)
+                       end)
+
+                       describe("When called with a player", function()
+                               it("Should call the private taskFinish function.", function()
+                                       testEncounter:finish(pCreatureObject)
+
+                                       assert.spy(testEncounter.taskFinish).was.called_with(testEncounter, pCreatureObject)
+                               end)
+                       end)
+               end)
+       end)
+
+       describe("Events", function()
+               describe("Spawn Task Handle Event", function()
+                       describe("When called with a player", function()
+                               local realSpawnEncounter
+
+                               setup(function()
+                                       realSpawnEncounter = testEncounter.spawnEncounter
+                               end)
+
+                               teardown(function()
+                                       testEncounter.spawnEncounter = realSpawnEncounter
+                               end)
+
+                               before_each(function()
+                                       testEncounter:start(pCreatureObject)
+                                       testEncounter.spawnEncounter = spy.new(function() end)
+
+                                       creatureObject.getScreenPlayState = spy.new(function() return TASK_STARTED end)
+                               end)
+
+                               it("Should call the spawnEncounter function on the set encounter.", function()
+                                       testEncounter.spawnTask:handleEvent(pCreatureObject)
+
+                                       assert.spy(testEncounter.spawnEncounter).was.called_with(testEncounter, pCreatureObject)
+                               end)
+                       end)
+               end)
+               describe("Despawn Task Handle Event", function()
+                       describe("When called with a player", function()
+                               local realDespawnEncounter
+
+                               setup(function()
+                                       realDespawnEncounter = testEncounter.despawnEncounter
+                               end)
+
+                               teardown(function()
+                                       testEncounter.despawnEncounter = realDespawnEncounter
+                               end)
+
+                               before_each(function()
+                                       testEncounter:start(pCreatureObject)
+                                       testEncounter.despawnEncounter = spy.new(function() end)
+
+                                       creatureObject.getScreenPlayState = spy.new(function() return TASK_STARTED end)
+                               end)
+
+                               it("Should call the despawnEncounter function on the set encounter.", function()
+                                       testEncounter.despawnTask:handleEvent(pCreatureObject)
+
+                                       assert.spy(testEncounter.despawnEncounter).was.called_with(testEncounter, pCreatureObject)
+                               end)
+                       end)
+               end)
+       end)
+
+       describe("Private functions", function()
+               describe("taskStart", function()
+                       describe("When called with a player", function()
+                               local realSpawnTask
+                               local realSetupSpawnAndDespawnEvents
+
+                               setup(function()
+                                       realSpawnTask = testEncounter.spawnTask
+                                       realSetupSpawnAndDespawnEvents = testEncounter.setupSpawnAndDespawnEvents
+                               end)
+
+                               teardown(function()
+                                       testEncounter.spawnTask = realSpawnTask
+                                       testEncounter.setupSpawnAndDespawnEvents = realSetupSpawnAndDespawnEvents
+                               end)
+
+                               before_each(function()
+                                       testEncounter.spawnTask = {}
+                                       testEncounter.spawnTask.start = spy.new(function() end)
+                                       testEncounter.setupSpawnAndDespawnEvents = spy.new(function() end)
+                               end)
+
+                               it("Should setup the spawn and despawn events.", function()
+                                       testEncounter:taskStart(pCreatureObject)
+
+                                       assert.spy(testEncounter.setupSpawnAndDespawnEvents).was.called_with(testEncounter)
+                               end)
+
+                               it("Should start the spawn task.", function()
+                                       testEncounter:taskStart(pCreatureObject)
+
+                                       assert.spy(testEncounter.spawnTask.start).was.called_with(testEncounter.spawnTask, pCreatureObject)
+                               end)
+                       end)
+               end)
+
+               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)
+
+                                       assert.same(testEncounter.minimumTimeUntilEncounter, testEncounter.spawnTask.minimumTimeUntilEvent)
+                               end)
+
+                               it("Should set the maximum event time on the spawn task to the maximum spawn time for the encounter.", function()
+                                       testEncounter:taskStart(pCreatureObject)
+
+                                       assert.same(testEncounter.maximumTimeUntilEncounter, testEncounter.spawnTask.maximumTimeUntilEvent)
+                               end)
+
+                               it("Should set the encounter variable on the spawn task.", function()
+                                       testEncounter:taskStart(pCreatureObject)
+
+                                       assert.same(testEncounter, testEncounter.spawnTask.encounter)
+                               end)
+
+                               it("Should set the minimum event time on the despawn task to the encounter despawn time.", function()
+                                       testEncounter:taskStart(pCreatureObject)
+
+                                       assert.same(testEncounter.encounterDespawnTime, testEncounter.despawnTask.minimumTimeUntilEvent)
+                               end)
+
+                               it("Should set the maximum event time on the despawn task to the encounter despawn time.", function()
+                                       testEncounter:taskStart(pCreatureObject)
+
+                                       assert.same(testEncounter.encounterDespawnTime, testEncounter.despawnTask.maximumTimeUntilEvent)
+                               end)
+
+                               it("Should set the encounter variable on the despawn task.", function()
+                                       testEncounter:taskStart(pCreatureObject)
+
+                                       assert.same(testEncounter, testEncounter.despawnTask.encounter)
+                               end)
+                       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
+                               local realIsPlayerInNpcCity
+                               local realIsPlayerInABuilding
+
+                               setup(function()
+                                       realIsPlayerOnline = testEncounter.isPlayerOnline
+                                       realIsPlayerInNpcCity = testEncounter.isPlayerInNpcCity
+                                       realIsPlayerInABuilding = testEncounter.isPlayerInABuilding
+                               end)
+
+                               teardown(function()
+                                       testEncounter.isPlayerOnline = realIsPlayerOnline
+                                       testEncounter.isPlayerInNpcCity = realIsPlayerInNpcCity
+                                       testEncounter.isPlayerInABuilding = realIsPlayerInABuilding
+                               end)
+
+                               before_each(function()
+                                       testEncounter.isPlayerOnline = spy.new(function() return true end)
+                                       testEncounter.isPlayerInNpcCity = spy.new(function() return false end)
+                                       testEncounter.isPlayerInABuilding = spy.new(function() return false end)
+                               end)
+
+                               describe("and the player is outside, not in an npc city and online.", function()
+                                       it("Should return true.", function()
+                                               assert.is_true(testEncounter:isPlayerInPositionForEncounter(pCreatureObject))
+                                       end)
+                               end)
+
+                               describe("and the player is offline", function()
+                                       it("Should return false.", function()
+                                               testEncounter.isPlayerOnline = spy.new(function() return false end)
+
+                                               assert.is_false(testEncounter:isPlayerInPositionForEncounter(pCreatureObject))
+                                       end)
+                               end)
+
+                               describe("and the player is in a NPC city", function()
+                                       it("Should return false.", function()
+                                               testEncounter.isPlayerInNpcCity = spy.new(function() return true end)
+
+                                               assert.is_false(testEncounter:isPlayerInPositionForEncounter(pCreatureObject))
+                                       end)
+                               end)
+
+                               describe("and the player is inside a building", function()
+                                       it("Should return false.", function()
+                                               testEncounter.isPlayerInABuilding = spy.new(function() return true end)
+
+                                               assert.is_false(testEncounter:isPlayerInPositionForEncounter(pCreatureObject))
+                                       end)
+                               end)
+                       end)
+               end)
+
+               describe("isPlayerOnline", function()
+                       describe("When called with a creature object pointer", function()
+                               it("Should return true if the player is online.", function()
+                                       playerObject.isOnline = spy.new(function() return true end)
+
+                                       assert.is_true(testEncounter:isPlayerOnline(pCreatureObject))
+
+                                       assert.spy(playerObject.isOnline).was.called(1)
+                               end)
+
+                               it("Should return false if the player is offline.", function()
+                                       playerObject.isOnline = spy.new(function() return false end)
+
+                                       assert.is_false(testEncounter:isPlayerOnline(pCreatureObject))
+
+                                       assert.spy(playerObject.isOnline).was.called(1)
+                               end)
+                       end)
+
+                       describe("When called with nil as argument", function()
+                               it("Should return false.", function()
+                                       assert.is_false(testEncounter:isPlayerOnline(nil))
+                               end)
+                       end)
+               end)
+
+               describe("isPlayerInABuilding", function()
+                       describe("When called with a creature object pointer", function()
+                               it("Should return true if the parent id of the player is not equal to 0", function()
+                                       sceneObjectPlayer.getParentID = spy.new(function() return 1 end)
+
+                                       assert.is_true(testEncounter:isPlayerInABuilding(pCreatureObject))
+
+                                       assert.spy(sceneObjectPlayer.getParentID).was.called(1)
+                               end)
+
+                               it("Should return false if the parent id of the player is equal to 0", function()
+                                       sceneObjectPlayer.getParentID = spy.new(function() return 0 end)
+
+                                       assert.is_false(testEncounter:isPlayerInABuilding(pCreatureObject))
+
+                                       assert.spy(sceneObjectPlayer.getParentID).was.called(1)
+                               end)
+                       end)
+
+                       describe("When called with nil as argument", function()
+                               it("Should return false.", function()
+                                       assert.is_false(testEncounter:isPlayerInABuilding(nil))
+                               end)
+                       end)
+               end)
+
+               describe("isPlayerInNpcCity", function()
+                       before_each(function()
+                               getCityRegionAt = spy.new(function() return pCityRegion end)
+                       end)
+
+                       describe("When called with a nil pointer", function()
+                               it("Should return false.", function()
+                                       assert.is_false(testEncounter:isPlayerInNpcCity(nil))
+                               end)
+                       end)
+
+                       describe("When called with a creature object pointer", function()
+                               after_each(function()
+                                       assert.spy(sceneObjectPlayer.getZoneName).was.called(1)
+                                       assert.spy(sceneObjectPlayer.getWorldPositionX).was.called(1)
+                                       assert.spy(sceneObjectPlayer.getWorldPositionY).was.called(1)
+                                       assert.spy(getCityRegionAt).was.called_with("testzone", 33, 22)
+                               end)
+
+                               describe("and player is in no region", function()
+                                       it("Should return false.", function()
+                                               getCityRegionAt = spy.new(function() return nil end)
+
+                                               assert.is_false(testEncounter:isPlayerInNpcCity(pCreatureObject))
+                                       end)
+                               end)
+
+                               describe("and the player is in city region", function()
+                                       it("Should return true if the city region belongs to a NPC city.", function()
+                                               cityRegion.isClientRegion = spy.new(function() return false end)
+
+                                               assert.is_true(testEncounter:isPlayerInNpcCity(pCreatureObject))
+
+                                               assert.spy(cityRegion.isClientRegion).was.called(1)
+                                       end)
+
+                                       it("Should return false if the city region belongs to a player city.", function()
+                                               cityRegion.isClientRegion = spy.new(function() return true end)
+
+                                               assert.is_false(testEncounter:isPlayerInNpcCity(pCreatureObject))
+
+                                               assert.spy(cityRegion.isClientRegion).was.called(1)
+                                       end)
+                               end)
+                       end)
+               end)
+
+               describe("createEncounter", function()
+                       describe("When called with a player", function()
+                               local realSetSpawnedObjectsToFollow
+                               local realCreateEncounterEvents
+
+                               setup(function()
+                                       realSetSpawnedObjectsToFollow = testEncounter.setSpawnedObjectsToFollow
+                                       realCreateEncounterEvents = testEncounter.createEncounterEvents
+                               end)
+
+                               teardown(function()
+                                       testEncounter.setSpawnedObjectsToFollow = realSetSpawnedObjectsToFollow
+                                       testEncounter.createEncounterEvents = realCreateEncounterEvents
+                               end)
+
+                               before_each(function()
+                                       testEncounter.setSpawnedObjectsToFollow = spy.new(function() end)
+                                       testEncounter.createEncounterEvents = spy.new(function() end)
+                               end)
+
+                               it("Should spawn the encounter objects.", function()
+                                       testEncounter:createEncounter(pCreatureObject)
+
+                                       assert.spy(SpawnMobilesMocks.spawnMobiles).was.called_with(pCreatureObject, testEncounter.taskName, testEncounter.spawnObjectList)
+                               end)
+
+                               describe("and the objects where spawned", function()
+                                       before_each(function()
+                                               SpawnMobilesMocks.spawnMobiles = spy.new(function() return spawnedObjects end)
+                                       end)
+
+                                       it("Should set all objects to follow the player.", function()
+                                               testEncounter:createEncounter(pCreatureObject)
+
+                                               assert.spy(testEncounter.setSpawnedObjectsToFollow).was.called_with(testEncounter, spawnedObjects, pCreatureObject)
+                                       end)
+
+                                       it("Should create events related to the spawned objects.", function()
+                                               testEncounter:createEncounter(pCreatureObject)
+
+                                               assert.spy(testEncounter.createEncounterEvents).was.called_with(testEncounter, pCreatureObject, spawnedObjects)
+                                       end)
+
+                                       it("Should call the onEncounterSpawned function().", function()
+                                               testEncounter:createEncounter(pCreatureObject)
+
+                                               assert.spy(testEncounter.onEncounterSpawned).was.called_with(testEncounter, pCreatureObject, spawnedObjects)
+                                       end)
+                               end)
+
+                               describe("and no objects where spawned", function()
+                                       it("Should not set all objects to follow the player.", function()
+                                               testEncounter:createEncounter(pCreatureObject)
+
+                                               assert.spy(testEncounter.setSpawnedObjectsToFollow).was.not_called()
+                                       end)
+
+                                       it("Should not create events related to the spawned objects.", function()
+                                               testEncounter:createEncounter(pCreatureObject)
+
+                                               assert.spy(testEncounter.createEncounterEvents).was.not_called()
+                                       end)
+
+                                       it("Should not call the onEncounterSpawned function().", function()
+                                               testEncounter:createEncounter(pCreatureObject)
+
+                                               assert.spy(testEncounter.onEncounterSpawned).was.not_called()
+                                       end)
+                               end)
+                       end)
+               end)
+
+               describe("createEncounterEvents", function()
+                       describe("When called with a player", function()
+                               local createEventArgList = {
+                                       { time = CLOSING_IN_TIME, name = testEncounter.taskName, func = "handleEncounterClosingIn", pSO = pCreatureObject },
+                                       { time = AT_PLAYER_TIME, name = testEncounter.taskName, func = "handleEncounterAtPlayer", pSO = pCreatureObject }
+                               }
+                               local callNumber
+
+                               before_each(function()
+                                       callNumber = 1
+
+                                       createEvent = spy.new(function(time, name, func, pSO)
+                                               assert.same(createEventArgList[callNumber]["time"], time)
+                                               assert.same(createEventArgList[callNumber]["name"], name)
+                                               assert.same(createEventArgList[callNumber]["func"], func)
+                                               assert.same(createEventArgList[callNumber]["pSO"], pSO)
+                                               callNumber = callNumber + 1
+                                       end)
+                               end)
+
+                               it("Should create two events for closing in and at player.", function()
+                                       testEncounter:createEncounterEvents(pCreatureObject)
+
+                                       assert.spy(createEvent).was.called(2)
+                               end)
+                       end)
+               end)
+
+               describe("setSpawnedObjectsToFollow", function()
+                       describe("When called with a player and a list of spawned objects", function()
+                               it("Should set each object to follow the player if the spawn object list indicates that the object should follow the player.", function()
+                                       testEncounter:setSpawnedObjectsToFollow(spawnedObjects, pCreatureObject)
+
+                                       assert.spy(aiAgentObject1.setFollowObject).was.called_with(aiAgentObject1, pCreatureObject)
+                                       assert.spy(aiAgentObject2.setFollowObject).was.not_called()
+                                       assert.spy(aiAgentObject3.setFollowObject).was.called_with(aiAgentObject3, pCreatureObject)
+                               end)
+                       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()
+                                       SpawnMobilesMocks.getSpawnedMobiles = spy.new(function() return spawnedObjects end)
+                               end)
+
+                               it("Should get a list of all spawned mobiles.", function()
+                                       testEncounter:handleEncounterClosingIn(pCreatureObject)
+
+                                       assert.spy(SpawnMobilesMocks.getSpawnedMobiles).was.called_with(pCreatureObject, testEncounter.taskName)
+                               end)
+
+                               it("Should call the onEncounterClosingIn function.", function()
+                                       testEncounter:handleEncounterClosingIn(pCreatureObject)
+
+                                       assert.spy(testEncounter.onEncounterClosingIn).was.called_with(testEncounter, pCreatureObject, spawnedObjects)
+                               end)
+                       end)
+               end)
+
+               describe("handleEncounterAtPlayer", function()
+                       describe("When called", function()
+                               local realSetSpawnedObjectsToFollow
+
+                               setup(function()
+                                       realSetSpawnedObjectsToFollow = testEncounter.setSpawnedObjectsToFollow
+                               end)
+
+                               teardown(function()
+                                       testEncounter.setSpawnedObjectsToFollow = realSetSpawnedObjectsToFollow
+                               end)
+
+                               before_each(function()
+                                       testEncounter.setSpawnedObjectsToFollow = spy.new(function() end)
+                                       SpawnMobilesMocks.getSpawnedMobiles = spy.new(function() return spawnedObjects end)
+                               end)
+
+                               it("Should get a list of all spawned mobiles.", function()
+                                       testEncounter:handleEncounterAtPlayer(pCreatureObject)
+
+                                       assert.spy(SpawnMobilesMocks.getSpawnedMobiles).was.called_with(pCreatureObject, testEncounter.taskName)
+                               end)
+
+                               it("Should set all spawned mobiles to stop following the player.", function()
+                                       testEncounter:handleEncounterAtPlayer(pCreatureObject)
+
+                                       assert.spy(testEncounter.setSpawnedObjectsToFollow).was.called_with(testEncounter, spawnedObjects, nil)
+                               end)
+
+                               it("Should call the onEncounterAtPlayer function.", function()
+                                       testEncounter:handleEncounterAtPlayer(pCreatureObject)
+
+                                       assert.spy(testEncounter.onEncounterAtPlayer).was.called_with(testEncounter, pCreatureObject, spawnedObjects)
+                               end)
+                       end)
+               end)
+       end)
+end)
index 383b766..db688e3 100644 (file)
@@ -205,6 +205,13 @@ describe("Task", function()
 
                                        assert.spy(theFunction).was.called_with(testTask, pCreatureObject)
                                end)
+
+                               it("Should return what the function returns.", function()
+                                       local returnValue = { "returnValue" }
+                                       local theFunction = spy.new(function() return returnValue end)
+
+                                       assert.same(returnValue, testTask:callFunctionIfNotNil(theFunction, pCreatureObject))
+                               end)
                        end)
 
                        describe("When called with the function equal to nil", function()
@@ -215,17 +222,21 @@ describe("Task", function()
                                end)
 
                                teardown(function()
-                                       --error = realError
+                                       error = realError
                                end)
 
                                setup(function()
-                                       --error = spy.new(function() end)
+                                       error = spy.new(function() end)
                                end)
 
                                it("Should generate an error about the function being nil.", function()
                                        testTask:callFunctionIfNotNil(nil, pCreatureObject)
 
-                                       --assert.spy(error).was.called()
+                                       assert.spy(error).was.called()
+                               end)
+
+                               it("Should return nil.", function()
+                                       assert.is_nil(testTask:callFunctionIfNotNil(nil, pCreatureObject))
                                end)
                        end)
                end)
index 650381c..f486acf 100644 (file)
@@ -1,6 +1,7 @@
 local SpawnMobiles = require("utils.spawn_mobiles")
 local realSpawnMobiles
 local realDespawnMobiles
+local realGetSpawnedMobiles
 
 local SpawnMobilesMocks = SpawnMobiles
 SpawnMobilesMocks.mocks = {}
@@ -8,16 +9,19 @@ SpawnMobilesMocks.mocks = {}
 function SpawnMobilesMocks.mocks.setup()
        realSpawnMobiles = SpawnMobiles.spawnMobiles
        realDespawnMobiles = SpawnMobiles.despawnMobiles
+       realGetSpawnedMobiles = SpawnMobiles.getSpawnedMobiles
 end
 
 function SpawnMobilesMocks.mocks.teardown()
        SpawnMobiles.spawnMobiles = realSpawnMobiles
        SpawnMobiles.despawnMobiles = realDespawnMobiles
+       SpawnMobiles.getSpawnedMobiles = realGetSpawnedMobiles
 end
 
 function SpawnMobilesMocks.mocks.before_each()
-       SpawnMobiles.spawnMobiles = spy.new(function() end)
+       SpawnMobiles.spawnMobiles = spy.new(function() return nil end)
        SpawnMobiles.despawnMobiles = spy.new(function() end)
+       SpawnMobiles.getSpawnedMobiles = spy.new(function() return nil end)
 end
 
 function SpawnMobilesMocks.mocks.after_each()
index 2d4ede0..90b90fc 100644 (file)
@@ -6,6 +6,7 @@
 -- To spawn the the mobiles, call the spawnMobiles function with the appropriate arguments. The format of the arguments are described below.
 -- This function will return a list with pointers to all spawned mobiles.
 -- To despawn the mobiles, call the despawnMobiles function with the appropriate arguments.
+-- To get a list with all spawned mobiles, call the getSpawnedMobiles function with the approprate arguments.
 --
 -- Arguments:
 -- prefix - a string used to store the id of all spawned mobiles. The information will not be stored persistent.
@@ -213,7 +214,7 @@ end
 -- @param pCreatureObject pointer to the creature object of the player.
 -- @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.getSpawnedMobilesList(pCreatureObject, prefix)
+function SpawnMobiles.getSpawnedMobiles(pCreatureObject, prefix)
        if not SpawnMobiles.isPrefixFree(pCreatureObject, prefix) then
                return SpawnMobiles.getSpawnedMobilePointersList(pCreatureObject, prefix)
        else
@@ -249,7 +250,7 @@ end
 -- @param pCreatureObject pointer to the creature object of the player.
 -- @param prefix the prefix to use for reading information about the mobiles to despawn.
 function SpawnMobiles.despawnMobiles(pCreatureObject, prefix)
-       SpawnMobiles.despawnMobilesInList(SpawnMobiles.getSpawnedMobilesList(pCreatureObject, prefix))
+       SpawnMobiles.despawnMobilesInList(SpawnMobiles.getSpawnedMobiles(pCreatureObject, prefix))
        ObjectManager.withSceneObject(pCreatureObject, function(sceneObject)
                writeData(sceneObject:getObjectID() .. prefix .. SPAWN_MOBILES_STRING .. IN_USE_STRING, PREFIX_FREE)
        end)
index 0726487..23e8a93 100644 (file)
@@ -181,28 +181,28 @@ describe("Spawn Mobile", function()
 
                describe("despawnMobiles", function()
                        describe("When called with a prefix", function()
-                               local realGetSpawnedMobilesList
+                               local realGetSpawnedMobiles
                                local realDespawnMobilesInList
 
                                setup(function()
-                                       realGetSpawnedMobilesList = SpawnMobiles.getSpawnedMobilesList
+                                       realGetSpawnedMobiles = SpawnMobiles.getSpawnedMobiles
                                        realDespawnMobilesInList = SpawnMobiles.despawnMobilesInList
                                end)
 
                                teardown(function()
-                                       SpawnMobiles.getSpawnedMobilesList = realGetSpawnedMobilesList
+                                       SpawnMobiles.getSpawnedMobiles = realGetSpawnedMobiles
                                        SpawnMobiles.despawnMobilesInList = realDespawnMobilesInList
                                end)
 
                                before_each(function()
-                                       SpawnMobiles.getSpawnedMobilesList = spy.new(function() return spawnedMobilesList end)
+                                       SpawnMobiles.getSpawnedMobiles = spy.new(function() return spawnedMobilesList end)
                                        SpawnMobiles.despawnMobilesInList = spy.new(function() end)
                                end)
 
                                it("Should get a list with pointers to the spawned mobiles from the prefix.", function()
                                        SpawnMobiles.despawnMobiles(pCreatureObject, prefix)
 
-                                       assert.spy(SpawnMobiles.getSpawnedMobilesList).was.called_with(pCreatureObject, prefix)
+                                       assert.spy(SpawnMobiles.getSpawnedMobiles).was.called_with(pCreatureObject, prefix)
                                end)
 
                                it("Should call the despawnMobilesInList function.", function()
@@ -218,6 +218,56 @@ describe("Spawn Mobile", function()
                                end)
                        end)
                end)
+
+               describe("getSpawnedMobiles", function()
+                       describe("When called with a player and a prefix", function()
+                               local realIsPrefixFree
+                               local realGetSpawnedMobilePointersList
+
+                               setup(function()
+                                       realIsPrefixFree = SpawnMobiles.isPrefixFree
+                                       realGetSpawnedMobilePointersList = SpawnMobiles.getSpawnedMobilePointersList
+                               end)
+
+                               teardown(function()
+                                       SpawnMobiles.isPrefixFree = realIsPrefixFree
+                                       SpawnMobiles.getSpawnedMobilePointersList = realGetSpawnedMobilePointersList
+                               end)
+
+                               before_each(function()
+                                       SpawnMobiles.isPrefixFree = spy.new(function() return true end)
+                                       SpawnMobiles.getSpawnedMobilePointersList = spy.new(function() return spawnedMobilesList end)
+                               end)
+
+                               it("Should check if the prefix is in use.", function()
+                                       SpawnMobiles.getSpawnedMobiles(pCreatureObject, prefix)
+
+                                       assert.spy(SpawnMobiles.isPrefixFree).was.called_with(pCreatureObject, prefix)
+                               end)
+
+                               describe("and the prefix is not in use", function()
+                                       it("Should return nil.", function()
+                                               assert.is_nil(SpawnMobiles.getSpawnedMobiles(pCreatureObject, prefix))
+                                       end)
+                               end)
+
+                               describe("and the prefix is in use", function()
+                                       before_each(function()
+                                               SpawnMobiles.isPrefixFree = spy.new(function() return false end)
+                                       end)
+
+                                       it("Should call the getSpawnedMobilesPointersList function.", function()
+                                       SpawnMobiles.getSpawnedMobiles(pCreatureObject, prefix)
+
+                                       assert.spy(SpawnMobiles.getSpawnedMobilePointersList).was.called_with(pCreatureObject, prefix)
+                                       end)
+
+                                       it("Should return a list with pointers to the spawned mobiles.", function()
+                                               assert.same(spawnedMobilesList, SpawnMobiles.getSpawnedMobiles(pCreatureObject, prefix))
+                                       end)
+                               end)
+                       end)
+               end)
        end)
 
        describe("Private functions", function()
@@ -690,56 +740,6 @@ describe("Spawn Mobile", function()
                        end)
                end)
 
-               describe("getSpawnedMobilesList", function()
-                       describe("When called with a player and a prefix", function()
-                               local realIsPrefixFree
-                               local realGetSpawnedMobilePointersList
-
-                               setup(function()
-                                       realIsPrefixFree = SpawnMobiles.isPrefixFree
-                                       realGetSpawnedMobilePointersList = SpawnMobiles.getSpawnedMobilePointersList
-                               end)
-
-                               teardown(function()
-                                       SpawnMobiles.isPrefixFree = realIsPrefixFree
-                                       SpawnMobiles.getSpawnedMobilePointersList = realGetSpawnedMobilePointersList
-                               end)
-
-                               before_each(function()
-                                       SpawnMobiles.isPrefixFree = spy.new(function() return true end)
-                                       SpawnMobiles.getSpawnedMobilePointersList = spy.new(function() return spawnedMobilesList end)
-                               end)
-
-                               it("Should check if the prefix is in use.", function()
-                                       SpawnMobiles.getSpawnedMobilesList(pCreatureObject, prefix)
-
-                                       assert.spy(SpawnMobiles.isPrefixFree).was.called_with(pCreatureObject, prefix)
-                               end)
-
-                               describe("and the prefix is not in use", function()
-                                       it("Should return nil.", function()
-                                               assert.is_nil(SpawnMobiles.getSpawnedMobilesList(pCreatureObject, prefix))
-                                       end)
-                               end)
-
-                               describe("and the prefix is in use", function()
-                                       before_each(function()
-                                               SpawnMobiles.isPrefixFree = spy.new(function() return false end)
-                                       end)
-
-                                       it("Should call the getSpawnedMobilesPointersList function.", function()
-                                       SpawnMobiles.getSpawnedMobilesList(pCreatureObject, prefix)
-
-                                       assert.spy(SpawnMobiles.getSpawnedMobilePointersList).was.called_with(pCreatureObject, prefix)
-                                       end)
-
-                                       it("Should return a list with pointers to the spawned mobiles.", function()
-                                               assert.same(spawnedMobilesList, SpawnMobiles.getSpawnedMobilesList(pCreatureObject, prefix))
-                                       end)
-                               end)
-                       end)
-               end)
-
                describe("getSpawnedMobilePointersList", function()
                        describe("When called with a player and a prefix", function()
                                local callNumberReadData