| using System; | 
| using System.Collections.Generic; | 
|   | 
|   | 
| //自选礼包的活动 | 
| public class CustomizedGiftModel  : GameSystemManager<CustomizedGiftModel>, IOpenServerActivity | 
| { | 
|     public event Action<int> onStateUpdate; | 
|     public Redpoint enRedPoint = new Redpoint(MainRedDot.CustomizedGiftRedpoint); | 
|     public const int redPointID = MainRedDot.CustomizedGiftRedpoint * 10 + 2; | 
|     public Redpoint redPoint = new Redpoint(MainRedDot.CustomizedGiftRedpoint, redPointID); //可能挂多个父红点 | 
|   | 
|     private int GiftAwardRecord; //领取状态 | 
|   | 
|     public const int activityType = (int)OpenServerActivityCenter.ActivityType.AT_Activity2; | 
|     public const int activityID = (int)NewDayActivityID.CustomizedGiftWin; | 
|     public static OperationType operaType = OperationType.default35; | 
|   | 
|     public int actNum; //对应界面 | 
|     public event Action UpdateRechargeGiftActEvent; | 
|   | 
|   | 
|     public override void Init() | 
|     { | 
|         OperationTimeHepler.Instance.operationStartEvent += OperationStartEvent; | 
|         OperationTimeHepler.Instance.operationEndEvent += OperationEndEvent; | 
|         OperationTimeHepler.Instance.operationAdvanceEvent += OperationAdvanceEvent; | 
|         OpenServerActivityCenter.Instance.Register(activityID, this, activityType); | 
|   | 
|     } | 
|   | 
|   | 
|   | 
|   | 
|     public bool IsOpen | 
|     { | 
|         get | 
|         { | 
|             return OperationTimeHepler.Instance.SatisfyOpenCondition(operaType); | 
|         } | 
|     } | 
|   | 
|     public bool priorityOpen | 
|     { | 
|         get | 
|         { | 
|             return redPoint.state == RedPointState.Simple; | 
|         } | 
|     } | 
|   | 
|     public bool IsAdvance | 
|     { | 
|         get | 
|         { | 
|             return OperationTimeHepler.Instance.SatisfyAdvanceCondition(operaType); | 
|         } | 
|     } | 
|   | 
|     private void OperationEndEvent(OperationType type, int state) | 
|     { | 
|         if (type == operaType && state == 0) | 
|         { | 
|             if (onStateUpdate != null) | 
|             { | 
|                 onStateUpdate(activityID); | 
|             } | 
|             UpdateRedpoint(); | 
|         } | 
|     } | 
|   | 
|     private void OperationAdvanceEvent(OperationType type) | 
|     { | 
|         if (type == operaType) | 
|         { | 
|             if (onStateUpdate != null) | 
|             { | 
|                 onStateUpdate(activityID); | 
|             } | 
|         } | 
|     } | 
|   | 
|     private void OperationStartEvent(OperationType type, int state) | 
|     { | 
|         if (type == operaType && state == 0) | 
|         { | 
|   | 
|             if (onStateUpdate != null) | 
|             { | 
|                 onStateUpdate(activityID); | 
|             } | 
|         } | 
|     } | 
|   | 
|   | 
|   | 
|   | 
|   | 
|     //是不是免费礼包 | 
|     public bool IsFree(int index) | 
|     { | 
|         return index == 0; | 
|     } | 
|   | 
|   | 
|     //0 不可领取 1 可领取  2 已领取 | 
|     public int GetBuyGiftState(int count) | 
|     { | 
|         OperationRechargeGiftAct act; | 
|         OperationTimeHepler.Instance.TryGetOperation(operaType, out act); | 
|   | 
|         if (act == null) return 0; | 
|         if (GetBuyTotalCnt() < count) return 0; | 
|         if (((int)Math.Pow(2, count) & GiftAwardRecord) == 0) | 
|         { | 
|             return 1; | 
|         } | 
|         return 2; | 
|     } | 
|   | 
|     public int GetBuyTotalCnt() | 
|     { | 
|         OperationRechargeGiftAct act; | 
|         OperationTimeHepler.Instance.TryGetOperation(operaType, out act); | 
|   | 
|         if (act == null) return 0; | 
|         int total = 0; | 
|         for (int i = 0; i < act.ctgIDs.Count; i++) | 
|         { | 
|             int ctgID = act.ctgIDs[i]; | 
|             RechargeCount rechargeCount; | 
|             if (RechargeManager.Instance.TryGetRechargeCount(ctgID, out rechargeCount)) | 
|             { | 
|                 total += rechargeCount.totalCount; | 
|             } | 
|   | 
|         } | 
|         return total; | 
|     } | 
|   | 
|     public Int2 GetBuyCntInfo(int ctgID) | 
|     { | 
|         OperationRechargeGiftAct act; | 
|         OperationTimeHepler.Instance.TryGetOperation(operaType, out act); | 
|   | 
|         RechargeCount rechargeCount; | 
|         RechargeManager.Instance.TryGetRechargeCount(ctgID, out rechargeCount); | 
|   | 
|         var ctgConfig = CTGConfig.Get(ctgID); | 
|         int buyCnt = 0; | 
|         int totalCnt = 0; | 
|         if (ctgConfig.DailyBuyCount != 0) | 
|         { | 
|             buyCnt = rechargeCount.todayCount; | 
|             totalCnt = ctgConfig.DailyBuyCount; | 
|         } | 
|         else | 
|         { | 
|             buyCnt = rechargeCount.totalCount; | 
|             totalCnt = ctgConfig.TotalBuyCount; | 
|         } | 
|   | 
|         return new Int2(buyCnt, totalCnt); | 
|     } | 
|   | 
|     void UpdateRedpoint() | 
|     { | 
|         redPoint.state = RedPointState.None; | 
|         if (!IsOpen) return; | 
|         OperationRechargeGiftAct act; | 
|         OperationTimeHepler.Instance.TryGetOperation(operaType, out act); | 
|         if (act == null) return; //封包顺序如果有问题 此处为空 | 
|   | 
|         for (int i = 0; i < act.buyCountGifts.Count; i++) | 
|         { | 
|             if (GetBuyGiftState(act.buyCountGifts[i].NeedBuyCount) == 1) | 
|             { | 
|                 redPoint.state = RedPointState.Simple; | 
|                 return; | 
|             } | 
|         } | 
|   | 
|     } | 
|   | 
|     public void UpdateBuyCountGiftPlayerInfo(HAA75_tagMCActBuyCountGiftPlayerInfo netPack) | 
|     { | 
|         if (netPack.ActNum != 10) | 
|             return; | 
|         actNum = netPack.ActNum; | 
|         GiftAwardRecord = (int)netPack.GiftAwardRecord; | 
|         UpdateRechargeGiftActEvent?.Invoke(); | 
|         UpdateRedpoint(); | 
|     } | 
|   | 
|   | 
|     public void SendGetAward(int count) | 
|     { | 
|         CA504_tagCMPlayerGetReward getReward = new CA504_tagCMPlayerGetReward(); | 
|         getReward.RewardType = 72; | 
|         getReward.DataEx = (uint)count; | 
|         getReward.DataExStr = actNum.ToString(); | 
|         getReward.DataExStrLen = (byte)getReward.DataExStr.Length; | 
|         GameNetSystem.Instance.SendInfo(getReward); | 
|     } | 
|   | 
| } |