| using System; | 
| using System.Collections; | 
| using System.Collections.Generic; | 
| using UnityEngine; | 
|   | 
|   | 
| /// <summary> | 
| /// 活动界面-集字  和精彩活动表关联 | 
| /// </summary> | 
| namespace vnxbqy.UI | 
| { | 
|     public class CollectWordsModel : Model, IBeforePlayerDataInitialize, IPlayerLoginOk, IOpenServerActivity | 
|     { | 
|         Operation collectWordsType = Operation.CollectWords; | 
|         int regesitType = 30; | 
|         public bool IsOpen | 
|         { | 
|             get | 
|             { | 
|                 return OperationTimeHepler.Instance.SatisfyOpenCondition(collectWordsType); | 
|             } | 
|         } | 
|   | 
|         public bool IsAdvance | 
|         { | 
|             get | 
|             { | 
|                 return false; | 
|             } | 
|         } | 
|   | 
|         public bool priorityOpen | 
|         { | 
|             get { return redpoint.state == RedPointState.Simple; } | 
|         } | 
|   | 
|   | 
|         public event Action ExChangeInfoUpdate; | 
|         public event Action<int> onStateUpdate; | 
|         //已兑换的记录 编号:已兑换次数 | 
|         public Dictionary<int, int> exchangeDict = new Dictionary<int, int>(); | 
|         public List<int> wordsID = new List<int>(); //活动的所有搜集物品ID | 
|         public byte actNum; //对应界面 | 
|   | 
|         PackModel packModel { get { return ModelCenter.Instance.GetModel<PackModel>(); } } | 
|   | 
|         public override void Init() | 
|         { | 
|             OperationTimeHepler.Instance.operationStartEvent += OperationStartEvent; | 
|             OperationTimeHepler.Instance.operationEndEvent += OperationEndEvent; | 
|             OperationTimeHepler.Instance.dayResetEvent += DayResetEvent; | 
|             OpenServerActivityCenter.Instance.Register(regesitType, this); | 
|   | 
|             OperationTimeHepler.Instance.operationTimeUpdateEvent += operationTimeUpdateEvent; | 
|             packModel.refreshItemCountEvent += RefreshItemCountEvent; | 
|         } | 
|   | 
|         public void OnBeforePlayerDataInitialize() | 
|         { | 
|             exchangeDict.Clear(); | 
|             wordsID.Clear(); | 
|         } | 
|   | 
|         public void OnPlayerLoginOk() | 
|         { | 
|             UpdateRedpoint(); | 
|         } | 
|   | 
|         public override void UnInit() | 
|         { | 
|             OperationTimeHepler.Instance.operationStartEvent -= OperationStartEvent; | 
|             OperationTimeHepler.Instance.operationEndEvent -= OperationEndEvent; | 
|             OperationTimeHepler.Instance.dayResetEvent -= DayResetEvent; | 
|   | 
|             OperationTimeHepler.Instance.operationTimeUpdateEvent -= operationTimeUpdateEvent; | 
|             packModel.refreshItemCountEvent -= RefreshItemCountEvent; | 
|         } | 
|   | 
|         private void DayResetEvent(int resetType) | 
|         { | 
|             OperationBase operationBase; | 
|             if (OperationTimeHepler.Instance.TryGetOperationTime(collectWordsType, out operationBase)) | 
|             { | 
|                 if (resetType == operationBase.resetType) | 
|                 { | 
|                     UpdateRedpoint(); | 
|                 } | 
|             } | 
|         } | 
|   | 
|         private void OperationEndEvent(Operation operationType, int state) | 
|         { | 
|             if (operationType == collectWordsType && state == 0) | 
|             { | 
|                 UpdateRedpoint(); | 
|                 if (onStateUpdate != null) | 
|                 { | 
|                     onStateUpdate(regesitType); | 
|                 } | 
|             } | 
|         } | 
|   | 
|         private void OperationStartEvent(Operation operationType, int state) | 
|         { | 
|             if (operationType == collectWordsType && state == 0) | 
|             { | 
|                 UpdateRedpoint(); | 
|                 if (onStateUpdate != null) | 
|                 { | 
|                     onStateUpdate(regesitType); | 
|                 } | 
|             } | 
|         } | 
|   | 
|         private void operationTimeUpdateEvent(Operation obj) | 
|         { | 
|             if (obj != collectWordsType) | 
|             { | 
|                 return; | 
|             } | 
|             wordsID.Clear(); | 
|             OperationCollectWords operation; | 
|             if (OperationTimeHepler.Instance.TryGetOperation(collectWordsType, out operation)) | 
|             { | 
|   | 
|                 for (int i = 0; i < operation.exchangeWords.Count; i++) | 
|                 { | 
|                     var wordList = operation.exchangeWords[i]; | 
|                     for (int j = 0; j < wordList.NeedItemCount; j++) | 
|                     { | 
|                         int itemID = (int)wordList.NeedItemList[j].ItemID; | 
|                         if (!wordsID.Contains(itemID)) | 
|                             wordsID.Add(itemID); | 
|                     } | 
|                 } | 
|             } | 
|         } | 
|   | 
|         #region 服务端数据 | 
|   | 
|         private void RefreshItemCountEvent(PackType packType, int index, int itemId) | 
|         { | 
|             if (!wordsID.Contains(itemId)) return; | 
|             UpdateRedpoint(); | 
|             if (ExChangeInfoUpdate != null) | 
|             { | 
|                 ExChangeInfoUpdate(); | 
|             } | 
|         } | 
|   | 
|         public void UpdateExchangeInfo(HAA41_tagMCActCollectWordsPlayerInfo package) | 
|         { | 
|             OperationCollectWords operation; | 
|             if (OperationTimeHepler.Instance.TryGetOperation(collectWordsType, out operation)) | 
|             { | 
|                 if (operation.ActNum != package.ActNum) | 
|                 { | 
|                     return; | 
|                 } | 
|                 actNum = package.ActNum; | 
|                 for (int i = 0; i < package.ExchangeCount; i++) | 
|                 { | 
|                     //已兑换次数 | 
|                     exchangeDict[package.ExchangeInfoList[i].ExchangeNum] = package.ExchangeInfoList[i].ExchangeCount; | 
|                 } | 
|                 UpdateRedpoint(); | 
|                 if (ExChangeInfoUpdate != null) | 
|                 { | 
|                     ExChangeInfoUpdate(); | 
|                 } | 
|             } | 
|         } | 
|   | 
|         //文字兑换奖励 | 
|         public void SendExchangeWord(byte exchangeNum) | 
|         { | 
|             var sendInfo = new CAA09_tagCMActCollectWordsExchange(); | 
|             sendInfo.ActNum = actNum; | 
|             sendInfo.ExchangeNum = exchangeNum; | 
|             GameNetSystem.Instance.SendInfo(sendInfo); | 
|   | 
|         } | 
|   | 
|         #endregion | 
|   | 
|         #region 红点 | 
|         public Redpoint redpoint = new Redpoint(MainRedDot.REDPOINT_OPENSERVER, 20930); | 
|         public int jumpIndex = 0; | 
|         public void UpdateRedpoint() | 
|         { | 
|             redpoint.state = RedPointState.None; | 
|             if (!IsOpen) | 
|             { | 
|                 return; | 
|             } | 
|             if (!DayRemind.Instance.GetDayRemind(DayRemind.WORD_YY_REDPOINT)) | 
|             { | 
|                 redpoint.state = RedPointState.Simple; | 
|                 return; | 
|             } | 
|   | 
|             jumpIndex = 0; | 
|             OperationCollectWords operation; | 
|             if (OperationTimeHepler.Instance.TryGetOperation(collectWordsType, out operation)) | 
|             { | 
|                 for (int i = 0; i < operation.exchangeWords.Count; i++) | 
|                 { | 
|                     var wordList = operation.exchangeWords[i]; | 
|                     if (exchangeDict[wordList.ExchangeNum] >= wordList.ExchangeCountMax) | 
|                     { | 
|                         continue; | 
|                     } | 
|                     var isEnough = true; | 
|                     for (int j = 0; j < wordList.NeedItemCount; j++) | 
|                     { | 
|                         int itemID = (int)wordList.NeedItemList[j].ItemID; | 
|                         var cnt = packModel.GetItemCountByID(PackType.Item, itemID); | 
|                         if (cnt < wordList.NeedItemList[j].ItemCount) | 
|                         { | 
|                             isEnough = false; | 
|                             break; | 
|                         } | 
|                     } | 
|   | 
|                     if (isEnough) | 
|                     { | 
|                         redpoint.state = RedPointState.Simple; | 
|                         jumpIndex = i; | 
|                         return; | 
|                     } | 
|                 } | 
|             } | 
|         } | 
|         #endregion | 
|     } | 
| } |