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 01:56:03 |
👁️ 阅读: 11
--前端开始]]
local npc = { } -- 类
npc.CONFIG = { -- 配置
MSG_ID = 9999, -- 修改你的通信协议号
UI_NAME = "购买宝宝", -- UI界面名称
NEED_LEVEL = 30, -- 需要等级
NEED_JOB = "法师", -- 需要职业
PET_CONFIG = { -- 宝宝配置
{name = "牛魔宝宝1", price = 100000, index = 1},
{name = "牛魔宝宝2", price = 200000, index = 2},
{name = "牛魔宝宝3", price = 300000, index = 3},
{name = "牛魔宝宝4", price = 400000, index = 4},
{name = "牛魔宝宝5", price = 500000, index = 5},
{name = "牛魔宝宝6", price = 600000, index = 6},
{name = "牛魔宝宝7", price = 700000, index = 7},
}
}
function npc:Lmain() -- 前端的入口处
local ui = GUI:npcUi(self.CONFIG.UI_NAME) -- 调用export
end
--前端结束]]
function npc:Smain(actor,p1,p2,p3,str)
local player = class(actor) -- 面向对象获取人物对象
if not player then return end
-- 路由分发机制
local dis = {
[1] = self.openUI, -- 打开界面
[2] = 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:openUI(actor, player, p2, p3, str)
-- 检查等级
if player.level < self.CONFIG.NEED_LEVEL then
player:send("需要等级" .. self.CONFIG.NEED_LEVEL .. "级才能购买宝宝")
return
end
-- 检查职业
if player.job ~= self.CONFIG.NEED_JOB then
player:send("只有" .. self.CONFIG.NEED_JOB .. "才能购买宝宝")
return
end
-- 检查是否已有宝宝
if player.bbnum > 0 then
player:send("您已经拥有宝宝,只能购买一个")
return
end
-- 发送打开UI消息
player:send("打开购买宝宝界面")
end
function npc:buyPet(actor, player, p2, p3, str)
-- 再次检查条件
if player.level < self.CONFIG.NEED_LEVEL then
player:send("需要等级" .. self.CONFIG.NEED_LEVEL .. "级才能购买宝宝")
return
end
if player.job ~= self.CONFIG.NEED_JOB then
player:send("只有" .. self.CONFIG.NEED_JOB .. "才能购买宝宝")
return
end
if player.bbnum > 0 then
player:send("您已经拥有宝宝,只能购买一个")
return
end
-- p2为宝宝索引
local petIndex = tonumber(p2)
if not petIndex or petIndex < 1 or petIndex > #self.CONFIG.PET_CONFIG then
player:send("无效的宝宝选择")
return
end
local petConfig = self.CONFIG.PET_CONFIG[petIndex]
local price = petConfig.price
-- 检查金币是否足够
if player.gold < price then
player:send("金币不足,需要" .. price .. "金币")
return
end
-- 扣除金币
player:addGold(-price)
-- 给予宝宝(这里需要根据实际宝宝给予方式调整)
-- player:addPet(petConfig.name) -- 假设有addPet方法
player:send("成功购买" .. petConfig.name .. ",花费" .. price .. "金币")
-- 记录日志
-- log("玩家" .. player.name .. "购买宝宝" .. petConfig.name .. ",花费" .. price .. "金币")
end
return npc
--前端开始]]
local npc = { } -- 类
npc.CONFIG = { -- 配置
MSG_ID = 9999, -- 修改你的通信协议号
UI_NAME = "购买宝宝", -- UI界面名称
NEED_LEVEL = 30, -- 需要等级
NEED_JOB = "法师", -- 需要职业
PET_CONFIG = { -- 宝宝配置
{name = "牛魔宝宝1", price = 100000, index = 1},
{name = "牛魔宝宝2", price = 200000, index = 2},
{name = "牛魔宝宝3", price = 300000, index = 3},
{name = "牛魔宝宝4", price = 400000, index = 4},
{name = "牛魔宝宝5", price = 500000, index = 5},
{name = "牛魔宝宝6", price = 600000, index = 6},
{name = "牛魔宝宝7", price = 700000, index = 7},
}
}
function npc:Lmain() -- 前端的入口处
local ui = GUI:npcUi(self.CONFIG.UI_NAME) -- 调用export
end
--前端结束]]
function npc:Smain(actor,p1,p2,p3,str)
local player = class(actor) -- 面向对象获取人物对象
if not player then return end
-- 路由分发机制
local dis = {
[1] = self.openUI, -- 打开界面
[2] = 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:openUI(actor, player, p2, p3, str)
-- 检查等级
if player.level < self.CONFIG.NEED_LEVEL then
player:send("需要等级" .. self.CONFIG.NEED_LEVEL .. "级才能购买宝宝")
return
end
-- 检查职业
if player.job ~= self.CONFIG.NEED_JOB then
player:send("只有" .. self.CONFIG.NEED_JOB .. "才能购买宝宝")
return
end
-- 检查是否已有宝宝
if player.bbnum > 0 then
player:send("您已经拥有宝宝,只能购买一个")
return
end
-- 发送打开UI消息
player:send("打开购买宝宝界面")
end
function npc:buyPet(actor, player, p2, p3, str)
-- 再次检查条件
if player.level < self.CONFIG.NEED_LEVEL then
player:send("需要等级" .. self.CONFIG.NEED_LEVEL .. "级才能购买宝宝")
return
end
if player.job ~= self.CONFIG.NEED_JOB then
player:send("只有" .. self.CONFIG.NEED_JOB .. "才能购买宝宝")
return
end
if player.bbnum > 0 then
player:send("您已经拥有宝宝,只能购买一个")
return
end
-- p2为宝宝索引
local petIndex = tonumber(p2)
if not petIndex or petIndex < 1 or petIndex > #self.CONFIG.PET_CONFIG then
player:send("无效的宝宝选择")
return
end
local petConfig = self.CONFIG.PET_CONFIG[petIndex]
local price = petConfig.price
-- 检查金币是否足够
if player.gold < price then
player:send("金币不足,需要" .. price .. "金币")
return
end
-- 扣除金币
player:addGold(-price)
-- 给予宝宝(这里需要根据实际宝宝给予方式调整)
-- player:addPet(petConfig.name) -- 假设有addPet方法
player:send("成功购买" .. petConfig.name .. ",花费" .. price .. "金币")
-- 记录日志
-- log("玩家" .. player.name .. "购买宝宝" .. petConfig.name .. ",花费" .. price .. "金币")
end
return npc
← 返回问答库