源战役客户端
No puede seleccionar más de 25 temas Los temas deben comenzar con una letra o número, pueden incluir guiones ('-') y pueden tener hasta 35 caracteres de largo.

450 líneas
18 KiB

  1. require("game.bag.AllAdditionView")
  2. require("game.bag.EquipItem")
  3. require("game.newMainRole.NewMainRoleView")
  4. require("game.newMainRole.NewMainRoleModel")
  5. require("game.newMainRole.roleAttribute.RoleAttributeModel")
  6. require("game.newMainRole.roleAttribute.RoleAttributeView")
  7. -- require("game.newMainRole.roleAttribute.RoleAttrInstructionView")
  8. -- require("game.newMainRole.roleAttribute.RoleAttrItem")
  9. -- require("game.newMainRole.roleAttribute.RoleAttrDesItem")
  10. require("game.newMainRole.roleAttribute.RolePropertyItem")
  11. require("game.newMainRole.roleAttribute.RolePropTips")
  12. require("game.newMainRole.WorldLevelView")
  13. require("game.newMainRole.SelectSysRoleHeadView")
  14. require("game.newMainRole.RoleHeadShowItem")
  15. -- require("game.newMainRole.RoleHeadTips")
  16. require("game.newMainRole.roleAttribute.RolePropertyTop")
  17. require("game.newMainRole.AttrDetailView") -- 属性详细介绍界面
  18. require("game.newMainRole.NewMainRoleHatredView") -- 善恶值界面
  19. NewMainRoleController = NewMainRoleController or BaseClass(BaseController)
  20. function NewMainRoleController:__init()
  21. NewMainRoleController.Instance = self
  22. self.model = NewMainRoleModel:getInstance()
  23. self.mainVo = RoleManager.Instance.mainRoleInfo
  24. self.test_pattern = false
  25. self:RegisterAllProtocals()
  26. self:AddAllEvents()
  27. end
  28. function NewMainRoleController:RegisterAllProtocals()
  29. self:RegisterProtocal(13013, "handler13013") --请求玩家figure
  30. self:RegisterProtocal(13014, "handler13014")
  31. self:RegisterProtocal(13085, "handler13085") --头像广播
  32. self:RegisterProtocal(13045, "Handler13045") --转职
  33. self:RegisterProtocal(13046, "Handler13046") --转职时间
  34. -- self:RegisterProtocal(13082, "handler13082")--检测是否可上传头像
  35. -- self:RegisterProtocal(13083, "handler13083")--上传头像
  36. -- self:RegisterProtocal(13086, "handler13086")--上传头像
  37. self:RegisterProtocal(13087, "handler13087") -- 登录相关时间查询协议
  38. self:RegisterProtocal(13088, "handler13088") -- 查询角色头像信息
  39. self:RegisterProtocal(13089, "handler13089") -- 激活头像
  40. self:RegisterProtocal(13090, "handler13090") -- 更换头像
  41. end
  42. function NewMainRoleController:AddAllEvents()
  43. local function onGameStart()
  44. -- 请求登录时间信息
  45. self:SendFmtToGame(13087)
  46. -- 请求头像信息
  47. self:SendFmtToGame(13088)
  48. -- self.model:CheckErrorRoleHead()
  49. end
  50. GlobalEventSystem:Bind(EventName.GAME_START, onGameStart)
  51. -- 头像是否可上传
  52. -- local onCheckRoleHeadForbidState = function()
  53. -- self:SendFmtToGame(13082)
  54. -- end
  55. -- GlobalEventSystem:Bind(EventName.CHECK_ROLE_HEAD_FORBID, onCheckRoleHeadForbidState)
  56. -- 头像上传
  57. -- local onRoleHeadUploadSucceed = function()
  58. -- self:SendFmtToGame(13083)
  59. -- end
  60. -- GlobalEventSystem:Bind(EventName.ROLEHEAD_UPLOAD_SUCCEED, onRoleHeadUploadSucceed)
  61. -- 本地头像上传
  62. -- local onChangeLocalHead = function(id)
  63. -- self:SendFmtToGame(13086, "h", id)
  64. -- end
  65. -- GlobalEventSystem:Bind(EventName.ROLEHEAD_LOCAL_UPLOAD, onChangeLocalHead)
  66. local function OPEN_PROP_TIP(id, val, x, y)
  67. do return end
  68. if not self.RolePropTips then
  69. self.RolePropTips = RolePropTips.New()
  70. end
  71. self.RolePropTips:Open(id, val, x, y)
  72. end
  73. RoleAttributeModel:getInstance():Bind(RoleAttributeModel.OPEN_PROP_VIEW, OPEN_PROP_TIP)
  74. --绑定打开称号界面的方法
  75. local function onOpenMainRoleView(index,sub_index,value)
  76. if self.mainRoleView == nil then
  77. self.mainRoleView = NewMainRoleView.New()
  78. end
  79. if not self.mainRoleView:HasOpen() then
  80. self.mainRoleView:Open(index,sub_index,value)
  81. else
  82. self.mainRoleView:ReOpen(index,sub_index,value)
  83. end
  84. end
  85. GlobalEventSystem:Bind(EventName.OPEN_NEW_MAIN_ROLE_VIEW, onOpenMainRoleView)
  86. local function close_mianrole_view()
  87. if self.mainRoleView and self.mainRoleView:HasOpen() then
  88. self.mainRoleView:Close()
  89. end
  90. end
  91. GlobalEventSystem:Bind(EventName.CLOSE_NEW_MAIN_ROLE_VIEW, close_mianrole_view)
  92. local function onOpenAllAdditionView(type)
  93. if self.AllAdditionView == nil then
  94. self.AllAdditionView = AllAdditionView.New()
  95. end
  96. self.AllAdditionView:Open(type)
  97. end
  98. self.model:Bind(NewMainRoleModel.OPEN_ALL_ADDITION_VIEW, onOpenAllAdditionView)
  99. local function open_attr_detail_view(type)
  100. if not self.attr_detail_view then
  101. self.attr_detail_view = AttrDetailView.New()
  102. end
  103. self.attr_detail_view:Open(type)
  104. end
  105. RoleAttributeModel:getInstance():Bind(RoleAttributeModel.OPEN_ATTR_DETAIL_VIEW, open_attr_detail_view)
  106. local function open_hatred_view(force_close)
  107. if force_close then
  108. if self.hatred_view == nil then return end
  109. if self.hatred_view:HasOpen() then self.hatred_view:Close() end
  110. return
  111. end
  112. if not self.hatred_view then
  113. self.hatred_view = NewMainRoleHatredView.New()
  114. end
  115. self.hatred_view:Open()
  116. end
  117. self.model:Bind(NewMainRoleModel.OPEN_HATRED_VIEW, open_hatred_view)
  118. local function sent_turn_career_protocal(...)
  119. local args = {...}
  120. if args[1] == 13045 then
  121. self:SendFmtToGame(args[1], "cc", args[2], args[3])
  122. elseif args[1] == 13046 then
  123. self:SendFmtToGame(args[1])
  124. end
  125. end
  126. self.model:Bind(NewMainRoleModel.SEND_TURN_CAREER_PROTOCAL, sent_turn_career_protocal)
  127. local function onRequestOtherInfo(unique_server_id, role_id, module_id)
  128. if unique_server_id and role_id and module_id then
  129. self:SendFmtToGame(13013, "hlh", unique_server_id, role_id, module_id)
  130. end
  131. end
  132. self.model:Bind(NewMainRoleModel.REQUEST_OTHER_PLAYER_INFO, onRequestOtherInfo)
  133. local function onRequestWorldLevel()
  134. self:SendFmtToGame(13011)
  135. end
  136. self.model:Bind(NewMainRoleModel.RequestWorldLevel, onRequestWorldLevel)
  137. local function onOpenWorldLevelView()
  138. if self.worldLevelView == nil then
  139. self.worldLevelView = WorldLevelView.New()
  140. end
  141. if not self.worldLevelView:HasOpen() then
  142. self.worldLevelView:Open()
  143. end
  144. end
  145. GlobalEventSystem:Bind(EventName.OPEN_WORLD_LEVEL_VIEW, onOpenWorldLevelView)
  146. local function onCloseWorldLevelView()
  147. if self.worldLevelView then
  148. self.worldLevelView:Close()
  149. self.worldLevelView = nil
  150. end
  151. end
  152. GlobalEventSystem:Bind(EventName.CLOSE_WORLD_LEVEL_VIEW, onCloseWorldLevelView)
  153. local function onGameStart()
  154. -- if self.test_pattern then
  155. -- if not self.game_start_set then
  156. -- local data = CookieWrapper.Instance:GetCookie(CookieLevelType.Account, CookieKey.TEST_DETECT_PLAYER_ATTR)
  157. -- if not data then
  158. -- data = {}
  159. -- end
  160. -- local vo = {
  161. -- start_time = os.date("%c", os.time()),
  162. -- role_id = self.mainVo.role_id,
  163. -- role_name = self.mainVo.name,
  164. -- read_time = os.date("%c", os.time()),
  165. -- role_lv = self.mainVo.level,
  166. -- attr_list = self:SetRoleAttrList(),
  167. -- }
  168. -- table.insert(data, vo)
  169. -- CookieWrapper.Instance:SaveCookie(CookieLevelType.Account, CookieTimeType.TYPE_ALWAYS, CookieKey.TEST_DETECT_PLAYER_ATTR, data)
  170. -- self.game_start_set = true
  171. -- end
  172. -- end
  173. end
  174. GlobalEventSystem:Bind(SceneManager.START, onGameStart)
  175. local function update_red_dot_by_tab_id_func( tab_id )--主要的更新红点方法
  176. if not tab_id then
  177. self.model:IsNeedRedAll()
  178. else
  179. self.model:IsNeedRed(tab_id)
  180. end
  181. local red_dot = self.model:GetAllRedDot()
  182. local bool = false
  183. for i,v in pairs(red_dot) do
  184. if v then
  185. bool = true
  186. break
  187. end
  188. end
  189. GlobalEventSystem:Fire(EventName.SHOW_FUNCTION_RED_POINT, 130, bool)
  190. end
  191. self.model:Bind(NewMainRoleModel.UPDATE_RED_DOT,update_red_dot_by_tab_id_func)
  192. -- 查询玩家已激活的头像信息
  193. local function onRequestRoleHeadInfo()
  194. self:SendFmtToGame(13088)
  195. end
  196. GlobalEventSystem:Bind(EventName.REQ_ROLE_HEAD_INFO, onRequestRoleHeadInfo)
  197. -- 请求激活目标头像
  198. local function onActivateRoleHead(photo_id)
  199. if not photo_id then return end
  200. self:SendFmtToGame(13089, "i", photo_id)
  201. end
  202. GlobalEventSystem:Bind(EventName.REQ_ACTIVATE_ROLEHEAD, onActivateRoleHead)
  203. -- 请求切换玩家头像
  204. local function onChangeRoleHead(photo_id)
  205. if not photo_id then return end
  206. self:SendFmtToGame(13090, "i", photo_id)
  207. end
  208. GlobalEventSystem:Bind(EventName.REQ_CHANGE_ROLEHEAD, onChangeRoleHead)
  209. -- local function onChangeAttr()
  210. -- if self.test_pattern then
  211. -- if self.game_start_set then
  212. -- local data = CookieWrapper.Instance:GetCookie(CookieLevelType.Account, CookieKey.TEST_DETECT_PLAYER_ATTR)
  213. -- if not data then
  214. -- data = {}
  215. -- end
  216. -- local vo = {
  217. -- start_time = 0,
  218. -- role_id = self.mainVo.role_id,
  219. -- role_name = self.mainVo.name,
  220. -- read_time = os.date("%c", os.time()),
  221. -- role_lv = self.mainVo.level,
  222. -- attr_list = self:SetRoleAttrList(),
  223. -- }
  224. -- table.insert(data, vo)
  225. -- CookieWrapper.Instance:SaveCookie(CookieLevelType.Account, CookieTimeType.TYPE_ALWAYS, CookieKey.TEST_DETECT_PLAYER_ATTR, data)
  226. -- end
  227. -- end
  228. -- end
  229. -- for k, v in pairs(Config.ConfigItemAttr.TestAttr) do -- 以下是数值策划测试所用
  230. -- self.mainVo:BindOne(v.attr_str, onChangeAttr)
  231. -- end
  232. end
  233. -- function NewMainRoleController:SetRoleAttrList()
  234. -- local list = {}
  235. -- for k, v in pairs(Config.ConfigItemAttr.TestAttr) do
  236. -- if v then
  237. -- local vo = {name = Config.ConfigItemAttr.Normal[v.id].name, attr_val = self.mainVo[v.attr_str]}
  238. -- table.insert(list, vo)
  239. -- end
  240. -- end
  241. -- return list
  242. -- end
  243. function NewMainRoleController:handler13013()
  244. local vo = {}
  245. vo.server_id = UserMsgAdapter.ReadFmt("h")
  246. vo.role_id = UserMsgAdapter.ReadFmt("l")
  247. vo.module_id = UserMsgAdapter.ReadFmt("h")
  248. vo.fighting = UserMsgAdapter.ReadFmt("i")
  249. FigureProtoVo.ReadFmt(vo)
  250. vo.server_name = UserMsgAdapter.ReadFmt("s")
  251. self.model:SetRoleFigure(vo)
  252. self.model:Fire(NewMainRoleModel.REQUEST_OTHER_PLAYER_INFO, vo, vo.module_id)
  253. end
  254. function NewMainRoleController:handler13014()
  255. self.model.other_guild_chief_vo = {}
  256. self.model.other_guild_chief_vo.server_id = UserMsgAdapter.ReadFmt("h")
  257. self.model.other_guild_chief_vo.guild_id = UserMsgAdapter.ReadFmt("l")
  258. self.model.other_guild_chief_vo.module_id = UserMsgAdapter.ReadFmt("h")
  259. self.model.other_guild_chief_vo.role_id = UserMsgAdapter.ReadFmt("l")
  260. -- self.model.other_guild_chief_vo.fighting = UserMsgAdapter.ReadFmt("i")
  261. FigureProtoVo.ReadFmt(self.model.other_guild_chief_vo)
  262. -- self.model.other_guild_chief_vo.server_name = UserMsgAdapter.ReadFmt("s")
  263. self.model:Fire(NewMainRoleModel.REQUEST_OTHER_PLAYER_INFO, self.model.other_guild_chief_vo, self.model.other_guild_chief_vo.module_id)
  264. end
  265. function NewMainRoleController:handler13085()
  266. local role_id, img_str, img_ver = self:ReadFmt("lsi")
  267. local role_vo = SceneManager.Instance:GetRoleVo(role_id)
  268. if role_vo then
  269. role_vo:ChangeVar("picture_ver", img_ver)
  270. role_vo:ChangeVar("picture", img_str)
  271. end
  272. GlobalEventSystem:Fire(EventName.MAINROLEHEAD_DATA_CHANGE, self.mainVo.role_id)
  273. end
  274. function NewMainRoleController:Handler13045()
  275. local error, str, career, sex = self:ReadFmt("iscc")
  276. if error == 1 then
  277. self.model:Fire(NewMainRoleModel.SEND_TURN_CAREER_PROTOCAL, 13046)
  278. ReincarnationController.Instance:OpenSuccessView(sex, nil, career)
  279. --self.model:Fire(MainRoleModel.TURN_CAREER_SUCCESS, career, sex)
  280. else
  281. ErrorCodeShow(error, str)
  282. end
  283. end
  284. function NewMainRoleController:Handler13046()
  285. local time = self:ReadFmt("i")
  286. self.model:Fire(MainRoleModel.GET_TURN_CAREER_TIME, time)
  287. end
  288. function NewMainRoleController:handler13082()
  289. local result = self:ReadFmt("c")
  290. if result == 1 then
  291. self:pickPhoto()
  292. elseif result == 2 then
  293. Message.show("你已被管理员禁止设置头像")
  294. else
  295. Message.show("未知原因,请与管理员联系")
  296. end
  297. end
  298. function NewMainRoleController:handler13083()
  299. local result, img_ver, img_str = self:ReadFmt("cis")
  300. if result == 1 then
  301. Message.show("保存头像成功!")
  302. RoleManager.Instance.mainRoleInfo:ChangeVar("picture_ver", img_ver)
  303. RoleManager.Instance.mainRoleInfo:ChangeVar("picture", img_str)
  304. RoleManager.Instance.mainRoleInfo:ChangeVar("profile_photo_id", "")
  305. GlobalEventSystem:Fire(EventName.MAINROLEHEAD_DATA_CHANGE, RoleManager.Instance.mainRoleInfo.role_id)
  306. elseif result == 2 then
  307. Message.show("你已被管理员禁止设置头像")
  308. else
  309. Message.show("保存头像失败!")
  310. end
  311. end
  312. function NewMainRoleController:handler13086()
  313. local result, icon_id = self:ReadFmt("ch")
  314. if result == 1 then
  315. Message.show("更头像成功!")
  316. RoleManager.Instance.mainRoleInfo.picture = ""--:ChangeVar("picture", "")
  317. RoleManager.Instance.mainRoleInfo.profile_photo_id = icon_id--:ChangeVar("local_picture_id", icon_id)
  318. GlobalEventSystem:Fire(EventName.MAINROLEHEAD_DATA_CHANGE)
  319. -- GlobalEventSystem:Fire(EventName.MAINROLEHEAD_LOCAL_DATA_CHANGE, RoleManager.Instance.mainRoleInfo.role_id)
  320. elseif result == 2 then
  321. Message.show("你已被管理员禁止设置头像")
  322. else
  323. ErrorCodeShow(result)
  324. end
  325. end
  326. function NewMainRoleController:handler13087( )
  327. -- 请求时服务器时间/上一次登录时间/本次登录时间/上次退出游戏时间
  328. local req_time, last_login_time, cur_login_time, last_quit_time = self:ReadFmt("iiii")
  329. self.model:SetRoleLoginTimeData(req_time, last_login_time, cur_login_time, last_quit_time)
  330. GlobalEventSystem:Fire(EventName.UPDATE_ROLE_LOGIN_TIME_DATA)
  331. end
  332. function NewMainRoleController:handler13088( )
  333. --开始构造数据,不要问为什么要这么做,为了要和112装扮模块的协议数据一致
  334. local vo = {}
  335. local len0 = self:ReadFmt("h") or 0
  336. vo.dress_type = ChatDressSubType.ROLE_HEAD
  337. vo.use_dress_id = RoleManager.Instance.mainRoleInfo.profile_photo_id
  338. vo.enable_list = {}
  339. for i = 1, len0 do
  340. vo.enable_list[i] = {
  341. dress_id = self:ReadFmt("i") or 0
  342. }
  343. end
  344. ChatDressModel:getInstance():UpdateDressData(vo)
  345. -- self.model:RefreshRoleHeadRed()
  346. WardrobeModel:GetInstance():Fire(WardrobeConst.UPDATE_RED_DOT, WardrobeConst.TabId.DRESS)
  347. self.model:Fire(NewMainRoleModel.REFRESH_ROLE_HEAD_ACTIVATE)
  348. end
  349. function NewMainRoleController:handler13089( )
  350. local result, photo_id = self:ReadFmt("ii")
  351. if result == 1 then
  352. Message.show("激活成功")
  353. -- 更新缓存
  354. local data = {
  355. dressup_list = {
  356. [1] = {
  357. dress_type = ChatDressSubType.ROLE_HEAD,
  358. dress_id = photo_id,
  359. }
  360. }
  361. }
  362. ChatDressModel:getInstance():UpdataUsingDress(data)
  363. local data = {
  364. dress_id = photo_id,
  365. dress_type = ChatDressSubType.ROLE_HEAD
  366. }
  367. ChatDressModel:getInstance():UpdataEnableList(data)
  368. -- 先自动替换头像
  369. RoleManager.Instance.mainRoleInfo:ChangeVar("profile_photo_id", photo_id)
  370. GlobalEventSystem:Fire(EventName.MAINROLEHEAD_DATA_CHANGE)
  371. WardrobeModel:GetInstance():Fire(WardrobeConst.UPDATE_RED_DOT, WardrobeConst.TabId.DRESS)
  372. else
  373. ErrorCodeShow(result)
  374. end
  375. end
  376. function NewMainRoleController:handler13090( )
  377. local result, photo_id = self:ReadFmt("ii")
  378. if result == 1 then
  379. if RoleManager.Instance.mainRoleInfo.profile_photo_id ~= 0 then -- 过滤掉非法头像切换的飘字
  380. Message.show("替换头像成功")
  381. local data = {
  382. dressup_list = {
  383. [1] = {
  384. dress_type = ChatDressSubType.ROLE_HEAD,
  385. dress_id = photo_id,
  386. }
  387. }
  388. }
  389. ChatDressModel:getInstance():UpdataUsingDress(data)
  390. end
  391. RoleManager.Instance.mainRoleInfo:ChangeVar("profile_photo_id", photo_id)
  392. GlobalEventSystem:Fire(EventName.MAINROLEHEAD_DATA_CHANGE)
  393. else
  394. ErrorCodeShow(result)
  395. end
  396. end
  397. function NewMainRoleController:pickPhoto()
  398. local operate_str = "pickPhoto"
  399. local role_info = RoleManager.Instance.mainRoleInfo
  400. local new_version = role_info.picture_ver + 1
  401. local file_path, file_name = UtilGetRolePicPath(role_info.role_id, nil, new_version)
  402. SDKUtil.CallSDKFunc("PhonePhoto", operate_str, {imagePath = file_path, imageName = file_name, imageWidth = 200, imageHeight = 200})
  403. local no_support_text = PlatformMgr:getInstance():NoSupportPhotoMsg()
  404. if no_support_text then
  405. local show_func = function()
  406. Message.show(no_support_text)
  407. end
  408. setTimeout(show_func, 1)
  409. end
  410. end