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[][]>();
|
//投资对应充值ID
|
Dictionary<int, int[]> m_InvestRechargeIds = new Dictionary<int, int[]>();
|
//投资对应购买情况
|
Dictionary<int, InvestInfo> m_InvestInfos = new Dictionary<int, InvestInfo>();
|
//投资类型
|
public List<int> investTypes = new List<int>();
|
|
|
public event Action<int> onInvestUpdate;
|
|
public const int redpointID = 20931;
|
public Redpoint redpoint = new Redpoint(redpointID);
|
|
|
public override void Init()
|
{
|
FuncOpen.Instance.OnFuncStateChangeEvent += OnFuncStateChangeEvent;
|
DTC0102_tagCDBPlayer.beforePlayerDataInitializeEvent += OnBeforePlayerDataInitialize;
|
DTC0403_tagPlayerLoginLoadOK.playerLoginOkEvent += OnPlayerLoginOk;
|
|
//通过配置决定是否有此投资项,如港台没有登录投资
|
ParseConfig();
|
|
}
|
|
|
|
public override void Release()
|
{
|
FuncOpen.Instance.OnFuncStateChangeEvent -= OnFuncStateChangeEvent;
|
DTC0102_tagCDBPlayer.beforePlayerDataInitializeEvent -= OnBeforePlayerDataInitialize;
|
DTC0403_tagPlayerLoginLoadOK.playerLoginOkEvent -= OnPlayerLoginOk;
|
}
|
|
public bool IsOpen()
|
{
|
return FuncOpen.Instance.IsFuncOpen((int)FuncOpenEnum.PrivilegeCard);
|
}
|
|
|
public void OnBeforePlayerDataInitialize()
|
{
|
m_InvestInfos.Clear();
|
}
|
|
public void OnPlayerLoginOk()
|
{
|
UpdateRedpoint();
|
}
|
|
|
void ParseConfig()
|
{
|
var funcConfig = FuncConfigConfig.Get("InvestCost");
|
m_InvestRechargeIds = ConfigParse.ParseIntArrayDict(funcConfig.Numerical1);
|
|
funcConfig = FuncConfigConfig.Get("InvestDay");
|
m_InvestItems = ConfigParse.ParseIntArray2Dict(funcConfig.Numerical3);
|
|
investTypes = m_InvestRechargeIds.Keys.ToList();
|
investTypes.Sort();
|
|
|
}
|
|
public OrderInfoConfig GetOrderInfoId(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 bool hasInvestType(int type)
|
{
|
return investTypes.Contains(type);
|
}
|
|
|
// public int GetInvestPassDays(int type)
|
// {
|
// return m_InvestInfos.ContainsKey(type) ? m_InvestInfos[type].days : 0;
|
// }
|
|
|
|
//id 为表里的ID
|
//0-未投资 1-未达成 2-可领取 3-已领取
|
public int GetSingleInvestState(int type, int id)
|
{
|
// if (IsInvested(type))
|
// {
|
// var day = GetInvestPassDays(type);
|
// if (m_InvestItems.ContainsKey(type)
|
// && m_InvestItems[type].ContainsKey(id))
|
// {
|
// if (IsRewardGot(type, id))
|
// {
|
// return 3;
|
// }
|
// var config = InvestConfig.Get(id);
|
|
// if (!m_InvestSingleInfos.ContainsKey(type))
|
// {
|
// return 0;
|
// }
|
|
// var index = id % 100;
|
// //每个数按位存31个激活索引
|
// var listIndex = index / 31;
|
// var bitIndex = index % 31;
|
|
|
// return day < config.needDay ? 1 : 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;
|
}
|
|
|
|
private void OnFuncStateChangeEvent(int id)
|
{
|
if (id == (int)FuncOpenEnum.PrivilegeCard)
|
{
|
UpdateRedpoint();
|
}
|
|
}
|
|
|
|
public void SendGetReward(int type, int id)
|
{
|
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(GetOrderInfoId(type));
|
}
|
|
public void UpdateInvestInfo(HA338_tagSCInvestInfo package)
|
{
|
if (!investTypes.Contains(package.InvestType))
|
{
|
return;
|
}
|
|
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;
|
}
|
|
}
|
|
|
|
public struct InvestInfo
|
{
|
public int InvestBuyTime; // 投资购买时间戳,永久的通过该时间判断是否有效或已过天数,任意类型均有该值,过期没有重置,前端自己判断
|
public int InvestEndTime; // 投资到期时间戳,非永久的通过该时间判断到期时间,有天数限制的才有值
|
public int AwardState; // 今日是否已领取奖励
|
}
|
}
|