Instructions Jenkins Doxygen

[Added] Player will lose the force crystal if he is killed by the sith 95/1395/3
authorLoshult <loshult@swgemu.com>
Tue, 18 Feb 2014 19:56:50 +0000 (19:56 +0000)
committerLoshult <loshult@swgemu.com>
Tue, 18 Feb 2014 20:44:47 +0000 (20:44 +0000)
shadows.
[Changed] Encounter start time for old man and sith shadows increased.
[Changed] Minimum spawn distance for old man and sith shadows increased.

Change-Id: I85c95fbb16ec3846306224b8109bd91fbf466a24

MMOCoreORB/bin/scripts/managers/jedi/village/mocks/old_man_encounter_mocks.lua
MMOCoreORB/bin/scripts/managers/jedi/village/old_man_encounter.lua
MMOCoreORB/bin/scripts/managers/jedi/village/sith_shadow_encounter.lua
MMOCoreORB/bin/scripts/managers/jedi/village/tests/old_man_encounter_Test.lua
MMOCoreORB/bin/scripts/managers/jedi/village/tests/sith_shadow_encounter_Test.lua

index a52a7f7..8d102cb 100644 (file)
@@ -4,32 +4,36 @@ local realStart
 local realDoesOldManBelongToThePlayer
 local realScheduleDespawnOfOldMan
 local realGiveForceCrystalToPlayer
+local realRemoveForceCrystalFromPlayer
 
-local OldManMocks = OldManEncounter
-OldManMocks.mocks = {}
+local OldManEncounterMocks = OldManEncounter
+OldManEncounterMocks.mocks = {}
 
-function OldManMocks.mocks.setup()
+function OldManEncounterMocks.mocks.setup()
        realStart = OldManEncounter.createSpawnOldManEvent
        realDoesOldManBelongToThePlayer = OldManEncounter.doesOldManBelongToThePlayer
        realScheduleDespawnOfOldMan = OldManEncounter.scheduleDespawnOfOldMan
        realGiveForceCrystalToPlayer = OldManEncounter.giveForceCrystalToPlayer
+       realRemoveForceCrystalFromPlayer = OldManEncounter.removeForceCrystalFromPlayer
 end
 
-function OldManMocks.mocks.teardown()
+function OldManEncounterMocks.mocks.teardown()
        OldManEncounter.createSpawnOldManEvent = realStart
        OldManEncounter.doesOldManBelongToThePlayer = realDoesOldManBelongToThePlayer
        OldManEncounter.scheduleDespawnOfOldMan = realScheduleDespawnOfOldMan
        OldManEncounter.giveForceCrystalToPlayer = realGiveForceCrystalToPlayer
+       OldManEncounter.removeForceCrystalFromPlayer = realRemoveForceCrystalFromPlayer
 end
 
-function OldManMocks.mocks.before_each()
+function OldManEncounterMocks.mocks.before_each()
        OldManEncounter.start = spy.new(function() end)
        OldManEncounter.doesOldManBelongToThePlayer = spy.new(function() return false end)
        OldManEncounter.scheduleDespawnOfOldMan = spy.new(function() end)
        OldManEncounter.giveForceCrystalToPlayer = spy.new(function() end)
+       OldManEncounter.removeForceCrystalFromPlayer = spy.new(function() end)
 end
 
-function OldManMocks.mocks.after_each()
+function OldManEncounterMocks.mocks.after_each()
 end
 
-return OldManMocks
+return OldManEncounterMocks
index cfc914a..8092814 100644 (file)
@@ -16,12 +16,12 @@ OldManEncounter = Encounter:new {
        -- Encounter properties
        --minimumTimeUntilEncounter = 12 * 60 * 60 * 1000, -- 12 hours
        --maximumTimeUntilEncounter = 24 * 60 * 60 * 1000, -- 24 hours
-       minimumTimeUntilEncounter = 12 * 1000, -- 12 hours
-       maximumTimeUntilEncounter = 24 * 1000, -- 24 hours
+       minimumTimeUntilEncounter = 30 * 1000, -- 12 hours
+       maximumTimeUntilEncounter = 60 * 1000, -- 24 hours
        --encounterDespawnTime = 5 * 60 * 1000, -- 5 minutes
        encounterDespawnTime = 60 * 1000, -- 5 minutes
        spawnObjectList = {
-               { template = "old_man", minimumDistance = 32, maximumDistance = 64, referencePoint = 0, followPlayer = true }
+               { template = "old_man", minimumDistance = 64, maximumDistance = 96, referencePoint = 0, followPlayer = true }
        },
        onEncounterSpawned = nil,
        isEncounterFinished = nil,
@@ -95,6 +95,29 @@ function OldManEncounter:giveForceCrystalToPlayer(pCreatureObject)
        end)
 end
 
+-- Remove the force crystal from the player.
+-- @param pCreatureObject pointer to the creature object of the player.
+function OldManEncounter:removeForceCrystalFromPlayer(pCreatureObject)
+       Logger:log("Removing crystal from player.", LT_INFO)
+       local forceCrystalId = ObjectManager.withCreatureObject(pCreatureObject, function(creatureObject)
+               return creatureObject:getScreenPlayState(self.taskName .. OLD_MAN_FORCE_CRYSTAL_ID_STRING)
+       end)
+       local pForceCrystal = getSceneObject(forceCrystalId)
+
+       if pForceCrystal ~= nil then
+               ObjectManager.withSceneObject(pForceCrystal, function(forceCrystal)
+                       forceCrystal:destroyObjectFromWorld()
+               end)
+       end
+
+       ObjectManager.withCreatureObject(pCreatureObject, function(creatureObject)
+               return creatureObject:removeScreenPlayState(0xFFFFFFFFFFFFFFFF, self.taskName .. OLD_MAN_FORCE_CRYSTAL_ID_STRING)
+       end)
+
+       QuestManager.resetQuest(pCreatureObject, QuestManager.quests.OLD_MAN_INITIAL)
+       QuestManager.resetQuest(pCreatureObject, QuestManager.quests.OLD_MAN_FORCE_CRYSTAL)
+end
+
 -- Check if the player is conversing with the old man that is spawned for the player
 -- @param pConversingPlayer pointer to the creature object of the player.
 -- @param pConversingOldMan pointer to the creature object of the conversing old man.
index c538dce..0d16f6a 100644 (file)
@@ -10,12 +10,12 @@ SithShadowEncounter = Encounter:new {
        -- Encounter properties
        --minimumTimeUntilEncounter = 12 * 60 * 60 * 1000, -- 12 hours
        --maximumTimeUntilEncounter = 24 * 60 * 60 * 1000, -- 24 hours
-       minimumTimeUntilEncounter = 12 * 1000, -- 12 hours
-       maximumTimeUntilEncounter = 24 * 1000, -- 24 hours
+       minimumTimeUntilEncounter = 30 * 1000, -- 12 hours
+       maximumTimeUntilEncounter = 60 * 1000, -- 24 hours
        --encounterDespawnTime = 5 * 60 * 1000, -- 5 minutes
        encounterDespawnTime = 60 * 1000, -- 5 minutes
        spawnObjectList = {
-               { template = "sith_shadow", minimumDistance = 32, maximumDistance = 64, referencePoint = 0, followPlayer = true },
+               { template = "sith_shadow", minimumDistance = 64, maximumDistance = 96, referencePoint = 0, followPlayer = true },
                { template = "sith_shadow", minimumDistance = 4, maximumDistance = 8, referencePoint = 1, followPlayer = true }
        },
        onEncounterSpawned = nil,
@@ -24,11 +24,11 @@ SithShadowEncounter = Encounter:new {
        onEncounterAtPlayer = nil
 }
 
--- Check if the sith shadow belongs to the player.
+-- Check if the sith shadow is the first one spawned for the player.
 -- @param pSithShadow pointer to the sith shadow.
 -- @param pCreatureObject pointer to the creature object of the player.
--- @return true if the sith shadow belongs to the encounter of the player.
-function SithShadowEncounter:isSithShadowOwnedByPlayer(pSithShadow, pCreatureObject)
+-- @return true if the sith shadow is the first one spawned for the player.
+function SithShadowEncounter:isTheFirstSithShadowOfThePlayer(pSithShadow, pCreatureObject)
        local spawnedSithShadows = SpawnMobiles.getSpawnedMobiles(pCreatureObject, self.taskName)
 
        if spawnedSithShadows ~= nil then
@@ -56,8 +56,8 @@ end
 -- @param nothing unused variable for the default footprint of event handlers.
 -- @return 1 if the correct player looted the creature to remove the observer, 0 otherwise to keep the observer.
 function SithShadowEncounter:onLoot(pLootedCreature, pLooter, nothing)
-       Logger:log("Looting", LT_INFO)
-       if self:isSithShadowOwnedByPlayer(pLootedCreature, pLooter) then
+       Logger:log("Looting the sith shadow.", LT_INFO)
+       if self:isTheFirstSithShadowOfThePlayer(pLootedCreature, pLooter) then
                self:addWaypointDatapadAsLoot(pLootedCreature)
                return 1
        end
@@ -65,13 +65,37 @@ function SithShadowEncounter:onLoot(pLootedCreature, pLooter, nothing)
        return 0
 end
 
+-- Handle the event PLAYERKILLED.
+-- @param pCreatureObject pointer to the creature object of the killed player.
+-- @param pKiller pointer to the creature object of the killer.
+-- @param noting unused variable for the default footprint of event handlers.
+-- @return 1 if the player was killed by one of the sith shadows, otherwise 0 to keep the observer.
+function SithShadowEncounter:onPlayerKilled(pCreatureObject, pKiller, nothing)
+       Logger:log("Player was killed.", LT_INFO)
+       if SpawnMobiles.isFromSpawn(pCreatureObject, SithShadowEncounter.taskName, pKiller) then
+               OldManEncounter:removeForceCrystalFromPlayer(pCreatureObject)
+               OldManEncounter:start(pCreatureObject)
+               return 1
+       end
+
+       return 0
+end
+
 -- Handling of the encounter spawned event.
 -- Register observer for looting one of the sith shadows.
 -- @param pCreatureObject pointer to the creature object of the player who has this encounter.
 -- @param spawnedObject list of pointers to the spawned sith shadows.
 function SithShadowEncounter:onEncounterSpawned(pCreatureObject, spawnedObjects)
-       Logger:log("Register loot observer", LT_INFO)
-       createObserver(LOOTCREATURE, "SithShadowEncounter", "onLoot", spawnedObjects[1])
+       Logger:log("Register Sith Shadow Encounter observers.", LT_INFO)
+       createObserver(LOOTCREATURE, self.taskName, "onLoot", spawnedObjects[1])
+       createObserver(OBJECTDESTRUCTION, self.taskName, "onPlayerKilled", pCreatureObject)
+end
+
+-- Check if the sith shadow encounter is finished or not.
+-- @param pCreatureObject pointer to the creature object of the player.
+-- @return true if the encounter is finished. I.e. the player has access to the village or lost the crystal.
+function SithShadowEncounter:isEncounterFinished(pCreatureObject)
+       return not QuestManager.hasCompletedQuest(pCreatureObject, QuestManager.quests.OLD_MAN_FORCE_CRYSTAL)
 end
 
 return SithShadowEncounter
index 6df682c..0d32fd5 100644 (file)
@@ -57,6 +57,7 @@ describe("OldManEncounter", function()
                creatureObjectPlayer.getSlottedObject = spy.new(function() return pPlayerInventory end)
                creatureObjectPlayer.removeScreenPlayState = spy.new(function() end)
                creatureObjectPlayer.setScreenPlayState = spy.new(function() end)
+               creatureObjectPlayer.getScreenPlayState = spy.new(function() end)
                DirectorManagerMocks.creatureObjects[pCreatureObject] = creatureObjectPlayer
 
                creatureObjectConversingOldMan = {}
@@ -74,6 +75,7 @@ describe("OldManEncounter", function()
 
                forceCrystal = {}
                forceCrystal.getObjectID = spy.new(function() return forceCrystalId end)
+               forceCrystal.destroyObjectFromWorld = spy.new(function() end)
                DirectorManagerMocks.sceneObjects[pForceCrystal] = forceCrystal
        end)
 
@@ -89,11 +91,11 @@ describe("OldManEncounter", function()
                        it("Should have template equal to old_man.", function()
                                assert.same("old_man", OldManEncounter.spawnObjectList[1]["template"])
                        end)
-                       it("Should have minimumDistance equal to 32.", function()
-                               assert.same(32, OldManEncounter.spawnObjectList[1]["minimumDistance"])
+                       it("Should have minimumDistance equal to 64.", function()
+                               assert.same(64, OldManEncounter.spawnObjectList[1]["minimumDistance"])
                        end)
-                       it("Should have maximumDistance equal to 64.", function()
-                               assert.same(64, OldManEncounter.spawnObjectList[1]["maximumDistance"])
+                       it("Should have maximumDistance equal to 96.", function()
+                               assert.same(96, OldManEncounter.spawnObjectList[1]["maximumDistance"])
                        end)
                        it("Should have referencePoint equal to 0.", function()
                                assert.same(0, OldManEncounter.spawnObjectList[1]["referencePoint"])
@@ -217,6 +219,61 @@ describe("OldManEncounter", function()
                        end)
                end)
 
+               describe("removeForceCrystalFromPlayer", function()
+                       describe("When called with a player", function()
+                               local realGetSceneObject
+
+                               setup(function()
+                                       realGetSceneObject = getSceneObject
+                               end)
+
+                               teardown(function()
+                                       getSceneObject = realGetSceneObject
+                               end)
+
+                               before_each(function()
+                                       getSceneObject = spy.new(function() return pForceCrystal end)
+                                       creatureObjectPlayer.getScreenPlayState = spy.new(function() return forceCrystalId end)
+                               end)
+
+                               it("Should read the force crystal id from the player.", function()
+                                       OldManEncounter:removeForceCrystalFromPlayer(pCreatureObject)
+
+                                       assert.spy(creatureObjectPlayer.getScreenPlayState).was.called_with(creatureObjectPlayer, OldManEncounter.taskName .. OLD_MAN_FORCE_CRYSTAL_ID_STRING)
+                               end)
+
+                               it("Should get a pointer to the scene object of the force crystal.", function()
+                                       OldManEncounter:removeForceCrystalFromPlayer(pCreatureObject)
+
+                                       assert.spy(getSceneObject).was.called_with(forceCrystalId)
+                               end)
+
+                               describe("and the force crystal exists.", function()
+                                       before_each(function()
+                                               getSceneObject = spy.new(function() return pForceCrystal end)
+                                       end)
+
+                                       it("Should delete the force crystal from the world.", function()
+                                               OldManEncounter:removeForceCrystalFromPlayer(pCreatureObject)
+
+                                               assert.spy(forceCrystal.destroyObjectFromWorld).was.called(1)
+                                       end)
+                               end)
+
+                               it("Should clear the force crystal id from the player.", function()
+                                       OldManEncounter:removeForceCrystalFromPlayer(pCreatureObject)
+
+                                       assert.spy(creatureObjectPlayer.removeScreenPlayState).was.called_with(creatureObjectPlayer, 0xFFFFFFFFFFFFFFFF, OldManEncounter.taskName .. OLD_MAN_FORCE_CRYSTAL_ID_STRING)
+                               end)
+
+                               it("Should reset the old man initial and the old man force crystal quests.", function()
+                                       OldManEncounter:removeForceCrystalFromPlayer(pCreatureObject)
+
+                                       assert.spy(QuestManagerMocks.resetQuest).was.called(2)
+                               end)
+                       end)
+               end)
+
                describe("doesOldManBelongToThePlayer", function()
                        describe("When called with a player and his old man", function()
                                it("Should get a list with pointer to the spawned old man for the player.", function()
index 89325b2..2fc5cce 100644 (file)
@@ -1,6 +1,8 @@
 local SithShadowEncounter = require("managers.jedi.village.sith_shadow_encounter")
 local DirectorManagerMocks = require("screenplays.mocks.director_manager_mocks")
+local QuestManagerMocks = require("managers.quest.mocks.quest_manager_mocks")
 local SpawnMobilesMocks = require("utils.mocks.spawn_mobiles_mocks")
+local OldManEncounterMocks = require("managers.jedi.village.mocks.old_man_encounter_mocks")
 
 LOOTCREATURE = 53
 
@@ -22,16 +24,22 @@ describe("Sith Shadow Encounter", function()
        setup(function()
                DirectorManagerMocks.mocks.setup()
                SpawnMobilesMocks.mocks.setup()
+               OldManEncounterMocks.mocks.setup()
+               QuestManagerMocks.mocks.setup()
        end)
 
        teardown(function()
                DirectorManagerMocks.mocks.teardown()
                SpawnMobilesMocks.mocks.teardown()
+               OldManEncounterMocks.mocks.teardown()
+               QuestManagerMocks.mocks.teardown()
        end)
 
        before_each(function()
                DirectorManagerMocks.mocks.before_each()
                SpawnMobilesMocks.mocks.before_each()
+               OldManEncounterMocks.mocks.before_each()
+               QuestManagerMocks.mocks.before_each()
 
                creatureObject = {}
                DirectorManagerMocks.creatureObjects[pCreatureObject] = creatureObject
@@ -53,6 +61,12 @@ describe("Sith Shadow Encounter", function()
 
                                assert.spy(createObserver).was.called_with(LOOTCREATURE, SithShadowEncounter.taskName, "onLoot", pFirstSithShadow)
                        end)
+
+                       it("Should register an observer for OBJECTDESTRUCTION on the player.", function()
+                               SithShadowEncounter:onEncounterSpawned(pCreatureObject, spawnedSithShadowList)
+
+                               assert.spy(createObserver).was.called_with(OBJECTDESTRUCTION, SithShadowEncounter.taskName, "onPlayerKilled", pCreatureObject)
+                       end)
                end)
        end)
 
@@ -87,6 +101,10 @@ describe("Sith Shadow Encounter", function()
 
                                                assert.spy(createLoot).was.called_with(pInventory, "sith_shadow_encounter_datapad", 0, true)
                                        end)
+
+                                       it("Should return 1 to remove the observer.", function()
+                                               assert.same(1, SithShadowEncounter:onLoot(pFirstSithShadow, pCreatureObject, 0))
+                                       end)
                                end)
 
                                describe("and both ids are not identical", function()
@@ -95,6 +113,10 @@ describe("Sith Shadow Encounter", function()
 
                                                assert.spy(createLoot).was.not_called()
                                        end)
+
+                                       it("Should return 0 to keep the observer.", function()
+                                               assert.same(0, SithShadowEncounter:onLoot(pSecondSithShadow, pCreatureObject, 0))
+                                       end)
                                end)
                        end)
 
@@ -108,6 +130,102 @@ describe("Sith Shadow Encounter", function()
 
                                        assert.spy(createLoot).was.not_called()
                                end)
+
+                               it("Should return 0 to keep the observer.", function()
+                                       assert.same(0, SithShadowEncounter:onLoot(pFirstSithShadow, pCreatureObject, 0))
+                               end)
+                       end)
+               end)
+       end)
+
+       describe("onPlayerKilled", function()
+               local realFinish
+
+               setup(function()
+                       realFinish = SithShadowEncounter.finish
+               end)
+
+               teardown(function()
+                       SithShadowEncounter.finish = realFinish
+               end)
+
+               before_each(function()
+                       SithShadowEncounter.finish = spy.new(function() end)
+               end)
+
+               it("Should check if the killer is from the sith shadow spawn of the player.", function()
+                       SithShadowEncounter:onPlayerKilled(pCreatureObject, pFirstSithShadow, 0)
+
+                       assert.spy(SpawnMobilesMocks.isFromSpawn).was.called_with(pCreatureObject, SithShadowEncounter.taskName, pFirstSithShadow)
+               end)
+
+               describe("and the killer is one of the sith shadows of the player", function()
+                       before_each(function()
+                               SpawnMobilesMocks.isFromSpawn = spy.new(function() return true end)
+                       end)
+
+                       it("Should remove the crystal from the player.", function()
+                               SithShadowEncounter:onPlayerKilled(pCreatureObject, pFirstSithShadow, 0)
+
+                               assert.spy(OldManEncounterMocks.removeForceCrystalFromPlayer).was.called_with(OldManEncounterMocks, pCreatureObject)
+                       end)
+
+                       it("Should restart the old man encounter.", function()
+                               SithShadowEncounter:onPlayerKilled(pCreatureObject, pFirstSithShadow, 0)
+
+                               assert.spy(OldManEncounterMocks.start).was.called_with(OldManEncounterMocks, pCreatureObject)
+                       end)
+
+                       it("Should return 1 to remove the observer.", function()
+                               assert.same(1, SithShadowEncounter:onPlayerKilled(pCreatureObject, pFirstSithShadow, 0))
+                       end)
+               end)
+
+               describe("and the killer is not one of the sith shadows of the player", function()
+                       it("Should not remove the crystal from the player.", function()
+                               SithShadowEncounter:onPlayerKilled(pCreatureObject, pFirstSithShadow, 0)
+
+                               assert.spy(OldManEncounterMocks.removeForceCrystalFromPlayer).was.not_called()
+                       end)
+
+                       it("Should not restart the old man encounter.", function()
+                               SithShadowEncounter:onPlayerKilled(pCreatureObject, pFirstSithShadow, 0)
+
+                               assert.spy(OldManEncounterMocks.start).was.not_called()
+                       end)
+
+                       it("Should return 0 to keep the observer.", function()
+                               assert.same(0, SithShadowEncounter:onPlayerKilled(pCreatureObject, pFirstSithShadow, 0))
+                       end)
+               end)
+       end)
+
+       describe("isEncounterFinished", function()
+               describe("When called with a player object", function()
+                       it("Should check if the player has the force crystal or not.", function()
+                               SithShadowEncounter:isEncounterFinished(pCreatureObject)
+
+                               assert.spy(QuestManagerMocks.hasCompletedQuest).was.called(1)
+                       end)
+
+                       describe("and the player has lost the force crystal", function()
+                               before_each(function()
+                                       QuestManagerMocks.hasCompletedQuest = spy.new(function() return false end)
+                               end)
+
+                               it("Should return true", function()
+                                       assert.is_true(SithShadowEncounter:isEncounterFinished(pCreatureObject))
+                               end)
+                       end)
+
+                       describe("and the player has not lost the force crystal", function()
+                               before_each(function()
+                                       QuestManagerMocks.hasCompletedQuest = spy.new(function() return true end)
+                               end)
+
+                               it("Should return false", function()
+                                       assert.is_false(SithShadowEncounter:isEncounterFinished(pCreatureObject))
+                               end)
                        end)
                end)
        end)