SummonAndChat.lua 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280
  1. SummonAndChat = {}
  2. -- 处理特殊道具
  3. function SummonAndChat.handleSpecialItems(actor, itemConfigId, count)
  4. -- info("MS===============" .. string.format("itemConfigId:%d, count:%d", itemConfigId, count))
  5. local itemConfig = ConfigDataManager.getById("cfg_item", itemConfigId)
  6. -- info("MS=============== itemConfig : ", itemConfig)
  7. if table.isNullOrEmpty(itemConfig) then
  8. return
  9. end
  10. local useParam = itemConfig.useparam
  11. if string.isNullOrEmpty(useParam) then
  12. return
  13. end
  14. local params = string.split(useParam, "#")
  15. local actionType = params[1]
  16. -- info("MS=============== 使用道具类型" .. string.format("actionType:%s", actionType))
  17. if actionType == "team_summon" then
  18. SummonAndChat.teamSummon(actor, itemConfigId, count)
  19. elseif actionType == "union_summon" then
  20. SummonAndChat.unionSummon(actor, itemConfigId, count)
  21. end
  22. end
  23. -- 队伍召唤功能
  24. function SummonAndChat.teamSummon(actor, itemConfigId, count)
  25. --找到队伍id
  26. local teamId = tonumber(getbaseinfo(actor, "teamid"))
  27. if teamId == nil or teamId == 0 then
  28. tipinfo(actor, "您不在队伍中")
  29. return false
  30. end
  31. local teamInfo = getteaminfo(actor, teamId)
  32. if table.isNullOrEmpty(teamInfo) then
  33. tipinfo(actor, "队伍信息获取失败")
  34. return false
  35. end
  36. -- 检查是否为队长
  37. local allTeamMemberInfo = teamInfo["allteammemberinfo"]
  38. --local isLeader = false
  39. --for _, memberInfo in pairs(allTeamMemberInfo) do
  40. --if tonumber(memberInfo["rid"]) == tonumber(getbaseinfo(actor, "rid")) and tonumber(memberInfo["leader"]) == 1 then
  41. --isLeader = true
  42. --break
  43. --end
  44. --end
  45. -- if not isLeader then
  46. -- tipinfo(actor, "只有队长才能使用队伍召唤卡")
  47. -- return false
  48. -- end
  49. -- 获取队长位置信息
  50. local mapId = tonumber(getbaseinfo(actor, "mapid"))
  51. local line = tonumber(getbaseinfo(actor, "line"))
  52. local x = tonumber(getbaseinfo(actor, "x"))
  53. local y = tonumber(getbaseinfo(actor, "y"))
  54. local mapName = getmapname(actor, mapId)
  55. local requesterName = getrolefield(actor, "role.basic.name")
  56. local requesterRid = tonumber(getbaseinfo(actor, "rid"))
  57. -- 向所有队员发送传送请求
  58. local summonCount = 0
  59. for _, memberInfo in pairs(allTeamMemberInfo) do
  60. local memberRid = tonumber(memberInfo["rid"])
  61. if memberRid ~= requesterRid then -- 不给自己发送
  62. local memberActor = getactor(actor, memberRid)
  63. if memberActor then
  64. -- 发送传送请求消息
  65. SummonAndChat.sendTransferRequest(memberActor, requesterRid, requesterName, "team", mapId, mapName,
  66. line, x, y)
  67. summonCount = summonCount + 1
  68. end
  69. end
  70. end
  71. if summonCount > 0 then
  72. tipinfo(actor, string.format("已向%d名队员发送传送请求", summonCount))
  73. return true
  74. else
  75. tipinfo(actor, "没有可召唤的队员")
  76. return false
  77. end
  78. end
  79. -- 战盟召唤功能
  80. function SummonAndChat.unionSummon(actor, itemConfigId, count)
  81. -- 检查是否为盟主
  82. local unionId = tonumber(getbaseinfo(actor, "unionid"))
  83. if unionId == nil or unionId == 0 then
  84. tipinfo(actor, "您不在战盟中")
  85. return false
  86. end
  87. local unionInfo = getunioninfo(actor, unionId)
  88. if table.isNullOrEmpty(unionInfo) then
  89. tipinfo(actor, "战盟信息获取失败")
  90. return false
  91. end
  92. -- 获取盟主位置信息
  93. local mapId = tonumber(getbaseinfo(actor, "mapid"))
  94. local line = tonumber(getbaseinfo(actor, "line"))
  95. local x = tonumber(getbaseinfo(actor, "x"))
  96. local y = tonumber(getbaseinfo(actor, "y"))
  97. local mapName = getbaseinfo(actor, 'maptitle')
  98. local requesterName = getrolefield(actor, "role.basic.name")
  99. local requesterRid = getbaseinfo(actor, "rid")
  100. -- 向所有战盟成员发送传送请求
  101. local allUnionMemberInfo = unionInfo["memberinfos"]
  102. -- info("MS=============== allUnionMemberInfo 数量 : ", #allUnionMemberInfo)
  103. local summonCount = 0
  104. for _, memberInfo in pairs(allUnionMemberInfo) do
  105. local memberRid = tonumber(memberInfo.rid)
  106. if memberRid ~= requesterRid then -- 不给自己发送
  107. local memberActor = getactor(actor, memberRid)
  108. if memberActor and tonumber(getbaseinfo(memberActor, "onlinestate")) == 1 then
  109. -- 发送传送请求消息
  110. info(string.format("MS=============== 发送传送请求消息给 %d requesterName: %s", memberRid, requesterName))
  111. SummonAndChat.sendTransferRequest(memberActor, requesterRid, requesterName, "union", mapId, mapName, line,
  112. x, y)
  113. summonCount = summonCount + 1
  114. info(string.format("MS=============== 发送传送请求消息完成, 当前数量 : %d", summonCount))
  115. end
  116. end
  117. end
  118. info(string.format("MS=============== 发送传送请求消息数量 : %d", summonCount))
  119. if summonCount > 0 then
  120. tipinfo(actor, string.format("已向 【 %d 名 】 战盟成员发送传送请求", summonCount))
  121. return true
  122. else
  123. tipinfo(actor, "没有可召唤的战盟成员")
  124. return false
  125. end
  126. end
  127. -- 发送传送请求消息
  128. function SummonAndChat.sendTransferRequest(targetActor, requesterRid, requesterName, requestType, mapId, mapName, line, x,
  129. y)
  130. local requestData = {
  131. requesterRid = requesterRid,
  132. requesterName = requesterName,
  133. requestType = requestType, -- "team" 或 "union"
  134. mapId = mapId,
  135. mapName = mapName,
  136. line = line,
  137. x = x,
  138. y = y,
  139. timestamp = getbaseinfo("nowsec")
  140. }
  141. -- 发送传送请求消息到客户端
  142. sendluamsg(targetActor, LuaMessageIdToClient.RES_SUMMON_TRANSFER_SUCCESS, requestData)
  143. -- info("MS=============== 发送传送请求消息到客户端")
  144. -- 存储请求信息,用于后续处理
  145. local requestKey = "@transfer_request_" .. requesterRid
  146. setplaydef(targetActor, requestKey, requestData)
  147. end
  148. -- 处理传送请求响应
  149. function SummonAndChat.handleTransferResponse(actor, msgData)
  150. -- info("MS=============== handleTransferResponse: ", msgData)
  151. local requestKey = "@transfer_request_" .. msgData.requesterRid
  152. local accepted = msgData.accepted
  153. local requesterRid = msgData.requesterRid
  154. local itemsNeedIndex = msgData.itemsNeedIndex
  155. local requestData = getplaydef(actor, requestKey)
  156. -- info("MS=============== 获取请求信息,用于后续处理 requestData: ", requestData)
  157. if table.isNullOrEmpty(requestData) then
  158. tipinfo(actor, "传送请求已过期")
  159. return false
  160. end
  161. -- 清除请求数据
  162. setplaydef(actor, requestKey, nil)
  163. if accepted then
  164. -- 检查请求是否过期(30秒内有效)
  165. local currentTime = getbaseinfo("nowsec")
  166. if currentTime - requestData.timestamp > 30 then
  167. tipinfo(actor, "传送请求已过期")
  168. return false
  169. end
  170. -- 检查地图是否可以传送
  171. local canTransfer, reason = SummonAndChat.checkMapTransferCondition(actor, requestData.mapId, requestData.line,
  172. requestData.x, requestData.y)
  173. -- info("MS=============== canTransfer: ", canTransfer)
  174. -- info("MS=============== reason: ", reason)
  175. if canTransfer then
  176. canTransfer, reason = SummonAndChat.checkMapTransferItemsNeed(actor, requestData.mapId, itemsNeedIndex)
  177. end
  178. -- info("MS=============== canTransfer2: ", canTransfer)
  179. -- info("MS=============== reason2: ", reason)
  180. if canTransfer then
  181. -- 执行传送
  182. maptransfer(actor, requestData.x, requestData.y, requestData.mapId, requestData.line, 3)
  183. -- tipinfo(actor, "已传送到" .. requestData.requesterName .. "身边")
  184. -- info("MS=============== 已传送到" .. requestData.requesterName .. "身边")
  185. -- 通知请求者
  186. local requesterActor = getactor(requestData.requesterRid)
  187. if requesterActor then
  188. local targetName = getrolefield(actor, "role.basic.name")
  189. tipinfo(requesterActor, "【 " .. targetName .. " 】接受了传送请求")
  190. end
  191. return true
  192. else
  193. tipinfo(actor, "无法传送:" .. reason)
  194. return false
  195. end
  196. else
  197. -- 通知请求者
  198. local requesterActor = getactor(requestData.requesterRid)
  199. if requesterActor then
  200. local targetName = getrolefield(actor, "role.basic.name")
  201. tipinfo(requesterActor, targetName .. "拒绝了传送请求")
  202. end
  203. tipinfo(actor, "已拒绝传送请求")
  204. return false
  205. end
  206. end
  207. -- 检查地图是否可以传送
  208. function SummonAndChat.checkMapTransferCondition(actor, mapId, line, x, y)
  209. -- 检查地图是否存在
  210. if not getmapname(actor, mapId) then
  211. return false, "目标地图不存在"
  212. end
  213. -- 检查线路是否存在
  214. if line <= 0 then
  215. return false, "目标线路无效"
  216. end
  217. -- 检查坐标是否有效
  218. if x < 0 or y < 0 then
  219. return false, "目标坐标无效"
  220. end
  221. -- 检查等级是否满足
  222. local mapLevel = ConfigDataManager.getTableValue("cfg_map_info", "intolv", "id", mapId)
  223. if tonumber(mapLevel) > tonumber(getbaseinfo(actor, "level")) then
  224. return false, "你的等级不足" .. mapLevel .. "级"
  225. end
  226. -- 检查是否在同一地图
  227. -- local currentMapId = tonumber(getbaseinfo(actor, "mapid"))
  228. -- if currentMapId ~= mapId then
  229. -- return false, "只能在同一地图内传送"
  230. -- end
  231. local checkResult, tip = LineManager.CheckCanEnterLineMap(actor, mapId, line)
  232. if checkResult ~= nil and checkResult == false then
  233. return checkResult, tip
  234. end
  235. return true, ""
  236. end
  237. -- 检查地图是否可以传送
  238. function SummonAndChat.checkMapTransferItemsNeed(actor, mapId, itemsNeedIndex)
  239. -- 检查地图是否存在
  240. if not getmapname(actor, mapId) then
  241. return false, "目标地图不存在"
  242. end
  243. local checkResult, tip = LineManager.CheckEnterLineMapItemsNeed(actor, mapId, itemsNeedIndex)
  244. if checkResult ~= nil and checkResult == false then
  245. return checkResult, tip
  246. end
  247. return true, ""
  248. end