Instructions Jenkins Doxygen

[Changed] Refactorred village jedi manager. 12/1112/2
authorLoshult <loshult@swgemu.com>
Thu, 14 Nov 2013 20:21:42 +0000 (20:21 +0000)
committerLoshult <loshult@swgemu.com>
Thu, 14 Nov 2013 20:21:42 +0000 (20:21 +0000)
[Changed] package.path for all screenplays to start in the scripts
folder.
[Changed] Introduced class-like, testable structure for the village jedi
manager.

Change-Id: Ibcef2a13a2bc9f35ff4676e13ae8177cb2e7035e

26 files changed:
MMOCoreORB/bin/scripts/ai/tests/AiBaseTest.lua
MMOCoreORB/bin/scripts/managers/jedi/hologrind/hologrind_jedi_manager.lua
MMOCoreORB/bin/scripts/managers/jedi/hologrind/tests/hologrind_jedi_manager_Test.lua
MMOCoreORB/bin/scripts/managers/jedi/jedi_manager.lua
MMOCoreORB/bin/scripts/managers/jedi/village/glowing.lua [new file with mode: 0755]
MMOCoreORB/bin/scripts/managers/jedi/village/mocks/glowing_mocks.lua [new file with mode: 0755]
MMOCoreORB/bin/scripts/managers/jedi/village/mocks/old_man_mocks.lua [changed mode: 0644->0755]
MMOCoreORB/bin/scripts/managers/jedi/village/mocks/village_jedi_manager_common_mocks.lua [new file with mode: 0644]
MMOCoreORB/bin/scripts/managers/jedi/village/mocks/village_jedi_manager_holocron_mocks.lua [changed mode: 0644->0755]
MMOCoreORB/bin/scripts/managers/jedi/village/mocks/village_jedi_manager_mocks.lua [changed mode: 0644->0755]
MMOCoreORB/bin/scripts/managers/jedi/village/old_man.lua [changed mode: 0644->0755]
MMOCoreORB/bin/scripts/managers/jedi/village/old_man_conv_handler.lua [changed mode: 0644->0755]
MMOCoreORB/bin/scripts/managers/jedi/village/tests/glowing_Test.lua [new file with mode: 0755]
MMOCoreORB/bin/scripts/managers/jedi/village/tests/old_man_Test.lua [changed mode: 0644->0755]
MMOCoreORB/bin/scripts/managers/jedi/village/tests/village_jedi_manager_Test.lua [changed mode: 0644->0755]
MMOCoreORB/bin/scripts/managers/jedi/village/tests/village_jedi_manager_common_Test.lua [new file with mode: 0644]
MMOCoreORB/bin/scripts/managers/jedi/village/tests/village_jedi_manager_holocron_Test.lua [changed mode: 0644->0755]
MMOCoreORB/bin/scripts/managers/jedi/village/village_jedi_manager.lua [changed mode: 0644->0755]
MMOCoreORB/bin/scripts/managers/jedi/village/village_jedi_manager_common.lua [new file with mode: 0644]
MMOCoreORB/bin/scripts/managers/jedi/village/village_jedi_manager_holocron.lua [changed mode: 0644->0755]
MMOCoreORB/bin/scripts/screenplays/screenplay.lua
MMOCoreORB/bin/scripts/screenplays/tests/screenplay_Test.lua
MMOCoreORB/bin/scripts/screenplays/themepark/test/themeParkLogicTest.lua
MMOCoreORB/bin/scripts/screenplays/themepark/themeParkLogic.lua
MMOCoreORB/src/server/zone/managers/director/DirectorManager.cpp [changed mode: 0644->0755]
MMOCoreORB/src/server/zone/managers/director/DirectorManager.h [changed mode: 0644->0755]

index acb93e8..b4c02e3 100644 (file)
@@ -1,7 +1,5 @@
-package.path = package.path .. ";scripts/ai/actions/?.lua;scripts/ai/?.lua"
-
 includeFile = spy.new(function() end)
-require("ai")
+require("ai.ai")
 
 describe("Basic Behavior Tests", function()
   it("Defines the Behavior Object", function()
index 2b9a0bd..e675d52 100644 (file)
@@ -1,5 +1,4 @@
-package.path = package.path .. ";scripts/managers/jedi/?.lua"
-JediManager = require("jedi_manager")
+JediManager = require("managers.jedi.jedi_manager")
 
 jediManagerName = "HologrindJediManager"
 
@@ -129,7 +128,7 @@ end
 -- Check if the player has mastered all hologrind professions and send sui window and award skills.
 -- @param pCreatureObject pointer to the creature object of the player to check the jedi progression on.
 function HologrindJediManager.checkIfProgressedToJedi(pCreatureObject)
-       if HologrindJediManager.getNumberOfMasteredProfessions(pCreatureObject) >= NUMBEROFPROFESSIONSTOMASTER and 
+       if HologrindJediManager.getNumberOfMasteredProfessions(pCreatureObject) >= NUMBEROFPROFESSIONSTOMASTER and
           not HologrindJediManager.isJedi(pCreatureObject) then
                HologrindJediManager.sendSuiWindow(pCreatureObject)
                HologrindJediManager.awardJediStatusAndSkill(pCreatureObject)
@@ -186,7 +185,7 @@ function HologrindJediManager.sendHolocronMessage(pCreatureObject)
        else
                HologrindJediManager.withCreatureAndPlayerObject(pCreatureObject, function(creatureObject, playerObject)
                        local professions = playerObject:getHologrindProfessions()
-                       for i = 1, table.getn(professions), 1 do                        
+                       for i = 1, table.getn(professions), 1 do
                                if not playerObject:hasBadge(professions[i]) then
                                        local professionText = HologrindJediManager.getProfessionStringIdFromBadgeNumber(professions[i])
                                        creatureObject:sendSystemMessageWithTO("@jedi_spam:holocron_light_information", "@skl_n:" .. professionText)
index 1c5ad8b..0563167 100644 (file)
@@ -1,13 +1,12 @@
 registerScreenPlay = spy.new(function() end)
 
-package.path = package.path .. ";scripts/managers/jedi/hologrind/?.lua"
-require("hologrind_jedi_manager")
+require("managers.jedi.hologrind.hologrind_jedi_manager")
 
 EXPECTEDNUMBEROFPROFESSIONSTOGRIND = 6
 EXPECTEDMAXIMUMNUMBEROFPROFESSIONSTOSHOWWITHHOLOCRON = 4
 
 describe("Hologrind Jedi Manager", function()
-       describe("Interface functions", function() 
+       describe("Interface functions", function()
                describe("onPlayerCreated", function()
                        it("Should call the add hologrind profession method of the lua player object the defined number of times", function()
                                local creaturePointer = {}
@@ -16,7 +15,7 @@ describe("Hologrind Jedi Manager", function()
                                local getPlayerObjectSpy = spy.new(function() return playerPointer end)
                                local realWithCreaturePlayerObject = HologrindJediManager.withCreaturePlayerObject
                                HologrindJediManager.withCreaturePlayerObject = spy.new(function(pCreatureObject, performThisFunction)
-                                       return performThisFunction({ addHologrindProfession = addHologrindProfessionSpy }) 
+                                       return performThisFunction({ addHologrindProfession = addHologrindProfessionSpy })
                                end)
 
                                HologrindJediManager.onPlayerCreated(creaturePointer)
@@ -39,7 +38,7 @@ describe("Hologrind Jedi Manager", function()
                                HologrindJediManager:onPlayerLoggedIn(creaturePointer)
 
                                assert.spy(HologrindJediManager.checkIfProgressedToJedi).was.called_with(creaturePointer)
-               
+
                                HologrindJediManager.checkIfProgressedToJedi = realCheckIfProgressedToJedi
                                HologrindJediManager.registerObservers = realRegisterObservers
                        end)
@@ -54,14 +53,14 @@ describe("Hologrind Jedi Manager", function()
                                HologrindJediManager:onPlayerLoggedIn(creaturePointer)
 
                                assert.spy(HologrindJediManager.registerObservers).was.called_with(creaturePointer)
-               
+
                                HologrindJediManager.checkIfProgressedToJedi = realCheckIfProgressedToJedi
                                HologrindJediManager.registerObservers = realRegisterObservers
                        end)
                end)
 
                describe("useHolocron", function()
-                       it("Should call sendHolocronMessage.", function() 
+                       it("Should call sendHolocronMessage.", function()
                                local sceneObjectPointer = { "sceneObjectPointer" }
                                local creaturePointer = { "creaturePointer" }
                                local realSendHolocronMessage = HologrindJediManager.sendHolocronMessage
@@ -77,7 +76,7 @@ describe("Hologrind Jedi Manager", function()
                        end)
 
                        describe("When sendHolocronMessage returns false", function()
-                               it("Should destroy the holocron.", function() 
+                               it("Should destroy the holocron.", function()
                                        local sceneObjectPointer = { "sceneObjectPointer" }
                                        local creaturePointer = { "creaturePointer" }
                                        local realSendHolocronMessage = HologrindJediManager.sendHolocronMessage
@@ -112,7 +111,7 @@ describe("Hologrind Jedi Manager", function()
                end)
        end)
 
-       describe("Private functions", function() 
+       describe("Private functions", function()
                it("Should define the number of professions to master to 6", function()
                        assert.same(EXPECTEDNUMBEROFPROFESSIONSTOGRIND, NUMBEROFPROFESSIONSTOMASTER)
                end)
@@ -208,7 +207,7 @@ describe("Hologrind Jedi Manager", function()
                end)
 
                describe("getNumberOfMasteredProfessions", function()
-                       it("Should get the profession to master list for the player and count the number of mastered professions", function() 
+                       it("Should get the profession to master list for the player and count the number of mastered professions", function()
                                local creaturePointer = { "creaturePointer" }
                                local getHologrindProfessionsSpy = spy.new(function() return { 1, 2, 3, 4 } end)
                                local hasBadgeSpy = spy.new(function(self, badgeNumber) return badgeNumber < 3 end)
@@ -254,7 +253,7 @@ describe("Hologrind Jedi Manager", function()
                end)
 
                describe("sendHolocronMessage", function()
-                       it("Should send next profession message to the player if the number of mastered professions is below the threshold", function() 
+                       it("Should send next profession message to the player if the number of mastered professions is below the threshold", function()
                                local creaturePointer = { "creaturePointer" }
                                local sendSystemMessageSpy = spy.new(function() end)
                                local sendSystemMessageWithTOSpy = spy.new(function() end)
@@ -267,11 +266,11 @@ describe("Hologrind Jedi Manager", function()
                                local realWithCreatureObject = HologrindJediManager.withCreatureObject
                                local realWithCreatureAndPlayerObject = HologrindJediManager.withCreatureAndPlayerObject
                                HologrindJediManager.getNumberOfMasteredProfessions = spy.new(function() return 2 end)
-                               HologrindJediManager.withCreatureObject = spy.new(function(pCreatureObject, performThisFunction) 
-                                       return performThisFunction(creatureObject) 
+                               HologrindJediManager.withCreatureObject = spy.new(function(pCreatureObject, performThisFunction)
+                                       return performThisFunction(creatureObject)
                                end)
-                               HologrindJediManager.withCreatureAndPlayerObject = spy.new(function(pCreatureObject, performThisFunction) 
-                                       return performThisFunction(creatureObject, playerObject) 
+                               HologrindJediManager.withCreatureAndPlayerObject = spy.new(function(pCreatureObject, performThisFunction)
+                                       return performThisFunction(creatureObject, playerObject)
                                end)
 
                                HologrindJediManager.sendHolocronMessage(creaturePointer)
@@ -287,7 +286,7 @@ describe("Hologrind Jedi Manager", function()
                                HologrindJediManager.withCreatureAndPlayerObject = realWithCreatureAndPlayerObject
                        end)
 
-                       it("Should send find out on your own message to the player if the number of mastered professions is above the threshold", function() 
+                       it("Should send find out on your own message to the player if the number of mastered professions is above the threshold", function()
                                local creaturePointer = { "creaturePointer" }
                                local sendSystemMessageSpy = spy.new(function() end)
                                local sendSystemMessageWithTOSpy = spy.new(function() end)
@@ -300,11 +299,11 @@ describe("Hologrind Jedi Manager", function()
                                local realWithCreatureObject = HologrindJediManager.withCreatureObject
                                local realWithCreatureAndPlayerObject = HologrindJediManager.withCreatureAndPlayerObject
                                HologrindJediManager.getNumberOfMasteredProfessions = spy.new(function() return 4 end)
-                               HologrindJediManager.withCreatureObject = spy.new(function(pCreatureObject, performThisFunction) 
-                                       return performThisFunction(creatureObject) 
+                               HologrindJediManager.withCreatureObject = spy.new(function(pCreatureObject, performThisFunction)
+                                       return performThisFunction(creatureObject)
                                end)
-                               HologrindJediManager.withCreatureAndPlayerObject = spy.new(function(pCreatureObject, performThisFunction) 
-                                       return performThisFunction(creatureObject, playerObject) 
+                               HologrindJediManager.withCreatureAndPlayerObject = spy.new(function(pCreatureObject, performThisFunction)
+                                       return performThisFunction(creatureObject, playerObject)
                                end)
 
                                HologrindJediManager.sendHolocronMessage(creaturePointer)
@@ -320,7 +319,7 @@ describe("Hologrind Jedi Manager", function()
                                HologrindJediManager.withCreatureAndPlayerObject = realWithCreatureAndPlayerObject
                        end)
 
-                       it("Should return false if the number of mastered professions is below the threshold", function() 
+                       it("Should return false if the number of mastered professions is below the threshold", function()
                                local creaturePointer = { "creaturePointer" }
                                local sendSystemMessageSpy = spy.new(function() end)
                                local sendSystemMessageWithTOSpy = spy.new(function() end)
@@ -333,11 +332,11 @@ describe("Hologrind Jedi Manager", function()
                                local realWithCreatureObject = HologrindJediManager.withCreatureObject
                                local realWithCreatureAndPlayerObject = HologrindJediManager.withCreatureAndPlayerObject
                                HologrindJediManager.getNumberOfMasteredProfessions = spy.new(function() return 2 end)
-                               HologrindJediManager.withCreatureObject = spy.new(function(pCreatureObject, performThisFunction) 
-                                       return performThisFunction(creatureObject) 
+                               HologrindJediManager.withCreatureObject = spy.new(function(pCreatureObject, performThisFunction)
+                                       return performThisFunction(creatureObject)
                                end)
-                               HologrindJediManager.withCreatureAndPlayerObject = spy.new(function(pCreatureObject, performThisFunction) 
-                                       return performThisFunction(creatureObject, playerObject) 
+                               HologrindJediManager.withCreatureAndPlayerObject = spy.new(function(pCreatureObject, performThisFunction)
+                                       return performThisFunction(creatureObject, playerObject)
                                end)
 
                                assert.is_not_true(HologrindJediManager.sendHolocronMessage(creaturePointer))
@@ -347,7 +346,7 @@ describe("Hologrind Jedi Manager", function()
                                HologrindJediManager.withCreatureAndPlayerObject = realWithCreatureAndPlayerObject
                        end)
 
-                       it("Should return true if the number of mastered professions is above the threshold", function() 
+                       it("Should return true if the number of mastered professions is above the threshold", function()
                                local creaturePointer = { "creaturePointer" }
                                local sendSystemMessageSpy = spy.new(function() end)
                                local sendSystemMessageWithTOSpy = spy.new(function() end)
@@ -360,11 +359,11 @@ describe("Hologrind Jedi Manager", function()
                                local realWithCreatureObject = HologrindJediManager.withCreatureObject
                                local realWithCreatureAndPlayerObject = HologrindJediManager.withCreatureAndPlayerObject
                                HologrindJediManager.getNumberOfMasteredProfessions = spy.new(function() return 4 end)
-                               HologrindJediManager.withCreatureObject = spy.new(function(pCreatureObject, performThisFunction) 
-                                       return performThisFunction(creatureObject) 
+                               HologrindJediManager.withCreatureObject = spy.new(function(pCreatureObject, performThisFunction)
+                                       return performThisFunction(creatureObject)
                                end)
-                               HologrindJediManager.withCreatureAndPlayerObject = spy.new(function(pCreatureObject, performThisFunction) 
-                                       return performThisFunction(creatureObject, playerObject) 
+                               HologrindJediManager.withCreatureAndPlayerObject = spy.new(function(pCreatureObject, performThisFunction)
+                                       return performThisFunction(creatureObject, playerObject)
                                end)
 
                                assert.is_true(HologrindJediManager.sendHolocronMessage(creaturePointer))
index f187afc..e0b306c 100644 (file)
@@ -1,5 +1,4 @@
-package.path = package.path .. ";scripts/screenplays/?.lua"
-JediManager = require("screenplay")
+JediManager = require("screenplays.screenplay")
 
 NOJEDIPROGRESSION = 0
 HOLOGRINDJEDIPROGRESSION = 1
diff --git a/MMOCoreORB/bin/scripts/managers/jedi/village/glowing.lua b/MMOCoreORB/bin/scripts/managers/jedi/village/glowing.lua
new file mode 100755 (executable)
index 0000000..9c3fad0
--- /dev/null
@@ -0,0 +1,229 @@
+local ScreenPlay = require("screenplays.screenplay")
+local OldMan = require("managers.jedi.village.old_man")
+local VillageJediManagerCommon = require("managers.jedi.village.village_jedi_manager_common")
+
+local Glowing = {}
+GlowingEventsAndObservers = {}
+local GlowingPrivate = ScreenPlay:new {}
+
+-- Expose private functions for testing.
+function Glowing.exposePrivateFunctions()
+       if BUSTED_TEST then
+               Glowing.private = GlowingPrivate
+               OldMan.global = GlowingEventsAndObservers
+       end
+end
+
+-- Hide private functions.
+function Glowing.hidePrivateFunctions()
+       Glowing.private = {}
+       Glowing.global = {}
+end
+
+TOTALNUMBEROFBADGESREQUIRED = 17
+NUMBEROFJEDIBADGESREQUIRED = 3
+NUMBEROFDIFFICULTBADGESREQUIRED = 3
+NUMBEROFEASYBADGESREQUIRED = 5
+NUMBEROFPROFESSIONBADGESREQUIRED = 1
+NUMBEROFCONTENTBADGESREQUIRED = 5
+
+JEDIBADGES = {
+       EXP_TAT_BENS_HUT,
+       EXP_YAV_TEMPLE_EXAR_KUN,
+       EXP_DAN_JEDI_TEMPLE
+}
+
+DIFFICULTBADGES = {
+       EXP_TAT_TUSKEN_POOL,
+       EXP_TAT_KRAYT_SKELETON,
+       EXP_TAT_SARLACC_PIT,
+       EXP_TAT_KRAYT_GRAVEYARD,
+       EXP_DAT_SARLACC
+}
+
+EASYBADGES = {
+       EXP_TAT_ESCAPE_POD,
+       EXP_TAT_LARS_HOMESTEAD,
+       EXP_NAB_GUNGAN_SACRED_PLACE,
+       EXP_COR_AGRILAT_SWAMP,
+       EXP_YAV_TEMPLE_WOOLAMANDER,
+       EXP_YAV_TEMPLE_BLUELEAF,
+       EXP_LOK_VOLCANO,
+       EXP_DAT_TARPIT,
+       EXP_DAT_ESCAPE_POD,
+       EXP_DAT_MISTY_FALLS_1,
+       EXP_DAT_MISTY_FALLS_2,
+       EXP_DAN_REBEL_BASE,
+       BDG_EXP_NAB_THEED_FALLS_BOTTOM,
+       BDG_EXP_NAB_DEEJA_FALLS_TOP,
+       BDG_EXP_NAB_AMIDALAS_SANDY_BEACH,
+       BDG_EXP_COR_REBEL_HIDEOUT,
+       BDG_EXP_COR_ROGUE_CORSEC_BASE,
+       BDG_EXP_COR_TYRENA_THEATER,
+       BDG_EXP_COR_BELA_VISTAL_FOUNTAIN,
+       BDG_EXP_DAT_CRASHED_SHIP,
+       BDG_EXP_DAT_IMP_PRISON,
+       BDG_EXP_DAN_DANTARI_VILLAGE1,
+       BDG_EXP_DAN_DANTARI_VILLAGE2,
+       BDG_EXP_END_EWOK_TREE_VILLAGE,
+       BDG_EXP_END_EWOK_LAKE_VILLAGE,
+       BDG_EXP_END_DULOK_VILLAGE,
+       BDG_EXP_END_IMP_OUTPOST,
+       BDG_EXP_TAL_CREATURE_VILLAGE,
+       BDG_EXP_TAL_IMP_BASE,
+       BDG_EXP_TAL_IMP_VS_REB_BATTLE,
+       BDG_EXP_TAL_AQUALISH_CAVE,
+       BDG_EXP_ROR_KOBALA_SPICE_MINE,
+       BDG_EXP_ROR_REBEL_OUTPOST,
+       BDG_EXP_ROR_IMP_CAMP,
+       BDG_EXP_ROR_IMP_HYPERDRIVE_FAC,
+       BDG_EXP_LOK_KIMOGILA_SKELETON
+}
+
+CONTENTBADGES = {
+       BDG_THM_PARK_JABBA_BADGE,
+       BDG_THM_PARK_IMPERIAL_BADGE,
+       BDG_THM_PARK_REBEL_BADGE,
+       BDG_THM_PARK_NYM_BADGE,
+       BDG_CORVETTE_IMP_DESTROY,
+       BDG_CORVETTE_IMP_RESCUE,
+       BDG_CORVETTE_IMP_ASSASSIN,
+       BDG_CORVETTE_NEUTRAL_DESTROY,
+       BDG_CORVETTE_NEUTRAL_RESCUE,
+       BDG_CORVETTE_NEUTRAL_ASSASSIN,
+       BDG_CORVETTE_REB_DESTROY,
+       BDG_CORVETTE_REB_RESCUE,
+       BDG_CORVETTE_REB_ASSASSIN,
+       WARREN_COMPASSION,
+       WARREN_HERO
+}
+
+PROFESSIONBADGES = {
+       COMBAT_1HSWORD_MASTER,
+       COMBAT_2HSWORD_MASTER,
+       COMBAT_BOUNTYHUNTER_MASTER,
+       COMBAT_BRAWLER_MASTER,
+       COMBAT_CARBINE_MASTER,
+       COMBAT_COMMANDO_MASTER,
+       COMBAT_MARKSMAN_MASTER,
+       COMBAT_PISTOL_MASTER,
+       COMBAT_POLEARM_MASTER,
+       COMBAT_RIFLEMAN_MASTER,
+       COMBAT_SMUGGLER_MASTER,
+       COMBAT_UNARMED_MASTER,
+       CRAFTING_ARCHITECT_MASTER,
+       CRAFTING_ARMORSMITH_MASTER,
+       CRAFTING_ARTISAN_MASTER,
+       CRAFTING_CHEF_MASTER,
+       CRAFTING_DROIDENGINEER_MASTER,
+       CRAFTING_MERCHANT_MASTER,
+       CRAFTING_TAILOR_MASTER,
+       CRAFTING_WEAPONSMITH_MASTER,
+       OUTDOORS_BIOENGINEER_MASTER,
+       OUTDOORS_CREATUREHANDLER_MASTER,
+       OUTDOORS_RANGER_MASTER,
+       OUTDOORS_SCOUT_MASTER,
+       OUTDOORS_SQUADLEADER_MASTER,
+       SCIENCE_COMBATMEDIC_MASTER,
+       SCIENCE_DOCTOR_MASTER,
+       SCIENCE_MEDIC_MASTER,
+       SOCIAL_DANCER_MASTER,
+       SOCIAL_ENTERTAINER_MASTER,
+       SOCIAL_IMAGEDESIGNER_MASTER,
+       SOCIAL_MUSICIAN_MASTER,
+       SOCIAL_POLITICIAN_MASTER,
+       CRAFTING_SHIPWRIGHT,
+       PILOT_REBEL_NAVY_NABOO,
+       PILOT_REBEL_NAVY_CORELLIA,
+       PILOT_REBEL_NAVY_TATOOINE,
+       PILOT_IMPERIAL_NAVY_NABOO,
+       PILOT_IMPERIAL_NAVY_CORELLIA,
+       PILOT_IMPERIAL_NAVY_TATOOINE,
+       PILOT_NEUTRAL_NABOO,
+       PILOT_CORELLIA,
+       PILOT_TATOOINE
+}
+
+-- Count the number of badges that the player got in the list.
+-- @param pCreatureObject pointer to the creature object of the player.
+-- @param list the list of badge numbers to check if the player has.
+-- @param upperLimit only count up to this limit.
+-- @return the number of badges in the list that the player has been awarded
+function GlowingPrivate.countBadgesInListToUpperLimit(pCreatureObject, list, upperLimit)
+       local numberOfBadges = 0
+       GlowingPrivate.withCreaturePlayerObject(pCreatureObject, function(playerObject)
+               for i = 1, table.getn(list), 1 do
+                       if playerObject:hasBadge(list[i]) then
+                               numberOfBadges = numberOfBadges + 1
+                               if numberOfBadges >= upperLimit then
+                                       break
+                               end
+                       end
+               end
+       end)
+       return numberOfBadges
+end
+
+-- Count the total number of badges towards the jedi progression for the player
+-- @param pCreatureObject pointer to the creature object of the player.
+-- @return the total number of interesting badges.
+function GlowingPrivate.countBadges(pCreatureObject)
+       local professionBadges = GlowingPrivate.countBadgesInListToUpperLimit(pCreatureObject, PROFESSIONBADGES, NUMBEROFPROFESSIONBADGESREQUIRED)
+       local jediBadges = GlowingPrivate.countBadgesInListToUpperLimit(pCreatureObject, JEDIBADGES, NUMBEROFJEDIBADGESREQUIRED)
+       local contentBadges = GlowingPrivate.countBadgesInListToUpperLimit(pCreatureObject, CONTENTBADGES, NUMBEROFCONTENTBADGESREQUIRED)
+       local difficultBadges = GlowingPrivate.countBadgesInListToUpperLimit(pCreatureObject, DIFFICULTBADGES, NUMBEROFDIFFICULTBADGESREQUIRED)
+       local easyBadges = GlowingPrivate.countBadgesInListToUpperLimit(pCreatureObject, EASYBADGES, NUMBEROFEASYBADGESREQUIRED)
+       return professionBadges + jediBadges + contentBadges + difficultBadges + easyBadges
+end
+
+-- Check if the player is glowing or not.
+-- @param pCreatureObject pointer to the creature object of the player.
+function GlowingPrivate.isGlowing(pCreatureObject)
+       if GlowingPrivate.countBadges(pCreatureObject) >= TOTALNUMBEROFBADGESREQUIRED then
+               VillageJediManagerCommon.setJediProgressionScreenPlayState(pCreatureObject, VILLAGE_JEDI_PROGRESSION_GLOWING)
+               OldMan.createSpawnOldManEvent(pCreatureObject)
+       end
+end
+
+-- Event handler for the BADGEAWARDED event.
+-- @param pCreatureObject pointer to the creature object of the player who was awarded with a badge.
+-- @param pCreatureObject2 pointer to the creature object of the player who was awarded with a badge.
+-- @param badgeNumber the badge number that was awarded.
+-- @return 0 to keep the observer active.
+function GlowingEventsAndObservers:badgeAwardedEventHandler(pCreatureObject, pCreatureObject2, badgeNumber)
+       GlowingPrivate.isGlowing(pCreatureObject)
+
+       return 0
+end
+
+-- Register observer on the player for observing badge awards.
+-- @param pCreatureObject pointer to the creature object of the player to register observers on.
+function GlowingPrivate.registerObservers(pCreatureObject)
+       createObserver(BADGEAWARDED, "Glowing", "badgeAwardedEventHandler", pCreatureObject)
+end
+
+-- Handling of the onPlayerLoggedIn event. The progression of the player will be checked and observers will be registered.
+-- @param pCreatureObject pointer to the creature object of the player who logged in.
+function Glowing.onPlayerLoggedIn(pCreatureObject)
+       if not GlowingPrivate.isGlowing(pCreatureObject) then
+               GlowingPrivate.registerObservers(pCreatureObject)
+       end
+end
+
+-- Get the jedi progression status for the player
+-- @param pCreatureObject pointer to the creature object of the player.
+-- @return the jedi progression status, 0 to 5 to be used to return correct string id to the player.
+function GlowingPrivate.getJediProgressionStatus(pCreatureObject)
+       local numberOfBadges = GlowingPrivate.countBadges(pCreatureObject)
+       return math.floor((numberOfBadges / TOTALNUMBEROFBADGESREQUIRED) * 5)
+end
+
+-- Handling of the checkForceStatus command.
+-- @param pCreatureObject pointer to the creature object of the player who performed the command
+function Glowing.checkForceStatusCommand(pCreatureObject)
+       GlowingPrivate.withCreatureObject(pCreatureObject, function(creatureObject)
+               creatureObject:sendSystemMessage("@jedi_spam:fs_progress_" .. GlowingPrivate.getJediProgressionStatus(pCreatureObject))
+       end)
+end
+
+return Glowing
diff --git a/MMOCoreORB/bin/scripts/managers/jedi/village/mocks/glowing_mocks.lua b/MMOCoreORB/bin/scripts/managers/jedi/village/mocks/glowing_mocks.lua
new file mode 100755 (executable)
index 0000000..9a416a6
--- /dev/null
@@ -0,0 +1,26 @@
+local Glowing = require("managers.jedi.village.glowing")\r
+local realCheckForceStatusCommand\r
+local realOnPlayerLoggedIn\r
+\r
+local GlowingMocks = Glowing\r
+GlowingMocks.mocks = {}\r
+\r
+function GlowingMocks.mocks.setup()\r
+       realCheckForceStatusCommand = Glowing.checkForceStatusCommand\r
+       realOnPlayerLoggedIn = Glowing.onPlayerLoggedIn\r
+end\r
+\r
+function GlowingMocks.mocks.teardown()\r
+       Glowing.checkForceStatusCommand = realCheckForceStatusCommand\r
+       Glowing.onPlayerLoggedIn = realOnPlayerLoggedIn\r
+end\r
+\r
+function GlowingMocks.mocks.before_each()\r
+       Glowing.checkForceStatusCommand = spy.new(function() end)\r
+       Glowing.onPlayerLoggedIn = spy.new(function() end)\r
+end\r
+\r
+function GlowingMocks.mocks.after_each()\r
+end\r
+\r
+return GlowingMocks
\ No newline at end of file
old mode 100644 (file)
new mode 100755 (executable)
index 590567f..6fb3450
@@ -1,32 +1,35 @@
+local OldMan = require("managers.jedi.village.old_man")
+
 local realCreateSpawnOldManEvent
 local realOldManBelongsToThePlayer
 local realScheduleDespawnOfOldMan
 local realGiveForceCrystalToPlayer
 
-local OldManMocks = {}
+local OldManMocks = OldMan
+OldManMocks.mocks = {}
 
-function OldManMocks.setup()
+function OldManMocks.mocks.setup()
        realCreateSpawnOldManEvent = OldMan.createSpawnOldManEvent
        realOldManBelongsToThePlayer = OldMan.oldManBelongsToThePlayer
        realScheduleDespawnOfOldMan = OldMan.scheduleDespawnOfOldMan
        realGiveForceCrystalToPlayer = OldMan.giveForceCrystalToPlayer
 end
 
-function OldManMocks.teardown()
+function OldManMocks.mocks.teardown()
        OldMan.createSpawnOldManEvent = realCreateSpawnOldManEvent
        OldMan.oldManBelongsToThePlayer = realOldManBelongsToThePlayer
        OldMan.scheduleDespawnOfOldMan = realScheduleDespawnOfOldMan
        OldMan.giveForceCrystalToPlayer = realGiveForceCrystalToPlayer
 end
 
-function OldManMocks.before_each()
+function OldManMocks.mocks.before_each()
        OldMan.createSpawnOldManEvent = spy.new(function() end)
        OldMan.oldManBelongsToThePlayer = spy.new(function() return false end)
        OldMan.scheduleDespawnOfOldMan = spy.new(function() end)
        OldMan.giveForceCrystalToPlayer = spy.new(function() end)
 end
 
-function OldManMocks.after_each()
+function OldManMocks.mocks.after_each()
 end
 
 return OldManMocks
diff --git a/MMOCoreORB/bin/scripts/managers/jedi/village/mocks/village_jedi_manager_common_mocks.lua b/MMOCoreORB/bin/scripts/managers/jedi/village/mocks/village_jedi_manager_common_mocks.lua
new file mode 100644 (file)
index 0000000..4c2c7d5
--- /dev/null
@@ -0,0 +1,31 @@
+local VillageJediManagerCommon = require("managers.jedi.village.village_jedi_manager_common")
+
+local realHasJediProgressionScreenPlayState
+local realSetJediProgressionScreenPlayState
+
+local VillageJediManagerCommonMocks = VillageJediManagerCommon
+VillageJediManagerCommonMocks.mocks = {}
+
+-- Function to be called in the setup method for a test to prepare the mocks.
+function VillageJediManagerCommonMocks.mocks.setup()
+       realHasJediProgressionScreenPlayState = VillageJediManagerCommonMocks.hasJediProgressionScreenPlayState
+       realSetJediProgressionScreenPlayState = VillageJediManagerCommonMocks.setJediProgressionScreenPlayState
+end
+
+-- Function to be called in the teardown method for a test to clean up the mocks.
+function VillageJediManagerCommonMocks.mocks.teardown()
+       VillageJediManagerCommon.hasJediProgressionScreenPlayState = realHasJediProgressionScreenPlayState
+       VillageJediManagerCommon.setJediProgressionScreenPlayState = realSetJediProgressionScreenPlayState
+end
+
+-- Function to be called in the before_each method for a test to prepare the mocks.
+function VillageJediManagerCommonMocks.mocks.before_each()
+       VillageJediManagerCommon.hasJediProgressionScreenPlayState = spy.new(function() end)
+       VillageJediManagerCommon.setJediProgressionScreenPlayState = spy.new(function() end)
+end
+
+-- Function to be called in the after_each method for a test to verify the mocks.
+function VillageJediManagerCommonMocks.mocks.after_each()
+end
+
+return VillageJediManagerCommonMocks
old mode 100644 (file)
new mode 100755 (executable)
index c283dcd..61716e8
@@ -1,6 +1,5 @@
-package.path = package.path .. ";scripts/managers/jedi/village/?.lua;scripts/screenplays/mocks/?.lua"
-local DirectorManagerMocks = require("director_manager_mocks")
-require("village_jedi_manager")
+local DirectorManagerMocks = require("screenplays.mocks.director_manager_mocks")
+require("managers.jedi.village.village_jedi_manager")
 
 local realCheckForceStatusCommand
 local realHasJediProgressionScreenPlayState
old mode 100644 (file)
new mode 100755 (executable)
index 04188e5..38ddf69
@@ -1,5 +1,23 @@
-package.path = package.path .. ";scripts/screenplays?.lua"
-require("screenplay")
+local ScreenPlay = require("screenplays.screenplay")
+local VillageJediManagerCommon = require("managers.jedi.village.village_jedi_manager_common")
+
+local OldMan = {}
+OldManPublicEventsAndObservers = {}
+local OldManPrivate = ScreenPlay:new {}
+
+-- Expose private functions for testing.
+function OldMan.exposePrivateFunctions()
+       if BUSTED_TEST then
+               OldMan.private = OldManPrivate
+               OldMan.global = OldManPublicEventsAndObservers
+       end
+end
+
+-- Hide private functions.
+function OldMan.hidePrivateFunctions()
+       OldMan.private = {}
+       OldMan.global = {}
+end
 
 OLD_MAN_MIN_SPAWN_DISTANCE = 32
 OLD_MAN_MAX_SPAWN_DISTANCE = 64
@@ -23,12 +41,10 @@ OLD_MAN_NO_OLD_MAN_SPAWNED = 0
 OLD_MAN_INVENTORY_STRING = "inventory"
 OLD_MAN_FORCE_CRYSTAL_STRING = "object/tangible/loot/quest/force_sensitive/force_crystal.iff"
 
-OldMan = ScreenPlay:new {}
-
 -- Spawn the old man near the player.
 -- @pCreatureObject pointer to the creature object of the player.
-function OldMan.spawnOldMan(pCreatureObject)
-       return OldMan.withSceneObject(pCreatureObject, function(sceneObject)
+function OldManPrivate.spawnOldMan(pCreatureObject)
+       return OldManPrivate.withSceneObject(pCreatureObject, function(sceneObject)
                local spawnPoint = getSpawnPoint(pCreatureObject, sceneObject:getWorldPositionX(), sceneObject:getWorldPositionY(), OLD_MAN_MIN_SPAWN_DISTANCE, OLD_MAN_MAX_SPAWN_DISTANCE)
                if spawnPoint ~= nil then
                        return spawnMobile(sceneObject:getZoneName(), OLD_MAN_TEMPLATE, OLD_MAN_RESPAWN_TIME, spawnPoint[1], spawnPoint[2], spawnPoint[3], OLD_MAN_HEADING, sceneObject:getParentID())
@@ -41,8 +57,8 @@ end
 -- @param pCreatureObject pointer to the creature object of the player.
 -- @param key the key to read the value from.
 -- @return the value written on the key.
-function OldMan.getScreenPlayStateFromPlayer(pCreatureObject, key)
-       return OldMan.withCreatureObject(pCreatureObject, function(creatureObject)
+function OldManPrivate.getScreenPlayStateFromPlayer(pCreatureObject, key)
+       return OldManPrivate.withCreatureObject(pCreatureObject, function(creatureObject)
                return creatureObject:getScreenPlayState(key)
        end)
 end
@@ -51,8 +67,8 @@ end
 -- @param pCreatureObject pointer to the creature object of the player.
 -- @param key the key to read the value from.
 -- @return the value written on the key.
-function OldMan.readTransientDataFromThePlayer(pCreatureObject, key)
-       return OldMan.withCreatureObject(pCreatureObject, function(creatureObject)
+function OldManPrivate.readTransientDataFromThePlayer(pCreatureObject, key)
+       return OldManPrivate.withCreatureObject(pCreatureObject, function(creatureObject)
                return readData(creatureObject:getObjectID() .. key)
        end)
 end
@@ -60,16 +76,16 @@ end
 -- Read the id of the old man from the player he was spawned for.
 -- @param pCreatureObject pointer to the creature object of the player who got the old man spawned.
 -- @return the id of the old man stored on the player.
-function OldMan.readOldManIdFromPlayer(pCreatureObject)
-       return OldMan.readTransientDataFromThePlayer(pCreatureObject, OLD_MAN_ID_STRING)
+function OldManPrivate.readOldManIdFromPlayer(pCreatureObject)
+       return OldManPrivate.readTransientDataFromThePlayer(pCreatureObject, OLD_MAN_ID_STRING)
 end
 
 -- Write persistent data to the player.
 -- @param pCreatureObject pointer to the creature object of the player.
 -- @param key the key to write the value to.
 -- @param value the value to write.
-function OldMan.setScreenPlayStateOnPlayer(pCreatureObject, key, value)
-       OldMan.withCreatureObject(pCreatureObject, function(creatureObject)
+function OldManPrivate.setScreenPlayStateOnPlayer(pCreatureObject, key, value)
+       OldManPrivate.withCreatureObject(pCreatureObject, function(creatureObject)
                creatureObject:setScreenPlayState(value, key)
        end)
 end
@@ -78,8 +94,8 @@ end
 -- @param pCreatureObject pointer to the creature object of the player.
 -- @param key the key to clear the value in.
 -- @param value the value to clear.
-function OldMan.removeScreenPlayStateOnPlayer(pCreatureObject, key, value)
-       OldMan.withCreatureObject(pCreatureObject, function(creatureObject)
+function OldManPrivate.removeScreenPlayStateOnPlayer(pCreatureObject, key, value)
+       OldManPrivate.withCreatureObject(pCreatureObject, function(creatureObject)
                creatureObject:removeScreenPlayState(value, key)
        end)
 end
@@ -88,8 +104,8 @@ end
 -- @param pCreatureObject pointer to the creature object of the player.
 -- @param key the key to write the value to.
 -- @param value the value to write.
-function OldMan.writeTransientDataToThePlayer(pCreatureObject, key, value)
-       OldMan.withCreatureObject(pCreatureObject, function(creatureObject)
+function OldManPrivate.writeTransientDataToThePlayer(pCreatureObject, key, value)
+       OldManPrivate.withCreatureObject(pCreatureObject, function(creatureObject)
                writeData(creatureObject:getObjectID() .. key, value)
        end)
 end
@@ -97,17 +113,17 @@ end
 -- Save the id of the old man to only enable the old man for the player he was spawned for.
 -- @param pCreatureObject pointer to the creature object of the player who got the old man spawned.
 -- @param pOldMan pointer to the creature object of the spawned old man.
-function OldMan.saveOldManIdOnPlayer(pCreatureObject, pOldMan)
-       OldMan.withCreatureObject(pOldMan, function(oldManCreatureObject)
-               OldMan.writeTransientDataToThePlayer(pCreatureObject, OLD_MAN_ID_STRING, oldManCreatureObject:getObjectID())
+function OldManPrivate.saveOldManIdOnPlayer(pCreatureObject, pOldMan)
+       OldManPrivate.withCreatureObject(pOldMan, function(oldManCreatureObject)
+               OldManPrivate.writeTransientDataToThePlayer(pCreatureObject, OLD_MAN_ID_STRING, oldManCreatureObject:getObjectID())
        end)
 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 OldMan.isPlayerOnline(pCreatureObject)
-       return OldMan.withCreaturePlayerObject(pCreatureObject, function(playerObject)
+function OldManPrivate.isPlayerOnline(pCreatureObject)
+       return OldManPrivate.withCreaturePlayerObject(pCreatureObject, function(playerObject)
                return playerObject:isOnline()
        end) == true
 end
@@ -115,8 +131,8 @@ 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 OldMan.isPlayerInABuilding(pCreatureObject)
-       return OldMan.withSceneObject(pCreatureObject, function(sceneObject)
+function OldManPrivate.isPlayerInABuilding(pCreatureObject)
+       return OldManPrivate.withSceneObject(pCreatureObject, function(sceneObject)
                return not (sceneObject:getParentID() == NOTINABUILDING)
        end) == true
 end
@@ -124,10 +140,10 @@ 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 OldMan.isPlayerInNpcCity(pCreatureObject)
-       return OldMan.withSceneObject(pCreatureObject, function(sceneObject)
+function OldManPrivate.isPlayerInNpcCity(pCreatureObject)
+       return OldManPrivate.withSceneObject(pCreatureObject, function(sceneObject)
                local pCityRegion = getCityRegionAt(sceneObject:getZoneName(), sceneObject:getWorldPositionX(), sceneObject:getWorldPositionY())
-               local inNpcCity = OldMan.withCityRegion(pCityRegion, function(cityRegion)
+               local inNpcCity = OldManPrivate.withCityRegion(pCityRegion, function(cityRegion)
                        return not cityRegion:isClientRegion()
                end)
                return inNpcCity == true
@@ -137,32 +153,32 @@ end
 -- Check if the player is in a postion where the old man can be spawned.
 -- @param pCreatureObject pointer to the creature object of the player.
 -- @return true if the player is in a position where the old man can be spawned.
-function OldMan.canOldManBeSpawned(pCreatureObject)
-       return (OldMan.isPlayerOnline(pCreatureObject) and not OldMan.isPlayerInABuilding(pCreatureObject) and not OldMan.isPlayerInNpcCity(pCreatureObject))
+function OldManPrivate.canOldManBeSpawned(pCreatureObject)
+       return (OldManPrivate.isPlayerOnline(pCreatureObject) and not OldManPrivate.isPlayerInABuilding(pCreatureObject) and not OldManPrivate.isPlayerInNpcCity(pCreatureObject))
 end
 
 -- Set a creature to follow another creature.
 -- @param pCreatureObject pointer to the creature who should follow another creature.
 -- @param pFollowObject pointer to the creature object of the creature to follow.
-function OldMan.setToFollow(pCreatureObject, pFollowObject)
-       OldMan.withCreatureAiAgent(pCreatureObject, function(aiAgent)
+function OldManPrivate.setToFollow(pCreatureObject, pFollowObject)
+       OldManPrivate.withCreatureAiAgent(pCreatureObject, function(aiAgent)
                aiAgent:setFollowObject(pFollowObject)
        end)
 end
 
 -- Function to handle the stop follow player event for the old man.
 -- @param pCreatureObject pointer to the creature object of the player who got an old man that should stop following.
-function OldMan:handleStopFollowPlayerEvent(pCreatureObject)
-       local oldManId = OldMan.readOldManIdFromPlayer(pCreatureObject)
+function OldManPublicEventsAndObservers:handleStopFollowPlayerEvent(pCreatureObject)
+       local oldManId = OldManPrivate.readOldManIdFromPlayer(pCreatureObject)
        local pOldMan = getSceneObject(oldManId)
-       OldMan.setToFollow(pOldMan, nil)
+       OldManPrivate.setToFollow(pOldMan, nil)
 end
 
 -- Get the first name of the player.
 -- @param pCreatureObject pointer to the creature object of the player.
 -- @return the first name of the player.
-function OldMan.getPlayerFirstName(pCreatureObject)
-       local firstName = OldMan.withCreatureObject(pCreatureObject, function(creatureObject)
+function OldManPrivate.getPlayerFirstName(pCreatureObject)
+       local firstName = OldManPrivate.withCreatureObject(pCreatureObject, function(creatureObject)
                return creatureObject:getFirstName()
        end)
 
@@ -176,36 +192,36 @@ end
 -- FUnction that sends the greeting string to the player from the old man.
 -- @param pOldMan pointer to the creature object of the old man.
 -- @param pCreatureObject pointer to the creature object of the player.
-function OldMan.sendGreetingString(pOldMan, pCreatureObject)
+function OldManPrivate.sendGreetingString(pOldMan, pCreatureObject)
        local greetingString = LuaStringIdChatParameter(OLD_MAN_GREETING_STRING)
-       local firstName = OldMan.getPlayerFirstName(pCreatureObject)
+       local firstName = OldManPrivate.getPlayerFirstName(pCreatureObject)
        greetingString:setTT(firstName)
        spatialChat(pOldMan, greetingString:_getObject())
 end
 
 -- Function to handle the spatial chat event for the old man.
 -- @param pCreatureObject pointer to the creature object of the player who got an old man that should say something in spatial chat.
-function OldMan:handleSpatialChatEvent(pCreatureObject)
-       local oldManId = OldMan.readOldManIdFromPlayer(pCreatureObject)
+function OldManPublicEventsAndObservers:handleSpatialChatEvent(pCreatureObject)
+       local oldManId = OldManPrivate.readOldManIdFromPlayer(pCreatureObject)
        local pOldMan = getSceneObject(oldManId)
-       OldMan.sendGreetingString(pOldMan, pCreatureObject)
+       OldManPrivate.sendGreetingString(pOldMan, pCreatureObject)
 end
 
 -- Despawn the old man.
 -- @param pointer to the creature object of the old man.
-function OldMan.despawnOldMan(pOldMan)
-       OldMan.withSceneObject(pOldMan, function(sceneObject)
+function OldManPrivate.despawnOldMan(pOldMan)
+       OldManPrivate.withSceneObject(pOldMan, function(sceneObject)
                sceneObject:destroyObjectFromWorld()
        end)
 end
 
 -- Function to handle the despawn of the old man.
 -- @param pCreatureObject pointer to the creature object of the player whos old man should despawn.
-function OldMan:handleDespawnEvent(pCreatureObject)
-       local oldManId = OldMan.readOldManIdFromPlayer(pCreatureObject)
+function OldManPublicEventsAndObservers:handleDespawnEvent(pCreatureObject)
+       local oldManId = OldManPrivate.readOldManIdFromPlayer(pCreatureObject)
        local pOldMan = getSceneObject(oldManId)
-       OldMan.despawnOldMan(pOldMan)
-       OldMan.writeTransientDataToThePlayer(pCreatureObject, OLD_MAN_ID_STRING, OLD_MAN_NO_OLD_MAN_SPAWNED)
+       OldManPrivate.despawnOldMan(pOldMan)
+       OldManPrivate.writeTransientDataToThePlayer(pCreatureObject, OLD_MAN_ID_STRING, OLD_MAN_NO_OLD_MAN_SPAWNED)
        OldMan.createSpawnOldManEvent(pCreatureObject)
 end
 
@@ -213,19 +229,19 @@ end
 -- @param pCreatureObject pointer to the creature object of the player whos old man should be despawned.
 -- @param time time until the old man should despawn.
 function OldMan.scheduleDespawnOfOldMan(pCreatureObject, time)
-       createEvent(time, "OldMan", "handleDespawnEvent", pCreatureObject)
+       createEvent(time, "OldManPublicEventsAndObservers", "handleDespawnEvent", pCreatureObject)
 end
 
 -- Try to spawn the old man and create the needed events.
 -- @param pCreatureObject pointer to the creature object of the player who should get the old man spawned.
 -- @return true if everything were successful.
-function OldMan.tryToSpawnOldMan(pCreatureObject)
-       local pOldMan = OldMan.spawnOldMan(pCreatureObject)
+function OldManPrivate.tryToSpawnOldMan(pCreatureObject)
+       local pOldMan = OldManPrivate.spawnOldMan(pCreatureObject)
        if pOldMan ~= nil then
-               OldMan.saveOldManIdOnPlayer(pCreatureObject, pOldMan)
-               OldMan.setToFollow(pOldMan, pCreatureObject)
-               createEvent(OLD_MAN_STOP_FOLLOW_TIME, "OldMan", "handleStopFollowPlayerEvent", pCreatureObject)
-               createEvent(OLD_MAN_SPATIAL_CHAT_TIME, "OldMan", "handleSpatialChatEvent", pCreatureObject)
+               OldManPrivate.saveOldManIdOnPlayer(pCreatureObject, pOldMan)
+               OldManPrivate.setToFollow(pOldMan, pCreatureObject)
+               createEvent(OLD_MAN_STOP_FOLLOW_TIME, "OldManPublicEventsAndObservers", "handleStopFollowPlayerEvent", pCreatureObject)
+               createEvent(OLD_MAN_SPATIAL_CHAT_TIME, "OldManPublicEventsAndObservers", "handleSpatialChatEvent", pCreatureObject)
                OldMan.scheduleDespawnOfOldMan(pCreatureObject, OLD_MAN_DESPAWN_TIME)
                return true
        else
@@ -235,10 +251,10 @@ end
 
 -- Function to handle the old man event.
 -- @param pCreatureObject pointer to the creature object who should have an event created for spawning the old man.
-function OldMan:handleSpawnOldManEvent(pCreatureObject)
-       OldMan.removeScreenPlayStateOnPlayer(pCreatureObject, OLD_MAN_EVENT_SCHEDULED_STRING, OLD_MAN_SCHEDULED)
-       if OldMan.canOldManBeSpawned(pCreatureObject) then
-               if not OldMan.tryToSpawnOldMan(pCreatureObject) then
+function OldManPublicEventsAndObservers:handleSpawnOldManEvent(pCreatureObject)
+       OldManPrivate.removeScreenPlayStateOnPlayer(pCreatureObject, OLD_MAN_EVENT_SCHEDULED_STRING, OLD_MAN_SCHEDULED)
+       if OldManPrivate.canOldManBeSpawned(pCreatureObject) then
+               if not OldManPrivate.tryToSpawnOldMan(pCreatureObject) then
                        OldMan.createSpawnOldManEvent(pCreatureObject)
                end
        else
@@ -249,27 +265,27 @@ end
 -- Check if an event has already been scheduled for spawning the old man for this player.
 -- @param pCreatureObject pointer to the creature object of the player.
 -- return true if an event is already scheduled.
-function OldMan.hasOldManSpawnEventScheduled(pCreatureObject)
-       return OldMan.getScreenPlayStateFromPlayer(pCreatureObject, OLD_MAN_EVENT_SCHEDULED_STRING) == OLD_MAN_SCHEDULED
+function OldManPrivate.hasOldManSpawnEventScheduled(pCreatureObject)
+       return OldManPrivate.getScreenPlayStateFromPlayer(pCreatureObject, OLD_MAN_EVENT_SCHEDULED_STRING) == OLD_MAN_SCHEDULED
 end
 
 -- Check if the spawn event should be created.
 -- @param pCreatureObject pointer to the creature object of the player.
 -- @return true if the spawn event should be created.
-function OldMan.shouldSpawnOldManEventBeCreated(pCreatureObject)
-       local eventNotScheduled = not OldMan.hasOldManSpawnEventScheduled(pCreatureObject)
-       local oldManNotSpawned = OldMan.readOldManIdFromPlayer(pCreatureObject) == OLD_MAN_NO_OLD_MAN_SPAWNED
-       local doesNotHaveCrystal = not VillageJediManager.hasJediProgressionScreenPlayState(pCreatureObject, VILLAGE_JEDI_PROGRESSION_HAS_CRYSTAL)
+function OldManPrivate.shouldSpawnOldManEventBeCreated(pCreatureObject)
+       local eventNotScheduled = not OldManPrivate.hasOldManSpawnEventScheduled(pCreatureObject)
+       local oldManNotSpawned = OldManPrivate.readOldManIdFromPlayer(pCreatureObject) == OLD_MAN_NO_OLD_MAN_SPAWNED
+       local doesNotHaveCrystal = not VillageJediManagerCommon.hasJediProgressionScreenPlayState(pCreatureObject, VILLAGE_JEDI_PROGRESSION_HAS_CRYSTAL)
        return eventNotScheduled and oldManNotSpawned and doesNotHaveCrystal
 end
 
 -- Generate an event to spawn the old man for the player.
 -- @param pCreatureObject pointer to the creature object who should have an event created for spawning the old man.
 function OldMan.createSpawnOldManEvent(pCreatureObject)
-       if OldMan.shouldSpawnOldManEventBeCreated(pCreatureObject) then
-               OldMan.setScreenPlayStateOnPlayer(pCreatureObject, OLD_MAN_EVENT_SCHEDULED_STRING, OLD_MAN_SCHEDULED)
+       if OldManPrivate.shouldSpawnOldManEventBeCreated(pCreatureObject) then
+               OldManPrivate.setScreenPlayStateOnPlayer(pCreatureObject, OLD_MAN_EVENT_SCHEDULED_STRING, OLD_MAN_SCHEDULED)
                local time = OLD_MAN_SPAWN_TIME + math.random(OLD_MAN_SPAWN_TIME)
-               createEvent(true, time, "OldMan", "handleSpawnOldManEvent", pCreatureObject)
+               createEvent(true, time, "OldManPublicEventsAndObservers", "handleSpawnOldManEvent", pCreatureObject)
        end
 end
 
@@ -278,20 +294,20 @@ end
 -- @param pConversingNpc pointer to the creature object of the old man.
 -- @return true if the old man belongs to the player.
 function OldMan.oldManBelongsToThePlayer(pConversingPlayer, pConversingNpc)
-       return OldMan.withCreatureObject(pConversingNpc, function(oldManCreatureObject)
-               return OldMan.readOldManIdFromPlayer(pConversingPlayer) == oldManCreatureObject:getObjectID()
+       return OldManPrivate.withCreatureObject(pConversingNpc, function(oldManCreatureObject)
+               return OldManPrivate.readOldManIdFromPlayer(pConversingPlayer) == oldManCreatureObject:getObjectID()
        end) == true
 end
 
 -- Give the force crystal to the player.
 -- @param pCreatureObject pointer to the creature object of the player.
 function OldMan.giveForceCrystalToPlayer(pCreatureObject)
-       OldMan.withCreatureObject(pCreatureObject, function(creatureObject)
+       OldManPrivate.withCreatureObject(pCreatureObject, function(creatureObject)
                local pInventory = creatureObject:getSlottedObject(OLD_MAN_INVENTORY_STRING)
 
                if pInventory ~= nil then
                        giveItem(pInventory, OLD_MAN_FORCE_CRYSTAL_STRING, -1)
-                       VillageJediManager.setJediProgressionScreenPlayState(pCreatureObject, VILLAGE_JEDI_PROGRESSION_HAS_CRYSTAL)
+                       VillageJediManagerCommon.setJediProgressionScreenPlayState(pCreatureObject, VILLAGE_JEDI_PROGRESSION_HAS_CRYSTAL)
                end
        end)
 end
old mode 100644 (file)
new mode 100755 (executable)
index 9bf6a82..c1c347d
@@ -1,3 +1,6 @@
+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
 
 old_man_conv_handler = Object:new {
@@ -59,9 +62,9 @@ function old_man_conv_handler.handleInit(pConversationTemplate, pConversingPlaye
        local nextScreen = "not_you"
 
        if OldMan.oldManBelongsToThePlayer(pConversingPlayer, pConversingNpc) then
-               if VillageJediManager.hasJediProgressionScreenPlayState(pConversingPlayer, VILLAGE_JEDI_PROGRESSION_COMPLETED_VILLAGE) then
+               if VillageJediManagerCommon.hasJediProgressionScreenPlayState(pConversingPlayer, VILLAGE_JEDI_PROGRESSION_COMPLETED_VILLAGE) then
                        nextScreen = "mellichae_intro"
-               elseif VillageJediManager.hasJediProgressionScreenPlayState(pConversingPlayer, VILLAGE_JEDI_PROGRESSION_GLOWING) then
+               elseif VillageJediManagerCommon.hasJediProgressionScreenPlayState(pConversingPlayer, VILLAGE_JEDI_PROGRESSION_GLOWING) then
                        nextScreen = "village_intro"
                end
        end
diff --git a/MMOCoreORB/bin/scripts/managers/jedi/village/tests/glowing_Test.lua b/MMOCoreORB/bin/scripts/managers/jedi/village/tests/glowing_Test.lua
new file mode 100755 (executable)
index 0000000..bf6d2b5
--- /dev/null
@@ -0,0 +1,298 @@
+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 VillageJediManagerCommonMocks = require("managers.jedi.village.mocks.village_jedi_manager_common_mocks")
+
+describe("Village Jedi Manager - Glowing", function()
+       local pCreatureObject = { "creatureObjectPointer" }
+       local pPlayerObject = { "playerObjectPointer" }
+       local creatureObject
+       local playerObject
+
+       setup(function()
+               DirectorManagerMocks.setup()
+               VillageJediManagerCommonMocks.mocks.setup()
+               OldManMocks.mocks.setup()
+
+               Glowing.exposePrivateFunctions()
+       end)
+
+       teardown(function()
+               DirectorManagerMocks.teardown()
+               VillageJediManagerCommonMocks.mocks.teardown()
+               OldManMocks.mocks.teardown()
+
+               Glowing.hidePrivateFunctions()
+       end)
+
+       before_each(function()
+               DirectorManagerMocks.before_each()
+               VillageJediManagerCommonMocks.mocks.before_each()
+               OldManMocks.mocks.before_each()
+
+               creatureObject = {}
+               creatureObject.getPlayerObject = spy.new(function() return pPlayerObject end)
+               creatureObject.sendSystemMessage = spy.new(function() end)
+               DirectorManagerMocks.creatureObjects[pCreatureObject] = creatureObject
+
+               playerObject = {}
+               playerObject.hasBadge = spy.new(function() return false end)
+               DirectorManagerMocks.playerObjects[pPlayerObject] = playerObject
+       end)
+
+       describe("Interface functions", function()
+               describe("checkForceStatusCommand", function()
+                       it("Should call getJediProgressionStatus and send the appropriate string id to the player", function()
+                               local realGetJediProgressionStatus = Glowing.private.getJediProgressionStatus
+                               Glowing.private.getJediProgressionStatus = spy.new(function() return 2 end)
+
+                               Glowing.checkForceStatusCommand(pCreatureObject)
+
+                               assert.spy(Glowing.private.getJediProgressionStatus).was.called_with(pCreatureObject)
+                               assert.spy(creatureObject.sendSystemMessage).was.called_with(creatureObject, "@jedi_spam:fs_progress_2")
+
+                               Glowing.private.getJediProgressionStatus = realGetJediProgressionStatus
+                       end)
+               end)
+
+               describe("onPlayerLoggedIn", function()
+                       local realIsGlowing
+                       local realRegisterObservers
+
+                       setup(function()
+                               realIsGlowing = Glowing.private.isGlowing
+                               realRegisterObservers = Glowing.private.registerObservers
+                       end)
+
+                       teardown(function()
+                               Glowing.private.isGlowing = realIsGlowing
+                               Glowing.private.registerObservers = realRegisterObservers
+                       end)
+
+                       before_each(function()
+                               Glowing.private.isGlowing = spy.new(function() return false end)
+                               Glowing.private.registerObservers = spy.new(function() end)
+                       end)
+
+                       describe("When called with a player as argument", function()
+                               it("Should check if the player is glowing or not.", function()
+                                       Glowing.onPlayerLoggedIn(pCreatureObject)
+
+                                       assert.spy(Glowing.private.isGlowing).was.called_with(pCreatureObject)
+                               end)
+
+                               describe("and the player is glowing", function()
+                                       it("Should not register observers on the player.", function()
+                                               Glowing.private.isGlowing = spy.new(function() return true end)
+
+                                               Glowing.onPlayerLoggedIn(pCreatureObject)
+
+                                               assert.spy(Glowing.private.registerObservers).was.not_called()
+                                       end)
+                               end)
+
+                               describe("and the player is not glowing", function()
+                                       it("Should register observers on the player.", function()
+                                               Glowing.onPlayerLoggedIn(pCreatureObject)
+
+                                               assert.spy(Glowing.private.registerObservers).was.called_with(pCreatureObject)
+                                       end)
+                               end)
+                       end)
+               end)
+       end)
+
+       describe("Private functions", function()
+               describe("countBadgesInListToUpperLimit", function()
+                       local list = { 1, 2, 3, 4 }
+                       local currentListItem = 0
+
+                       before_each(function()
+                               currentListItem = 0
+                       end)
+
+                       it("Should check if the player has each badge number in the list", function()
+                               playerObject.hasBadge = spy.new(function(playerObject, badgeNumber)
+                                       currentListItem = currentListItem + 1
+                                       return badgeNumber == list[currentListItem]
+                               end)
+
+                               assert.is.same(Glowing.private.countBadgesInListToUpperLimit(pCreatureObject, list, 10), 4)
+
+                               assert.spy(playerObject.hasBadge).was.called(4)
+                       end)
+
+                       it("Should return the correct number of badges that the player has", function()
+                               playerObject.hasBadge = spy.new(function(playerObject, badgeNumber)
+                                       return badgeNumber < 3
+                               end)
+
+                               assert.is.same(Glowing.private.countBadgesInListToUpperLimit(pCreatureObject, list, 10), 2)
+
+                               assert.spy(playerObject.hasBadge).was.called(4)
+                       end)
+
+                       it("Should abort the counting early if upper limit is reached", function()
+                               playerObject.hasBadge = spy.new(function(playerObject, badgeNumber)
+                                       return badgeNumber < 4
+                               end)
+
+                               assert.is.same(Glowing.private.countBadgesInListToUpperLimit(pCreatureObject, list, 2), 2)
+
+                               assert.spy(playerObject.hasBadge).was.called(2)
+                       end)
+               end)
+
+               describe("countBadges", function()
+                       local realCountBadgesInListToUpperLimit
+
+                       setup(function()
+                               realCountBadgesInListToUpperLimit = Glowing.private.countBadgesInListToUpperLimit
+                       end)
+
+                       teardown(function()
+                               Glowing.private.countBadgesInListToUpperLimit = realCountBadgesInListToUpperLimit
+                       end)
+
+                       it("Should call the countBadgesInListToUpperLimit five times with correct arguments", function()
+                               local argumentList = {
+                                       { PROFESSIONBADGES, 1, false },
+                                       { JEDIBADGES, 3, false },
+                                       { CONTENTBADGES, 5, false },
+                                       { DIFFICULTBADGES, 3, false },
+                                       { EASYBADGES, 5, false }
+                               }
+
+                               Glowing.private.countBadgesInListToUpperLimit = spy.new(function(pCO, l, n)
+                                       for i = 1, table.getn(argumentList), 1 do
+                                               if argumentList[i][1] == l and argumentList[i][2] == n and pCO == pCreatureObject then
+                                                       argumentList[i][3] = true
+                                               end
+                                       end
+                                       return 0
+                               end)
+
+                               assert.is.same(Glowing.private.countBadges(pCreatureObject), 0)
+
+                               assert.is.same(argumentList[1][3] and argumentList[2][3] and argumentList[3][3] and argumentList[4][3] and argumentList[5][3], true)
+                               assert.spy(Glowing.private.countBadgesInListToUpperLimit).was.called(5)
+                       end)
+
+                       it("Should sum the return values from countBadgesInListToUpperLimit", function()
+                               local returnList = {
+                                       1, 1, 1, 1, 1,
+                                       2, 2, 2, 2, 2,
+                                       3, 3, 3, 3, 3,
+                                       3, 4, 3, 6, 7
+                               }
+                               local returnNo = 0
+
+                               Glowing.private.countBadgesInListToUpperLimit = spy.new(function()
+                                       returnNo = returnNo + 1
+                                       return returnList[returnNo]
+                               end)
+
+                               assert.is.same(Glowing.private.countBadges(pCreatureObject), 5)
+                               assert.is.same(Glowing.private.countBadges(pCreatureObject), 10)
+                               assert.is.same(Glowing.private.countBadges(pCreatureObject), 15)
+                               assert.is.same(Glowing.private.countBadges(pCreatureObject), 23)
+                       end)
+               end)
+
+               describe("getJediProgressionStatus", function()
+                       it("Should return linear values between 0 and 5 depending on the number of counted badges", function()
+                               local returnValue = -1
+                               local realCountBadges = Glowing.private.countBadges
+                               Glowing.private.countBadges = spy.new(function()
+                                       returnValue = returnValue + 1
+                                       return returnValue
+                               end)
+
+                               assert.is.same(Glowing.private.getJediProgressionStatus(pCreatureObject), 0)
+                               assert.is.same(Glowing.private.getJediProgressionStatus(pCreatureObject), 0)
+                               assert.is.same(Glowing.private.getJediProgressionStatus(pCreatureObject), 0)
+                               assert.is.same(Glowing.private.getJediProgressionStatus(pCreatureObject), 0)
+                               assert.is.same(Glowing.private.getJediProgressionStatus(pCreatureObject), 1)
+                               assert.is.same(Glowing.private.getJediProgressionStatus(pCreatureObject), 1)
+                               assert.is.same(Glowing.private.getJediProgressionStatus(pCreatureObject), 1)
+                               assert.is.same(Glowing.private.getJediProgressionStatus(pCreatureObject), 2)
+                               assert.is.same(Glowing.private.getJediProgressionStatus(pCreatureObject), 2)
+                               assert.is.same(Glowing.private.getJediProgressionStatus(pCreatureObject), 2)
+                               assert.is.same(Glowing.private.getJediProgressionStatus(pCreatureObject), 2)
+                               assert.is.same(Glowing.private.getJediProgressionStatus(pCreatureObject), 3)
+                               assert.is.same(Glowing.private.getJediProgressionStatus(pCreatureObject), 3)
+                               assert.is.same(Glowing.private.getJediProgressionStatus(pCreatureObject), 3)
+                               assert.is.same(Glowing.private.getJediProgressionStatus(pCreatureObject), 4)
+                               assert.is.same(Glowing.private.getJediProgressionStatus(pCreatureObject), 4)
+                               assert.is.same(Glowing.private.getJediProgressionStatus(pCreatureObject), 4)
+                               assert.is.same(Glowing.private.getJediProgressionStatus(pCreatureObject), 5)
+
+                               assert.spy(Glowing.private.countBadges).was.called(18)
+
+                               Glowing.private.countBadges = realCountBadges
+                       end)
+               end)
+
+               describe("registerObservers", function()
+                       describe("When called with a player object", function()
+                               it("Should register an observer for the BADGEAWARDED event on the player.", function()
+                                       Glowing.private.registerObservers(pCreatureObject)
+
+                                       assert.spy(createObserver).was.called_with(BADGEAWARDED, "Glowing", "badgeAwardedEventHandler", pCreatureObject)
+                               end)
+                       end)
+               end)
+
+               describe("isGlowing", function()
+                       local realCountBadges
+
+                       setup(function()
+                               realCountBadges = Glowing.private.countBadges
+                       end)
+
+                       teardown(function()
+                               Glowing.private.countBadges = realCountBadges
+                       end)
+
+                       before_each(function()
+                               Glowing.private.countBadges = spy.new(function() return TOTALNUMBEROFBADGESREQUIRED end)
+                       end)
+
+                       describe("When called with a player as argument", function()
+                               it("Should count the number of badges the player has towards the jedi progression.", function()
+                                       Glowing.private.isGlowing(pCreatureObject)
+
+                                       assert.spy(Glowing.private.countBadges).was.called(1)
+                               end)
+
+                               describe("and the player has all the needed badges", function()
+                                       before_each(function()
+                                               Glowing.private.countBadges = spy.new(function() return TOTALNUMBEROFBADGESREQUIRED end)
+                                       end)
+
+                                       it("Should set the village jedi progression screen play state glowing on the player", function()
+                                               Glowing.private.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()
+                                               Glowing.private.isGlowing(pCreatureObject)
+
+                                               assert.spy(OldManMocks.createSpawnOldManEvent).was.called_with(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()
+                                               Glowing.private.countBadges = spy.new(function() return TOTALNUMBEROFBADGESREQUIRED - 1 end)
+
+                                               Glowing.private.isGlowing(pCreatureObject)
+
+                                               assert.spy(OldManMocks.createSpawnOldManEvent).was.not_called()
+                                       end)
+                               end)
+                       end)
+               end)
+       end)
+end)
old mode 100644 (file)
new mode 100755 (executable)
index 2326f26..65507a0
@@ -1,7 +1,8 @@
-package.path = package.path .. ";scripts/managers/jedi/village/?.lua;scripts/managers/jedi/village/mocks/?.lua;scripts/screenplays/mocks/?.lua"
-local DirectorManagerMocks = require("director_manager_mocks")
-local VillageJediManagerMocks = require("village_jedi_manager_mocks")
-require("old_man")
+BUSTED_TEST = true
+
+local DirectorManagerMocks = require("screenplays.mocks.director_manager_mocks")
+local OldMan = require("managers.jedi.village.old_man")
+local VillageJediManagerCommonMocks = require("managers.jedi.village.mocks.village_jedi_manager_common_mocks")
 
 describe("Old Man", function()
        local pCreatureObject = { "creatureObjectPointer" }
@@ -25,17 +26,21 @@ describe("Old Man", function()
 
        setup(function()
                DirectorManagerMocks.setup()
-               VillageJediManagerMocks.setup()
+               VillageJediManagerCommonMocks.mocks.setup()
+
+               OldMan.exposePrivateFunctions()
        end)
 
        teardown(function()
                DirectorManagerMocks.teardown()
-               VillageJediManagerMocks.teardown()
+               VillageJediManagerCommonMocks.mocks.teardown()
+
+               OldMan.hidePrivateFunctions()
        end)
 
        before_each(function()
                DirectorManagerMocks.before_each()
-               VillageJediManagerMocks.before_each()
+               VillageJediManagerCommonMocks.mocks.before_each()
 
                getCityRegionAt = spy.new(function() return pCityRegion end)
                getSceneObject = spy.new(function() return pOldMan end)
@@ -93,36 +98,36 @@ describe("Old Man", function()
                                local realReadOldManIdFromPlayer
 
                                setup(function()
-                                       realHasOldManSpawnEventScheduled = OldMan.hasOldManSpawnEventScheduled
-                                       realReadOldManIdFromPlayer = OldMan.readOldManIdFromPlayer
+                                       realHasOldManSpawnEventScheduled = OldMan.private.hasOldManSpawnEventScheduled
+                                       realReadOldManIdFromPlayer = OldMan.private.readOldManIdFromPlayer
                                end)
 
                                teardown(function()
-                                       OldMan.hasOldManSpawnEventScheduled = realHasOldManSpawnEventScheduled
-                                       OldMan.readOldManIdFromPlayer = realReadOldManIdFromPlayer
+                                       OldMan.private.hasOldManSpawnEventScheduled = realHasOldManSpawnEventScheduled
+                                       OldMan.private.readOldManIdFromPlayer = realReadOldManIdFromPlayer
                                end)
 
                                before_each(function()
-                                       OldMan.hasOldManSpawnEventScheduled = spy.new(function() return false end)
-                                       OldMan.readOldManIdFromPlayer = spy.new(function() return OLD_MAN_NO_OLD_MAN_SPAWNED end)
+                                       OldMan.private.hasOldManSpawnEventScheduled = spy.new(function() return false end)
+                                       OldMan.private.readOldManIdFromPlayer = spy.new(function() return OLD_MAN_NO_OLD_MAN_SPAWNED end)
                                end)
 
                                it("Should check if the player has an event already scheduled.", function()
                                        OldMan.createSpawnOldManEvent(pCreatureObject)
 
-                                       assert.spy(OldMan.hasOldManSpawnEventScheduled).was.called_with(pCreatureObject)
+                                       assert.spy(OldMan.private.hasOldManSpawnEventScheduled).was.called_with(pCreatureObject)
                                end)
 
                                it("Should check if the player has an old man already spawned.", function()
                                        OldMan.createSpawnOldManEvent(pCreatureObject)
 
-                                       assert.spy(OldMan.readOldManIdFromPlayer).was.called_with(pCreatureObject)
+                                       assert.spy(OldMan.private.readOldManIdFromPlayer).was.called_with(pCreatureObject)
                                end)
 
                                it("Should check if the player already has the crystal.", function()
                                        OldMan.createSpawnOldManEvent(pCreatureObject)
 
-                                       assert.spy(VillageJediManager.hasJediProgressionScreenPlayState).was.called_with(pCreatureObject, VILLAGE_JEDI_PROGRESSION_HAS_CRYSTAL)
+                                       assert.spy(VillageJediManagerCommonMocks.hasJediProgressionScreenPlayState).was.called_with(pCreatureObject, VILLAGE_JEDI_PROGRESSION_HAS_CRYSTAL)
                                end)
 
                                describe("and no event is scheduled, no old man has been spawned and the player does not have the crystal.", function()
@@ -141,7 +146,7 @@ describe("Old Man", function()
 
                                describe("and an event is already scheduled", function()
                                        before_each(function()
-                                               OldMan.hasOldManSpawnEventScheduled = spy.new(function() return true end)
+                                               OldMan.private.hasOldManSpawnEventScheduled = spy.new(function() return true end)
                                        end)
 
                                        it("Should not create an event for spawning the old man.", function()
@@ -159,7 +164,7 @@ describe("Old Man", function()
 
                                describe("and an old man has already been spawned", function()
                                        before_each(function()
-                                               OldMan.readOldManIdFromPlayer = spy.new(function() return oldManId end)
+                                               OldMan.private.readOldManIdFromPlayer = spy.new(function() return oldManId end)
                                        end)
 
                                        it("Should not create an event for spawning the old man.", function()
@@ -177,7 +182,7 @@ describe("Old Man", function()
 
                                describe("and the player has already gotten the crystal", function()
                                        before_each(function()
-                                               VillageJediManager.hasJediProgressionScreenPlayState = spy.new(function() return true end)
+                                               VillageJediManagerCommonMocks.hasJediProgressionScreenPlayState = spy.new(function() return true end)
                                        end)
 
                                        it("Should not create an event for spawning the old man.", function()
@@ -226,7 +231,7 @@ describe("Old Man", function()
                                it("Should create an event to despawn the old man.", function()
                                        OldMan.scheduleDespawnOfOldMan(pCreatureObject, OLD_MAN_DESPAWN_TIME)
 
-                                       assert.spy(createEvent).was.called_with(OLD_MAN_DESPAWN_TIME, "OldMan", "handleDespawnEvent", pCreatureObject)
+                                       assert.spy(createEvent).was.called_with(OLD_MAN_DESPAWN_TIME, "OldManPublicEventsAndObservers", "handleDespawnEvent", pCreatureObject)
                                end)
                        end)
                end)
@@ -249,7 +254,7 @@ describe("Old Man", function()
                                        it("Should update the village jedi progression state on the player.", function()
                                                OldMan.giveForceCrystalToPlayer(pCreatureObject)
 
-                                               assert.spy(VillageJediManager.setJediProgressionScreenPlayState).was.called_with(pCreatureObject, VILLAGE_JEDI_PROGRESSION_HAS_CRYSTAL)
+                                               assert.spy(VillageJediManagerCommonMocks.setJediProgressionScreenPlayState).was.called_with(pCreatureObject, VILLAGE_JEDI_PROGRESSION_HAS_CRYSTAL)
                                        end)
                                end)
 
@@ -267,14 +272,14 @@ describe("Old Man", function()
                                        it("Should not update the village jedi progression state on the player.", function()
                                                OldMan.giveForceCrystalToPlayer(pCreatureObject)
 
-                                               assert.spy(VillageJediManager.setJediProgressionScreenPlayState).was.not_called()
+                                               assert.spy(VillageJediManagerCommonMocks.setJediProgressionScreenPlayState).was.not_called()
                                        end)
                                end)
                        end)
                end)
        end)
 
-       describe("Private methods", function()
+       describe("Events", function()
                describe("handleSpawnOldManEvent", function()
                        describe("When event to spawn old man is triggered", function()
                                local realCanOldManBeSpawned
@@ -283,62 +288,200 @@ describe("Old Man", function()
                                local realSaveOldManIdOnPlayer
 
                                setup(function()
-                                       realCanOldManBeSpawned = OldMan.canOldManBeSpawned
-                                       realTryToSpawnOldMan = OldMan.tryToSpawnOldMan
+                                       realCanOldManBeSpawned = OldMan.private.canOldManBeSpawned
+                                       realTryToSpawnOldMan = OldMan.private.tryToSpawnOldMan
                                        realCreateSpawnOldManEvent = OldMan.createSpawnOldManEvent
-                                       realSaveOldManIdOnPlayer = OldMan.saveOldManIdOnPlayer
+                                       realSaveOldManIdOnPlayer = OldMan.private.saveOldManIdOnPlayer
                                end)
 
                                teardown(function()
-                                       OldMan.canOldManBeSpawned = realCanOldManBeSpawned
-                                       OldMan.tryToSpawnOldMan = realTryToSpawnOldMan
+                                       OldMan.private.canOldManBeSpawned = realCanOldManBeSpawned
+                                       OldMan.private.tryToSpawnOldMan = realTryToSpawnOldMan
                                        OldMan.createSpawnOldManEvent = realCreateSpawnOldManEvent
-                                       OldMan.saveOldManIdOnPlayer = realSaveOldManIdOnPlayer
+                                       OldMan.private.saveOldManIdOnPlayer = realSaveOldManIdOnPlayer
                                end)
 
                                before_each(function()
-                                       OldMan.canOldManBeSpawned = spy.new(function() return true end)
-                                       OldMan.tryToSpawnOldMan = spy.new(function() return true end)
+                                       OldMan.private.canOldManBeSpawned = spy.new(function() return true end)
+                                       OldMan.private.tryToSpawnOldMan = spy.new(function() return true end)
                                        OldMan.createSpawnOldManEvent = spy.new(function() end)
-                                       OldMan.saveOldManIdOnPlayer = spy.new(function() end)
+                                       OldMan.private.saveOldManIdOnPlayer = spy.new(function() end)
                                end)
 
                                it("Should reset screen play state about old man being scheduled.", function()
-                                       OldMan:handleSpawnOldManEvent(pCreatureObject)
+                                       OldMan.global:handleSpawnOldManEvent(pCreatureObject)
 
                                        assert.spy(creatureObjectPlayer.removeScreenPlayState).was.called_with(creatureObjectPlayer, OLD_MAN_SCHEDULED, OLD_MAN_EVENT_SCHEDULED_STRING)
                                end)
 
                                it("Should try to spawn the old man if the player is in a place where the old man can be spawned.", function()
-                                       OldMan:handleSpawnOldManEvent(pCreatureObject)
+                                       OldMan.global:handleSpawnOldManEvent(pCreatureObject)
 
-                                       assert.spy(OldMan.canOldManBeSpawned).was.called_with(pCreatureObject)
-                                       assert.spy(OldMan.tryToSpawnOldMan).was.called_with(pCreatureObject)
+                                       assert.spy(OldMan.private.canOldManBeSpawned).was.called_with(pCreatureObject)
+                                       assert.spy(OldMan.private.tryToSpawnOldMan).was.called_with(pCreatureObject)
                                        assert.spy(OldMan.createSpawnOldManEvent).was.not_called()
                                end)
 
                                it("Should reschedule the event if the player is not in a place where the old man can be spawned.", function()
-                                       OldMan.canOldManBeSpawned = spy.new(function() return false end)
+                                       OldMan.private.canOldManBeSpawned = spy.new(function() return false end)
 
-                                       OldMan:handleSpawnOldManEvent(pCreatureObject)
+                                       OldMan.global:handleSpawnOldManEvent(pCreatureObject)
 
-                                       assert.spy(OldMan.canOldManBeSpawned).was.called_with(pCreatureObject)
-                                       assert.spy(OldMan.tryToSpawnOldMan).was.not_called()
+                                       assert.spy(OldMan.private.canOldManBeSpawned).was.called_with(pCreatureObject)
+                                       assert.spy(OldMan.private.tryToSpawnOldMan).was.not_called()
                                        assert.spy(OldMan.createSpawnOldManEvent).was.called_with(pCreatureObject)
                                end)
 
                                it("Should reschedule the event if the spawning of the old man fails.", function()
-                                       OldMan.tryToSpawnOldMan = spy.new(function() return false end)
+                                       OldMan.private.tryToSpawnOldMan = spy.new(function() return false end)
+
+                                       OldMan.global:handleSpawnOldManEvent(pCreatureObject)
+
+                                       assert.spy(OldMan.private.canOldManBeSpawned).was.called_with(pCreatureObject)
+                                       assert.spy(OldMan.private.tryToSpawnOldMan).was.called_with(pCreatureObject)
+                                       assert.spy(OldMan.createSpawnOldManEvent).was.called_with(pCreatureObject)
+                               end)
+                       end)
+               end)
+
+               describe("handleStopFollowPlayerEvent", function()
+                       local realSetToFollow
+                       local realReadOldManIdFromPlayer
+
+                       setup(function()
+                               realSetToFollow = OldMan.private.setToFollow
+                               realReadOldManIdFromPlayer = OldMan.private.readOldManIdFromPlayer
+                       end)
+
+                       teardown(function()
+                               OldMan.private.setToFollow = realSetToFollow
+                               OldMan.private.readOldManIdFromPlayer = realReadOldManIdFromPlayer
+                       end)
+
+                       before_each(function()
+                               OldMan.private.setToFollow = spy.new(function() end)
+                               OldMan.private.readOldManIdFromPlayer = spy.new(function() return oldManId end)
+                       end)
+
+                       describe("When called with the player as argument", function()
+                               it("Should read the old man id from the player.", function()
+                                       OldMan.global:handleStopFollowPlayerEvent(pCreatureObject)
+
+                                       assert.spy(OldMan.private.readOldManIdFromPlayer).was.called_with(pCreatureObject)
+                               end)
+
+                               it("Should get a pointer to the old man.", function()
+                                       OldMan.global:handleStopFollowPlayerEvent(pCreatureObject)
+
+                                       assert.spy(getSceneObject).was.called_with(oldManId)
+                               end)
+
+                               it("Should tell the old man to follow no one.", function()
+                                       OldMan.global:handleStopFollowPlayerEvent(pCreatureObject)
+
+                                       assert.spy(OldMan.private.setToFollow).was.called_with(pOldMan, nil)
+                               end)
+                       end)
+               end)
+
+               describe("handleSpatialChatEvent", function()
+                       local realSendGreetingString
+                       local realReadOldManIdFromPlayer
+
+                       setup(function()
+                               realSendGreetingString = OldMan.private.sendGreetingString
+                               realReadOldManIdFromPlayer = OldMan.private.readOldManIdFromPlayer
+                       end)
+
+                       teardown(function()
+                               OldMan.private.sendGreetingString = realSendGreetingString
+                               OldMan.private.readOldManIdFromPlayer = realReadOldManIdFromPlayer
+                       end)
+
+                       before_each(function()
+                               OldMan.private.sendGreetingString = spy.new(function() end)
+                               OldMan.private.readOldManIdFromPlayer = spy.new(function() return oldManId end)
+                       end)
+
+                       describe("When called with the player as argument", function()
+                               it("Should read the old man id from the player.", function()
+                                       OldMan.global:handleSpatialChatEvent(pCreatureObject)
+
+                                       assert.spy(OldMan.private.readOldManIdFromPlayer).was.called_with(pCreatureObject)
+                               end)
+
+                               it("Should get a pointer to the old man.", function()
+                                       OldMan.global:handleSpatialChatEvent(pCreatureObject)
+
+                                       assert.spy(getSceneObject).was.called_with(oldManId)
+                               end)
+
+                               it("Should send the greeting string.", function()
+                                       OldMan.global:handleSpatialChatEvent(pCreatureObject)
+
+                                       assert.spy(OldMan.private.sendGreetingString).was.called_with(pOldMan, pCreatureObject)
+                               end)
+                       end)
+               end)
+
+               describe("handleDespawnEvent", function()
+                       local realDespawnOldMan
+                       local realReadOldManIdFromPlayer
+                       local realCreateSpawnOldManEvent
+
+                       setup(function()
+                               realDespawnOldMan = OldMan.private.despawnOldMan
+                               realReadOldManIdFromPlayer = OldMan.private.readOldManIdFromPlayer
+                               realCreateSpawnOldManEvent = OldMan.createSpawnOldManEvent
+                       end)
+
+                       teardown(function()
+                               OldMan.private.despawnOldMan = realDespawnOldMan
+                               OldMan.private.readOldManIdFromPlayer = realReadOldManIdFromPlayer
+                               OldMan.createSpawnOldManEvent = realCreateSpawnOldManEvent
+                       end)
+
+                       before_each(function()
+                               OldMan.private.despawnOldMan = spy.new(function() end)
+                               OldMan.private.readOldManIdFromPlayer = spy.new(function() return oldManId end)
+                               OldMan.createSpawnOldManEvent = spy.new(function() end)
+                       end)
+
+                       describe("When called with the player as argument", function()
+                               it("Should read the old man id from the player.", function()
+                                       OldMan.global:handleDespawnEvent(pCreatureObject)
+
+                                       assert.spy(OldMan.private.readOldManIdFromPlayer).was.called_with(pCreatureObject)
+                               end)
+
+                               it("Should get a pointer to the old man.", function()
+                                       OldMan.global:handleDespawnEvent(pCreatureObject)
+
+                                       assert.spy(getSceneObject).was.called_with(oldManId)
+                               end)
+
+                               it("Should despawn the old man.", function()
+                                       OldMan.global:handleDespawnEvent(pCreatureObject)
+
+                                       assert.spy(OldMan.private.despawnOldMan).was.called_with(pOldMan)
+                               end)
+
+                               it("Should set the id of the spawned old man to 0 to indicate that he is despawned.", function()
+                                       OldMan.global:handleDespawnEvent(pCreatureObject)
+
+                                       assert.spy(writeData).was.called_with(playerId .. OLD_MAN_ID_STRING, OLD_MAN_NO_OLD_MAN_SPAWNED)
+                               end)
 
-                                       OldMan:handleSpawnOldManEvent(pCreatureObject)
+                               it("Should reschedule the old man.", function()
+                                       OldMan.global:handleDespawnEvent(pCreatureObject)
 
-                                       assert.spy(OldMan.canOldManBeSpawned).was.called_with(pCreatureObject)
-                                       assert.spy(OldMan.tryToSpawnOldMan).was.called_with(pCreatureObject)
                                        assert.spy(OldMan.createSpawnOldManEvent).was.called_with(pCreatureObject)
                                end)
                        end)
                end)
+       end)
 
+       describe("Private methods", function()
                describe("canOldManBeSpawned", function()
                        describe("When called with a creature object as argument", function()
                                local realIsPlayerOnline
@@ -346,50 +489,50 @@ describe("Old Man", function()
                                local realIsPlayerInABuilding
 
                                setup(function()
-                                       realIsPlayerOnline = OldMan.isPlayerOnline
-                                       realIsPlayerInNpcCity = OldMan.isPlayerInNpcCity
-                                       realIsPlayerInABuilding = OldMan.isPlayerInABuilding
+                                       realIsPlayerOnline = OldMan.private.isPlayerOnline
+                                       realIsPlayerInNpcCity = OldMan.private.isPlayerInNpcCity
+                                       realIsPlayerInABuilding = OldMan.private.isPlayerInABuilding
                                end)
 
                                teardown(function()
-                                       OldMan.isPlayerOnline = realIsPlayerOnline
-                                       OldMan.isPlayerInNpcCity = realIsPlayerInNpcCity
-                                       OldMan.isPlayerInABuilding = realIsPlayerInABuilding
+                                       OldMan.private.isPlayerOnline = realIsPlayerOnline
+                                       OldMan.private.isPlayerInNpcCity = realIsPlayerInNpcCity
+                                       OldMan.private.isPlayerInABuilding = realIsPlayerInABuilding
                                end)
 
                                before_each(function()
-                                       OldMan.isPlayerOnline = spy.new(function() return true end)
-                                       OldMan.isPlayerInNpcCity = spy.new(function() return false end)
-                                       OldMan.isPlayerInABuilding = spy.new(function() return false end)
+                                       OldMan.private.isPlayerOnline = spy.new(function() return true end)
+                                       OldMan.private.isPlayerInNpcCity = spy.new(function() return false end)
+                                       OldMan.private.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(OldMan.canOldManBeSpawned(pCreatureObject))
+                                               assert.is_true(OldMan.private.canOldManBeSpawned(pCreatureObject))
                                        end)
                                end)
 
                                describe("and the player is offline", function()
                                        it("Should return false.", function()
-                                               OldMan.isPlayerOnline = spy.new(function() return false end)
+                                               OldMan.private.isPlayerOnline = spy.new(function() return false end)
 
-                                               assert.is_false(OldMan.canOldManBeSpawned(pCreatureObject))
+                                               assert.is_false(OldMan.private.canOldManBeSpawned(pCreatureObject))
                                        end)
                                end)
 
                                describe("and the player is in a NPC city", function()
                                        it("Should return false.", function()
-                                               OldMan.isPlayerInNpcCity = spy.new(function() return true end)
+                                               OldMan.private.isPlayerInNpcCity = spy.new(function() return true end)
 
-                                               assert.is_false(OldMan.canOldManBeSpawned(pCreatureObject))
+                                               assert.is_false(OldMan.private.canOldManBeSpawned(pCreatureObject))
                                        end)
                                end)
 
                                describe("and the player is inside a building", function()
                                        it("Should return false.", function()
-                                               OldMan.isPlayerInABuilding = spy.new(function() return true end)
+                                               OldMan.private.isPlayerInABuilding = spy.new(function() return true end)
 
-                                               assert.is_false(OldMan.canOldManBeSpawned(pCreatureObject))
+                                               assert.is_false(OldMan.private.canOldManBeSpawned(pCreatureObject))
                                        end)
                                end)
                        end)
@@ -400,7 +543,7 @@ describe("Old Man", function()
                                it("Should return true if the player is online.", function()
                                        playerObject.isOnline = spy.new(function() return true end)
 
-                                       assert.is_true(OldMan.isPlayerOnline(pCreatureObject))
+                                       assert.is_true(OldMan.private.isPlayerOnline(pCreatureObject))
 
                                        assert.spy(LuaCreatureObject).was.called_with(pCreatureObject)
                                        assert.spy(LuaPlayerObject).was.called_with(pPlayerObject)
@@ -410,7 +553,7 @@ describe("Old Man", function()
                                it("Should return false if the player is offline.", function()
                                        playerObject.isOnline = spy.new(function() return false end)
 
-                                       assert.is_false(OldMan.isPlayerOnline(pCreatureObject))
+                                       assert.is_false(OldMan.private.isPlayerOnline(pCreatureObject))
 
                                        assert.spy(LuaCreatureObject).was.called_with(pCreatureObject)
                                        assert.spy(LuaPlayerObject).was.called_with(pPlayerObject)
@@ -420,7 +563,7 @@ describe("Old Man", function()
 
                        describe("When called with nil as argument", function()
                                it("Should return false.", function()
-                                       assert.is_false(OldMan.isPlayerOnline(nil))
+                                       assert.is_false(OldMan.private.isPlayerOnline(nil))
                                end)
                        end)
                end)
@@ -430,7 +573,7 @@ describe("Old Man", 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(OldMan.isPlayerInABuilding(pCreatureObject))
+                                       assert.is_true(OldMan.private.isPlayerInABuilding(pCreatureObject))
 
                                        assert.spy(LuaSceneObject).was.called(1)
                                        assert.spy(sceneObjectPlayer.getParentID).was.called(1)
@@ -439,7 +582,7 @@ describe("Old Man", function()
                                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(OldMan.isPlayerInABuilding(pCreatureObject))
+                                       assert.is_false(OldMan.private.isPlayerInABuilding(pCreatureObject))
 
                                        assert.spy(LuaSceneObject).was.called(1)
                                        assert.spy(sceneObjectPlayer.getParentID).was.called(1)
@@ -448,7 +591,7 @@ describe("Old Man", function()
 
                        describe("When called with nil as argument", function()
                                it("Should return false.", function()
-                                       assert.is_false(OldMan.isPlayerInABuilding(nil))
+                                       assert.is_false(OldMan.private.isPlayerInABuilding(nil))
                                end)
                        end)
                end)
@@ -456,7 +599,7 @@ describe("Old Man", function()
                describe("isPlayerInNpcCity", function()
                        describe("When called with a nil pointer", function()
                                it("Should return false", function()
-                                       assert.is_false(OldMan.isPlayerInNpcCity(nil))
+                                       assert.is_false(OldMan.private.isPlayerInNpcCity(nil))
                                end)
                        end)
 
@@ -473,7 +616,7 @@ describe("Old Man", function()
                                        it("Should return false.", function()
                                                getCityRegionAt = spy.new(function() return nil end)
 
-                                               assert.is_false(OldMan.isPlayerInNpcCity(pCreatureObject))
+                                               assert.is_false(OldMan.private.isPlayerInNpcCity(pCreatureObject))
                                        end)
                                end)
 
@@ -481,7 +624,7 @@ describe("Old Man", 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(OldMan.isPlayerInNpcCity(pCreatureObject))
+                                               assert.is_true(OldMan.private.isPlayerInNpcCity(pCreatureObject))
 
                                                assert.spy(LuaCityRegion).was.called(1)
                                        end)
@@ -489,7 +632,7 @@ describe("Old Man", function()
                                        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(OldMan.isPlayerInNpcCity(pCreatureObject))
+                                               assert.is_false(OldMan.private.isPlayerInNpcCity(pCreatureObject))
 
                                                assert.spy(LuaCityRegion).was.called(1)
                                        end)
@@ -506,14 +649,14 @@ describe("Old Man", function()
 
                        describe("When called with a creature object pointer", function()
                                it("Should get a spawn point for the old man.", function()
-                                       OldMan.spawnOldMan(pCreatureObject)
+                                       OldMan.private.spawnOldMan(pCreatureObject)
 
                                        assert.spy(getSpawnPoint).was.called_with(pCreatureObject, 33, 22, OLD_MAN_MIN_SPAWN_DISTANCE, OLD_MAN_MAX_SPAWN_DISTANCE)
                                end)
 
                                describe("and a spawn point is returned", function()
                                        it("Should spawn the old man.", function()
-                                               OldMan.spawnOldMan(pCreatureObject)
+                                               OldMan.private.spawnOldMan(pCreatureObject)
 
                                                assert.spy(sceneObjectPlayer.getZoneName).was.called(1)
                                                assert.spy(sceneObjectPlayer.getParentID).was.called(1)
@@ -521,7 +664,7 @@ describe("Old Man", function()
                                        end)
 
                                        it("Should return a pointer to the spawned old man.", function()
-                                               assert.same(OldMan.spawnOldMan(pCreatureObject), pOldMan)
+                                               assert.same(OldMan.private.spawnOldMan(pCreatureObject), pOldMan)
                                        end)
                                end)
 
@@ -531,7 +674,7 @@ describe("Old Man", function()
                                        end)
 
                                        it("Should not spawn the old man.", function()
-                                               OldMan.spawnOldMan(pCreatureObject)
+                                               OldMan.private.spawnOldMan(pCreatureObject)
 
                                                assert.spy(sceneObjectPlayer.getZoneName).was.not_called()
                                                assert.spy(sceneObjectPlayer.getParentID).was.not_called()
@@ -539,7 +682,7 @@ describe("Old Man", function()
                                        end)
 
                                        it("Should return nil.", function()
-                                               assert.is_nil(OldMan.spawnOldMan(pCreatureObject))
+                                               assert.is_nil(OldMan.private.spawnOldMan(pCreatureObject))
                                        end)
                                end)
                        end)
@@ -548,7 +691,7 @@ describe("Old Man", function()
                describe("saveOldManIdOnPlayer", function()
                        describe("When called with player and old man", function()
                                it("Should store the object id of the old man on the player.", function()
-                                       OldMan.saveOldManIdOnPlayer(pCreatureObject, pOldMan)
+                                       OldMan.private.saveOldManIdOnPlayer(pCreatureObject, pOldMan)
 
                                        assert.spy(writeData).was.called_with(playerId .. OLD_MAN_ID_STRING, oldManId)
                                        assert.spy(LuaCreatureObject).was.called(2)
@@ -565,52 +708,52 @@ describe("Old Man", function()
                                local realSetToFollow
 
                                setup(function()
-                                       realSpawnOldMan = OldMan.spawnOldMan
-                                       realSaveOldManIdOnPlayer = OldMan.saveOldManIdOnPlayer
-                                       realSetToFollow = OldMan.setToFollow
+                                       realSpawnOldMan = OldMan.private.spawnOldMan
+                                       realSaveOldManIdOnPlayer = OldMan.private.saveOldManIdOnPlayer
+                                       realSetToFollow = OldMan.private.setToFollow
                                end)
 
                                teardown(function()
-                                       OldMan.spawnOldMan = realSpawnOldMan
-                                       OldMan.saveOldManIdOnPlayer = realSaveOldManIdOnPlayer
-                                       OldMan.setToFollow = realSetToFollow
+                                       OldMan.private.spawnOldMan = realSpawnOldMan
+                                       OldMan.private.saveOldManIdOnPlayer = realSaveOldManIdOnPlayer
+                                       OldMan.private.setToFollow = realSetToFollow
                                end)
 
                                before_each(function()
-                                       OldMan.spawnOldMan = spy.new(function() end)
-                                       OldMan.saveOldManIdOnPlayer = spy.new(function() end)
-                                       OldMan.setToFollow = spy.new(function() end)
+                                       OldMan.private.spawnOldMan = spy.new(function() end)
+                                       OldMan.private.saveOldManIdOnPlayer = spy.new(function() end)
+                                       OldMan.private.setToFollow = spy.new(function() end)
                                end)
 
                                it("Should spawn the old man.", function()
-                                       OldMan.tryToSpawnOldMan(pCreatureObject)
+                                       OldMan.private.tryToSpawnOldMan(pCreatureObject)
 
-                                       assert.spy(OldMan.spawnOldMan).was.called_with(pCreatureObject)
+                                       assert.spy(OldMan.private.spawnOldMan).was.called_with(pCreatureObject)
                                end)
 
                                describe("and spawning the old man was successful", function()
                                        before_each(function()
-                                               OldMan.spawnOldMan = spy.new(function() return pOldMan end)
+                                               OldMan.private.spawnOldMan = spy.new(function() return pOldMan end)
                                        end)
 
                                        it("Should save the id of the old man on the player.", function()
-                                               OldMan.tryToSpawnOldMan(pCreatureObject)
+                                               OldMan.private.tryToSpawnOldMan(pCreatureObject)
 
-                                               assert.spy(OldMan.saveOldManIdOnPlayer).was.called_with(pCreatureObject, pOldMan)
+                                               assert.spy(OldMan.private.saveOldManIdOnPlayer).was.called_with(pCreatureObject, pOldMan)
                                        end)
 
                                        it("Should return true.", function()
-                                               assert.is_true(OldMan.tryToSpawnOldMan(pCreatureObject))
+                                               assert.is_true(OldMan.private.tryToSpawnOldMan(pCreatureObject))
                                        end)
 
                                        it("Should set the old man to follow the player.", function()
-                                               OldMan.tryToSpawnOldMan(pCreatureObject)
+                                               OldMan.private.tryToSpawnOldMan(pCreatureObject)
 
-                                               assert.spy(OldMan.setToFollow).was.called_with(pOldMan, pCreatureObject)
+                                               assert.spy(OldMan.private.setToFollow).was.called_with(pOldMan, pCreatureObject)
                                        end)
 
                                        it("Should create events for the old man to send greeting string, to stop follow the player and for despawning.", function()
-                                               OldMan.tryToSpawnOldMan(pCreatureObject)
+                                               OldMan.private.tryToSpawnOldMan(pCreatureObject)
 
                                                assert.spy(createEvent).was.called(3)
                                        end)
@@ -618,18 +761,18 @@ describe("Old Man", function()
 
                                describe("and spawning the old man failed", function()
                                        before_each(function()
-                                               OldMan.spawnOldMan = spy.new(function() return nil end)
+                                               OldMan.private.spawnOldMan = spy.new(function() return nil end)
                                        end)
 
                                        it("Should not save the id of the old man on the player, not make the old man follow the player nor create an event.", function()
-                                               OldMan.tryToSpawnOldMan(pCreatureObject)
-                                               assert.spy(OldMan.saveOldManIdOnPlayer).was.not_called()
-                                               assert.spy(OldMan.setToFollow).was.not_called()
+                                               OldMan.private.tryToSpawnOldMan(pCreatureObject)
+                                               assert.spy(OldMan.private.saveOldManIdOnPlayer).was.not_called()
+                                               assert.spy(OldMan.private.setToFollow).was.not_called()
                                                assert.spy(createEvent).was.not_called()
                                        end)
 
                                        it("Should return false.", function()
-                                               assert.is_false(OldMan.tryToSpawnOldMan(pCreatureObject))
+                                               assert.is_false(OldMan.private.tryToSpawnOldMan(pCreatureObject))
                                        end)
                                end)
                        end)
@@ -638,7 +781,7 @@ describe("Old Man", function()
                describe("setToFollow", function()
                        describe("When called with a old man and a player", function()
                                it("Should set the old man to follow the player", function()
-                                       OldMan.setToFollow(pOldMan, pCreatureObject)
+                                       OldMan.private.setToFollow(pOldMan, pCreatureObject)
 
                                        assert.spy(aiAgent.setFollowObject).was.called_with(aiAgent, pCreatureObject)
                                end)
@@ -646,7 +789,7 @@ describe("Old Man", function()
 
                        describe("When called with old man argument equal to nil", function()
                                it("Should not do anything.", function()
-                                       OldMan.setToFollow(nil, pCreatureObject)
+                                       OldMan.private.setToFollow(nil, pCreatureObject)
 
                                        assert.spy(aiAgent.setFollowObject).was.not_called()
                                end)
@@ -654,97 +797,17 @@ describe("Old Man", function()
 
                        describe("When called with player argument equal to nil", function()
                                it("Should not do anything.", function()
-                                       OldMan.setToFollow(pOldMan, nil)
+                                       OldMan.private.setToFollow(pOldMan, nil)
 
                                        assert.spy(aiAgent.setFollowObject).was.called_with(aiAgent, nil)
                                end)
                        end)
                end)
 
-               describe("handleStopFollowPlayerEvent", function()
-                       local realSetToFollow
-                       local realReadOldManIdFromPlayer
-
-                       setup(function()
-                               realSetToFollow = OldMan.setToFollow
-                               realReadOldManIdFromPlayer = OldMan.readOldManIdFromPlayer
-                       end)
-
-                       teardown(function()
-                               OldMan.setToFollow = realSetToFollow
-                               OldMan.readOldManIdFromPlayer = realReadOldManIdFromPlayer
-                       end)
-
-                       before_each(function()
-                               OldMan.setToFollow = spy.new(function() end)
-                               OldMan.readOldManIdFromPlayer = spy.new(function() return oldManId end)
-                       end)
-
-                       describe("When called with the player as argument", function()
-                               it("Should read the old man id from the player.", function()
-                                       OldMan:handleStopFollowPlayerEvent(pCreatureObject)
-
-                                       assert.spy(OldMan.readOldManIdFromPlayer).was.called_with(pCreatureObject)
-                               end)
-
-                               it("Should get a pointer to the old man.", function()
-                                       OldMan:handleStopFollowPlayerEvent(pCreatureObject)
-
-                                       assert.spy(getSceneObject).was.called_with(oldManId)
-                               end)
-
-                               it("Should tell the old man to follow no one.", function()
-                                       OldMan:handleStopFollowPlayerEvent(pCreatureObject)
-
-                                       assert.spy(OldMan.setToFollow).was.called_with(pOldMan, nil)
-                               end)
-                       end)
-               end)
-
-               describe("handleSpatialChatEvent", function()
-                       local realSendGreetingString
-                       local realReadOldManIdFromPlayer
-
-                       setup(function()
-                               realSendGreetingString = OldMan.sendGreetingString
-                               realReadOldManIdFromPlayer = OldMan.readOldManIdFromPlayer
-                       end)
-
-                       teardown(function()
-                               OldMan.sendGreetingString = realSendGreetingString
-                               OldMan.readOldManIdFromPlayer = realReadOldManIdFromPlayer
-                       end)
-
-                       before_each(function()
-                               OldMan.sendGreetingString = spy.new(function() end)
-                               OldMan.readOldManIdFromPlayer = spy.new(function() return oldManId end)
-                       end)
-
-                       describe("When called with the player as argument", function()
-                               it("Should read the old man id from the player.", function()
-                                       OldMan:handleSpatialChatEvent(pCreatureObject)
-
-                                       assert.spy(OldMan.readOldManIdFromPlayer).was.called_with(pCreatureObject)
-                               end)
-
-                               it("Should get a pointer to the old man.", function()
-                                       OldMan:handleSpatialChatEvent(pCreatureObject)
-
-                                       assert.spy(getSceneObject).was.called_with(oldManId)
-                               end)
-
-                               it("Should send the greeting string.", function()
-                                       OldMan:handleSpatialChatEvent(pCreatureObject)
-
-                                       assert.spy(OldMan.sendGreetingString).was.called_with(pOldMan, pCreatureObject)
-                               end)
-                       end)
-               end)
-
                describe("readOldManIdFromPlayer", function()
                        describe("When called with a pointer to a creature object of a player as argument", function()
                                it("Should read the old man id from the player.", function()
-                                       OldMan.readOldManIdFromPlayer(pCreatureObject)
+                                       OldMan.private.readOldManIdFromPlayer(pCreatureObject)
 
                                        assert.spy(readData).was.called_with(playerId .. OLD_MAN_ID_STRING)
                                        assert.spy(LuaCreatureObject).was.called(1)
@@ -758,37 +821,37 @@ describe("Old Man", function()
                                local realGetPlayerFirstName
 
                                setup(function()
-                                       realGetPlayerFirstName = OldMan.getPlayerFirstName
+                                       realGetPlayerFirstName = OldMan.private.getPlayerFirstName
                                end)
 
                                teardown(function()
-                                       OldMan.getPlayerFirstName = realGetPlayerFirstName
+                                       OldMan.private.getPlayerFirstName = realGetPlayerFirstName
                                end)
 
                                before_each(function()
-                                       OldMan.getPlayerFirstName = spy.new(function() return playerFirstName end)
+                                       OldMan.private.getPlayerFirstName = spy.new(function() return playerFirstName end)
                                end)
 
                                it("Should create a string id for the oldman_greeting string.", function()
-                                       OldMan.sendGreetingString(pOldMan, pCreatureObject)
+                                       OldMan.private.sendGreetingString(pOldMan, pCreatureObject)
 
                                        assert.spy(LuaStringIdChatParameter).was.called_with(OLD_MAN_GREETING_STRING)
                                end)
 
                                it("Should get the name of the player.", function()
-                                       OldMan.sendGreetingString(pOldMan, pCreatureObject)
+                                       OldMan.private.sendGreetingString(pOldMan, pCreatureObject)
 
-                                       assert.spy(OldMan.getPlayerFirstName).was.called_with(pCreatureObject)
+                                       assert.spy(OldMan.private.getPlayerFirstName).was.called_with(pCreatureObject)
                                end)
 
                                it("Should set the %TT of the string to the name of the player.", function()
-                                       OldMan.sendGreetingString(pOldMan, pCreatureObject)
+                                       OldMan.private.sendGreetingString(pOldMan, pCreatureObject)
 
                                        assert.spy(greetingStringId.setTT).was.called(1)
                                end)
 
                                it("Should send the string id to spatial chat.", function()
-                                       OldMan.sendGreetingString(pOldMan, pCreatureObject)
+                                       OldMan.private.sendGreetingString(pOldMan, pCreatureObject)
 
                                        assert.spy(spatialChat).was.called_with(pOldMan, pGreetingStringId)
                                end)
@@ -798,70 +861,14 @@ describe("Old Man", function()
                describe("getPlayerFirstName", function()
                        describe("When called with a player", function()
                                it("Should return the first name of the player.", function()
-                                       assert.same(OldMan.getPlayerFirstName(pCreatureObject), playerFirstName)
+                                       assert.same(OldMan.private.getPlayerFirstName(pCreatureObject), playerFirstName)
 
                                        assert.spy(creatureObjectPlayer.getFirstName).was.called(1)
                                end)
                        end)
                        describe("When called with nil", function()
                                it("Should return an empty string.", function()
-                                       assert.same(OldMan.getPlayerFirstName(nil), "")
-                               end)
-                       end)
-               end)
-
-               describe("handleDespawnEvent", function()
-                       local realDespawnOldMan
-                       local realReadOldManIdFromPlayer
-                       local realCreateSpawnOldManEvent
-
-                       setup(function()
-                               realDespawnOldMan = OldMan.despawnOldMan
-                               realReadOldManIdFromPlayer = OldMan.readOldManIdFromPlayer
-                               realCreateSpawnOldManEvent = OldMan.createSpawnOldManEvent
-                       end)
-
-                       teardown(function()
-                               OldMan.despawnOldMan = realDespawnOldMan
-                               OldMan.readOldManIdFromPlayer = realReadOldManIdFromPlayer
-                               OldMan.createSpawnOldManEvent = realCreateSpawnOldManEvent
-                       end)
-
-                       before_each(function()
-                               OldMan.despawnOldMan = spy.new(function() end)
-                               OldMan.readOldManIdFromPlayer = spy.new(function() return oldManId end)
-                               OldMan.createSpawnOldManEvent = spy.new(function() end)
-                       end)
-
-                       describe("When called with the player as argument", function()
-                               it("Should read the old man id from the player.", function()
-                                       OldMan:handleDespawnEvent(pCreatureObject)
-
-                                       assert.spy(OldMan.readOldManIdFromPlayer).was.called_with(pCreatureObject)
-                               end)
-
-                               it("Should get a pointer to the old man.", function()
-                                       OldMan:handleDespawnEvent(pCreatureObject)
-
-                                       assert.spy(getSceneObject).was.called_with(oldManId)
-                               end)
-
-                               it("Should despawn the old man.", function()
-                                       OldMan:handleDespawnEvent(pCreatureObject)
-
-                                       assert.spy(OldMan.despawnOldMan).was.called_with(pOldMan)
-                               end)
-
-                               it("Should set the id of the spawned old man to 0 to indicate that he is despawned.", function()
-                                       OldMan:handleDespawnEvent(pCreatureObject)
-
-                                       assert.spy(writeData).was.called_with(playerId .. OLD_MAN_ID_STRING, OLD_MAN_NO_OLD_MAN_SPAWNED)
-                               end)
-
-                               it("Should reschedule the old man.", function()
-                                       OldMan:handleDespawnEvent(pCreatureObject)
-
-                                       assert.spy(OldMan.createSpawnOldManEvent).was.called_with(pCreatureObject)
+                                       assert.same(OldMan.private.getPlayerFirstName(nil), "")
                                end)
                        end)
                end)
@@ -869,7 +876,7 @@ describe("Old Man", function()
                describe("despawnOldMan", function()
                        describe("When called with an old man as argument", function()
                                it("Should destroy the old man from the world.", function()
-                                       OldMan.despawnOldMan(pOldMan)
+                                       OldMan.private.despawnOldMan(pOldMan)
 
                                        assert.spy(sceneObjectOldMan.destroyObjectFromWorld).was.called(1)
                                end)
@@ -877,7 +884,7 @@ describe("Old Man", function()
 
                        describe("When called with nil as argument", function()
                                it("Should not try to destroy the old man from the world.", function()
-                                       OldMan.despawnOldMan(nil)
+                                       OldMan.private.despawnOldMan(nil)
 
                                        assert.spy(sceneObjectOldMan.destroyObjectFromWorld).was.not_called()
                                end)
@@ -887,7 +894,7 @@ describe("Old Man", function()
                describe("hasOldManSpawnEventScheduled", function()
                        describe("When called with a player as argument", function()
                                it("Should read the event scheduled information from the player.", function()
-                                       OldMan.hasOldManSpawnEventScheduled(pCreatureObject)
+                                       OldMan.private.hasOldManSpawnEventScheduled(pCreatureObject)
 
                                        assert.spy(creatureObjectPlayer.getScreenPlayState).was.called_with(creatureObjectPlayer, OLD_MAN_EVENT_SCHEDULED_STRING)
                                end)
@@ -896,7 +903,7 @@ describe("Old Man", function()
                                        it("Should return true.", function()
                                                creatureObjectPlayer.getScreenPlayState = spy.new(function() return OLD_MAN_SCHEDULED end)
 
-                                               assert.is_true(OldMan.hasOldManSpawnEventScheduled(pCreatureObject))
+                                               assert.is_true(OldMan.private.hasOldManSpawnEventScheduled(pCreatureObject))
                                        end)
                                end)
 
@@ -904,7 +911,7 @@ describe("Old Man", function()
                                        it("Should return false.", function()
                                                creatureObjectPlayer.getScreenPlayState = spy.new(function() return OLD_MAN_NOT_SCHEDULED end)
 
-                                               assert.is_false(OldMan.hasOldManSpawnEventScheduled(pCreatureObject))
+                                               assert.is_false(OldMan.private.hasOldManSpawnEventScheduled(pCreatureObject))
                                        end)
                                end)
                        end)
old mode 100644 (file)
new mode 100755 (executable)
index f2e1466..5bcc01e
@@ -1,10 +1,8 @@
-registerScreenPlay = spy.new(function() end)
-
-package.path = package.path .. ";scripts/managers/jedi/village/?.lua;scripts/managers/jedi/village/mocks/?.lua;scripts/screenplays/mocks/?.lua"
-require("village_jedi_manager")
-local DirectorManagerMocks = require("director_manager_mocks")
-local OldManMocks = require("old_man_mocks")
-local VillageJediManagerHolocronMocks = require("village_jedi_manager_holocron_mocks")
+local DirectorManagerMocks = require("screenplays.mocks.director_manager_mocks")
+local GlowingMocks = require("managers.jedi.village.mocks.glowing_mocks")
+local OldManMocks = require("managers.jedi.village.mocks.old_man_mocks")
+local VillageJediManager = require("managers.jedi.village.village_jedi_manager")
+local VillageJediManagerHolocronMocks = require("managers.jedi.village.mocks.village_jedi_manager_holocron_mocks")
 
 describe("Village Jedi Manager", function()
        local pCreatureObject = { "creatureObjectPointer" }
@@ -15,26 +13,26 @@ describe("Village Jedi Manager", function()
 
        setup(function()
                DirectorManagerMocks.setup()
-               OldManMocks.setup()
+               GlowingMocks.mocks.setup()
+               OldManMocks.mocks.setup()
                VillageJediManagerHolocronMocks.setup()
        end)
 
        teardown(function()
                DirectorManagerMocks.teardown()
-               OldManMocks.teardown()
+               GlowingMocks.mocks.teardown()
+               OldManMocks.mocks.teardown()
                VillageJediManagerHolocronMocks.teardown()
        end)
 
        before_each(function()
                DirectorManagerMocks.before_each()
-               OldManMocks.before_each()
+               GlowingMocks.mocks.before_each()
+               OldManMocks.mocks.before_each()
                VillageJediManagerHolocronMocks.before_each()
 
                creatureObject = {}
-               creatureObject.getPlayerObject = spy.new(function() return pPlayerObject end)
-               creatureObject.hasScreenPlayState = spy.new(function() return false end)
                creatureObject.sendSystemMessage = spy.new(function() end)
-               creatureObject.setScreenPlayState = spy.new(function() end)
                DirectorManagerMocks.creatureObjects[pCreatureObject] = creatureObject
 
                playerObject = {}
@@ -54,287 +52,24 @@ describe("Village Jedi Manager", function()
                end)
 
                describe("checkForceStatusCommand", function()
-                       it("Should call getJediProgressionStatus and send the appropriate string id to the player", function()
-                               local realGetJediProgressionStatus = VillageJediManager.getJediProgressionStatus
-                               VillageJediManager.getJediProgressionStatus = spy.new(function() return 2 end)
-
+                       it("Should call checkForceStatusCommand in the glowing module.", function()
                                VillageJediManager:checkForceStatusCommand(pCreatureObject)
 
-                               assert.spy(VillageJediManager.getJediProgressionStatus).was.called_with(pCreatureObject)
-                               assert.spy(creatureObject.sendSystemMessage).was.called_with(creatureObject, "@jedi_spam:fs_progress_2")
-
-                               VillageJediManager.getJediProgressionStatus = realGetJediProgressionStatus
+                               assert.spy(GlowingMocks.checkForceStatusCommand).was.called_with(pCreatureObject)
                        end)
                end)
 
                describe("onPlayerLoggedIn", function()
-                       local realCheckAndHandleJediProgression
-                       local realRegisterObservers
-
-                       setup(function()
-                               realCheckAndHandleJediProgression = VillageJediManager.checkAndHandleJediProgression
-                               realRegisterObservers = VillageJediManager.registerObservers
-                       end)
-
-                       teardown(function()
-                               VillageJediManager.checkAndHandleJediProgression = realCheckAndHandleJediProgression
-                               VillageJediManager.registerObservers = realRegisterObservers
-                       end)
-
-                       before_each(function()
-                               VillageJediManager.checkAndHandleJediProgression = spy.new(function() end)
-                               VillageJediManager.registerObservers = spy.new(function() end)
-                       end)
-
                        describe("When called with a player as argument", function()
-                               it("Should check and handle the jedi progression of the player", function()
-                                       VillageJediManager:onPlayerLoggedIn(pCreatureObject)
-
-                                       assert.spy(VillageJediManager.checkAndHandleJediProgression).was.called_with(pCreatureObject)
-                               end)
-
-                               it("Should register observers on the player", function()
+                               it("Should call the onPlayerLoggedIn function in the Glowing module with the player as argument.", function()
                                        VillageJediManager:onPlayerLoggedIn(pCreatureObject)
 
-                                       assert.spy(VillageJediManager.registerObservers).was.called_with(pCreatureObject)
-                               end)
-                       end)
-               end)
-
-               describe("setJediProgressionScreenPlayState", function()
-                       describe("When called with a player and a state", function()
-                               it("Should write the state to the village jedi progression screen play state.", function()
-                                       VillageJediManager.setJediProgressionScreenPlayState(pCreatureObject, VILLAGE_JEDI_PROGRESSION_COMPLETED_VILLAGE)
-
-                                       assert.spy(creatureObject.setScreenPlayState).was.called_with(creatureObject, VILLAGE_JEDI_PROGRESSION_COMPLETED_VILLAGE, VILLAGE_JEDI_PROGRESSION_SCREEN_PLAY_STATE_STRING)
-                               end)
-                       end)
-
-                       describe("When called with the player pointer equal to nil", function()
-                               it("Should not write the state to the village jedi progression screen play state.", function()
-                                       VillageJediManager.setJediProgressionScreenPlayState(nil, VILLAGE_JEDI_PROGRESSION_COMPLETED_VILLAGE)
-
-                                       assert.spy(creatureObject.setScreenPlayState).was.not_called()
-                               end)
-                       end)
-               end)
-
-               describe("hasJediProgressionScreenPlayState", function()
-                       describe("When called with a player and a state", function()
-                               it("Should check if the player has the screen play state.", function()
-                                       VillageJediManager.hasJediProgressionScreenPlayState(pCreatureObject, VILLAGE_JEDI_PROGRESSION_COMPLETED_VILLAGE)
-
-                                       assert.spy(creatureObject.hasScreenPlayState).was.called_with(creatureObject, VILLAGE_JEDI_PROGRESSION_COMPLETED_VILLAGE, VILLAGE_JEDI_PROGRESSION_SCREEN_PLAY_STATE_STRING)
-                               end)
-
-                               it("Should return true if the player has the screen play state.", function()
-                                       creatureObject.hasScreenPlayState = spy.new(function() return true end)
-
-                                       assert.same(true, VillageJediManager.hasJediProgressionScreenPlayState(pCreatureObject, VILLAGE_JEDI_PROGRESSION_COMPLETED_VILLAGE))
-                               end)
-
-                               it("Should return false if the player does not have the screen play state.", function()
-                                       assert.same(false, VillageJediManager.hasJediProgressionScreenPlayState(pCreatureObject, VILLAGE_JEDI_PROGRESSION_COMPLETED_VILLAGE))
-                               end)
-                       end)
-
-                       describe("When called with the player pointer equal to nil", function()
-                               it("Should return false.", function()
-                                       assert.same(false, VillageJediManager.hasJediProgressionScreenPlayState(nil, VILLAGE_JEDI_PROGRESSION_COMPLETED_VILLAGE))
+                                       assert.spy(GlowingMocks.onPlayerLoggedIn).was.called_with(pCreatureObject)
                                end)
                        end)
                end)
        end)
 
        describe("Private functions", function()
-               describe("countBadgesInListToUpperLimit", function()
-                       local list = { 1, 2, 3, 4 }
-                       local currentListItem = 0
-
-                       before_each(function()
-                               currentListItem = 0
-                       end)
-
-                       it("Should check if the player has each badge number in the list", function()
-                               playerObject.hasBadge = spy.new(function(playerObject, badgeNumber)
-                                       currentListItem = currentListItem + 1
-                                       return badgeNumber == list[currentListItem]
-                               end)
-
-                               assert.is.same(VillageJediManager.countBadgesInListToUpperLimit(pCreatureObject, list, 10), 4)
-
-                               assert.spy(playerObject.hasBadge).was.called(4)
-                       end)
-
-                       it("Should return the correct number of badges that the player has", function()
-                               playerObject.hasBadge = spy.new(function(playerObject, badgeNumber)
-                                       return badgeNumber < 3
-                               end)
-
-                               assert.is.same(VillageJediManager.countBadgesInListToUpperLimit(pCreatureObject, list, 10), 2)
-
-                               assert.spy(playerObject.hasBadge).was.called(4)
-                       end)
-
-                       it("Should abort the counting early if upper limit is reached", function()
-                               playerObject.hasBadge = spy.new(function(playerObject, badgeNumber)
-                                       return badgeNumber < 4
-                               end)
-
-                               assert.is.same(VillageJediManager.countBadgesInListToUpperLimit(pCreatureObject, list, 2), 2)
-
-                               assert.spy(playerObject.hasBadge).was.called(2)
-                       end)
-               end)
-
-               describe("countBadges", function()
-                       it("Should call the countBadgesInListToUpperLimit five times with correct arguments", function()
-                               local argumentList = {
-                                       { PROFESSIONBADGES, 1, false },
-                                       { JEDIBADGES, 3, false },
-                                       { CONTENTBADGES, 5, false },
-                                       { DIFFICULTBADGES, 3, false },
-                                       { EASYBADGES, 5, false }
-                               }
-                               local realCountBadgesInListToUpperLimit = VillageJediManager.countBadgesInListToUpperLimit
-                               VillageJediManager.countBadgesInListToUpperLimit = spy.new(function(pCO, l, n)
-                                       for i = 1, table.getn(argumentList), 1 do
-                                               if argumentList[i][1] == l and argumentList[i][2] == n and pCO == pCreatureObject then
-                                                       argumentList[i][3] = true
-                                               end
-                                       end
-                                       return 0
-                               end)
-
-                               assert.is.same(VillageJediManager.countBadges(pCreatureObject), 0)
-
-                               assert.is.same(argumentList[1][3] and argumentList[2][3] and argumentList[3][3] and argumentList[4][3] and argumentList[5][3], true)
-                               assert.spy(VillageJediManager.countBadgesInListToUpperLimit).was.called(5)
-
-                               VillageJediManager.countBadgesInListToUpperLimit = realCountBadgesInListToUpperLimit
-                       end)
-
-                       it("Should sum the return values from countBadgesInListToUpperLimit", function()
-                               local returnList = {
-                                       1, 1, 1, 1, 1,
-                                       2, 2, 2, 2, 2,
-                                       3, 3, 3, 3, 3,
-                                       3, 4, 3, 6, 7
-                               }
-                               local returnNo = 0
-                               local realCountBadgesInListToUpperLimit = VillageJediManager.countBadgesInListToUpperLimit
-                               VillageJediManager.countBadgesInListToUpperLimit = spy.new(function()
-                                       returnNo = returnNo + 1
-                                       return returnList[returnNo]
-                               end)
-
-                               assert.is.same(VillageJediManager.countBadges(pCreatureObject), 5)
-                               assert.is.same(VillageJediManager.countBadges(pCreatureObject), 10)
-                               assert.is.same(VillageJediManager.countBadges(pCreatureObject), 15)
-                               assert.is.same(VillageJediManager.countBadges(pCreatureObject), 23)
-
-                               VillageJediManager.countBadgesInListToUpperLimit = realCountBadgesInListToUpperLimit
-                       end)
-               end)
-
-               describe("getJediProgressionStatus", function()
-                       it("Should return linear values between 0 and 5 depending on the number of counted badges", function()
-                               local returnValue = -1
-                               local realCountBadges = VillageJediManager.countBadges
-                               VillageJediManager.countBadges = spy.new(function()
-                                       returnValue = returnValue + 1
-                                       return returnValue
-                               end)
-
-                               assert.is.same(VillageJediManager.getJediProgressionStatus(pCreatureObject), 0)
-                               assert.is.same(VillageJediManager.getJediProgressionStatus(pCreatureObject), 0)
-                               assert.is.same(VillageJediManager.getJediProgressionStatus(pCreatureObject), 0)
-                               assert.is.same(VillageJediManager.getJediProgressionStatus(pCreatureObject), 0)
-                               assert.is.same(VillageJediManager.getJediProgressionStatus(pCreatureObject), 1)
-                               assert.is.same(VillageJediManager.getJediProgressionStatus(pCreatureObject), 1)
-                               assert.is.same(VillageJediManager.getJediProgressionStatus(pCreatureObject), 1)
-                               assert.is.same(VillageJediManager.getJediProgressionStatus(pCreatureObject), 2)
-                               assert.is.same(VillageJediManager.getJediProgressionStatus(pCreatureObject), 2)
-                               assert.is.same(VillageJediManager.getJediProgressionStatus(pCreatureObject), 2)
-                               assert.is.same(VillageJediManager.getJediProgressionStatus(pCreatureObject), 2)
-                               assert.is.same(VillageJediManager.getJediProgressionStatus(pCreatureObject), 3)
-                               assert.is.same(VillageJediManager.getJediProgressionStatus(pCreatureObject), 3)
-                               assert.is.same(VillageJediManager.getJediProgressionStatus(pCreatureObject), 3)
-                               assert.is.same(VillageJediManager.getJediProgressionStatus(pCreatureObject), 4)
-                               assert.is.same(VillageJediManager.getJediProgressionStatus(pCreatureObject), 4)
-                               assert.is.same(VillageJediManager.getJediProgressionStatus(pCreatureObject), 4)
-                               assert.is.same(VillageJediManager.getJediProgressionStatus(pCreatureObject), 5)
-
-                               assert.spy(VillageJediManager.countBadges).was.called(18)
-
-                               VillageJediManager.countBadges = realCountBadges
-                       end)
-               end)
-
-               describe("registerObservers", function()
-                       describe("When called with a player object", function()
-                               it("Should register an observer for the BADGEAWARDED event on the player.", function()
-                                       VillageJediManager.registerObservers(pCreatureObject)
-
-                                       assert.spy(createObserver).was.called_with(BADGEAWARDED, "VillageJediManager", "badgeAwardedEventHandler", pCreatureObject)
-                               end)
-                       end)
-               end)
-
-               describe("checkAndHandleJediProgression", function()
-                       local realCountBadges
-                       local realSetJediProgressionScreenPlayState
-
-                       setup(function()
-                               realCountBadges = VillageJediManager.countBadges
-                               realSetJediProgressionScreenPlayState = VillageJediManager.setJediProgressionScreenPlayState
-                       end)
-
-                       teardown(function()
-                               VillageJediManager.countBadges = realCountBadges
-                               VillageJediManager.setJediProgressionScreenPlayState = realSetJediProgressionScreenPlayState
-                       end)
-
-                       before_each(function()
-                               VillageJediManager.countBadges = spy.new(function() return TOTALNUMBEROFBADGESREQUIRED end)
-                               VillageJediManager.setJediProgressionScreenPlayState = spy.new(function() end)
-                       end)
-
-                       describe("When called with a player as argument", function()
-                               it("Should count the number of badges the player has towards the jedi progression.", function()
-                                       VillageJediManager.checkAndHandleJediProgression(pCreatureObject)
-
-                                       assert.spy(VillageJediManager.countBadges).was.called(1)
-                               end)
-
-                               describe("and the player has all the needed badges", function()
-                                       before_each(function()
-                                               VillageJediManager.countBadges = spy.new(function() return TOTALNUMBEROFBADGESREQUIRED end)
-                                       end)
-
-                                       it("Should set the village jedi progression screen play state glowing on the player", function()
-                                               VillageJediManager.checkAndHandleJediProgression(pCreatureObject)
-
-                                               assert.spy(VillageJediManager.setJediProgressionScreenPlayState).was.called_with(pCreatureObject, VILLAGE_JEDI_PROGRESSION_GLOWING)
-                                       end)
-
-                                       it("Should create an event to spawn the old man", function()
-                                               VillageJediManager.checkAndHandleJediProgression(pCreatureObject)
-
-                                               assert.spy(OldMan.createSpawnOldManEvent).was.called_with(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()
-                                               VillageJediManager.countBadges = spy.new(function() return TOTALNUMBEROFBADGESREQUIRED - 1 end)
-
-                                               VillageJediManager.checkAndHandleJediProgression(pCreatureObject)
-
-                                               assert.spy(OldMan.createSpawnOldManEvent).was.not_called()
-                                       end)
-                               end)
-                       end)
-               end)
        end)
 end)
diff --git a/MMOCoreORB/bin/scripts/managers/jedi/village/tests/village_jedi_manager_common_Test.lua b/MMOCoreORB/bin/scripts/managers/jedi/village/tests/village_jedi_manager_common_Test.lua
new file mode 100644 (file)
index 0000000..fa2504b
--- /dev/null
@@ -0,0 +1,71 @@
+local DirectorManagerMocks = require("screenplays.mocks.director_manager_mocks")
+
+local VillageJediManagerCommon = require("managers.jedi.village.village_jedi_manager_common")
+
+describe("Village Jedi Manager Common", function()
+       local pCreatureObject = { "creatureObjectPointer" }
+       local creatureObject
+
+       setup(function()
+               DirectorManagerMocks.setup()
+       end)
+
+       teardown(function()
+               DirectorManagerMocks.teardown()
+       end)
+
+       before_each(function()
+               DirectorManagerMocks.before_each()
+
+               creatureObject = {}
+               creatureObject.hasScreenPlayState = spy.new(function() return 0 end)
+               creatureObject.setScreenPlayState = spy.new(function() end)
+               DirectorManagerMocks.creatureObjects[pCreatureObject] = creatureObject
+       end)
+
+       describe("Interface functions", function()
+               describe("setJediProgressionScreenPlayState", function()
+                       describe("When called with a player and a state", function()
+                               it("Should write the state to the village jedi progression screen play state.", function()
+                                       VillageJediManagerCommon.setJediProgressionScreenPlayState(pCreatureObject, VILLAGE_JEDI_PROGRESSION_COMPLETED_VILLAGE)
+
+                                       assert.spy(creatureObject.setScreenPlayState).was.called_with(creatureObject, VILLAGE_JEDI_PROGRESSION_COMPLETED_VILLAGE, VILLAGE_JEDI_PROGRESSION_SCREEN_PLAY_STATE_STRING)
+                               end)
+                       end)
+
+                       describe("When called with the player pointer equal to nil", function()
+                               it("Should not write the state to the village jedi progression screen play state.", function()
+                                       VillageJediManagerCommon.setJediProgressionScreenPlayState(nil, VILLAGE_JEDI_PROGRESSION_COMPLETED_VILLAGE)
+
+                                       assert.spy(creatureObject.setScreenPlayState).was.not_called()
+                               end)
+                       end)
+               end)
+
+               describe("hasJediProgressionScreenPlayState", function()
+                       describe("When called with a player and a state", function()
+                               it("Should check if the player has the screen play state.", function()
+                                       VillageJediManagerCommon.hasJediProgressionScreenPlayState(pCreatureObject, VILLAGE_JEDI_PROGRESSION_COMPLETED_VILLAGE)
+
+                                       assert.spy(creatureObject.hasScreenPlayState).was.called_with(creatureObject, VILLAGE_JEDI_PROGRESSION_COMPLETED_VILLAGE, VILLAGE_JEDI_PROGRESSION_SCREEN_PLAY_STATE_STRING)
+                               end)
+
+                               it("Should return true if the player has the screen play state.", function()
+                                       creatureObject.hasScreenPlayState = spy.new(function() return 1 end)
+
+                                       assert.same(true, VillageJediManagerCommon.hasJediProgressionScreenPlayState(pCreatureObject, VILLAGE_JEDI_PROGRESSION_COMPLETED_VILLAGE))
+                               end)
+
+                               it("Should return false if the player does not have the screen play state.", function()
+                                       assert.same(false, VillageJediManagerCommon.hasJediProgressionScreenPlayState(pCreatureObject, VILLAGE_JEDI_PROGRESSION_COMPLETED_VILLAGE))
+                               end)
+                       end)
+
+                       describe("When called with the player pointer equal to nil", function()
+                               it("Should return false.", function()
+                                       assert.same(false, VillageJediManagerCommon.hasJediProgressionScreenPlayState(nil, VILLAGE_JEDI_PROGRESSION_COMPLETED_VILLAGE))
+                               end)
+                       end)
+               end)
+       end)
+end)
old mode 100644 (file)
new mode 100755 (executable)
index 23910e4..fcac4bf
@@ -1,16 +1,15 @@
-package.path = package.path .. ";scripts/managers/jedi/village/?.lua"
-VillageJediManagerHolocron = require("village_jedi_manager_holocron")
+VillageJediManagerHolocron = require("managers.jedi.village.village_jedi_manager_holocron")
 
 describe("Village Jedi Manager Holocron", function()
-       describe("Interface functions", function() 
+       describe("Interface functions", function()
                describe("useHolocron", function()
-                       it("Should use the holocron if the player is a jedi and does not have max force at the moment", function() 
+                       it("Should use the holocron if the player is a jedi and does not have max force at the moment", function()
                                local pCreatureObject = { "creatureObjectPointer" }
                                local pSceneObject = { "sceneObjectPointer" }
                                local realCanUseHolocron = VillageJediManagerHolocron.canUseHolocron
                                local realCanReplenishForce = VillageJediManagerHolocron.canReplenishForce
                                local realUseTheHolocron = VillageJediManagerHolocron.useTheHolocron
-                               
+
                                VillageJediManagerHolocron.canUseHolocron = spy.new(function() return true end)
                                VillageJediManagerHolocron.canReplenishForce = spy.new(function() return true end)
                                VillageJediManagerHolocron.useTheHolocron = spy.new(function() end)
@@ -26,13 +25,13 @@ describe("Village Jedi Manager Holocron", function()
                                VillageJediManagerHolocron.useTheHolocron = realUseTheHolocron
                        end)
 
-                       it("Should send message about not able to replenish force if player is jedi but has full force", function() 
+                       it("Should send message about not able to replenish force if player is jedi but has full force", function()
                                local pCreatureObject = { "creatureObjectPointer" }
                                local pSceneObject = { "sceneObjectPointer" }
                                local realCanUseHolocron = VillageJediManagerHolocron.canUseHolocron
                                local realCanReplenishForce = VillageJediManagerHolocron.canReplenishForce
                                local realCannotReplenishForce = VillageJediManagerHolocron.cannotReplenishForce
-                               
+
                                VillageJediManagerHolocron.canUseHolocron = spy.new(function() return true end)
                                VillageJediManagerHolocron.canReplenishForce = spy.new(function() return false end)
                                VillageJediManagerHolocron.cannotReplenishForce = spy.new(function() end)
@@ -48,12 +47,12 @@ describe("Village Jedi Manager Holocron", function()
                                VillageJediManagerHolocron.cannotReplenishForce = realCannotReplenishForce
                        end)
 
-                       it("Should send message about not being able to use the holocron if player is not jedi", function() 
+                       it("Should send message about not being able to use the holocron if player is not jedi", function()
                                local pCreatureObject = { "creatureObjectPointer" }
                                local pSceneObject = { "sceneObjectPointer" }
                                local realCanUseHolocron = VillageJediManagerHolocron.canUseHolocron
                                local realCannotUseHolocron = VillageJediManagerHolocron.cannotUseHolocron
-                               
+
                                VillageJediManagerHolocron.canUseHolocron = spy.new(function() return false end)
                                VillageJediManagerHolocron.cannotUseHolocron = spy.new(function() end)
 
@@ -68,7 +67,7 @@ describe("Village Jedi Manager Holocron", function()
                end)
        end)
 
-       describe("Private functions", function() 
+       describe("Private functions", function()
                describe("canUseHolocron", function()
                        it("Should return false if player is not jedi", function()
                                local pCreatureObject = { "creatureObjectPointer" }
old mode 100644 (file)
new mode 100755 (executable)
index ebe2ce9..40b919e
-package.path = package.path .. ";scripts/managers/jedi/?.lua;scripts/managers/jedi/village/?.lua"
-JediManager = require("jedi_manager")
-require("village_jedi_manager_holocron")
-require("old_man_conv_handler")
-require("old_man")
+JediManager = require("managers.jedi.jedi_manager")
+require("managers.jedi.village.village_jedi_manager_holocron")
+require("managers.jedi.village.old_man_conv_handler")
+local Glowing = require("managers.jedi.village.glowing")
 
 jediManagerName = "VillageJediManager"
 
-TOTALNUMBEROFBADGESREQUIRED = 17
-NUMBEROFJEDIBADGESREQUIRED = 3
-NUMBEROFDIFFICULTBADGESREQUIRED = 3
-NUMBEROFEASYBADGESREQUIRED = 5
-NUMBEROFPROFESSIONBADGESREQUIRED = 1
-NUMBEROFCONTENTBADGESREQUIRED = 5
-
 NOTINABUILDING = 0
 
-VILLAGE_JEDI_PROGRESSION_SCREEN_PLAY_STATE_STRING = "VillageJediProgression"
-VILLAGE_JEDI_PROGRESSION_GLOWING = 1
-VILLAGE_JEDI_PROGRESSION_HAS_CRYSTAL = 2
-VILLAGE_JEDI_PROGRESSION_HAS_VILLAGE_ACCESS = 4
-VILLAGE_JEDI_PROGRESSION_COMPLETED_VILLAGE = 8
-VILLAGE_JEDI_PROGRESSION_DEFEATED_MELLIACHAE = 16
-
-JEDIBADGES = {
-       EXP_TAT_BENS_HUT,
-       EXP_YAV_TEMPLE_EXAR_KUN,
-       EXP_DAN_JEDI_TEMPLE
-}
-
-DIFFICULTBADGES = {
-       EXP_TAT_TUSKEN_POOL,
-       EXP_TAT_KRAYT_SKELETON,
-       EXP_TAT_SARLACC_PIT,
-       EXP_TAT_KRAYT_GRAVEYARD,
-       EXP_DAT_SARLACC
-}
-
-EASYBADGES = {
-       EXP_TAT_ESCAPE_POD,
-       EXP_TAT_LARS_HOMESTEAD,
-       EXP_NAB_GUNGAN_SACRED_PLACE,
-       EXP_COR_AGRILAT_SWAMP,
-       EXP_YAV_TEMPLE_WOOLAMANDER,
-       EXP_YAV_TEMPLE_BLUELEAF,
-       EXP_LOK_VOLCANO,
-       EXP_DAT_TARPIT,
-       EXP_DAT_ESCAPE_POD,
-       EXP_DAT_MISTY_FALLS_1,
-       EXP_DAT_MISTY_FALLS_2,
-       EXP_DAN_REBEL_BASE,
-       BDG_EXP_NAB_THEED_FALLS_BOTTOM,
-       BDG_EXP_NAB_DEEJA_FALLS_TOP,
-       BDG_EXP_NAB_AMIDALAS_SANDY_BEACH,
-       BDG_EXP_COR_REBEL_HIDEOUT,
-       BDG_EXP_COR_ROGUE_CORSEC_BASE,
-       BDG_EXP_COR_TYRENA_THEATER,
-       BDG_EXP_COR_BELA_VISTAL_FOUNTAIN,
-       BDG_EXP_DAT_CRASHED_SHIP,
-       BDG_EXP_DAT_IMP_PRISON,
-       BDG_EXP_DAN_DANTARI_VILLAGE1,
-       BDG_EXP_DAN_DANTARI_VILLAGE2,
-       BDG_EXP_END_EWOK_TREE_VILLAGE,
-       BDG_EXP_END_EWOK_LAKE_VILLAGE,
-       BDG_EXP_END_DULOK_VILLAGE,
-       BDG_EXP_END_IMP_OUTPOST,
-       BDG_EXP_TAL_CREATURE_VILLAGE,
-       BDG_EXP_TAL_IMP_BASE,
-       BDG_EXP_TAL_IMP_VS_REB_BATTLE,
-       BDG_EXP_TAL_AQUALISH_CAVE,
-       BDG_EXP_ROR_KOBALA_SPICE_MINE,
-       BDG_EXP_ROR_REBEL_OUTPOST,
-       BDG_EXP_ROR_IMP_CAMP,
-       BDG_EXP_ROR_IMP_HYPERDRIVE_FAC,
-       BDG_EXP_LOK_KIMOGILA_SKELETON
-}
-
-CONTENTBADGES = {
-       BDG_THM_PARK_JABBA_BADGE,
-       BDG_THM_PARK_IMPERIAL_BADGE,
-       BDG_THM_PARK_REBEL_BADGE,
-       BDG_THM_PARK_NYM_BADGE,
-       BDG_CORVETTE_IMP_DESTROY,
-       BDG_CORVETTE_IMP_RESCUE,
-       BDG_CORVETTE_IMP_ASSASSIN,
-       BDG_CORVETTE_NEUTRAL_DESTROY,
-       BDG_CORVETTE_NEUTRAL_RESCUE,
-       BDG_CORVETTE_NEUTRAL_ASSASSIN,
-       BDG_CORVETTE_REB_DESTROY,
-       BDG_CORVETTE_REB_RESCUE,
-       BDG_CORVETTE_REB_ASSASSIN,
-       WARREN_COMPASSION,
-       WARREN_HERO
-}
-
-PROFESSIONBADGES = {
-       COMBAT_1HSWORD_MASTER,
-       COMBAT_2HSWORD_MASTER,
-       COMBAT_BOUNTYHUNTER_MASTER,
-       COMBAT_BRAWLER_MASTER,
-       COMBAT_CARBINE_MASTER,
-       COMBAT_COMMANDO_MASTER,
-       COMBAT_MARKSMAN_MASTER,
-       COMBAT_PISTOL_MASTER,
-       COMBAT_POLEARM_MASTER,
-       COMBAT_RIFLEMAN_MASTER,
-       COMBAT_SMUGGLER_MASTER,
-       COMBAT_UNARMED_MASTER,
-       CRAFTING_ARCHITECT_MASTER,
-       CRAFTING_ARMORSMITH_MASTER,
-       CRAFTING_ARTISAN_MASTER,
-       CRAFTING_CHEF_MASTER,
-       CRAFTING_DROIDENGINEER_MASTER,
-       CRAFTING_MERCHANT_MASTER,
-       CRAFTING_TAILOR_MASTER,
-       CRAFTING_WEAPONSMITH_MASTER,
-       OUTDOORS_BIOENGINEER_MASTER,
-       OUTDOORS_CREATUREHANDLER_MASTER,
-       OUTDOORS_RANGER_MASTER,
-       OUTDOORS_SCOUT_MASTER,
-       OUTDOORS_SQUADLEADER_MASTER,
-       SCIENCE_COMBATMEDIC_MASTER,
-       SCIENCE_DOCTOR_MASTER,
-       SCIENCE_MEDIC_MASTER,
-       SOCIAL_DANCER_MASTER,
-       SOCIAL_ENTERTAINER_MASTER,
-       SOCIAL_IMAGEDESIGNER_MASTER,
-       SOCIAL_MUSICIAN_MASTER,
-       SOCIAL_POLITICIAN_MASTER,
-       CRAFTING_SHIPWRIGHT,
-       PILOT_REBEL_NAVY_NABOO,
-       PILOT_REBEL_NAVY_CORELLIA,
-       PILOT_REBEL_NAVY_TATOOINE,
-       PILOT_IMPERIAL_NAVY_NABOO,
-       PILOT_IMPERIAL_NAVY_CORELLIA,
-       PILOT_IMPERIAL_NAVY_TATOOINE,
-       PILOT_NEUTRAL_NABOO,
-       PILOT_CORELLIA,
-       PILOT_TATOOINE
-}
-
 VillageJediManager = JediManager:new {
        screenplayName = jediManagerName,
        jediManagerName = jediManagerName,
@@ -153,104 +21,16 @@ function VillageJediManager:useHolocron(pSceneObject, pCreatureObject)
        VillageJediManagerHolocron.useHolocron(pSceneObject, pCreatureObject)
 end
 
--- Count the number of badges that the player got in the list.
--- @param pCreatureObject pointer to the creature object of the player.
--- @param list the list of badge numbers to check if the player has.
--- @param upperLimit only count up to this limit.
--- @return the number of badges in the list that the player has been awarded
-function VillageJediManager.countBadgesInListToUpperLimit(pCreatureObject, list, upperLimit)
-       local numberOfBadges = 0
-       VillageJediManager.withCreaturePlayerObject(pCreatureObject, function(playerObject)
-               for i = 1, table.getn(list), 1 do
-                       if playerObject:hasBadge(list[i]) then
-                               numberOfBadges = numberOfBadges + 1
-                               if numberOfBadges >= upperLimit then
-                                       break
-                               end
-                       end
-               end
-       end)
-       return numberOfBadges
-end
-
--- Count the total number of badges towards the jedi progression for the player
--- @param pCreatureObject pointer to the creature object of the player.
--- @return the total number of interesting badges.
-function VillageJediManager.countBadges(pCreatureObject)
-       local professionBadges = VillageJediManager.countBadgesInListToUpperLimit(pCreatureObject, PROFESSIONBADGES, NUMBEROFPROFESSIONBADGESREQUIRED)
-       local jediBadges = VillageJediManager.countBadgesInListToUpperLimit(pCreatureObject, JEDIBADGES, NUMBEROFJEDIBADGESREQUIRED)
-       local contentBadges = VillageJediManager.countBadgesInListToUpperLimit(pCreatureObject, CONTENTBADGES, NUMBEROFCONTENTBADGESREQUIRED)
-       local difficultBadges = VillageJediManager.countBadgesInListToUpperLimit(pCreatureObject, DIFFICULTBADGES, NUMBEROFDIFFICULTBADGESREQUIRED)
-       local easyBadges = VillageJediManager.countBadgesInListToUpperLimit(pCreatureObject, EASYBADGES, NUMBEROFEASYBADGESREQUIRED)
-       return professionBadges + jediBadges + contentBadges + difficultBadges + easyBadges
-end
-
--- Get the jedi progression status for the player
--- @param pCreatureObject pointer to the creature object of the player.
--- @return the jedi progression status, 0 to 5 to be used to return correct string id to the player.
-function VillageJediManager.getJediProgressionStatus(pCreatureObject)
-       local numberOfBadges = VillageJediManager.countBadges(pCreatureObject)
-       return math.floor((numberOfBadges / TOTALNUMBEROFBADGESREQUIRED) * 5)
-end
-
 -- Handling of the checkForceStatus command.
 -- @param pCreatureObject pointer to the creature object of the player who performed the command
 function VillageJediManager:checkForceStatusCommand(pCreatureObject)
-       VillageJediManager.withCreatureObject(pCreatureObject, function(creatureObject)
-               creatureObject:sendSystemMessage("@jedi_spam:fs_progress_" .. VillageJediManager.getJediProgressionStatus(pCreatureObject))
-       end)
-end
-
--- Check if the player should progress towards jedi and handle any events for it.
--- @param pCreatureObject pointer to the creature object of the player.
-function VillageJediManager.checkAndHandleJediProgression(pCreatureObject)
-       if VillageJediManager.countBadges(pCreatureObject) >= TOTALNUMBEROFBADGESREQUIRED then
-               VillageJediManager.setJediProgressionScreenPlayState(pCreatureObject, VILLAGE_JEDI_PROGRESSION_GLOWING)
-               OldMan.createSpawnOldManEvent(pCreatureObject)
-       end
-end
-
--- Event handler for the BADGEAWARDED event.
--- @param pCreatureObject pointer to the creature object of the player who was awarded with a badge.
--- @param pCreatureObject2 pointer to the creature object of the player who was awarded with a badge.
--- @param badgeNumber the badge number that was awarded.
--- @return 0 to keep the observer active.
-function VillageJediManager:badgeAwardedEventHandler(pCreatureObject, pCreatureObject2, badgeNumber)
-       VillageJediManager.checkAndHandleJediProgression(pCreatureObject)
-
-       return 0
-end
-
--- Register observer on the player for observing badge awards.
--- @param pCreatureObject pointer to the creature object of the player to register observers on.
-function VillageJediManager.registerObservers(pCreatureObject)
-       createObserver(BADGEAWARDED, "VillageJediManager", "badgeAwardedEventHandler", pCreatureObject)
+       Glowing.checkForceStatusCommand(pCreatureObject)
 end
 
 -- Handling of the onPlayerLoggedIn event. The progression of the player will be checked and observers will be registered.
 -- @param pCreatureObject pointer to the creature object of the player who logged in.
 function VillageJediManager:onPlayerLoggedIn(pCreatureObject)
-       VillageJediManager.checkAndHandleJediProgression(pCreatureObject)
-       VillageJediManager.registerObservers(pCreatureObject)
-end
-
--- Set the jedi progression screen play state on the player.
--- @param pCreatureObject pointer to the creature object of the player.
--- @param state the state to set.
-function VillageJediManager.setJediProgressionScreenPlayState(pCreatureObject, state)
-       VillageJediManager.withCreatureObject(pCreatureObject, function(creatureObject)
-               creatureObject:setScreenPlayState(state, VILLAGE_JEDI_PROGRESSION_SCREEN_PLAY_STATE_STRING)
-       end)
-end
-
--- Check ifthe player has the jedi progression screen play state.
--- @param pCreatureObject pointer to the creature object of the player.
--- @param state the state to check if the player has.
--- @return true if the player has the state.
-function VillageJediManager.hasJediProgressionScreenPlayState(pCreatureObject, state)
-       return VillageJediManager.withCreatureObject(pCreatureObject, function(creatureObject)
-               return creatureObject:hasScreenPlayState(state, VILLAGE_JEDI_PROGRESSION_SCREEN_PLAY_STATE_STRING)
-       end) == true
+       Glowing.onPlayerLoggedIn(pCreatureObject)
 end
 
 registerScreenPlay("VillageJediManager", true)
diff --git a/MMOCoreORB/bin/scripts/managers/jedi/village/village_jedi_manager_common.lua b/MMOCoreORB/bin/scripts/managers/jedi/village/village_jedi_manager_common.lua
new file mode 100644 (file)
index 0000000..3f6bb09
--- /dev/null
@@ -0,0 +1,31 @@
+local ScreenPlay = require("screenplays.screenplay")
+
+local VillageJediManagerCommon = ScreenPlay:new {}
+
+VILLAGE_JEDI_PROGRESSION_SCREEN_PLAY_STATE_STRING = "VillageJediProgression"
+VILLAGE_JEDI_PROGRESSION_GLOWING = 1
+VILLAGE_JEDI_PROGRESSION_HAS_CRYSTAL = 2
+VILLAGE_JEDI_PROGRESSION_HAS_VILLAGE_ACCESS = 4
+VILLAGE_JEDI_PROGRESSION_COMPLETED_VILLAGE = 8
+VILLAGE_JEDI_PROGRESSION_DEFEATED_MELLIACHAE = 16
+
+-- Set the jedi progression screen play state on the player.
+-- @param pCreatureObject pointer to the creature object of the player.
+-- @param state the state to set.
+function VillageJediManagerCommon.setJediProgressionScreenPlayState(pCreatureObject, state)
+       VillageJediManagerCommon.withCreatureObject(pCreatureObject, function(creatureObject)
+               creatureObject:setScreenPlayState(state, VILLAGE_JEDI_PROGRESSION_SCREEN_PLAY_STATE_STRING)
+       end)
+end
+
+-- Check if the player has the jedi progression screen play state.
+-- @param pCreatureObject pointer to the creature object of the player.
+-- @param state the state to check if the player has.
+-- @return true if the player has the state.
+function VillageJediManagerCommon.hasJediProgressionScreenPlayState(pCreatureObject, state)
+       return VillageJediManagerCommon.withCreatureObject(pCreatureObject, function(creatureObject)
+               return creatureObject:hasScreenPlayState(state, VILLAGE_JEDI_PROGRESSION_SCREEN_PLAY_STATE_STRING) == 1
+       end) == true
+end
+
+return VillageJediManagerCommon
old mode 100644 (file)
new mode 100755 (executable)
index 01c8d20..4fff738
@@ -1,5 +1,4 @@
-package.path = package.path .. ";scripts/screenplays?.lua"
-require("screenplay")
+require("screenplays.screenplay")
 
 USEDHOLOCRON = "used_holocron"
 HOLOCRONCOOLDOWNTIME = 24 * 60 * 60 * 1000 -- 24 hours
@@ -10,7 +9,7 @@ VillageJediManagerHolocron = ScreenPlay:new {}
 -- @param pCreatureObject pointer to the creature object of the player who tries to use the holocron.
 -- @return true if the player can use the holocron.
 function VillageJediManagerHolocron.canUseHolocron(pCreatureObject)
-       return VillageJediManagerHolocron.withCreatureAndPlayerObject(pCreatureObject, function(creatureObject, playerObject) 
+       return VillageJediManagerHolocron.withCreatureAndPlayerObject(pCreatureObject, function(creatureObject, playerObject)
                return playerObject:isJedi() and not creatureObject:checkCooldownRecovery(USEDHOLOCRON)
        end)
 end
@@ -28,7 +27,7 @@ end
 -- @param pSceneObject pointer to the scene object of the holocron.
 -- @param pCreatureObject pointer to the creature object of the player who is using the holocron.
 function VillageJediManagerHolocron.useTheHolocron(pSceneObject, pCreatureObject)
-       VillageJediManagerHolocron.withCreatureAndPlayerObject(pCreatureObject, function(creatureObject, playerObject) 
+       VillageJediManagerHolocron.withCreatureAndPlayerObject(pCreatureObject, function(creatureObject, playerObject)
                -- The holocrom hums softly as you feel your Force power replenish.
                creatureObject:sendSystemMessage("@jedi_spam:holocron_force_replenish")
                playerObject:setForcePower(playerObject:getForcePowerMax());
index 0ae4d66..605cb0f 100644 (file)
@@ -1,5 +1,4 @@
-package.path = package.path .. ";scripts/screenplays/?.lua"
-require("screenplay")
+require("screenplays.screenplay")
 
 describe("ScreenPlay", function()
        it("Shall return nil if the creature object pointer is nil to the withCreatureAiAgent function.", function()
@@ -124,7 +123,7 @@ describe("ScreenPlay", function()
                local getPlayerObjectSpy = spy.new(function() return pPlayerObject end)
                local realLuaCreatureObject = LuaCreatureObject
                LuaCreatureObject = spy.new(function() return { getPlayerObject = getPlayerObjectSpy } end)
-               local realLuaPlayerObject  = LuaPlayerObject 
+               local realLuaPlayerObject  = LuaPlayerObject
                LuaPlayerObject = spy.new(function() return playerObjectCreated end)
 
                ScreenPlay.withCreaturePlayerObject(pCreatureObject, function(playerObject) playerObjectArgument = playerObject end)
@@ -144,10 +143,10 @@ describe("ScreenPlay", function()
                local creatureObjectCreated = { getPlayerObject = getPlayerObjectSpy }
                local realLuaCreatureObject = LuaCreatureObject
                LuaCreatureObject = spy.new(function() return creatureObjectCreated end)
-               local realLuaPlayerObject  = LuaPlayerObject 
+               local realLuaPlayerObject  = LuaPlayerObject
                LuaPlayerObject = spy.new(function() return playerObjectCreated end)
 
-               ScreenPlay.withCreatureAndPlayerObject(pCreatureObject, function(creatureObject, playerObject) 
+               ScreenPlay.withCreatureAndPlayerObject(pCreatureObject, function(creatureObject, playerObject)
                        creatureObjectArgument = creatureObject
                        playerObjectArgument = playerObject
                end)
index 7c837e4..cff9b6e 100644 (file)
@@ -1,8 +1,6 @@
-package.path = package.path .. ";scripts/screenplays/themepark/?.lua"
-
 includeFile = spy.new(function() end)
 
-require("themeParkLogic")
+require("screenplays.themepark.themeParkLogic")
 
 describe("Theme Park Logic", function()
   it("Defines the purple color of waypoints to the value 5.", function()
index 8069235..6f8b319 100644 (file)
@@ -1,5 +1,4 @@
-package.path = package.path .. ";scripts/screenplays/?.lua"
-require("screenplay")
+require("screenplays.screenplay")
 
 WAYPOINT_COLOR_PURPLE = 5
 SIT = 1
@@ -42,10 +41,10 @@ function ThemeParkLogic:permissionObservers()
                local permission = self.permissionMap[i]
                self:setupPermissionGroups(permission)
                local pRegion = getRegion(permission.planetName, permission.regionName)
-               
+
                if pRegion ~= nil then
                        createObserver(ENTEREDAREA, self.className, "cellPermissionsObserver", pRegion)
-               end 
+               end
        end
 end
 
@@ -72,7 +71,7 @@ function ThemeParkLogic:cellPermissionsObserver(pRegion, pCreature)
        end
 
        local creatureSceneObject = LuaSceneObject(pCreature)
-       
+
        if creatureSceneObject:isCreatureObject() then
                local region = LuaSceneObject(pRegion)
                for i = 1, # self.permissionMap, 1 do
@@ -80,8 +79,8 @@ function ThemeParkLogic:cellPermissionsObserver(pRegion, pCreature)
                                self:setCellPermissions(self.permissionMap[i], pCreature)
                        end
                end
-       end     
-       
+       end
+
        return 0
 end
 
@@ -89,7 +88,7 @@ function ThemeParkLogic:setCellPermissions(permissions, pCreature)
        if pCreature ~= nil then
                local creature = LuaCreatureObject(pCreature)
                local pGhost = creature:getPlayerObject()
-               if pGhost ~= nil then   
+               if pGhost ~= nil then
                        local ghost = LuaPlayerObject(pGhost)
                        for i = 1, # permissions.permissions, 1 do
                                if self:hasPermission(permissions.permissions[i].conditions, pCreature) == true then
@@ -130,7 +129,7 @@ function ThemeParkLogic:isInFaction(faction, pCreature)
        end
 
        local creature = LuaCreatureObject(pCreature)
-       
+
        if creature:getFaction() == faction then
                return true
        else
@@ -160,9 +159,9 @@ function ThemeParkLogic:hasMissionState(mission, missionState, pCreature)
        if pCreature == nil then
                return false
        end
-       
+
        local npcNumber = self:getActiveNpcNumber(pCreature)
-       
+
        if npcNumber > missionState then
                return true
        else
@@ -173,20 +172,20 @@ end
 function ThemeParkLogic:getNpcNumber(pNpc)
        if pNpc == nil then
                return 0
-       end     
+       end
        local npc = LuaCreatureObject(pNpc)
-       
+
        local x = npc:getPositionX()
        local y = npc:getPositionY()
        local z = npc:getPositionZ()
-       
+
        for i = 1, # self.npcMap do
                local npcData = self.npcMap[i].spawnData
                if (math.abs(x - npcData.x) < 0.1) and (math.abs(z - npcData.z) < 0.1) and (math.abs(y - npcData.y) < 0.1) then
                        return self.npcMap[i].npcNumber
                end
        end
-       
+
        return 1
 end
 
@@ -204,9 +203,9 @@ function ThemeParkLogic:getActiveNpcNumber(pConversingPlayer)
        if pConversingPlayer == nil then
                return -1
        end
-       
+
        local creature = LuaCreatureObject(pConversingPlayer)
-       
+
        local npcNumber = 1
        local activeNpcNumber = 1
        for i = 1, 10, 1 do
@@ -223,7 +222,7 @@ function ThemeParkLogic:activeNpc(pConversingPlayer, pConversingNpc)
        if pConversingPlayer == nil then
                return -1
        end
-       
+
        local npcNumber = self:getNpcNumber(pConversingNpc)
        local activeNpcNumber = self:getActiveNpcNumber(pConversingPlayer)
        return npcNumber - activeNpcNumber
@@ -237,9 +236,9 @@ function ThemeParkLogic:getCurrentMissionNumber(npcNumber, pConversingPlayer)
 
        local npcData = self:getNpcData(npcNumber)
        if npcData ~= nil then
-               local npcName = npcData.spawnData.npcTemplate   
+               local npcName = npcData.spawnData.npcTemplate
                local numberOfMissionsTotal = table.getn(npcData.missions)
-               
+
                local missionsCompleted = 0
                local stateToCheck = 1
                for i = 1, numberOfMissionsTotal, 1 do
@@ -248,7 +247,7 @@ function ThemeParkLogic:getCurrentMissionNumber(npcNumber, pConversingPlayer)
                                missionsCompleted = missionsCompleted + 1
                        end
                end
-               
+
                return missionsCompleted + 1
        else
                return 0
@@ -260,17 +259,17 @@ function ThemeParkLogic:missionStatus(pConversingPlayer)
                return 0
        end
        local creature = LuaCreatureObject(pConversingPlayer)
-       
+
        return readData(creature:getObjectID() .. ":activeMission")
 end
 
-function ThemeParkLogic:getStfFile(npcNumber)  
+function ThemeParkLogic:getStfFile(npcNumber)
        local npcData = self:getNpcData(npcNumber)
 
        return npcData.stfFile
 end
 
-function ThemeParkLogic:getHasWaypointNames(npcNumber) 
+function ThemeParkLogic:getHasWaypointNames(npcNumber)
        local npcData = self:getNpcData(npcNumber)
 
        return npcData.hasWaypointNames
@@ -281,7 +280,7 @@ function ThemeParkLogic:handleMissionAccept(npcNumber, missionNumber, pConversin
        local creature = LuaCreatureObject(pConversingPlayer)
 
        writeStringData(creature:getObjectID() .. ":activeScreenPlay", self.className)
-       
+
        if mission.missionType == "deliver" then
                return self:handleDeliverMissionAccept(mission, pConversingPlayer, missionNumber)
        elseif mission.missionType == "escort" then
@@ -299,20 +298,20 @@ function ThemeParkLogic:writeData(pConversingPlayer, dataName, value)
        if pConversingPlayer == nil then
                return
        end
-       
+
        local creature = LuaCreatureObject(pConversingPlayer)
        writeData(creature:getObjectID() .. dataName, value)
 end
 
 function ThemeParkLogic:getMission(npcNumber, missionNumber)
        local npcData = self:getNpcData(npcNumber)
-       
+
        if (npcData == nil) then
                printf("null npcData in ThemeParkLogic:getMission for %s", self.className);
        end
-       
+
        local missions = npcData.missions
-       
+
        return missions[missionNumber]
 end
 
@@ -374,9 +373,9 @@ function ThemeParkLogic:spawnMissionNpcs(mission, pConversingPlayer)
        if table.getn(spawnPoints) ~= numberOfSpawns then
                return false
        end
-       
+
        writeData(creature:getObjectID() .. ":missionSpawns", numberOfSpawns)
-       
+
        local mainNpcs = mission.primarySpawns
        for i = 1, table.getn(mission.primarySpawns), 1 do
                local pNpc = self:spawnNpc(mainNpcs[i], spawnPoints[i], pConversingPlayer, i)
@@ -403,12 +402,12 @@ function ThemeParkLogic:spawnMissionNpcs(mission, pConversingPlayer)
                        end
                end
        end
-       
+
        local secondaryNpcs = mission.secondarySpawns
        for i = 1 + table.getn(mission.primarySpawns), numberOfSpawns, 1 do
                self:spawnNpc(secondaryNpcs[i - table.getn(mission.primarySpawns)], spawnPoints[i], pConversingPlayer, i)
        end
-       
+
        return true
 end
 
@@ -419,7 +418,7 @@ function ThemeParkLogic:notifyDefeatedTargetWithLoot(pVictim, pAttacker)
 
        local victim = LuaCreatureObject(pVictim)
        local attacker = LuaCreatureObject(pAttacker)
-       
+
        local victimID = victim:getObjectID()
        local attackerID = attacker:getObjectID()
 
@@ -441,7 +440,7 @@ function ThemeParkLogic:notifyDefeatedTargetWithLoot(pVictim, pAttacker)
        for j = 1, # requiredItems, 1 do
                for i = 0, numberOfItems - 1, 1 do
                        local pItem = inventory:getContainerObject(i)
-                       
+
                        if pItem ~= nil then
                                local item = LuaSceneObject(pItem)
 
@@ -489,11 +488,11 @@ function ThemeParkLogic:lootedByCorrectPlayer(itemID, looterID)
        end
 end
 
-function ThemeParkLogic:getMissionLootCount(pLooter)   
+function ThemeParkLogic:getMissionLootCount(pLooter)
        local npcNumber = self:getActiveNpcNumber(pLooter)
        local missionNumber = self:getCurrentMissionNumber(npcNumber, pLooter)
        local mission = self:getMission(npcNumber, missionNumber)
-       
+
        if mission.missionType == "confiscate" then
                return table.getn(mission.itemSpawns)
        else
@@ -508,19 +507,19 @@ function ThemeParkLogic:notifyDefeatedTarget(pVictim, pAttacker)
 
        local victim = LuaCreatureObject(pVictim)
        local attacker = LuaCreatureObject(pAttacker)
-       
+
        local victimID = victim:getObjectID()
        local attackerID = attacker:getObjectID()
-       
+
        if self:killedByCorrectPlayer(victimID, attackerID) == true then
                local currentKillCount = readData(attackerID .. ":killedMissionNpcs") + 1
                writeData(attackerID .. ":killedMissionNpcs", currentKillCount)
-               
+
                if currentKillCount == self:getMissionKillCount(pAttacker) then
                        self:completeMission(pAttacker)
                end
        end
-       
+
        return 1
 end
 
@@ -531,26 +530,26 @@ function ThemeParkLogic:notifyDamagedTarget(pTarget, pAttacker, damage)
        local npcNumber = self:getActiveNpcNumber(pAttacker)
        local missionNumber = self:getCurrentMissionNumber(npcNumber, pAttacker)
        local stfFile = self:getStfFile(npcNumber)
-       
+
        local attacker = LuaCreatureObject(pAttacker)
        local target = LuaCreatureObject(pTarget)
-       
+
        local targetID = target:getObjectID()
        local attackerID = attacker:getObjectID()
-       
+
        if self:killedByCorrectPlayer(targetID, attackerID) == true then
                spatialChat(pTarget, stfFile .. ":npc_breech_" .. missionNumber)
                return 1
        end
-       
+
        return 0
 end
 
-function ThemeParkLogic:getMissionKillCount(pAttacker) 
+function ThemeParkLogic:getMissionKillCount(pAttacker)
        local npcNumber = self:getActiveNpcNumber(pAttacker)
        local missionNumber = self:getCurrentMissionNumber(npcNumber, pAttacker)
        local mission = self:getMission(npcNumber, missionNumber)
-       
+
        if mission.missionType == "assassinate" then
                return table.getn(mission.primarySpawns)
        else
@@ -570,14 +569,14 @@ function ThemeParkLogic:spawnNpc(npcTemplate, position, pConversingPlayer, spawn
        if pConversingPlayer == nil then
                return nil
        end
-       
+
        local pNpc = spawnMobile(npcTemplate.planetName, npcTemplate.npcTemplate, 0, position[1], position[2], position[3], math.random(-180, 180), position[4])
-       
+
        if pNpc ~= nil then
                local npc = LuaCreatureObject(pNpc)
                local npcName = self:getNpcName(npcTemplate.npcName)
                npc:setCustomObjectName(npcName)
-               
+
                local creature = LuaCreatureObject(pConversingPlayer)
 
                writeData(creature:getObjectID() .. ":missionSpawn:no" .. spawnNumber, npc:getObjectID())
@@ -599,19 +598,19 @@ function ThemeParkLogic:giveMissionItems(mission, pConversingPlayer)
 
        local creature = LuaCreatureObject(pConversingPlayer)
        writeData(creature:getObjectID() .. ":activeMission", 1)
-       
+
        local itemsToGive = mission.itemSpawns
-       
+
        local pInventory = creature:getSlottedObject("inventory")
        if pInventory == nil then
                return
        end
-       
+
        writeData(creature:getObjectID() .. ":missionItems", table.getn(itemsToGive))
-       
+
        for i = 1, table.getn(itemsToGive), 1 do
                local pItem = giveItem(pInventory, itemsToGive[i].itemTemplate, -1)
-               
+
                if (pItem ~= nil) then
                        local item = LuaSceneObject(pItem)
                        item:setCustomObjectName(itemsToGive[i].itemName)
@@ -624,13 +623,13 @@ function ThemeParkLogic:getMissionDescription(pConversingPlayer, direction)
        local activeNpcNumber = self:getActiveNpcNumber(pConversingPlayer)
        local missionNumber = self:getCurrentMissionNumber(activeNpcNumber, pConversingPlayer)
        local creature = LuaCreatureObject(pConversingPlayer)
-       
+
        local npcNumber = 1
        while (npcNumber < activeNpcNumber) do
                missionNumber = missionNumber + table.getn(self:getNpcData(npcNumber).missions)
                npcNumber = npcNumber * 2
        end
-       
+
        if self.missionDescriptionStf == "" then
                local wpNames = self:getHasWaypointNames(activeNpcNumber)
                local currentMissionNumber = self:getCurrentMissionNumber(activeNpcNumber, pConversingPlayer)
@@ -714,7 +713,7 @@ end
 
 function ThemeParkLogic:getSpawnPoints(numberOfSpawns, x, y, pConversingPlayer)
        local spawnPoints = {}
-       
+
        local spawnDistance = self.distance
 
        local firstSpawnPoint = getSpawnPoint(pConversingPlayer, x, y, spawnDistance, (spawnDistance/2)*3)
@@ -727,7 +726,7 @@ function ThemeParkLogic:getSpawnPoints(numberOfSpawns, x, y, pConversingPlayer)
                        end
                end
        end
-       
+
        return spawnPoints
 end
 
@@ -737,22 +736,22 @@ function ThemeParkLogic:hasRequiredItem(pConversingPlayer)
        end
 
        local creature = LuaCreatureObject(pConversingPlayer)
-       
+
        local pInventory = creature:getSlottedObject("inventory")
        if pInventory == nil then
                return false
        end
 
        local inventory = LuaSceneObject(pInventory)
-       
+
        local itemID = readData(creature:getObjectID() .. ":missionItem:no1")
-               
+
        local pItem = inventory:getContainerObjectById(itemID)
-       
+
        if pItem == nil then
                return false
        end
-       
+
        return true
 end
 
@@ -762,12 +761,12 @@ function ThemeParkLogic:hasLootedRequiredItem(activeNpcNumber, pConversingPlayer
        end
 
        local creature = LuaCreatureObject(pConversingPlayer)
-       
+
        local pInventory = creature:getSlottedObject("inventory")
        if pInventory == nil then
                return false
        end
-       
+
        local inventory = LuaSceneObject(pInventory)
 
        local numberOfItems = inventory:getContainerObjectsSize()
@@ -779,7 +778,7 @@ function ThemeParkLogic:hasLootedRequiredItem(activeNpcNumber, pConversingPlayer
                unmatchedItems = unmatchedItems + 1
                for i = 0, numberOfItems - 1, 1 do
                        local pItem = inventory:getContainerObject(i)
-                       
+
                        if pItem ~= nil then
                                local item = LuaSceneObject(pItem)
                                if requiredItems[j].itemTemplate == item:getTemplateObjectPath() and requiredItems[j].itemName == item:getCustomObjectName() then
@@ -790,7 +789,7 @@ function ThemeParkLogic:hasLootedRequiredItem(activeNpcNumber, pConversingPlayer
                        end
                end
        end
-       
+
        if unmatchedItems == 0 then
                for i = 1, # itemsToDestroy, 1 do
                        itemsToDestroy[i]:destroyObjectFromWorld()
@@ -805,7 +804,7 @@ end
 function ThemeParkLogic:getRequiredItem(activeNpcNumber, pConversingPlayer)
        local missionNumber = self:getCurrentMissionNumber(activeNpcNumber, pConversingPlayer)
        local mission = self:getMission(activeNpcNumber, missionNumber)
-       
+
        return mission.itemSpawns
 end
 
@@ -832,7 +831,7 @@ function ThemeParkLogic:completeMission(pConversingPlayer)
        if pConversingPlayer == nil then
                return
        end
-       
+
        local creature = LuaCreatureObject(pConversingPlayer)
 
        local npcNumber = self:getActiveNpcNumber(pConversingPlayer)
@@ -859,7 +858,7 @@ function ThemeParkLogic:handleMissionReward(pConversingPlayer)
        local missionNumber = self:getCurrentMissionNumber(npcNumber, pConversingPlayer)
        local mission = self:getMission(npcNumber, missionNumber)
        local rewards = mission.rewards
-       
+
        for i = 1, # rewards, 1 do
                local reward = rewards[i]
                if reward.rewardType == "credits" then
@@ -880,10 +879,10 @@ function ThemeParkLogic:givePermission(pConversingPlayer, permissionGroup)
        if pConversingPlayer == nil then
                return
        end
-       
+
        local creature = LuaCreatureObject(pConversingPlayer)
        local pGhost = creature:getPlayerObject()
-       
+
        if pGhost ~= nil then
                local ghost = LuaPlayerObject(pGhost)
                ghost:addPermissionGroup(permissionGroup, true)
@@ -894,10 +893,10 @@ function ThemeParkLogic:giveBadge(pConversingPlayer, badge)
        if pConversingPlayer == nil then
                return
        end
-       
+
        local creature = LuaCreatureObject(pConversingPlayer)
        local pGhost = creature:getPlayerObject()
-       
+
        if pGhost ~= nil then
                local ghost = LuaPlayerObject(pGhost)
                ghost:awardBadge(badge)
@@ -909,12 +908,12 @@ function ThemeParkLogic:giveLoot(pConversingPlayer, lootGroup)
                return
        end
        local creature = LuaCreatureObject(pConversingPlayer)
-       
+
        local pInventory = creature:getSlottedObject("inventory")
        if pInventory == nil then
                return
        end
-       
+
        createLoot(pInventory, lootGroup, 0, true)
        creature:sendSystemMessage("@theme_park/messages:theme_park_reward")
 end
@@ -924,7 +923,7 @@ function ThemeParkLogic:giveCredits(pConversingPlayer, amount)
                return
        end
        local creature = LuaCreatureObject(pConversingPlayer)
-       
+
        creature:addCashCredits(amount, true)
        creature:sendSystemMessageWithDI("@theme_park/messages:theme_park_credits_pp", amount)
 end
@@ -936,7 +935,7 @@ function ThemeParkLogic:giveFaction(pConversingPlayer, faction, points)
        local creature = LuaCreatureObject(pConversingPlayer)
        local pPlayerObject = creature:getSlottedObject("ghost")
        local playerObject = LuaPlayerObject(pPlayerObject)
-       
+
        playerObject:increaseFactionStanding(faction, points)
 end
 
@@ -945,12 +944,12 @@ function ThemeParkLogic:giveItem(pConversingPlayer, itemList)
                return
        end
        local creature = LuaCreatureObject(pConversingPlayer)
-       
+
        local pInventory = creature:getSlottedObject("inventory")
        if pInventory == nil then
                return
        end
-       
+
        for currentItem = 1, # itemList, 1 do
                local thisItem = itemList[currentItem]
                local itemTemplate = thisItem.itemTemplate
@@ -970,17 +969,17 @@ function ThemeParkLogic:cleanUpMission(pConversingPlayer)
        self:removeWaypoint(pConversingPlayer)
 
        local creature = LuaCreatureObject(pConversingPlayer)
-       
+
        local numberOfSpawns = readData(creature:getObjectID() .. ":missionSpawns")
        for i = 1, numberOfSpawns, 1 do
                local objectID = readData(creature:getObjectID() .. ":missionSpawn:no" .. i)
                local pNpc = getSceneObject(objectID)
-                       
+
                if pNpc ~= nil then
                        local npc = LuaSceneObject(pNpc)
                        npc:destroyObjectFromWorld()
                end
-       end     
+       end
 end
 
 function ThemeParkLogic:removeDeliverItem(pConversingPlayer)
@@ -989,18 +988,18 @@ function ThemeParkLogic:removeDeliverItem(pConversingPlayer)
        end
 
        local creature = LuaCreatureObject(pConversingPlayer)
-                       
+
        local pInventory = creature:getSlottedObject("inventory")
        if pInventory == nil then
                return false
        end
 
        local inventory = LuaSceneObject(pInventory)
-       
+
        local numberOfItems = readData(creature:getObjectID() .. ":missionItems")
        for i = 1, numberOfItems, 1 do
                local itemID = readData(creature:getObjectID() .. ":missionItem:no" .. i)
-                       
+
                local pItem = inventory:getContainerObjectById(itemID)
                if pItem ~= nil then
                        local item = LuaSceneObject(pItem)
@@ -1014,17 +1013,17 @@ function ThemeParkLogic:goToNextMission(pConversingPlayer)
        if pConversingPlayer == nil then
                return
        end
-       
+
        local npcNumber = self:getActiveNpcNumber(pConversingPlayer)
        local missionNumber = self:getCurrentMissionNumber(npcNumber, pConversingPlayer)
        local npcData = self:getNpcData(npcNumber)
-       local npcName = npcData.spawnData.npcTemplate   
-       
+       local npcName = npcData.spawnData.npcTemplate
+
        local creature = LuaCreatureObject(pConversingPlayer)
        writeData(creature:getObjectID() .. ":activeMission", 0)
        writeStringData(creature:getObjectID() .. ":activeScreenPlay", "")
        creature:setScreenPlayState(math.pow(2, missionNumber - 1), self.screenPlayState .. "_mission_" .. npcName)
-       
+
        if missionNumber == table.getn(npcData.missions) then
                creature:setScreenPlayState(npcNumber, self.screenPlayState)
        end
@@ -1041,11 +1040,11 @@ function ThemeParkLogic:getMissionType(activeNpcNumber, pConversingPlayer)
        if pConversingPlayer == nil then
                return
        end
-       
+
        local npcNumber = self:getActiveNpcNumber(pConversingPlayer)
        local missionNumber = self:getCurrentMissionNumber(npcNumber, pConversingPlayer)
        local mission = self:getMission(npcNumber, missionNumber)
-       
+
        return mission.missionType
 end
 
@@ -1056,16 +1055,16 @@ function ThemeParkLogic:escortedNpcCloseEnough(pConversingPlayer)
 
        local creature = LuaCreatureObject(pConversingPlayer)
        local playerSceneObject = LuaSceneObject(pConversingPlayer)
-       
+
        local objectID = readData(creature:getObjectID() .. ":missionSpawn:no1")
        local pNpc = getSceneObject(objectID)
-                       
+
        if pNpc ~= nil then
                if playerSceneObject:getDistanceTo(pNpc) < 64 then
                        return true
                end
        end
-       
+
        return false
 end
 
@@ -1073,10 +1072,10 @@ function ThemeParkLogic:resetCurrentMission(pConversingPlayer)
        if pConversingPlayer == nil then
                return
        end
-       
+
        local creature = LuaCreatureObject(pConversingPlayer)
        writeData(creature:getObjectID() .. ":activeMission", 0)
        writeStringData(creature:getObjectID() .. ":activeScreenPlay", "")
-       
+
        self:cleanUpMission(pConversingPlayer)
 end
old mode 100644 (file)
new mode 100755 (executable)
index 31d95c7..223e025
@@ -112,6 +112,18 @@ void DirectorManager::startGlobalScreenPlays() {
        }
 }
 
+void DirectorManager::setupLuaPackagePath(Lua* luaEngine) {
+       lua_State* L = luaEngine->getLuaState();
+       lua_getglobal(L, "package");
+       lua_getfield(L, -1, "path");
+       String currentPath = lua_tostring(L, -1);
+       currentPath = currentPath.concat(";scripts/?.lua");
+       lua_pop(L, 1);
+       lua_pushstring(L, currentPath.toCharArray());
+       lua_setfield(L, -2, "path");
+       lua_pop(L, 1);
+}
+
 void DirectorManager::initializeLuaEngine(Lua* luaEngine) {
        if (DEBUG_MODE)
                setLogging(true);
@@ -124,6 +136,8 @@ void DirectorManager::initializeLuaEngine(Lua* luaEngine) {
        luaEngine->setGlobalLogging(true);
        luaEngine->setLogging(true);
 
+       setupLuaPackagePath(luaEngine);
+
        lua_register(luaEngine->getLuaState(), "includeFile", includeFile);
        lua_register(luaEngine->getLuaState(), "createEvent", createEvent);
        lua_register(luaEngine->getLuaState(), "createObserver", createObserver);
@@ -1347,7 +1361,7 @@ int DirectorManager::spawnMobile(lua_State* L) {
                lua_pushnil(L);
        } else {
                creature->updateDirection(Math::deg2rad(heading));
-               
+
                if (creature->isAiAgent()) {
                        AiAgent* ai = cast<AiAgent*>(creature);
                        ai->setRespawnTimer(respawnTimer);
@@ -1717,11 +1731,11 @@ int DirectorManager::isZoneEnabled(lua_State* L) {
        }
 
        String zoneid = lua_tostring(L, -1);
-       
+
        Zone* zone = ServerCore::getZoneServer()->getZone(zoneid);
-       
+
        lua_pushboolean(L, (zone != NULL));
-       
+
        return 1;
 }
 
old mode 100644 (file)
new mode 100755 (executable)
index 4b6a6b0..6a474b5
@@ -126,6 +126,7 @@ namespace server {
                static int getCityRegionAt(lua_State* L);
 
        private:
+               void setupLuaPackagePath(Lua* luaEngine);
                void initializeLuaEngine(Lua* luaEngine);
                int loadScreenPlays(Lua* luaEngine);
                void loadJediManager(Lua* luaEngine);