using System;
|
using System.Collections;
|
using System.Collections.Generic;
|
using System.Linq;
|
using UnityEngine;
|
namespace vnxbqy.UI
|
{
|
public class MonthWeekInvestModel : Model, IBeforePlayerDataInitialize, IPlayerLoginOk
|
{
|
Dictionary<int, Dictionary<int, List<Item>>> m_InvestItems = new Dictionary<int, Dictionary<int, List<Item>>>();
|
Dictionary<int, List<int>> m_InvestRechargeIds = new Dictionary<int, List<int>>();
|
Dictionary<int, InvestInfo> m_InvestInfos = new Dictionary<int, InvestInfo>();
|
//{投资类型:[领取天,当前天]} 天从1开始
|
Dictionary<int, List<List<int>>> m_InvestSingleInfos = new Dictionary<int, List<List<int>>>();
|
Dictionary<int, Redpoint> m_Redpoints = new Dictionary<int, Redpoint>();
|
public List<int> investTypes { get; private set; }
|
|
int m_SelectType = 0;
|
public int selectType
|
{
|
get { return m_SelectType; }
|
set
|
{
|
if (m_SelectType != value)
|
{
|
m_SelectType = value;
|
if (onSelectUpdate != null)
|
{
|
onSelectUpdate();
|
}
|
}
|
}
|
}
|
|
public int jumpType { get; set; }
|
|
public bool IsOpen
|
{
|
get
|
{
|
return FuncOpen.Instance.IsFuncOpen(119);
|
}
|
}
|
|
public bool IsAdvance { get { return false; } }
|
|
public bool priorityOpen
|
{
|
get
|
{
|
return redpoint.state == RedPointState.Simple || redpoint.state == RedPointState.GetReward;
|
}
|
}
|
|
public event Action<int> onStateUpdate;
|
public event Action onSelectUpdate;
|
public event Action onInvestUpdate;
|
|
public readonly Redpoint redpoint = new Redpoint(201, 20103);
|
public readonly Redpoint redpoint2 = new Redpoint(201, 20104);
|
VipModel vipModel { get { return ModelCenter.Instance.GetModel<VipModel>(); } }
|
|
public override void Init()
|
{
|
//OpenServerActivityCenter.Instance.Register(22, this);
|
FuncOpen.Instance.OnFuncStateChangeEvent += OnFuncStateChangeEvent;
|
|
ParseConfig();
|
}
|
|
public void OnBeforePlayerDataInitialize()
|
{
|
m_InvestInfos.Clear();
|
m_InvestSingleInfos.Clear();
|
}
|
|
public void OnPlayerLoginOk()
|
{
|
//foreach (var type in investTypes)
|
//{
|
// DayRemind.Instance.SetDayRemind("MonthWeekInvest_" + type);
|
//}
|
|
UpdateRedpoint();
|
}
|
|
public override void UnInit()
|
{
|
FuncOpen.Instance.OnFuncStateChangeEvent -= OnFuncStateChangeEvent;
|
}
|
|
void ParseConfig()
|
{
|
var funcConfig = FuncConfigConfig.Get("InvestCost");
|
var json = LitJson.JsonMapper.ToObject(funcConfig.Numerical3);
|
foreach (var typeKey in json.Keys)
|
{
|
var type = int.Parse(typeKey);
|
m_InvestRechargeIds[type] = new List<int>(LitJson.JsonMapper.ToObject<int[]>(json[typeKey].ToJson()));
|
if (type == 8)
|
m_Redpoints.Add(type, new Redpoint(redpoint.id, redpoint.id * 100 + type));
|
else if (type == 7)
|
m_Redpoints.Add(type, new Redpoint(redpoint2.id, redpoint2.id * 100 + type));
|
}
|
investTypes = m_InvestRechargeIds.Keys.ToList();
|
|
investTypes.Sort((x, y) =>
|
{
|
return -x.CompareTo(y);
|
});
|
|
var configs = InvestConfig.GetValues();
|
foreach (var config in configs)
|
{
|
if (!investTypes.Contains(config.type))
|
{
|
continue;
|
}
|
|
Dictionary<int, List<Item>> dict;
|
if (!m_InvestItems.TryGetValue(config.type, out dict))
|
{
|
dict = new Dictionary<int, List<Item>>();
|
m_InvestItems.Add(config.type, dict);
|
}
|
|
List<Item> items;
|
if (!dict.TryGetValue(config.id, out items))
|
{
|
items = new List<Item>();
|
dict.Add(config.id, items);
|
}
|
|
var itemJson = LitJson.JsonMapper.ToObject(config.award);
|
var itemArray = LitJson.JsonMapper.ToObject<int[][]>(itemJson["1"].ToJson());
|
for (int i = 0; i < itemArray.Length; i++)
|
{
|
items.Add(new Item()
|
{
|
id = itemArray[i][0],
|
count = itemArray[i][1],
|
});
|
}
|
}
|
}
|
|
public int GetOrderInfoId(int type)
|
{
|
var ids = m_InvestRechargeIds[type];
|
for (int i = 0; i < ids.Count; i++)
|
{
|
OrderInfoConfig config;
|
if (vipModel.TryGetOrderInfo(ids[i], out config))
|
{
|
return config.id;
|
}
|
}
|
return 0;
|
}
|
|
public int GetSelectType()
|
{
|
if (jumpType != 0 && investTypes.Contains(jumpType))
|
{
|
var type = jumpType;
|
jumpType = 0;
|
return type;
|
}
|
else
|
{
|
foreach (var type in m_Redpoints.Keys)
|
{
|
if (m_Redpoints[type].state == RedPointState.GetReward)
|
{
|
return type;
|
}
|
}
|
}
|
return investTypes[0];
|
}
|
|
public int GetInvestPassDays(int type)
|
{
|
return m_InvestInfos.ContainsKey(type) ? m_InvestInfos[type].days : 0;
|
}
|
|
public int GetTotalIncome(int type)
|
{
|
var income = 0;
|
if (m_InvestItems.ContainsKey(type))
|
{
|
foreach (var items in m_InvestItems[type].Values)
|
{
|
income += items[0].count;
|
}
|
}
|
return income;
|
}
|
|
public int GetFirstIncome(int type)
|
{
|
if (m_InvestItems.ContainsKey(type))
|
{
|
var ctgID = (int)OrderInfoConfig.Get(GetOrderInfoId(type)).CTGID;
|
var config = CTGConfig.Get(ctgID);
|
if (config == null)
|
{
|
return 0 ;
|
}
|
return config.GainGold;
|
}
|
return 0;
|
}
|
|
public int GetDailyIncome(int type)
|
{
|
var income = 0;
|
if (m_InvestItems.ContainsKey(type))
|
{
|
var index = 0;
|
foreach (var items in m_InvestItems[type].Values)
|
{
|
if (index == 1)
|
{
|
income = items[0].count;
|
break;
|
}
|
index++;
|
}
|
}
|
return income;
|
}
|
|
public int GetSingleInvestState(int type, int id)//0-未投资 1-未达成 2-可领取 3-已领取 4-已过期
|
{
|
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);
|
return day < config.needDay ? 1 : 2;//day == config.needDay ? 2 : 4;
|
}
|
}
|
return 0;
|
}
|
|
public float GetIncomeRate(int type, int day)
|
{
|
var orderInfoId = GetOrderInfoId(type);
|
var orderInfoConfig = OrderInfoConfig.Get(orderInfoId);
|
//var money = (int)orderInfoConfig.PayRMBNum * 100;
|
var money = 300;
|
if (type == 7)
|
{
|
money = 9800;
|
}
|
var income = 0;
|
if (m_InvestItems.ContainsKey(type))
|
{
|
foreach (var id in m_InvestItems[type].Keys)
|
{
|
var config = InvestConfig.Get(id);
|
if (day >= config.needDay)
|
{
|
income += m_InvestItems[type][id][0].count;
|
}
|
}
|
}
|
return (float)income / money;
|
}
|
|
public bool TryGetItems(int type, int id, out List<Item> items)
|
{
|
items = null;
|
if (m_InvestItems.ContainsKey(type))
|
{
|
return m_InvestItems[type].TryGetValue(id, out items);
|
}
|
return false;
|
}
|
|
public bool TryGetInvestItems(int type, out Dictionary<int, List<Item>> dict)
|
{
|
return m_InvestItems.TryGetValue(type, out dict);
|
}
|
|
public bool IsInvested(int type)
|
{
|
return m_InvestInfos.ContainsKey(type) && m_InvestInfos[type].money > 0;
|
}
|
|
public bool IsRewardGot(int type, int id)
|
{
|
if (m_InvestSingleInfos.ContainsKey(type))
|
{
|
var index = id % 100;
|
//每个数按位存31个激活索引
|
var listIndex = index / 31;
|
var bitIndex = index % 31;
|
return ((int)Math.Pow(2, bitIndex) & m_InvestSingleInfos[type][1][listIndex]) != 0;
|
}
|
return false;
|
}
|
|
private void OnFuncStateChangeEvent(int id)
|
{
|
if (id == 119)
|
{
|
if (onStateUpdate != null)
|
{
|
onStateUpdate(22);
|
}
|
UpdateRedpoint();
|
}
|
}
|
|
public void SendGetReward(int type, int id)
|
{
|
var pak = new CA541_tagCMGetInvestReward();
|
pak.InvestType = (byte)type;
|
pak.RewardIndex = (byte)(id % 100);
|
GameNetSystem.Instance.SendInfo(pak);
|
}
|
|
public void SendInvest(int type)
|
{
|
var orderInfoId = GetOrderInfoId(type);
|
var config = OrderInfoConfig.Get(orderInfoId);
|
vipModel.CTG(config);
|
}
|
|
public void SetDayRemind(int type)
|
{
|
//DayRemind.Instance.SetDayRemind("MonthWeekInvest_" + type, true);
|
//UpdateRedpoint();
|
}
|
|
public void OnReceivePackageEx(HA338_tagMCInvestInfo package)
|
{
|
if (!investTypes.Contains(package.InvestType))
|
{
|
return;
|
}
|
|
m_InvestInfos[package.InvestType] = new InvestInfo()
|
{
|
days = (int)package.CurDay,
|
money = package.CurDay >= 1 ? 1 : 0,
|
};
|
|
List<List<int>> singleInfos;
|
if (!m_InvestSingleInfos.TryGetValue(package.InvestType, out singleInfos))
|
{
|
singleInfos = new List<List<int>>();
|
m_InvestSingleInfos.Add(package.InvestType, singleInfos);
|
}
|
singleInfos.Clear();
|
singleInfos.Add(new List<int>());
|
singleInfos.Add(new List<int>());
|
singleInfos.Add(new List<int>());
|
singleInfos[0].Add((int)package.CurDay);
|
for (int i = 0; i < package.ValueCount; i++)
|
{
|
singleInfos[1].Add((int)package.RewardValue[i]);
|
singleInfos[2].Add((int)package.ProgressValue[i]);
|
}
|
UpdateRedpoint();
|
|
if (onInvestUpdate != null)
|
{
|
onInvestUpdate();
|
}
|
}
|
|
void UpdateRedpoint()
|
{
|
List<int> redpointTypes = new List<int>();
|
List<int> dayReminds = new List<int>();
|
if (IsOpen)
|
{
|
foreach (var type in investTypes)
|
{
|
if (!IsInvested(type))
|
{
|
//if (!DayRemind.Instance.GetDayRemind("MonthWeekInvest_" + type))
|
//{
|
// dayReminds.Add(type);
|
//}
|
continue;
|
}
|
foreach (var id in m_InvestItems[type].Keys)
|
{
|
if (GetSingleInvestState(type, id) == 2)
|
{
|
redpointTypes.Add(type);
|
break;
|
}
|
}
|
}
|
}
|
foreach (var type in m_Redpoints.Keys)
|
{
|
m_Redpoints[type].state = redpointTypes.Contains(type) ? RedPointState.GetReward : dayReminds.Contains(type) ? RedPointState.Simple : RedPointState.None;
|
}
|
}
|
|
public struct InvestInfo
|
{
|
public int money;
|
public int days;
|
}
|
}
|
}
|