Instructions Jenkins Doxygen

[Changed] sith shadows to only give the waypoint datapad as loot if 24/1324/2
authorLoshult <loshult@swgemu.com>
Fri, 10 Jan 2014 12:50:05 +0000 (12:50 +0000)
committerLoshult <loshult@swgemu.com>
Fri, 10 Jan 2014 13:04:33 +0000 (13:04 +0000)
looted by correct player.
[Added] withInventoryPointer function to lua object manager.

Change-Id: I2365608bc170964849ec1e099259aae4063c0899

MMOCoreORB/bin/scripts/managers/jedi/village/sith_shadow_encounter.lua
MMOCoreORB/bin/scripts/managers/jedi/village/tests/sith_shadow_encounter_Test.lua [new file with mode: 0644]
MMOCoreORB/bin/scripts/managers/object/object_manager.lua
MMOCoreORB/bin/scripts/managers/object/tests/object_manager_Test.lua
MMOCoreORB/bin/scripts/mobile/quest/serverobjects.lua
MMOCoreORB/bin/scripts/mobile/quest/sith_shadow_datapad.lua [deleted file]
MMOCoreORB/bin/scripts/screenplays/mocks/director_manager_mocks.lua

index aa60a1e..c538dce 100644 (file)
@@ -2,6 +2,7 @@ local Encounter = require("quest.tasks.encounter")
 local QuestManager = require("managers.quest.quest_manager")
 local ObjectManager = require("managers.object.object_manager")
 local SpawnMobiles = require("utils.spawn_mobiles")
+local Logger = require("utils.logger")
 
 SithShadowEncounter = Encounter:new {
        -- Task properties
@@ -14,7 +15,7 @@ SithShadowEncounter = Encounter:new {
        --encounterDespawnTime = 5 * 60 * 1000, -- 5 minutes
        encounterDespawnTime = 60 * 1000, -- 5 minutes
        spawnObjectList = {
-               { template = "sith_shadow_datapad", minimumDistance = 32, maximumDistance = 64, referencePoint = 0, followPlayer = true },
+               { template = "sith_shadow", minimumDistance = 32, maximumDistance = 64, referencePoint = 0, followPlayer = true },
                { template = "sith_shadow", minimumDistance = 4, maximumDistance = 8, referencePoint = 1, followPlayer = true }
        },
        onEncounterSpawned = nil,
@@ -23,4 +24,54 @@ SithShadowEncounter = Encounter:new {
        onEncounterAtPlayer = nil
 }
 
+-- Check if the sith shadow belongs to 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)
+       local spawnedSithShadows = SpawnMobiles.getSpawnedMobiles(pCreatureObject, self.taskName)
+
+       if spawnedSithShadows ~= nil then
+               return ObjectManager.withCreatureObject(spawnedSithShadows[1], function(sithShadowInList)
+                       return ObjectManager.withCreatureObject(pSithShadow, function(sithShadow)
+                               return sithShadowInList:getObjectID() == sithShadow:getObjectID()
+                       end) == true
+               end) == true
+       else
+               return false
+       end
+end
+
+-- Create the waypoint data pad as loot on the sith shadow.
+-- @param pSithShadow pointer to the creature object of the sith shadow.
+function SithShadowEncounter:addWaypointDatapadAsLoot(pSithShadow)
+       ObjectManager.withInventoryPointer(pSithShadow, function(pInventory)
+               createLoot(pInventory, "sith_shadow_encounter_datapad", 0, true)
+       end)
+end
+
+-- Event handler for the LOOTCREATURE event on one of the sith shadows.
+-- @param pLootedCreature pointer to the sith shadow creature that is being looted.
+-- @param pLooter pointer to the creature object of the looter.
+-- @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
+               self:addWaypointDatapadAsLoot(pLootedCreature)
+               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])
+end
+
 return SithShadowEncounter
diff --git a/MMOCoreORB/bin/scripts/managers/jedi/village/tests/sith_shadow_encounter_Test.lua b/MMOCoreORB/bin/scripts/managers/jedi/village/tests/sith_shadow_encounter_Test.lua
new file mode 100644 (file)
index 0000000..89325b2
--- /dev/null
@@ -0,0 +1,114 @@
+local SithShadowEncounter = require("managers.jedi.village.sith_shadow_encounter")
+local DirectorManagerMocks = require("screenplays.mocks.director_manager_mocks")
+local SpawnMobilesMocks = require("utils.mocks.spawn_mobiles_mocks")
+
+LOOTCREATURE = 53
+
+describe("Sith Shadow Encounter", function()
+       local pCreatureObject = { "creatureObjectPointer" }
+       local pFirstSithShadow = { "firstSithShadowPointer" }
+       local pSecondSithShadow = { "secondSithShadowPointer" }
+       local spawnedSithShadowList = {
+               pFirstSithShadow,
+               pSecondSithShadow
+       }
+       local creatureObject
+       local firstSithShadowObject
+       local secondSithShadowObject
+       local pInventory = { "inventoryPointer" }
+       local firstSithShadowId = 12345
+       local secondSithShadowId = 23456
+
+       setup(function()
+               DirectorManagerMocks.mocks.setup()
+               SpawnMobilesMocks.mocks.setup()
+       end)
+
+       teardown(function()
+               DirectorManagerMocks.mocks.teardown()
+               SpawnMobilesMocks.mocks.teardown()
+       end)
+
+       before_each(function()
+               DirectorManagerMocks.mocks.before_each()
+               SpawnMobilesMocks.mocks.before_each()
+
+               creatureObject = {}
+               DirectorManagerMocks.creatureObjects[pCreatureObject] = creatureObject
+
+               firstSithShadowObject = {}
+               firstSithShadowObject.getObjectID = spy.new(function() return firstSithShadowId end)
+               firstSithShadowObject.getSlottedObject = spy.new(function() return pInventory end)
+               DirectorManagerMocks.creatureObjects[pFirstSithShadow] = firstSithShadowObject
+
+               secondSithShadowObject = {}
+               secondSithShadowObject.getObjectID = spy.new(function() return secondSithShadowId end)
+               DirectorManagerMocks.creatureObjects[pSecondSithShadow] = secondSithShadowObject
+       end)
+
+       describe("onEncounterSpawned", function()
+               describe("When called with a pointer to a player and a list of spawned sith shadows", function()
+                       it("Should register an observer for LOOTCREATURE on the first sith shadow in the sith shadow list.", function()
+                               SithShadowEncounter:onEncounterSpawned(pCreatureObject, spawnedSithShadowList)
+
+                               assert.spy(createObserver).was.called_with(LOOTCREATURE, SithShadowEncounter.taskName, "onLoot", pFirstSithShadow)
+                       end)
+               end)
+       end)
+
+       describe("onLoot", function()
+               describe("When called with a pointer to a creature and a pointer to the looter", function()
+                       it("Should get the list of spawned sith shadows for the looter.", function()
+                               SithShadowEncounter:onLoot(pFirstSithShadow, pCreatureObject, 0)
+
+                               assert.spy(SpawnMobilesMocks.getSpawnedMobiles).was.called_with(pCreatureObject, SithShadowEncounter.taskName)
+                       end)
+
+                       describe("and the player has a list of spawned sith shadows", function()
+                               before_each(function()
+                                       SpawnMobilesMocks.getSpawnedMobiles = spy.new(function() return spawnedSithShadowList end)
+                               end)
+
+                               it("Should get the id of the first sith shadow in the list", function()
+                                       SithShadowEncounter:onLoot(pSecondSithShadow, pCreatureObject, 0)
+
+                                       assert.spy(firstSithShadowObject.getObjectID).was.called_with(firstSithShadowObject)
+                               end)
+
+                               it("Should get the id of the looted creature", function()
+                                       SithShadowEncounter:onLoot(pSecondSithShadow, pCreatureObject, 0)
+
+                                       assert.spy(secondSithShadowObject.getObjectID).was.called_with(secondSithShadowObject)
+                               end)
+
+                               describe("and both ids are identical", function()
+                                       it("Should create loot in the inventory of the sith shadow.", function()
+                                               SithShadowEncounter:onLoot(pFirstSithShadow, pCreatureObject, 0)
+
+                                               assert.spy(createLoot).was.called_with(pInventory, "sith_shadow_encounter_datapad", 0, true)
+                                       end)
+                               end)
+
+                               describe("and both ids are not identical", function()
+                                       it("Should not create loot in the inventory of the looted sith shadow.", function()
+                                               SithShadowEncounter:onLoot(pSecondSithShadow, pCreatureObject, 0)
+
+                                               assert.spy(createLoot).was.not_called()
+                                       end)
+                               end)
+                       end)
+
+                       describe("and the player has no spawned sith shadows", function()
+                               before_each(function()
+                                       SpawnMobilesMocks.getSpawnedMobiles = spy.new(function() return nil end)
+                               end)
+
+                               it("Should not create loot in the inventory of the looted sith shadow.", function()
+                                       SithShadowEncounter:onLoot(pFirstSithShadow, pCreatureObject, 0)
+
+                                       assert.spy(createLoot).was.not_called()
+                               end)
+                       end)
+               end)
+       end)
+end)
index c4b6ebf..bf46da1 100644 (file)
@@ -92,4 +92,21 @@ function ObjectManager.withCreatureAndPlayerObject(pCreatureObject, performThisF
        end)
 end
 
+-- Perform the supplied function with the inventory pointer from the pointer to the creature object.
+-- @param pCreatureObject a pointer to a creature object.
+-- @param performThisFunction a function that takes a pointer to an inventory as its argument.
+-- @return whatever performThisFunction returns or nil if the pCreatureObject pointer is nil or does not have an inventory.
+function ObjectManager.withInventoryPointer(pCreatureObject, performThisFunction)
+       return ObjectManager.withCreatureObject(pCreatureObject, function(creatureObject)
+               local pInventory = creatureObject:getSlottedObject("inventory")
+
+               if pInventory ~= nil then
+                       return performThisFunction(pInventory)
+               else
+                       return nil
+               end
+       end)
+end
+
+
 return ObjectManager
index a0749fa..2e38e1e 100644 (file)
@@ -11,6 +11,7 @@ describe("Object Manager", function()
        local creatureObject = { "creatureObject" }
        local playerObject = { "playerObject" }
        local cityRegion = { "cityRegion" }
+       local pInventory = { "inventoryPointer" }
 
        setup(function()
                DirectorManagerMocks.mocks.setup()
@@ -29,6 +30,7 @@ describe("Object Manager", function()
                DirectorManagerMocks.cityRegions[pCityRegion] = cityRegion
 
                creatureObject.getPlayerObject = spy.new(function() return pPlayerObject end)
+               creatureObject.getSlottedObject = spy.new(function() return pInventory end)
                DirectorManagerMocks.creatureObjects[pCreatureObject] = creatureObject
        end)
 
@@ -59,6 +61,10 @@ describe("Object Manager", function()
                assert.is.Nil(ObjectManager.withCreatureAndPlayerObject(nil, function(creatureObject, playerObject) end))
        end)
 
+       it("Shall return nil if the creature object pointer is nil to the withInventoryPointer function.", function()
+               assert.is.Nil(ObjectManager.withInventoryPointer(nil, function(pInventory) end))
+       end)
+
        it("Shall call the supplied lambda expression with the AiAgent when calling the withCreatureAiAgent function.", function()
                local aiAgentArgument = nil
 
@@ -124,4 +130,25 @@ describe("Object Manager", function()
                assert.same(creatureObjectArgument, creatureObject)
                assert.same(playerObjectArgument, playerObject)
        end)
+
+       it("Shall call the getSlottedObject function with 'inventory' as argument when calling the withInventoryPointer function.", function()
+               ObjectManager.withInventoryPointer(pCreatureObject, function() end)
+
+               assert.spy(creatureObject.getSlottedObject).was.called_with(creatureObject, "inventory")
+       end)
+
+       it("Shall call the supplied lambda expression with the pointer to inventory when calling the withInventoryPointer function.", function()
+               local pInventoryArgument = nil
+
+               ObjectManager.withInventoryPointer(pCreatureObject, function(pInventory) pInventoryArgument = pInventory end)
+               assert.same(pInventoryArgument, pInventory)
+       end)
+
+       it("Shall not call the supplied lambda expression with the pointer to inventory when calling the withInventoryPointer function if the creature does not have an inventory.", function()
+               local lambdaExpressionCalled = false
+               creatureObject.getSlottedObject = spy.new(function() return nil end)
+
+               ObjectManager.withInventoryPointer(pCreatureObject, function(pInventory) lambdaExpressionCalled = true end)
+               assert.is_false(lambdaExpressionCalled)
+       end)
 end)
index f5f692f..b65af86 100644 (file)
@@ -5,4 +5,3 @@ includeFile("quest/chadra_fan_male.lua")
 includeFile("quest/chadra_fan_thief.lua")
 includeFile("quest/gadget_specialist.lua")
 includeFile("quest/sith_shadow.lua")
-includeFile("quest/sith_shadow_datapad.lua")
diff --git a/MMOCoreORB/bin/scripts/mobile/quest/sith_shadow_datapad.lua b/MMOCoreORB/bin/scripts/mobile/quest/sith_shadow_datapad.lua
deleted file mode 100644 (file)
index d8a3b84..0000000
+++ /dev/null
@@ -1,69 +0,0 @@
-sith_shadow_datapad = Creature:new {
-       objectName = "@mob/creature_names:shadow_punk",
-       socialGroup = "sith_shadow",
-       pvpFaction = "sith_shadow",
-       faction = "sith_shadow",
-       level = 10,
-       chanceHit = 0.28,
-       damageMin = 90,
-       damageMax = 110,
-       baseXp = 356,
-       baseHAM = 810,
-       baseHAMmax = 990,
-       armor = 0,
-       resists = {0,0,0,0,0,0,0,-1,-1},
-       meatType = "",
-       meatAmount = 0,
-       hideType = "",
-       hideAmount = 0,
-       boneType = "",
-       boneAmount = 0,
-       milk = 0,
-       tamingChance = 0,
-       ferocity = 0,
-       pvpBitmask = AGGRESSIVE + ATTACKABLE + ENEMY,
-       creatureBitmask = PACK + KILLER,
-       optionsBitmask = 128,
-       diet = HERBIVORE,
-
-       templates = {
-               "object/mobile/dressed_sith_shadow_hum_f_01.iff",
-               "object/mobile/dressed_sith_shadow_hum_f_02.iff",
-               "object/mobile/dressed_sith_shadow_hum_f_03.iff",
-               "object/mobile/dressed_sith_shadow_hum_m_01.iff",
-               "object/mobile/dressed_sith_shadow_hum_m_02.iff",
-               "object/mobile/dressed_sith_shadow_hum_m_03.iff",
-               "object/mobile/dressed_sith_shadow_aqualish_f_01.iff",
-               "object/mobile/dressed_sith_shadow_aqualish_f_02.iff",
-               "object/mobile/dressed_sith_shadow_aqualish_m_01.iff",
-               "object/mobile/dressed_sith_shadow_aqualish_m_02.iff",
-               "object/mobile/dressed_sith_shadow_nikto_m_01.iff",
-               "object/mobile/dressed_sith_shadow_nikto_m_02.iff",
-               "object/mobile/dressed_sith_shadow_nikto_m_03.iff",
-               "object/mobile/dressed_sith_shadow_rodian_f_01.iff",
-               "object/mobile/dressed_sith_shadow_rodian_f_02.iff",
-               "object/mobile/dressed_sith_shadow_rodian_m_01.iff",
-               "object/mobile/dressed_sith_shadow_rodian_m_02.iff",
-               "object/mobile/dressed_sith_shadow_trn_f_01.iff",
-               "object/mobile/dressed_sith_shadow_trn_m_01.iff",
-               "object/mobile/dressed_sith_shadow_trn_m_02.iff",
-               "object/mobile/dressed_sith_shadow_trn_m_03.iff",
-               "object/mobile/dressed_sith_shadow_zab_f_01.iff",
-               "object/mobile/dressed_sith_shadow_zab_f_02.iff",
-               "object/mobile/dressed_sith_shadow_zab_m_01.iff",
-               "object/mobile/dressed_sith_shadow_zab_m_02.iff",
-               "object/mobile/dressed_sith_shadow_zab_m_03.iff"},
-       lootGroups = {
-           {
-                       groups = {
-                               {group = "sith_shadow_encounter_datapad", chance = 10000000}
-                       },
-                       lootChance = 10000000
-               }
-       },
-       weapons = {"pirate_weapons_light"},
-       conversationTemplate = "",
-       attacks = merge(brawlernovice,marksmannovice)
-}
-
-CreatureTemplates:addCreatureTemplate(sith_shadow_datapad, "sith_shadow_datapad")
index 4f115e0..051169f 100644 (file)
@@ -19,6 +19,7 @@ end
 -- Function to be called in the before_each method for a test to prepare the mocks.
 function DirectorManagerMocks.mocks.before_each()
        createEvent = spy.new(function() end)
+       createLoot = spy.new(function() end)
        createObserver = spy.new(function() end)
        getCityRegionAt = spy.new(function() return nil end)
        getSceneObject = spy.new(function() return nil end)