优化下列代码 if arg == 101 then if GetMenPai(sceneId, selfId) ~= 9 then x990010_MsgBox( sceneId, selfId, targetId, "你已是别的门派的高徒了,我们不收你。" ) return end LuaFnJoinMenpai(sceneId, selfId, targetId, MP_XINGSU) LuaFnSetXinFaLevel(sceneId,selfId,31,30) LuaFnSetXinFaLevel(sceneId,selfId,32,30) LuaFnSetXinFaLevel(sceneId,selfId,33,30) LuaFnSetXinFaLevel(sceneId,selfId,34,30) LuaFnSetXinFaLevel(sceneId,selfId,35,30) LuaFnSetXinFaLevel(sceneId,selfId,36,30) --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, "#cFF0000[门派公告]:#c66ccff["..nam.."]#P已经加入了"..x990010_g_mpInfo[arg-101][1].."!", 4 ) CallScriptFunction( 999994, "ActionSkill",sceneId, selfId, -1 ) x990010_ooo( sceneId, selfId) end if arg == 102 then if GetMenPai(sceneId, selfId) ~= 9 then x990010_MsgBox( sceneId, selfId, targetId, "你已是别的门派的高徒了,我们不收你。" ) return end LuaFnJoinMenpai(sceneId, selfId, targetId, MP_XIAOYAO) LuaFnSetXinFaLevel(sceneId,selfId,49,30) LuaFnSetXinFaLevel(sceneId,selfId,50,30) LuaFnSetXinFaLevel(sceneId,selfId,51,30) LuaFnSetXinFaLevel(sceneId,selfId,52,30) LuaFnSetXinFaLevel(sceneId,selfId,53,30) LuaFnSetXinFaLevel(sceneId,selfId,54,30) --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, "#cFF0000[门派公告]:#c66ccff["..nam.."]#P已经加入了"..x990010_g_mpInfo[arg-101][1].."!", 4 ) x990010_ooo( sceneId, selfId) CallScriptFunction( 999994, "ActionSkill",sceneId, selfId, -1 ) end
时间: 2023-07-14 08:12:30 浏览: 141
优化代码
可以考虑将重复的代码提取为函数,减少代码冗余。同时,可以将一些常量进行定义,以提高代码可读性和可维护性。以下是优化后的代码:
```
local MP_XINGSU = 9
local MP_XIAOYAO = 10
local function joinMenpai(sceneId, selfId, targetId, mpInfo, xinfaLevels)
if GetMenPai(sceneId, selfId) ~= 9 then
x990010_MsgBox(sceneId, selfId, targetId, "你已是别的门派的高徒了,我们不收你。")
return
end
LuaFnJoinMenpai(sceneId, selfId, targetId, mpInfo[2])
for i, level in ipairs(xinfaLevels) do
LuaFnSetXinFaLevel(sceneId, selfId, level, 30)
end
LuaFnSendSpecificImpactToUnit(sceneId, selfId, selfId, selfId, 148, 0)
local name = LuaFnGetName(sceneId, selfId)
BroadMsgByChatPipe(sceneId, selfId, "#cFF0000[门派公告]:#c66ccff["..name.."]#P已经加入了"..mpInfo[1].."!", 4)
x990010_ooo(sceneId, selfId)
CallScriptFunction(999994, "ActionSkill", sceneId, selfId, -1)
end
if arg == 101 then
joinMenpai(sceneId, selfId, targetId, x990010_g_mpInfo[arg-101], {31, 32, 33, 34, 35, 36})
end
if arg == 102 then
joinMenpai(sceneId, selfId, targetId, x990010_g_mpInfo[arg-101], {49, 50, 51, 52, 53, 54})
end
```
阅读全文