优化这段代码 if idxx == 1 then LuaFnDelAvailableItem(sceneId,selfId,30008106,1) LuaFnJoinMenpai(sceneId, selfId, targetId, 5) LuaFnSetXinFaLevel(sceneId,selfId,31,60) LuaFnSetXinFaLevel(sceneId,selfId,32,60) LuaFnSetXinFaLevel(sceneId,selfId,33,60) LuaFnSetXinFaLevel(sceneId,selfId,34,60) LuaFnSetXinFaLevel(sceneId,selfId,35,60) LuaFnSetXinFaLevel(sceneId,selfId,36,60) LuaFnSetXinFaLevel(sceneId,selfId,60,60) LuaFnSetXinFaLevel(sceneId,selfId,77,60) LuaFnSendSpecificImpactToUnit(sceneId, selfId, selfId, selfId, 148, 0) local nam = LuaFnGetName( sceneId, selfId ) BroadMsgByChatPipe( sceneId, selfId, "#Y恭喜玩家 "..nam.." 成功更换到星宿。", 4 ) return end if idxx == 2 then LuaFnJoinMenpai(sceneId, selfId, targetId, 8) LuaFnDelAvailableItem(sceneId,selfId,30008106,1) LuaFnSetXinFaLevel(sceneId,selfId,49,60) LuaFnSetXinFaLevel(sceneId,selfId,50,60) LuaFnSetXinFaLevel(sceneId,selfId,51,60) LuaFnSetXinFaLevel(sceneId,selfId,52,60) LuaFnSetXinFaLevel(sceneId,selfId,53,60) LuaFnSetXinFaLevel(sceneId,selfId,54,60) LuaFnSetXinFaLevel(sceneId,selfId,63,60) LuaFnSetXinFaLevel(sceneId,selfId,80,60) LuaFnSendSpecificImpactToUnit(sceneId, selfId, selfId, selfId, 148, 0) local nam = LuaFnGetName( sceneId, selfId ) BroadMsgByChatPipe( sceneId, selfId, "#Y恭喜玩家 "..nam.." 成功更换到逍遥。", 4 ) return end if idxx == 3 then LuaFnJoinMenpai(sceneId, selfId, targetId, 0) LuaFnDelAvailableItem(sceneId,selfId,30008106,1) LuaFnSetXinFaLevel(sceneId,selfId,1,60) LuaFnSetXinFaLevel(sceneId,selfId,2,60) LuaFnSetXinFaLevel(sceneId,selfId,3,60) LuaFnSetXinFaLevel(sceneId,selfId,4,60) LuaFnSetXinFaLevel(sceneId,selfId,5,60) LuaFnSetXinFaLevel(sceneId,selfId,6,60) LuaFnSetXinFaLevel(sceneId,selfId,55,60) LuaFnSetXinFaLevel(sceneId,selfId,72,60) LuaFnSendSpecificImpactToUnit(sceneId, selfId, selfId, selfId, 148, 0) local nam = LuaFnGetName( sceneId, selfId ) BroadMsgByChatPipe( sceneId, selfId, "#Y恭喜玩家 "..nam.." 成功更换到少林。", 4 ) return end
时间: 2023-06-25 21:05:55 浏览: 180
优化代码
可以将重复的代码提取出来,使代码更简洁和易于维护。比如可以定义一个表格,存储每个门派对应的技能等级,然后根据idxx的值从表格中获取相应的技能等级,遍历表格设置技能等级。代码如下:
```
-- 定义表格,存储每个门派对应的技能等级
local menpaiSkillLevel = {
[1] = {1, 2, 3, 4, 5, 6, 55, 72},
[2] = {31, 32, 33, 34, 35, 36, 60, 77},
[3] = {49, 50, 51, 52, 53, 54, 63, 80},
}
if idxx == 1 then
-- 星宿
LuaFnDelAvailableItem(sceneId,selfId,30008106,1)
LuaFnJoinMenpai(sceneId, selfId, targetId, 5)
local skillLevel = menpaiSkillLevel[1]
elseif idxx == 2 then
-- 逍遥
LuaFnJoinMenpai(sceneId, selfId, targetId, 8)
LuaFnDelAvailableItem(sceneId,selfId,30008106,1)
local skillLevel = menpaiSkillLevel[2]
elseif idxx == 3 then
-- 少林
LuaFnJoinMenpai(sceneId, selfId, targetId, 0)
LuaFnDelAvailableItem(sceneId,selfId,30008106,1)
local skillLevel = menpaiSkillLevel[3]
end
-- 遍历表格,设置技能等级
for i, level in ipairs(skillLevel) do
LuaFnSetXinFaLevel(sceneId,selfId,level,60)
end
LuaFnSendSpecificImpactToUnit(sceneId, selfId, selfId, selfId, 148, 0)
local nam = LuaFnGetName( sceneId, selfId )
if idxx == 1 then
BroadMsgByChatPipe( sceneId, selfId, "#Y恭喜玩家 "..nam.." 成功更换到星宿。", 4 )
elseif idxx == 2 then
BroadMsgByChatPipe( sceneId, selfId, "#Y恭喜玩家 "..nam.." 成功更换到逍遥。", 4 )
elseif idxx == 3 then
BroadMsgByChatPipe( sceneId, selfId, "#Y恭喜玩家 "..nam.." 成功更换到少林。", 4 )
end
return
```
阅读全文