Codigo de Sobres JaroTCG
unknown
lua
a year ago
2.9 kB
10
Indexable
drop_slots = {
-- 1 Singular
{
total = 17, -- Cantidad total de Singulares
target = 1,
shuffle = {}
},
-- 2 Legendary
{
total = 57, -- Cantidad total de Legendarias
target = 1,
shuffle = {}
},
-- 3 Epic
{
total = 59, -- Cantidad total de Epicas
target = 1,
shuffle = {}
},
-- 4 Rare
{
total = 60, -- Cantidad total de Raras
target = 3,
shuffle = {}
},
-- 5 Common
{
total = 114, -- Cantidad total de Comunes
target = 6,
shuffle = {}
}
}
function onObjectLeaveContainer(container, leave_object)
if container ~= self then return end
local slot1legendary = true;
local slot2epic = true;
-- Calculate Chances
if (math.random(1, 4) == 1) then
-- First Slot will have an Epic
slot1legendary = false;
end
if (math.random(1, 4) == 1) then
-- Second Slot will have a Rare
slot2epic = false;
end
drop_slots[2].target = 0 + bool_to_number(slot1legendary)
drop_slots[3].target = 1 + bool_to_number(slot2epic) - bool_to_number(slot1legendary)
drop_slots[4].target = 4 - bool_to_number(slot2epic)
self.destruct() -- Destroy Card Pack
-- Shuffle Cards within their Rarities
total = 0
for k, v in pairs(drop_slots) do
-- offset indices
t = 0
for j = 1, v.total do
v.shuffle[j] = j - 1 + total
t = t + 1
end
total = total + t
-- do the actual suffle
v.shuffle = shuffleTable(v.shuffle)
end
-- Destroy remaining cards outside the target, within each rarity
for k, v in pairs(drop_slots) do
for j = 1, v.total - v.target do
destroyCardAtIndex(leave_object, v.shuffle[j])
end
end
end
function bool_to_number(value)
return value and 1 or 0
end
function destroyCardAtIndex(leave_object, index)
leave_object.takeObject({index = index}).destruct()
for k,v in pairs(drop_slots) do
decrementValuesGreaterThan(v.shuffle, index)
end
end
function decrementValuesGreaterThan(tbl, num)
local size = #tbl
for i = 1, size do
if tbl[i] > num then
tbl[i] = tbl[i] - 1
end
end
return tbl
end
function shuffleTable(tbl)
local size = #tbl
for i = size, 1, -1 do
local rand = math.random(i)
tbl[i], tbl[rand] = tbl[rand], tbl[i]
end
return tbl
endEditor is loading...
Leave a Comment