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
--前端开始]]
local npc = { } -- 类
npc.CONFIG = { -- 配置
MSG_ID = 6008, -- 通信协议号
UI_NAME = "my_bshc", -- UI界面名称
}
function npc:Lmain() -- 前端的入口处
local ui = GUI:npcUi(self.CONFIG.UI_NAME) -- 调用export
self.ui = ui
-- 为每个购买按钮添加点击事件
for i = 1, 7 do
local btn = ui["Button_" .. i]
if btn then
GUI:addOnClickEvent(btn, function()
SL:toServer(self.CONFIG.MSG_ID, 1, i) -- p1=1表示购买操作,p2=按钮索引
end)
end
end
-- 关闭按钮
if ui.close then
GUI:addOnClickEvent(ui.close, function()
GUI:removeFromParent(self.ui.nativeUI)
end)
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, -- 购买宝宝
}
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) -- 购买宝宝
-- 检测职业必须是法师
local job = getbaseinfo(actor, 0) -- 获取职业
if job ~= 1 then -- 1代表法师职业
player:send("只有法师职业才能购买宝宝!")
return
end
-- 检测是否已经购买过宝宝
local ncount = getbaseinfo(actor, 38) -- 获取召唤物数量
for i = 0, ncount-1 do
local mon = getslavebyindex(actor, i)
if mon then
player:send("您已经拥有宝宝,不能重复购买!")
return
end
end
-- 根据按钮索引确定价格和宝宝类型
local prices = {100000, 200000, 300000, 400000, 500000, 600000, 700000}
local babyNames = {"牛魔宝宝1", "牛魔宝宝2", "牛魔宝宝3", "牛魔宝宝4",
"牛魔宝宝5", "牛魔宝宝6", "牛魔宝宝7"}
if not p2 or p2 < 1 or p2 > 7 then
player:send("无效的宝宝类型!")
return
end
local price = prices[p2]
local babyName = babyNames[p2]
-- 检查金币是否足够
local gold = getbaseinfo(actor, 40) -- 获取金币数量
if gold < price then
player:send(string.format("金币不足!需要%s金币,您只有%s金币", price, gold))
return
end
-- 扣除金币
addbaseinfo(actor, 40, -price)
-- 召唤宝宝(这里需要根据实际召唤函数实现)
-- 示例:callmon(actor, babyName, 1)
player:send(string.format("成功购买%s!", babyName))
-- 记录日志
-- 下日志!
end
return npc