miduo_client/Assets/ManagedResources/~Lua/Modules/Vip/VipManager.lua

451 lines
12 KiB
Lua
Raw Normal View History

2020-08-25 15:46:38 +08:00
--[[
2020-05-09 13:31:21 +08:00
* @ClassName VipManager
* @Description
* @Date 2019/5/22 10:22
* @Author MagicianJoker, fengliudianshao@outlook.com
* @Copyright Copyright (c) 2019, MagicianJoker
--]]
VipManager = {}
local this = VipManager
local vipLevel = 0
local hadTakeLevelBox, hadTakeDailyBox
local vipLevelConfig = ConfigManager.GetConfig(ConfigName.VipLevelConfig)
local shopData = ConfigManager.GetConfig((ConfigName.StoreConfig))
local minLevel = 0
local maxLevel = 0
local m_chargedNum = 0
local m_rewardLeve = 0
local lastCharged = 0
function this.Initialize()
--累充金额,由服务器返回
-- 设置最高等级
this.SetMaxVipLevel()
this.totalCostMoney = 0
-- 初始化Vip礼包数据
this.InitVipShopData()
-- 监听商店开启
Game.GlobalEvent:AddEvent(GameEvent.FunctionCtrl.OnFunctionOpen, function (openId)
if openId == 20 then
CheckRedPointStatus(RedPointType.VIP_SHOP_DETAIL)
end
end)
end
-- 登录时初始化Vip信息
function this.InitInfoOnLogin(msg)
-- 避免服务器不同代码
if msg.amount then
lastCharged = msg.amount
this.RefreshChargeMoney(msg.amount, true)
end
if msg.vipDaily then
Log("今日领取礼包时的Vip等级是 -- " .. msg.vipDaily)
2020-05-09 13:31:21 +08:00
this.SetRewardVipLevel(msg.vipDaily)
end
-- 每天第一次登录时, 重置红点信息
if PatFaceManager.isFirstLog == 0 then
this.ReSetBtnListRedState()
end
2020-06-13 11:47:13 +08:00
PlayerPrefs.SetInt(PlayerManager.uid.."czlb", 0)--成长礼包红点每次登录显示
2020-05-09 13:31:21 +08:00
end
--vip等级的取设, 刷新Vip等级
function this.SetVipLevel(level)
vipLevel = level
AdventureManager.RefreshAttachVipData()
MapTrialManager.RefreshAttachVipData()
SecretBoxManager.RefreshFreeTime()
RecruitManager.RefreshFreeTime()
GoodFriendManager.OnRefreshEnegryData()
CheckRedPointStatus(RedPointType.LuckyCat_GetReward)
Game.GlobalEvent:DispatchEvent(GameEvent.Bag.BagGold)
2020-08-22 15:31:14 +08:00
--发送埋点数据
CustomEventManager.SendCustomEvents(FBSDKCustomEventType.VipLv,vipLevel)
2020-05-09 13:31:21 +08:00
end
-- 刷新累充数量,更新VIP等级
function this.RefreshChargeMoney(chargedNum, isLogin)
-- 先检测是否升级了
local oldLevel = this.SetLevelByCost(lastCharged)
m_chargedNum = chargedNum
local vipLevel = this.SetLevelByCost(chargedNum)
2020-05-25 19:16:23 +08:00
-- this.SetVipLevel(vipLevel)
2020-05-09 13:31:21 +08:00
if oldLevel ~= this.GetVipLevel() and not isLogin then
Log("Vip等级提升")
2020-05-09 13:31:21 +08:00
CheckRedPointStatus(RedPointType.VIP_SHOP_DETAIL)
CheckRedPointStatus(RedPointType.VipPrivilege)
end
-- 同步充值金额
lastCharged = chargedNum
--刷新下签到红点
CheckRedPointStatus(RedPointType.CumulativeSignIn)
Log("已充值金额" .. chargedNum)
2020-05-09 13:31:21 +08:00
end
-- 获得累充数量
function this.GetChargedNum()
return m_chargedNum
end
-- 根据充值数量设置Vip等级
function this.SetLevelByCost(cost)
Log("cost" .. cost)
local level = minLevel
if cost <= vipLevelConfig[minLevel].MoneyLimit then
level = minLevel
elseif cost >= vipLevelConfig[maxLevel].MoneyLimit then
level = maxLevel
end
for k, v in ConfigPairs(vipLevelConfig) do
local money = v.MoneyLimit
if v.VipLevel < maxLevel then
if cost >= money and cost < vipLevelConfig[v.VipLevel + 1].MoneyLimit then
level = v.VipLevel + 1
end
end
end
Log("Level --- " .. level)
level = level > maxLevel and maxLevel or level
Log(string.format("累充数%s对应的Vip等级%s", cost, level))
2020-05-09 13:31:21 +08:00
return level
end
-- 距离升级到下一档位还需充值金额
function this.GetNextLevelNeed()
local chargedNum = this.GetChargedNum()
local nextLevelNeed = vipLevelConfig[this.GetVipLevel()].MoneyLimit
local maxLevelNeed = this.CurLevelMoneyNeed(maxLevel)
-- 最高等级不需要再充钱
local needNum = 0
if chargedNum < maxLevelNeed then
needNum = nextLevelNeed - chargedNum
needNum = needNum <= 0 and 0 or needNum
else
nextLevelNeed = maxLevelNeed
end
return needNum, nextLevelNeed
end
-- 达到当前档位需要的累充金额
function this.CurLevelMoneyNeed(curLevel)
local need = 0
local lastLevel = curLevel - 1 <= 0 and 0 or curLevel - 1
need = vipLevelConfig[lastLevel].MoneyLimit
if curLevel == 0 then
need = 0
end
return need
end
function this.GetVipLevel()
return vipLevel
end
--vip等级权益状态的取设
function this.SetTakeLevelBoxStatus(value)
hadTakeLevelBox = value
end
function this.GetTakeLevelBoxStatus()
return hadTakeLevelBox
end
--vip每日礼包权益状态的取设
function this.SetTakeDailyBoxStatus(value)
hadTakeDailyBox = value
end
function this.GetTakeDailyBoxStatus()
return hadTakeDailyBox
end
function this.InitCommonData(context)
2020-05-25 19:16:23 +08:00
this.SetVipLevel(context.vipLevel)
2020-05-09 13:31:21 +08:00
this.SetTakeDailyBoxStatus(context.hadTakeDailyBox)
this.SetTakeLevelBoxStatus(context.hadTakeLevelBox)
end
--五点刷新数据
function this.FiveAMRefreshLocalData(hadTakeDailyBox)
Log("5点刷新数据")
2020-05-09 13:31:21 +08:00
VipManager.SetTakeDailyBoxStatus(hadTakeDailyBox)
--通知Vip界面刷新数据
MapTrialManager.RefreshAttachVipData()
SecretBoxManager.RefreshFreeTime()
RecruitManager.RefreshFreeTime()
GoodFriendManager.OnRefreshDataNextDay()
ShopManager.FiveAMRedpotStatusReset()
-- 5点时刷新一下
this.SetRewardVipLevel(hadTakeDailyBox)
-- 重置按钮的红点状态
this.ReSetBtnListRedState()
Game.GlobalEvent:DispatchEvent(GameEvent.Vip.OnVipDailyRewardStatusChanged)
CheckRedPointStatus(RedPointType.VIP_SHOP_DETAIL)
CheckRedPointStatus(RedPointType.VipPrivilege)
end
-- 需要显示在主界面的文字
function this.GetMainPanelShowText()
local missionInfo = TaskManager.GetTypeTaskList(TaskTypeDef.VipTask)
table.sort(missionInfo, function(a, b)
return a.state < b.state
end)
local isDone = true
for i = 1, #missionInfo do
if missionInfo[i].state == 0 then
isDone = false
break
end
end
local str = ""
if isDone then
str="当前特权等级的任务已经完成"
2020-05-09 13:31:21 +08:00
else
str= ConfigManager.GetConfigData(ConfigName.TaskConfig, missionInfo[1].missionId).Desc
end
--Log("missionInfo[1].missionId ------------"..missionInfo[1].missionId)
--local info = ConfigManager.GetConfigData(ConfigName.TaskConfig, missionInfo[1].missionId)
--
--str = isDone and "当前特权等级的任务已经完成" or info.Desc
return str
end
-- 某一特权对应的第一个礼包奖励
function this.GetFirstNameByLevel(level)
level = level + 1
local str = ""
for k, v in ConfigPairs(shopData) do
if v.StoreId == SHOP_TYPE.VIP_GIFT and v.Sort == level then
str = v.GoodsName
break
end
end
return str
end
function this.InitVipShopData()
this.vipShopData = {}
for k, v in ConfigPairs(shopData) do
if v.StoreId == SHOP_TYPE.VIP_GIFT then
this.vipShopData[v.Sort] = v
end
end
end
function this.SetMaxVipLevel()
local max = 0
for i, v in ConfigPairs(vipLevelConfig) do
max = max > v.VipLevel and max or v.VipLevel
end
maxLevel = max
-- Log("最大Vip等级" .. max)
end
function this.GetMaxVipLevel()
return maxLevel
end
-- 获取豪华月卡的激活状态
function this.GetMonthCardOpenState()
local isActive = false
--local endTime = OperatingManager.GetGoodsEndTime(GoodsTypeDef.LuxuryMonthCard)
--if endTime and endTime - GetTimeStamp() > 0 then
-- isActive = true
--else
-- isActive = false
--end
local curAllMonthCardData = OperatingManager.GetMonthCardData()
isActive = curAllMonthCardData[MONTH_CARD_TYPE.LUXURYMONTHCARD] and curAllMonthCardData[MONTH_CARD_TYPE.LUXURYMONTHCARD].endingTime ~= 0
return isActive
end
-- 获取每日奖励的领取状态。0时表示未领 大于0表示已经领取过
function this.GetRewardState()
return m_rewardLeve
end
-- 设置领取礼包时的Vip等级
function this.SetRewardVipLevel(level)
m_rewardLeve = level
end
-- 获取今天领取礼包时的Vip等级
function this.GetRewardVipLevel()
return m_rewardLeve
end
------------------------- 红点 --------------------------
function this.ReSetBtnListRedState()
for i = 0, maxLevel do
this.SetBuyBtnRed(i, 0)
end
end
--- 记录按钮点击红点
function this.GetBuyBtnRedState(level)
return PlayerPrefs.GetInt(PlayerManager.uid .. "VIP_GIFT" .. level)
end
function this.SetBuyBtnRed(level, value)
PlayerPrefs.SetInt(PlayerManager.uid .. "VIP_GIFT" .. level, value)
end
-- 一排按钮的红点
function this.GetBtnListRed(level)
local data = this.vipShopData[level + 1]
local leftNum = ShopManager.GetShopItemRemainBuyTimes(SHOP_TYPE.VIP_GIFT, data.Id)
local canBuy = false -- 剩余购买次数大于0
if leftNum > 0 and this.GetVipLevel() >= level then
canBuy = true
else
canBuy = false
end
local isFirst = this.GetBuyBtnRedState(level) == 0 -- 今天或者解锁后的第一次点击
return isFirst and canBuy
end
-- 检查红点
function this.CheckRedPoint()
2020-05-25 19:16:23 +08:00
-- local isShopOpen = ActTimeCtrlManager.SingleFuncState(20)
-- -- 检查每日礼包奖励
-- local hasReward = false
-- local isActive = this.GetMonthCardOpenState()
-- local getState = this.GetRewardState()
-- if not isActive then
-- hasReward = false
-- else
-- if getState < 1 then
-- hasReward = true
-- else
-- hasReward = false
-- end
-- end
-- --按钮红点
-- local num = 0
-- for i = 0, maxLevel do
-- if this.GetBtnListRed(i) then
-- num = num + 1
-- end
-- end
-- local condition = hasReward or num > 0
-- condition = condition and isShopOpen
-- --Log("红点检测结果" .. tostring(condition))
-- return condition
return false
2020-05-09 13:31:21 +08:00
end
--外面那个不检测商店
function this.CheckVipRedPoint()
-- 检查每日礼包奖励
local hasReward = false
local isActive = this.GetMonthCardOpenState()
local getState = this.GetRewardState()
if not isActive then
hasReward = false
else
if getState < 1 then
hasReward = true
else
hasReward = false
end
end
--按钮红点
local num = 0
for i = 0, maxLevel do
if this.GetBtnListRed(i) then
num = num + 1
end
end
local condition = hasReward or num > 0
--Log("外面Vip入口检测结果" .. tostring(condition))
return condition
end
2020-05-25 19:16:23 +08:00
-- 检测新vip红点
function this.CheckNewVipRP()
if VipManager.GetVipLevel() >= VipManager.GetMaxVipLevel() then
return false
end
local isFinish = true
local list = TaskManager.GetTypeTaskList(TaskTypeDef.VipTask)
if not list then return false end
for _, t in ipairs(list) do
if t.state == VipTaskStatusDef.CanReceive then
return true
elseif t.state == VipTaskStatusDef.NotFinished then
isFinish = false
end
end
return isFinish
end
2020-06-08 13:57:30 +08:00
function this.CheckGrowthPackagePointStatus()--成长礼包
2020-11-04 14:24:08 +08:00
-- local redointTime =PlayerPrefs.GetInt(PlayerManager.uid.."czlb", 0)
-- local rechargeNum= VipManager.GetChargedNum()--已经充值的金额
-- local shopData = ShopManager.GetShopDataByType(SHOP_TYPE.VIP_GIFT).storeItem
-- local shopItemConfig = ConfigManager.GetConfig(ConfigName.StoreConfig)
-- for i = 1, #shopData do
-- local boughtNum = ShopManager.GetShopItemHadBuyTimes(SHOP_TYPE.VIP_GIFT, shopData[i].id)
-- if rechargeNum >= shopItemConfig[shopData[i].id].BuyRule[2] and boughtNum == 0 then
-- if redointTime == 0 then
-- return true
-- end
-- end
-- end
2020-06-08 13:57:30 +08:00
return false
end
2020-05-09 13:31:21 +08:00
---主界面显示使用
function this.SetVipLevelImg()
--- vip 0 暂时没有资源
local level = this.GetVipLevel()
level = level or 0
local img = Util.LoadSprite("r_zjm_tequanpaizi_0" .. level)
return img
end
-----------------------------------------------------
2020-06-13 11:47:13 +08:00
--- 获取vip属性加成
function this.GetAddPro()
local proList = {}
local level = this.GetVipLevel()
local VipLvConfig = ConfigManager.GetConfigData(ConfigName.VipLevelConfig, level)
for idx, dataInfo in ipairs(VipLvConfig.Property) do
proList[dataInfo[1]] = dataInfo[2]
end
return proList
end
2020-05-09 13:31:21 +08:00
2020-06-23 18:36:24 +08:00
return this