-------------------------------------------------------------------------------------
-------------------------------------------------------------------------------------
--ahsin做的:宠物快捷加点lua
--版本:20241105
--本lua只支持cgmsv+新框架,不然100%跑不起来
-------------------------------------------------------------------------------------
-------------------------------------------------------------------------------------
--模块类
local petjdModule = ModuleBase:createModule('petjd')
--加载模块钩子
function petjdModule nLoad()
self:logInfo('load')
petjd_npc = self:NPC_createNormal('宠物快捷加点',14720,{x=247,y=92,mapType=0,map=1000,direction=4})--触发用npc
Char.SetData(petjd_npc,CONST.对象_ENEMY_PetFlg+2,0)--可穿透体
self:NPC_regWindowTalkedEvent(petjd_npc,Func.bind(self.playersel,self))--窗口点选触发
self:NPC_regTalkedEvent(petjd_npc,Func.bind(self.face2npc,self))--面向npc触发
end
local petindex = {}--宠物index表
local petname = {}--宠物名字表
local petpoints = {}--宠物待加点表
local nowpet = {}--宠物选择表
local nowsel = {}--bp选择表
function petjdModule:playersel(npc,player,seq,sel,data)--窗口点选触发
--print("seq:"..seq.." ,sel:"..sel.." data:"..data)
seq = tonumber(seq)
sel = tonumber(sel)
data = tonumber(data)
if sel == 16 then--返回
self:face2npc(npc,player)
end
if seq == 101 then--选宠物
for i= 1,5 do
if data == i and petname[player][i-1] == '无' then--该位置没宠
NLG.ShowWindowTalked(player,npc,%窗口_信息框%,18,404,'@c\\n\\n\\n\\n该位置没有宠物。')
return
elseif data == i and petpoints[player][i-1] == 0 then--该宠物无点可加
NLG.ShowWindowTalked(player,npc,%窗口_信息框%,18,404,'@c\\n\\n\\n\\n'..petname[player][i-1]..' 的待加点数不足。')
return
elseif data == i then--可加点
nowpet[player] = {}
nowpet[player] = petindex[player][i-1]
local msg = '3|@c\\n【CN魔力 - 宠物快捷加点】\\n\\n'
..petname[player][i-1]..' | 剩余点数:'..petpoints[player][i-1]
..'\\n\\n加体力\\n加力量\\n加强度\\n加速度\\n加魔法'
NLG.ShowWindowTalked(player,npc,%窗口_选择框%,18,202,msg)
return
end
end
end
if seq == 202 then--选加点项目
local name = Char.GetData(nowpet[player],CONST.对象_名字)
local point = Char.GetData(nowpet[player],CONST.对象_升级点)
local level = Char.GetData(nowpet[player],CONST.对象_等级)
local tili = math.floor(Char.GetData(nowpet[player],CONST.对象_体力)/100)
local liliang = math.floor(Char.GetData(nowpet[player],CONST.对象_力量)/100)
local qiangdu = math.floor(Char.GetData(nowpet[player],CONST.对象_强度)/100)
local sudu = math.floor(Char.GetData(nowpet[player],CONST.对象_速度)/100)
local mofa = math.floor(Char.GetData(nowpet[player],CONST.对象_魔法)/100)
local total = math.floor((point+tili+liliang+qiangdu+sudu+mofa)/2)
if data == 2 then--加体力
if tili >= total then
NLG.ShowWindowTalked(player,npc,%窗口_信息框%,18,404,'@c\\n\\n\\n\\n体力已爆点,无法加点。')
else
nowsel[player] = '体力'
local msg = ' 【CN魔力 - 宠物体力加点】\\n'
..'\\n 名称:'..name..' 等级:'..level
..'\\n'
..'\\n'..left(' 现体力:$1'..tili..'$0',24)..' 拥有点:$5'..point..'$0'
..'\\n'..left(' 爆体力:$4'..total..'$0',24)..' 最多加:$8'..total-tili..'$0'
..'\\n\\n\\n↓↓↓请输入需要加的体力点'
NLG.ShowWindowTalked(player,npc,%窗口_输入框%,19,303,msg)
end
return
elseif data == 3 then--加力量
if liliang >= total then
NLG.ShowWindowTalked(player,npc,%窗口_信息框%,18,404,'@c\\n\\n\\n\\n力量已爆点,无法加点。')
else
nowsel[player] = '力量'
local msg = ' 【CN魔力 - 宠物力量加点】\\n'
..'\\n 名称:'..name..' 等级:'..level
..'\\n'
..'\\n'..left(' 现力量:$1'..liliang..'$0',24)..' 拥有点:$5'..point..'$0'
..'\\n'..left(' 爆力量:$4'..total..'$0',24)..' 最多加:$8'..total-liliang..'$0'
..'\\n\\n\\n↓↓↓请输入需要加的力量点'
NLG.ShowWindowTalked(player,npc,%窗口_输入框%,19,303,msg)
end
return
elseif data == 4 then--加强度
if qiangdu >= total then
NLG.ShowWindowTalked(player,npc,%窗口_信息框%,18,404,'@c\\n\\n\\n\\n强度已爆点,无法加点。')
else
nowsel[player] = '强度'
local msg = ' 【CN魔力 - 宠物强度加点】\\n'
..'\\n 名称:'..name..' 等级:'..level
..'\\n'
..'\\n'..left(' 现强度:$1'..qiangdu..'$0',24)..' 拥有点:$5'..point..'$0'
..'\\n'..left(' 爆强度:$4'..total..'$0',24)..' 最多加:$8'..total-qiangdu..'$0'
..'\\n\\n\\n↓↓↓请输入需要加的强度点'
NLG.ShowWindowTalked(player,npc,%窗口_输入框%,19,303,msg)
end
return
elseif data == 5 then--加速度
if sudu >= total then
NLG.ShowWindowTalked(player,npc,%窗口_信息框%,18,404,'@c\\n\\n\\n\\n速度已爆点,无法加点。')
else
nowsel[player] = '速度'
local msg = ' 【CN魔力 - 宠物速度加点】\\n'
..'\\n 名称:'..name..' 等级:'..level
..'\\n'
..'\\n'..left(' 现速度:$1'..sudu..'$0',24)..' 拥有点:$5'..point..'$0'
..'\\n'..left(' 爆速度:$4'..total..'$0',24)..' 最多加:$8'..total-sudu..'$0'
..'\\n\\n\\n↓↓↓请输入需要加的速度点'
NLG.ShowWindowTalked(player,npc,%窗口_输入框%,19,303,msg)
end
return
elseif data == 6 then--加魔法
if mofa >= total then
NLG.ShowWindowTalked(player,npc,%窗口_信息框%,18,404,'@c\\n\\n\\n\\n魔法已爆点,无法加点。')
else
nowsel[player] = '魔法'
local msg = ' 【CN魔力 - 宠物魔法加点】\\n'
..'\\n 名称:'..name..' 等级:'..level
..'\\n'
..'\\n'..left(' 现魔法:$1'..mofa..'$0',24)..' 拥有点:$5'..point..'$0'
..'\\n'..left(' 爆魔法:$4'..total..'$0',24)..' 最多加:$8'..total-mofa..'$0'
..'\\n\\n\\n↓↓↓请输入需要加的魔法点'
NLG.ShowWindowTalked(player,npc,%窗口_输入框%,19,303,msg)
end
return
end
end
if seq == 303 then--加点
if not isinteger(data) then
NLG.ShowWindowTalked(player,npc,%窗口_信息框%,18,404,'@c\\n\\n\\n\\n只能输入大于0的整数的数字。')
return
end
local name = Char.GetData(nowpet[player],CONST.对象_名字)
local point = Char.GetData(nowpet[player],CONST.对象_升级点)
local level = Char.GetData(nowpet[player],CONST.对象_等级)
local tili = math.floor(Char.GetData(nowpet[player],CONST.对象_体力)/100)
local liliang = math.floor(Char.GetData(nowpet[player],CONST.对象_力量)/100)
local qiangdu = math.floor(Char.GetData(nowpet[player],CONST.对象_强度)/100)
local sudu = math.floor(Char.GetData(nowpet[player],CONST.对象_速度)/100)
local mofa = math.floor(Char.GetData(nowpet[player],CONST.对象_魔法)/100)
local total = math.floor((point+tili+liliang+qiangdu+sudu+mofa)/2)
if point <= 0 then
NLG.ShowWindowTalked(player,npc,%窗口_信息框%,18,404,'@c\\n\\n\\n\\n'..name..' 的点数已用完。')
return
end
if data > point then
NLG.ShowWindowTalked(player,npc,%窗口_信息框%,18,404,'@c\\n\\n\\n\\n你输入的数字大于拥有点数。')
return
end
if nowsel[player] == '体力' and sel == 1 then
if data > total-tili then
NLG.ShowWindowTalked(player,npc,%窗口_信息框%,18,404,'@c\\n\\n\\n\\n体力已爆点,无法加点。')
return
end
Char.SetData(nowpet[player],CONST.对象_升级点,point-data)
Char.SetData(nowpet[player],CONST.对象_体力,(tili+data)*100)
Pet.UpPet(player,nowpet[player])
NLG.PlaySe(player,78,0,0)
NLG.ShowWindowTalked(player,npc,%窗口_信息框%,17,888,'@c\\n名称:'..name..' 等级:'..level..'\\n\\n\\n\\n本次体力加了:'..data..'点,完成。')
return
end
if nowsel[player] == '力量' and sel == 1 then
if data > total-liliang then
NLG.ShowWindowTalked(player,npc,%窗口_信息框%,18,404,'@c\\n\\n\\n\\n力量已爆点,无法加点。')
return
end
Char.SetData(nowpet[player],CONST.对象_升级点,point-data)
Char.SetData(nowpet[player],CONST.对象_力量,(liliang+data)*100)
Pet.UpPet(player,nowpet[player])
NLG.PlaySe(player,78,0,0)
NLG.ShowWindowTalked(player,npc,%窗口_信息框%,17,888,'@c\\n名称:'..name..' 等级:'..level..'\\n\\n\\n\\n本次力量加了:'..data..'点,完成。')
return
end
if nowsel[player] == '强度' and sel == 1 then
if data > total-qiangdu then
NLG.ShowWindowTalked(player,npc,%窗口_信息框%,18,404,'@c\\n\\n\\n\\n强度已爆点,无法加点。')
return
end
Char.SetData(nowpet[player],CONST.对象_升级点,point-data)
Char.SetData(nowpet[player],CONST.对象_强度,(qiangdu+data)*100)
Pet.UpPet(player,nowpet[player])
NLG.PlaySe(player,78,0,0)
NLG.ShowWindowTalked(player,npc,%窗口_信息框%,17,888,'@c\\n名称:'..name..' 等级:'..level..'\\n\\n\\n\\n本次强度加了:'..data..'点,完成。')
return
end
if nowsel[player] == '速度' and sel == 1 then
if data > total-sudu then
NLG.ShowWindowTalked(player,npc,%窗口_信息框%,18,404,'@c\\n\\n\\n\\n速度已爆点,无法加点。')
return
end
Char.SetData(nowpet[player],CONST.对象_升级点,point-data)
Char.SetData(nowpet[player],CONST.对象_速度,(sudu+data)*100)
Pet.UpPet(player,nowpet[player])
NLG.PlaySe(player,78,0,0)
NLG.ShowWindowTalked(player,npc,%窗口_信息框%,17,888,'@c\\n名称:'..name..' 等级:'..level..'\\n\\n\\n\\n本次速度加了:'..data..'点,完成。')
return
end
if nowsel[player] == '魔法' and sel == 1 then
if data > total-mofa then
NLG.ShowWindowTalked(player,npc,%窗口_信息框%,18,404,'@c\\n\\n\\n\\n魔法已爆点,无法加点。')
return
end
Char.SetData(nowpet[player],CONST.对象_升级点,point-data)
Char.SetData(nowpet[player],CONST.对象_魔法,(mofa+data)*100)
Pet.UpPet(player,nowpet[player])
NLG.PlaySe(player,78,0,0)
NLG.ShowWindowTalked(player,npc,%窗口_信息框%,17,888,'@c\\n名称:'..name..' 等级:'..level..'\\n\\n\\n\\n本次魔法加了:'..data..'点,完成。')
return
end
end
end
function petjdModule:face2npc(npc,player)--面向npc触发
petindex[player] = {}
petname[player] = {}
petpoints[player] = {}
for i = 0,4 do
petindex[player] = Char.GetPet(player,i)
petname[player] = Char.GetData(petindex[player],CONST.对象_名字) or '无'
petpoints[player] = Char.GetData(petindex[player],CONST.对象_升级点) or 0
end
local xunxi = "3|@c\\n【CN魔力 - 宠物快捷加点】"
.."\\n请选择需要加点的宠物:"
.."\\n"
.."\\n"..petname[player][0]..' | 剩余点数:'..petpoints[player][0]
.."\\n"..petname[player][1]..' | 剩余点数:'..petpoints[player][1]
.."\\n"..petname[player][2]..' | 剩余点数:'..petpoints[player][2]
.."\\n"..petname[player][3]..' | 剩余点数:'..petpoints[player][3]
.."\\n"..petname[player][4]..' | 剩余点数:'..petpoints[player][4]
NLG.ShowWindowTalked(player,npc,%窗口_选择框%,%按钮_关闭%,101,xunxi)
end
function left(str,len)--居左
local char = ' ' -- 填充空格
if len-#str >= 0 then
local padding = string.rep(char,len-#str)
return str..padding
else
return str
end
end
function isinteger(v)--大于0的整数判断
if not tonumber(v) then
--print('integer false1')
return false
end
if tonumber(v) <= 0 then
--print('integer false2')
return false
end
if tonumber(v) % 1 == 0 then
--print('integer true')
return true
else
--print('integer false3')
return false
end
end
--卸载模块钩子
function petjdModule nUnload()
self:logInfo('unload')
end
return petjdModule
|
|