@@ -58,6 +58,10 @@ DD.eventDirector.eventsPerClientCap = 2 -- how many events a single client can b
5858DD .eventDirector .mainEventCap = 1 -- how many main events can be active at the same time (negative values means it is uncapped)
5959DD .eventDirector .canMainEventBeRegularEvent = false -- can a main event be called when a regular event is to be started
6060DD .eventDirector .mainEventsDisableRespawning = true -- if there is any active main event then respawning will be disabled
61+ DD .eventDirector .goodnessBiasInitial = - 3 -- offsets goodness
62+ DD .eventDirector .goodnessBiasGrowth = 1 / 60 / 10 -- per second
63+ DD .eventDirector .cooldownDecrementInitial = 1 -- per second
64+ DD .eventDirector .cooldownDecrementGrowth = 1 / 60 / 20 -- per second
6165
6266-- Debug function
6367DD .eventDirector .debug = function (list )
@@ -125,6 +129,8 @@ DD.eventDirector.getClientEvents = function (client)
125129
126130 return events
127131end
132+
133+ -- Sees if client is below configured event cap
128134DD .eventDirector .isClientBelowEventCap = function (client )
129135 if DD .eventDirector .eventsPerClientCap <= 0 then return true end
130136
@@ -294,6 +300,18 @@ Hook.Add("character.death", "DD.friendlyFireDetector", function(character)
294300 return true
295301end )
296302
303+
304+ -- calculates the weight of an event
305+ local calculateEventWeight = function (eventClass )
306+ if ((eventClass .tbl .isMainEvent ~= isMainEvent ) and not (eventClass .tbl .isMainEvent and DD .eventDirector .canMainEventBeRegularEvent )) or
307+ (eventClass .tbl .minimunAlivePercentage > alivePercentage ) or (eventClass .tbl .minimunDeadPercentage > deadPercentage ) then
308+ return 0
309+ end
310+ local directorGoodness = DD .eventDirector .goodness + DD .eventDirector .goodnessBiasInitial + DD .eventDirector .goodnessBiasGrowth * DD .roundTimer
311+ local weight = eventClass .tbl .weight / math.max (0.5 , math.abs (eventClass .tbl .goodness + directorGoodness ))
312+ return math.max (0 , weight )
313+ end
314+
297315-- Start a new event
298316DD .eventDirector .startNewEvent = function (isMainEvent )
299317 local isMainEvent = isMainEvent
@@ -315,12 +333,10 @@ DD.eventDirector.startNewEvent = function (isMainEvent)
315333
316334 -- Get weights
317335 local weights = {}
318- for key , value in pairs (DD .eventDirector .eventPool ) do
319- if (value .tbl .isMainEvent == isMainEvent ) or (value .tbl .isMainEvent and DD .eventDirector .canMainEventBeRegularEvent ) then
320- weights [key ] = math.max (0 , value .tbl .weight - value .tbl .weight * value .tbl .goodness * DD .eventDirector .goodness )
321- end
322- if (value .tbl .minimunAlivePercentage > alivePercentage ) or (value .tbl .minimunDeadPercentage > deadPercentage ) then
323- weights [key ] = 0
336+ for key , eventClass in pairs (DD .eventDirector .eventPool ) do
337+ local weight = calculateEventWeight (eventClass )
338+ if weight > 0 then
339+ weights [key ] = weight
324340 end
325341 end
326342 -- Start event
@@ -330,7 +346,7 @@ DD.eventDirector.startNewEvent = function (isMainEvent)
330346 event .start (event )
331347
332348 if not event .failed then
333- DD .eventDirector .goodness = DD .eventDirector .goodness + event .goodness / 2
349+ DD .eventDirector .goodness = DD .eventDirector .goodness + event .goodness
334350 DD .eventDirector .cooldown = event .cooldown
335351 if isMainEvent then
336352 DD .eventDirector .mainEventCooldown = event .cooldown
@@ -377,23 +393,28 @@ DD.thinkFunctions.eventDirector = function ()
377393 if (DD .thinkCounter % 30 ~= 0 ) or (not Game .RoundStarted ) or (DD .roundData .roundEnding ) then return end
378394 local timesPerSecond = 2
379395
396+ -- get current cooldown value decrement amount
397+ local cooldownDecrement = math .round (DD .eventDirector .cooldownDecrementInitial + DD .roundTimer * DD .eventDirector .cooldownDecrementGrowth , 1 )
398+
399+ -- main event
380400 if (DD .eventDirector .mainEvent == nil ) and (DD .eventDirector .mainEventCooldown <= 0 ) then
381401 DD .eventDirector .startNewEvent (true )
382- DD .eventDirector .mainEventCooldown = 1
402+ DD .eventDirector .mainEventCooldown = 1 -- I don't know if this line is needed, but I rather play it safe
383403 else
384- DD .eventDirector .mainEventCooldown = DD .eventDirector .mainEventCooldown - 1 / timesPerSecond
404+ DD .eventDirector .mainEventCooldown = DD .eventDirector .mainEventCooldown - cooldownDecrement / timesPerSecond
385405 end
386406
407+ -- side/minor events
387408 if DD .eventDirector .cooldown <= 0 then
388409 DD .eventDirector .startNewEvent ()
389410 else
390- DD .eventDirector .cooldown = DD .eventDirector .cooldown - 1 / timesPerSecond
411+ DD .eventDirector .cooldown = DD .eventDirector .cooldown - cooldownDecrement / timesPerSecond
391412 end
392413end
393414
394415-- Called at round start
395416DD .roundStartFunctions .eventDirector = function ()
396- DD .eventDirector .goodness = - 3 -- negative goodness means lots of bad events happened, and thus event director will favour good events
417+ DD .eventDirector .goodness = 0
397418 DD .eventDirector .mainEvent = nil
398419 DD .eventDirector .events = {}
399420 DD .eventDirector .cooldown = 60 * 4
0 commit comments