//--------------------------------------------------------
|
// [Author]: 第二世界
|
// [ Date ]: Thursday, April 26, 2018
|
//--------------------------------------------------------
|
using System;
|
using System.Collections.Generic;
|
|
using vnxbqy.UI;
|
using System.Linq;
|
//仙玉投资
|
public struct FairyInvestInfo
|
{
|
public int money;//金额
|
public int gear;//
|
}
|
|
public struct FairyInvestItems
|
{
|
public int id;
|
public int levelLimit;
|
public Dictionary<int, List<Item>> items;//奖励
|
}
|
|
public class FairyJadeInvestmentModel : Model, IBeforePlayerDataInitialize, IPlayerLoginOk, IOpenServerActivity
|
{
|
public Dictionary<int, Dictionary<int, FairyInvestItems>> fairyInvestItems = new Dictionary<int, Dictionary<int, FairyInvestItems>>();//根据投资类型来存储奖励类型和金额(类型3,4,5);
|
public Dictionary<int, Dictionary<int, int>> fairyInvestSingleInfos = new Dictionary<int, Dictionary<int, int>>();//根据类型存储奖励信息
|
public Dictionary<int, FairyInvestInfo> fairyInvestInfos = new Dictionary<int, FairyInvestInfo>();//根据类型获取各个类型投资的档位金额和分档
|
public Dictionary<int, int> fairyInvestLevelLimits { get; private set; }
|
|
public List<int> fairyInvestMultiples = new List<int>();
|
|
public int fairyInvestType { get; set; }
|
|
public int selectInvestMoney { get; set; }
|
|
public int prioritySelectIndex { get; private set; }
|
|
bool isServerPrepare = false;
|
public bool IsRedpoint = false;
|
|
private int redpointLevelLimit = 0;//显示等级
|
private int redpointDays = 0;//显示天数
|
private bool redpointDirty = true;
|
|
public readonly Redpoint redpoint = new Redpoint(209, 20910);//仙玉投资红点
|
|
|
public bool IsOpen
|
{
|
get
|
{
|
return IsFuncOpen();
|
}
|
}
|
|
public bool priorityOpen
|
{
|
get
|
{
|
return redpoint.state != RedPointState.None;
|
}
|
}
|
|
public bool IsAdvance
|
{
|
get
|
{
|
return false;
|
}
|
}
|
|
public event Action<int> onStateUpdate;
|
public event Action fairyInvestUpdate;
|
|
VipInvestModel investModel { get { return ModelCenter.Instance.GetModel<VipInvestModel>(); } }
|
|
public override void Init()
|
{
|
ParseConfig();
|
|
OpenServerActivityCenter.Instance.Register(10, this);
|
}
|
|
public void OnBeforePlayerDataInitialize()
|
{
|
redpointDirty = true;
|
isServerPrepare = false;
|
IsRedpoint = false;
|
selectInvestMoney = 0;
|
fairyInvestInfos.Clear();
|
fairyInvestSingleInfos.Clear();
|
}
|
|
public void OnPlayerLoginOk()
|
{
|
redpointDirty = true;
|
isServerPrepare = true;
|
fairyInvestType = GetFairyInvestType();
|
UpdateRedpoint();
|
IsShowRedPointSimple();
|
PlayerDatas.Instance.playerDataRefreshEvent -= PlayerDataRefreshEvent;
|
PlayerDatas.Instance.playerDataRefreshEvent += PlayerDataRefreshEvent;
|
FairyJadeInvestmentWin.FairyJadeInvestmentRedPointEvent -= FairyJadeInvestmentRedPoint;
|
FairyJadeInvestmentWin.FairyJadeInvestmentRedPointEvent += FairyJadeInvestmentRedPoint;
|
GlobalTimeEvent.Instance.secondEvent -= PerSecond;
|
GlobalTimeEvent.Instance.secondEvent += PerSecond;
|
}
|
|
public override void UnInit()
|
{
|
|
}
|
|
private void ParseConfig()
|
{
|
var funcConfig = FuncConfigConfig.Get("InvestRedPoint");
|
redpointLevelLimit = int.Parse(funcConfig.Numerical2);
|
redpointDays = int.Parse(funcConfig.Numerical3);
|
|
funcConfig = FuncConfigConfig.Get("JadeInvest");
|
fairyInvestMultiples.AddRange(ConfigParse.GetMultipleStr<int>(funcConfig.Numerical1));
|
|
funcConfig = FuncConfigConfig.Get("GoldInvestLVLimit");
|
fairyInvestLevelLimits = ConfigParse.GetDic<int, int>(funcConfig.Numerical1);
|
|
var configs = InvestConfig.GetValues();
|
foreach (var config in configs)
|
{
|
if (fairyInvestLevelLimits.ContainsKey(config.type))
|
{
|
Dictionary<int, FairyInvestItems> dict;
|
if (!fairyInvestItems.TryGetValue(config.type,out dict))
|
{
|
dict = new Dictionary<int, FairyInvestItems>();
|
fairyInvestItems.Add(config.type, dict);
|
}
|
|
var items = new Dictionary<int, List<Item>>();
|
var json = LitJson.JsonMapper.ToObject(config.award);
|
foreach (string gearKey in json.Keys)
|
{
|
var gear = int.Parse(gearKey);
|
items.Add(gear, new List<Item>());
|
var itemArray = LitJson.JsonMapper.ToObject<int[][]>(json[gearKey].ToJson());
|
for (int j = 0; j < itemArray.Length; j++)
|
{
|
items[gear].Add(new Item()
|
{
|
id = itemArray[j][0],
|
count = itemArray[j][1],
|
});
|
}
|
}
|
|
dict.Add(config.id % 100, new FairyInvestItems()
|
{
|
id = config.id % 100,
|
levelLimit = config.needLV,
|
items = items,
|
});
|
}
|
}
|
}
|
|
|
private void PerSecond()
|
{
|
if (redpointDirty)
|
{
|
int InvestGold = GetInvestGold();
|
if (InvestGold > 0)
|
{
|
UpdateRedpoint();
|
}
|
IsShowRedPointSimple();
|
redpointDirty = false;
|
}
|
}
|
|
private void PlayerDataRefreshEvent(PlayerDataType dataType)
|
{
|
if (dataType == PlayerDataType.LV)
|
{
|
redpointDirty = true;
|
}
|
}
|
|
private void FairyJadeInvestmentRedPoint()
|
{
|
RedPointSate();
|
}
|
|
private bool IsFuncOpen()//功能是否开启
|
{
|
bool existInvestGear = false;
|
|
int gear = GetFairyInvestGear();
|
var maxGear = investModel.GetInvestMaxGear(fairyInvestType);
|
|
if (gear > 0)
|
{
|
if (gear < maxGear)
|
{
|
existInvestGear = true;
|
}
|
else if (gear == maxGear)
|
{
|
var dit = GetInfoSeriors();
|
foreach (int key in dit.Keys)
|
{
|
if (dit[key] < gear)
|
{
|
existInvestGear = true;
|
}
|
}
|
}
|
}
|
|
if (!FuncOpen.Instance.IsFuncOpen(118))
|
{
|
return false;
|
}
|
|
var maxLevelLimit = fairyInvestLevelLimits.Values.Last();
|
|
if (PlayerDatas.Instance.baseData.LV > maxLevelLimit && !existInvestGear)
|
{
|
return false;
|
}
|
else
|
{
|
return true;
|
}
|
}
|
|
public void GetInfoSeriors(HA337_tagMCGoldInvestInfo package)//接受信息
|
{
|
if (fairyInvestLevelLimits.ContainsKey(package.InvestType))
|
{
|
var fairyInvestInfo = new FairyInvestInfo()
|
{
|
money = (int)package.InvestGold,
|
gear = investModel.GetInvestGear(package.InvestType, (int)package.InvestGold),
|
};
|
fairyInvestInfos[package.InvestType] = fairyInvestInfo;
|
|
if (!fairyInvestSingleInfos.ContainsKey(package.InvestType))//奖励刷新赋值
|
{
|
fairyInvestSingleInfos.Add(package.InvestType, new Dictionary<int, int>());
|
}
|
var Dit = fairyInvestSingleInfos[package.InvestType];
|
for (int i = 0; i < package.RewardRecordCnt; i++)
|
{
|
Dit[(int)package.InvestRewardList[i].RewardIndex] = (int)package.InvestRewardList[i].RewardValue;
|
}
|
|
UpdateRedpoint();
|
if (fairyInvestUpdate != null)
|
{
|
fairyInvestUpdate();
|
}
|
}
|
}
|
|
public void SendGotInvestReward(int type, int index)//领取奖励
|
{
|
var pak = new CA541_tagCMGetInvestReward();
|
pak.InvestType = (byte)type;
|
pak.RewardIndex = (byte)index;
|
GameNetSystem.Instance.SendInfo(pak);
|
}
|
|
public void SendFairyInvest(int type, int money)//仙玉投资
|
{
|
var pak = new CA540_tagCMGoldInvest();
|
pak.InvestType = (byte)type;
|
pak.InvestGold = (uint)money;
|
GameNetSystem.Instance.SendInfo(pak);
|
}
|
|
private void UpdateRedpoint()//红点
|
{
|
prioritySelectIndex = 0;
|
|
var redpointAble = false;
|
|
int playerLevel = PlayerDatas.Instance.baseData.LV;
|
|
if (fairyInvestLevelLimits.ContainsKey(fairyInvestType) && fairyInvestItems.ContainsKey(fairyInvestType))
|
{
|
|
int investGear = fairyInvestInfos.ContainsKey(fairyInvestType) ? fairyInvestInfos[fairyInvestType].gear : 0;
|
|
var investItems = fairyInvestItems[fairyInvestType];
|
|
var index = 0;
|
foreach (var investItem in investItems.Values)
|
{
|
if (playerLevel >= investItem.levelLimit)
|
{
|
if (investGear != 0)
|
{
|
var gear = fairyInvestSingleInfos[fairyInvestType][investItem.id];
|
if (gear == 0)
|
{
|
redpointAble = true;
|
prioritySelectIndex = index;
|
break;
|
}
|
else
|
{
|
var currentItems = investItem.items.ContainsKey(investGear) ? investItem.items[investGear] : null;
|
var items = investItem.items.ContainsKey(gear) ? investItem.items[gear] : null;
|
if (currentItems[0].count > items[0].count)
|
{
|
redpointAble = true;
|
prioritySelectIndex = index;
|
break;
|
}
|
}
|
}
|
}
|
index++;
|
}
|
|
index = 0;
|
if (!redpointAble && investGear != 0)
|
{
|
foreach (var investItem in investItems.Values)
|
{
|
if (investItem.levelLimit > playerLevel)
|
{
|
prioritySelectIndex = index;
|
return;
|
}
|
index++;
|
}
|
}
|
}
|
|
redpoint.state = redpointAble ? RedPointState.GetReward : RedPointState.None;
|
|
|
}
|
private void RedPointSate()//月卡投资创角前三天红点
|
{
|
int InvestGold = GetInvestGold();
|
if (InvestGold > 0)
|
{
|
return;
|
}
|
if (IsRedpoint)
|
{
|
if (IsFuncOpen())
|
{
|
redpoint.state = RedPointState.Simple;
|
}
|
|
}
|
else
|
{
|
UpdateRedpoint();
|
}
|
}
|
|
private void IsShowRedPointSimple()
|
{
|
int GetDayOfYear = DateTime.Now.DayOfYear;
|
string strKey = "IsOpenFiaryJadeRedPoint" + PlayerDatas.Instance.baseData.PlayerID;
|
int day = LocalSave.GetInt(strKey);
|
if (day != GetDayOfYear)
|
{
|
if (TimeUtility.CreateDays <= redpointDays && redpoint.state == RedPointState.None
|
&& PlayerDatas.Instance.baseData.LV >= redpointLevelLimit)
|
{
|
LocalSave.SetInt(strKey, GetDayOfYear);
|
IsRedpoint = true;
|
RedPointSate();
|
return;
|
}
|
|
}
|
if (!IsFuncOpen())//功能关闭
|
{
|
redpoint.state = RedPointState.None;
|
return;
|
}
|
}
|
|
public void MessageNotification()
|
{
|
var _funcOrder = 0;
|
var gear = GetFairyInvestGear();
|
if (!OpenServerActivityCenter.Instance.IsAnyActivityOpen(out _funcOrder))
|
{
|
SysNotifyMgr.Instance.ShowTip("JadeInvestmentLimit1");//信息提示
|
return;
|
}
|
else if (gear <= 0 && PlayerDatas.Instance.baseData.LV >= fairyInvestLevelLimits.Values.Last())
|
{
|
SysNotifyMgr.Instance.ShowTip("JadeInvestmentLimit2");//信息提示
|
return;
|
}
|
else
|
{
|
bool isOpen = false;
|
if (gear == 4)
|
{
|
var dit = GetInfoSeriors();
|
foreach (int key in dit.Keys)
|
{
|
if (dit[key] != 4)
|
{
|
isOpen = true;
|
}
|
}
|
}
|
if (!isOpen && PlayerDatas.Instance.baseData.LV >= 300)
|
{
|
SysNotifyMgr.Instance.ShowTip("JadeInvestmentLimit3");//信息提示
|
return;
|
}
|
}
|
}
|
|
public int GetFairyInvestType()//获取投资类型
|
{
|
int playerLevel = PlayerDatas.Instance.baseData.LV;
|
|
var selectType = fairyInvestLevelLimits.Keys.First();
|
|
foreach (var type in fairyInvestInfos.Keys)
|
{
|
if (fairyInvestInfos[type].money == 0)
|
{
|
continue;
|
}
|
|
var existUnGotReward = false;
|
|
var investGear = fairyInvestInfos[type].gear;
|
|
if (fairyInvestSingleInfos.ContainsKey(type))
|
{
|
var singleInfos = fairyInvestSingleInfos[type];
|
var investItems = fairyInvestItems[type];
|
foreach (var investItem in investItems.Values)
|
{
|
if (playerLevel >= investItem.levelLimit)
|
{
|
var gotGear = singleInfos[investItem.id];
|
if (gotGear == 0)
|
{
|
existUnGotReward = true;
|
}
|
else
|
{
|
List<Item> currentItems = investItem.items.ContainsKey(investGear) ? investItem.items[investGear] : null;
|
List<Item> items = investItem.items.ContainsKey(gotGear) ? investItem.items[gotGear] : null;
|
if (currentItems[0].count > items[0].count)
|
{
|
existUnGotReward = true;
|
}
|
}
|
}
|
}
|
|
if (existUnGotReward || playerLevel <= fairyInvestLevelLimits[type])
|
{
|
selectType = type;
|
break;
|
}
|
}
|
}
|
|
return selectType;
|
}
|
|
public int GetFairyInvestGear()//获取投资档位
|
{
|
if (fairyInvestInfos.ContainsKey(fairyInvestType))
|
{
|
return fairyInvestInfos[fairyInvestType].gear;
|
}
|
return 0;
|
}
|
|
public int GetInvestGold()//获取投资金额
|
{
|
int InvestGold = 0;
|
int type = fairyInvestType;
|
if (fairyInvestInfos.ContainsKey(type))
|
{
|
InvestGold = fairyInvestInfos[type].money;
|
}
|
return InvestGold;
|
}
|
public Dictionary<int, int> GetInfoSeriors()
|
{
|
Dictionary<int, int> dit = new Dictionary<int, int>();
|
int type = fairyInvestType;
|
if (fairyInvestSingleInfos.ContainsKey(type))
|
{
|
dit = fairyInvestSingleInfos[type];
|
}
|
return dit;
|
}
|
}
|
|
|
|
|