Jaro TCG - Tabletop Sobre (Actualizado #2)

 avatar
unknown
lua
6 months ago
3.5 kB
6
Indexable
drop_slots = {
    -- 1 Singular
    {
        total = 17, -- Cantidad total de Singulares
        target = 1,
        shuffle = {}
    },
    -- 2 Alternative
    {
        total = 0, -- Cantidad total de Alternativas
        target = 0,
        shuffle = {}
    }, 
    -- 3 Legendary
    {
        total = 57, -- Cantidad total de Legendarias
        target = 0,
        shuffle = {}
    }, 
    -- 4 Epic
    {
        total = 59, -- Cantidad total de Epicas
        target = 1,
        shuffle = {}
    }, 
    -- 5 Rare
    {
        total = 60, -- Cantidad total de Raras
        target = 3,
        shuffle = {}
    }, 
    -- 6 Common
    {
        total = 114, -- Cantidad total de Comunes
        target = 6,
        shuffle = {}
    } 
    }

    function filterObjectEnter(enter_object)
        -- false = no objects can enter
        return false
      end
    
    function onObjectLeaveContainer(container, leave_object)
        if container ~= self then return end
    
        local slot2Alternative = false;
        local slot2legendary = false;
        local slot3epic = false;

        -- Calculate Chances
        if (math.random(1, 20) == 1) then
            -- Second Slot Will Have An Alternative
            drop_slots[2].target = 1
            slot2Alternative = true
        elseif (math.random(1, 4) ~= 1) then
                -- Second Slot will have a Legendary, if not Epic
                drop_slots[3].target = 1
                slot2legendary = true
        end
    
        if (math.random(1, 4) ~= 1) then
            -- Third Slot will have an Epic, if not Rare
            slot3epic = true;
        end

        drop_slots[4].target = 1 + bool_to_number(slot3epic) - bool_to_number(slot2legendary) - bool_to_number(slot2Alternative)
        drop_slots[5].target = 4 - bool_to_number(slot3epic)
    
        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
    end
Editor is loading...
Leave a Comment