recurring command updates fix
This commit is contained in:
Binary file not shown.
@@ -240,36 +240,45 @@ end
|
|||||||
function Stage:CheckAndUpdateSelf()
|
function Stage:CheckAndUpdateSelf()
|
||||||
self._logger:debug("Checking on Stage: " .. self.zoneName)
|
self._logger:debug("Checking on Stage: " .. self.zoneName)
|
||||||
|
|
||||||
local activeCount = 0
|
|
||||||
local dbTables = self:GetStageTables()
|
local dbTables = self:GetStageTables()
|
||||||
|
|
||||||
local availableMissions = {}
|
---@return Array<Mission>
|
||||||
for _, mission in pairs(dbTables.missionsByCode) do
|
local getAvailableMissions = function ()
|
||||||
local state = mission:getState()
|
---@type Array<Mission>
|
||||||
|
local availableMissions = {}
|
||||||
if state == "ACTIVE" then
|
for _, mission in pairs(dbTables.missionsByCode) do
|
||||||
activeCount = activeCount + 1
|
if mission:getState() == "NEW" then
|
||||||
|
table.insert(availableMissions, mission)
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
return availableMissions
|
||||||
|
end
|
||||||
|
|
||||||
if state == "NEW" then
|
---@return number
|
||||||
table.insert(availableMissions, mission)
|
local getActiveMissionsCount = function ()
|
||||||
|
local result = 0
|
||||||
|
for _, mission in pairs(dbTables.missionsByCode) do
|
||||||
|
if mission:getState() == "ACTIVE" then
|
||||||
|
result = result + 1
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
return result
|
||||||
end
|
end
|
||||||
|
|
||||||
local max = dbTables.maxMissions
|
local max = dbTables.maxMissions
|
||||||
local availableMissionsCount = Spearhead.Util.tableLength(availableMissions)
|
local availableMissionsCount = Spearhead.Util.tableLength(getAvailableMissions())
|
||||||
|
local activeCount = getActiveMissionsCount()
|
||||||
if activeCount < max and availableMissionsCount > 0 then
|
if activeCount < max and availableMissionsCount > 0 then
|
||||||
for i = activeCount+1, max do
|
for i = activeCount+1, max do
|
||||||
if availableMissionsCount == 0 then
|
if availableMissionsCount == 0 then
|
||||||
i = max+1 --exits this loop
|
i = max+1 --exits this loop
|
||||||
else
|
else
|
||||||
local index = math.random(1, availableMissionsCount)
|
local mission = Spearhead.Util.randomFromList(getAvailableMissions()) --[[@as Mission]]
|
||||||
|
|
||||||
---@type Mission
|
|
||||||
local mission = table.remove(availableMissions, index)
|
|
||||||
if mission then
|
if mission then
|
||||||
mission:SpawnActive()
|
mission:SpawnActive()
|
||||||
activeCount = activeCount + 1;
|
activeCount = activeCount + 1;
|
||||||
|
else
|
||||||
|
return
|
||||||
end
|
end
|
||||||
availableMissionsCount = availableMissionsCount - 1
|
availableMissionsCount = availableMissionsCount - 1
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -2,6 +2,7 @@
|
|||||||
|
|
||||||
--- ZoneMission is missions that are defined by zones in the ME
|
--- ZoneMission is missions that are defined by zones in the ME
|
||||||
---@class ZoneMission : Mission, OnUnitLostListener
|
---@class ZoneMission : Mission, OnUnitLostListener
|
||||||
|
---@field private _state MissionState
|
||||||
---@field private _missionGroups MissionGroups
|
---@field private _missionGroups MissionGroups
|
||||||
local ZoneMission = {}
|
local ZoneMission = {}
|
||||||
|
|
||||||
@@ -137,9 +138,6 @@ function ZoneMission:UpdateState(checkHealth, messageIfDone)
|
|||||||
if checkHealth == nil then checkHealth = false end
|
if checkHealth == nil then checkHealth = false end
|
||||||
if messageIfDone == false then messageIfDone = true end
|
if messageIfDone == false then messageIfDone = true end
|
||||||
|
|
||||||
if self._state == "COMPLETED" then
|
|
||||||
return
|
|
||||||
end
|
|
||||||
|
|
||||||
if checkHealth == true then
|
if checkHealth == true then
|
||||||
local function unitAliveState(unitName)
|
local function unitAliveState(unitName)
|
||||||
@@ -254,6 +252,11 @@ function ZoneMission:SpawnActive()
|
|||||||
|
|
||||||
self._logger:info("Activating " .. self.name)
|
self._logger:info("Activating " .. self.name)
|
||||||
|
|
||||||
|
if self._state == "COMPLETED" or self._state == "ACTIVE" then
|
||||||
|
self._logger:debug("Mission already completed, not spawning")
|
||||||
|
return
|
||||||
|
end
|
||||||
|
|
||||||
self._state = "ACTIVE"
|
self._state = "ACTIVE"
|
||||||
for _, group in pairs(self._missionGroups.groups) do
|
for _, group in pairs(self._missionGroups.groups) do
|
||||||
group:Spawn()
|
group:Spawn()
|
||||||
|
|||||||
@@ -6,10 +6,10 @@
|
|||||||
---@field missionType MissionType
|
---@field missionType MissionType
|
||||||
---@field missionTypeDisplay string
|
---@field missionTypeDisplay string
|
||||||
---@field priority MissionPriority
|
---@field priority MissionPriority
|
||||||
---@field missionBriefing string
|
|
||||||
---@field location Vec2?
|
---@field location Vec2?
|
||||||
---@field code string
|
---@field code string
|
||||||
---@field protected state MissionState
|
---@field protected _state MissionState
|
||||||
|
---@field protected _missionBriefing string
|
||||||
---@field getState fun(self: Mission): MissionState @Get the mission state
|
---@field getState fun(self: Mission): MissionState @Get the mission state
|
||||||
---@field protected _logger Logger
|
---@field protected _logger Logger
|
||||||
---@field protected _database Database
|
---@field protected _database Database
|
||||||
@@ -37,10 +37,10 @@ function Mission.newSuper(self, zoneName, missionName, missionType, missionBrief
|
|||||||
self.name = missionName
|
self.name = missionName
|
||||||
self.missionType = missionType
|
self.missionType = missionType
|
||||||
self.priority = priority
|
self.priority = priority
|
||||||
self.state = "NEW"
|
self._state = "NEW"
|
||||||
self._logger = logger
|
self._logger = logger
|
||||||
self._database = database
|
self._database = database
|
||||||
self.missionBriefing = missionBriefing
|
self._missionBriefing = missionBriefing
|
||||||
self.code = tostring(database:GetNewMissionCode())
|
self.code = tostring(database:GetNewMissionCode())
|
||||||
|
|
||||||
self._completeListeners = {}
|
self._completeListeners = {}
|
||||||
@@ -55,7 +55,7 @@ end
|
|||||||
|
|
||||||
---@return MissionState
|
---@return MissionState
|
||||||
function Mission:getState()
|
function Mission:getState()
|
||||||
return self.state
|
return self._state
|
||||||
end
|
end
|
||||||
|
|
||||||
--region PUBLIC
|
--region PUBLIC
|
||||||
|
|||||||
+1
-1
@@ -52,7 +52,7 @@ SpearheadConfig = {
|
|||||||
maxMissionStage = 10,
|
maxMissionStage = 10,
|
||||||
|
|
||||||
--Stage starting number
|
--Stage starting number
|
||||||
startingStage = 0,
|
startingStage = 1,
|
||||||
|
|
||||||
---DEBUG logging. Consider keeping this disabled
|
---DEBUG logging. Consider keeping this disabled
|
||||||
debugEnabled = true
|
debugEnabled = true
|
||||||
|
|||||||
Reference in New Issue
Block a user