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
🤖 回答引擎: 浮生梦专用2 |
🕒 时间: 2026-03-04 02:01:53 |
👁️ 阅读: 9
--前端开始]]
local npc = { } -- 类
npc.CONFIG = { -- 配置
MSG_ID = 9999, -- 修改你的通信协议号
UI_NAME = "修改你的export名字", -- UI界面名称
}
function npc:Lmain() -- 前端的入口处
local ui = GUI:npcUi(self.CONFIG.UI_NAME) -- 调用export
--- 根据按钮 增加入场的特效 可以使用cocos 2dx 3.1.5的lua版本!
--- 调用按钮 发送服务端协议
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, 7)
if job ~= 2 then -- 假设法师的职业ID是2
player:send("只有法师可以购买宝宝!")
return
end
-- 检查等级是否达到30级
local level = getbaseinfo(actor, 6)
if level < 30 then
player:send("需要达到30级才能购买宝宝!")
return
end
-- 计算可购买的宝宝数量
local maxCount = math.floor((level - 30) / 5) + 1
if maxCount <= 0 then
player:send("等级不足,无法购买宝宝!")
return
end
-- 获取当前宝宝数量
local currentCount = getbaseinfo(actor, 38) or 0
if currentCount >= maxCount then
player:send("已达到当前等级可携带的宝宝数量上限!")
return
end
-- 根据p2参数确定购买的宝宝类型和价格
local babyConfig = {
[1] = {name = "牛魔宝宝1", price = 100000},
[2] = {name = "牛魔宝宝2", price = 200000},
[3] = {name = "牛魔宝宝3", price = 300000},
[4] = {name = "牛魔宝宝4", price = 400000},
[5] = {name = "牛魔宝宝5", price = 500000},
[6] = {name = "牛魔宝宝6", price = 600000},
[7] = {name = "牛魔宝宝7", price = 700000},
}
local config = babyConfig[p2]
if not config then
player:send("无效的宝宝类型!")
return
end
-- 检查金币是否足够
local gold = player:getGold()
if gold < config.price then
player:send(string.format("金币不足!需要%s金币,当前只有%s金币", config.price, gold))
return
end
-- 扣除金币
player:setGold(gold - config.price)
-- 增加宝宝数量
player:setBaseInfo(38, currentCount + 1)
-- 发送购买成功消息
player:send(string.format("成功购买%s!当前宝宝数量:%d/%d", config.name, currentCount + 1, maxCount))
-- 记录日志
local name = getbaseinfo(actor, 1)
local uid = getbaseinfo(actor, 2)
print(string.format("[宝宝购买] 玩家:%s(UID:%s) 购买了%s,消耗%s金币", name, uid, config.name, config.price))
end
--后端结束
return npc
--前端开始]]
local npc = { } -- 类
npc.CONFIG = { -- 配置
MSG_ID = 9999, -- 修改你的通信协议号
UI_NAME = "修改你的export名字", -- UI界面名称
}
function npc:Lmain() -- 前端的入口处
local ui = GUI:npcUi(self.CONFIG.UI_NAME) -- 调用export
--- 根据按钮 增加入场的特效 可以使用cocos 2dx 3.1.5的lua版本!
--- 调用按钮 发送服务端协议
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, 7)
if job ~= 2 then -- 假设法师的职业ID是2
player:send("只有法师可以购买宝宝!")
return
end
-- 检查等级是否达到30级
local level = getbaseinfo(actor, 6)
if level < 30 then
player:send("需要达到30级才能购买宝宝!")
return
end
-- 计算可购买的宝宝数量
local maxCount = math.floor((level - 30) / 5) + 1
if maxCount <= 0 then
player:send("等级不足,无法购买宝宝!")
return
end
-- 获取当前宝宝数量
local currentCount = getbaseinfo(actor, 38) or 0
if currentCount >= maxCount then
player:send("已达到当前等级可携带的宝宝数量上限!")
return
end
-- 根据p2参数确定购买的宝宝类型和价格
local babyConfig = {
[1] = {name = "牛魔宝宝1", price = 100000},
[2] = {name = "牛魔宝宝2", price = 200000},
[3] = {name = "牛魔宝宝3", price = 300000},
[4] = {name = "牛魔宝宝4", price = 400000},
[5] = {name = "牛魔宝宝5", price = 500000},
[6] = {name = "牛魔宝宝6", price = 600000},
[7] = {name = "牛魔宝宝7", price = 700000},
}
local config = babyConfig[p2]
if not config then
player:send("无效的宝宝类型!")
return
end
-- 检查金币是否足够
local gold = player:getGold()
if gold < config.price then
player:send(string.format("金币不足!需要%s金币,当前只有%s金币", config.price, gold))
return
end
-- 扣除金币
player:setGold(gold - config.price)
-- 增加宝宝数量
player:setBaseInfo(38, currentCount + 1)
-- 发送购买成功消息
player:send(string.format("成功购买%s!当前宝宝数量:%d/%d", config.name, currentCount + 1, maxCount))
-- 记录日志
local name = getbaseinfo(actor, 1)
local uid = getbaseinfo(actor, 2)
print(string.format("[宝宝购买] 玩家:%s(UID:%s) 购买了%s,消耗%s金币", name, uid, config.name, config.price))
end
--后端结束
return npc
← 返回问答库