E.g.
infinite dungeon event file: {group="majeyal-generic", percent_factor=0.5},
majeyal-generic event file: {name="weird-pedestals", percent=10},
"weird-pedestals" event should be taken as a 5% chance, but
The following line combienes the group percent_factor and the event percent and puts it into the event percent_factor but the following code to choose an event only uses event.precent it ignores the percent_factor.
Code: Select all
Gamestate.lua - line 1889 (b42)
if e.percent_factor and ee.percent then ee.percent_factor = math.floor(ee.percent * e.percent_factor) end
I.e.
[3] = {
[percent] = 10
[name] = weird-pedestals
[percent_factor] = 5
}
The following replacement for Gamestate.lua:startEvents() should correct this (tested that events still fire with new code)
Code: Select all
function _M:startEvents()
if not game.zone.events then print("No zone events loaded") return end
if not game.zone.assigned_events then
local levels = {}
if game.zone.events_by_level then
levels[game.level.level] = {}
else
for i = 1, game.zone.max_level do levels[i] = {} end
end
-- Generate the events list for this zone, eventually loading from group files
local evts, mevts = {}, {}
for i, e in ipairs(game.zone.events) do
if e.name then if e.minor then mevts[#mevts+1] = e else evts[#evts+1] = e end
elseif e.group then
local f, err = loadfile("/data/general/events/groups/"..e.group..".lua")
if not f then error(err) end
setfenv(f, setmetatable({level=game.level, zone=game.zone}, {__index=_G}))
local list = f()
for j, ee in ipairs(list) do
if e.percent_factor and ee.percent then ee.percent_factor = e.percent_factor end
if ee.name then if ee.minor then mevts[#mevts+1] = ee else evts[#evts+1] = ee end end
end
end
end
-- Randomize the order they are checked as
table.shuffle(evts)
table.print(evts)
table.shuffle(mevts)
table.print(mevts)
for i, e in ipairs(evts) do
local eventPercent
if e.percent_factor then eventPercent = math.floor(e.percent * e.percent_factor) else eventPercent = e.percent end
-- If we allow it, try to find a level to host it
if (e.always or rng.percent(eventPercent)) and (not e.unique or not self:doneEvent(e.name)) then
local lev = nil
local forbid = e.forbid or {}
forbid = table.reverse(forbid)
if game.zone.events_by_level then
lev = game.level.level
else
if game.zone.events.one_per_level then
local list = {}
for i = 1, #levels do if #levels[i] == 0 and not forbid[i] then list[#list+1] = i end end
if #list > 0 then
lev = rng.table(list)
end
else
if forbid then
local t = table.genrange(1, game.zone.max_level, true)
t = table.minus_keys(t, forbid)
lev = rng.table(table.keys(t))
else
lev = rng.range(1, game.zone.max_level)
end
end
end
if lev then
lev = levels[lev]
lev[#lev+1] = e.name
end
end
end
for i, e in ipairs(mevts) do
local eventPercent
if e.percent_factor then eventPercent = math.floor(e.percent * e.percent_factor) else eventPercent = e.percent end
local forbid = e.forbid or {}
forbid = table.reverse(forbid)
local start, stop = 1, game.zone.max_level
if game.zone.events_by_level then start, stop = game.level.level, game.level.level end
for lev = start, stop do
if rng.percent(eventPercent) and not forbid[lev] then
local lev = levels[lev]
lev[#lev+1] = e.name
if e.max_repeat then
local nb = 1
local p = eventPercent
while nb <= e.max_repeat do
if rng.percent(p) then
lev[#lev+1] = e.name
else
break
end
p = p / 2
end
end
end
end
end
game.zone.assigned_events = levels
end
return function()
print("Assigned events list")
table.print(game.zone.assigned_events)
for i, e in ipairs(game.zone.assigned_events[game.level.level] or {}) do
local f, err = loadfile("/data/general/events/"..e..".lua")
if not f then error(err) end
setfenv(f, setmetatable({level=game.level, zone=game.zone, event_id=e.name, Map=Map}, {__index=_G}))
f()
end
game.zone.assigned_events[game.level.level] = {}
if game.zone.events_by_level then game.zone.assigned_events = nil end
end
end