CrossMap.lua 5.5 KB

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