GuildPlayerProxy.lua 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486
  1. local RemoteProxy = requireProxy("remote/RemoteProxy")
  2. local GuildPlayerProxy = class("GuildPlayerProxy" , RemoteProxy)
  3. GuildPlayerProxy.NAME = global.ProxyTable.GuildPlayerProxy
  4. local cjson = require("cjson")
  5. GuildPlayerProxy.GuildRank =
  6. {
  7. chairman = 1, -- 会长
  8. viceChairman = 2, -- 副会长
  9. elite = 3, -- 精英
  10. member = 4, -- 会员
  11. rank5 = 5
  12. }
  13. -- 行会变更类型
  14. GuildPlayerProxy.ChangeType = {
  15. DISMISS = 0, -- 解散
  16. JOIN_IN = 1, -- 加入
  17. LEAVE = 2, -- 离开
  18. CREATE = 3, -- 创建
  19. UPDATE = 4, -- 职位变更
  20. }
  21. function GuildPlayerProxy:ctor()
  22. GuildPlayerProxy.super.ctor(self)
  23. self._guildName = "" -- 行会名字
  24. self._guildID = "" -- 行会ID
  25. self._rank = 0 -- 职位
  26. self._donateNum = 0 -- 当天捐献
  27. self._isJoinGuild = false -- 是否加入公会
  28. self._removeUserInfo = nil -- 踢掉的行会成员
  29. self._appoint_rank_data = nil -- 任命数据
  30. self._first = true
  31. end
  32. function GuildPlayerProxy:Init()
  33. end
  34. function GuildPlayerProxy:GetRank()
  35. return self._rank or 0
  36. end
  37. function GuildPlayerProxy:SetRank(rank)
  38. self._rank = rank
  39. end
  40. function GuildPlayerProxy:GetDonateNum()
  41. return self._donateNum or 0
  42. end
  43. function GuildPlayerProxy:SetDonateNum(num)
  44. self._donateNum = num
  45. end
  46. function GuildPlayerProxy:IsJoinGuild()
  47. return self._isJoinGuild or false
  48. end
  49. function GuildPlayerProxy:SetJoinGuild(status)
  50. self._isJoinGuild = status
  51. end
  52. function GuildPlayerProxy:GetGuildName()
  53. return self._guildName or ""
  54. end
  55. function GuildPlayerProxy:SetGuildName(name)
  56. self._guildName = name
  57. end
  58. function GuildPlayerProxy:GetGuildId()
  59. return self._guildID or ""
  60. end
  61. function GuildPlayerProxy:SetGuildId(guildID)
  62. self._guildID = guildID
  63. end
  64. -- 获取行会创建时间
  65. function GuildPlayerProxy:GetGuildCreateTime()
  66. return self._createTime
  67. end
  68. function GuildPlayerProxy:SetGuildCreateTime(createTime)
  69. self._createTime = createTime
  70. end
  71. -- 是否是会长
  72. function GuildPlayerProxy:IsMaster(rank)
  73. rank = rank or self:GetRank()
  74. return rank == GuildPlayerProxy.GuildRank.chairman
  75. end
  76. -- 是否是会长或者副会长
  77. function GuildPlayerProxy:IsChairman(rank)
  78. rank = rank or self:GetRank()
  79. return rank == GuildPlayerProxy.GuildRank.chairman or rank == GuildPlayerProxy.GuildRank.viceChairman
  80. end
  81. -- 初始化语音
  82. function GuildPlayerProxy:VoiceInit()
  83. if not self._first and self._is_bind_player_finish and self._is_join_member_finish then
  84. local VoiceManagerProxy = global.Facade:retrieveProxy(global.ProxyTable.VoiceManagerProxy)
  85. VoiceManagerProxy:VoiceInit()
  86. end
  87. end
  88. function GuildPlayerProxy:SetBindMainPlayerFininsh(isFinish)
  89. self._is_bind_player_finish = isFinish
  90. self:VoiceInit()
  91. end
  92. function GuildPlayerProxy:SetJoinMemberFinish(isFinish)
  93. self._is_join_member_finish = isFinish
  94. self:VoiceInit()
  95. end
  96. function GuildPlayerProxy:GetJoinMemberFinish()
  97. return self._is_join_member_finish
  98. end
  99. -- 踢人收人权限
  100. function GuildPlayerProxy:HaveGuildPower(rank)
  101. rank = rank or self:GetRank()
  102. return rank < 3
  103. end
  104. function GuildPlayerProxy:GetContribute()
  105. return GetItemDataNumber(5)
  106. end
  107. function GuildPlayerProxy:handle_GUILD_PLAYER_INFO(msg)
  108. local head = msg:GetHeader()
  109. local data = msg:GetData()
  110. local oldRank = self:GetRank()
  111. local oldGuildID = self:GetGuildId()
  112. if msg:GetDataLength() > 0 then
  113. local str = data:ReadString(msg:GetDataLength())
  114. local info = cjson.decode(str)
  115. if not info then
  116. return
  117. end
  118. local guildId = info.guildId
  119. if string.len(oldGuildID) > 0 and not guildId then
  120. -- 发送退出行会消息
  121. local GuildProxy = global.Facade:retrieveProxy(global.ProxyTable.GuildProxy)
  122. GuildProxy:ClearMemberList()
  123. global.Facade:sendNotification(global.NoticeTable.Exit_Guild)
  124. ssr.ssrBridge:OnJoinOrExitGuild(2)
  125. end
  126. self:SetRank(info.Rank)
  127. self:SetGuildId(guildId)
  128. self:SetGuildName(info.guildName)
  129. self:SetDonateNum(info.GuildGold)
  130. self:SetGuildCreateTime(info.CreateTime)
  131. if info.GuildRelation and info.GuildRelation ~= "" then
  132. local jsonData = cjson.decode(info.GuildRelation)
  133. local diffData = {}
  134. local GuildProxy= global.Facade:retrieveProxy(global.ProxyTable.GuildProxy)
  135. GuildProxy:SetGuildAllyRelation(jsonData.GuildAllList, diffData)
  136. GuildProxy:SetGuildWarRelation(jsonData.GuildWarList, diffData)
  137. global.Facade:sendNotification(global.NoticeTable.RefreshGuildActorColor, {guilds=diffData})
  138. end
  139. end
  140. local newGuildID = self:GetGuildId()
  141. local oldHaveGuild = string.len(oldGuildID) > 0
  142. local newHaveGuild = string.len(newGuildID) > 0
  143. if newHaveGuild then
  144. self:SetJoinGuild(true)
  145. global.Facade:sendNotification(global.NoticeTable.Join_Guild)
  146. local GuildProxy = global.Facade:retrieveProxy(global.ProxyTable.GuildProxy)
  147. GuildProxy:RequestGuildInfo()
  148. else
  149. self:SetJoinGuild(false)
  150. self._is_join_member_finish = true
  151. end
  152. if not oldHaveGuild and newHaveGuild then
  153. ssr.ssrBridge:OnJoinOrExitGuild(1, self:GetGuildName())
  154. end
  155. SL:onLUAEvent(LUA_EVENT_PLAYER_GUILD_INFO_CHANGE)
  156. if self._first then --语音初始化
  157. if self._is_bind_player_finish and self._is_join_member_finish then
  158. local VoiceManagerProxy = global.Facade:retrieveProxy( global.ProxyTable.VoiceManagerProxy )
  159. VoiceManagerProxy:VoiceInit()
  160. end
  161. else
  162. if oldHaveGuild and newGuildID == oldGuildID then
  163. if oldRank ~= self:GetRank() then --职位改变
  164. local VoiceManagerProxy = global.Facade:retrieveProxy( global.ProxyTable.VoiceManagerProxy )
  165. VoiceManagerProxy:VoiceGuildRoleChange({
  166. operatorType = GuildPlayerProxy.ChangeType.UPDATE,
  167. isGuild = true, -- 是否行会操作
  168. })
  169. -- 任命
  170. if self._appoint_rank_data then
  171. -- 语音2.0 职位变更
  172. VoiceManagerProxy:VoiceGuildRankChange_New({
  173. guildRoleId = self._appoint_rank_data.UserID,
  174. newRank = self._appoint_rank_data.Rank
  175. })
  176. self._appoint_rank_data = nil
  177. end
  178. end
  179. end
  180. self._exit_guildid = oldGuildID --保存下离开时的行会id
  181. if oldHaveGuild and not newHaveGuild and not self._is_diss_guildid then --离开
  182. local VoiceManagerProxy = global.Facade:retrieveProxy( global.ProxyTable.VoiceManagerProxy )
  183. VoiceManagerProxy:VoiceGuildChange({
  184. operatorType = GuildPlayerProxy.ChangeType.LEAVE,
  185. guildId = oldGuildID
  186. })
  187. -- 语音2.0 离开行会
  188. VoiceManagerProxy:VoiceGuildLeave_New({
  189. guildId = oldGuildID,
  190. })
  191. elseif oldGuildID ~= newGuildID then -- 刷新行会信息
  192. if oldHaveGuild then
  193. local VoiceManagerProxy = global.Facade:retrieveProxy( global.ProxyTable.VoiceManagerProxy )
  194. VoiceManagerProxy:VoiceGuildChange({
  195. operatorType = GuildPlayerProxy.ChangeType.LEAVE,
  196. guildId = oldGuildID
  197. })
  198. end
  199. -- 有比赛战模式脚本那直接换行会的情况, 没走198号消息, 统一在这判断是否加入
  200. local guildId = self:GetGuildId()
  201. if guildId and guildId ~= "" and not self:IsMaster() then
  202. local VoiceManagerProxy = global.Facade:retrieveProxy( global.ProxyTable.VoiceManagerProxy )
  203. VoiceManagerProxy:VoiceGuildChange({
  204. operatorType = GuildPlayerProxy.ChangeType.JOIN_IN,
  205. guildId = newGuildID
  206. })
  207. -- 语音2.0 加入行会
  208. VoiceManagerProxy:VoiceGuildJoinIn_New()
  209. end
  210. end
  211. end
  212. self._first = false
  213. end
  214. function GuildPlayerProxy:RequestApplyGuild(guildId)
  215. LuaSendMsg(global.MsgType.MSG_CS_GUILD_APPLY_REQUEST, 0, 0, 0, 0, guildId, string.len(guildId))
  216. end
  217. function GuildPlayerProxy:ResponseApplyGuild(msg)
  218. local header = msg:GetHeader()
  219. local data = msg:GetData()
  220. -- 判断是否成功
  221. if header.recog == 0 then
  222. local guildId = nil
  223. if msg:GetDataLength() > 0 then
  224. guildId = data:ReadString(msg:GetDataLength())
  225. end
  226. -- 显示行会主界面
  227. global.Facade:sendNotification(global.NoticeTable.Layer_GuildFrame_Refresh)
  228. elseif header.recog == -2 then
  229. --已经有行会
  230. global.Facade:sendNotification(global.NoticeTable.SystemTips, GET_STRING(50000066))
  231. elseif header.recog == -3 then
  232. --申请的行会为空
  233. global.Facade:sendNotification(global.NoticeTable.SystemTips, GET_STRING(50000067))
  234. elseif header.recog == -4 then
  235. --已经申请过
  236. global.Facade:sendNotification(global.NoticeTable.SystemTips, GET_STRING(50000068))
  237. elseif header.recog == -5 then
  238. --cd中
  239. global.Facade:sendNotification(global.NoticeTable.SystemTips, GET_STRING(50000069))
  240. elseif header.recog == -6 then
  241. --人数已满
  242. global.Facade:sendNotification(global.NoticeTable.SystemTips, GET_STRING(50000082))
  243. end
  244. end
  245. function GuildPlayerProxy:RequestGuildExit()
  246. self._leave_guild = self:GetGuildId()
  247. LuaSendMsg(global.MsgType.MSG_CS_GUILD_EXIT_REQUEST, 0, 0, 0, 0, "", 0)
  248. end
  249. function GuildPlayerProxy:ResponseGuildExit(msg)
  250. local recog = msg:GetHeader().recog
  251. if recog == 0 then
  252. SL:CloseGuildMainUI()
  253. -- 语音2.0 离开行会
  254. local VoiceManagerProxy = global.Facade:retrieveProxy(global.ProxyTable.VoiceManagerProxy)
  255. VoiceManagerProxy:VoiceGuildLeave_New({
  256. guildId = self._leave_guild,
  257. })
  258. self._leave_guild = nil
  259. elseif recog == -3 then
  260. global.Facade:sendNotification(global.NoticeTable.SystemTips, GET_STRING(50000091))
  261. end
  262. end
  263. function GuildPlayerProxy:RequestAppointRank(uid, rank)
  264. if uid and rank then
  265. local jsonStr = cjson.encode({UserID = uid, Rank = rank})
  266. self._appoint_rank_data = {UserID = uid, Rank = rank}
  267. LuaSendMsg(global.MsgType.MSG_SC_GUILD_APPOINT_RANK_REQUEST, 0, 0, 0, 0, jsonStr, string.len(jsonStr))
  268. end
  269. end
  270. function GuildPlayerProxy:ResponseAppointRank(msg)
  271. local header = msg:GetHeader()
  272. local data = msg:GetData()
  273. -- 0 成功
  274. -- -3 不是成员
  275. -- -4 操作者没有权限
  276. -- -5 不能同级操作
  277. -- -6 不能是自己
  278. if header.recog == 0 then
  279. -- 更新职位显示
  280. if msg:GetDataLength() > 0 then
  281. local str = data:ReadString(msg:GetDataLength())
  282. local jsonData = cjson.decode(str)
  283. local GuildProxy = global.Facade:retrieveProxy(global.ProxyTable.GuildProxy)
  284. local member = GuildProxy:getMemberByUID(jsonData.UserID)
  285. if member then
  286. member.Rank = jsonData.Rank
  287. end
  288. global.Facade:sendNotification(global.NoticeTable.Layer_Guild_Member_Rank_Refresh, jsonData)
  289. global.Facade:sendNotification(global.NoticeTable.SystemTips,GET_STRING(50000021))
  290. -- 语音2.0 职位变更
  291. if self._appoint_rank_data and self._appoint_rank_data.Rank ~= self:GetRank() then
  292. local VoiceManagerProxy = global.Facade:retrieveProxy(global.ProxyTable.VoiceManagerProxy)
  293. VoiceManagerProxy:VoiceGuildRankChange_New({
  294. guildRoleId = jsonData.UserID,
  295. newRank = jsonData.Rank
  296. })
  297. self._appoint_rank_data = nil
  298. end
  299. end
  300. elseif header.recog == -7 then -- 人数已满
  301. global.Facade:sendNotification(global.NoticeTable.SystemTips,GET_STRING(50000020))
  302. end
  303. -- 失败
  304. if header.recog ~= 0 then
  305. self._appoint_rank_data = nil
  306. end
  307. end
  308. function GuildPlayerProxy:ResponsePlayerAppointed(msg)
  309. local header = msg:GetHeader()
  310. local data = msg:GetData()
  311. local length = msg:GetDataLength()
  312. if length > 0 then
  313. local name = data:ReadString(length)
  314. global.Facade:sendNotification(global.NoticeTable.SystemTips, string.format(GET_STRING(50000022), name, GetGuildOfficialName(header.recog)))
  315. end
  316. end
  317. function GuildPlayerProxy:RequestRemoveMember(UserID)
  318. if UserID then
  319. local GuildProxy = global.Facade:retrieveProxy(global.ProxyTable.GuildProxy)
  320. self._removeUserInfo = GuildProxy:getMemberByUID(UserID)
  321. LuaSendMsg(global.MsgType.MSG_CS_GUILD_SUB_MEMBER_REQUEST, 0, 0, 0, 0, UserID, string.len(UserID))
  322. end
  323. end
  324. function GuildPlayerProxy:ResponseRemoveMember(msg)
  325. local recog = msg:GetHeader().recog
  326. if recog == 0 then
  327. global.Facade:sendNotification(global.NoticeTable.Layer_Guild_Member_Remove)
  328. -- 语音2.0 行会踢人
  329. local removeUserInfo = self._removeUserInfo or {}
  330. local VoiceManagerProxy = global.Facade:retrieveProxy(global.ProxyTable.VoiceManagerProxy)
  331. VoiceManagerProxy:VoiceGuildRemove_New({
  332. guildRoleId = removeUserInfo.UserID,
  333. removeRank = removeUserInfo.Rank
  334. })
  335. elseif recog == -1 then
  336. global.Facade:sendNotification(global.NoticeTable.SystemTips, GET_STRING(50000092))
  337. elseif recog == -3 then
  338. global.Facade:sendNotification(global.NoticeTable.SystemTips, GET_STRING(50000086))
  339. elseif recog == -4 then
  340. global.Facade:sendNotification(global.NoticeTable.SystemTips, GET_STRING(50000093))
  341. elseif recog == -5 then
  342. global.Facade:sendNotification(global.NoticeTable.SystemTips, GET_STRING(50000088))
  343. end
  344. end
  345. function GuildPlayerProxy:RequestDissolveGuild()
  346. self._is_dissolve_guild = true
  347. LuaSendMsg(global.MsgType.MSG_CS_GUILD_DISSOLVE_REQUEST, 0, 0, 0, 0, "", 0)
  348. end
  349. function GuildPlayerProxy:ResponseDissolveGuild(msg)
  350. local recog = msg:GetHeader().recog
  351. if recog == 0 then
  352. local guildId = self._exit_guildid or self:GetGuildId()
  353. -- 解散成功,数据重置
  354. self:SetRank(0)
  355. self:SetDonateNum(0)
  356. self:SetJoinGuild(false)
  357. local VoiceManagerProxy = global.Facade:retrieveProxy(global.ProxyTable.VoiceManagerProxy)
  358. VoiceManagerProxy:VoiceGuildChange({
  359. operatorType = GuildPlayerProxy.ChangeType.DISMISS,
  360. guildId = guildId
  361. })
  362. -- 语音2.0 解散
  363. VoiceManagerProxy:VoiceGuildDisMiss_New({
  364. guildId = guildId
  365. })
  366. self._exit_guildid = nil
  367. self._is_diss_guildid = false
  368. self._is_diss_guildid = false
  369. SL:CloseGuildMainUI()
  370. elseif recog == -1 then
  371. global.Facade:sendNotification(global.NoticeTable.SystemTips, GET_STRING(50000094))
  372. end
  373. end
  374. function GuildPlayerProxy:ResponseDissolveGuildBroadcast(msg)
  375. local header = msg:GetHeader()
  376. local data = msg:GetData()
  377. -- 解散成功,数据重置
  378. self:SetRank(0)
  379. self:SetDonateNum(0)
  380. self:SetJoinGuild(false)
  381. SL:CloseGuildMainUI()
  382. end
  383. function GuildPlayerProxy:onRegister()
  384. GuildPlayerProxy.super.onRegister(self)
  385. -- 行会成员 行会信息
  386. LuaRegisterMsgHandler(global.MsgType.MSG_SC_GUILD_SHOW_INTRODUCE_RESPONSE,function(msg) self:handle_GUILD_PLAYER_INFO(msg) end)
  387. LuaRegisterMsgHandler(global.MsgType.MSG_SC_GUILD_APPLY_RESPONSE,function(msg) self:ResponseApplyGuild(msg) end)
  388. -- 退出行会
  389. LuaRegisterMsgHandler(global.MsgType.MSG_SC_GUILD_EXIT_RESPONSE,function(msg) self:ResponseGuildExit(msg) end)
  390. -- 委派职务
  391. LuaRegisterMsgHandler(global.MsgType.MSG_SC_GUILD_APPOINT_RANK_RESPONSE,function(msg) self:ResponseAppointRank(msg) end)
  392. -- 被委派的玩家
  393. LuaRegisterMsgHandler(global.MsgType.MSG_SC_GUILD_PLAYER_APPOINTED,function(msg) self:ResponsePlayerAppointed(msg) end)
  394. -- 移除会员
  395. LuaRegisterMsgHandler(global.MsgType.MSG_SC_GUILD_SUB_MEMBER_RESPONSE,function(msg) self:ResponseRemoveMember(msg) end)
  396. -- 解散行会
  397. LuaRegisterMsgHandler(global.MsgType.MSG_SC_GUILD_DISSOLVE_RESPONSE,function(msg) self:ResponseDissolveGuild(msg) end)
  398. LuaRegisterMsgHandler(global.MsgType.MSG_SC_GUILD_DISSOLVE_RESPONSE_BROADCAST,function(msg) self:ResponseDissolveGuildBroadcast(msg) end)
  399. end
  400. return GuildPlayerProxy