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 = 9999, -- 修改你的通信协议号
UI_NAME = "购买宝宝", -- UI界面名称
-- 宝宝购买配置
PETS = {
{ name = "牛魔宝宝1", price = 100000, monster = "牛魔宝宝1" },
{ name = "牛魔宝宝2", price = 200000, monster = "牛魔宝宝2" },
{ name = "牛魔宝宝3", price = 300000, monster = "牛魔宝宝3" },
{ name = "牛魔宝宝4", price = 400000, monster = "牛魔宝宝4" },
{ name = "牛魔宝宝5", price = 500000, monster = "牛魔宝宝5" },
{ name = "牛魔宝宝6", price = 600000, monster = "牛魔宝宝6" },
{ name = "牛魔宝宝7", price = 700000, monster = "牛魔宝宝7" },
}
}
function npc:Lmain() -- 前端的入口处
local ui = GUI:npcUi(self.CONFIG.UI_NAME) -- 调用export
-- 入场特效
local root = ui.root or ui
if root then
GUI:setScale(root, 0.5)
GUI:runAction(root, GUI:ScaleTo(0.3, 1.0))
end
-- 为每个购买按钮添加点击事件
for i = 1, #self.CONFIG.PETS do
local btn = ui["Button_" .. i]
if btn then
GUI:onClick(btn, function()
-- 发送购买请求到服务端
SL:toServer(self.CONFIG.MSG_ID, 1, i, 0, "")
end)
end
end
-- 关闭按钮
if ui.close then
GUI:onClick(ui.close, function()
GUI:closeAll()
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.buyPet, -- 购买宝宝
}
local handler = dis[p1]
if handler then
handler(self, actor, player, p2, p3, str)
else
player:send("未知的操作请求! 错误码:" .. tostring(p1))
-- 下日志!
end
end
function npc:buyPet(actor, player, petIndex, p3, str)
-- 检查职业:必须是法师
if player.job ~= "法师" then
player:send("只有法师才能购买宝宝!")
return
end
-- 检查等级
if player.lv < 30 then
player:send("需要达到30级才能购买宝宝!")
return
end
-- 计算可携带的宝宝数量
local maxPets = 1 -- 基础1个
if player.lv >= 30 then
maxPets = maxPets + math.floor((player.lv - 30) / 5)
end
-- 检查当前宝宝数量
local currentPets = player.bbnum or 0
if currentPets >= maxPets then
player:send("您当前最多只能携带" .. maxPets .. "个宝宝!")
return
end
-- 获取宠物配置
local petConfig = self.CONFIG.PETS[petIndex]
if not petConfig then
player:send("无效的宝宝类型!")
return
end
-- 检查金币
if not player:checkmoney("金币", petConfig.price) then
player:send("金币不足!需要" .. petConfig.price .. "金币")
return
end
-- 扣除金币
player:money("金币", "-", petConfig.price)
-- 召唤宝宝
player:summon(petConfig.monster)
-- 发送成功消息
player:send("成功购买" .. petConfig.name .. "!")
end
return npc