CustomTransmit.lua 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141
  1. CustomTransmit = {}
  2. function CustomTransmit.GetPointFromMapMove(mapId)
  3. -- 处理自定义坐标
  4. local mapMoveCfg = ConfigDataManager.getTableFirst("cfg_mapmove", "mapid", mapId)
  5. if mapMoveCfg == nil then
  6. return nil
  7. end
  8. local mapX = mapMoveCfg["mapx"]
  9. local mapY = mapMoveCfg["mapy"]
  10. if not string.isNullOrEmpty(mapX) and not string.isNullOrEmpty(mapY) then
  11. return tonumber(mapX), tonumber(mapY)
  12. end
  13. local poz = mapMoveCfg["poz"]
  14. local pointMap = string.toIntIntMap(poz, "#", "|")
  15. if table.isNullOrEmpty(pointMap) then
  16. return nil
  17. end
  18. local num = math.random(0, table.count(pointMap) - 1)
  19. local index = 0
  20. for x, y in pairs(pointMap) do
  21. if num == index then
  22. return x, y
  23. end
  24. index = index + 1
  25. end
  26. return nil
  27. end
  28. function CustomTransmit.CustomToTransmit(actor, targetMap, targetLine, currX, currY, x, y, fromMapMove)
  29. local checkResult = CustomTransmit.checkTransmit(actor, targetMap, targetLine, currX, currY, x, y)
  30. if checkResult ~= nil then
  31. return checkResult
  32. end
  33. local line = getbaseinfo(actor, "line")
  34. -- 如果坐标来自mapMove表,则再次自定义计算坐标点
  35. if fromMapMove then
  36. -- 判断地图是不是相同的地图.如果是.则坐标不变
  37. local pInfoMap = getbaseinfo(actor, "map")
  38. if pInfoMap == targetMap and line ~= targetLine then
  39. local px = getbaseinfo(actor, "x")
  40. local py = getbaseinfo(actor, "y")
  41. local result = {
  42. result = false,
  43. x = px,
  44. y = py
  45. }
  46. return result
  47. end
  48. local x, y = CustomTransmit.GetPointFromMapMove(targetMap)
  49. if x == nil or y == nil then
  50. return nil
  51. end
  52. local result = {
  53. result = false,
  54. x = x,
  55. y = y
  56. }
  57. -- jprint("自定义传送新坐标", targetMap, result)
  58. return result
  59. end
  60. -- 只能传送到当前线路
  61. local mapLineConfig = ConfigDataManager.getTableValue("cfg_map_line", "mapline", "id", targetMap)
  62. if string.isNullOrEmpty(mapLineConfig) then
  63. return
  64. end
  65. local canTransmit = false
  66. local lines = string.split(mapLineConfig, "|")
  67. for i,ll in ipairs(lines) do
  68. local sll = string.split(ll, "#")
  69. local ln = tonumber(sll[2])
  70. if ln == line then
  71. canTransmit = true
  72. break
  73. end
  74. end
  75. if canTransmit then
  76. return { result = false,
  77. x = x,
  78. y = y,
  79. line = line
  80. }
  81. end
  82. end
  83. function CustomTransmit.checkTransmit(actor, targetMap, targetLine, currX, currY, x, y)
  84. local mapId = getbaseinfo(actor, "unimapid")
  85. local dupInfo = getduplicate(mapId)
  86. if dupInfo then
  87. local dupType = dupInfo['type']
  88. if dupType == DuplicateType.WAR_ALLIANCE then
  89. return WarAlliance.CheckTransfer(actor, currX, currY, x, y)
  90. end
  91. end
  92. -- 检查能不能进入特权地图
  93. local inGoldMap = TripleIncome.CheckInGoldMap(actor, targetMap)
  94. if inGoldMap ~= nil then
  95. return inGoldMap
  96. end
  97. -- 内置传送校验跨服地图条件
  98. local targetMapConfig = ConfigDataManager.getById("cfg_map_info", targetMap)
  99. if table.isEmpty(targetMapConfig) then
  100. return nil
  101. end
  102. if targetMapConfig.serverType == CrossMap.CROSS_MAP_TYPE then
  103. return CrossMap.canEnter(actor, targetMap)
  104. end
  105. end
  106. function CustomTransmit.DoTransmit(actor, msgData)
  107. -- mapCfgId, line, x, y
  108. local mapCfgId = msgData.mapCfgId
  109. local line = msgData.line
  110. if string.isNullOrEmpty(mapCfgId) then
  111. mapCfgId = getbaseinfo(actor, "mapid")
  112. end
  113. if string.isNullOrEmpty(line) then
  114. line = getbaseinfo(actor, "line")
  115. end
  116. local x = msgData.x
  117. local y = msgData.y
  118. maptransfer(actor, x, y, mapCfgId, line)
  119. sendluamsg(actor, LuaMessageIdToClient.RES_CUSTOME_TRANSFER, {})
  120. end