CrossMap.lua 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156
  1. CrossMap = {}
  2. local IN_CROSS_MAP_KEY = "T$ENTER_CROSS_MAP"
  3. -- 跨服主城ID
  4. CrossMap.CROSS_MAP_ID = 21000
  5. --跨服地图类型
  6. CrossMap.CROSS_MAP_TYPE = 2;
  7. function CrossMap.Enter(actor)
  8. --神之国度的地图ID
  9. local mapId = CrossMap.CROSS_MAP_ID;
  10. if getbaseinfo(actor, "mapid") == mapId then
  11. noticeTip.noticeinfo(actor, StringIdConst.TEXT344)
  12. return
  13. end
  14. local cfgs = ConfigDataManager.getTable("cfg_mapmove", "mapid", mapId)
  15. local cfg = cfgs[1]
  16. local x = cfg["mapx"]
  17. local y = cfg["mapy"]
  18. if x == nil or x == nil then
  19. noticeTip.noticeinfo(actor, StringIdConst.TEXT345)
  20. return
  21. end
  22. local can_enter = CrossMap.canEnter(actor, mapId)
  23. if not can_enter then
  24. return
  25. end
  26. jprint("进入神之国度", actor, mapId, x, y)
  27. maptransfer(actor, x, y, mapId, 1)
  28. end
  29. function CrossMap.Transfer2NPC(actor, data)
  30. -- 快捷指令 - 传送跨服地图NPC
  31. local npc_id = data.npcid
  32. local npc_config = ConfigDataManager.getById("cfg_npclist", npc_id)
  33. gameDebug.assertTrue(table.notEmpty(npc_config), "获取NPC配置为空", npc_id)
  34. local map_id = npc_config.mapid
  35. local can_enter = CrossMap.canEnter(actor, map_id)
  36. if not can_enter then
  37. return
  38. end
  39. local x = npc_config.x
  40. local y = npc_config.y
  41. local line = 1
  42. local range = 1
  43. maptransfer(actor, x, y, map_id, line, range)
  44. local param = { ['map_id'] = map_id, ['npc_id'] = npc_id }
  45. sendluamsg(actor, LuaMessageIdToClient.RES_CROSS_MAP_TRANSFER_TO_NPC, param)
  46. end
  47. --- 校验是否可以进入跨服地图 (跨服地图的cfg_map_info表ID)
  48. function CrossMap.canEnter(actor, mapId)
  49. local condition = ConfigDataManager.getTableValue("cfg_map_info", "condition", "id", mapId)
  50. local condition_arr = string.split(condition, "#")
  51. if table.isEmpty(condition_arr) or #condition_arr < 3 then
  52. return true
  53. end
  54. -- 检查玩家等级、强化、追加
  55. local level_limit = string.tonumber(condition_arr[1])
  56. -- 检查等级
  57. if level_limit > 0 then
  58. local level = getbaseinfo(actor, "level")
  59. if level < level_limit then
  60. tipinfo(actor, "进入跨服地图角色等级需要" .. condition_arr[1] .. "级")
  61. return false
  62. end
  63. end
  64. -- 检查强化
  65. local strengthlv = CrossMap.GetEquipStrengthORAppendLv(actor, "strengthlv")
  66. local strong_limit = string.tonumber(condition_arr[2])
  67. if strong_limit > 0 and strengthlv < strong_limit then
  68. tipinfo(actor, "进入跨服强化总等级需要" .. condition_arr[2] .. "级")
  69. return false
  70. end
  71. -- 检查追加
  72. local appentlv = CrossMap.GetEquipStrengthORAppendLv(actor, "appendlv")
  73. local append_limit = string.tonumber(condition_arr[3])
  74. if append_limit > 0 and appentlv < append_limit then
  75. tipinfo(actor, "进入跨服追加总等级需要" .. condition_arr[3] .. "级")
  76. return false
  77. end
  78. return true
  79. end
  80. function CrossMap.EnterView(actor, targetActor)
  81. local osid = getbaseinfo(targetActor, "originalserverid")
  82. local targetServerId = getbaseinfo(targetActor, "serverid")
  83. jprint("查看sid", getbaseinfo(actor, "rolename"), osid, targetServerId)
  84. if osid ~= targetServerId then
  85. local targetId = getbaseinfo(targetActor, "id")
  86. local targetName = getbaseinfo(targetActor, "rolename")
  87. local res = {
  88. targetServerId = osid,
  89. targetId = targetId,
  90. targetName = targetName
  91. }
  92. sendluamsg(actor, LuaMessageIdToClient.RES_SERVER_ID_INFO, res)
  93. end
  94. end
  95. function CrossMap.CheckEnterCrossMap(actor, oldMapCfgId, newMapCfgId)
  96. local serverType = ConfigDataManager.getTableValue("cfg_map_info", "servertype", "id", newMapCfgId)
  97. if tonumber(serverType) == CrossMap.CROSS_MAP_TYPE then
  98. setplaydef(actor, IN_CROSS_MAP_KEY, 1)
  99. --进入跨服地图
  100. local res = { type = 1, mapId = newMapCfgId }
  101. sendluamsg(actor, LuaMessageIdToClient.RES_IN_OUT_CROSS_MAP, res)
  102. jprint("进入跨服地图", oldMapCfgId, newMapCfgId)
  103. else
  104. local state = getplaydef(actor, IN_CROSS_MAP_KEY)
  105. jprint("cross_state", state)
  106. if state ~= nil and state == 1 then
  107. --退出跨服地图
  108. local res = { type = 0, mapId = newMapCfgId }
  109. sendluamsg(actor, LuaMessageIdToClient.RES_IN_OUT_CROSS_MAP, res)
  110. jprint("退出跨服地图", oldMapCfgId, newMapCfgId)
  111. end
  112. setplaydef(actor, IN_CROSS_MAP_KEY, 0)
  113. end
  114. end
  115. function CrossMap.GetEquipStrengthORAppendLv(actor, args_name)
  116. local all_equip = getputonequipinfo(actor)
  117. local all_data = EquipAndAppear.getLuaItemExtData(actor)
  118. if table.isEmpty(all_equip) or table.isEmpty(all_data) then
  119. return false
  120. end
  121. local max_level = 0
  122. for _, equip in pairs(all_equip) do
  123. local equip_data = all_data[equip.id]
  124. if table.isEmpty(equip_data) then
  125. goto continue
  126. end
  127. local lv = equip_data[args_name] or 0
  128. max_level = max_level + lv
  129. :: continue ::
  130. end
  131. return max_level
  132. end