| using System;  | 
| using System.Collections;  | 
| using System.Collections.Generic;  | 
|   | 
| using UnityEngine;  | 
| namespace vnxbqy.UI  | 
| {  | 
|       | 
|     public class OSGiftModel : Model, IPlayerLoginOk, IBeforePlayerDataInitialize, IOpenServerActivity  | 
|     {  | 
|         VipModel vipModel  | 
|         {  | 
|             get { return ModelCenter.Instance.GetModel<VipModel>(); }  | 
|         }  | 
|   | 
|         PetModel petModel  | 
|         {  | 
|             get { return ModelCenter.Instance.GetModel<PetModel>(); }  | 
|         }  | 
|   | 
|         public override void Init()  | 
|         {  | 
|             ParseConfig();  | 
|             vipModel.rechargeCountEvent += RechargeCountEvent;  | 
|             FuncOpen.Instance.OnFuncStateChangeEvent += OnFuncStateChangeEvent;  | 
|             OpenServerActivityCenter.Instance.Register(6, this);  | 
|         }  | 
|   | 
|         public override void UnInit()  | 
|         {  | 
|             vipModel.rechargeCountEvent -= RechargeCountEvent;  | 
|             FuncOpen.Instance.OnFuncStateChangeEvent -= OnFuncStateChangeEvent;  | 
|         }  | 
|   | 
|         public void OnBeforePlayerDataInitialize()  | 
|         {  | 
|         }  | 
|   | 
|         public void OnPlayerLoginOk()  | 
|         {  | 
|             if (onStateUpdate != null)  | 
|             {  | 
|                 onStateUpdate(6);  | 
|             }  | 
|             UpdateRedpoint();  | 
|         }  | 
|   | 
|         public event Action<int> onStateUpdate;  | 
|         public event Action onSelectUpdate;  | 
|   | 
|         public bool IsOpen  | 
|         {  | 
|             get  | 
|             {  | 
|                 return ExistAnyGift();  | 
|             }  | 
|         }  | 
|   | 
|         public bool priorityOpen  | 
|         {  | 
|             get  | 
|             {  | 
|                 for (int i = 0; i < redpoints.Count; i++)  | 
|                 {  | 
|                     if (redpoints[i].state == RedPointState.Simple)  | 
|                     {  | 
|                         return true;  | 
|                     }  | 
|                 }  | 
|                 return false;  | 
|             }  | 
|         }  | 
|   | 
|         public bool IsAdvance  | 
|         {  | 
|             get  | 
|             {  | 
|                 return false;  | 
|             }  | 
|         }  | 
|   | 
|         int m_SelectIndex = 0;  | 
|         public int selectIndex  | 
|         {  | 
|             get { return m_SelectIndex; }  | 
|             set  | 
|             {  | 
|                 if (value != m_SelectIndex)  | 
|                 {  | 
|                     m_SelectIndex = value;  | 
|                     if (onSelectUpdate != null)  | 
|                     {  | 
|                         onSelectUpdate();  | 
|                     }  | 
|                 }  | 
|                 m_SelectIndex = value;  | 
|             }  | 
|         }  | 
|   | 
|         public int jumpGiftId { get; set; }  | 
|   | 
|         public List<SuperValueGift> gifts { get; private set; }  | 
|         public List<int> alreadyOpens { get; private set; }  | 
|         public SkillActivePoint skillActivePoint { get; private set; }  | 
|         void ParseConfig()  | 
|         {  | 
|             gifts = new List<SuperValueGift>();  | 
|             alreadyOpens = new List<int>();  | 
|             var config = FuncConfigConfig.Get("SuperGiftTimeList");  | 
|             var array = LitJson.JsonMapper.ToObject<int[][]>(config.Numerical1);  | 
|             for (int i = 0; i < array.Length; i++)  | 
|             {  | 
|                 gifts.Add(new SuperValueGift()  | 
|                 {  | 
|                     payType = array[i][0],  | 
|                     functionId = array[i][1],  | 
|                 });  | 
|             }  | 
|   | 
|             for (int i = 0; i < gifts.Count; i++)  | 
|             {  | 
|                 redpoints.Add(new Redpoint(MainRedDot.REDPOINT_OPENSERVER, 20906 * 100 + i));  | 
|             }  | 
|   | 
|             config = FuncConfigConfig.Get("ImmortalDomainActivePoint");  | 
|             var skillArray = LitJson.JsonMapper.ToObject<int[]>(config.Numerical4);  | 
|             skillActivePoint = new SkillActivePoint()  | 
|             {  | 
|                 skillId = skillArray[0],  | 
|                 levelArea = skillArray[1],  | 
|                 upperPoint = skillArray[2],  | 
|                 limit = skillArray[3],  | 
|             };  | 
|         }  | 
|   | 
|         private void RechargeCountEvent(int id)  | 
|         {  | 
|             UpdateRedpoint();  | 
|         }  | 
|   | 
|         private void OnFuncStateChangeEvent(int id)  | 
|         {  | 
|             foreach (var gift in gifts)  | 
|             {  | 
|                 if (gift.functionId == id)  | 
|                 {  | 
|                     if(onStateUpdate != null)  | 
|                     {  | 
|                         onStateUpdate(6);  | 
|                     }  | 
|                     UpdateRedpoint();  | 
|                     break;  | 
|                 }  | 
|             }  | 
|         }  | 
|   | 
|         public bool ExistAnyGift()  | 
|         {  | 
|             for (int i = 0; i < gifts.Count; i++)  | 
|             {  | 
|                 if (!IsGiftExist(gifts[i].payType))  | 
|                 {  | 
|                     continue;  | 
|                 }  | 
|                 return true;  | 
|             }  | 
|             return false;  | 
|         }  | 
|   | 
|         public bool IsGiftExist(int payType)  | 
|         {  | 
|             if (IsGiftAlreadyBuy(payType))  | 
|             {  | 
|                 return false;  | 
|             }  | 
|             var gift = gifts.Find((x) =>  | 
|             {  | 
|                 return x.payType == payType;  | 
|             });  | 
|             if (!gift.Equals(default(SuperValueGift)))  | 
|             {  | 
|                 return FuncOpen.Instance.IsFuncOpen(gift.functionId);  | 
|             }  | 
|             return false;  | 
|         }  | 
|   | 
|         public bool IsGiftAlreadyBuy(int payType)  | 
|         {  | 
|             var rechargeId = GetRechargeId(payType);  | 
|             if (rechargeId != 0)  | 
|             {  | 
|                 VipModel.RechargeCount rechargeCount;  | 
|                 if (vipModel.TryGetRechargeCount(rechargeId, out rechargeCount))  | 
|                 {  | 
|                     var rechargeConfig = CTGConfig.Get(rechargeId);  | 
|                     return rechargeCount.totalCount >= rechargeConfig.TotalBuyCount;  | 
|                 }  | 
|             }  | 
|             return false;  | 
|         }  | 
|   | 
|         public void DisplayErrorRemind(int payType)  | 
|         {  | 
|             var gift = gifts.Find((x) =>  | 
|             {  | 
|                 return x.payType == payType;  | 
|             });  | 
|             if (!gift.Equals(default(SuperValueGift)))  | 
|             {  | 
|                 FuncOpen.Instance.ProcessorFuncErrorTip(gift.functionId);  | 
|             }  | 
|         }  | 
|   | 
|         public int GetRechargeId(int payType)  | 
|         {  | 
|             var list = vipModel.GetCTGConfigs(VersionConfig.Get().appId);  | 
|             if (list != null)  | 
|             {  | 
|                 for (int i = 0; i < list.Count; i++)  | 
|                 {  | 
|                     var config = CTGConfig.Get(list[i]);  | 
|                     if (config != null && config.PayType == payType)  | 
|                     {  | 
|                         return config.RecordID;  | 
|                     }  | 
|                 }  | 
|             }  | 
|             return 0;  | 
|         }  | 
|   | 
|         public void SetAreadyOpens()  | 
|         {  | 
|             alreadyOpens.Clear();  | 
|             for (int i = 0; i < gifts.Count; i++)  | 
|             {  | 
|                 if (IsGiftExist(gifts[i].payType))  | 
|                 {  | 
|                     alreadyOpens.Add(i);  | 
|                 }  | 
|             }  | 
|         }  | 
|   | 
|         public int GetDefaultSelect()  | 
|         {  | 
|             for (int i = 0; i < alreadyOpens.Count; i++)  | 
|             {  | 
|                 if (gifts[alreadyOpens[i]].payType == jumpGiftId)  | 
|                 {  | 
|                     jumpGiftId = 0;  | 
|                     return alreadyOpens[i];  | 
|                 }  | 
|             }  | 
|             jumpGiftId = 0;  | 
|             for (int i = 0; i < alreadyOpens.Count; i++)  | 
|             {  | 
|                 if (redpoints[alreadyOpens[i]].state == RedPointState.Simple)  | 
|                 {  | 
|                     return alreadyOpens[i];  | 
|                 }  | 
|             }  | 
|             return alreadyOpens[0];  | 
|         }  | 
|   | 
|         bool GetDayRemind(int index)  | 
|         {  | 
|             return LocalSave.GetInt(StringUtility.Contact("OSGift_", index, "_",  | 
|                 PlayerDatas.Instance.baseData.PlayerID), 0) == TimeUtility.Day;  | 
|         }  | 
|   | 
|         public void SetDayRemind(int index)  | 
|         {  | 
|             if (redpoints[index].state == RedPointState.Simple)  | 
|             {  | 
|                 LocalSave.SetInt(StringUtility.Contact("OSGift_", index, "_",  | 
|                        PlayerDatas.Instance.baseData.PlayerID), TimeUtility.Day);  | 
|                 UpdateRedpoint();  | 
|             }  | 
|         }  | 
|   | 
|         public void GetPetInfo(out int petId, out int level)  | 
|         {  | 
|             petId = 0;  | 
|             level = petModel.GetSkillUnlockLevel(skillActivePoint.skillId);  | 
|             petModel.TryGetPetId(skillActivePoint.skillId, out petId);  | 
|         }  | 
|   | 
|         public int GetSkillActivePoint(int level)  | 
|         {  | 
|             var totalPoint = 0;  | 
|   | 
|             var step = level / skillActivePoint.levelArea;  | 
|             var maxLevel = step * skillActivePoint.levelArea;  | 
|             for (int i = 0; i < step; i++)  | 
|             {  | 
|                 var levels = i == 0 ? (skillActivePoint.levelArea - 1) : skillActivePoint.levelArea;  | 
|                 var point = Mathf.Min(skillActivePoint.limit, (i + 1) * skillActivePoint.upperPoint);  | 
|                 totalPoint += point * levels;  | 
|             }  | 
|   | 
|             {  | 
|                 var point = Mathf.Min(skillActivePoint.limit, (step + 1) * skillActivePoint.upperPoint);  | 
|                 var levels = level - maxLevel;  | 
|                 if (maxLevel == 0)  | 
|                 {  | 
|                     levels -= 1;  | 
|                 }  | 
|                 totalPoint += Mathf.Max(0, levels) * point;  | 
|             }  | 
|   | 
|             return totalPoint;  | 
|         }  | 
|   | 
|         List<Redpoint> redpoints = new List<Redpoint>();  | 
|   | 
|         void UpdateRedpoint()  | 
|         {  | 
|             for (int i = 0; i < redpoints.Count; i++)  | 
|             {  | 
|                 redpoints[i].state = RedPointState.None;  | 
|                 if (IsGiftExist(gifts[i].payType) && !IsGiftAlreadyBuy(gifts[i].payType)  | 
|                     && !GetDayRemind(i))  | 
|                 {  | 
|                     redpoints[i].state = RedPointState.Simple;  | 
|                 }  | 
|             }  | 
|         }  | 
|   | 
|         public struct SuperValueGift  | 
|         {  | 
|             public int payType;  | 
|             public int functionId;  | 
|         }  | 
|   | 
|         public struct SkillActivePoint  | 
|         {  | 
|             public int skillId;  | 
|             public int levelArea;  | 
|             public int upperPoint;  | 
|             public int limit;  | 
|         }  | 
|     }  | 
| }  | 
|   |