//-------------------------------------------------------- // [Author]: 第二世界 // [ Date ]: Monday, March 19, 2018 //-------------------------------------------------------- using System; using System.Collections.Generic; using Snxxz.UI; //月卡投资 namespace Snxxz.UI { public class MonthlyInvestmentClass { public int ID;//ID public int Type;//类型 public int NeedDay;//需要天数 public int NeedLv;//需要等级 public MonthlyInvestmentModel.MonthlyInvestmentItem monthlyInvestmentItem;//奖励 } [XLua.LuaCallCSharp] public class MonthlyInvestmentModel : Model, IBeforePlayerDataInitialize, IPlayerLoginOk { public Dictionary MonthlyInvestmentDic = new Dictionary(); public Dictionary InfoSeriors = new Dictionary();//奖励领取信息 public event Action MonthlyInvestmentUpdating; private int tagAwardGet=0;//奖励信息 public int Days=0;//当前天数 public int InvestGold = 0;//投资额度 public override void Init() { Assignment(); } public void OnBeforePlayerDataInitialize() { InfoSeriors.Clear(); Days = 0; InvestGold = 0; } public void OnPlayerLoginOk() { } public override void UnInit() { } public void GetInfoSeriors(HA337_tagMCGoldInvestInfo vNetData)//接受信息 { if (vNetData.InvestType == 1) { Days = (int)vNetData.CurDay;//当前天数 InvestGold = (int)vNetData.InvestGold; if (vNetData.InvestRewardList.Length > 1) { InfoSeriors.Clear(); for (int i = 0; i < vNetData.InvestRewardList.Length; i++) { InfoSeriors.Add((int)vNetData.InvestRewardList[i].RewardIndex, (int)vNetData.InvestRewardList[i].RewardValue); } } else { for (int i = 0; i < vNetData.InvestRewardList.Length; i++) { if (InfoSeriors.ContainsKey((int)vNetData.InvestRewardList[i].RewardIndex)) { InfoSeriors[(int)vNetData.InvestRewardList[i].RewardIndex] = (int)vNetData.InvestRewardList[i].RewardValue; } } } } if (MonthlyInvestmentUpdating != null) { MonthlyInvestmentUpdating(); } } public void SendInvestment(int InvestType,int RewardIndex)//领取奖励 { CA541_tagCMGetInvestReward CA541 = new CA541_tagCMGetInvestReward(); CA541.InvestType = (byte)InvestType; CA541.RewardIndex= (byte)RewardIndex; GameNetSystem.Instance.SendInfo(CA541); } public void InvestmentMonthlyInvestment(int InvestType,int InvestGold)//月卡投资 { CA540_tagCMGoldInvest C540 = new CA540_tagCMGoldInvest(); C540.InvestType = (byte)InvestType; C540.InvestGold = (uint)InvestGold; GameNetSystem.Instance.SendInfo(C540); } public bool IsTagGetInfoSeriors(int index) { if (InfoSeriors.ContainsKey(index)) { if (InfoSeriors[index] == 0) { return false; } else { return true; } } else { return true; } } public bool IsTagGet(int _index) { return (tagAwardGet & (1 << _index)) != 0; } public class MonthlyInvestmentItem { private Dictionary> m_AwardDict = new Dictionary>(); public List GetAwardItem(int _job) { List _items = null; m_AwardDict.TryGetValue(_job, out _items); return _items; } public void Add(int _job, AwardItem _item) { List _list = null; if (!m_AwardDict.TryGetValue(_job, out _list)) { _list = new List(); m_AwardDict.Add(_job, _list); } _list.Add(_item); } } public void Assignment() { var investConfig = InvestConfig.GetValues(); foreach (var value in investConfig) { if (value.type == 1 && !MonthlyInvestmentDic.ContainsKey(value.needDay)) { MonthlyInvestmentClass monthlyInvestment = new MonthlyInvestmentClass(); monthlyInvestment.ID = value.id; monthlyInvestment.Type = value.type; monthlyInvestment.NeedDay = value.needDay; monthlyInvestment.NeedLv = value.needLV; MonthlyInvestmentItem _monthyItem = new MonthlyInvestmentItem(); var _jsonData = LitJson.JsonMapper.ToObject(value.award); foreach (string key in _jsonData.Keys) { var _job = int.Parse(key); var _itemArray = LitJson.JsonMapper.ToObject(_jsonData[key].ToJson()); for (int j = 0; j < _itemArray.Length; j++) { _monthyItem.Add(_job, new AwardItem() { item = new Item(_itemArray[j][0], _itemArray[j][1]), isBind = _itemArray[j][2], }); } } monthlyInvestment.monthlyInvestmentItem = _monthyItem; MonthlyInvestmentDic.Add(value.needDay, monthlyInvestment); } } } } }