前端UI展示:GUILayout\F\合成面板.lua

Hecheng = {}

local _cfg = cfg_compound

local GUIparent = ""

local wnd_w, wnd_h = 815, 575

local page1 

local _color = {
    ["true"] = "#787974",
    ["false"] = "#DEBA6C",
}

Hecheng.main = function()
    local _parent = GUI:Win_Create ( "Hecheng", 0, 0, 0, 0, true, false, true, true)
    if _parent then 
        GUIparent = _parent
        winSize = SL:GetScreenSize()
        local x = winSize.width  / 2
        local y = winSize.height / 2
        local w = winSize.width 
        local h = winSize.height

        --设置透明关闭按钮
        local handle = GUI:Layout_Create(_parent, "layout_close", x, y, w, h)
        
        if handle then 
            GUI:Layout_setBackGroundColor(handle, "#000000")
            GUI:Layout_setBackGroundColorType(handle, 1)
            GUI:Layout_setBackGroundColorOpacity(handle, 95)
            GUI:setAnchorPoint(handle, 0.5, 0.5)
            
            GUI:setTouchEnabled(handle, true)
            GUI:addOnClickEvent(handle, function()
                GUI:Win_Close(_parent)
            end)
        end
        --NPC背景
        local img_bg = GUI:Image_Create( _parent,  "img_bg", x, y, "res/01/010000.png")
        if img_bg then 
            GUI:setAnchorPoint(img_bg, 0.5, 0.5)
            GUI:setContentSize(img_bg, {width = wnd_w, height = wnd_h})
            GUI:setTouchEnabled(img_bg, true)

        end
        --关闭按钮
        local btn_close = GUI:Button_Create( img_bg, "btn_close", wnd_w-25, wnd_h-20, "res/01/010008.png")
        if btn_close then
            GUI:setAnchorPoint(btn_close, 1, 1)
            GUI:Button_loadTexturePressed(btn_close, "res/01/010009.png")
            GUI:addOnClickEvent(btn_close, function ()
                GUI:Win_Close(_parent)
            end)
        end

        local img_line = GUI:Image_Create( img_bg, "img_line", 190, 20, "res/custom/common/img_line_1.png")
        local txt_title = GUI:Text_Create(img_bg, "txt_title", wnd_w / 2, wnd_h - 50, 20, "#D6C6AD", "合  成")
        GUI:setAnchorPoint(txt_title, 0.5, 0.5)

        --左侧列表
        local left_listview = GUI:ListView_Create(img_bg, "left_listview", 130, 0, 116, wnd_h - 120, 1)
        if left_listview then 
            GUI:setAnchorPoint(left_listview, 0.5, 0)
            GUI:ListView_setItemsMargin(left_listview, 10)
            GUI:ListView_setClippingEnabled(left_listview, true)
            GUI:ListView_setDirection(left_listview, 1)
            for i, v in ipairs(_cfg) do 
                local btn_hc = GUI:Button_Create( left_listview, "btn_hc" .. i, 0, 0, "res/01/010005.png")

                if btn_hc then 
                    local txt_btn = GUI:Text_Create(btn_hc, "txt_btn" .. i, 55, 6, 20 , "#787974", v.title)
                    GUI:setAnchorPoint(txt_btn, 0.5, 0)
                    GUI:Button_loadTexturePressed(btn_hc, "res/01/010006.png")
                    GUI:Button_loadTextureDisabled(btn_hc, "res/01/010006.png")
                end

                GUI:addOnClickEvent(btn_hc, function ()
                    Hecheng.updatePage(i)
                end)

                if i == 1 then 
                    Hecheng.updatePage(1)
                end             
            end
        end
    end

end

--右侧合成按钮展示
function Hecheng.updatePage(index)
    
    if index == page1 then return end

    --取消上次选中按钮
    if page1 then
        local btn_select = GUI:GetWindow(GUIparent, "img_bg/left_listview/btn_hc" .. page1 )
        local txt_btn = GUI:GetWindow(btn_select, "txt_btn" .. page1 )
        GUI:Button_setBrightEx(btn_select, true)  --取消选择状态
        GUI:Text_setTextColor(txt_btn, _color["true"])
    end

    --新的按钮选中状态
    local btn_select = GUI:GetWindow(GUIparent, "img_bg/left_listview/btn_hc" .. index )
    if btn_select then 
        local txt_btn = GUI:GetWindow(btn_select, "txt_btn" .. index )
        GUI:Button_setBrightEx(btn_select, false)
        GUI:Text_setTextColor(txt_btn, _color["false"])
        
    end
    --全局变量保存当前选中按钮,方便下次切换时判断
    page1 = index
    Hecheng.updateUI(index)
end

local imgUI = {}

--刷新合成页面
function Hecheng.updateUI(index)
    
    local _parent = GUI:GetWindow(GUIparent, "img_bg")
    local right_list = GUI:GetWindow(_parent, "right_list")
    if not right_list then 
        right_list = GUI:ListView_Create( _parent, "right_list",  195, 445 / 2 + 15, 560,445, 1)
        GUI:setAnchorPoint(right_list, 0,0.5)
        GUI:ListView_setClippingEnabled(right_list,true)
        GUI:ListView_setItemsMargin(right_list, 15)
    end

    GUI:removeAllChildren(right_list)

    local cfg = _cfg[page1]
    local max = #cfg 
    local limit = 2
    local num = math.ceil(max/limit) --循环的行数
    local idx = 0
    local item_w, item_h = 270, 190

    for i = 1, num do 
        
        local handle = GUI:Layout_Create( right_list, "layout_item_" .. i, 0, 0, item_w * limit + 10, item_h + 10) --每行 创建个容器
        GUI:setAnchorPoint(handle, 0.5, 0.5)
        GUI:setTouchEnabled(handle, true)
        -- GUI:Layout_setBackGroundColor(handle, "#4AE74A")
        -- GUI:Layout_setBackGroundColorType(handle, 1)
        -- GUI:Layout_setBackGroundColorOpacity(handle, 155)
        for j = 1, limit do --创建2个背景图
            idx = idx + 1
            if idx <= max then --保存创建的背景图和合成物品个数相同,避免多建
                local _handle = GUI:Image_Create( handle, "item_" .. j,  (j - 1) * (item_w + 7) + 5, 5, "res/custom/common/bg_hhdb_02.jpg")
                if _handle then 
                    GUI:Image_setScale9Slice(_handle, 10, 10, 10, 10)
                    GUI:setAnchorPoint(_handle, 0,0)
                    GUI:setContentSize(_handle, {width = item_w, height = item_h})
                    GUI:setTouchEnabled(_handle, true)
                    imgUI["item_"..idx] = _handle  --保存在imgUI中
                end
                
            end 

        end
    end


    for i, v in ipairs(cfg) do
        -- SL:Print("index === ".. i)
        local _fahandle =  imgUI["item_" .. i]
        local item_name = SL:GetItemNameByIndex(v.product[1][1])
        
        local handle = GUI:Text_Create(_fahandle, "txt_title", item_w/2, item_h - 20, 18, "#D6C6AD", item_name)
        if handle then
            GUI:setAnchorPoint(handle, 0.5, 0.5)
        end
        
        handle = GUI:Image_Create( _fahandle, "item_bg" .. i, 30, 70, "res/custom/common/object_di_1.png")
        if handle then 
            GUI:setScale(handle, 0.9)
        end

        GUI:ItemShow_Create(_fahandle, "item" .. i, 30, 70, {index = v.product[1][1], look = true})
        GUI:RichText_Create(_fahandle, "txt_pro" .. i, 10, 30, "成功率:"..v.probability/100 .. "%", 200, 16,  "#D6C6AD")
        handle = GUI:Button_Create( _fahandle, "page1_" .. i, 130, 20, "res/01/010005.png")

        if handle then 
            local txt_handle = GUI:Text_Create(handle, "Go", 55, 5, 18, "#FFFFB7", "合  成")
            GUI:setAnchorPoint(txt_handle, 0.5, 0)
            GUI:addOnClickEvent(handle, function()
                Hecheng.go(v.idx)
            end)
        end

        local x, y = 185, 120
        for j, var in ipairs(v.itemid1) do
            local bag_num = SL:GetItemNumberByIndex(var[1])
            local cost_num = var[2]
            local cost_name = SL:GetItemNameByIndex(var[1])
            local str = SLChangeColour(bag_num, cost_num, cost_name)
            local handle = GUI:RichText_Create(_fahandle, "txt_need" .. j, x, y, str, 265)
            y = y -30
            GUI:setAnchorPoint(handle, 0.5,0.5)
        end

    end
    

end

Hecheng.go = function(index)
    SL:SubmitForm("F/合成表单","main",index)
end

Hecheng.main()

    使用到的方法:GUILayout\A\GUIinit.lua

    --转换单位 10000 = 1万
    function SLUnitBase(strnum)
    
        if strnum >= 10000 and  strnum < 100000000 then
            strnum = math.floor(strnum*0.001)*0.1
            strnum = tostring(strnum).."万"
        elseif strnum >= 100000000 then
            strnum = math.floor(strnum*0.0000001)*0.1
            strnum = tostring(strnum).."亿"
        end
    
        return strnum
    end
    
    
    
    --元宝:100/1000 (strdes:Anum/Bnum)
    function SLChangeColour(Anum,Bnum,strdes)
        local a = "<font color='#E1BD70' size='16'>%s</font><font color='#C0C0C0' size='16'></font><font color='#4AE74A' size='16'>%s</font>"
        local b = "<font color='#E1BD70' size='16'>%s</font><font color='#C0C0C0' size='16'></font><font color='#FF0000' size='16'>%s</font>"
        local rtext_str = ""
        local A = SLUnitBase(Anum)
        local B = SLUnitBase(Bnum)
    
        if Anum >= Bnum then
            rtext_str = string.format(a, strdes,A.."/"..B)
        else
            rtext_str = string.format(b, strdes,A.."/"..B)
        end
    
        return rtext_str
    end

      配置文件

      local config = {
      	[1] = {
      		type = 1,
      		page1 = 1,
      		page2 = 1,
      		condition = 10001,
      		page3 = 1,
      		condition2 = 10001,
      		itemid1 = {
      			[1] = {
      				[1] = 8000101,
      				[2] = 3,
      			},
      			[2] = {
      				[1] = 4,
      				[2] = 10000,
      			},
      		},
      		product = {
      			[1] = {
      				[1] = 8000102,
      				[2] = 1,
      			},
      		},
      		name2 = "红宝石",
      		probability = 10000,
      	},
      	[2] = {
      		type = 1,
      		page1 = 1,
      		page2 = 1,
      		condition = 10001,
      		page3 = 2,
      		condition2 = 10001,
      		itemid1 = {
      			[1] = {
      				[1] = 8000102,
      				[2] = 3,
      			},
      			[2] = {
      				[1] = 4,
      				[2] = 20000,
      			},
      		},
      		product = {
      			[1] = {
      				[1] = 8000103,
      				[2] = 1,
      			},
      		},
      		name2 = "红宝石",
      		probability = 10000,
      	},
      	[3] = {
      		type = 1,
      		page1 = 1,
      		page2 = 1,
      		condition = 10001,
      		page3 = 3,
      		condition2 = 10001,
      		itemid1 = {
      			[1] = {
      				[1] = 8000103,
      				[2] = 3,
      			},
      			[2] = {
      				[1] = 4,
      				[2] = 50000,
      			},
      		},
      		product = {
      			[1] = {
      				[1] = 8000104,
      				[2] = 1,
      			},
      		},
      		name2 = "红宝石",
      		probability = 10000,
      	},
      	[4] = {
      		type = 1,
      		page1 = 1,
      		page2 = 1,
      		condition = 10001,
      		page3 = 4,
      		condition2 = 10001,
      		itemid1 = {
      			[1] = {
      				[1] = 8000104,
      				[2] = 2,
      			},
      			[2] = {
      				[1] = 4,
      				[2] = 100000,
      			},
      		},
      		product = {
      			[1] = {
      				[1] = 8000105,
      				[2] = 1,
      			},
      		},
      		name2 = "红宝石",
      		probability = 10000,
      	},
      	[5] = {
      		type = 1,
      		page1 = 1,
      		page2 = 1,
      		condition = 10001,
      		page3 = 5,
      		condition2 = 10001,
      		itemid1 = {
      			[1] = {
      				[1] = 8000105,
      				[2] = 2,
      			},
      			[2] = {
      				[1] = 4,
      				[2] = 200000,
      			},
      		},
      		product = {
      			[1] = {
      				[1] = 8000106,
      				[2] = 1,
      			},
      		},
      		name2 = "红宝石",
      		probability = 10000,
      	},
      	[6] = {
      		type = 1,
      		page1 = 1,
      		page2 = 1,
      		condition = 10001,
      		page3 = 6,
      		condition2 = 10001,
      		itemid1 = {
      			[1] = {
      				[1] = 8000106,
      				[2] = 2,
      			},
      			[2] = {
      				[1] = 4,
      				[2] = 400000,
      			},
      		},
      		product = {
      			[1] = {
      				[1] = 8000107,
      				[2] = 1,
      			},
      		},
      		name2 = "红宝石",
      		probability = 10000,
      	},
      	[7] = {
      		type = 1,
      		page1 = 1,
      		page2 = 1,
      		condition = 10001,
      		page3 = 7,
      		condition2 = 10001,
      		itemid1 = {
      			[1] = {
      				[1] = 8000107,
      				[2] = 2,
      			},
      			[2] = {
      				[1] = 4,
      				[2] = 800000,
      			},
      		},
      		product = {
      			[1] = {
      				[1] = 8000108,
      				[2] = 1,
      			},
      		},
      		name2 = "红宝石",
      		probability = 10000,
      	},
      	[8] = {
      		type = 1,
      		page1 = 1,
      		page2 = 2,
      		condition = 10001,
      		page3 = 1,
      		condition2 = 10001,
      		itemid1 = {
      			[1] = {
      				[1] = 8000201,
      				[2] = 3,
      			},
      			[2] = {
      				[1] = 4,
      				[2] = 10000,
      			},
      		},
      		product = {
      			[1] = {
      				[1] = 8000202,
      				[2] = 1,
      			},
      		},
      		name2 = "黄宝石",
      		probability = 10000,
      	},
      	[9] = {
      		type = 1,
      		page1 = 1,
      		page2 = 2,
      		condition = 10001,
      		page3 = 2,
      		condition2 = 10001,
      		itemid1 = {
      			[1] = {
      				[1] = 8000202,
      				[2] = 3,
      			},
      			[2] = {
      				[1] = 4,
      				[2] = 20000,
      			},
      		},
      		product = {
      			[1] = {
      				[1] = 8000203,
      				[2] = 1,
      			},
      		},
      		name2 = "黄宝石",
      		probability = 10000,
      	},
      	[10] = {
      		type = 1,
      		page1 = 1,
      		page2 = 2,
      		condition = 10001,
      		page3 = 3,
      		condition2 = 10001,
      		itemid1 = {
      			[1] = {
      				[1] = 8000203,
      				[2] = 3,
      			},
      			[2] = {
      				[1] = 4,
      				[2] = 50000,
      			},
      		},
      		product = {
      			[1] = {
      				[1] = 8000204,
      				[2] = 1,
      			},
      		},
      		name2 = "黄宝石",
      		probability = 10000,
      	},
      	[11] = {
      		type = 1,
      		page1 = 1,
      		page2 = 2,
      		condition = 10001,
      		page3 = 4,
      		condition2 = 10001,
      		itemid1 = {
      			[1] = {
      				[1] = 8000204,
      				[2] = 2,
      			},
      			[2] = {
      				[1] = 4,
      				[2] = 100000,
      			},
      		},
      		product = {
      			[1] = {
      				[1] = 8000205,
      				[2] = 1,
      			},
      		},
      		name2 = "黄宝石",
      		probability = 10000,
      	},
      	[12] = {
      		type = 1,
      		page1 = 1,
      		page2 = 2,
      		condition = 10001,
      		page3 = 5,
      		condition2 = 10001,
      		itemid1 = {
      			[1] = {
      				[1] = 8000205,
      				[2] = 2,
      			},
      			[2] = {
      				[1] = 4,
      				[2] = 200000,
      			},
      		},
      		product = {
      			[1] = {
      				[1] = 8000206,
      				[2] = 1,
      			},
      		},
      		name2 = "黄宝石",
      		probability = 10000,
      	},
      	[13] = {
      		type = 1,
      		page1 = 1,
      		page2 = 2,
      		condition = 10001,
      		page3 = 6,
      		condition2 = 10001,
      		itemid1 = {
      			[1] = {
      				[1] = 8000206,
      				[2] = 2,
      			},
      			[2] = {
      				[1] = 4,
      				[2] = 400000,
      			},
      		},
      		product = {
      			[1] = {
      				[1] = 8000207,
      				[2] = 1,
      			},
      		},
      		name2 = "黄宝石",
      		probability = 10000,
      	},
      	[14] = {
      		type = 1,
      		page1 = 1,
      		page2 = 2,
      		condition = 10001,
      		page3 = 7,
      		condition2 = 10001,
      		itemid1 = {
      			[1] = {
      				[1] = 8000207,
      				[2] = 2,
      			},
      			[2] = {
      				[1] = 4,
      				[2] = 800000,
      			},
      		},
      		product = {
      			[1] = {
      				[1] = 8000208,
      				[2] = 1,
      			},
      		},
      		name2 = "黄宝石",
      		probability = 10000,
      	},
      	[15] = {
      		type = 1,
      		page1 = 1,
      		page2 = 3,
      		condition = 10001,
      		page3 = 1,
      		condition2 = 10001,
      		itemid1 = {
      			[1] = {
      				[1] = 8000301,
      				[2] = 3,
      			},
      			[2] = {
      				[1] = 4,
      				[2] = 10000,
      			},
      		},
      		product = {
      			[1] = {
      				[1] = 8000302,
      				[2] = 1,
      			},
      		},
      		name2 = "绿宝石",
      		probability = 10000,
      	},
      	[16] = {
      		type = 1,
      		page1 = 1,
      		page2 = 3,
      		condition = 10001,
      		page3 = 2,
      		condition2 = 10001,
      		itemid1 = {
      			[1] = {
      				[1] = 8000302,
      				[2] = 3,
      			},
      			[2] = {
      				[1] = 4,
      				[2] = 20000,
      			},
      		},
      		product = {
      			[1] = {
      				[1] = 8000303,
      				[2] = 1,
      			},
      		},
      		name2 = "绿宝石",
      		probability = 10000,
      	},
      	[17] = {
      		type = 1,
      		page1 = 1,
      		page2 = 3,
      		condition = 10001,
      		page3 = 3,
      		condition2 = 10001,
      		itemid1 = {
      			[1] = {
      				[1] = 8000303,
      				[2] = 3,
      			},
      			[2] = {
      				[1] = 4,
      				[2] = 50000,
      			},
      		},
      		product = {
      			[1] = {
      				[1] = 8000304,
      				[2] = 1,
      			},
      		},
      		name2 = "绿宝石",
      		probability = 10000,
      	},
      	[18] = {
      		type = 1,
      		page1 = 1,
      		page2 = 3,
      		condition = 10001,
      		page3 = 4,
      		condition2 = 10001,
      		itemid1 = {
      			[1] = {
      				[1] = 8000304,
      				[2] = 2,
      			},
      			[2] = {
      				[1] = 4,
      				[2] = 100000,
      			},
      		},
      		product = {
      			[1] = {
      				[1] = 8000305,
      				[2] = 1,
      			},
      		},
      		name2 = "绿宝石",
      		probability = 10000,
      	},
      	[19] = {
      		type = 1,
      		page1 = 1,
      		page2 = 3,
      		condition = 10001,
      		page3 = 5,
      		condition2 = 10001,
      		itemid1 = {
      			[1] = {
      				[1] = 8000305,
      				[2] = 2,
      			},
      			[2] = {
      				[1] = 4,
      				[2] = 200000,
      			},
      		},
      		product = {
      			[1] = {
      				[1] = 8000306,
      				[2] = 1,
      			},
      		},
      		name2 = "绿宝石",
      		probability = 10000,
      	},
      	[20] = {
      		type = 1,
      		page1 = 1,
      		page2 = 3,
      		condition = 10001,
      		page3 = 6,
      		condition2 = 10001,
      		itemid1 = {
      			[1] = {
      				[1] = 8000306,
      				[2] = 2,
      			},
      			[2] = {
      				[1] = 4,
      				[2] = 400000,
      			},
      		},
      		product = {
      			[1] = {
      				[1] = 8000307,
      				[2] = 1,
      			},
      		},
      		name2 = "绿宝石",
      		probability = 10000,
      	},
      	[21] = {
      		type = 1,
      		page1 = 1,
      		page2 = 3,
      		condition = 10001,
      		page3 = 7,
      		condition2 = 10001,
      		itemid1 = {
      			[1] = {
      				[1] = 8000307,
      				[2] = 2,
      			},
      			[2] = {
      				[1] = 4,
      				[2] = 800000,
      			},
      		},
      		product = {
      			[1] = {
      				[1] = 8000308,
      				[2] = 1,
      			},
      		},
      		name2 = "绿宝石",
      		probability = 10000,
      	},
      	[22] = {
      		type = 1,
      		page1 = 1,
      		page2 = 4,
      		condition = 10001,
      		page3 = 1,
      		condition2 = 10001,
      		itemid1 = {
      			[1] = {
      				[1] = 8000401,
      				[2] = 2,
      			},
      			[2] = {
      				[1] = 4,
      				[2] = 20000,
      			},
      		},
      		product = {
      			[1] = {
      				[1] = 8000402,
      				[2] = 1,
      			},
      		},
      		name2 = "珊瑚石",
      		probability = 10000,
      	},
      	[23] = {
      		type = 1,
      		page1 = 1,
      		page2 = 4,
      		condition = 10001,
      		page3 = 2,
      		condition2 = 10001,
      		itemid1 = {
      			[1] = {
      				[1] = 8000402,
      				[2] = 2,
      			},
      			[2] = {
      				[1] = 4,
      				[2] = 40000,
      			},
      		},
      		product = {
      			[1] = {
      				[1] = 8000403,
      				[2] = 1,
      			},
      		},
      		name2 = "珊瑚石",
      		probability = 10000,
      	},
      	[24] = {
      		type = 1,
      		page1 = 1,
      		page2 = 4,
      		condition = 10001,
      		page3 = 3,
      		condition2 = 10001,
      		itemid1 = {
      			[1] = {
      				[1] = 8000403,
      				[2] = 2,
      			},
      			[2] = {
      				[1] = 4,
      				[2] = 80000,
      			},
      		},
      		product = {
      			[1] = {
      				[1] = 8000404,
      				[2] = 1,
      			},
      		},
      		name2 = "珊瑚石",
      		probability = 10000,
      	},
      	[25] = {
      		type = 1,
      		page1 = 1,
      		page2 = 4,
      		condition = 10001,
      		page3 = 4,
      		condition2 = 10001,
      		itemid1 = {
      			[1] = {
      				[1] = 8000404,
      				[2] = 2,
      			},
      			[2] = {
      				[1] = 4,
      				[2] = 1600000,
      			},
      		},
      		product = {
      			[1] = {
      				[1] = 8000405,
      				[2] = 1,
      			},
      		},
      		name2 = "珊瑚石",
      		probability = 10000,
      	},
      	[26] = {
      		type = 1,
      		page1 = 1,
      		page2 = 5,
      		condition = 10001,
      		page3 = 1,
      		condition2 = 10001,
      		itemid1 = {
      			[1] = {
      				[1] = 8000501,
      				[2] = 2,
      			},
      			[2] = {
      				[1] = 4,
      				[2] = 20000,
      			},
      		},
      		product = {
      			[1] = {
      				[1] = 8000502,
      				[2] = 1,
      			},
      		},
      		name2 = "琉璃石",
      		probability = 10000,
      	},
      	[27] = {
      		type = 1,
      		page1 = 1,
      		page2 = 5,
      		condition = 10001,
      		page3 = 2,
      		condition2 = 10001,
      		itemid1 = {
      			[1] = {
      				[1] = 8000502,
      				[2] = 2,
      			},
      			[2] = {
      				[1] = 4,
      				[2] = 40000,
      			},
      		},
      		product = {
      			[1] = {
      				[1] = 8000503,
      				[2] = 1,
      			},
      		},
      		name2 = "琉璃石",
      		probability = 10000,
      	},
      	[28] = {
      		type = 1,
      		page1 = 1,
      		page2 = 5,
      		condition = 10001,
      		page3 = 3,
      		condition2 = 10001,
      		itemid1 = {
      			[1] = {
      				[1] = 8000503,
      				[2] = 2,
      			},
      			[2] = {
      				[1] = 4,
      				[2] = 80000,
      			},
      		},
      		product = {
      			[1] = {
      				[1] = 8000504,
      				[2] = 1,
      			},
      		},
      		name2 = "琉璃石",
      		probability = 10000,
      	},
      	[29] = {
      		type = 1,
      		page1 = 1,
      		page2 = 5,
      		condition = 10001,
      		page3 = 4,
      		condition2 = 10001,
      		itemid1 = {
      			[1] = {
      				[1] = 8000504,
      				[2] = 2,
      			},
      			[2] = {
      				[1] = 4,
      				[2] = 1600000,
      			},
      		},
      		product = {
      			[1] = {
      				[1] = 8000505,
      				[2] = 1,
      			},
      		},
      		name2 = "琉璃石",
      		probability = 10000,
      	},
      	[30] = {
      		type = 1,
      		page1 = 1,
      		page2 = 6,
      		condition = 10001,
      		page3 = 1,
      		condition2 = 10001,
      		itemid1 = {
      			[1] = {
      				[1] = 8000601,
      				[2] = 2,
      			},
      			[2] = {
      				[1] = 4,
      				[2] = 20000,
      			},
      		},
      		product = {
      			[1] = {
      				[1] = 8000602,
      				[2] = 1,
      			},
      		},
      		name2 = "琥珀石",
      		probability = 10000,
      	},
      	[31] = {
      		type = 1,
      		page1 = 1,
      		page2 = 6,
      		condition = 10001,
      		page3 = 2,
      		condition2 = 10001,
      		itemid1 = {
      			[1] = {
      				[1] = 8000602,
      				[2] = 2,
      			},
      			[2] = {
      				[1] = 4,
      				[2] = 40000,
      			},
      		},
      		product = {
      			[1] = {
      				[1] = 8000603,
      				[2] = 1,
      			},
      		},
      		name2 = "琥珀石",
      		probability = 10000,
      	},
      	[32] = {
      		type = 1,
      		page1 = 1,
      		page2 = 6,
      		condition = 10001,
      		page3 = 3,
      		condition2 = 10001,
      		itemid1 = {
      			[1] = {
      				[1] = 8000603,
      				[2] = 2,
      			},
      			[2] = {
      				[1] = 4,
      				[2] = 80000,
      			},
      		},
      		product = {
      			[1] = {
      				[1] = 8000604,
      				[2] = 1,
      			},
      		},
      		name2 = "琥珀石",
      		probability = 10000,
      	},
      	[33] = {
      		type = 1,
      		page1 = 1,
      		page2 = 6,
      		condition = 10001,
      		page3 = 4,
      		condition2 = 10001,
      		itemid1 = {
      			[1] = {
      				[1] = 8000604,
      				[2] = 2,
      			},
      			[2] = {
      				[1] = 4,
      				[2] = 1600000,
      			},
      		},
      		product = {
      			[1] = {
      				[1] = 8000605,
      				[2] = 1,
      			},
      		},
      		name2 = "琥珀石",
      		probability = 10000,
      	},
      	[34] = {
      		type = 1,
      		page1 = 1,
      		page2 = 7,
      		condition = 10001,
      		page3 = 1,
      		condition2 = 10001,
      		itemid1 = {
      			[1] = {
      				[1] = 8000701,
      				[2] = 2,
      			},
      			[2] = {
      				[1] = 4,
      				[2] = 20000,
      			},
      		},
      		product = {
      			[1] = {
      				[1] = 8000702,
      				[2] = 1,
      			},
      		},
      		name2 = "玛瑙石",
      		probability = 10000,
      	},
      	[35] = {
      		type = 1,
      		page1 = 1,
      		page2 = 7,
      		condition = 10001,
      		page3 = 2,
      		condition2 = 10001,
      		itemid1 = {
      			[1] = {
      				[1] = 8000702,
      				[2] = 2,
      			},
      			[2] = {
      				[1] = 4,
      				[2] = 40000,
      			},
      		},
      		product = {
      			[1] = {
      				[1] = 8000703,
      				[2] = 1,
      			},
      		},
      		name2 = "玛瑙石",
      		probability = 10000,
      	},
      	[36] = {
      		type = 1,
      		page1 = 1,
      		page2 = 7,
      		condition = 10001,
      		page3 = 3,
      		condition2 = 10001,
      		itemid1 = {
      			[1] = {
      				[1] = 8000703,
      				[2] = 2,
      			},
      			[2] = {
      				[1] = 4,
      				[2] = 80000,
      			},
      		},
      		product = {
      			[1] = {
      				[1] = 8000704,
      				[2] = 1,
      			},
      		},
      		name2 = "玛瑙石",
      		probability = 10000,
      	},
      	[37] = {
      		type = 1,
      		page1 = 1,
      		page2 = 7,
      		condition = 10001,
      		page3 = 4,
      		condition2 = 10001,
      		itemid1 = {
      			[1] = {
      				[1] = 8000704,
      				[2] = 2,
      			},
      			[2] = {
      				[1] = 4,
      				[2] = 1600000,
      			},
      		},
      		product = {
      			[1] = {
      				[1] = 8000705,
      				[2] = 1,
      			},
      		},
      		name2 = "玛瑙石",
      		probability = 10000,
      	},
      	[38] = {
      		type = 1,
      		page1 = 1,
      		page2 = 8,
      		condition = 10001,
      		page3 = 1,
      		condition2 = 10001,
      		itemid1 = {
      			[1] = {
      				[1] = 8000801,
      				[2] = 2,
      			},
      			[2] = {
      				[1] = 4,
      				[2] = 20000,
      			},
      		},
      		product = {
      			[1] = {
      				[1] = 8000802,
      				[2] = 1,
      			},
      		},
      		name2 = "红玉髓",
      		probability = 10000,
      	},
      	[39] = {
      		type = 1,
      		page1 = 1,
      		page2 = 8,
      		condition = 10001,
      		page3 = 2,
      		condition2 = 10001,
      		itemid1 = {
      			[1] = {
      				[1] = 8000802,
      				[2] = 2,
      			},
      			[2] = {
      				[1] = 4,
      				[2] = 40000,
      			},
      		},
      		product = {
      			[1] = {
      				[1] = 8000803,
      				[2] = 1,
      			},
      		},
      		name2 = "红玉髓",
      		probability = 10000,
      	},
      	[40] = {
      		type = 1,
      		page1 = 1,
      		page2 = 8,
      		condition = 10001,
      		page3 = 3,
      		condition2 = 10001,
      		itemid1 = {
      			[1] = {
      				[1] = 8000803,
      				[2] = 2,
      			},
      			[2] = {
      				[1] = 4,
      				[2] = 80000,
      			},
      		},
      		product = {
      			[1] = {
      				[1] = 8000804,
      				[2] = 1,
      			},
      		},
      		name2 = "红玉髓",
      		probability = 10000,
      	},
      	[41] = {
      		type = 1,
      		page1 = 1,
      		page2 = 8,
      		condition = 10001,
      		page3 = 4,
      		condition2 = 10001,
      		itemid1 = {
      			[1] = {
      				[1] = 8000804,
      				[2] = 2,
      			},
      			[2] = {
      				[1] = 4,
      				[2] = 1600000,
      			},
      		},
      		product = {
      			[1] = {
      				[1] = 8000805,
      				[2] = 1,
      			},
      		},
      		name2 = "红玉髓",
      		probability = 10000,
      	},
      	
      }
      return config

        服务端的响应脚本

        lib996:include("Script/serialize.lua")
        
        local _cfg = lib996:include("QuestDiary/cfgcsv/cfg_compound.lua")
        local filename = "合成表单"
        local ratio = 10000 --万分比
        
        function main(actor, idx)
            idx = tonumber(idx)
            local cfg = _cfg[idx]
        
            if not cfg then return end 
        
            if not Bag.checkBagEmptyNum(actor, 1) then 
                lib996:sendmsg(actor, 1, '{"Msg":"<font color=#ffff00>包裹空间不足</font>", "Type":9}')
                return
            end
        
            local name = Player.checkItemNumByTable(actor, cfg.itemid1)
            if name then 
                lib996:sendmsg(actor, 1, '{"Msg":"<font color=\'#ffff00\'>材料['..name..']不足</font>", "Type":9}')
                return
            end
        
            Player.takeItemByTable(actor, cfg.itemid1, "道具合成")
            if FProbabilityHit(cfg.probability, ratio) then 
                lib996:sendmsg(actor, 1, '{"Msg":"<font color=\'#ff0000\'>道具合成失败!</font>","Type":9}')
                lib996:showformwithcontent(actor, "", "Hecheng.updateText()")
                return
            end
        
            Player.giveItemByTable(actor, cfg.product, "物品合成")
            lib996:showformwithcontent(actor, "", "Hecheng.updateText()")
        end
        
        
        local function _onClicknpc(actor, npcid)
            if npcid == 312 then 
                lib996:showformwithcontent(actor, "F/合成面板", "HeCheng")
            end
        end
        
        
        
        
        GameEvent.add(EventCfg.onClicknpc, _onClicknpc, filename)

          配套的player

          Player = {}
          
          --检查货币数量
          function Player.checkMoneyNum(actor, moneytype, num)
              local moneynum = lib996:querymoney(actor, moneytype)
              if moneytype == ConstCfg.money.bdyb then
                  moneynum = moneynum + lib996:querymoney(actor, ConstCfg.money.yb)
              end
              if moneytype == ConstCfg.money.lf then
                  moneynum = moneynum + lib996:querymoney(actor, ConstCfg.money.bdlf)
              end
              return moneynum >= num
          end
          
          --获取虚冲金额
          function Player.getBillNum(actor)
              return lib996:getint(0,actor,VarCfg.U_real_recharge)
          end
          
          --获取今日虚冲金额
          function Player.getTodayBillNum(actor)
              return lib996:getint(0,actor,VarCfg.U_today_real_recharge)
          end
          
          --扣除货币数量
          function Player.takeMoney(actor, idx,num, desc)
              if idx == ConstCfg.money.bdyb then  --游戏设定 绑定元宝不足扣除正常元宝
                  local bdyb = lib996:querymoney(actor, ConstCfg.money.bdyb)
                  if num > bdyb then    --所需元宝大于绑定元宝时
                      lib996:changemoney(actor, ConstCfg.money.bdyb, "-", bdyb, desc, true)   --首先扣除所有绑定元宝
                      lib996:changemoney(actor, ConstCfg.money.yb, "-", (num-bdyb), desc, true)  --正常元宝补充不足元宝
                  end
              end
              if idx == ConstCfg.money.lf then  --游戏设定 优先扣除绑定灵符
                  local bdlf = lib996:querymoney(actor, ConstCfg.money.bdlf)
                  if bdlf >= num then
                      --如果绑定灵符大于等于需要扣除的数量
                      lib996:changemoney(actor, ConstCfg.money.bdlf, "-", num, desc, true)
                      -- LOGWrite("进入2,原:",bdlf,"修改后:",lib996:querymoney(actor, ConstCfg.money.bdlf))
                      num = 0
                  else
                      --如果绑定灵符不足
                      if bdlf > 0 then
                          lib996:changemoney(actor, ConstCfg.money.bdlf, "-", bdlf, desc, true)
                          num = num - bdlf
                      end
                      -- LOGWrite("进入3,原:",bdlf,"修改后:",lib996:querymoney(actor, ConstCfg.money.bdlf))
                  end
              end
              lib996:changemoney(actor, idx, "-", num, desc, true)
          end
          
          --检查 物品 货币 装备是否满足数量(数量不足返回不足物品的名字)
          function Player.checkItemNumByTable(actor, t, multiple)
              for _,item in ipairs(t) do
                  local idx,num = item[1],item[2]
                  if multiple then num=num*multiple end
          
                  local name = idx==ConstCfg.money.bdyb and "元宝" or lib996:getstditeminfo(idx, ConstCfg.stditeminfo.name)
                  if Item.isCurrency(idx) then        --货币
                      if not Player.checkMoneyNum(actor, idx, num) then
                          return name, num
                      end
                  else                                    --物品 装备
                      if not Bag.checkItemNumByIdx(actor, idx, num) then
                          return name, num
                      end
                  end
              end
          end
          
          --如果是装备要检查身上(只供物品合成使用)
          function Player.libcheckItemNumByTableEx(actor, t, multiple)
              for _,item in ipairs(t) do
                  local idx,num = item[1],item[2]
                  if multiple then num = num * multiple end
                  local name = lib996:getstditeminfo(idx, ConstCfg.stditeminfo.name)
                  if Item.isCurrency(idx) then        --货币
                      if not Player.checkMoneyNum(actor, idx, num) then
                          return false, name, num
                      end
                  elseif Item.isItem(idx) then        --物品
                      if not Bag.checkItemNumByIdx(actor, idx, num) then
                          return false, name, num
                      end
                  else                                --装备
                      local count = Bag.getItemNumByIdx(actor, idx)
                      if count < num then
                          local wheres = Item.getWheresByIdx(idx)
                          if wheres then
                              for _,where in ipairs(wheres) do
                                  local equipobj = lib996:linkbodyitem(actor, where)
                                  if equipobj ~= "0" then
                                      local equipidx = lib996:getiteminfo(actor, equipobj, ConstCfg.iteminfo.idx)
                                      if equipidx == idx then
                                          count = count + 1
                                      end
                                  end
                              end
                          end
                      end
                      if count < num then
                          return false, name, num
                      end
                  end
              end
              return true
          end
          
          --拿走物品
          function Player.takeItemByTable(actor, t, desc, multiple)
              for _,item in ipairs(t) do
                  local idx,num = item[1],item[2]
                  if multiple then num=num*multiple end
                  if Item.isCurrency(idx) then        --货币
                      if idx == 4 then  --游戏设定 绑定元宝不足扣除正常元宝
                          local bdyb = lib996:querymoney(actor, 4)
                          if num > bdyb then    --所需元宝大于绑定元宝时
                              lib996:changemoney(actor, 4, "-", bdyb, desc, true)   --首先扣除所有绑定元宝
                              lib996:changemoney(actor, 2, "-", (num-bdyb), desc, true)  --正常元宝补充不足元宝
                          end
                      end
                      if idx == ConstCfg.money.lf then  --游戏设定 优先扣除绑定灵符
                          local bdlf = lib996:querymoney(actor, ConstCfg.money.bdlf)
                          if bdlf >= num then
                              --如果绑定灵符大于等于需要扣除的数量
                              lib996:changemoney(actor, ConstCfg.money.bdlf, "-", num, desc, true)
                              -- LOGWrite("进入2,原:",bdlf,"修改后:",lib996:querymoney(actor, ConstCfg.money.bdlf))
                              num = 0
                          else
                              --如果绑定灵符不足
                              lib996:changemoney(actor, ConstCfg.money.bdlf, "-", bdlf, desc, true)
                              -- LOGWrite("进入3,原:",bdlf,"修改后:",lib996:querymoney(actor, ConstCfg.money.bdlf))
                              num = num - bdlf
                          end
                      end
                      if num > 0 then
                          lib996:changemoney(actor, idx, "-", num, desc, true)
                      end
                  else                                    --物品 装备
                      local name = lib996:getstditeminfo(idx, ConstCfg.stditeminfo.name)
                      lib996:takeitem(actor, name, num)
                  end
              end
          end
          
          --优先拿走非绑定物品
          function Player.takeItemByTableEx(actor, t, desc, multiple, isbind)
              --拆分物品和货币
              local t_gold = {}
              local t_item = {}
              local t_overlap_item = {}
              local iteminfos = {}
              local itemoverlapinfos = {}
              for _,item in ipairs(t) do  
                  local idx,num = item[1],item[2]
                  if multiple then num = num * multiple end
                  if Item.isCurrency(idx) then    --货币
                      t_gold[idx] = num
                  else                                --物品 装备
                      local overlap = lib996:getstditeminfo(idx, ConstCfg.stditeminfo.overlap)
                      if overlap == 0 then        --不叠加
                          t_item[idx] = num
                          iteminfos[idx] = {bind={}, notbind={}}
                      else                        --叠加物品
                          t_overlap_item[idx] = num
                          itemoverlapinfos[idx] = {bind={}, notbind={}}
                      end
                  end
              end
              --绑定与非绑定物品唯一id分开保存
              local item_num = lib996:getbaseinfo(actor, ConstCfg.gbase.bag_num)
              for i=0, item_num-1 do
                  local itemobj = lib996:getiteminfobyindex(actor, i)
                  local itemidx = lib996:getiteminfo(actor, itemobj, ConstCfg.iteminfo.idx)
                  for idx,_ in pairs(t_item) do
                      if idx == itemidx then
                          local bind = lib996:getiteminfo(actor, itemobj, ConstCfg.iteminfo.bind)
                          local t_bind = bind==0 and iteminfos[idx].notbind or iteminfos[idx].bind
                          local itemmakeindex = lib996:getiteminfo(actor, itemobj, ConstCfg.iteminfo.id)
                          table.insert(t_bind, itemmakeindex)
                      end
                  end
          
                  for idx,_ in pairs(t_overlap_item) do
                      if idx == itemidx then
                          local bind = lib996:getiteminfo(actor, itemobj, ConstCfg.iteminfo.bind)
                          local t_bind = bind==0 and itemoverlapinfos[idx].notbind or itemoverlapinfos[idx].bind
                          local itemmakeindex = lib996:getiteminfo(actor, itemobj, ConstCfg.iteminfo.id)
                          local itemnum = lib996:getiteminfo(actor, itemobj, ConstCfg.iteminfo.overlap)
                          t_bind[itemmakeindex] = itemnum
                      end
                  end
              end
          
              --身上穿戴的物品也算在合成物品内
              for idx,_t in pairs(iteminfos) do
                  if Item.isEquip(idx) then
                      local wheres = Item.getWheresByIdx(idx)
                      for _,where in ipairs(wheres) do
                          local equipobj = lib996:linkbodyitem(actor, where)
                          if equipobj ~= "0" then
                              local equipidx = lib996:getiteminfo(actor, equipobj, ConstCfg.iteminfo.idx)
                              if equipidx == idx then
                                  local bind = lib996:getiteminfo(actor, equipobj, ConstCfg.iteminfo.bind)
                                  local t_bind = bind==0 and iteminfos[idx].notbind or iteminfos[idx].bind
                                  local equipmakeindex = lib996:getiteminfo(actor, equipobj, ConstCfg.iteminfo.id)
                                  table.insert(t_bind, equipmakeindex)
                              end
                          end
                      end
                  end
              end
          
              --扣物品
              local t_take = {}
              for idx,need_num in pairs(t_item) do
                  local t_bind, t_notbind = iteminfos[idx].bind, iteminfos[idx].notbind
                  local t_first = isbind and {t_notbind} or {t_bind, t_notbind}
                  for _,v in ipairs(t_first) do
                      for _,makeindex in ipairs(v) do
                          table.insert(t_take, makeindex)
                          need_num = need_num - 1
                          if need_num == 0 then break end
                      end
                      if need_num == 0 then break end
                  end
              end
              if #t_take > 0 then
                  local takestr = table.concat(t_take, ",")
                  lib996:delitembymakeindex(actor, takestr)
              end
          
              for idx,need_num in pairs(t_overlap_item) do
                  local temp_num = need_num
                  local t_bind, t_notbind = itemoverlapinfos[idx].bind, itemoverlapinfos[idx].notbind
                  local t_first = isbind and {t_notbind} or {t_bind, t_notbind}
                  for _,v in ipairs(t_first) do
                      if temp_num <= 0 then break end
                      for makeindex,num in pairs(v) do
                          temp_num = temp_num - num
                          if temp_num > 0 then
                              lib996:delitembymakeindex(actor, tostring(makeindex), num)
                              need_num = need_num - num
                          else
                              lib996:delitembymakeindex(actor, tostring(makeindex), need_num)
                              break
                          end
                      end
                  end
              end
          
              --扣货币
              for idx,num in pairs(t_gold) do
                  lib996:changemoney(actor, idx, "-", num, desc, true)
              end
              return isbind
              --如果有一个物品是固定绑定 其他物品优先扣除绑定物品
              --如果没有任何物品是固定绑定那么说明非绑定物品足够
              --判断物品是否叠加物品 如果是叠加物品要单独拿走
          end
          
          --给物品
          function Player.giveItemByTable(actor, t, desc, multiple, isbind)
              multiple = multiple or 1         --倍数
          
              for _,item in ipairs(t) do
                  local idx,num,bind = item[1],item[2],item[3]
                  if Item.isCurrency(idx) then        --货币
                      lib996:changemoney(actor, idx, "+", num * multiple, desc, true)
                  else                                    --物品 装备
                      local name = lib996:getstditeminfo(idx, ConstCfg.stditeminfo.name)
                      if bind or isbind then
                          lib996:giveitem(actor, name, num * multiple, ConstCfg.binding)
                      else
                          lib996:giveitem(actor, name, num * multiple)
                      end
                  end
              end
          end
          
          --给物品盒子
          function Player.giveItemBoxByIdx(actor, idx)
              local name = lib996:getstditeminfo(idx, ConstCfg.stditeminfo.name)
              lib996:giveitem(actor, name)
          end
          
          --获取当前穿戴装备的唯一id数组通过idx
          function Player.getEquipIdsByIdx(actor, idx)
              if not Item.isEquip(idx) then return {} end
          
              local equipids = {}
              local wheres = Item.getWheresByIdx(idx)
              for _,where in ipairs(wheres) do
                  local equipobj = lib996:linkbodyitem(actor, where)
                  if equipobj ~= "0" then
                      local equipidx = lib996:getiteminfo(actor, equipobj, ConstCfg.iteminfo.idx)
                      if equipidx == idx then
                          local equipmakeindex = lib996:getiteminfo(actor, equipobj, ConstCfg.iteminfo.id)
                          table.insert(equipids, equipmakeindex)
                      end
                  end
              end
              return equipids
          end
          
          --获取装备位idx
          function Player.getEquipPosIdx(actor, pos)
              local itemobj = lib996:linkbodyitem(actor, pos)
              if itemobj=="0" then return end
              local idx = lib996:getiteminfo(actor, itemobj, ConstCfg.iteminfo.idx)
              return idx
          end
          
          return Player
            撰写回复...