--前端开始]]
local npc = {} -- 类
npc.CONFIG = { -- 配置
MSG_ID = 6011, -- 通信协议号
UI_NAME = "my_wqhc", -- UI界面名称
COST_MONEY = 100000, -- 强化消耗金币
MAX_STAR = 5, -- 最大强化等级
}
function npc:Lmain() -- 前端的入口处
local ui = GUI:npcUi(self.CONFIG.UI_NAME) -- 调用export
self.ui = ui
local data = {
stdMode = {5,6}, -- 分类过滤:支持单数字,也支持多个数组如 {5, 6, 22}
itemsPerRow = 5, -- 排版:每行显示几个
spacingX = 45, -- 排版:X方向间距
spacingY = 45, -- 排版:Y方向间距
startX = 25, -- 排版:起始X
startYOffset = 45, -- 排版:第一个物品距离顶部的Y偏移量
paddingY = 5, -- 排版:上下边缘留白
jumpToTop = true -- 排版:刷新后是否强制回到顶部
}
GUI:bag(ui.ScrollView_1, data,function (itemData)
GUI:updataItembox(ui.ItemShow_1,itemData.MakeIndex) -- 更新装备栏
if itemData and itemData.MakeIndex then
self.itemMKindex = itemData.MakeIndex
end
end)
GUI:checkBoxOnly(ui,6)
GUI:onClick(ui.Button_1,function ()
local where = GUI:getCheckboxOnley(ui,6)
if not where then
player:send("请选择存放位置!")
return
end
SL:toServer(self.CONFIG.MSG_ID, 1,self.itemMKindex,where)
end)
end
--前端结束]]
function npc:Smain(actor,p1,p2,p3,str)
local player = class(actor) -- 面向对象获取人物对象
if not player then return end
-- 路由分发机制
local dis = {
[1] = self.func1, -- 方法1
}
local handler = dis[p1]
if handler then
handler(self, actor, player, p2, p3, str)
else
player:send("未知的操作请求! 错误码:" .. tostring(p1))
end
end
function npc:func1(actor, player, p2, p3, str) -- 方法1
local where = p3
if not where then
player:send("请选择装备!!")
return
end
local itemObj = player:getItemObj(where)
if not itemObj then
player:send("请穿戴对应的装备!")
return
end
local starNum = player:getItemStar(where)
if starNum >= self.CONFIG.MAX_STAR then
player:send("装备的强化等级已经达到最高!")
return
end
if not player:checkMoney("金币", self.CONFIG.COST_MONEY) then
player:send("强化失败,金币不足" .. self.CONFIG.COST_MONEY .. "!")
return
end
-- 随机概率判定(这里简化处理,实际可根据需要调整)
if math.random(1, 100) <= 50 then -- 50%成功率
player:decMoney("金币", self.CONFIG.COST_MONEY)
player:addItemVar(where, 1, 1) -- 增加强化等级
player:send("强化成功!当前强化等级:" .. (starNum + 1))
else
player:decMoney("金币", self.CONFIG.COST_MONEY)
player:send("强化失败!")
end
end
return npc