Allow random effect utils to be filtered (#159)

This commit is contained in:
legokidlogan 2024-09-27 21:10:57 -06:00 committed by GitHub
parent 9231b0d252
commit 1998a73758
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -162,15 +162,24 @@ end
ply: (optional) (Player)
- If specified, will only return an effect that the player can receive.
- Will return nil if the player cannot receive any effects from this pool.
excludedEffects: (optional) (table)
- A lookup table from curse name to true, of effects to exclude from the draw pool.
- Case-sensitive, equivalent to effectData.nameUpper (e.g. "TopDown")
--]]
function CFCUlxCurse.GetRandomEffect( ply )
if not ply then
local id = math.random( #CFCUlxCurse.Effects )
function CFCUlxCurse.GetRandomEffect( ply, excludedEffects )
excludedEffects = excludedEffects or {}
return CFCUlxCurse.Effects[id]
local effectPool = {}
for _, effectData in ipairs( CFCUlxCurse.Effects ) do
if not excludedEffects[effectData.nameUpper] then
table.insert( effectPool, effectData )
end
end
return getRandomCompatibleEffect( ply, CFCUlxCurse.Effects )
if not ply then return effectPool[math.random( #effectPool )] end
return getRandomCompatibleEffect( ply, effectPool )
end
--[[
@ -180,20 +189,25 @@ end
ply: (optional) (Player)
- If specified, will only return an effect that the player can receive.
- Will return nil if the player cannot receive any effects from this pool.
excludedEffects: (optional) (table)
- A lookup table from curse name to true, of effects to exclude from the draw pool.
- Case-sensitive, equivalent to effectData.nameUpper (e.g. "TopDown")
--]]
function CFCUlxCurse.GetRandomOnetimeEffect( ply )
if not ply then
local id = onetimeEffectIDs[math.random( #onetimeEffectIDs )]
return CFCUlxCurse.Effects[id]
end
function CFCUlxCurse.GetRandomOnetimeEffect( ply, excludedEffects )
excludedEffects = excludedEffects or {}
local effectPool = {}
for i, id in ipairs( onetimeEffectIDs ) do
effectPool[i] = CFCUlxCurse.Effects[id]
for _, id in ipairs( onetimeEffectIDs ) do
local effectData = CFCUlxCurse.Effects[id]
if not excludedEffects[effectData.nameUpper] then
table.insert( effectPool, effectData )
end
end
if not ply then return effectPool[math.random( #effectPool )] end
return getRandomCompatibleEffect( ply, effectPool )
end