group NPC runtime data together
This commit is contained in:
parent
e9de6a384c
commit
71d5a3bff2
|
@ -39,14 +39,17 @@ this.runtimeData = {
|
|||
-- used for checking when entering wandering NPC's house, will probably remove
|
||||
byCell = {}
|
||||
},
|
||||
-- holder for all NPC data
|
||||
NPCs = {
|
||||
-- NPCs who have been moved
|
||||
movedNPCs = {},
|
||||
moved = {},
|
||||
-- NPCs who stick around in bad weather and have been moved
|
||||
movedBadWeatherNPCs = {},
|
||||
movedBadWeather = {},
|
||||
-- NPCs who have been disabled
|
||||
disabledNPCs = {},
|
||||
disabled = {},
|
||||
-- NPCs who stick around in bad weather and have been disabled
|
||||
disabledBadWeatherNPCs = {},
|
||||
disabledBadWeather = {}
|
||||
},
|
||||
-- positions that haven't been used
|
||||
positions = {},
|
||||
-- player companions
|
||||
|
|
|
@ -16,11 +16,12 @@ local function moveNPC(homeData)
|
|||
-- add to in memory table
|
||||
local badWeather = checks.isBadWeatherNPC(npc)
|
||||
if badWeather then
|
||||
common.runtimeData.movedBadWeatherNPCs[homeData.ogPlaceName] = common.runtimeData.movedBadWeatherNPCs[homeData.ogPlaceName] or {}
|
||||
common.runtimeData.movedBadWeatherNPCs[homeData.ogPlaceName][npc.id] = homeData
|
||||
common.runtimeData.NPCs.movedBadWeather[homeData.ogPlaceName] =
|
||||
common.runtimeData.NPCs.movedBadWeather[homeData.ogPlaceName] or {}
|
||||
common.runtimeData.NPCs.movedBadWeather[homeData.ogPlaceName][npc.id] = homeData
|
||||
else
|
||||
common.runtimeData.movedNPCs[homeData.ogPlaceName] = common.runtimeData.movedNPCs[homeData.ogPlaceName] or {}
|
||||
common.runtimeData.movedNPCs[homeData.ogPlaceName][npc.id] = homeData
|
||||
common.runtimeData.NPCs.moved[homeData.ogPlaceName] = common.runtimeData.NPCs.moved[homeData.ogPlaceName] or {}
|
||||
common.runtimeData.NPCs.moved[homeData.ogPlaceName][npc.id] = homeData
|
||||
end
|
||||
|
||||
-- set npc data, so we can move NPCs back after a load
|
||||
|
@ -45,11 +46,11 @@ local function disableNPC(npc, cell)
|
|||
-- same thing as moveNPC, but disables instead
|
||||
-- add to runtimeData
|
||||
if checks.isBadWeatherNPC(npc) then
|
||||
common.runtimeData.disabledBadWeatherNPCs[cell.id] = common.runtimeData.disabledBadWeatherNPCs[cell.id] or {}
|
||||
common.runtimeData.disabledBadWeatherNPCs[cell.id][npc.id] = npc
|
||||
common.runtimeData.NPCs.disabledBadWeather[cell.id] = common.runtimeData.NPCs.disabledBadWeather[cell.id] or {}
|
||||
common.runtimeData.NPCs.disabledBadWeather[cell.id][npc.id] = npc
|
||||
else
|
||||
common.runtimeData.disabledNPCs[cell.id] = common.runtimeData.disabledNPCs[cell.id] or {}
|
||||
common.runtimeData.disabledNPCs[cell.id][npc.id] = npc
|
||||
common.runtimeData.NPCs.disabled[cell.id] = common.runtimeData.NPCs.disabled[cell.id] or {}
|
||||
common.runtimeData.NPCs.disabled[cell.id][npc.id] = npc
|
||||
end
|
||||
-- set NPC data
|
||||
npc.data.NPCsGoHome = {disabled = true}
|
||||
|
@ -132,11 +133,12 @@ local function checkForMovedOrDisabledNPCs(cell)
|
|||
if npc.data.NPCsGoHome.disabled then
|
||||
-- disabled NPC
|
||||
if badWeather then
|
||||
common.runtimeData.disabledBadWeatherNPCs[cell.id] = common.runtimeData.disabledBadWeatherNPCs[cell.id] or {}
|
||||
common.runtimeData.disabledBadWeatherNPCs[cell.id][npc.id] = npc
|
||||
common.runtimeData.NPCs.disabledBadWeather[cell.id] =
|
||||
common.runtimeData.NPCs.disabledBadWeather[cell.id] or {}
|
||||
common.runtimeData.NPCs.disabledBadWeather[cell.id][npc.id] = npc
|
||||
else
|
||||
common.runtimeData.disabledNPCs[cell.id] = common.runtimeData.disabledNPCs[cell.id] or {}
|
||||
common.runtimeData.disabledNPCs[cell.id][npc.id] = npc
|
||||
common.runtimeData.NPCs.disabled[cell.id] = common.runtimeData.NPCs.disabled[cell.id] or {}
|
||||
common.runtimeData.NPCs.disabled[cell.id][npc.id] = npc
|
||||
end
|
||||
else
|
||||
-- homed NPC
|
||||
|
@ -147,11 +149,13 @@ local function checkForMovedOrDisabledNPCs(cell)
|
|||
|
||||
-- add to in memory table
|
||||
if badWeather then
|
||||
common.runtimeData.movedBadWeatherNPCs[homeData.ogPlaceName] = common.runtimeData.movedBadWeatherNPCs[homeData.ogPlaceName] or {}
|
||||
common.runtimeData.movedBadWeatherNPCs[cell.id][npc.id] = homeData
|
||||
common.runtimeData.NPCs.movedBadWeather[homeData.ogPlaceName] =
|
||||
common.runtimeData.NPCs.movedBadWeather[homeData.ogPlaceName] or {}
|
||||
common.runtimeData.NPCs.movedBadWeather[cell.id][npc.id] = homeData
|
||||
else
|
||||
common.runtimeData.movedNPCs[homeData.ogPlaceName] = common.runtimeData.movedNPCs[homeData.ogPlaceName] or {}
|
||||
common.runtimeData.movedNPCs[cell.id][npc.id] = homeData
|
||||
common.runtimeData.NPCs.moved[homeData.ogPlaceName] =
|
||||
common.runtimeData.NPCs.moved[homeData.ogPlaceName] or {}
|
||||
common.runtimeData.NPCs.moved[cell.id][npc.id] = homeData
|
||||
end
|
||||
end
|
||||
end
|
||||
|
@ -216,8 +220,8 @@ this.processNPCs = function(cell)
|
|||
-- LuaFormatter off
|
||||
-- check for bad weather NPCs that have been disabled, and re-enable them
|
||||
if config.keepBadWeatherNPCs then
|
||||
if not common.isEmptyTable(common.runtimeData.movedBadWeatherNPCs[cell.id]) then putNPCsBack(common.runtimeData.movedBadWeatherNPCs[cell.id]) end
|
||||
if not common.isEmptyTable(common.runtimeData.disabledBadWeatherNPCs[cell.id]) then reEnableNPCs(common.runtimeData.disabledBadWeatherNPCs[cell.id]) end
|
||||
if not common.isEmptyTable(common.runtimeData.NPCs.movedBadWeather[cell.id]) then putNPCsBack(common.runtimeData.NPCs.movedBadWeather[cell.id]) end
|
||||
if not common.isEmptyTable(common.runtimeData.NPCs.disabledBadWeather[cell.id]) then reEnableNPCs(common.runtimeData.NPCs.disabledBadWeather[cell.id]) end
|
||||
end
|
||||
elseif night then
|
||||
log(common.logLevels.large, "[PROC] !!Good or bad weather and night!!")
|
||||
|
@ -228,10 +232,10 @@ this.processNPCs = function(cell)
|
|||
else
|
||||
log(common.logLevels.large, "[PROC] !!Good weather and not night!!")
|
||||
-- put everyone back
|
||||
if not common.isEmptyTable(common.runtimeData.movedNPCs[cell.id]) then putNPCsBack(common.runtimeData.movedNPCs[cell.id]) end
|
||||
if not common.isEmptyTable(common.runtimeData.movedBadWeatherNPCs[cell.id]) then putNPCsBack(common.runtimeData.movedBadWeatherNPCs[cell.id]) end
|
||||
if not common.isEmptyTable(common.runtimeData.disabledNPCs[cell.id]) then reEnableNPCs(common.runtimeData.disabledNPCs[cell.id]) end
|
||||
if not common.isEmptyTable(common.runtimeData.disabledBadWeatherNPCs[cell.id]) then reEnableNPCs(common.runtimeData.disabledBadWeatherNPCs[cell.id]) end
|
||||
if not common.isEmptyTable(common.runtimeData.NPCs.moved[cell.id]) then putNPCsBack(common.runtimeData.NPCs.moved[cell.id]) end
|
||||
if not common.isEmptyTable(common.runtimeData.NPCs.movedBadWeather[cell.id]) then putNPCsBack(common.runtimeData.NPCs.movedBadWeather[cell.id]) end
|
||||
if not common.isEmptyTable(common.runtimeData.NPCs.disabled[cell.id]) then reEnableNPCs(common.runtimeData.NPCs.disabled[cell.id]) end
|
||||
if not common.isEmptyTable(common.runtimeData.NPCs.disabledBadWeather[cell.id]) then reEnableNPCs(common.runtimeData.NPCs.disabledBadWeather[cell.id]) end
|
||||
-- LuaFormatter on
|
||||
end
|
||||
end
|
||||
|
|
|
@ -101,9 +101,8 @@ local function updateCells()
|
|||
log(common.logLevels.large, "[MAIN] Applying changes to cell %s", cell.id)
|
||||
|
||||
-- initialize runtime data if needed
|
||||
for _, t in pairs({"movedNPCs", "movedBadWeatherNPCs", "disabledNPCs", "disabledBadWeatherNPCs"}) do
|
||||
common.runtimeData[t][cell.id] = common.runtimeData[t][cell.id] or {}
|
||||
end
|
||||
for _, t in pairs(common.runtimeData.NPCs) do t[cell.id] = t[cell.id] or {} end
|
||||
|
||||
applyChanges(cell)
|
||||
end
|
||||
|
||||
|
|
Loading…
Reference in a new issue