local newfruitmachine = {}

-- 下注按钮
newfruitmachine.BetIcon ={
    {
        ["id"] = 7,
        ["iconnormal"] = "fruit1_barnormal",
        ["iconclick"] = "fruit1_barclick",
        ["iconunclick"] = "fruit1_barunclick",
        ["BetRate"] = 100,
        ["clicksound"] = "cop_fruitmachine_bet_bar.wav",
    },
    {
        ["id"] = 6,
        ["iconnormal"] = "fruit1_7normal",
        ["iconclick"] = "fruit1_7click",
        ["iconunclick"] = "fruit1_7unclick",
        ["BetRate"] = 40,
        ["clicksound"] = "cop_fruitmachine_bet_7.wav",
    },
    {
        ["id"] = 5,
        ["iconnormal"] = "fruit1_xingxingnormal",
        ["iconclick"] = "fruit1_xingxingclick",
        ["iconunclick"] = "fruit1_xingxingunclick",
        ["BetRate"] = 30,
        ["clicksound"] = "cop_fruitmachine_bet_star.wav",
    },
    {
        ["id"] = 4,
        ["iconnormal"] = "fruit1_xiguanormal",
        ["iconclick"] = "fruit1_xiguaclick",
        ["iconunclick"] = "fruit1_xiguaunclick",
        ["BetRate"] = 25,
        ["clicksound"] = "cop_fruitmachine_bet_watermelon.wav",
    },
    {
        ["id"] = 3,
        ["iconnormal"] = "fruit1_lingdangnormal",
        ["iconclick"] = "fruit1_lingdangclick",
        ["iconunclick"] = "fruit1_lingdangunclick",
        ["BetRate"] = 20,
        ["clicksound"] = "cop_fruitmachine_bet_bell.wav",
    },
    {
        ["id"] = 2,
        ["iconnormal"] = "fruit1_ningmengnormal",
        ["iconclick"] = "fruit1_ningmengclick",
        ["iconunclick"] = "fruit1_ningmengunclick",
        ["BetRate"] = 15,
        ["clicksound"] = "cop_fruitmachine_bet_lemon.wav",
    },
    {
        ["id"] = 1,
        ["iconnormal"] = "fruit1_chengzinormal",
        ["iconclick"] = "fruit1_chengziclick",
        ["iconunclick"] = "fruit1_chengziunclick",
        ["BetRate"] = 10,
        ["clicksound"] = "cop_fruitmachine_bet_orange.wav",
    },
    {
        ["id"] = 0,
        ["iconnormal"] = "fruit1_pingguonormal",
        ["iconclick"] = "fruit1_pingguoclick",
        ["iconunclick"] = "fruit1_pingguounclick",
        ["BetRate"] = 5,
        ["clicksound"] = "cop_fruitmachine_bet_apple.wav",
    },
}

newfruitmachine.RaffleIcon = {
    {
        ["id"] = 3,
        ["icon"] = "fruit1_iconlingdang3",
        ["rateicon"] = nil,
        ["rate"] = 3,
        ["beticon"] = 3,
    },
    {
        ["id"] = 4,
        ["icon"] = "fruit1_iconchengzi",
        ["rateicon"] = nil,
        ["rate"] = 10,
        ["beticon"] = 1,
    },
    {
        ["id"] = 5,
        ["icon"] = "fruit1_iconlingdang",
        ["rateicon"] = nil,
        ["rate"] = 20,
        ["beticon"] = 3,
    },
    {
        ["id"] = 6,
        ["icon"] = "fruit1_iconbar50",
        ["rateicon"] = nil,
        ["rate"] = 50,
        ["beticon"] = 7,
    },
    {
        ["id"] = 7,
        ["icon"] = "fruit1_iconbar",
        ["rateicon"] = nil,
        ["rate"] = 100,
        ["beticon"] = 7,
    },
    {
        ["id"] = 8,
        ["icon"] = "fruit1_iconpingguo",
        ["rateicon"] = nil,
        ["rate"] = 5,
        ["beticon"] = 0,
    },
    {
        ["id"] = 9,
        ["icon"] = "fruit1_iconpingguo3",
        ["rateicon"] = nil,
        ["rate"] = 3,
        ["beticon"] = 0,
    },
    {
        ["id"] = 10,
        ["icon"] = "fruit1_iconningmeng",
        ["rateicon"] = nil,
        ["rate"] = 15,
        ["beticon"] = 2,
    },
    {
        ["id"] = 11,
        ["icon"] = "fruit1_iconxigua3",
        ["rateicon"] = nil,
        ["rate"] = 3,
        ["beticon"] = 4,
    },
    {
        ["id"] = 12,
        ["icon"] = "fruit1_iconxigua",
        ["rateicon"] = nil,
        ["rate"] = 25,
        ["beticon"] = 4,
    },
    {
        -- 蓝色lucky
        ["id"] = 13,
        ["icon"] = "fruit1_iconlucky",
        ["rateicon"] = nil,
        ["iconbg"] = "fruit1_shuiguodi2",
        ["rate"] = 31,
    },
    {
        ["id"] = 14,
        ["icon"] = "fruit1_iconpingguo",
        ["rateicon"] = nil,
        ["rate"] = 5,
        ["beticon"] = 0,
    },
    {
        ["id"] = 15,
        ["icon"] = "fruit1_iconchengzi3",
        ["rateicon"] = nil,
        ["rate"] = 3,
        ["beticon"] = 1,
    },
    {
        ["id"] = 16,
        ["icon"] = "fruit1_iconchengzi",
        ["rateicon"] = nil,
        ["rate"] = 10,
        ["beticon"] = 1,
    },
    {
        ["id"] = 17,
        ["icon"] = "fruit1_iconlingdang",
        ["rateicon"] = nil,
        ["rate"] = 20,
        ["beticon"] = 3,
    },
    {
        ["id"] = 18,
        ["icon"] = "fruit1_icon73",
        ["rateicon"] = nil,
        ["rate"] = 3,
        ["beticon"] = 6,
    },
    {
        ["id"] = 19,
        ["icon"] = "fruit1_icon7",
        ["rateicon"] = nil,
        ["rate"] = 40,
        ["beticon"] = 6,
    },
    {
        ["id"] = 20,
        ["icon"] = "fruit1_iconpingguo",
        ["rateicon"] = nil,
        ["rate"] = 5,
        ["beticon"] = 0,
    },
    {
        ["id"] = 21,
        ["icon"] = "fruit1_iconningmeng3",
        ["rateicon"] = nil,
        ["rate"] = 3,
        ["beticon"] = 2,
    },
    {
        ["id"] = 22,
        ["icon"] = "fruit1_iconningmeng",
        ["rateicon"] = nil,
        ["rate"] = 15,
        ["beticon"] = 2,
    },
    {
        ["id"] = 23,
        ["icon"] = "fruit1_iconxingxing",
        ["rateicon"] = nil,
        ["rate"] = 30,
        ["beticon"] = 5,
    },
    {
        ["id"] = 24,
        ["icon"] = "fruit1_iconxingxing3",
        ["rateicon"] = nil,
        ["rate"] = 3,
        ["beticon"] = 5,
    },
    {
        -- 黑色lucky
        ["id"] = 1,
        ["icon"] = "fruit1_iconlucky",
        ["rateicon"] = nil,
        ["iconbg"] = "fruit1_shuiguodi3",
        ["rate"] = 2,
    },
    {
        ["id"] = 2,
        ["icon"] = "fruit1_iconpingguo",
        ["rateicon"] = nil,
        ["rate"] = 5,
        ["beticon"] = 0,
    },
}

newfruitmachine.BetPool = {
    ["Gold"] = {
        {
            ["money"] = 10000,
            ["id"] = 1,
            ["nIndex"] = 1,
        },
        {
            ["money"] = 100000,
            ["id"] = 2,
            ["nIndex"] = 2,
        },
        {
            ["money"] = 1000000,
            ["id"] = 3,
            ["nIndex"] = 3,
        },
        {
            ["money"] = 10000000,
            ["id"] = 4,
            ["nIndex"] = 4,
        },
        {
            ["money"] = 100000000,
            ["id"] = 5,
            ["nIndex"] = 5,
        },
    },
    ["EMoney"] = {
        {
            ["money"] = 1,
            ["id"] = 1,
            ["nIndex"] = 1,
        },
        {
            ["money"] = 5,
            ["id"] = 2,
            ["nIndex"] = 2,
        },
        {
            ["money"] = 10,
            ["id"] = 3,
            ["nIndex"] = 3,
        },
        {
            ["money"] = 50,
            ["id"] = 4,
            ["nIndex"] = 4,
        },
        {
            ["money"] = 100,
            ["id"] = 5,
            ["nIndex"] = 5,
        },
    }
}

newfruitmachine.BetResultInfo = {
    {
        -- 大苹果事件
        ["id"] = 1,
        ["eventtype"] = 1,
        ["subevent"] = 1,
    },
    {
        -- 大苹果事件
        ["id"] = 2,
        ["eventtype"] = 1,
        ["subevent"] = 2,
    },
    {
        -- 黑色lucky
        ["id"] = 3,
        ["eventtype"] = 2,
        ["subevent"] = 1,
    },
    {
        -- 黑色lucky
        ["id"] = 4,
        ["eventtype"] = 2,
        ["subevent"] = 2,
    },
    {
        -- 黑色lucky
        ["id"] = 5,
        ["eventtype"] = 2,
        ["subevent"] = 3,
    },
    {
        -- 黑色lucky
        ["id"] = 6,
        ["eventtype"] = 2,
        ["subevent"] = 4,
    },
    {
        -- 黑色lucky
        ["id"] = 7,
        ["eventtype"] = 2,
        ["subevent"] = 5,
    },
    {
        -- 蓝色lucky 仙女散花
        ["id"] = 8,
        ["eventtype"] = 3,
        ["subevent"] = 1,
    },
    {
        -- 蓝色lucky 天龙八部
        ["id"] = 9,
        ["eventtype"] = 3,
        ["subevent"] = 2,
    },
    {
        -- 蓝色lucky 九堡莲灯
        ["id"] = 10,
        ["eventtype"] = 3,
        ["subevent"] = 3,
    },
    {
        -- 蓝色lucky 大满贯
        ["id"] = 11,
        ["eventtype"] = 3,
        ["subevent"] = 4,
    },
    {
        -- 隐藏lucky 小三元
        ["id"] = 12,
        ["eventtype"] = 4,
        ["subevent"] = 1,
    },
    {
        -- 隐藏lucky 大三元
        ["id"] = 13,
        ["eventtype"] = 4,
        ["subevent"] = 2,
    },
    {
        -- 隐藏lucky 纵横四海1
        ["id"] = 14,
        ["eventtype"] = 4,
        ["subevent"] = 3,
    },
    {
        -- 隐藏lucky 纵横四海2
        ["id"] = 15,
        ["eventtype"] = 4,
        ["subevent"] = 3,
    },
    {
        -- 隐藏lucky 纵横四海3
        ["id"] = 16,
        ["eventtype"] = 4,
        ["subevent"] = 3,
    },
    {
        -- 隐藏lucky 开火车
        ["id"] = 17,
        ["eventtype"] = 4,
        ["subevent"] = 4,
    },
}

-- type  1:金币 2:天石
newfruitmachine.MachineType = {
    [33128] = {
        ["type"] = 1,
    },
    [33129] = {
        ["type"] = 2,
    }
}

newfruitmachine.GetSuitableId = function(i64Money, bGold)
    if bGold then
        if i64Money <= 10000000 then
            return 1;
        elseif i64Money <= 100000000 then
            return 2;
        elseif i64Money <= 1000000000 then
            return 3;
        elseif i64Money <= 10000000000 then
            return 4;
        else
            return 5;
        end
    else
        if i64Money <= 1 then
            return 1;
        elseif i64Money <= 5 then
            return 2;
        elseif i64Money <= 10 then
            return 3;
        elseif i64Money <= 50 then
            return 4;
        else
            return 5;
        end
    end
end

newfruitmachine.GetIdPoolIndex = function (idPool, bGold)
    local strKey = "";
    if bGold then
        strKey = "Gold"
    else
        strKey = "EMoney"
    end

    for k, v in pairs(newfruitmachine.BetPool) do
        if k == strKey then
            for i = 1, #v do
                if v[i]["id"] == idPool then
                    return v[i]["nIndex"];
                end
            end
        end
    end

    return 0;
end

newfruitmachine.GetIdRaffleIndex = function (idIcon)
    if idIcon == 25 then
        local index = math.random(1,24);
        if index == 23 or index == 11 then
            return index + 1;
        end

        return index
    end

    for k, v in pairs(newfruitmachine.RaffleIcon) do
        if v and v["id"] == idIcon then
            return k
        end
    end
end

newfruitmachine.GetIdRaffleIconRate = function (idIcon)
    for k, v in pairs(newfruitmachine.RaffleIcon) do
        if v and v["id"] == idIcon then
            return v["rate"]
        end
    end
end

newfruitmachine.GetRaffleIconToBetId = function (idIcon)
    for k, v in pairs(newfruitmachine.RaffleIcon) do
        if v and v["id"] == idIcon then
            return v["beticon"]
        end
    end
end

newfruitmachine.GetBetIconCount = function ()
    return #newfruitmachine.BetIcon;
end

newfruitmachine.GetBetIconId = function (nIndex)
    local tbValue = newfruitmachine.BetIcon[nIndex];
    if tbValue == nil then
        return 0;
    end

    return tbValue["id"];
end

newfruitmachine.BetIconSound = {
    [0] = "sound/cop_fruitmachine_award_apple.wav",
    [1] = "sound/cop_fruitmachine_award_orange.wav",
    [2] = "sound/cop_fruitmachine_award_lemon.wav",
    [3] = "sound/cop_fruitmachine_award_bell.wav",
    [4] = "sound/cop_fruitmachine_award_watermelon.wav",
    [5] = "sound/cop_fruitmachine_award_star.wav",
    [6] = "sound/cop_fruitmachine_award_7.wav",
    [7] = "sound/cop_fruitmachine_award_bar.wav",
}

newfruitmachine.GetRewardIdPlaySound = function(nRewardId)
    local nTargetId = nil;
    for k, v in pairs(newfruitmachine.RaffleIcon) do
        if v and v["id"] == nRewardId then
            nTargetId = v["beticon"];
        end
    end

    if nTargetId == nil then
        return nil;
    end

    return newfruitmachine.BetIconSound[nTargetId];
end

newfruitmachine.GetMachineType = function(idnpc)
    if newfruitmachine.MachineType[idnpc] ~= nil then
        return newfruitmachine.MachineType[idnpc]["type"]
    end
end

return newfruitmachine