Chat.lua 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151
  1. ---
  2. --- Created by zhouzhipeng.
  3. --- DateTime: 2024/8/20 下午1:55
  4. ---
  5. Chat = {}
  6. local this = {}
  7. --- 消息类型常量
  8. MsgTypeConst = {
  9. COMMON = 0, --普通消息
  10. TEAM_RECRUIT = 1, --组队招募
  11. DUPLICATE_RECRUIT = 2, --副本招募
  12. SIEGE_RECRUIT = 3, --攻城战召唤盟友
  13. KML_DUPTEAM_RECRUIT = 4, -- KML副本组队招募
  14. UNRECOGNIZED = -1, -- 未知
  15. }
  16. --- 聊天频道常量
  17. ChannelConst = {
  18. SYSTEM = 0; --系统
  19. FIGHT = 1; --战斗
  20. WORLD = 2; --世界
  21. CURRENT = 3; --当前
  22. UNION = 4; --公会
  23. RECRUIT = 5; --招募
  24. NEARBY = 6; --附近
  25. TEAM = 7; --队伍
  26. PERSONAL = 8; --私聊
  27. FRIEND = 9; --好友聊天
  28. TRADE = 10; --交易
  29. }
  30. -- 玩家是否在线
  31. function Chat.playerIsOnLineReq (actor, data)
  32. -- jprint("playerIsOnLineReq actor:" .. actor:toString() .. ", data类型:" .. type(data) .. ",data:" .. tostring(data))
  33. local onLineInfo = {}
  34. for _, id in pairs(data) do
  35. local targetactor = getactor(actor, id)
  36. local onHook = getbaseinfo(targetactor, "onhook")
  37. local online = {}
  38. online["rid"] = id
  39. if onHook == nil or onHook == "" then
  40. online["onLine"] = 1
  41. else
  42. online["onLine"] = tostring(onHook)
  43. end
  44. table.insert(onLineInfo, online)
  45. end
  46. sendluamsg(actor, LuaMessageIdToClient.PLAYER_IS_ON_LINE_RES, onLineInfo)
  47. -- jprint("playerIsOnLineReq actor:" .. actor:toString() .. ", 结尾 data类型: " .. type(data) .. ",data:" .. tostring(data))
  48. end
  49. -- 发送招募信息
  50. function Chat.reqRecruitInfo (actor, data)
  51. -- jprint("reqRecruitInfo actor:" .. actor:toString() .. ", data类型:" .. type(data) .. ",data:" .. tostring(data))
  52. local cfgId = data["id"]
  53. local channel = data["channel"]
  54. local maxLv, minLv = 0, 0
  55. if cfgId > 0 then
  56. local repList = ConfigDataManager.getById("cfg_rep", cfgId)
  57. if repList == nil then
  58. error(actor, actor "reqRecruitInfo cfg_rep id:", cfgId, "不存在")
  59. return
  60. end
  61. local repCfg = repList
  62. local levelStr = repCfg["level"]
  63. local levels = string.split(levelStr, "#")
  64. minLv = levels[1]
  65. maxLv = levels[2]
  66. end
  67. local teamSize = getbaseinfo(actor, "groupmembercount")
  68. local teamId = getbaseinfo(actor, "teamid")
  69. local teamMaxSize = ConfigDataManager.getTableValue("cfg_global", "value", "id", GlobalConfigId.TEAM_MEMBER_MAX)
  70. -- recruit@副本id,最小等级,最高等级,人数,总人数,team_id@
  71. local msg = "recruit@" .. cfgId .. "," .. minLv .. "," .. maxLv .. "," .. tostring(teamSize) .. "," .. teamMaxSize .. "," .. tostring(teamId) .. "@"
  72. if channel == 5 then
  73. local canShout = setteamtochannel(actor, cfgId, minLv, maxLv)
  74. if canShout == 0 then
  75. return
  76. end
  77. end
  78. sendtochannel(actor, msg, channel, MsgTypeConst.DUPLICATE_RECRUIT)
  79. end
  80. -- 队伍喊话
  81. function setteamtochannel(actor, cfgId, minLv, maxLv)
  82. local teamId = getbaseinfo(actor, "teamid")
  83. if teamId == 0 then
  84. noticeTip.noticeinfo(actor, StringIdConst.TEXT341)
  85. return 0
  86. end
  87. local teamSize = getbaseinfo(actor, "groupmembercount")
  88. local teamMaxSize = ConfigDataManager.getTableValue("cfg_global", "value", "id", 121)
  89. if teamMaxSize == teamSize then
  90. noticeTip.noticeinfo(actor, StringIdConst.TEXT342)
  91. return 0
  92. end
  93. local teamShout = getplaydef(actor, tostring(teamId))
  94. local now = getbaseinfo("now")
  95. if teamShout ~= nil and teamShout[1] > now then
  96. noticeTip.noticeinfo(actor, StringIdConst.TEXT343)
  97. return 0
  98. end
  99. local nextShoutTime = now + 30000
  100. local shoutInfo = { nextShoutTime, cfgId, minLv, maxLv }
  101. setplaydef(actor, tostring(teamId), shoutInfo)
  102. local teamInfo = getteaminfo(actor, teamId)
  103. local allTeamMemberInfo = teamInfo["allteammemberinfo"]
  104. for index, value in ipairs(allTeamMemberInfo) do
  105. local teamRid = value["rid"]
  106. local targetactor
  107. if actor:toString() == tostring(teamRid) then
  108. targetactor = actor
  109. elseif actor:toString() ~= tostring(teamRid) then
  110. targetactor = getactor(actor, teamRid)
  111. end
  112. Team.teamrecruitchange(targetactor, cfgId, maxLv, minLv)
  113. end
  114. return 1
  115. end
  116. function chattest(actor, rid)
  117. jprint("测试测试 reqRecruitInfo actor:" .. actor:toString())
  118. local cfgId = 1
  119. local maxLv, minLv = 0, 0
  120. if cfgId > 0 then
  121. local repList = ConfigDataManager.getById("cfg_rep", cfgId)
  122. if repList == nil then
  123. jprint("reqRecruitInfo cfg_rep id:" .. cfgId .. "不存在")
  124. return
  125. end
  126. local repCfg = repList[1]
  127. local levelStr = repCfg["level"]
  128. local levels = string.split(levelStr, "#")
  129. minLv = levels[1]
  130. maxLv = levels[2]
  131. end
  132. local teamSize = getbaseinfo(actor, "groupmembercount")
  133. local teamId = getbaseinfo(actor, "teamid")
  134. local teamMaxSize = ConfigDataManager.getTableValue("cfg_global", "value", "id", 121)
  135. local msg = "recruit@" .. cfgId .. "," .. minLv .. "," .. maxLv .. "," .. tostring(teamSize) .. "," .. teamMaxSize .. "," .. tostring(teamId) .. "@"
  136. sendtochannel(actor, msg, 5, 2)
  137. jprint("测试测试 reqRecruitInfo actor:" .. actor:toString() .. ", cfgId: " .. tostring(cfgId) .. ",maxLv:" .. tostring(maxLv) .. ", minLv:" .. tostring(minLv) .. ", teamSize:" .. tostring(teamSize) .. ", teamMaxSize:" .. tostring(teamMaxSize) .. ", teamId:" .. tostring(teamId))
  138. end