local ui = {}
local _V = function(...) return SL:GetMetaValue(...) end
local FUNCQUEUE = {}
local TAGOBJ = {}
function ui.init(parent, __data__, __update__)
if __update__ then return ui.update(__data__) end
-- Create Node_1
local Node_1 = GUI:Nod
根据UI界面,这是一个马匹合成系统。我来实现前后端逻辑:
前端代码(Lua):
```lua
function npc:main_hc()
local ui, root = GUI:npcUi("mapi_hc")
-- 显示褐马铠物品
local function critem(widget, itemName)
local setData = {}
setData.mouseCheckTimes = 6
setData.itemData = table
local item = GUI:ItemShow_Create(widget, "item"..idx, 0, 0, setData)
end
-- 显示褐马铠
critem(ui.hang111, "褐马铠")
-- 马牌回收按钮
GUI:onClick(ui.Button_1, function()
SL:toServer(1240, 1, 0)
end)
-- 第一个马匹合成按钮
GUI:onClick(ui.Button_2, function()
SL:toServer(1240, 1, 1)
end)
-- 配置马匹合成列表
for i = 1, #self.CONFIG.horse do
local new = GUI:Clone(ui.clone_h)
critem(new, self.CONFIG.horse[i].name)
local xiaohaoStr = GUI:getChildByName(new, "str")
local str = "消耗:"..self.CONFIG.horse[i].needitem.."*1 马牌:"..self.CONFIG.horse[i].num.."个"
GUI:setText(xiaohaoStr, str)
GUI:ListView_pushBackCustomItem(ui.ListView_1, new)
local btn = GUI:getChildByName(new, "horse_btn")
GUI:onClick(btn, function()
SL:print(i+1)
SL:toServer(1240, 1, i+1)
end)
end
SL:print(GUI:ListView_getItemCount(ui.ListView_1), "数量!")
end
function npc:Lmain()
local ui, root = GUI:npcUi("mapi")
GUI:onClick(ui.Button_1, function() -- 马匹合成
self:main_hc()
end)
end
```
后端代码(Lua):
```lua
function npc:Smain(actor, p1, p2, p3, str)
local player = class(actor)
if p1 == 1 then -- 马匹合成
if p2 == 0 then -- 马牌回收
-- 马牌回收逻辑
local result = player:consumeItem("马牌", 1)
if result then
player:addItem("金币", 100) -- 示例:回收获得金币
player:sendMsg("马牌回收成功")
end
elseif p2 == 1 then -- 第一个马匹合成
-- 合成褐马铠逻辑
local hasItem = player:hasItem("马牌", 1)
if hasItem then
player:consumeItem("马牌", 1)
player:addItem("褐马铠", 1)
player:sendMsg("褐马铠合成成功")
else
player:sendMsg("马牌不足")
end
else -- 其他马匹合成
local horseIndex = p2 - 1
if horseIndex <= #self.CONFIG.horse then
local horseData = self.CONFIG.horse[horseIndex]
local hasNeedItem = player:hasItem(horseData.needitem, 1)
local hasHorseToken = player:hasItem("马牌", horseData.num)
if hasNeedItem and hasHorseToken then
player:consumeItem(horseData.needitem, 1)
player:consumeItem("马牌", horseData.num)
player:addItem(horseData.name, 1)
player:sendMsg(horseData.name.."合成成功")
else
player:sendMsg("材料不足")
end
end
end
end
end
```
这个实现包括:
1. 前端界面显示马匹合成列表
2. 马牌回收功能
3. 多个马匹合成选项
4. 后端验证材料消耗和物品发放
5. 使用协议1240进行前后端通信