-- <* -- @Author: Saber -- @Description: 招财猫活动controller -- *> require("game.fortuneCat.FortuneCatModel") require("game.fortuneCat.FortuneCatMainView") -- 招财猫活动主界面 require("game.fortuneCat.FortuneCatRecordItem") -- 招财猫活动招财记录节点 require("game.fortuneCat.FortuneCatRollItem") -- 招财猫活动抽奖节点 require("game.fortuneCat.FortuneCatAdTipsView") -- 招财猫活动广告界面 FortuneCatController = FortuneCatController or BaseClass(BaseController, true) local FortuneCatController = FortuneCatController function FortuneCatController:__init() FortuneCatController.Instance = self self.model = FortuneCatModel:getInstance() self:AddEvents() self:RegisterAllProtocal() end function FortuneCatController:RegisterAllProtocal( ) self:RegisterProtocal(33219, "handle33219") -- 查询招财猫活动配置数据 self:RegisterProtocal(33220, "handle33220") -- 查询单个招财猫活动信息 self:RegisterProtocal(33221, "handle33221") -- 招财猫招财 self:RegisterProtocal(33222, "handle33222") -- 招财猫招财记录 end function FortuneCatController:AddEvents() local function onRequestHandler(...) local args = {...} if args[1] == 33220 or args[1] == 33221 or args[1] == 33222 then self:SendFmtToGame(args[1], "hh", args[2], args[3]) else self:SendFmtToGame(args[1]) end end self.model:Bind(FortuneCatModel.REQUEST_CCMD_EVENT, onRequestHandler) local function game_start() self.model:Fire(FortuneCatModel.REQUEST_CCMD_EVENT, 33219) end GlobalEventSystem:Bind(EventName.GAME_START, game_start) local function on_lv_up(lv) local open_lv = GetModuleOpenLevel(331, 64, true) if lv == open_lv then -- 活动按钮 self.model:CheckEventOpen() end end RoleManager.Instance.mainRoleInfo:Bind(EventName.CHANGE_LEVEL, on_lv_up) local function onTaskFinishHandler(taskId) if taskId == CustomActivityModel.CAT_FOTANA_TASK_ID then self.model:CheckAdViewOpen() end end GlobalEventSystem:Bind(TaskEvent.ANS_FINISHED_TASK_LIST, onTaskFinishHandler) local function open_fortune_cat_view(show, sub_type) if show then if not sub_type then return end if not self.fc_cat_view then self.fc_cat_view = FortuneCatMainView.New() end if not self.fc_cat_view:HasOpen() then self.fc_cat_view:Open(sub_type) end else if self.fc_cat_view then self.fc_cat_view:Close() end end end self.model:Bind(FortuneCatModel.OPEN_FORTUNE_CAT_VIEW, open_fortune_cat_view) local function open_fortune_cat_ad_view(show, sub_type) if show then if not sub_type then return end if self.model.fc_login_ad_view_flag then return end if not self.fc_cat_ad_view then self.fc_cat_ad_view = FortuneCatAdTipsView.New() end if not self.fc_cat_ad_view:HasOpen() then self.fc_cat_ad_view:Open(sub_type) end else if self.fc_cat_ad_view then self.fc_cat_ad_view:Close() end end end self.model:Bind(FortuneCatModel.OPEN_FORTUNE_CAT_AD_VIEW, open_fortune_cat_ad_view) -- 监听玩家彩钻是否满足转盘需要 local function check_role_jin() local function check_role_jin_delay() self.model:CheckFCAllSubTypeRed() end TimeManager.GetInstance():StartTime("FortuneCatController_CheckRoleJin", 1, check_role_jin_delay) end RoleManager.Instance.mainRoleInfo:BindOne("jin", check_role_jin) end function FortuneCatController:handle33219( ) local vo = SCMD33219.New(true) self.model:SetFortuneCatConfig(vo) -- 存在活动配置和活动信息协议的时序问题,所以拿到配置的时候也更新一下按钮打开情况 self.model:CheckEventOpen() self.model:Fire(FortuneCatModel.UPDATE_FORTUNE_CAT_CONFIG) end function FortuneCatController:handle33220( ) local vo = SCMD33220.New(true) self.model:SetFortuneCatRollTimes(vo) self.model:CheckFortuneCatRed(vo.sub_type) self.model:Fire(FortuneCatModel.UPDATE_FORTUNE_CAT_ROLL_TIME, vo.sub_type) end function FortuneCatController:handle33221( ) local vo = SCMD33221.New(true) if vo.res == 1 then self.model:SetFortuneCatRollResult(vo) self.model:CheckFortuneCatRed(vo.sub_type) self.model:Fire(FortuneCatModel.UPDATE_FORTUNE_CAT_RESULT, vo) local function delay_method( ) if self.fc_cat_view and self.fc_cat_view:HasOpen() then -- 构造玩家抽奖信息数据 local role_vo = RoleManager.Instance.mainRoleInfo local info_data = { role_id = role_vo.role_id, role_name = role_vo.name, time = TimeUtil:getServerTime(), times = vo.times, sort = vo.sort, mult = vo.mult, } self.model:UpdateFortuneCatRollRecord(vo, info_data) self.model:Fire(FortuneCatModel.UPDATE_FORTUNE_CAT_ROLL_RECORD, vo.sub_type) end end -- 延时3秒弹出数据 setTimeout(delay_method, FortuneCatModel.AnimTime) else ErrorCodeShow(vo.res) end end function FortuneCatController:handle33222( ) local vo = SCMD33222.New(true) self.model:SetFortuneCatRollRecord(vo) self.model:Fire(FortuneCatModel.UPDATE_FORTUNE_CAT_ROLL_RECORD, vo.sub_type) end