|
|
- --[[@------------------------------------------------------------------
- @description:珍宝阁
- @author:HWR
- ----------------------------------------------------------------------]]
- require("game.proto.104.Require104")
- require("game.treasureHouse.TreasureHouseModel")
- require("game.treasureHouse.TreasureHouseConst")
- require("game.treasureHouse.TreasureHouseView")
- require("game.treasureHouse.TreasureHouseRewardView")
- require("game.treasureHouse.TreasureHouseRewardItem")
- require("game.treasureHouse.TreasureHouseTaskItem")
- require("game.treasureHouse.TreasureHouseItem")
- require("game.treasureHouse.TreasureHouseRecordItem")
- require("game.treasureHouse.TreasureHouseResultItem")
- require("game.treasureHouse.TreasureHouseResultView")
-
- TreasureHouseController = TreasureHouseController or BaseClass(BaseController)
- function TreasureHouseController:__init()
- TreasureHouseController.Instance = self
- self.model = TreasureHouseModel:getInstance()
- self:InitEvent()
- self:registerAllProtocals()
- end
-
- function TreasureHouseController:getInstance()
- if TreasureHouseController.Instance == nil then
- TreasureHouseController.New()
- end
- return TreasureHouseController.Instance
- end
-
- function TreasureHouseController:InitEvent()
- local function onRequestHandler(...)
- local args = {...}
- if args[1] == 10401 or args[1] == 10404 or args[1] == 10405 then
- self:SendFmtToGame(args[1], "c", args[2])
- elseif args[1] == 10402 then
- self:SendFmtToGame(args[1], "h", args[2])
- else
- self:SendFmtToGame(args[1])
- end
- end
- self.model:Bind(TreasureHouseConst.REQ_TREASURE_HOUSE_SCMD, onRequestHandler)
-
- local onGameStartHandler = function ()
- self.model:Fire(TreasureHouseConst.REQ_TREASURE_HOUSE_SCMD, 10400)
- self.model:Fire(TreasureHouseConst.REQ_TREASURE_HOUSE_SCMD, 10403)
- end
- self:Bind(EventName.GAME_START, onGameStartHandler)
-
- local function on_open_treasure_house_view( ... )
- if not self.treasure_house_view then
- self.treasure_house_view = TreasureHouseView.New()
- end
- self.treasure_house_view:Open()
- end
- self.model:Bind(TreasureHouseConst.OPEN_TREASURE_HOUSE_VIEW, on_open_treasure_house_view)
- local function on_open_treasure_house_reward_view( ... )
- if not self.treasure_house_reward_view then
- self.treasure_house_reward_view = TreasureHouseRewardView.New()
- end
- self.treasure_house_reward_view:Open()
- end
- self.model:Bind(TreasureHouseConst.OPEN_TREASURE_HOUSE_REWARD_VIEW, on_open_treasure_house_reward_view)
- local function on_update_red( ... )
- local function call_back( ... )
- local bool = self.model:IsTreasureHouseNeedRed()
- GlobalEventSystem:Fire(ActivityIconManager.UPDATE_ICON_TIPS,10400,bool)
- end
- TimeManager.GetInstance():StartTime("TreasureHouseController:on_update_red", 0.5, call_back)
- end
- self.model:Bind(TreasureHouseConst.UPDATE_TREASURE_HOUSE_RED, on_update_red)
-
- local function open_result_view(data)
- if self.treasure_house_result_view == nil then
- self.treasure_house_result_view = TreasureHouseResultView.New()
- end
- if self.treasure_house_result_view:HasOpen() then
- self.treasure_house_result_view:UpdateView(data)
- else
- self.treasure_house_result_view:Open(data)
- end
- end
- self.model:Bind(TreasureHouseConst.OPEN_TREASURE_HOUSE_RESULT_VIEW,open_result_view)
- end
-
-
- function TreasureHouseController:registerAllProtocals()
- self:RegisterProtocal(10400,"handle10400")--珍宝阁期数轮次等综合信息查询
- self:RegisterProtocal(10401,"handle10401")--抽取奖励
- self:RegisterProtocal(10402,"handle10402")--领取次数保底奖励
- self:RegisterProtocal(10403,"handle10403")--抽奖券任务进度
- self:RegisterProtocal(10404,"handle10404")--抽奖券任务领取
- self:RegisterProtocal(10405,"handle10405")--抽奖券购买
- self:RegisterProtocal(10406,"handle10406")--抽奖传闻记录查询
- self:RegisterProtocal(10407,"handle10407")--抽奖传闻记录新增推送
- end
-
- -- ########## 珍宝阁期数轮次等综合信息查询 ############
- -- protocol=10400
- -- {
- -- c2s{
- -- }
- -- s2c{
- -- curr_period:int8 // 期数
- -- curr_round:int8 // 当前所处的次数保底轮次阶段
- -- curr_count:int8 // 当前轮次抽取次数
- -- award_round:int8 // 该期数尚未领取完奖励的轮次
- -- count_awards:array{ // 最后领取的轮次奖励(领取后再刷新下一轮)
- -- count:int8 // 累计次数档位
- -- stage:int8 // 状态(0未达成 1未领取 2已领取)
- -- }
- -- }
- -- }
-
- function TreasureHouseController:handle10400()
- local vo = SCMD10400.New(true)
- -- print("HWR:TreasureHouseController [start:79] vo:", vo)
- -- PrintTable(vo)
- -- print("HWR:TreasureHouseController [end]")
- self.model:SetTreasureHouseBaseInfo(vo)
- self.model:Fire(TreasureHouseConst.UPDATE_TREASURE_HOUSE_RED)
- end
-
- -- ########## 抽取奖励 ############
- -- protocol=10401
- -- {
- -- c2s{
- -- count:int8 // 抽取次数(1、10)
- -- }
- -- s2c{
- -- errcode:int32 // 错误码
- -- award_list:array{ // 抽取到的奖励列表
- -- award_id:int32 // 奖励id
- -- }
- -- }
- -- }
-
-
- function TreasureHouseController:handle10401()
- local vo = SCMD10401.New(true)
- if vo.errcode == 1 then
- self.model:Fire(TreasureHouseConst.REQ_TREASURE_HOUSE_SCMD, 10400)
- local data = {}
- data.award = {}
- data.col_num = 5
- data.pool_type = TableSize(vo.award_list)
- local goods_vo
- local cfg = Config.Treasurehouseitems
- for k, v in pairs(vo.award_list) do
- local awards = stringtotable(cfg[v.award_id].awards)
- data.award[#data.award+1] = {awards[1][1], awards[1][2], awards[1][3], is_rare = cfg[v.award_id].is_rare }
- end
- -- GlobalEventSystem:Fire(EventName.OPEN_COM_AWARD_RESULT_VIEW, data)
- self.model:Fire(TreasureHouseConst.OPEN_TREASURE_HOUSE_RESULT_VIEW, data)
- else
- ErrorCodeShow(vo.errcode)
- end
- -- print("HWR:TreasureHouseController [start:106] vo:", vo)
- -- PrintTable(vo)
- -- print("HWR:TreasureHouseController [end]")
- end
-
- -- ########## 领取次数保底奖励 ############
- -- protocol=10402
- -- {
- -- c2s{
- -- count:int8 // 需要领取的对应次数
- -- }
- -- s2c{
- -- errcode:int32 // 错误码
- -- }
- -- }
- function TreasureHouseController:handle10402()
- local vo = SCMD10402.New(true)
- if vo.errcode == 1 then
- self.model:Fire(TreasureHouseConst.REQ_TREASURE_HOUSE_SCMD, 10400)
- Message.show("领取奖励成功", "success")
- else
- ErrorCodeShow(vo.errcode)
- end
- -- print("HWR:TreasureHouseController [start:128] vo:", vo)
- -- PrintTable(vo)
- -- print("HWR:TreasureHouseController [end]")
- end
-
- -- ########## 抽奖券任务进度 ############
- -- protocol=10403
- -- {
- -- c2s{
- -- }
- -- s2c{
- -- task_list:array{ // 任务列表
- -- id:int8 // 任务id
- -- times:int8 // 已完成次数
- -- state:int8 // 当前状态(0未完成 1未领取 2已领取)
- -- }
- -- }
- -- }
-
- function TreasureHouseController:handle10403()
- local vo = SCMD10403.New(true)
- -- print("HWR:TreasureHouseController [start:149] vo:", vo)
- -- PrintTable(vo)
- -- print("HWR:TreasureHouseController [end]")
- self.model:SetTreasureHouseTaskInfo(vo)
- self.model:Fire(TreasureHouseConst.UPDATE_TREASURE_HOUSE_RED)
- end
-
- -- ########## 抽奖券任务领取 ############
- -- protocol=10404
- -- {
- -- c2s{
- -- id:int8 // 任务id
- -- }
- -- s2c{
- -- errcode:int32 // 错误码
- -- }
- -- }
-
- function TreasureHouseController:handle10404()
- local vo = SCMD10404.New(true)
- -- print("HWR:TreasureHouseController [start:170] vo:", vo)
- -- PrintTable(vo)
- -- print("HWR:TreasureHouseController [end]")
- if vo.errcode == 1 then
- self.model:Fire(TreasureHouseConst.REQ_TREASURE_HOUSE_SCMD, 10403)
- Message.show("领取任务奖励成功", "success")
- else
- ErrorCodeShow(vo.errcode)
- end
- end
-
- -- ########## 抽奖券购买 ############
- -- protocol=10405
- -- {
- -- c2s{
- -- id:int8 // 任务id
- -- }
- -- s2c{
- -- errcode:int32 // 错误码
- -- }
- -- }
-
- function TreasureHouseController:handle10405()
- local vo = SCMD10405.New(true)
- -- print("HWR:TreasureHouseController [start:194] vo:", vo)
- -- PrintTable(vo)
- -- print("HWR:TreasureHouseController [end]")
- if vo.errcode == 1 then
- self.model:Fire(TreasureHouseConst.REQ_TREASURE_HOUSE_SCMD, 10403)
- Message.show("领取任务奖励成功", "success")
- else
- ErrorCodeShow(vo.errcode)
- end
- end
-
- function TreasureHouseController:handle10406( )
- local vo = SCMD10406.New(true)
- -- print("HWR:TreasureHouseController [start:224] vo:", vo)
- -- PrintTable(vo)
- -- print("HWR:TreasureHouseController [end]")
- self.model:SetTreasureHouseRecordInfo(vo.list)
- end
-
- function TreasureHouseController:handle10407( )
- local vo = SCMD10407.New(true)
- self.model:AddTreasureHouseRecordInfo(vo.list)
- end
|