| //--------------------------------------------------------  | 
| //    [Author]:           第二世界  | 
| //    [  Date ]:           Monday, January 21, 2019  | 
| //--------------------------------------------------------  | 
| using System;  | 
| using System.Collections.Generic;  | 
|   | 
| using vnxbqy.UI;  | 
| using System.Linq;  | 
|   | 
|   | 
|   | 
| //春节活动巡礼  | 
| public class SpringFestivalModel : Model, IBeforePlayerDataInitialize, IPlayerLoginOk  | 
| {  | 
|     public Dictionary<int, WeekPartyDayInfoClass> SpringFestivalInfoDic = new Dictionary<int, WeekPartyDayInfoClass>();//每天领取奖励信息  | 
|     public event Action SpringFestivalRewardUpdate;//领奖记录变化  | 
|     public Dictionary<int, WeekPartyDayClass> SpringFestivalDayDic = new Dictionary<int, WeekPartyDayClass>();//每天的奖励信息  | 
|     public Dictionary<int, WeekPartyActionClass> SpringFestivalDic = new Dictionary<int, WeekPartyActionClass>();//活动模板总信息  | 
|     public Dictionary<int, Redpoint> RedPointDic = new Dictionary<int, Redpoint>();//红点  | 
|     private const int Redpoint_key1 = 21402;//周狂欢红点  | 
|     public Redpoint redPointStre1 = new Redpoint(214, Redpoint_key1);  | 
|     public int LimitLV = 0;//限制等级  | 
|     private int _JumpIndex = -1;//跳转选中值  | 
|     public int JumpIndex  | 
|     {  | 
|         get { return _JumpIndex; }  | 
|         set { _JumpIndex = value; }  | 
|     }  | 
|     private int _SelectedNow = 0;  | 
|     public int SelectedNow//选中天  | 
|     {  | 
|         get { return _SelectedNow; }  | 
|         set { _SelectedNow = value; }  | 
|     }  | 
|   | 
|     private int _DayNow = 0;  | 
|     public int DayNow//当前天  | 
|     {  | 
|         get { return _DayNow; }  | 
|         set { _DayNow = value; }  | 
|     }  | 
|     public override void Init()  | 
|     {  | 
|   | 
|     }  | 
|   | 
|     public void OnBeforePlayerDataInitialize()  | 
|     {  | 
|         SpringFestivalInfoDic.Clear();  | 
|     }  | 
|   | 
|     public void OnPlayerLoginOk()  | 
|     {  | 
|         GetDayNow();  | 
|         OperationTimeHepler.Instance.operationStartEvent -= OperationStartEvent;  | 
|         OperationTimeHepler.Instance.dayResetEvent -= DayResetEvent;  | 
|         OperationTimeHepler.Instance.operationStartEvent += OperationStartEvent;  | 
|         OperationTimeHepler.Instance.dayResetEvent += DayResetEvent;  | 
|     }  | 
|   | 
|   | 
|     public override void UnInit()  | 
|     {  | 
|   | 
|     }  | 
|     private void DayResetEvent(int obj)  | 
|     {  | 
|         if (obj == (int)Operation.OpenServiceAchievement)  | 
|         {  | 
|             GetDayNow();  | 
|             SetRedPoint();  | 
|         }  | 
|     }  | 
|   | 
|     private void OperationStartEvent(Operation arg1, int arg2)  | 
|     {  | 
|         if (arg1 == Operation.OpenServiceAchievement)  | 
|         {  | 
|             GetDayNow();  | 
|             SetRedPoint();  | 
|         }  | 
|     }  | 
|   | 
|     public void SpringFestivalInfo(HAA21_tagMCFeastWeekPartyPlayerInfo info)//每天领奖信息  | 
|     {  | 
|         for (int i = 0; i < info.Count; i++)  | 
|         {  | 
|             var DayInfo = info.DayInfoList[i];  | 
|             WeekPartyDayInfoClass WeekPartyDayInfo = new WeekPartyDayInfoClass();  | 
|             WeekPartyDayInfo.DayIndex = (int)DayInfo.DayIndex;  | 
|             WeekPartyDayInfo.Point = (int)DayInfo.Point;  | 
|             WeekPartyDayInfo.AwardRecord = (int)DayInfo.AwardRecord;  | 
|   | 
|             if (SpringFestivalInfoDic.ContainsKey((int)DayInfo.DayIndex))  | 
|             {  | 
|                 var dit = SpringFestivalInfoDic[(int)DayInfo.DayIndex];  | 
|                 dit.DayIndex = (int)DayInfo.DayIndex;  | 
|                 dit.Point = (int)DayInfo.Point;  | 
|                 dit.AwardRecord = (int)DayInfo.AwardRecord;  | 
|                 for (int j = 0; j < DayInfo.ACount; j++)  | 
|                 {  | 
|                     var taskList = DayInfo.TaskList[j];  | 
|                     int Index = dit.ActionType.FindIndex(s => s.TemplateID == taskList.TemplateID);  | 
|                     if (Index != -1)  | 
|                     {  | 
|                         dit.ActionType[Index].CurTimes = (int)taskList.CurTimes;  | 
|                         dit.ActionType[Index].GotTimes = (int)taskList.GotTimes;  | 
|                     }  | 
|                     else  | 
|                     {  | 
|                         ActionTypeClass ActionType = new ActionTypeClass();  | 
|                         ActionType.TemplateID = taskList.TemplateID;  | 
|                         ActionType.CurTimes = (int)taskList.CurTimes;  | 
|                         ActionType.GotTimes = (int)taskList.GotTimes;  | 
|                         dit.ActionType.Add(ActionType);  | 
|                     }  | 
|                 }  | 
|                 SpringFestivalInfoDic[(int)DayInfo.DayIndex] = dit;  | 
|             }  | 
|             else  | 
|             {  | 
|                 WeekPartyDayInfo.ActionType = new List<ActionTypeClass>();  | 
|                 for (int k = 0; k < DayInfo.ACount; k++)  | 
|                 {  | 
|                     var Task = DayInfo.TaskList[k];  | 
|                     ActionTypeClass ActionType = new ActionTypeClass();  | 
|                     ActionType.TemplateID = Task.TemplateID;  | 
|                     ActionType.CurTimes = (int)Task.CurTimes;  | 
|                     ActionType.GotTimes = (int)Task.GotTimes;  | 
|                     WeekPartyDayInfo.ActionType.Add(ActionType);  | 
|                 }  | 
|                 SpringFestivalInfoDic.Add((int)DayInfo.DayIndex, WeekPartyDayInfo);  | 
|             }  | 
|         }  | 
|         GetDayNow();  | 
|         SetRedPoint();  | 
|         if (SpringFestivalRewardUpdate != null)  | 
|         {  | 
|             SpringFestivalRewardUpdate();  | 
|         }  | 
|     }  | 
|   | 
|     public void SpringFestivalTemplate(HAA20_tagMCFeastWeekPartyInfo info)//每天模板信息  | 
|     {  | 
|         LimitLV = info.LimitLV;  | 
|         for (int i = 0; i < info.DayCnt; i++)  | 
|         {  | 
|             int Index = i;  | 
|             var DayInfo = info.DayInfoList[i];  | 
|             WeekPartyDayClass WeekPartyDay = new WeekPartyDayClass();  | 
|             WeekPartyDay.TemplateList = new int[DayInfo.ActCnt];  | 
|             for (int k = 0; k < DayInfo.ActCnt; k++)  | 
|             {  | 
|                 WeekPartyDay.TemplateList[k] = DayInfo.TemplateList[k];  | 
|             }  | 
|             WeekPartyDay.WeekPartyItem = new WeekPartyItemClass[DayInfo.PCount];  | 
|             for (int p = 0; p < DayInfo.PCount; p++)  | 
|             {  | 
|                 WeekPartyItemClass WeekPartyItem = new WeekPartyItemClass();  | 
|                 var Item = DayInfo.PItemInfo[p];  | 
|                 WeekPartyItem.NeedPoint = Item.NeedPoint;  | 
|                 WeekPartyItem.ItemID = (int)Item.ItemID;  | 
|                 WeekPartyItem.ItemCnt = (int)Item.ItemCnt;  | 
|                 WeekPartyItem.IsBind = (int)Item.IsBind;  | 
|                 WeekPartyDay.WeekPartyItem[p] = WeekPartyItem;  | 
|             }  | 
|             if (SpringFestivalDayDic.ContainsKey(Index))  | 
|             {  | 
|                 SpringFestivalDayDic[Index] = WeekPartyDay;  | 
|             }  | 
|             else  | 
|             {  | 
|                 SpringFestivalDayDic.Add(Index, WeekPartyDay);  | 
|             }  | 
|         }// 每天模板  | 
|         for (int i = 0; i < info.TCount; i++)  | 
|         {  | 
|             var ActionInfo = info.ActionInfo[i];  | 
|             WeekPartyActionClass WeekPartyAction = new WeekPartyActionClass();  | 
|             WeekPartyAction.TemplateID = (int)ActionInfo.TemplateID;  | 
|             WeekPartyAction.ActionType = (int)ActionInfo.ActionType;  | 
|             WeekPartyAction.TotalTimes = (int)ActionInfo.TotalTimes;  | 
|             WeekPartyAction.SingleTimes = (int)ActionInfo.SingleTimes;  | 
|             WeekPartyAction.Point = (int)ActionInfo.Point;  | 
|             WeekPartyAction.WeekPartyItem = new WeekPartyItemClass[ActionInfo.Count];  | 
|             for (int z = 0; z < ActionInfo.Count; z++)  | 
|             {  | 
|                 var item = ActionInfo.ItemInfo[z];  | 
|                 WeekPartyItemClass WeekPartyItem = new WeekPartyItemClass();  | 
|                 WeekPartyItem.ItemID = (int)item.ItemID;  | 
|                 WeekPartyItem.ItemCnt = (int)item.ItemCnt;  | 
|                 WeekPartyItem.IsBind = item.IsBind;  | 
|                 WeekPartyItem.NeedPoint = 0;  | 
|                 WeekPartyAction.WeekPartyItem[z] = WeekPartyItem;  | 
|             }  | 
|             if (SpringFestivalDic.ContainsKey((int)ActionInfo.TemplateID))  | 
|             {  | 
|                 SpringFestivalDic[(int)ActionInfo.TemplateID] = WeekPartyAction;  | 
|             }  | 
|             else  | 
|             {  | 
|                 SpringFestivalDic.Add((int)ActionInfo.TemplateID, WeekPartyAction);  | 
|             }  | 
|         }// 活动模板信息  | 
|         SetRedPoint();  | 
|     }  | 
|   | 
|     public int GetRewardNumber(int Day, int ID)//获取领奖次数  | 
|     {  | 
|         int Num = 0;  | 
|         if (SpringFestivalInfoDic.ContainsKey(Day))  | 
|         {  | 
|             var SpringFestivalDay = SpringFestivalInfoDic[Day];  | 
|   | 
|             for (int i = 0; i < SpringFestivalDay.ActionType.Count; i++)  | 
|             {  | 
|                 var ActionType = SpringFestivalDay.ActionType[i];  | 
|                 if (ID == ActionType.TemplateID)  | 
|                 {  | 
|                     Num = ActionType.GotTimes;  | 
|                 }  | 
|             }  | 
|         }  | 
|         return Num;  | 
|   | 
|     }  | 
|     public int GetCarryOutNum(int Day, int ID)//获取已完成次数  | 
|     {  | 
|         int Num = 0;  | 
|         if (SpringFestivalInfoDic.ContainsKey(Day))  | 
|         {  | 
|             var SpringFestival = SpringFestivalInfoDic[Day];  | 
|   | 
|             for (int i = 0; i < SpringFestival.ActionType.Count; i++)  | 
|             {  | 
|                 var ActionType = SpringFestival.ActionType[i];  | 
|                 if (ID == ActionType.TemplateID)  | 
|                 {  | 
|                     Num = ActionType.CurTimes;  | 
|                 }  | 
|             }  | 
|         }  | 
|         return Num;  | 
|     }  | 
|     public int GetPoint(int day)//获取某一天的积分  | 
|     {  | 
|         int Point = 0;  | 
|         if (SpringFestivalInfoDic.ContainsKey(day))  | 
|         {  | 
|             Point = SpringFestivalInfoDic[day].Point;  | 
|         }  | 
|         return Point;  | 
|     }  | 
|     public void SendGetSpringFestival(int day, int temdayplateID)//领取春节活动奖励  | 
|     {  | 
|         CA504_tagCMPlayerGetReward getReward = new CA504_tagCMPlayerGetReward();  | 
|         getReward.RewardType = (byte)GotServerRewardType.Def_RewardType_FeastWeekPartyAct;  | 
|         getReward.DataEx = (uint)day;  | 
|         string StrID = temdayplateID.ToString();  | 
|         getReward.DataExStrLen = (byte)StrID.Length;  | 
|         getReward.DataExStr = StrID;  | 
|         GameNetSystem.Instance.SendInfo(getReward);  | 
|     }  | 
|     public void SendGetSpringFestivalPoint(int day, int point)//领取春节积分奖励  | 
|     {  | 
|         CA504_tagCMPlayerGetReward getReward = new CA504_tagCMPlayerGetReward();  | 
|         getReward.RewardType = (byte)GotServerRewardType.Def_RewardType_FeastWeekPartyPoint;  | 
|         getReward.DataEx = (uint)day;  | 
|         string StrID = point.ToString();  | 
|         getReward.DataExStrLen = (byte)StrID.Length;  | 
|         getReward.DataExStr = StrID;  | 
|         GameNetSystem.Instance.SendInfo(getReward);  | 
|     }  | 
|     public bool IsDayReward(int day, int index)//是否领取奖励  | 
|     {  | 
|         bool _bool = false;  | 
|         int AwardRecord = 0;  | 
|         foreach (var key in SpringFestivalInfoDic.Keys)  | 
|         {  | 
|             if (key == day)  | 
|             {  | 
|                 AwardRecord = SpringFestivalInfoDic[key].AwardRecord;  | 
|             }  | 
|         }  | 
|         _bool = MathUtility.GetBitValue((uint)AwardRecord, (ushort)index);  | 
|         return _bool;  | 
|     }  | 
|     private void SetRedPoint()//红点设置  | 
|     {  | 
|         SetRedPointId();  | 
|         foreach (var key in RedPointDic.Keys)  | 
|         {  | 
|             RedPointDic[key].state = RedPointState.None;  | 
|         }  | 
|         foreach (var key in RedPointDic.Keys)  | 
|         {  | 
|             RedPointDic[key].state = SetRedPointState(key);  | 
|         }  | 
|     }  | 
|     private void SetRedPointId()//设置红点ID  | 
|     {  | 
|         if (RedPointDic.Count >= 7)  | 
|         {  | 
|             return;  | 
|         }  | 
|         RedPointDic.Clear();  | 
|         foreach (var key in SpringFestivalInfoDic.Keys)  | 
|         {  | 
|             int RedPoint = Redpoint_key1 * 10 + key;  | 
|             if (!RedPointDic.ContainsKey(key))  | 
|             {  | 
|                 Redpoint redPointMountStare = new Redpoint(Redpoint_key1, RedPoint);  | 
|                 RedPointDic.Add(key, redPointMountStare);  | 
|             }  | 
|         }  | 
|   | 
|     }  | 
|     private RedPointState SetRedPointState(int day)//红点状态设置  | 
|     {  | 
|         if (!SpringFestivalDayDic.ContainsKey(day) || !SpringFestivalInfoDic.ContainsKey(day) || day > DayNow)  | 
|         {  | 
|             return RedPointState.None;  | 
|         }  | 
|         WeekPartyDayClass WeekPartyDay = new WeekPartyDayClass();  | 
|         int point = SpringFestivalInfoDic[day].Point;  | 
|         foreach (var key in SpringFestivalDayDic.Keys)  | 
|         {  | 
|             if (key == day)  | 
|             {  | 
|                 WeekPartyDay = SpringFestivalDayDic[key];  | 
|             }  | 
|         }  | 
|         for (int i = 0; i < WeekPartyDay.WeekPartyItem.Length; i++)//积分奖励  | 
|         {  | 
|             var item = WeekPartyDay.WeekPartyItem[i];  | 
|             int type = i;  | 
|             bool IsBool = IsDayReward(day, type);  | 
|             if (point >= item.NeedPoint && !IsBool)  | 
|             {  | 
|                 return RedPointState.GetReward;  | 
|             }  | 
|         }  | 
|         for (int i = 0; i < WeekPartyDay.TemplateList.Length; i++)  | 
|         {  | 
|             var TemplateID = WeekPartyDay.TemplateList[i];  | 
|             if (SpringFestivalDic.ContainsKey(TemplateID))  | 
|             {  | 
|                 var WeekPartyAction = SpringFestivalDic[TemplateID];  | 
|                 int number = WeekPartyAction.TotalTimes / WeekPartyAction.SingleTimes;  | 
|                 int rewardNum = GetRewardNumber(day, TemplateID);//已领奖次数  | 
|                 int carryOutNum = GetCarryOutNum(day, TemplateID);//已完成次数  | 
|                 int TaypeNumber = 0;  | 
|                 if (carryOutNum - rewardNum > 0)  | 
|                 {  | 
|                     TaypeNumber = (carryOutNum - rewardNum) / WeekPartyAction.SingleTimes;  | 
|                 }  | 
|                 if (TaypeNumber > 0 && rewardNum < number)  | 
|                 {  | 
|                     return RedPointState.GetReward;  | 
|                 }  | 
|             }  | 
|         }  | 
|         return RedPointState.None;  | 
|     }  | 
|   | 
|     public void GetDayNow()  | 
|     {  | 
|         OperationBase operationBase;  | 
|         if (OperationTimeHepler.Instance.TryGetOperationTime(Operation.SpringFestival, out operationBase))  | 
|         {  | 
|             int inday = (operationBase as EventDaysTime).GetInDayNow();  | 
|             if (SpringFestivalInfoDic.Count <= 0 && inday <= 0)  | 
|             {  | 
|                 _DayNow = 0;  | 
|             }  | 
|             else if (inday >= 0 && SpringFestivalInfoDic.Count > 0 && inday < SpringFestivalInfoDic.Count)  | 
|             {  | 
|                 _DayNow = inday;  | 
|             }  | 
|             else if (SpringFestivalInfoDic.Count > 0 && inday >= SpringFestivalInfoDic.Count)  | 
|             {  | 
|                 _DayNow = SpringFestivalInfoDic.Count - 1;  | 
|             }  | 
|   | 
|         }  | 
|     }  | 
|   | 
|     public bool IsOpenFeatures()  | 
|     {  | 
|         bool Isbool = false;  | 
|         Isbool = (OperationTimeHepler.Instance.SatisfyOpenCondition(Operation.SpringFestival)  | 
|             || OperationTimeHepler.Instance.SatisfyAdvanceCondition(Operation.SpringFestival));  | 
|         return Isbool;  | 
|     }  | 
|     public bool IsJumpOpen()//是否都能执行跳转  | 
|     {  | 
|         bool Isbool = IsOpenFeatures();  | 
|         if (!Isbool)  | 
|         {  | 
|             SysNotifyMgr.Instance.ShowTip("OutofActivityTime");  | 
|         }  | 
|         return Isbool;  | 
|     }  | 
| }  | 
|   | 
|   | 
|   | 
|   | 
|   |