Instructions Jenkins Doxygen

[Added] functionality to save the id of the spawned old man on the 67/967/1
authorLoshult <loshult@swgemu.com>
Sat, 19 Oct 2013 10:56:56 +0000 (10:56 +0000)
committerLoshult <loshult@swgemu.com>
Sun, 20 Oct 2013 05:19:28 +0000 (05:19 +0000)
player
[Fixed] getCityRegionAt not returning nil when no city region was found.
[Added] a player can now only converse with his old man.

Change-Id: I85f099673648c754cbf5acaec71e35761d24cfff

MMOCoreORB/bin/scripts/managers/jedi/village/old_man.lua
MMOCoreORB/bin/scripts/managers/jedi/village/old_man_conv_handler.lua
MMOCoreORB/bin/scripts/managers/jedi/village/tests/old_man_Test.lua
MMOCoreORB/bin/scripts/managers/jedi/village/village_jedi_manager.lua
MMOCoreORB/src/server/zone/managers/director/DirectorManager.cpp

index 554e8b5..cbceef6 100644 (file)
@@ -6,17 +6,30 @@ OLD_MAN_MAX_SPAWN_DISTANCE = 64
 OLD_MAN_TEMPLATE = "old_man"
 OLD_MAN_RESPAWN_TIME = 0
 OLD_MAN_HEADING = 0
+OLD_MAN_ID_STRING = ":old_man_id"
 
 OldMan = ScreenPlay:new {}
 
 -- Spawn the old man near the player.
 -- @pCreatureObject pointer to the creature object of the player.
 function OldMan.spawnOldMan(pCreatureObject)
-       OldMan.withSceneObject(pCreatureObject, function(sceneObject)
+       return OldMan.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
-                       spawnMobile(sceneObject:getZoneName(), OLD_MAN_TEMPLATE, OLD_MAN_RESPAWN_TIME, spawnPoint[1], spawnPoint[2], spawnPoint[3], OLD_MAN_HEADING, sceneObject:getParentID())
+                       return spawnMobile(sceneObject:getZoneName(), OLD_MAN_TEMPLATE, OLD_MAN_RESPAWN_TIME, spawnPoint[1], spawnPoint[2], spawnPoint[3], OLD_MAN_HEADING, sceneObject:getParentID())
                end
+               return nil
+       end)
+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(pCreatureObject, function(playerCreatureObject)
+               OldMan.withCreatureObject(pOldMan, function(oldManCreatureObject)
+                       writeData(playerCreatureObject:getObjectID() .. OLD_MAN_ID_STRING, oldManCreatureObject:getObjectID())
+               end)
        end)
 end
 
@@ -56,7 +69,12 @@ end
 function OldMan:handleSpawnOldManEvent(pCreatureObject)
        if OldMan.isPlayerOnline(pCreatureObject) and not OldMan.isPlayerInABuilding(pCreatureObject) and 
            not OldMan.isPlayerInNpcCity(pCreatureObject) then
-               OldMan.spawnOldMan(pCreatureObject)
+               local pOldMan = OldMan.spawnOldMan(pCreatureObject)
+               if pOldMan ~= nil then
+                       OldMan.saveOldManIdOnPlayer(pCreatureObject, pOldMan)
+               else
+                       OldMan.createSpawnOldManEvent(pCreatureObject)
+               end
        else
                OldMan.createSpawnOldManEvent(pCreatureObject)
        end
@@ -68,4 +86,16 @@ function OldMan.createSpawnOldManEvent(pCreatureObject)
        createEvent(20000, "OldMan", "handleSpawnOldManEvent", pCreatureObject)
 end
 
+-- Check if the old man belongs to the player or not.
+-- @param pConversingPlayer pointer to the creature object of the conversing player.
+-- @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(pConversingPlayer, function(playerCreatureObject)
+               return OldMan.withCreatureObject(pConversingNpc, function(oldManCreatureObject)
+                       return readData(playerCreatureObject:getObjectID() .. OLD_MAN_ID_STRING) == oldManCreatureObject:getObjectID()
+               end) == true
+       end) == true
+end
+
 return OldMan
index 2edab22..70682cb 100644 (file)
@@ -51,7 +51,7 @@ function old_man_conv_handler.handleInit(pConversationTemplate, pConversingPlaye
        local conversationTemplate = LuaConversationTemplate(pConversationTemplate)
        local nextScreen = "not_you"
 
-       if VillageJediManager.oldManBelongsToThePlayer(pConversingPlayer, pConversingNpc) then
+       if OldMan.oldManBelongsToThePlayer(pConversingPlayer, pConversingNpc) then
                if VillageJediManager.isGlowing(pConversingPlayer) then
                        nextScreen = "village_intro"
                elseif VillageJediManager.readyForMellichae(pConversingPlayer) then
index 41be41f..5b0177d 100644 (file)
@@ -3,6 +3,7 @@ require("old_man")
 
 describe("Old Man", function()
        local pCreatureObject = { "creatureObjectPointer" }
+       local pOldMan = { "oldManPointer" }
 
        describe("Interface methods", function()
                describe("createSpawnOldManEvent", function()
@@ -19,6 +20,69 @@ describe("Old Man", function()
                                end)
                        end)
                end)
+
+               describe("oldManBelongsToThePlayer", function()
+                       local playerId = 12345678
+                       local oldManId = 98765432
+                       local getObjectIDPlayerSpy
+                       local getObjectIDOldManSpy
+                       local creatureObjectPlayer
+                       local creatureObjectOldMan
+                       local realWithCreatureObject
+                       local realReadData
+
+                       setup(function()
+                               realWithCreatureObject = OldMan.withCreatureObject
+                               realReadData = readData
+                       end)
+
+                       teardown(function()
+                               OldMan.withCreatureObject = realWithCreatureObject
+                               readData = realReadData
+                       end)
+
+                       before_each(function()
+                               getObjectIDPlayerSpy = spy.new(function() return playerId end)
+                               getObjectIDOldManSpy = spy.new(function() return oldManId end)
+                               creatureObjectPlayer = { getObjectID = getObjectIDPlayerSpy }
+                               creatureObjectOldMan = { getObjectID = getObjectIDOldManSpy }
+                               OldMan.withCreatureObject = spy.new(function(pco, performThisFunction)
+                                       if pco == pCreatureObject then
+                                               return performThisFunction(creatureObjectPlayer)
+                                       elseif pco == pOldMan then
+                                               return performThisFunction(creatureObjectOldMan)
+                                       else
+                                               return nil
+                                       end
+                               end)
+                       end)
+
+                       describe("When called with a player and his old man", function()
+                               it("Should return true", function()
+                                       readData = spy.new(function() return oldManId end)
+
+                                       assert.is_true(OldMan.oldManBelongsToThePlayer(pCreatureObject, pOldMan))
+
+                                       assert.spy(OldMan.withCreatureObject).was.called(2)
+                                       assert.spy(getObjectIDPlayerSpy).was.called(1)
+                                       assert.spy(getObjectIDOldManSpy).was.called(1)
+                                       assert.spy(readData).was.called_with(playerId .. OLD_MAN_ID_STRING)
+                               end)
+                       end)
+
+                       describe("When called with a player and an old man of another player", function()
+                               it("Should return false", function()
+                                       readData = spy.new(function() return 0 end)
+
+                                       assert.is_false(OldMan.oldManBelongsToThePlayer(pCreatureObject, pOldMan))
+
+                                       assert.spy(OldMan.withCreatureObject).was.called(2)
+                                       assert.spy(getObjectIDPlayerSpy).was.called(1)
+                                       assert.spy(getObjectIDOldManSpy).was.called(1)
+                                       assert.spy(readData).was.called_with(playerId .. OLD_MAN_ID_STRING)
+                               end)
+                       end)
+               end)
        end)
 
        describe("Private methods", function()
@@ -29,6 +93,7 @@ describe("Old Man", function()
                                local realIsPlayerInNpcCity
                                local realSpawnOldMan
                                local realCreateSpawnOldManEvent
+                               local realSaveOldManIdOnPlayer
 
                                setup(function()
                                        realIsPlayerOnline = OldMan.isPlayerOnline
@@ -36,6 +101,7 @@ describe("Old Man", function()
                                        realIsPlayerInNpcCity = OldMan.isPlayerInNpcCity
                                        realSpawnOldMan = OldMan.spawnOldMan
                                        realCreateSpawnOldManEvent = OldMan.createSpawnOldManEvent
+                                       realSaveOldManIdOnPlayer = OldMan.saveOldManIdOnPlayer
                                end)
 
                                teardown(function()
@@ -44,14 +110,16 @@ describe("Old Man", function()
                                        OldMan.isPlayerInNpcCity = realIsPlayerInNpcCity
                                        OldMan.spawnOldMan = realSpawnOldMan
                                        OldMan.createSpawnOldManEvent = realCreateSpawnOldManEvent
+                                       OldMan.saveOldManIdOnPlayer = realSaveOldManIdOnPlayer
                                end)
 
                                before_each(function()                                  
                                        OldMan.isPlayerOnline = spy.new(function() return true end)
                                        OldMan.isPlayerInABuilding = spy.new(function() return false end)
                                        OldMan.isPlayerInNpcCity = spy.new(function() return false end)
-                                       OldMan.spawnOldMan = spy.new(function() end)
+                                       OldMan.spawnOldMan = spy.new(function() return pOldMan end)
                                        OldMan.createSpawnOldManEvent = spy.new(function() end)
+                                       OldMan.saveOldManIdOnPlayer = spy.new(function() end)
                                end)
 
                                it("Should spawn the old man if the player is online, not inside a building and outside all NPC cities.", function()
@@ -64,6 +132,12 @@ describe("Old Man", function()
                                        assert.spy(OldMan.createSpawnOldManEvent).was.not_called()
                                end)
 
+                               it("Should save the object id of the spawned old man on the player.", function()
+                                       OldMan:handleSpawnOldManEvent(pCreatureObject)
+
+                                       assert.spy(OldMan.saveOldManIdOnPlayer).was.called_with(pCreatureObject, pOldMan)
+                               end)
+
                                it("Should reschedule the event if the player is offline.", function()
                                        OldMan.isPlayerOnline = spy.new(function() return false end)
 
@@ -99,6 +173,18 @@ describe("Old Man", function()
                                        assert.spy(OldMan.spawnOldMan).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.spawnOldMan = spy.new(function() return nil end)
+
+                                       OldMan:handleSpawnOldManEvent(pCreatureObject)
+
+                                       assert.spy(OldMan.isPlayerOnline).was.called_with(pCreatureObject)
+                                       assert.spy(OldMan.isPlayerInABuilding).was.called_with(pCreatureObject)
+                                       assert.spy(OldMan.isPlayerInNpcCity).was.called_with(pCreatureObject)
+                                       assert.spy(OldMan.spawnOldMan).was.called_with(pCreatureObject)
+                                       assert.spy(OldMan.createSpawnOldManEvent).was.called_with(pCreatureObject)
+                               end)
                        end)
                end)
 
@@ -331,7 +417,7 @@ describe("Old Man", function()
                                        assert.same(pso, pCreatureObject)
                                        return performThisFunction(sceneObject)
                                end)
-                               spawnMobile = spy.new(function() end)
+                               spawnMobile = spy.new(function() return pOldMan end)
                        end)
 
                        after_each(function()
@@ -350,27 +436,74 @@ describe("Old Man", function()
                                end)
 
                                describe("and a spawn point is returned", function()
-                                       it("Should spawn the old man.", function()
+                                       before_each(function()
                                                getSpawnPoint = spy.new(function() return { 1, 2, 3 } end)
+                                       end)
 
+                                       it("Should spawn the old man.", function()
                                                OldMan.spawnOldMan(pCreatureObject)
 
                                                assert.spy(getZoneNameSpy).was.called(1)
                                                assert.spy(getParentIDSpy).was.called(1)
                                                assert.spy(spawnMobile).was.called_with("testzone", OLD_MAN_TEMPLATE, OLD_MAN_RESPAWN_TIME, 1, 2, 3, OLD_MAN_HEADING, 0)
                                        end)
+
+                                       it("Should return a pointer to the spawned old man.", function()
+                                               assert.same(OldMan.spawnOldMan(pCreatureObject), pOldMan)
+                                       end)
                                end)
 
                                describe("and no spawn point is returned", function()
-                                       it("Should not spawn the old man.", function()
+                                       before_each(function()
                                                getSpawnPoint = spy.new(function() return nil end)
+                                       end)
 
+                                       it("Should not spawn the old man.", function()
                                                OldMan.spawnOldMan(pCreatureObject)
 
                                                assert.spy(getZoneNameSpy).was.not_called()
                                                assert.spy(getParentIDSpy).was.not_called()
                                                assert.spy(spawnMobile).was.not_called()
                                        end)
+
+                                       it("Should return nil.", function()
+                                               assert.is_nil(OldMan.spawnOldMan(pCreatureObject))
+                                       end)
+                               end)
+                       end)
+               end)
+
+               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()
+                                       local playerId = 12345678
+                                       local oldManId = 98765432
+                                       local realWriteData = writeData
+                                       writeData = spy.new(function() end)
+                                       getObjectIDPlayerSpy = spy.new(function() return playerId end)
+                                       getObjectIDOldManSpy = spy.new(function() return oldManId end)
+                                       local creatureObjectPlayer = { getObjectID = getObjectIDPlayerSpy }
+                                       local creatureObjectOldMan = { getObjectID = getObjectIDOldManSpy }
+                                       local realWithCreatureObject = OldMan.withCreatureObject
+                                       OldMan.withCreatureObject = spy.new(function(pco, performThisFunction)
+                                               if pco == pCreatureObject then
+                                                       return performThisFunction(creatureObjectPlayer)
+                                               elseif pco == pOldMan then
+                                                       return performThisFunction(creatureObjectOldMan)
+                                               else
+                                                       return nil
+                                               end
+                                       end)                                    
+
+                                       OldMan.saveOldManIdOnPlayer(pCreatureObject, pOldMan)
+
+                                       assert.spy(writeData).was.called_with(playerId .. OLD_MAN_ID_STRING, oldManId)
+                                       assert.spy(OldMan.withCreatureObject).was.called(2)
+                                       assert.spy(getObjectIDPlayerSpy).was.called(1)
+                                       assert.spy(getObjectIDOldManSpy).was.called(1)
+
+                                       writeData = realWriteData
+                                       OldMan.withCreatureObject = realWithCreatureObject
                                end)
                        end)
                end)
index 004f786..7153ee9 100644 (file)
@@ -226,14 +226,6 @@ function VillageJediManager:onPlayerLoggedIn(pCreatureObject)
        VillageJediManager.registerObservers(pCreatureObject)
 end
 
--- Check if the old man belongs to the player or not.
--- @param pConversingPlayer pointer to the creature object of the conversing player.
--- @param pConversingNpc pointer to the creature object of the old man.
--- @return true if the old man belongs to the player.
-function VillageJediManager.oldManBelongsToThePlayer(pConversingPlayer, pConversingNpc)
-       return true
-end
-
 -- Check if the old man spawned due to the player becoming glowing and need access to the village.
 -- @param pCreatureObject pointer to the creature object of the player.
 -- @return true if the player is glowing and need access to the village.
index 7c4eba2..e4a2796 100644 (file)
@@ -154,6 +154,7 @@ void DirectorManager::initializeLuaEngine(Lua* luaEngine) {
        lua_register(luaEngine->getLuaState(), "getGCWDiscount", getGCWDiscount);
        lua_register(luaEngine->getLuaState(), "getTerrainHeight", getTerrainHeight);
        lua_register(luaEngine->getLuaState(), "awardSkill", awardSkill);
+       lua_register(luaEngine->getLuaState(), "getCityRegionAt", getCityRegionAt);
 
        luaEngine->setGlobalInt("POSITIONCHANGED", ObserverEventType::POSITIONCHANGED);
        luaEngine->setGlobalInt("CLOSECONTAINER", ObserverEventType::CLOSECONTAINER);
@@ -1887,7 +1888,11 @@ int DirectorManager::getCityRegionAt(lua_State* L) {
 
        CityRegion* cityRegion = planetManager->getRegionAt(x, y);
 
-       lua_pushlightuserdata(L, cityRegion);
+       if (cityRegion != NULL) {
+               lua_pushlightuserdata(L, cityRegion);
+       } else {
+               lua_pushnil(L);
+       }
 
        return 1;
 }