using System;
|
using System.Collections.Generic;
|
using UnityEngine.UI;
|
using System.Linq;
|
using LitJson;
|
|
public class InvestModel : GameSystemManager<InvestModel>
|
{
|
public const int monthCardType = 1; // 月卡
|
public const int foreverCardType = 2; //永久卡 权限
|
|
|
//投资对应奖励
|
Dictionary<int, int[][]> m_InvestItems = new Dictionary<int, int[][]>();
|
Dictionary<int, int> m_InvestDays = new Dictionary<int, int>(); //投资对应天数
|
Dictionary<int, int> m_InvestMaxDays = new Dictionary<int, int>(); //投资对应最大购买累加天数
|
|
//投资对应充值ID
|
Dictionary<int, int[]> m_InvestRechargeIds = new Dictionary<int, int[]>();
|
Dictionary<int, int> m_InvestCTGIDToType = new Dictionary<int, int>();
|
|
//投资对应购买情况
|
Dictionary<int, InvestInfo> m_InvestInfos = new Dictionary<int, InvestInfo>();
|
//投资类型
|
|
//--特权--
|
//增加副本购买次数
|
Dictionary<int, Dictionary<int, int>> m_InvestAddFBCount = new Dictionary<int, Dictionary<int, int>>();
|
//副本购买次数免费的副本ID 和 m_InvestAddFBCount 配合使用 相当于 特权增加副本上限但是发包流程需和服务端商量
|
Dictionary<int, int[]> m_InvestFreeFBID = new Dictionary<int, int[]>();
|
//演武场增加上限
|
Dictionary<int, int> m_InvestArenaMaxCnt = new Dictionary<int, int>();
|
//祝福树能量增加上限
|
Dictionary<int, int> m_InvestAddBlessEnergyCount = new Dictionary<int, int>();
|
|
// 特权权限数量
|
Dictionary<int, int> m_PrivilegeLins = new Dictionary<int, int>();
|
// 战斗倍数开启对应特权
|
Dictionary<int, int> m_PrivilegeFightSpeed = new Dictionary<int, int>();
|
// 英雄积分招募开启的特权类型
|
int[] heroScoreCallOpenType;
|
|
|
public event Action<int> onInvestUpdate;
|
|
public Redpoint redpoint1 = new Redpoint(MainRedDot.RedPoint_PrivilegeCard, MainRedDot.RedPoint_PrivilegeCard * 10 + 1);
|
public Redpoint redpoint2 = new Redpoint(MainRedDot.RedPoint_PrivilegeCard, MainRedDot.RedPoint_PrivilegeCard * 10 + 2);
|
|
|
public override void Init()
|
{
|
DTC0102_tagCDBPlayer.beforePlayerDataInitializeEvent += OnBeforePlayerDataInitialize;
|
RechargeManager.Instance.rechargeCountEvent += OnRechargeCountEvent;
|
//通过配置决定是否有此投资项,如港台没有登录投资
|
ParseConfig();
|
|
}
|
|
|
|
public override void Release()
|
{
|
DTC0102_tagCDBPlayer.beforePlayerDataInitializeEvent -= OnBeforePlayerDataInitialize;
|
RechargeManager.Instance.rechargeCountEvent -= OnRechargeCountEvent;
|
}
|
|
public bool IsOpen()
|
{
|
return FuncOpen.Instance.IsFuncOpen((int)FuncOpenEnum.PrivilegeCard);
|
}
|
|
|
public void OnBeforePlayerDataInitialize()
|
{
|
m_InvestInfos.Clear();
|
lastTotalBuyCountDict.Clear();
|
}
|
|
|
|
void ParseConfig()
|
{
|
var funcConfig = FuncConfigConfig.Get("InvestCost");
|
m_InvestRechargeIds = ConfigParse.ParseIntArrayDict(funcConfig.Numerical1);
|
foreach (var item in m_InvestRechargeIds)
|
{
|
m_InvestCTGIDToType[item.Value[0]] = item.Key;
|
}
|
|
funcConfig = FuncConfigConfig.Get("InvestDay");
|
m_InvestDays = ConfigParse.ParseIntDict(funcConfig.Numerical1);
|
m_InvestMaxDays = ConfigParse.ParseIntDict(funcConfig.Numerical2);
|
m_InvestItems = ConfigParse.ParseIntArray2Dict(funcConfig.Numerical3);
|
|
|
funcConfig = FuncConfigConfig.Get("InvestPower");
|
m_InvestAddFBCount = ConfigParse.ParseDictInDict(funcConfig.Numerical1);
|
m_InvestFreeFBID = ConfigParse.ParseIntArrayDict(funcConfig.Numerical2);
|
m_InvestArenaMaxCnt = ConfigParse.ParseIntDict(funcConfig.Numerical3);
|
m_InvestAddBlessEnergyCount = ConfigParse.ParseIntDict(funcConfig.Numerical4);
|
|
funcConfig = FuncConfigConfig.Get("PrivilegeCard");
|
m_PrivilegeLins = ConfigParse.ParseIntDict(funcConfig.Numerical1);
|
m_PrivilegeFightSpeed = ConfigParse.ParseIntDict(funcConfig.Numerical2);
|
heroScoreCallOpenType = JsonMapper.ToObject<int[]>(funcConfig.Numerical3);
|
|
}
|
|
Dictionary<int, int> lastTotalBuyCountDict = new Dictionary<int, int>();
|
void OnRechargeCountEvent(int ctgID)
|
{
|
|
if (m_InvestCTGIDToType.ContainsKey(ctgID))
|
{
|
var type = m_InvestCTGIDToType[ctgID];
|
RechargeManager.Instance.TryGetRechargeCount(ctgID, out var rechargeCount);
|
if (!DTC0403_tagPlayerLoginLoadOK.finishedLogin)
|
{
|
lastTotalBuyCountDict[type] = rechargeCount.totalCount;
|
return;
|
}
|
var count = 0;
|
lastTotalBuyCountDict.TryGetValue(type, out count);
|
if (count < rechargeCount.totalCount)
|
{
|
lastTotalBuyCountDict[type] = rechargeCount.totalCount;
|
UIManager.Instance.OpenWindow<PrivilegeActiveCardWin>(type);
|
}
|
}
|
}
|
|
|
|
//获取投资剩余时间 秒
|
public int GetInvestLeftTime(int type)
|
{
|
if (type == 1 && m_InvestInfos[type].InvestEndTime > 0)
|
{
|
//月卡 限时类型的投资 未到期就算投资
|
return m_InvestInfos[type].InvestEndTime - TimeUtility.AllSeconds;
|
}
|
return 0;
|
}
|
|
|
|
//0-未投资 1-可领取 2-已领取
|
public int GetInvestState(int type)
|
{
|
if (IsInvested(type))
|
{
|
if (m_InvestInfos[type].AwardState == 0)
|
{
|
return 1;
|
}
|
return 2;
|
}
|
return 0;
|
}
|
|
|
//判断是否购买了投资
|
public bool IsInvested(int type)
|
{
|
if (!m_InvestInfos.ContainsKey(type))
|
{
|
return false;
|
}
|
if (type == 1)
|
{
|
//月卡 限时类型的投资 未到期就算投资
|
return m_InvestInfos[type].InvestEndTime > 0 && m_InvestInfos[type].InvestEndTime > TimeUtility.AllSeconds;
|
}
|
|
//永久类型的投资 只要购买了就算投资
|
return m_InvestInfos[type].InvestBuyTime > 0;
|
}
|
|
|
//type 投资类型
|
public void SendGetReward(int type, int id = 0)
|
{
|
var pak = new CA541_tagCMGetInvestReward();
|
pak.InvestType = (byte)type;
|
pak.RewardIndex = (byte)id;
|
GameNetSystem.Instance.SendInfo(pak);
|
}
|
|
//购买投资
|
public void BuyInvest(int type)
|
{
|
RechargeManager.Instance.CTG(GetOrderInfo(type));
|
}
|
|
|
public void UpdateInvestInfo(HA338_tagSCInvestInfo package)
|
{
|
|
m_InvestInfos[package.InvestType] = new InvestInfo()
|
{
|
InvestBuyTime = (int)package.InvestBuyTime,
|
InvestEndTime = (int)package.InvestEndTime,
|
AwardState = package.AwardState
|
};
|
|
|
UpdateRedpoint();
|
|
if (onInvestUpdate != null)
|
{
|
onInvestUpdate(package.InvestType);
|
}
|
}
|
|
void UpdateRedpoint()
|
{
|
if (!IsOpen())
|
{
|
return;
|
}
|
|
redpoint1.state = GetInvestState(monthCardType) == 1 ? RedPointState.Simple : RedPointState.None;
|
redpoint2.state = GetInvestState(foreverCardType) == 1 ? RedPointState.Simple : RedPointState.None;
|
|
}
|
|
#region 特权接口
|
|
//副本增加的购买次数上限
|
public int GetAddFBBuyCount(int _mapID)
|
{
|
int addCount = 0;
|
foreach (var item in m_InvestAddFBCount)
|
{
|
if (!IsInvested(item.Key))
|
{
|
continue;
|
}
|
foreach (var mapID in item.Value.Keys)
|
{
|
if (mapID == _mapID)
|
{
|
addCount += item.Value[mapID];
|
}
|
}
|
}
|
|
return addCount;
|
}
|
|
//副本免费的购买次数
|
public bool GetFBIsFree(int _mapID)
|
{
|
foreach (var item in m_InvestFreeFBID)
|
{
|
if (!IsInvested(item.Key))
|
{
|
continue;
|
}
|
foreach (var mapID in item.Value)
|
{
|
if (mapID == _mapID)
|
{
|
return true;
|
}
|
}
|
}
|
return false;
|
}
|
|
|
public int GetPrivilegeLins(int type)
|
{
|
if (m_PrivilegeLins.ContainsKey(type))
|
{
|
return m_PrivilegeLins[type];
|
}
|
return 0;
|
}
|
|
public OrderInfoConfig GetOrderInfo(int type)
|
{
|
var ids = m_InvestRechargeIds[type];
|
for (int i = 0; i < ids.Length; i++)
|
{
|
OrderInfoConfig config;
|
if (RechargeManager.Instance.TryGetOrderInfo(ids[i], out config))
|
{
|
return config;
|
}
|
}
|
return null;
|
}
|
|
public int GetCTGID(int type)
|
{
|
return m_InvestRechargeIds[type][0];
|
}
|
|
public int[][] GetDayAwards(int type)
|
{
|
return m_InvestItems[type];
|
}
|
|
//演武场凭证上限
|
public int GetArenaAddMaxCount()
|
{
|
int addCount = 0;
|
foreach (var item in m_InvestArenaMaxCnt)
|
{
|
if (!IsInvested(item.Key))
|
{
|
continue;
|
}
|
addCount += item.Value;
|
}
|
|
return addCount;
|
}
|
|
//购买天数是否达上限
|
public bool IsBuyMaxDay(int type)
|
{
|
if (m_InvestMaxDays.ContainsKey(type) && m_InvestInfos.ContainsKey(type))
|
{
|
if (m_InvestInfos[type].InvestEndTime > 0)
|
{
|
return (m_InvestInfos[type].InvestEndTime - TimeUtility.AllSeconds) / 60 / 60 / 24 + m_InvestDays[type] >= m_InvestMaxDays[type];
|
}
|
}
|
return false;
|
}
|
|
//祝福能量上限
|
public int GetBlessAddEnergyMax()
|
{
|
int addCount = 0;
|
foreach (var item in m_InvestAddBlessEnergyCount)
|
{
|
if (!IsInvested(item.Key))
|
{
|
continue;
|
}
|
addCount += item.Value;
|
}
|
|
return addCount;
|
}
|
|
//是否激活英雄积分召唤
|
public bool IsActiveHeroScoreCall()
|
{
|
foreach (var type in heroScoreCallOpenType)
|
{
|
if (IsInvested(type))
|
{
|
return true;
|
}
|
}
|
return false;
|
}
|
|
public bool IsActiveFightSpeed(int speed)
|
{
|
foreach (var item in m_PrivilegeFightSpeed)
|
{
|
if (!IsInvested(item.Key))
|
{
|
continue;
|
}
|
if (item.Value == speed)
|
{
|
return true;
|
}
|
}
|
return false;
|
}
|
|
#endregion
|
|
|
|
|
public struct InvestInfo
|
{
|
public int InvestBuyTime; // 投资购买时间戳,永久的通过该时间判断是否有效或已过天数,任意类型均有该值,过期没有重置,前端自己判断
|
public int InvestEndTime; // 投资到期时间戳,非永久的通过该时间判断到期时间,有天数限制的才有值
|
public int AwardState; // 今日是否已领取奖励
|
}
|
}
|