require("game.proto.334.Require334")
|
|
require("game.sakuraGift.SakuraGiftModel")
|
|
require("game.sakuraGift.SakuraGiftConst")
|
|
require("game.sakuraGift.view.SakuraGiftView")
|
|
require("game.sakuraGift.view.SakuraGiftShopView")
|
|
require("game.sakuraGift.view.SakuraGiftShopItem")
|
|
require("game.sakuraGift.view.SakuraGiftAwardItem")
|
|
require("game.sakuraGift.view.SakuraGiftExchangeView")
|
|
require("game.sakuraGift.view.SakuraGiftMessageView")
|
|
require("game.sakuraGift.view.SakuraGiftChuanwenItem")
|
|
require("game.sakuraGift.view.SakuraGiftRewardView")
|
|
require("game.sakuraGift.view.SakuraGiftRewardItem")
|
|
require("game.sakuraGift.view.SakuraGiftChuanwenLabel")
|
|
|
|
SakuraGiftController = SakuraGiftController or BaseClass(BaseController, true)
|
|
local SakuraGiftController = SakuraGiftController
|
|
|
|
function SakuraGiftController:__init()
|
|
SakuraGiftController.Instance = self
|
|
self.model = SakuraGiftModel:getInstance()
|
|
self:AddEvents()
|
|
self:RegisterAllProtocal()
|
|
|
|
end
|
|
|
|
function SakuraGiftController:__delete()
|
|
end
|
|
|
|
function SakuraGiftController:RegisterAllProtocal( )
|
|
local register_cfg = {
|
|
[33400] = {
|
|
handler = function(self,scmd)
|
|
self:Handle33400( scmd )
|
|
end,
|
|
},
|
|
[33401] = {
|
|
handler = function(self,scmd)
|
|
self:Handle33401( scmd )
|
|
end,
|
|
},
|
|
[33402] = {
|
|
handler = function(self,scmd)
|
|
self:Handle33402( scmd )
|
|
end,
|
|
},
|
|
[33403] = {
|
|
handler = function(self,scmd)
|
|
self:Handle33403( scmd )
|
|
end,
|
|
},
|
|
[33404] = {
|
|
handler = function(self,scmd)
|
|
self:Handle33404( scmd )
|
|
end,
|
|
},
|
|
}
|
|
self:RegisterProtocalByCFG(register_cfg)
|
|
end
|
|
|
|
function SakuraGiftController:AddEvents()
|
|
local function on_game_start()
|
|
self.model:Reset()
|
|
end
|
|
GlobalEventSystem:Bind(EventName.GAME_START, on_game_start)
|
|
|
|
local function onRequestProtocal(...)
|
|
local args = {...}
|
|
if args[1] == 33400 or args[1] == 33403 then
|
|
self:SendFmtToGame(args[1], "h", args[2])
|
|
elseif args[1] == 33402 then
|
|
self:SendFmtToGame(args[1], "hc", args[2], args[3])
|
|
elseif args[1] == 33401 then
|
|
self:SendFmtToGame(args[1], "hcc", args[2], args[3], args[4])
|
|
elseif args[1] == 33404 then
|
|
self:SendFmtToGame(args[1], "hih", args[2], args[3], args[4])
|
|
end
|
|
end
|
|
self.model:Bind(SakuraGiftModel.REQUEST_CCMD_EVENT, onRequestProtocal)
|
|
|
|
local function OPEN_BASE_VIEW( sub_type, is_close )
|
|
if is_close then
|
|
if self.sakuragiftview then
|
|
self.sakuragiftview:Close()
|
|
end
|
|
return
|
|
end
|
|
if self.sakuragiftview == nil then
|
|
self.sakuragiftview = SakuraGiftView.New()
|
|
end
|
|
local base_type = CustomActivityModel.CustomActBaseType.SAKURA_GIFT
|
|
local sub_type = sub_type or CustomActivityModel:getInstance():getActMinSubType(base_type)
|
|
self.cur_sub_type = sub_type
|
|
if not self.sakuragiftview:HasOpen() then
|
|
self.sakuragiftview:Open(sub_type)
|
|
end
|
|
end
|
|
self.model:Bind(SakuraGiftModel.OPEN_BASE_VIEW, OPEN_BASE_VIEW)
|
|
|
|
local function OPEN_SHOP_VIEW( sub_type, is_close )
|
|
if is_close then
|
|
if self.sakuragiftshopview then
|
|
self.sakuragiftshopview:Close()
|
|
end
|
|
return
|
|
end
|
|
if self.sakuragiftshopview == nil then
|
|
self.sakuragiftshopview = SakuraGiftShopView.New()
|
|
end
|
|
if not self.sakuragiftshopview:HasOpen() then
|
|
self.sakuragiftshopview:Open(sub_type)
|
|
end
|
|
end
|
|
self.model:Bind(SakuraGiftModel.OPEN_SHOP_VIEW, OPEN_SHOP_VIEW)
|
|
|
|
local onSakuraGiftExchangeView = function (data, is_close)--兑换请求界面
|
|
if self.SakuraGiftExchangeView == nil then
|
|
self.SakuraGiftExchangeView = SakuraGiftExchangeView.New()
|
|
end
|
|
if self.SakuraGiftExchangeView:HasOpen() and not is_close then
|
|
elseif not is_close then
|
|
self.SakuraGiftExchangeView:Open(data)
|
|
else
|
|
self.SakuraGiftExchangeView:Close()
|
|
end
|
|
end
|
|
self.model:Bind(SakuraGiftModel.OPEN_EXCHANGE_REQ_VIEW, onSakuraGiftExchangeView)
|
|
|
|
|
|
local onSakuraGiftRewardView = function (data, is_close)
|
|
if self.SakuraGiftRewardView == nil then
|
|
self.SakuraGiftRewardView = SakuraGiftRewardView.New()
|
|
end
|
|
if self.SakuraGiftRewardView:HasOpen() and not is_close then
|
|
elseif not is_close then
|
|
self.SakuraGiftRewardView:Open(data)
|
|
else
|
|
self.SakuraGiftRewardView:Close()
|
|
end
|
|
end
|
|
self.model:Bind(SakuraGiftModel.OPEN_REWARD_VIEW, onSakuraGiftRewardView)
|
|
|
|
-- 上方滚屏
|
|
-- local onSakuraGiftMessageView = function (show)
|
|
-- if show then
|
|
-- if self.SakuraGiftMessageView == nil then
|
|
-- self.SakuraGiftMessageView = SakuraGiftMessageView.New()
|
|
-- end
|
|
-- else
|
|
-- if self.SakuraGiftMessageView then
|
|
-- self:HideNoticeView(false)
|
|
-- self.SakuraGiftMessageView:DeleteMe()
|
|
-- self.SakuraGiftMessageView = nil
|
|
-- end
|
|
-- end
|
|
-- end
|
|
-- self.model:Bind(SakuraGiftModel.OPEN_MESSAGE_VIEW, onSakuraGiftMessageView)
|
|
end
|
|
|
|
----------滚屏跑马逻辑-start---------
|
|
-- function SakuraGiftController:AppendNoticeMsg( content )
|
|
-- if not self.SakuraGiftMessageView then
|
|
-- return
|
|
-- end
|
|
-- self.SakuraGiftMessageView:AppendMessage(content)
|
|
-- end
|
|
|
|
-- function SakuraGiftController:HideNoticeView(bool)
|
|
-- if self.SakuraGiftMessageView then
|
|
-- self.SakuraGiftMessageView:SetHide(bool)
|
|
-- end
|
|
-- end
|
|
|
|
-- function SakuraGiftController:InitMessage( )
|
|
-- if self.SakuraGiftMessageView then
|
|
-- self.SakuraGiftMessageView:InitMsg()
|
|
-- end
|
|
-- end
|
|
----------滚屏跑马逻辑-end-----------
|
|
|
|
--[[############## 基础信息 ##############
|
|
protocol=33400
|
|
{
|
|
c2s{
|
|
sub_type :int16 // 活动子类型
|
|
}
|
|
s2c{
|
|
sub_type :int16 // 活动子类型
|
|
lucky_value :int32 // 源樱值(幸运值)
|
|
use_free_times :int8 // 已使用免费次数
|
|
}
|
|
}--]]
|
|
function SakuraGiftController:Handle33400( scmd )
|
|
self.model:SetActInfo(scmd)
|
|
self.model:CheckAllRed( scmd.sub_type )
|
|
self.model:Fire(SakuraGiftModel.REFRESH_ACT_INFO)
|
|
end
|
|
|
|
--[[############## 抽奖 ##############
|
|
protocol=33401
|
|
{
|
|
c2s{
|
|
sub_type :int16 // 活动子类型
|
|
type :int8 // 1-单抽 2-十连抽
|
|
is_auto :int8 // 是否自动购买
|
|
}
|
|
s2c{
|
|
errcode :int32 // 错误码
|
|
sub_type :int16 // 活动子类型
|
|
lucky_value :int32 // 源樱值(幸运值)
|
|
use_free_times :int8 // 已使用免费次数
|
|
reward_list:array{
|
|
reward_id :int32 // 奖励物品Id
|
|
num :int16 // 数量
|
|
}
|
|
score :int32 // 当前拥有积分
|
|
}
|
|
}
|
|
--]]
|
|
function SakuraGiftController:Handle33401( scmd )
|
|
if scmd.errcode == 1 then
|
|
Message.show("操作成功~")
|
|
self.model:SetActInfo(scmd)
|
|
self.model:CheckAllRed( scmd.sub_type )
|
|
self.model:Fire(SakuraGiftModel.REFRESH_ACT_INFO)
|
|
self.model:ShowGetRewardView(scmd.reward_list)
|
|
self.model:Fire(SakuraGiftModel.REQUEST_CCMD_EVENT,33402, scmd.sub_type, 1)
|
|
else
|
|
ErrorCodeShow(scmd.errcode)
|
|
end
|
|
end
|
|
|
|
--[[############## 记录信息 ##############
|
|
protocol=33402
|
|
{
|
|
c2s{
|
|
sub_type :int16 // 活动子类型
|
|
log_type :int8 // 1-全服记录 2-个人记录
|
|
}
|
|
s2c{
|
|
sub_type :int16 // 活动子类型
|
|
log_type :int8 // 1-全服记录 2-个人记录
|
|
log_list:array{
|
|
name :string
|
|
good_type_id :int32 // 物品配置Id
|
|
num :int16 // 物品数量
|
|
time :int32 // 时间
|
|
}
|
|
}
|
|
}--]]
|
|
function SakuraGiftController:Handle33402( scmd )
|
|
if scmd.sub_type == self.cur_sub_type then -- 全服传闻
|
|
local sort_func = function ( a, b )
|
|
return a.time < b.time
|
|
end
|
|
table.sort(scmd.log_list, sort_func)
|
|
self.model:InitMessage()
|
|
-- local function delay_method( )
|
|
local sort_func = function ( a, b )
|
|
return a.time > b.time
|
|
end
|
|
table.sort(scmd.log_list, sort_func)
|
|
for k,v in ipairs(scmd.log_list) do
|
|
local content = "%s 在%s中祈福得到了%s * %s,实在是福运绵长啊"
|
|
local goods_name = GoodsModel:getInstance():getGoodsName(v.good_type_id, true)
|
|
content = string.format(content,
|
|
HtmlColorTxt( v.name, ColorUtil.YELLOW_DARK),
|
|
HtmlColorTxt( "[源樱之礼]", ColorUtil.GREEN_DARK),
|
|
goods_name, v.num )
|
|
self.model:AppendNoticeMsg( content )
|
|
end
|
|
self.model:Fire(SakuraGiftModel.UPDATE_CHUANWEN)
|
|
-- end
|
|
-- setTimeout(delay_method, 3)
|
|
end
|
|
-- self.model:Fire(SakuraGiftModel.REFRESH_RECORD_INFO, scmd)
|
|
end
|
|
|
|
--积分商城信息
|
|
function SakuraGiftController:Handle33403( scmd )
|
|
self.model:SetShopInfo(scmd)
|
|
self.model:CheckAllRed( scmd.sub_type )
|
|
self.model:Fire(SakuraGiftModel.REFRESH_SHOP_INFO)
|
|
end
|
|
|
|
|
|
--[[############## 积分商城兑换 ##############
|
|
protocol=33404
|
|
{
|
|
c2s{
|
|
sub_type :int16 // 活动子类型
|
|
reward_id :int32 // 奖励Id(对应奖励配置Id)
|
|
buy_num :int16 // 兑换数量
|
|
}
|
|
s2c{
|
|
errcode :int32 // 错误码
|
|
sub_type :int16 // 活动子类型
|
|
score :int32 // 当前拥有积分
|
|
// 只更新兑换的物品数据
|
|
reward_id :int32 // 奖励Id(对应奖励配置Id)
|
|
times :int16 // 已兑换次数
|
|
}
|
|
}--]]
|
|
--积分商城兑换
|
|
function SakuraGiftController:Handle33404( scmd )
|
|
if scmd.errcode == 1 then
|
|
--print('=======Msh:SakuraGiftController.lua[200] ===TABLE====')
|
|
--PrintTable(scmd)
|
|
Message.show("兑换成功~")
|
|
local is_find = self.model:RefreshShopOneInfo(scmd)
|
|
--print('=======Msh:SakuraGiftController.lua[204] =======', is_find)
|
|
if is_find then
|
|
self.model:CheckRedByType(SakuraGiftModelRedType.Exchange, scmd.sub_type)
|
|
self.model:Fire(SakuraGiftModel.REFRESH_SHOP_INFO)
|
|
else
|
|
self.model:Fire(SakuraGiftModel.REQUEST_CCMD_EVENT, 33403, scmd.sub_type)
|
|
end
|
|
else
|
|
ErrorCodeShow(scmd.errcode)
|
|
end
|
|
end
|