优化代码 if GetMenPai(sceneId, selfId) == 9 then if idxx == 1 then 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) TryRecieveItem( sceneId, selfId, 39000043, 1)--新手礼包 TryRecieveItem( sceneId, selfId, 10124005, 1)--新手时装 TryRecieveItem( sceneId, selfId, 10141006, 1)--新手坐骑 LuaFnSendSpecificImpactToUnit(sceneId, selfId, selfId, selfId, 160, 0) local nam = LuaFnGetName( sceneId, selfId ) BroadMsgByChatPipe( sceneId, selfId, "#Y恭喜玩家 "..nam.." 成功加入到星宿。", 4 ) return end if idxx == 2 then LuaFnJoinMenpai(sceneId, selfId, targetId, 8) 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) TryRecieveItem( sceneId, selfId, 39000043, 1)--新手礼包 TryRecieveItem( sceneId, selfId, 10124007, 1)--新手时装 TryRecieveItem( sceneId, selfId, 10141007, 1)--新手坐骑 LuaFnSendSpecificImpactToUnit(sceneId, selfId, selfId, selfId, 160, 0) local nam = LuaFnGetName( sceneId, selfId ) BroadMsgByChatPipe( sceneId, selfId, "#Y恭喜玩家 "..nam.." 成功加入到逍遥。", 4 ) return end
时间: 2023-06-26 16:05:13 浏览: 97
代码优化方式
可以尝试使用一个表格来存储每个门派的信息,包括门派id、技能等级等等。然后根据传入的门派id在表格中查找对应的信息,避免了大量的if语句。示例代码如下:
```
-- 定义门派信息表格
local menpaiInfo = {
[9] = { -- 星宿
xinfaLevels = {31, 32, 33, 34, 35, 36, 60, 77},
specificImpactIds = {148, 160},
items = {{id=39000043, count=1}, {id=10124005, count=1}, {id=10141006, count=1}},
chatMsg = "#Y恭喜玩家 %s 成功加入到星宿。",
joinMenpaiFunc = function(sceneId, selfId, targetId)
return LuaFnJoinMenpai(sceneId, selfId, targetId, 5)
end
},
[2] = { -- 逍遥
xinfaLevels = {49, 50, 51, 52, 53, 54, 63, 80},
specificImpactIds = {148, 160},
items = {{id=39000043, count=1}, {id=10124007, count=1}, {id=10141007, count=1}},
chatMsg = "#Y恭喜玩家 %s 成功加入到逍遥。",
joinMenpaiFunc = function(sceneId, selfId, targetId)
return LuaFnJoinMenpai(sceneId, selfId, targetId, 8)
end
}
}
-- 根据传入的门派id查找对应的信息
local info = menpaiInfo[GetMenPai(sceneId, selfId)]
if info then
if idxx == 1 or idxx == 2 then
info.joinMenpaiFunc(sceneId, selfId, targetId)
for _, xinfaLevel in ipairs(info.xinfaLevels) do
LuaFnSetXinFaLevel(sceneId, selfId, xinfaLevel, 60)
end
for _, specificImpactId in ipairs(info.specificImpactIds) do
LuaFnSendSpecificImpactToUnit(sceneId, selfId, selfId, selfId, specificImpactId, 0)
end
for _, item in ipairs(info.items) do
TryRecieveItem(sceneId, selfId, item.id, item.count)
end
local nam = LuaFnGetName(sceneId, selfId)
BroadMsgByChatPipe(sceneId, selfId, string.format(info.chatMsg, nam), 4)
return
end
end
```
注意,这只是一个简单的示例代码,如果需要更多的门派信息或者处理逻辑,需要根据实际情况来修改。
阅读全文