TeamProxy.lua 30 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961
  1. local RemoteProxy = requireProxy("remote/RemoteProxy")
  2. local TeamProxy = class("TeamProxy", RemoteProxy)
  3. TeamProxy.NAME = global.ProxyTable.TeamProxy
  4. local cjson = require("cjson")
  5. local bubbleId = 3
  6. -- 0创建队伍 1解散队伍 2加入队伍 3离开队伍 4换队长
  7. TeamProxy.ChangeType = {
  8. CREATE = 0,
  9. DISMISS = 1,
  10. JOIN_IN = 2,
  11. LEAVE = 3,
  12. UPDATE = 4,
  13. }
  14. function TeamProxy:ctor()
  15. TeamProxy.super.ctor(self)
  16. self._data = {}
  17. self._memberMax = 11 -- 人数上限
  18. self._noCallRemind = false -- 不再提醒召集令
  19. self:Init()
  20. end
  21. function TeamProxy:Init()
  22. -- 我在队伍中职位 1队长 0队员
  23. self._data.myRank = 0
  24. -- 成员列表
  25. self._data.memberItems = {}
  26. -- 附近队伍列表
  27. self._data.nearTeamItems = {}
  28. -- 申请列表
  29. self._data.applyItems = {}
  30. -- 邀请列表
  31. self._data.inviteItems = {}
  32. -- 允许组队 1同意 0不同意
  33. self._data.permit = 0
  34. -- 自动同意 1同意 0不同意
  35. self._data.auto = 0
  36. -- 允许添加
  37. self._data.permit_add = 0
  38. -- 允许交易
  39. self._data.permit_deal = 0
  40. -- 允许挑战
  41. self._data.permit_challenge = 0
  42. -- 允许显示
  43. self._data.permit_show = 0
  44. -- 队伍id
  45. self._data.group_id = 0
  46. self._is_transfer_team = false -- 是否请求转移队长职位,语音需要请求者去发送消息
  47. self._exit_team_id = {} -- 记录下退出队伍的id,语音请求时,升级为队长的人进行发送
  48. self._remove_team_uid = {} -- 踢出uid
  49. self._memberMax = tonumber(SL:GetMetaValue("GAME_DATA","team_num")) or self._memberMax
  50. end
  51. function TeamProxy:onRegister()
  52. TeamProxy.super.onRegister(self)
  53. end
  54. function TeamProxy:Tips(tipsStr)
  55. tipsStr = tipsStr or tostring(tipsStr)
  56. global.Facade:sendNotification(global.NoticeTable.SystemTips, tipsStr)
  57. end
  58. function TeamProxy:CheckMemberData()
  59. for _, vItem in pairs(self._data.memberItems) do
  60. vItem.UserID = vItem.UserID or ""
  61. vItem.sUserName = vItem.sUserName or ""
  62. vItem.Sex = vItem.Sex or 0
  63. vItem.Job = vItem.Job or 0
  64. vItem.Level = vItem.Level or 0
  65. vItem.Power = vItem.Power or 0
  66. vItem.SGuildName = vItem.SGuildName or ""
  67. vItem.Rand = vItem.Rand or 0
  68. end
  69. end
  70. function TeamProxy:UpdateMemberMaxNum()
  71. self._memberMax = tonumber(SL:GetMetaValue("GAME_DATA", "team_num")) or self._memberMax
  72. end
  73. function TeamProxy:ClearTeam()
  74. self:Init()
  75. self:ClearApplyItems()
  76. -- 刷新队伍
  77. SLBridge:onLUAEvent(LUA_EVENT_TEAM_MEMBER_UPDATE)
  78. end
  79. function TeamProxy:LeaveTeam()
  80. if self:GetMemberCount() <= 0 then
  81. return false
  82. end
  83. -- 清除队伍数据
  84. self:ClearTeam()
  85. end
  86. function TeamProxy:GetNearTeamItems()
  87. return self._data.nearTeamItems
  88. end
  89. function TeamProxy:ClearNearTeam()
  90. self._data.nearTeamItems = {}
  91. SLBridge:onLUAEvent(LUA_EVENT_TEAM_NEAR_UPDATE)
  92. end
  93. function TeamProxy:GetTeamMember()
  94. return self._data.memberItems
  95. end
  96. function TeamProxy:ClearTeamMember()
  97. local memberCount = self:GetMemberCount()
  98. self._data.memberItems = {}
  99. -- 踢出 离开队伍
  100. local VoiceManagerProxy = global.Facade:retrieveProxy(global.ProxyTable.VoiceManagerProxy)
  101. if memberCount > 1 then --退出队伍 没有返回数据 就在这里进行判断下是离开还是解散
  102. VoiceManagerProxy:VoiceTeam({ operateType = TeamProxy.ChangeType.LEAVE,})
  103. -- 语音2.0 退出
  104. if self._is_auto_leave then
  105. VoiceManagerProxy:VoiceTeamLeave_New()
  106. self._is_auto_leave = false
  107. end
  108. elseif memberCount == 1 then
  109. self._data.memberItems = {}
  110. VoiceManagerProxy:VoiceTeam({ operateType = TeamProxy.ChangeType.DISMISS,})
  111. -- 语音2.0 解散
  112. local VoiceManagerProxy = global.Facade:retrieveProxy(global.ProxyTable.VoiceManagerProxy)
  113. VoiceManagerProxy:VoiceTeamDisMiss_New()
  114. end
  115. global.Facade:sendNotification(global.NoticeTable.MainActorChange_OwnSidePlayer, 2)
  116. end
  117. function TeamProxy:DealTeam(userID, value)
  118. local myID = global.gamePlayerController:GetMainPlayerID()
  119. if myID == userID then
  120. return false
  121. end
  122. local actor = global.actorManager:GetActor(userID)
  123. if not actor then
  124. return false
  125. end
  126. local needRefresh = actor:SetCampValue("InTeam", value)
  127. if not self._optionsUtils then
  128. self._optionsUtils = requireProxy("optionsUtils")
  129. end
  130. if needRefresh then
  131. self._optionsUtils:CheckOwnSidePlayerVisible(actor)
  132. end
  133. end
  134. function TeamProxy:IsTeamMember(uid)
  135. if not uid then
  136. uid = global.gamePlayerController:GetMainPlayerID()
  137. end
  138. for _, v in pairs(self._data.memberItems) do
  139. if v.UserID and v.UserID == uid then
  140. return true
  141. end
  142. end
  143. return false
  144. end
  145. function TeamProxy:IsTeamLeader(uid)
  146. if not uid then
  147. uid = global.gamePlayerController:GetMainPlayerID()
  148. end
  149. for _, v in pairs(self._data.memberItems) do
  150. if v.UserID == uid and v.Rand == 1 then
  151. return true
  152. end
  153. end
  154. return false
  155. end
  156. function TeamProxy:GetMemberCount()
  157. if not self._data.memberItems then
  158. return 0
  159. end
  160. return #self._data.memberItems
  161. end
  162. function TeamProxy:GetMemberMax()
  163. return self._memberMax
  164. end
  165. function TeamProxy:GetMyRank()
  166. return self._data.myRank
  167. end
  168. function TeamProxy:GetTeamLeaderId()
  169. return self._data.group_id or 0
  170. end
  171. --允许组队
  172. function TeamProxy:GetPermitStatus()
  173. return self._data.permit
  174. end
  175. function TeamProxy:SetPermitStatus(status)
  176. self._data.permit = status
  177. end
  178. --同行会自动进队
  179. function TeamProxy:GetAutoStatus()
  180. return self._data.auto
  181. end
  182. function TeamProxy:SetAutoStatus(status)
  183. self._data.auto = status
  184. end
  185. --允许添加
  186. function TeamProxy:GetAddStatus()
  187. return self._data.permit_add
  188. end
  189. function TeamProxy:SetAddStatus(status)
  190. self._data.permit_add = status
  191. end
  192. --允许交易
  193. function TeamProxy:GetDealStatus()
  194. return self._data.permit_deal
  195. end
  196. function TeamProxy:SetDealStatus(status)
  197. self._data.permit_deal = status
  198. end
  199. --允许挑战
  200. function TeamProxy:GetChallengeStatus()
  201. return self._data.permit_challenge
  202. end
  203. function TeamProxy:SetChallengeStatus(status)
  204. self._data.permit_challenge = status
  205. end
  206. --允许显示
  207. function TeamProxy:GetShowStatus()
  208. return self._data.permit_show
  209. end
  210. function TeamProxy:SetShowStatus(status)
  211. self._data.permit_show = status
  212. end
  213. function TeamProxy:GetNoCallRemind()
  214. return self._noCallRemind
  215. end
  216. function TeamProxy:SetNoCallRemind(status)
  217. self._noCallRemind = status
  218. end
  219. function TeamProxy:GetApplyItems()
  220. return self._data.applyItems
  221. end
  222. function TeamProxy:removeApplyItemById(id)
  223. if not self._data.applyItems then return end
  224. for index, v in pairs(self._data.applyItems) do
  225. if v.UserID == id then
  226. table.remove(self._data.applyItems, index)
  227. return
  228. end
  229. end
  230. end
  231. function TeamProxy:ClearApplyItems()
  232. self._data.applyItems = {}
  233. -- 气泡
  234. local tipsData = {}
  235. tipsData.id = bubbleId
  236. tipsData.status = false
  237. global.Facade:sendNotification(global.NoticeTable.BubbleTipsStatusChange, tipsData)
  238. end
  239. function TeamProxy:GetInviteItems()
  240. return self._data.inviteItems
  241. end
  242. function TeamProxy:getInviteCount()
  243. local count = 0
  244. for _, v in pairs(self._data.inviteItems) do
  245. count = count + 1
  246. end
  247. return count
  248. end
  249. function TeamProxy:ClearInviteItems()
  250. self._data.inviteItems = {}
  251. -- 气泡
  252. local tipsData = {}
  253. tipsData.status = false
  254. tipsData.id = bubbleId
  255. global.Facade:sendNotification(global.NoticeTable.BubbleTipsStatusChange, tipsData)
  256. end
  257. function TeamProxy:RespNearTeam(msg)
  258. local len = msg:GetDataLength()
  259. if len <= 0 then
  260. return
  261. end
  262. local msgData = msg:GetData()
  263. local sliceStr = msgData:ReadString(len)
  264. local cjson = require("cjson")
  265. local jsonData = cjson.decode(sliceStr)
  266. if not jsonData then
  267. return
  268. end
  269. dump(jsonData)
  270. local nearData = {}
  271. for _, v in pairs(jsonData) do
  272. nearData[v.UserID] = v
  273. end
  274. -- 附近队伍
  275. self._data.nearTeamItems = nearData
  276. SLBridge:onLUAEvent(LUA_EVENT_TEAM_NEAR_UPDATE)
  277. end
  278. function TeamProxy:RespTeamCreateSuccess(msg)
  279. -- 创建队伍成功
  280. self:Tips(GET_STRING(50000109))
  281. self:RequestNearTeam()
  282. local groupId = 0
  283. local msgLen = msg:GetDataLength()
  284. local msgHdr = msg:GetHeader()
  285. if msgLen > 0 then
  286. groupId = msg:GetData():ReadString(msgLen)
  287. end
  288. self._data.group_id = groupId
  289. self._data.myRank = 1
  290. local VoiceManagerProxy = global.Facade:retrieveProxy(global.ProxyTable.VoiceManagerProxy)
  291. VoiceManagerProxy:VoiceTeam({
  292. operateType = TeamProxy.ChangeType.CREATE,
  293. myRank = 1
  294. })
  295. -- 语音2.0 队伍创建
  296. VoiceManagerProxy:VoiceTeamCreate_New()
  297. end
  298. function TeamProxy:RespTeamCreateFailed(msg)
  299. -- 创建队伍失败
  300. self:Tips(GET_STRING(50000110))
  301. end
  302. function TeamProxy:RespTeamMemberUpdate(msg)
  303. local len = msg:GetDataLength()
  304. if len <= 0 then
  305. return
  306. end
  307. local msgData = msg:GetData()
  308. local sliceStr = msgData:ReadString(len)
  309. local jsonData = cjson.decode(sliceStr)
  310. if not jsonData then
  311. return
  312. end
  313. -- dump(jsonData)
  314. local isDel = false
  315. -- 检测是否有成员退出
  316. for _,a in pairs(self._data.memberItems) do
  317. if a then
  318. local isQuit = true
  319. for _,b in pairs(jsonData) do
  320. if a.UserID == b.UserID then
  321. isQuit = false
  322. break
  323. end
  324. end
  325. if isQuit then
  326. self._exit_team_id[a.UserID] = true
  327. global.Facade:sendNotification(global.NoticeTable.SystemTips, string.format(GET_STRING(50000120), a.sUserName))
  328. SLBridge:onLUAEvent(LUA_EVENT_LEAVETEAM, a.sUserName)
  329. self:DealTeam(a.UserID, false)
  330. isDel = true
  331. break
  332. end
  333. end
  334. end
  335. -- 没有成员退出,则查看是否有新增
  336. local isJoinSelf = false
  337. local proxyPlayerProperty = global.Facade:retrieveProxy(global.ProxyTable.PlayerProperty)
  338. local roleUID = proxyPlayerProperty:GetRoleUID()
  339. if isDel == false then
  340. for _,a in pairs(jsonData) do
  341. if a then
  342. local isJoin = true
  343. for _,b in pairs(self._data.memberItems) do
  344. if a.UserID == b.UserID then
  345. isJoin = false
  346. break
  347. end
  348. end
  349. if isJoin then
  350. if not isJoinSelf then
  351. isJoinSelf = a.UserID == roleUID
  352. end
  353. SLBridge:onLUAEvent(LUA_EVENT_JOINTEAM, a.sUserName)
  354. self:DealTeam(a.UserID, true)
  355. end
  356. end
  357. end
  358. end
  359. -- 上次组队
  360. local lastMemberCount = #self._data.memberItems or 0
  361. -- 整理队伍信息,自己如果不是队长,放到第二位
  362. -- 自己在队伍的信息(队长/队员)
  363. local myRank = self:GetMyRank()
  364. self._data.myRank = 0
  365. self._data.memberItems = {}
  366. local isJoin = false
  367. local isUpdate = false
  368. local groupId = self:GetTeamLeaderId()
  369. local teamUserId = nil --队长id
  370. for _, v in pairs(jsonData) do
  371. -- 是否是队长
  372. if self._data.myRank == 0 and v.UserID == roleUID and v.Rand == 1 then
  373. self._data.myRank = 1
  374. isUpdate = myRank ~= self._data.myRank
  375. end
  376. if self._exit_team_id[v.UserID] then
  377. self._exit_team_id[v.UserID] = nil
  378. end
  379. if v.Rand == 1 then
  380. table.insert(self._data.memberItems, 1, v)
  381. self._data.group_id = v.GroupID
  382. teamUserId = v.UserID
  383. elseif v.UserID == roleUID then
  384. isUpdate = true
  385. if next(self._data.memberItems) then
  386. table.insert(self._data.memberItems, 2, v)
  387. isJoin = true
  388. else
  389. table.insert(self._data.memberItems, v)
  390. end
  391. else
  392. table.insert(self._data.memberItems, v)
  393. end
  394. end
  395. self:CheckMemberData()
  396. -- 广播组队
  397. SLBridge:onLUAEvent(LUA_EVENT_TEAM_MEMBER_UPDATE)
  398. if self._data.myRank == 0 then
  399. self:ClearApplyItems()
  400. end
  401. if lastMemberCount ~= #self._data.memberItems then
  402. if isJoin then
  403. local VoiceManagerProxy = global.Facade:retrieveProxy(global.ProxyTable.VoiceManagerProxy)
  404. VoiceManagerProxy:VoiceTeam({
  405. operateType = TeamProxy.ChangeType.JOIN_IN
  406. })
  407. if isJoinSelf and lastMemberCount == 0 then
  408. -- 语音2.0 队伍加入
  409. VoiceManagerProxy:VoiceTeamJoinIn_New()
  410. end
  411. global.Facade:sendNotification(global.NoticeTable.MainActorChange_OwnSidePlayer, 2)
  412. end
  413. end
  414. if isUpdate and myRank and myRank ~= self._data.myRank then
  415. local isVoice = false
  416. if self._data.myRank == 1 then
  417. isVoice = true
  418. end
  419. local newMyRank = self._data.myRank
  420. local newTeamUerId = nil
  421. if next(self._exit_team_id) then
  422. if self._exit_team_id[roleUID] then
  423. isVoice = false
  424. end
  425. else
  426. if not self._is_transfer_team then
  427. isVoice = false
  428. elseif myRank == 1 then
  429. newMyRank = myRank
  430. newTeamUerId = teamUserId
  431. isVoice = true
  432. end
  433. end
  434. if isVoice then
  435. self._exit_team_id = {}
  436. local VoiceManagerProxy = global.Facade:retrieveProxy(global.ProxyTable.VoiceManagerProxy)
  437. VoiceManagerProxy:VoiceTeam({
  438. operateType = TeamProxy.ChangeType.UPDATE,
  439. myRank = newMyRank,
  440. teamUserId = newTeamUerId
  441. })
  442. end
  443. -- 语音2.0 移交队长 新队长处理
  444. if self._data.myRank == 1 then
  445. local VoiceManagerProxy = global.Facade:retrieveProxy(global.ProxyTable.VoiceManagerProxy)
  446. VoiceManagerProxy:VoiceTeamRankChange_New({
  447. roleId = groupId -- 老队长teamid
  448. })
  449. end
  450. end
  451. --语音2.0 队长更换 除队长外都通知
  452. if groupId and groupId ~= 0 and teamUserId and teamUserId ~= 0 and groupId ~= teamUserId and self._data.myRank ~= 1 then
  453. local VoiceManagerProxy = global.Facade:retrieveProxy(global.ProxyTable.VoiceManagerProxy)
  454. VoiceManagerProxy:VoiceTeamUpdate_New( {
  455. roleId = teamUserId,
  456. } )
  457. end
  458. self._is_transfer_team = false
  459. end
  460. function TeamProxy:RespLeaveTeam(msg)
  461. -- 踢出队伍的时候,参数是3. 离开队伍的时候,带的参数是2,这两个是有区别的
  462. local header = msg:GetHeader()
  463. dump(header)
  464. if header.recog == 3 then
  465. -- 被踢出队伍
  466. self:Tips(GET_STRING(50000112))
  467. elseif header.recog == 2 then
  468. -- 离开队伍
  469. self:Tips(GET_STRING(50000111))
  470. end
  471. -- 队伍职位变为队员
  472. self._data.myRank = 0
  473. -- 清空队伍成员
  474. self:ClearTeamMember()
  475. -- 清空申请列表
  476. self:ClearApplyItems()
  477. -- 请求附近队伍
  478. self:ClearNearTeam()
  479. self:RequestNearTeam()
  480. -- 刷新队伍
  481. SLBridge:onLUAEvent(LUA_EVENT_TEAM_MEMBER_UPDATE)
  482. local VoiceManagerProxy = global.Facade:retrieveProxy(global.ProxyTable.VoiceManagerProxy)
  483. VoiceManagerProxy:VoiceTeam({
  484. operateType = TeamProxy.ChangeType.LEAVE
  485. })
  486. -- 语音2.0 离开队伍
  487. if self._is_auto_leave then
  488. local VoiceManagerProxy = global.Facade:retrieveProxy(global.ProxyTable.VoiceManagerProxy)
  489. VoiceManagerProxy:VoiceTeamLeave_New()
  490. self._is_auto_leave = false
  491. end
  492. end
  493. function TeamProxy:RespTeamInvite(msg)
  494. local header = msg:GetHeader()
  495. dump(header)
  496. local len = msg:GetDataLength()
  497. local voiceTeanChangeType = nil --语音需要的改变类型
  498. if header.recog == 0 then
  499. --邀请入队成功
  500. global.Facade:sendNotification(global.NoticeTable.SystemTips, GET_STRING(50000102))
  501. elseif header.recog == 1 then
  502. --组队人数上限
  503. global.Facade:sendNotification(global.NoticeTable.SystemTips, GET_STRING(50000103))
  504. elseif header.recog == 2 then
  505. --已有队伍
  506. global.Facade:sendNotification(global.NoticeTable.SystemTips, GET_STRING(50000104))
  507. elseif header.recog == 4 then
  508. --队伍解散
  509. global.Facade:sendNotification(global.NoticeTable.SystemTips, GET_STRING(50000105))
  510. voiceTeanChangeType = TeamProxy.ChangeType.DISMISS
  511. -- 语音2.0 队伍解散
  512. local VoiceManagerProxy = global.Facade:retrieveProxy(global.ProxyTable.VoiceManagerProxy)
  513. VoiceManagerProxy:VoiceTeamDisMiss_New()
  514. elseif header.recog == 5 then
  515. --申请入队失败
  516. global.Facade:sendNotification(global.NoticeTable.SystemTips, GET_STRING(50000106))
  517. elseif header.recog == 6 then
  518. --已经申请
  519. global.Facade:sendNotification(global.NoticeTable.SystemTips, GET_STRING(50000107))
  520. elseif header.recog == 7 then
  521. --申请成功
  522. global.Facade:sendNotification(global.NoticeTable.SystemTips, GET_STRING(50000108))
  523. elseif header.recog == 8 then
  524. --有人申请入队
  525. local function callback()
  526. global.Facade:sendNotification(global.NoticeTable.Layer_TeamApply_Open)
  527. end
  528. local data = {}
  529. data.id = bubbleId
  530. data.status = true
  531. data.callback = callback
  532. global.Facade:sendNotification(global.NoticeTable.BubbleTipsStatusChange, data)
  533. elseif header.recog == 9 then
  534. --申请人下线或死亡
  535. global.Facade:sendNotification(global.NoticeTable.SystemTips, GET_STRING(50000114))
  536. elseif header.recog == 10 then
  537. --申请人已经入队
  538. global.Facade:sendNotification(global.NoticeTable.SystemTips, GET_STRING(50000115))
  539. elseif header.recog == 11 or header.recog == 12 then
  540. --11,12=带有字串消息
  541. if len > 0 then
  542. local msgData = msg:GetData()
  543. local tipsStr = msgData:ReadString(len)
  544. global.Facade:sendNotification(global.NoticeTable.SystemTips, tipsStr)
  545. end
  546. elseif header.recog == 13 then
  547. --踢出队员成功
  548. global.Facade:sendNotification(global.NoticeTable.SystemTips, GET_STRING(50000116))
  549. -- 语音2.0 踢出成员
  550. local uid = table.remove(self._remove_team_uid, 1)
  551. if uid and self:GetMyRank() == 1 then
  552. local VoiceManagerProxy = global.Facade:retrieveProxy(global.ProxyTable.VoiceManagerProxy)
  553. VoiceManagerProxy:VoiceTeamRemove_New({
  554. teamRoleId = uid
  555. })
  556. end
  557. elseif header.recog == 14 then
  558. --对方没设置允许组队
  559. global.Facade:sendNotification(global.NoticeTable.SystemTips, GET_STRING(50000123))
  560. elseif header.recog == -1 then
  561. -- 对方不在线
  562. global.Facade:sendNotification(global.NoticeTable.SystemTips, GET_STRING(1009))
  563. end
  564. if voiceTeanChangeType then
  565. local VoiceManagerProxy = global.Facade:retrieveProxy(global.ProxyTable.VoiceManagerProxy)
  566. VoiceManagerProxy:VoiceGuildRoleChange({
  567. operateType = voiceTeanChangeType,
  568. isTeam = true, --是否队伍操作
  569. })
  570. end
  571. end
  572. function TeamProxy:showApplyBubbleTips()
  573. local function callback()
  574. global.Facade:sendNotification(global.NoticeTable.Layer_TeamApply_Open)
  575. end
  576. local applyList = self:GetApplyItems()
  577. local status = applyList and table.nums(applyList) > 0
  578. local data = {}
  579. data.id = bubbleId
  580. data.status = status
  581. data.callback = callback
  582. global.Facade:sendNotification(global.NoticeTable.BubbleTipsStatusChange, data)
  583. end
  584. function TeamProxy:RespTeamApplyList(msg)
  585. local len = msg:GetDataLength()
  586. if len <= 0 then
  587. return
  588. end
  589. local msgData = msg:GetData()
  590. local sliceStr = msgData:ReadString(len)
  591. local jsonData = cjson.decode(sliceStr)
  592. dump(jsonData)
  593. if not jsonData or type(jsonData) ~= "table" then
  594. return
  595. end
  596. self._data.applyItems = jsonData
  597. SLBridge:onLUAEvent(LUA_EVENT_TEAM_APPLY_UPDATE)
  598. self:showApplyBubbleTips()
  599. end
  600. --被邀请
  601. function TeamProxy:handle_MSG_SC_TEAM_INVITE(msg)
  602. local len = msg:GetDataLength()
  603. if len <= 0 then
  604. return
  605. end
  606. local msgData = msg:GetData()
  607. local sliceStr = msgData:ReadString(len)
  608. local jsonData = cjson.decode(sliceStr)
  609. dump(jsonData)
  610. if (not jsonData) or type(jsonData) ~= "table" then
  611. return
  612. end
  613. if self:GetPermitStatus() == 0 then
  614. self:RequestApplyRefuse(jsonData.UserID)
  615. return
  616. end
  617. self._data.inviteItems[jsonData.UserID] = jsonData
  618. local function callback()
  619. local count = self:getInviteCount()
  620. if count == 1 then
  621. SL:OpenTeamBeInvite(jsonData)
  622. global.Facade:sendNotification(global.NoticeTable.BubbleTipsStatusChange, { id = bubbleId, status = false })
  623. elseif count > 1 then
  624. local tipsData = {}
  625. tipsData.list = {}
  626. for _, v in pairs(self:GetInviteItems()) do
  627. local data = {}
  628. data.str = string.format(GET_STRING(50000119), v.sUserName)
  629. data.agreeCall = function()
  630. if v.bMaster then
  631. self:RequestInviteAgree(v.UserID)
  632. else
  633. self:RequestApply(v.GroupId)
  634. end
  635. end
  636. data.disAgreeCall = function()
  637. self:RequestInviteRefuse(v.UserID)
  638. if self:getInviteCount() == 0 then
  639. global.Facade:sendNotification(global.NoticeTable.BubbleTipsStatusChange, { id = bubbleId, status = false })
  640. end
  641. end
  642. table.insert(tipsData.list, data)
  643. end
  644. local MainPropertyMediator = global.Facade:retrieveMediator("MainPropertyMediator")
  645. if MainPropertyMediator then
  646. local node = MainPropertyMediator:GetBubbleButtonByID(bubbleId)
  647. if node and not tolua.isnull(node) then
  648. tipsData.pos = node:getWorldPosition()
  649. end
  650. end
  651. global.Facade:sendNotification(global.NoticeTable.Layer_CommonBubbleInfo_Open, tipsData)
  652. end
  653. end
  654. local data = {}
  655. data.id = bubbleId
  656. data.status = true
  657. data.callback = callback
  658. global.Facade:sendNotification(global.NoticeTable.BubbleTipsStatusChange, data)
  659. end
  660. --允许组队
  661. function TeamProxy:RespPermitStatus(msg)
  662. local header = msg:GetHeader()
  663. if header.param3 == 1 then -- 英雄数据不处理
  664. return
  665. end
  666. local jsonData = ParseRawMsgToJson(msg)
  667. -- dump(jsonData)
  668. if jsonData then
  669. self:SetPermitStatus(jsonData.AllowGroup or 0)
  670. self:SetAutoStatus(jsonData.AllowGGroup or 0)
  671. self:SetAddStatus(jsonData.AllowAdd or 0)
  672. self:SetDealStatus(jsonData.AllowDeal or 0)
  673. self:SetChallengeStatus(jsonData.AllowChallenge or 0)
  674. self:SetShowStatus(jsonData.AllowShow or 0)
  675. end
  676. end
  677. function TeamProxy:RequestCreateTeam()
  678. -- 创建队伍
  679. LuaSendMsg(global.MsgType.MSG_CS_TEAM_CREATE_REQUEST)
  680. end
  681. function TeamProxy:RequestLeaveTeam()
  682. -- 退出队伍
  683. -- print("退出队伍")
  684. self._is_auto_leave = true
  685. LuaSendMsg(global.MsgType.MSG_CS_TEAM_LEAVE)
  686. local mediator = global.Facade:retrieveMediator("NoticeMediator")
  687. if mediator:GetEffectsData()[3] then
  688. local teamId = self:GetTeamLeaderId()
  689. for _, v in ipairs(mediator:GetEffectsData()[3]) do
  690. global.Facade:sendNotification(global.NoticeTable.Layer_Notice_RemoveChild, tostring(v))
  691. end
  692. mediator:GetEffectsData()[3] = {}
  693. end
  694. self._exit_team_id = {}
  695. end
  696. function TeamProxy:RequestNearTeam()
  697. -- 请求附近队伍
  698. LuaSendMsg(global.MsgType.MSG_CS_TEAM_NEAR_TEAM_REQUEST)
  699. end
  700. function TeamProxy:RequestInvite(uid, name)
  701. --没有队伍先创建一个
  702. if self:GetMemberCount() == 0 then
  703. self:RequestCreateTeam()
  704. elseif self:GetMemberCount() >= self:GetMemberMax() then
  705. global.Facade:sendNotification(global.NoticeTable.SystemTips, GET_STRING(50000122))
  706. return
  707. end
  708. local params = {}
  709. if uid then
  710. params.userId = uid
  711. elseif name then
  712. params.userName = name
  713. end
  714. local jsonData = cjson.encode(params)
  715. dump(jsonData)
  716. -- 邀请入队
  717. LuaSendMsg(global.MsgType.MSG_CS_TEAM_INVITE_REQUEST, 0, 0, 0, 0, jsonData, string.len(jsonData))
  718. end
  719. function TeamProxy:RequestApply(uid)
  720. -- 申请入队
  721. if self:GetMemberCount() > 0 then
  722. global.Facade:sendNotification(global.NoticeTable.SystemTips, GET_STRING(50000121))
  723. return
  724. end
  725. LuaSendMsg(global.MsgType.MSG_CS_TEAM_APPLY, 0, 0, 0, 0, uid, string.len(uid))
  726. end
  727. function TeamProxy:RequestApplyData()
  728. -- 请求申请列表
  729. LuaSendMsg(global.MsgType.MSG_CS_TEAM_APPLY_LIST_REQUEST)
  730. end
  731. function TeamProxy:RequestApplyAgree(uid)
  732. if self:GetMemberCount() >= self:GetMemberMax() then
  733. global.Facade:sendNotification(global.NoticeTable.SystemTips, GET_STRING(50000122))
  734. return
  735. end
  736. -- 同意申请
  737. self:removeApplyItemById(uid)
  738. LuaSendMsg(global.MsgType.MSG_CS_TEAM_APPLY_CONFIRM, 0, 0, 0, 0, uid, string.len(uid))
  739. self:showApplyBubbleTips()
  740. end
  741. function TeamProxy:RequestApplyRefuse(uid)
  742. -- 拒绝申请
  743. self:removeApplyItemById(uid)
  744. LuaSendMsg(global.MsgType.MSG_CS_TEAM_APPLY_CONFIRM, 1, 0, 0, 0, uid, string.len(uid))
  745. self:showApplyBubbleTips()
  746. end
  747. function TeamProxy:RequestInviteRefuse(uid)
  748. -- 拒绝邀请
  749. self._data.inviteItems[uid] = nil
  750. LuaSendMsg(global.MsgType.MSG_CS_TEAM_APPLY_CONFIRM, 1, 0, 0, 0, uid, string.len(uid))
  751. local function callback()
  752. global.Facade:sendNotification(global.NoticeTable.Layer_TeamApply_Open)
  753. end
  754. local status = self._data.inviteItems and table.nums(self._data.inviteItems) > 0
  755. local data = {}
  756. data.id = bubbleId
  757. data.status = status
  758. data.callback = callback
  759. global.Facade:sendNotification(global.NoticeTable.BubbleTipsStatusChange, data)
  760. end
  761. function TeamProxy:RequestInviteAgree(uid)
  762. -- 同意邀请
  763. LuaSendMsg(global.MsgType.MSG_CS_TEAM_INVITE_AGREE, 0, 0, 0, 0, uid, string.len(uid))
  764. self._data.inviteItems[uid] = nil
  765. for _, v in pairs(self:GetInviteItems()) do
  766. self:RequestApplyRefuse(v.UserID)
  767. end
  768. self:ClearInviteItems()
  769. end
  770. function TeamProxy:RequestSubMember(uid)
  771. -- 请求T人
  772. table.insert(self._remove_team_uid, uid)
  773. LuaSendMsg(global.MsgType.MSG_CS_TEAM_SUB_REQUEST, 0, 0, 0, 0, uid, string.len(uid))
  774. end
  775. function TeamProxy:RequestTransferLeader(uid)
  776. -- 移交队长
  777. self._is_transfer_team = true
  778. LuaSendMsg(global.MsgType.MSG_CS_TEAM_TRANSFER_LEADER, 0, 0, 0, 0, uid, string.len(uid))
  779. end
  780. function TeamProxy:RequestPermit()
  781. -- 允许组队
  782. local status = self:GetPermitStatus()
  783. local auto = self:GetAutoStatus()
  784. local params = {}
  785. params.AllowGroup = self:GetPermitStatus()
  786. params.AllowGGroup = self:GetAutoStatus()
  787. params.AllowAdd = self:GetAddStatus()
  788. params.AllowDeal = self:GetDealStatus()
  789. params.AllowChallenge = self:GetChallengeStatus()
  790. params.AllowShow = self:GetShowStatus()
  791. local jsonData = cjson.encode(params)
  792. LuaSendMsg(global.MsgType.MSG_CS_TEAM_PERMIT_REQUEST, status, auto, 0, 0, jsonData, string.len(jsonData))
  793. end
  794. function TeamProxy:RegisterMsgHandler()
  795. TeamProxy.super.RegisterMsgHandler(self)
  796. local msgType = global.MsgType
  797. -- 附近队伍
  798. LuaRegisterMsgHandler(msgType.MSG_CS_TEAM_NEAR_TEAM_RESPONSE, handler(self, self.RespNearTeam))
  799. -- 更新队伍信息
  800. LuaRegisterMsgHandler(msgType.MSG_SC_TEAM_UPDATE_MEMBER, handler(self, self.RespTeamMemberUpdate))
  801. -- 创建队伍 成功
  802. LuaRegisterMsgHandler(msgType.MSG_CS_TEAM_CREATE_SUCCESS_RESPONSE, handler(self, self.RespTeamCreateSuccess))
  803. -- 创建队伍 失败
  804. LuaRegisterMsgHandler(msgType.MSG_CS_TEAM_CREATE_FAIL_RESPONSE, handler(self, self.RespTeamCreateFailed))
  805. -- 邀请玩家 回执
  806. LuaRegisterMsgHandler(msgType.MSG_SC_TEAM_INVITE_RESPONSE, handler(self, self.RespTeamInvite))
  807. -- 申请列表 回执
  808. LuaRegisterMsgHandler(msgType.MSG_SC_TEAM_APPLY_LIST_REPONSE, handler(self, self.RespTeamApplyList))
  809. -- 被邀请
  810. LuaRegisterMsgHandler(msgType.MSG_SC_TEAM_INVITE, handler(self, self.handle_MSG_SC_TEAM_INVITE))
  811. --允许组队
  812. LuaRegisterMsgHandler(msgType.MSG_SC_TEAM_PERMIT_REPONSE, handler(self, self.RespPermitStatus))
  813. end
  814. return TeamProxy