GoldLine_1.lua 2.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  1. GoldLine = {}
  2. function GoldLine.GetGoldMapInfo(actor, mapCfgId)
  3. local mapLineConfig = ConfigDataManager.getTableValue("cfg_map_line", "mapline", "id", mapCfgId)
  4. if string.isNullOrEmpty(mapLineConfig) then
  5. return
  6. end
  7. local lineMap = string.toStringStringMap(mapLineConfig, "#", "|")
  8. local result = {}
  9. for _, line in pairs(lineMap) do
  10. local playerCount = getmapplayercount(actor, mapCfgId, line)
  11. local mapItem = { mapCfgId = mapCfgId, line = line, playerCount = playerCount }
  12. table.insert(result, mapItem)
  13. end
  14. sendluamsg(actor, LuaMessageIdToClient.RES_MAP_INFO, result)
  15. end
  16. -- 扩展现有的 GoldLine 模块 2025.08.23 拓展地图线路
  17. function GoldLine.GetLinePolicy(actor, mapCfgId, line)
  18. -- 通过地图ID获取线路策略映射
  19. local mapLineConfig = ConfigDataManager.getTableValue("cfg_map_line", "line_policy_id", "id", mapCfgId)
  20. if string.isNullOrEmpty(mapLineConfig) then
  21. return nil
  22. end
  23. -- 解析线路策略映射,找到对应线路的策略ID
  24. local policyId = GoldLine.getPolicyIdByLine(mapLineConfig, line)
  25. if not policyId then
  26. return nil
  27. end
  28. -- 返回对应的策略配置
  29. local policy = ConfigDataManager.getTableValue("cfg_line_policy", "id", policyId)
  30. return policy
  31. end
  32. -- 新增:根据线路策略映射和线路ID获取策略ID 2025.08.23 拓展地图线路
  33. function GoldLine.getPolicyIdByLine(linePolicyStr, targetLine)
  34. if string.isNullOrEmpty(linePolicyStr) then
  35. return nil
  36. end
  37. -- 分割多个映射关系 "1#1|2#1|3#1"
  38. local mappings = string.split(linePolicyStr, "|")
  39. for _, mapping in pairs(mappings) do
  40. -- 分割单个映射 "1#1"
  41. local parts = string.split(mapping, "#")
  42. if #parts == 2 then
  43. local lineId = tonumber(parts[1])
  44. local policyId = tonumber(parts[2])
  45. if lineId == tonumber(targetLine) then
  46. return policyId
  47. end
  48. end
  49. end
  50. return nil
  51. end
  52. function GoldLine.checkEnterCondition(actor, condition)
  53. if condition == "NONE" then
  54. return true
  55. elseif condition == "TRADE_CARD" then
  56. -- 检查是否有交易卡
  57. local tradeCardId = 70700001
  58. return Bag.checkItem(actor, tradeCardId, 1)
  59. elseif condition == "ENJOY_PACKAGE" then
  60. -- 检查是否有畅玩礼包
  61. local enjoyPackageId = 70700002
  62. return Bag.checkItem(actor, enjoyPackageId, 1)
  63. end
  64. return false
  65. end
  66. function GoldLine.canEnterLine(actor, mapCfgId, targetLine)
  67. local policy = GoldLine.GetLinePolicy(actor, mapCfgId, targetLine)
  68. if not policy then
  69. return false, "线路不存在或地图不支持该线路"
  70. end
  71. -- 检查进入条件
  72. if not GoldLine.checkEnterCondition(actor, policy.enterCondition) then
  73. return false, "不满足进入条件"
  74. end
  75. return true, "可以进入"
  76. end