Chat.lua 7.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209
  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. CROSS_MAP = 101; --跨服聊天
  30. }
  31. function Chat.onQuitGame(actor)
  32. setplaydef(actor, "T$chat_on_line", 1)
  33. end
  34. function Chat.login(actor)
  35. setplaydef(actor, "T$chat_on_line", 0)
  36. end
  37. -- 玩家是否在线
  38. function Chat.playerIsOnLineReq (actor, data)
  39. -- jprint("playerIsOnLineReq actor:" .. actor:toString() .. ", data类型:" .. type(data) .. ",data:" .. tostring(data))
  40. local onLineInfo = {}
  41. for _, id in pairs(data) do
  42. local targetactor = getactor(id, 1001)
  43. local value = 1
  44. if targetactor then
  45. value = getplaydef(targetactor, "T$chat_on_line")
  46. end
  47. local online = {}
  48. online["rid"] = id
  49. online["onLine"] = value
  50. table.insert(onLineInfo, online)
  51. end
  52. sendluamsg(actor, LuaMessageIdToClient.PLAYER_IS_ON_LINE_RES, onLineInfo)
  53. -- jprint("playerIsOnLineReq actor:" .. actor:toString() .. ", 结尾 data类型: " .. type(data) .. ",data:" .. tostring(data))
  54. end
  55. -- 发送招募信息
  56. function Chat.reqRecruitInfo (actor, data)
  57. -- jprint("reqRecruitInfo actor:" .. actor:toString() .. ", data类型:" .. type(data) .. ",data:" .. tostring(data))
  58. local cfgId = data["id"]
  59. local channel = data["channel"]
  60. local maxLv, minLv = 0, 0
  61. if cfgId > 0 then
  62. local repList = ConfigDataManager.getById("cfg_rep", cfgId)
  63. if repList == nil then
  64. error(actor, actor "reqRecruitInfo cfg_rep id:", cfgId, "不存在")
  65. return
  66. end
  67. local repCfg = repList
  68. local levelStr = repCfg["level"]
  69. local levels = string.split(levelStr, "#")
  70. minLv = levels[1]
  71. maxLv = levels[2]
  72. end
  73. local teamSize = getbaseinfo(actor, "groupmembercount")
  74. local teamId = getbaseinfo(actor, "teamid")
  75. local teamMaxSize = ConfigDataManager.getTableValue("cfg_global", "value", "id", GlobalConfigId.TEAM_MEMBER_MAX)
  76. -- recruit@副本id,最小等级,最高等级,人数,总人数,team_id@
  77. local msg = "recruit@" .. cfgId .. "," .. minLv .. "," .. maxLv .. "," .. tostring(teamSize) .. "," .. teamMaxSize .. "," .. tostring(teamId) .. "@"
  78. if channel == 5 then
  79. local canShout = setteamtochannel(actor, cfgId, minLv, maxLv)
  80. if canShout == 0 then
  81. return
  82. end
  83. end
  84. sendtochannel(actor, msg, channel, MsgTypeConst.DUPLICATE_RECRUIT)
  85. end
  86. -- 队伍喊话
  87. function setteamtochannel(actor, cfgId, minLv, maxLv)
  88. local teamId = getbaseinfo(actor, "teamid")
  89. if teamId == 0 then
  90. noticeTip.noticeinfo(actor, StringIdConst.TEXT341)
  91. return 0
  92. end
  93. local teamSize = getbaseinfo(actor, "groupmembercount")
  94. local teamMaxSize = ConfigDataManager.getTableValue("cfg_global", "value", "id", 121)
  95. if teamMaxSize == teamSize then
  96. noticeTip.noticeinfo(actor, StringIdConst.TEXT342)
  97. return 0
  98. end
  99. local teamShout = getplaydef(actor, tostring(teamId))
  100. local now = getbaseinfo("now")
  101. if teamShout ~= nil and teamShout[1] > now then
  102. noticeTip.noticeinfo(actor, StringIdConst.TEXT343)
  103. return 0
  104. end
  105. local nextShoutTime = now + 30000
  106. local shoutInfo = { nextShoutTime, cfgId, minLv, maxLv }
  107. setplaydef(actor, tostring(teamId), shoutInfo)
  108. local teamInfo = getteaminfo(actor, teamId)
  109. local allTeamMemberInfo = teamInfo["allteammemberinfo"]
  110. for index, value in ipairs(allTeamMemberInfo) do
  111. local teamRid = value["rid"]
  112. local targetactor
  113. if actor:toString() == tostring(teamRid) then
  114. targetactor = actor
  115. elseif actor:toString() ~= tostring(teamRid) then
  116. targetactor = getactor(actor, teamRid)
  117. end
  118. Team.teamrecruitchange(targetactor, cfgId, maxLv, minLv)
  119. end
  120. return 1
  121. end
  122. function chattest(actor, rid)
  123. jprint("测试测试 reqRecruitInfo actor:" .. actor:toString())
  124. local cfgId = 1
  125. local maxLv, minLv = 0, 0
  126. if cfgId > 0 then
  127. local repList = ConfigDataManager.getById("cfg_rep", cfgId)
  128. if repList == nil then
  129. jprint("reqRecruitInfo cfg_rep id:" .. cfgId .. "不存在")
  130. return
  131. end
  132. local repCfg = repList[1]
  133. local levelStr = repCfg["level"]
  134. local levels = string.split(levelStr, "#")
  135. minLv = levels[1]
  136. maxLv = levels[2]
  137. end
  138. local teamSize = getbaseinfo(actor, "groupmembercount")
  139. local teamId = getbaseinfo(actor, "teamid")
  140. local teamMaxSize = ConfigDataManager.getTableValue("cfg_global", "value", "id", 121)
  141. local msg = "recruit@" .. cfgId .. "," .. minLv .. "," .. maxLv .. "," .. tostring(teamSize) .. "," .. teamMaxSize .. "," .. tostring(teamId) .. "@"
  142. sendtochannel(actor, msg, 5, 2)
  143. jprint("测试测试 reqRecruitInfo actor:" .. actor:toString() .. ", cfgId: " .. tostring(cfgId) .. ",maxLv:" .. tostring(maxLv) .. ", minLv:" .. tostring(minLv) .. ", teamSize:" .. tostring(teamSize) .. ", teamMaxSize:" .. tostring(teamMaxSize) .. ", teamId:" .. tostring(teamId))
  144. end
  145. function Chat.OutVersionChant(actor, param)
  146. this.outVersionChant(actor, param)
  147. end
  148. function this.outVersionChant(actor, param)
  149. local channel = tonumber(param['channel'])
  150. if channel == ChannelConst.CROSS_MAP then
  151. this.crossMapChatChannel(actor, param)
  152. end
  153. end
  154. function this.crossMapChatChannel(actor, param)
  155. local content = param['content']
  156. local itemList = param['item']
  157. local nextChatTime = tonumber(param['nextchattime'])
  158. local channel = tonumber(param['channel'])
  159. local config = ConfigDataManager.getById("cfg_system_switch", 229)
  160. local needlevel = config['needlevel']
  161. if table.notEmpty(config) then
  162. local level = getbaseinfo(actor, "level")
  163. if tonumber(level) < string.tonumber(needlevel) then
  164. return
  165. end
  166. end
  167. local now = tonumber(getbaseinfo(actor, "now"))
  168. if now < nextChatTime then
  169. local logText = "再过".. (math.round((nextChatTime - now) / 1000)) .. "秒可以再次发言。"
  170. tipinfo(actor, logText)
  171. return
  172. end
  173. local chatParam = {}
  174. chatParam["content"] = content
  175. chatParam["item"] = itemList
  176. chatParam["channel"] = channel
  177. chatParam["target"] = {}
  178. chatParam["useworldcd"] = 1
  179. chatParam["iscrossmap"] = 1
  180. chatParam["crossmapcondition"] = "checklevel>=" .. needlevel
  181. outversionchat(actor, chatParam)
  182. end
  183. function this.debug(...)
  184. gameDebug.print("[Chat]", ...)
  185. end
  186. LoginEventListerTable:eventLister("0", "chat", Chat.login)