Roll function by Loleris

https://twitter.com/LM_loleris/status/1463892208478822403?cxt=HHwWhoC9vaSN5dAoAAAA
mail@pastecode.io avatar
unknown
lua
2 years ago
403 B
236
Indexable
Never
local function roll(t, _a, _b)
	return  _a
		and (_a > 0
			and -math.random(1, _a)
			or _a < 0
			and (select(2, next(t, _b)) >= -_a
				and next(t, _b)
				or roll(t, _a + select(2, next(t, _b)), next(t, _b)))
			or (next(t, _b)
				and select(2, next(t, _b)) + roll(t, 0, next(t, _b))
				or 0))
		or roll(t, roll(t, roll(t, 0)))
end
print(roll({Common = 80, Rare = 15, Legendary = 5}))