Instructions Jenkins Doxygen

[Added] despawn of old man after conversation has ended. 26/1026/1
authorLoshult <loshult@swgemu.com>
Tue, 29 Oct 2013 21:12:14 +0000 (21:12 +0000)
committerLoshult <loshult@swgemu.com>
Tue, 29 Oct 2013 21:12:14 +0000 (21:12 +0000)
Change-Id: I0344aa8d3a52ab1aa5190251f09f6a8e54284d1d

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

index 6bca28f..d7090be 100644 (file)
@@ -10,10 +10,11 @@ OLD_MAN_ID_STRING = ":old_man_id"
 OLD_MAN_EVENT_SCHEDULED_STRING = "old_man_event_scheduled"
 OLD_MAN_NOT_SCHEDULED = 0
 OLD_MAN_SCHEDULED = 1
+OLD_MAN_SPAWNED = 2
 --OLD_MAN_SPAWN_TIME = 12 * 60 * 60 * 1000 -- 12 hours as base
 OLD_MAN_DESPAWN_TIME = 5 * 60 * 1000 -- 5 minutes
-OLD_MAN_SPAWN_TIME = 2 * 60 * 1000 -- 12 minutes as base for testing
---OLD_MAN_SPAWN_TIME = 12 * 1000 -- 12 seconds as base for testing
+--OLD_MAN_SPAWN_TIME = 12 * 60 * 1000 -- 12 minutes as base for testing
+OLD_MAN_SPAWN_TIME = 12 * 1000 -- 12 seconds as base for testing
 --OLD_MAN_DESPAWN_TIME = 30 * 1000 -- 30 seconds as base for testing
 OLD_MAN_STOP_FOLLOW_TIME = 15 * 1000 -- 15 seconds
 OLD_MAN_SPATIAL_CHAT_TIME = 5 * 1000 -- 5 seconds
@@ -37,7 +38,7 @@ 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.readPersistentDataFromThePlayer(pCreatureObject, key)
+function OldMan.getScreenPlayStateFromPlayer(pCreatureObject, key)
        return OldMan.withCreatureObject(pCreatureObject, function(creatureObject)
                return creatureObject:getScreenPlayState(key)
        end)
@@ -64,12 +65,22 @@ 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.writePersistentDataToThePlayer(pCreatureObject, key, value)
+function OldMan.setScreenPlayStateOnPlayer(pCreatureObject, key, value)
        OldMan.withCreatureObject(pCreatureObject, function(creatureObject)
                creatureObject:setScreenPlayState(value, key)
        end)
 end
 
+-- Clear persistent data to the player.
+-- @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)
+               creatureObject:removeScreenPlayState(value, key)
+       end)
+end
+
 -- Write transient data to the player.
 -- @param pCreatureObject pointer to the creature object of the player.
 -- @param key the key to write the value to.
@@ -194,6 +205,13 @@ function OldMan:handleDespawnEvent(pCreatureObject)
        OldMan.createSpawnOldManEvent(pCreatureObject)
 end
 
+-- Schedule despawn of the old man.
+-- @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)
+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.
@@ -204,7 +222,7 @@ function OldMan.tryToSpawnOldMan(pCreatureObject)
                OldMan.setToFollow(pOldMan, pCreatureObject)
                createEvent(OLD_MAN_STOP_FOLLOW_TIME, "OldMan", "handleStopFollowPlayerEvent", pCreatureObject)
                createEvent(OLD_MAN_SPATIAL_CHAT_TIME, "OldMan", "handleSpatialChatEvent", pCreatureObject)
-               createEvent(OLD_MAN_DESPAWN_TIME, "OldMan", "handleDespawnEvent", pCreatureObject)
+               OldMan.scheduleDespawnOfOldMan(pCreatureObject, OLD_MAN_DESPAWN_TIME)
                return true
        else
                return false
@@ -214,7 +232,7 @@ 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.writePersistentDataToThePlayer(pCreatureObject, OLD_MAN_EVENT_SCHEDULED_STRING, OLD_MAN_NOT_SCHEDULED)
+       OldMan.removeScreenPlayStateOnPlayer(pCreatureObject, OLD_MAN_EVENT_SCHEDULED_STRING, OLD_MAN_SCHEDULED)
        if OldMan.canOldManBeSpawned(pCreatureObject) then
                if not OldMan.tryToSpawnOldMan(pCreatureObject) then
                        OldMan.createSpawnOldManEvent(pCreatureObject)
@@ -228,14 +246,14 @@ end
 -- @param pCreatureObject pointer to the creature object of the player.
 -- return true if an event is already scheduled.
 function OldMan.hasOldManSpawnEventScheduled(pCreatureObject)
-       return OldMan.readPersistentDataFromThePlayer(pCreatureObject, OLD_MAN_EVENT_SCHEDULED_STRING) == OLD_MAN_SCHEDULED
+       return OldMan.getScreenPlayStateFromPlayer(pCreatureObject, OLD_MAN_EVENT_SCHEDULED_STRING) == OLD_MAN_SCHEDULED
 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 not OldMan.hasOldManSpawnEventScheduled(pCreatureObject) then
-               OldMan.writePersistentDataToThePlayer(pCreatureObject, OLD_MAN_EVENT_SCHEDULED_STRING, OLD_MAN_SCHEDULED)
+               OldMan.setScreenPlayStateOnPlayer(pCreatureObject, OLD_MAN_EVENT_SCHEDULED_STRING, OLD_MAN_SCHEDULED)
                createEvent(true, OLD_MAN_SPAWN_TIME + math.random(OLD_MAN_SPAWN_TIME), "OldMan", "handleSpawnOldManEvent", pCreatureObject)
        end
 end
index 70682cb..0d06398 100644 (file)
@@ -1,3 +1,5 @@
+OLD_MAN_CONVERSATION_ENDED_DESPAWN_TIME = 10 * 1000 -- 10 seconds
+
 old_man_conv_handler = Object:new {
 }
  
@@ -42,6 +44,8 @@ function old_man_conv_handler:runScreenHandlers(pConversationTemplate, pConversi
 
        if screenID == "init" then
                pConversationScreen = old_man_conv_handler.handleInit(pConversationTemplate, pConversingPlayer, pConversingNpc, selectedOption, pConversationScreen)
+       elseif screenID == "village_give_crystal" or screenID == "village_another_time" or screenID == "village_another_time2" or screenID == "mellichae_later" then
+               OldMan.scheduleDespawnOfOldMan(pConversingPlayer, OLD_MAN_CONVERSATION_ENDED_DESPAWN_TIME)
        end
 
        return pConversationScreen
index 41f1061..621e4ab 100644 (file)
@@ -38,42 +38,43 @@ describe("Old Man", function()
                readData = spy.new(function() return oldManId end)
                spawnMobile = spy.new(function() return pOldMan end)
 
-               creatureObjectPlayer = { getFirstName = nil, getObjectID = nil, getPlayerObject = nil, getScreenPlayState = nil, setScreenPlayState = nil }
+               creatureObjectPlayer = {}
                creatureObjectPlayer.getFirstName = spy.new(function() return playerFirstName end)
                creatureObjectPlayer.getObjectID = spy.new(function() return playerId end)
                creatureObjectPlayer.getPlayerObject = spy.new(function() return pPlayerObject end)
                creatureObjectPlayer.getScreenPlayState = spy.new(function() return 0 end)
                creatureObjectPlayer.setScreenPlayState = spy.new(function() end)
+               creatureObjectPlayer.removeScreenPlayState = spy.new(function() end)
                DirectorManagerMocks.creatureObjects[pCreatureObject] = creatureObjectPlayer
                
-               creatureObjectOldMan = { getObjectID = nil }
+               creatureObjectOldMan = {}
                creatureObjectOldMan.getObjectID = spy.new(function() return oldManId end)
                DirectorManagerMocks.creatureObjects[pOldMan] = creatureObjectOldMan
 
-               sceneObjectPlayer = { getParentID = nil, getZoneName = nil, getWorldPositionX = nil, getWorldPositionY = nil }
+               sceneObjectPlayer = {}
                sceneObjectPlayer.getParentID = spy.new(function() return 0 end)
                sceneObjectPlayer.getZoneName = spy.new(function() return "testzone" end)
                sceneObjectPlayer.getWorldPositionX = spy.new(function() return 33 end)
                sceneObjectPlayer.getWorldPositionY = spy.new(function() return 22 end)
                DirectorManagerMocks.sceneObjects[pCreatureObject] = sceneObjectPlayer
                
-               sceneObjectOldMan = { destroyObjectFromWorld = nil }
+               sceneObjectOldMan = {}
                sceneObjectOldMan.destroyObjectFromWorld = spy.new(function() end)
                DirectorManagerMocks.sceneObjects[pOldMan] = sceneObjectOldMan          
 
-               playerObject = { isOnline = nil }
+               playerObject = {}
                playerObject.isOnline = spy.new(function() return true end)
                DirectorManagerMocks.playerObjects[pPlayerObject] = playerObject
 
-               cityRegion = { isClientRegion = nil }
+               cityRegion = {}
                cityRegion.isClientRegion = spy.new(function() return false end)
                DirectorManagerMocks.cityRegions[pCityRegion] = cityRegion
                
-               aiAgent = { setFollowObject = nil }
+               aiAgent = {}
                aiAgent.setFollowObject = spy.new(function() end)
                DirectorManagerMocks.aiAgents[pOldMan] = aiAgent
                
-               greetingStringId = { _getObject = nil, setTT = nil }
+               greetingStringId = {}
                greetingStringId._getObject = spy.new(function() return pGreetingStringId end)
                greetingStringId.setTT = spy.new(function(object, string) assert.same(string, playerFirstName) end)
                DirectorManagerMocks.stringIds[OLD_MAN_GREETING_STRING] = greetingStringId