-------------------------------------------------------------- -- Generic Survival Instance Server Zone Script: requiring this -- file gives the custom functions for the Survival game. -- updated mrb... 1/7/10 -------------------------------------------------------------- -------------------------------------------------------------- -- Includes -------------------------------------------------------------- require('ai/L_ACTIVITY_MANAGER') --////////////////////////////////////////////////////////////////////////////////// local gConstants = {} local tMobSets = {} local tSpawnerNetworks = {} --============================================================ -- Script only local variables local gGamestate = { tPlayers = {}, -- players who have entered the game tWaitingPlayers = {}, -- players who haven't accepted yet iTotalSpawned = 0, -- total number of spawned mobs iWaveNum = 1, -- current wave number iRewardTick = 1, -- number of rewards given } --////////////////////////////////////////////////////////////////////////////////// -- helper function that prints out a variable to the log function dumpVar(name,var,indent) if( indent == nil ) then indent = "" end if( type(var) == "table" ) then print( indent .. name .. " is a table with " .. #var .. " entries:" ) local i,v = next(var) while i do dumpVar(i,v,indent .. " ") i, v = next(var, i) end else local startOfLine = indent .. name .. " is " if( type(var) == "userdata" ) then if( type(var.GetID) == "function" ) then print( startOfLine .. "an object proxy with ID = " .. var:GetID() ) else print( startOfLine .. "unknown userdata" ) end elseif( var == nil ) then print( startOfLine .. "nil" ) elseif( var == true ) then print( startOfLine .. "true" ) elseif( var == false ) then print( startOfLine .. "false" ) else print( startOfLine .. "a(n) " .. type(var) .. " with value = " .. var ) end end end function basePlayerReady(self, msg, newMsg) if not self:GetVar('SurvivalStartupComplete') then self:SetVar('SurvivalStartupComplete', true) SurvivalStartup() end --SetPlayerSpawnPoints(self) end ---------------------------------------------------------------- -- Startup of the object ---------------------------------------------------------------- function baseStartup(self, newMsg) -- Initialize the pseudo random number generator and return math.randomseed( os.time() ) self:SetVar('playersAccepted', 0) self:SetVar('playersReady', false) self:MiniGameSetParameters{numTeams = 1, playersPerTeam = 4} -- print('*****************************************************') -- dumpVar('tSpawnerNetworks', tSpawnerNetworks, ' ') -- print('*****************************************************') end ---------------------------------------------------------------- -- Player has loaded into the map ---------------------------------------------------------------- function basePlayerLoaded(self, msg, newMsg) -- adding the players to the gGamestate tables table.insert(gGamestate.tPlayers, msg.playerID:GetID()) table.insert(gGamestate.tWaitingPlayers, msg.playerID:GetID()) -- adding player to mini game team self:MiniGameAddPlayer{playerID = msg.playerID} self:MiniGameSetTeam{playerID = msg.playerID, teamID = 1} --print('my team is ' .. self:MiniGameGetTeam{ playerID = msg.playerID}.teamID) -- setting up player ui self:NotifyClientZoneObject{name = 'Define_Player_To_UI', paramObj = msg.playerID, rerouteID = msg.playerID} -- freeze the player movement/controls --msg.playerID:SetUserCtrlCompPause{bPaused = true} if not self:GetVar('wavesStarted') then -- updating the scoreboard for the new players for k,v in ipairs(gGamestate.tPlayers) do self:NotifyClientZoneObject{name = 'Update_ScoreBoard', paramObj = GAMEOBJ:GetObjectByID(v), paramStr = "0", param1 = 0, param2 = 0} end self:NotifyClientZoneObject{name = 'Show_ScoreBoard', paramStr = msg.playerID:GetID()} end -- move players to correct spawn locations SetPlayerSpawnPoints(self) if not self:GetVar('wavesStarted') then for k,v in ipairs(gGamestate.tPlayers) do local bPass = false for key,value in ipairs(gGamestate.tWaitingPlayers) do if value == v then bPass = true end end if not bPass then self:NotifyClientZoneObject{name = 'PlayerConfirm_ScoreBoard', paramObj = GAMEOBJ:GetObjectByID(v)} end end if table.maxn(gGamestate.tWaitingPlayers) == 0 then --print('All players have accepted') ActivityTimerStopAllTimers() ActivityTimerStart('AllAcceptedDelay', gConstants.startDelay, gConstants.startDelay) --(timerName, updateTime, stopTime) elseif #gGamestate.tPlayers > #gGamestate.tWaitingPlayers then if not self:GetVar('AcceptedDelayStarted') then self:SetVar('AcceptedDelayStarted', true) ActivityTimerStart('AcceptedDelay', 1, gConstants.acceptedDelay ) --(timerName, updateTime, stopTime) else ActivityTimerReset('AcceptedDelay') end end else local playerID = msg.playerID if not playerID then return end table.insert(gGamestate.tWaitingPlayers, v) UpdatePlayer(playerID) --playerID:SetUserCtrlCompPause{bPaused = false} GetLeaderboardData(self, playerID, 5) -- start the music playerID:ActivateNDAudioMusicCue{m_NDAudioMusicCueName = 'AG_Horde'} --set player stats to max playerID:SetHealth{health = playerID:GetMaxHealth{}.health} --print('max health = ' .. playerID:GetMaxHealth{}.health) playerID:SetArmor{armor = playerID:GetMaxArmor{}.armor} playerID:SetImagination{imagination = playerID:GetMaxImagination{}.imagination} end end ---------------------------------------------------------------- -- Player has exited the map ---------------------------------------------------------------- function basePlayerExit(self, msg, newMsg) local playerNum = 0 --print('player ' .. msg.playerID:GetName().name .. ' has exited') for i = 1, table.maxn(gGamestate.tPlayers) do if gGamestate.tPlayers[i] == msg.playerID:GetID() then playerNum = i end end if playerNum ~= 0 then table.remove(gGamestate.tPlayers, playerNum) -- set player to not auto-respawn msg.playerID:SetPlayerAllowedRespawn{dontPromptForRespawn=false} end playerNum = 0 for k,v in ipairs(gGamestate.tWaitingPlayers) do if msg.playerID:GetID() == v then playerNum = k end end if playerNum ~= 0 then table.remove(gGamestate.tWaitingPlayers, playerNum) end if not self:GetVar('wavesStarted') then self:NotifyClientZoneObject{name = 'Exit_Waves', paramObj = msg.playerID, paramStr = '0', param1 = 0, param2 = 0} for k,v in ipairs(gGamestate.tPlayers) do local bPass = false for key,value in ipairs(gGamestate.tWaitingPlayers) do if value == v then bPass = true end end if not bPass then self:NotifyClientZoneObject{name = 'PlayerConfirm_ScoreBoard', paramObj = GAMEOBJ:GetObjectByID(v)} end end --print('num of players left waiting: ' .. #gGamestate.tWaitingPlayers) if #gGamestate.tPlayers == 0 then return end if table.maxn(gGamestate.tWaitingPlayers) == 0 then --print('All players have accepted') ActivityTimerStopAllTimers() ActivityTimerStart('AllAcceptedDelay', gConstants.startDelay, gConstants.startDelay) --(timerName, updateTime, stopTime) elseif #gGamestate.tPlayers > #gGamestate.tWaitingPlayers then if not self:GetVar('AcceptedDelayStarted') then self:SetVar('AcceptedDelayStarted', true) ActivityTimerStart('AcceptedDelay', 1, gConstants.acceptedDelay ) --(timerName, updateTime, stopTime) else ActivityTimerReset('AcceptedDelay') end end else SetActivityValue(msg.playerID, 0, 0) UpdatePlayer(msg.playerID, true) if checkAllPlayersDead() then GameOver(self, msg.playerID) end end end ---------------------------------------------------------------- -- Received a fire event messaged from the client ---------------------------------------------------------------- function baseFireEventServerSide(self, msg, newMsg) if msg.args == 'start' then --print('start') PlayerAccepted(self) elseif msg.args == 'exit' then --print('exit') local iZone = gConstants.returnZone local tPos = gConstants.returnLoc --print('returnZone = ' .. iZone) for k,v in ipairs(gGamestate.tPlayers) do GAMEOBJ:GetObjectByID(v):TransferToZone{ zoneID = iZone, pos_x = tPos.x, pos_y = tPos.y, pos_z = tPos.z} --, rot_x = 0, rot_y = 0, rot_z = 0, rot_w = 0 end end end ---------------------------------------------------------------- -- Received a fire event messaged from someplace on the server ---------------------------------------------------------------- function baseFireEvent(self,msg, newMsg) if msg.args == 'start' then StartWaves(self) elseif msg.args == 'DeactivateRewards' then --print('fireevent DeactivateRewards') spawnerResetT(tSpawnerNetworks.rewardNetworks) end end ---------------------------------------------------------------- -- A player had died ---------------------------------------------------------------- function basePlayerDied(self, msg, newMsg) local finalTime = ActivityTimerGetCurrentTime('ClockTick') SetActivityValue(msg.playerID, 0, finalTime) GameOver(self, msg.playerID) end ---------------------------------------------------------------- -- Received a notify object message ---------------------------------------------------------------- function baseNotifyObject(self, msg, newMsg) local player = msg.ObjIDSender -- check to make sure the player is in the activity if not IsPlayerInActivity(player) then return end -- update smash count UpdateActivityValue(player, 1, 1) -- update kill score UpdateActivityValue(player, 3, msg.param1) end ---------------------------------------------------------------- -- This is called when players hit the UI to exit or stop the game. ---------------------------------------------------------------- function baseMessageBoxRespond(self, msg, newMsg) if (msg.identifier == "RePlay" ) then --print("************* RePlay *************"..msg.sender:GetName().name) self:NotifyClientZoneObject{name = 'PlayerConfirm_ScoreBoard', paramObj = msg.sender} PlayerAccepted(self, msg.sender) elseif (msg.identifier == "Exit" ) then --print("************* Exit *************"..msg.sender:GetName().name) -- exit level local iZone = gConstants.returnZone local tPos = gConstants.returnLoc --print('returnZone = ' .. iZone) msg.sender:TransferToZone{ zoneID = iZone, pos_x = tPos.x, pos_y = tPos.y, pos_z = tPos.z} --, rot_x = 0, rot_y = 0, rot_z = 0, rot_w = 0 end end -- Custom Functions function setGameVariables(passedConstants, passedMobSets, passedSpawnerNetworks) --print('updated') gConstants = passedConstants tMobSets = passedMobSets tSpawnerNetworks = passedSpawnerNetworks end ---------------------------------------------------------------- -- Custom function: Checks to see if all players have accepted, -- if they have then the game is started. ---------------------------------------------------------------- function PlayerAccepted(self, playerID) local playerNum = 0 for k,v in ipairs(gGamestate.tWaitingPlayers) do if playerID:GetID() == v then playerNum = k end end if playerNum == 0 then return end table.remove(gGamestate.tWaitingPlayers, playerNum) --print('num of players left waiting: ' .. #gGamestate.tWaitingPlayers) if table.maxn(gGamestate.tWaitingPlayers) == 0 then --print('All players have accepted') ActivityTimerStopAllTimers() ActivityTimerStart('AllAcceptedDelay', gConstants.startDelay, gConstants.startDelay) --(timerName, updateTime, stopTime) else if not self:GetVar('AcceptedDelayStarted') then self:SetVar('AcceptedDelayStarted', true) ActivityTimerStart('AcceptedDelay', 1, gConstants.acceptedDelay) --(timerName, updateTime, stopTime) else ActivityTimerReset('AcceptedDelay') end end end ---------------------------------------------------------------- -- Custom function: Starts the game. ---------------------------------------------------------------- function StartWaves(self) SetupActivity(4) self:SetVar('playersReady', true) self:SetVar('baseMobSetNum', 1) self:SetVar('randMobSetNum', 1) self:SetVar('AcceptedDelayStarted', false) for k,v in ipairs(gGamestate.tPlayers) do local playerID = GAMEOBJ:GetObjectByID(v) if not playerID then return end table.insert(gGamestate.tWaitingPlayers, v) UpdatePlayer(playerID) --playerID:SetUserCtrlCompPause{bPaused = false} GetLeaderboardData(self, playerID, 5) -- start the music playerID:ActivateNDAudioMusicCue{m_NDAudioMusicCueName = 'AG_Horde'} --set player stats to max --print('health = ' .. playerID:GetHealth{}.health) --print('armor = ' .. playerID:GetArmor{}.armor) --print('imagination = ' .. playerID:GetImagination{}.imagination) playerID:SetHealth{health = playerID:GetMaxHealth{}.health} playerID:SetArmor{armor = playerID:GetMaxArmor{}.armor} playerID:SetImagination{imagination = playerID:GetMaxImagination{}.imagination} --print('new health = ' .. playerID:GetHealth{}.health) --print('new armor = ' .. playerID:GetArmor{}.armor) --print('new imagination = ' .. playerID:GetImagination{}.imagination) end --print('start smashables') activateSpawnerNetwork(tSpawnerNetworks.smashNetworks) self:SetVar('wavesStarted', true) self:NotifyClientZoneObject{name = 'Start_Wave_Message', paramStr = "Start!"} --ActivityTimerStart('StartDelay', 3, 3) --(timerName, updateTime, stopTime) end ---------------------------------------------------------------- -- Custom function: Checks to see if all the players are dead, -- then stops the game. ---------------------------------------------------------------- function checkAllPlayersDead() local deadPlayers = 0 for k,v in ipairs(gGamestate.tPlayers) do local playerID = GAMEOBJ:GetObjectByID(v) if not playerID then return end if playerID:IsDead().bDead then deadPlayers = deadPlayers + 1 end end if deadPlayers == table.maxn(gGamestate.tPlayers) then return true end return false end function SetPlayerSpawnPoints(self) for k,v in ipairs(gGamestate.tPlayers) do local playerID = GAMEOBJ:GetObjectByID(v) if not playerID then return end local spawnObj = self:GetObjectsInGroup{ group = 'P' .. k .. '_Spawn', ignoreSpawners = true }.objects[1] local pos = spawnObj:GetPosition().pos local rot = spawnObj:GetRotation() playerID:Teleport{pos = pos, x = rot.x, y = rot.y, z = rot.z, w = rot.w, bSetRotation = true} end end ---------------------------------------------------------------- -- Custom function: Happens when all players have died, this -- stops all running processes and resets gGamestate variables ---------------------------------------------------------------- function GameOver(self, player) if not checkAllPlayersDead() then return end local finalTime = ActivityTimerGetCurrentTime('ClockTick') ActivityTimerStopAllTimers() --print('Kill Mobs ***') spawnerResetT(tSpawnerNetworks.baseNetworks) spawnerResetT(tSpawnerNetworks.randNetworks) spawnerResetT(tSpawnerNetworks.rewardNetworks) SetPlayerSpawnPoints(self) for k,v in ipairs(gGamestate.tPlayers) do local playerID = GAMEOBJ:GetObjectByID(v) if not playerID then return end local timeVar = GetActivityValue(playerID, 0) local smashVar = GetActivityValue(playerID, 1)--/gGamestate.iTotalSpawned local scoreVar = GetActivityValue(playerID, 2) self:NotifyClientZoneObject{name = 'Update_ScoreBoard', paramObj = playerID, paramStr = tostring(scoreVar), param1 = timeVar, param2 = smashVar} playerID:Resurrect() --print('smashed = ' .. smashVar .. ' out of ' .. gGamestate.iTotalSpawned .. ' for ' .. ' score = ' .. scoreVar .. ' @ %' .. math.floor((smashVar/gGamestate.iTotalSpawned)*100) ) -- stop the music playerID:DeactivateNDAudioMusicCue{m_NDAudioMusicCueName = 'AG_Horde'} -- needed to get rewards -- taskType = DB name for series of achievments, target = activityID, value1 = what it will evaluate local actMgr = self:GetObjectsInGroup{ group = 'instance_manager', ignoreSpawners = true }.objects[1] local sTaskType = 'survival_time_team' if #gGamestate.tPlayers == 1 then sTaskType = 'survival_time_solo' end playerID:UpdateMissionTask{ taskType = sTaskType, value = timeVar, value2 = actMgr:GetActivityID().activityID} -- target = actMgr, -- update mission 479 if the player is on it and has lasted 60 seconds local misState = playerID:GetMissionState{missionID = 479}.missionState if misState > 1 and misState < 4 and timeVar >= 60 then playerID:UpdateMissionTask{taskType = "complete", value = 479, value2 = 1, target = actMgr} end --print('***************************') --print('send update mission task') --print(playerID:GetName().name .. ' ' .. actMgr:GetName().name) --print(sTaskType) --print(actMgr:GetLOT().objtemplate) --print(timeVar) --print('***************************') end for k,v in ipairs(gGamestate.tPlayers) do local playerID = GAMEOBJ:GetObjectByID(v) if not playerID then return end StopActivity(playerID, finalTime, smashVar, scoreVar) end --print('smashed = ' .. GetActivityValue(player, 2) .. ' score = ' .. GetActivityValue(player, 1)) -- reset ticks gGamestate.iWaveNum = 1 -- current wave number gGamestate.iRewardTick = 1 -- number of rewards given gGamestate.iTotalSpawned = 0 -- number of mobs smashed self:SetVar('wavesStarted', false) end function basePlayerResurrected(self, msg, newMsg) self:NotifyClientZoneObject{name = 'Show_ScoreBoard', paramStr = msg.playerID:GetID()} end ---------------------------------------------------------------- -- Custom function: Gets a random number that is not the old number ---------------------------------------------------------------- function newRand(oldNum, maxRand) if maxRand == 1 then return '01', '01' end local randNum = math.random(1, maxRand) if randNum < 10 then randNum = '0' .. randNum end while randNum == oldNum do --print('found same') randNum = math.random(1, maxRand) if randNum < 10 then randNum = '0' .. randNum end end return randNum end ---------------------------------------------------------------- -- Custom function: Starts a spawner network ---------------------------------------------------------------- function activateSpawnerNetwork(spawnNetwork) for k,v in ipairs(spawnNetwork) do for i = 1, v.spawnerNum do --print('activateSpawnerNetwork: ' .. v.spawnerName .. '0' .. i) local spawner = LEVEL:GetSpawnerByName(v.spawnerName[i] .. v.spawnerNum) if spawner then --print('activateSpawnerNetwork --> ' .. v.spawnerName .. '0' .. i) if not spawner:SpawnerIsActive().bActive then --print('activate now') spawner:SpawnerActivate() end --print('reset now') spawner:SpawnerReset() end end end end ---------------------------------------------------------------- -- Custom function: Resets a spawner network ---------------------------------------------------------------- function spawnerResetT(spawnNetwork, bMaintainSpawnNum, iNumToMaintain) --dumpVar('resetTable', spawnNetwork, ' ') for k,v in ipairs(spawnNetwork) do for i = 1, table.maxn(v.spawnerName) do local spawner = LEVEL:GetSpawnerByName(v.spawnerName[i] .. v.spawnerNum) if spawner then --print('reset: ' .. v.spawnerName[i] .. v.spawnerNum) --track total mobs spawned gGamestate.iTotalSpawned = gGamestate.iTotalSpawned + spawner:SpawnerGetTotalSpawned().iSpawned v.bIsActive = false if not bMaintainSpawnNum then spawner:SpawnerDestroyObjects() end if iNumToMaintain then spawner:SpawnerSetNumToMaintain{uiNum = iNumToMaintain} --print('set spawn number to ' .. iNumToMaintain) end spawner:SpawnerDeactivate() end end end end ---------------------------------------------------------------- -- Custom function: Spawns mobs on a spawner network, Now... ---------------------------------------------------------------- function spawnNow(spawner, spawnNum) if spawner then --print('*** Spawn Now!!') if not spawner:SpawnerIsActive().bActive then spawner:SpawnerSetNumToMaintain{uiNum = spawnNum} spawner:SpawnerActivate() else spawner:SpawnerSetNumToMaintain{uiNum = spawnNum} spawner:SpawnerReset() end end end ---------------------------------------------------------------- -- Custom function: Returns a random spawn set from tMobSets or false ---------------------------------------------------------------- function getRandomSet(setName, setNum) local randNum = math.random(1, #tMobSets[setName]['tier' .. setNum]) local randSet = tMobSets[setName]['tier' .. setNum][randNum] --dumpVar('** ' .. setName .. ' using: ' .. randNum, randSet) if randSet then return randSet end return false end ---------------------------------------------------------------- -- Custom function: Returns a random spawner number from the given -- spawner table or false ---------------------------------------------------------------- function getRandomSpawnerNum(tSpawner) local randNum = 0 local bValid = false while not bValid do randNum = 0 for k,v in ipairs(tSpawner) do if v.bIsLocked == false then randNum = randNum + 1 end end randNum = math.random(1, randNum) if randNum == 1 then bValid = true elseif not tSpawner[randNum].bIsActive then bValid = true tSpawner[randNum].bIsActive = true end end if randNum ~= 0 then return randNum end return false end ---------------------------------------------------------------- -- Custom function: Update the spawner in the specified way ---------------------------------------------------------------- function updateSpawner(self, tSpawner, spawnNum) if not tSpawner then return end if spawnNum then --print('Spawner: ' .. tSpawner.spawnerName[1] .. tSpawner.spawnerNum .. ' spawn: ' .. spawnNum) local spawner = LEVEL:GetSpawnerByName(tSpawner.spawnerName[1] .. tSpawner.spawnerNum) spawnNow(spawner, spawnNum) return end local newSet = getRandomSet(tSpawner.set, self:GetVar(tSpawner.set .. 'Num')) if newSet then local newSpawner = getRandomSpawnerNum(tSpawner) for k,v in ipairs(newSet) do if v ~= 0 then --print('Spawner: ' .. tSpawner[newSpawner].spawnerName[k] .. tSpawner[newSpawner].spawnerNum .. ' spawn: ' .. tSpawner[newSpawner].spawnerNum) local spawner = LEVEL:GetSpawnerByName(tSpawner[newSpawner].spawnerName[k] .. tSpawner[newSpawner].spawnerNum) spawnNow(spawner, v) end end end end ---------------------------------------------------------------- -- Custom function: Decides how to spawne mobs ---------------------------------------------------------------- function spawnMobs(self) if not self:GetVar('wavesStarted') then return end gGamestate.iWaveNum = gGamestate.iWaveNum + 1 local spawnNum = gGamestate.iWaveNum if spawnNum > gConstants.rewardInterval then spawnNum = spawnNum - (gGamestate.iRewardTick-1) end for k,v in ipairs(gConstants.baseMobsStartTierAt) do if spawnNum == v then --print('************** Base Tier ' .. v .. ' **************') self:SetVar('baseMobSetNum', k) end end for k,v in ipairs(gConstants.randMobsStartTierAt) do if spawnNum == v then self:SetVar('randMobSetNum', k) --print('************** Random Tier ' .. v .. ' **************') end end if gGamestate.iWaveNum == gConstants.unlockNetwork3 then tSpawnerNetworks.randNetworks[3].bIsLocked = false end spawnerResetT(tSpawnerNetworks.baseNetworks, true, 0) spawnerResetT(tSpawnerNetworks.randNetworks, true, 0) updateSpawner(self, tSpawnerNetworks.baseNetworks) --print('**** Spawn Tier' .. self:GetVar('baseMobSetNum') .. ' BaseMobs @ ' .. spawnNum .. '****') if spawnNum >= gConstants.startMobSet2 then -- gGamestate.iWaveNum >= gConstants.startMobSet2 and if spawnNum == gConstants.startMobSet2 then --print('************** Start Random Mobs Set 2 **************') end --print('**** Spawn Tier' .. self:GetVar('randMobSetNum') .. ' RandMobs1 @ ' .. spawnNum .. '****') updateSpawner(self, tSpawnerNetworks.randNetworks) end if spawnNum >= gConstants.startMobSet3 then --gGamestate.iWaveNum >= gConstants.startMobSet3 and if spawnNum == gConstants.startMobSet3 then --print('************** Start Random Mobs Set 3 **************') end --print('**** Spawn Tier' .. self:GetVar('randMobSetNum') .. ' RandMobs2 ' .. spawnNum .. '****') updateSpawner(self, tSpawnerNetworks.randNetworks) end end -- Notify messages from Activity Manager ---------------------------------------------------------------- -- notify from activity mng: When activity is stopped this is -- needed to update the leaderboard. ---------------------------------------------------------------- function notifyDoCalculateActivityRating(self,other,msg) -- get the time for the player --print('Time = ' .. msg.fValue1) --print('Smash = ' .. msg.fValue2) --print('Score = ' .. msg.fValue3) msg.outActivityRating = msg.fValue1 return msg end -- activity timers ---------------------------------------------------------------- -- notify from activity mng: When ActivityTimerUpdate is sent, -- basically when a timer hits it updateInterval. ---------------------------------------------------------------- function notifyActivityTimerUpdate(self, other, msg) if msg.name == "AcceptedDelay" then --print('update delay timer to ' .. math.ceil(msg.timeRemaining)) self:NotifyClientZoneObject{name = 'Update_Default_Start_Timer', param1 = math.ceil(msg.timeRemaining)} end if msg.name == "ClockTick" then self:NotifyClientZoneObject{name = 'Update_Timer', param1 = msg.timeElapsed} end if msg.name == "SpawnTick" and not self:GetVar('isCoolDown') then spawnMobs(self) end end ---------------------------------------------------------------- -- notify from activity mng: When ActivityTimerDone is sent, -- basically when the activity timer has reached it's duration. ---------------------------------------------------------------- function notifyActivityTimerDone(self, other, msg) if msg.name == "AcceptedDelay" then --or msg.name == "AllAcceptedDelay" --print('update delay timer to 0') self:NotifyClientZoneObject{name = 'Update_Default_Start_Timer', param1 = 0} ActivityTimerStart('AllAcceptedDelay', 1, 1) elseif msg.name == "AllAcceptedDelay" then --or msg.name == "AllAcceptedDelay" --print('accepted delay *******************************') self:NotifyClientZoneObject{name = 'Kill_Default_Start_Timer'} self:NotifyClientZoneObject{name = 'Kill_ScoreBoard'} self:NotifyClientZoneObject{name = 'Reset_Timer'} ActivityTimerStart('StartDelay', 3, 3) --(timerName, updateTime, stopTime) StartWaves(self) elseif msg.name == "StartDelay" then --print('adding in timers *******************************') ActivityTimerStart('ClockTick', 1) --(timerName, updateTime, stopTime) ActivityTimerStart('SpawnTick', gConstants.waveTime) --(timerName, updateTime, stopTime) spawnMobs(self) ActivityTimerStart('CoolDownStart', (gConstants.rewardInterval*gConstants.waveTime), (gConstants.rewardInterval*gConstants.waveTime)) --(timerName, updateTime, stopTime) ActivityTimerStart('PlaySpawnSound', 3, 3) --(timerName, updateTime, stopTime) elseif msg.name == "CoolDownStart" then --print('cool down start timer *******************************') self:SetVar('isCoolDown', true) ActivityTimerStop('SpawnTick') ActivityTimerStart('CoolDownStop', gConstants.coolDownTime, gConstants.coolDownTime) -- set music to cooldown the music for k,v in ipairs(gGamestate.tPlayers) do GAMEOBJ:GetObjectByID(v):SetNDAudioMusicParameter{m_NDAudioMusicParameterName = 'Intensity', m_Value = 0.0} end --print('**** Reward ****') updateSpawner(self, tSpawnerNetworks.rewardNetworks[1], 1) gGamestate.iRewardTick = gGamestate.iRewardTick + 1 --print('stopping clock tick') ActivityTimerStart('CoolDownTick', 1, gConstants.coolDownTime) --(timerName, updateTime, stopTime) spawnerResetT(tSpawnerNetworks.baseNetworks, true, 0) spawnerResetT(tSpawnerNetworks.randNetworks, true, 0) elseif msg.name == "CoolDownStop" then --print('cool down stop timer *******************************') self:SetVar('isCoolDown', false) ActivityTimerStart('SpawnTick', gConstants.waveTime) --(timerName, updateTime, stopTime) ActivityTimerStart('CoolDownStart', (gConstants.rewardInterval*gConstants.waveTime), (gConstants.rewardInterval*gConstants.waveTime)) --(timerName, updateTime, stopTime) local iValue = self:GetVar('musicValue') if iValue then if gGamestate.iRewardTick <= 3 then iValue = iValue + 1.0 else iValue = 1.0 end else iValue = 1.0 end self:SetVar('musicValue', iValue) -- set music to normal the music for k,v in ipairs(gGamestate.tPlayers) do GAMEOBJ:GetObjectByID(v):SetNDAudioMusicParameter{m_NDAudioMusicParameterName = 'Intensity', m_Value = iValue} end spawnMobs(self) ActivityTimerStart('PlaySpawnSound', 3, 3) --(timerName, updateTime, stopTime) elseif msg.name == "PlaySpawnSound" then -- play war horn sound for k,v in ipairs(gGamestate.tPlayers) do GAMEOBJ:GetObjectByID(v):PlayNDAudioEmitter{m_NDAudioEventGUID = '{ca36045d-89df-4e96-a317-1e152d226b69}'} end end end function baseActivityStateChangeRequest(self, msg, newMsg) if (msg.wsStringValue == "gamestate" ) then self:NotifyClientZoneObject{name = "SetGameState"} end end