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-06 22:06:20 |
👁️ 阅读: 10
--前端开始]]
local npc = { } -- 类
npc.CONFIG = { -- 配置
MSG_ID = 9999, -- 修改你的通信协议号
UI_NAME = "zhuansheng", -- UI界面名称
Maxlv = 10,
needItems = {"法师之星", "金币"},
levels = {
[1] = {needlevel = 75, needNum = {10, 10000000}},
[2] = {needlevel = 75, needNum = {20, 20000000}},
[3] = {needlevel = 75, needNum = {40, 30000000}},
[4] = {needlevel = 75, needNum = {80, 40000000}},
[5] = {needlevel = 75, needNum = {160, 50000000}},
[6] = {needlevel = 75, needNum = {320, 60000000}},
[7] = {needlevel = 75, needNum = {640, 70000000}},
[8] = {needlevel = 75, needNum = {1280, 80000000}},
[9] = {needlevel = 75, needNum = {2560, 90000000}},
[10] = {needlevel = 75, needNum = {5120, 100000000}},
}
}
function npc:Lmain() -- 前端的入口处
local ui = GUI:npcUi(self.CONFIG.UI_NAME) -- 调用export
-- 入场特效
GUI:runAction(ui.Node_1, GUI:ActionSequence(
GUI:ActionFadeIn(0.3),
GUI:ActionScaleTo(0.1, 1.1),
GUI:ActionScaleTo(0.1, 1)
))
-- 转生按钮事件
GUI:onClick(ui.sendbtn, function()
-- 按钮点击特效
GUI:runAction(ui.sendbtn, GUI:ActionSequence(
GUI:ActionScaleTo(0.1, 0.9),
GUI:ActionScaleTo(0.1, 1)
))
-- 发送转生请求到服务端
SL:toServer(self.CONFIG.MSG_ID, 1, 0, 0, "")
end)
-- 初始化物品显示
self:updataitemshow(ui)
end
function npc:updataitemshow(ui)
-- 这里需要从服务端获取当前转生等级来更新显示
-- 示例:更新法师之星和金币的显示
GUI:ItemShow_updateItem(ui.ItemShow_fszx, {
index = SL:itemname2idx("法师之星"),
count = 10, -- 应从配置或服务端获取
})
GUI:ItemShow_updateItem(ui.itemshow_money, {
index = SL:itemname2idx("金币"),
count = 10000000, -- 应从配置或服务端获取
})
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 rlv = getbaseinfo(actor, 39) -- 获取当前转生等级
if rlv >= self.CONFIG.Maxlv then
player:send("您已达成最高转生等级!")
return
end
local nextLv = rlv + 1
local cfg = self.CONFIG.levels[nextLv]
if not cfg then
player:send("转生配置错误!")
return
end
-- 检查等级
local curLv = getbaseinfo(actor, 6)
if curLv < cfg.needlevel then
player:send("等级不足" .. cfg.needlevel .. "级,无法进行" .. nextLv .. "转!")
return
end
-- 检查物品和金币
local itemName = self.CONFIG.needItems[1]
local itemIdx = itemname2idx(itemName)
local itemCount = getitemcount(actor, itemIdx)
if itemCount < cfg.needNum[1] then
player:send(itemName .. "数量不足,需要" .. cfg.needNum[1] .. "个!")
return
end
local money = getbaseinfo(actor, 40) -- 获取金币
if money < cfg.needNum[2] then
player:send("金币不足,需要" .. cfg.needNum[2] .. "!")
return
end
-- 消耗物品和金币
decitem(actor, itemIdx, cfg.needNum[1])
decmoney(actor, cfg.needNum[2])
-- 设置转生等级
setbaseinfo(actor, 39, nextLv)
-- 重置等级为1级
setbaseinfo(actor, 6, 1)
-- 添加属性加成(示例:加5-5攻击,5%HP)
local att = string.format("3#4#%s|3#6#%s|3#8#%s", 5, 5, 5)
player:attlist("转生属性加成", att)
-- 发送成功消息
player:send("恭喜你成功完成" .. nextLv .. "转!")
-- 通知前端刷新
player:send(self.CONFIG.MSG_ID, 2000, nextLv, 0, "")
end
return npc
--前端开始]]
local npc = { } -- 类
npc.CONFIG = { -- 配置
MSG_ID = 9999, -- 修改你的通信协议号
UI_NAME = "zhuansheng", -- UI界面名称
Maxlv = 10,
needItems = {"法师之星", "金币"},
levels = {
[1] = {needlevel = 75, needNum = {10, 10000000}},
[2] = {needlevel = 75, needNum = {20, 20000000}},
[3] = {needlevel = 75, needNum = {40, 30000000}},
[4] = {needlevel = 75, needNum = {80, 40000000}},
[5] = {needlevel = 75, needNum = {160, 50000000}},
[6] = {needlevel = 75, needNum = {320, 60000000}},
[7] = {needlevel = 75, needNum = {640, 70000000}},
[8] = {needlevel = 75, needNum = {1280, 80000000}},
[9] = {needlevel = 75, needNum = {2560, 90000000}},
[10] = {needlevel = 75, needNum = {5120, 100000000}},
}
}
function npc:Lmain() -- 前端的入口处
local ui = GUI:npcUi(self.CONFIG.UI_NAME) -- 调用export
-- 入场特效
GUI:runAction(ui.Node_1, GUI:ActionSequence(
GUI:ActionFadeIn(0.3),
GUI:ActionScaleTo(0.1, 1.1),
GUI:ActionScaleTo(0.1, 1)
))
-- 转生按钮事件
GUI:onClick(ui.sendbtn, function()
-- 按钮点击特效
GUI:runAction(ui.sendbtn, GUI:ActionSequence(
GUI:ActionScaleTo(0.1, 0.9),
GUI:ActionScaleTo(0.1, 1)
))
-- 发送转生请求到服务端
SL:toServer(self.CONFIG.MSG_ID, 1, 0, 0, "")
end)
-- 初始化物品显示
self:updataitemshow(ui)
end
function npc:updataitemshow(ui)
-- 这里需要从服务端获取当前转生等级来更新显示
-- 示例:更新法师之星和金币的显示
GUI:ItemShow_updateItem(ui.ItemShow_fszx, {
index = SL:itemname2idx("法师之星"),
count = 10, -- 应从配置或服务端获取
})
GUI:ItemShow_updateItem(ui.itemshow_money, {
index = SL:itemname2idx("金币"),
count = 10000000, -- 应从配置或服务端获取
})
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 rlv = getbaseinfo(actor, 39) -- 获取当前转生等级
if rlv >= self.CONFIG.Maxlv then
player:send("您已达成最高转生等级!")
return
end
local nextLv = rlv + 1
local cfg = self.CONFIG.levels[nextLv]
if not cfg then
player:send("转生配置错误!")
return
end
-- 检查等级
local curLv = getbaseinfo(actor, 6)
if curLv < cfg.needlevel then
player:send("等级不足" .. cfg.needlevel .. "级,无法进行" .. nextLv .. "转!")
return
end
-- 检查物品和金币
local itemName = self.CONFIG.needItems[1]
local itemIdx = itemname2idx(itemName)
local itemCount = getitemcount(actor, itemIdx)
if itemCount < cfg.needNum[1] then
player:send(itemName .. "数量不足,需要" .. cfg.needNum[1] .. "个!")
return
end
local money = getbaseinfo(actor, 40) -- 获取金币
if money < cfg.needNum[2] then
player:send("金币不足,需要" .. cfg.needNum[2] .. "!")
return
end
-- 消耗物品和金币
decitem(actor, itemIdx, cfg.needNum[1])
decmoney(actor, cfg.needNum[2])
-- 设置转生等级
setbaseinfo(actor, 39, nextLv)
-- 重置等级为1级
setbaseinfo(actor, 6, 1)
-- 添加属性加成(示例:加5-5攻击,5%HP)
local att = string.format("3#4#%s|3#6#%s|3#8#%s", 5, 5, 5)
player:attlist("转生属性加成", att)
-- 发送成功消息
player:send("恭喜你成功完成" .. nextLv .. "转!")
-- 通知前端刷新
player:send(self.CONFIG.MSG_ID, 2000, nextLv, 0, "")
end
return npc
← 返回问答库