using System; using System.Collections.Generic; using LitJson; public class DailySpecialsManager : GameSystemManager { public int[] dailyRechargeIds; // 每日特惠礼包充值ID列表(单独购买用) public int bundleRechargeId; // 打包购买充值ID public int originalPrice; public bool isDailySpecialsToggleOn; // 本次登录不再提醒的状态 RechargeManager rechargeManager { get { return RechargeManager.Instance; } } public override void Init() { DTC0102_tagCDBPlayer.beforePlayerDataInitializeEventOnRelogin += OnBeforePlayerDataInitializeEventOnRelogin; rechargeManager.rechargeCountEvent += OnRechargeCountEvent; StoreModel.Instance.RefreshShopEvent += OnRefreshShopEvent; StoreModel.Instance.RefreshBuyShopLimitEvent += OnRefreshBuyShopLimitEvent; FuncOpen.Instance.OnFuncStateChangeEvent += OnFuncStateChange; InitTable(); InitRedpoints(); } public override void Release() { DTC0102_tagCDBPlayer.beforePlayerDataInitializeEventOnRelogin -= OnBeforePlayerDataInitializeEventOnRelogin; rechargeManager.rechargeCountEvent -= OnRechargeCountEvent; StoreModel.Instance.RefreshShopEvent -= OnRefreshShopEvent; StoreModel.Instance.RefreshBuyShopLimitEvent -= OnRefreshBuyShopLimitEvent; FuncOpen.Instance.OnFuncStateChangeEvent -= OnFuncStateChange; } private void OnFuncStateChange(int obj) { if (FuncOpen.Instance.IsFuncOpen((int)FuncOpenEnum.DailySpecials)) { UpdateRedPoint(); } } private void OnBeforePlayerDataInitializeEventOnRelogin() { isDailySpecialsToggleOn = false; } private void OnRechargeCountEvent(int obj) { UpdateRedPoint(); } private void OnRefreshBuyShopLimitEvent() { UpdateRedPoint(); } private void OnRefreshShopEvent() { UpdateRedPoint(); } void InitTable() { var config = FuncConfigConfig.Get("DailyTehui"); dailyRechargeIds = JsonMapper.ToObject(config.Numerical1); bundleRechargeId = int.Parse(config.Numerical2); originalPrice = int.Parse(config.Numerical3); } public bool IsWeekGiftBuy(int ctgId) { if (!CTGConfig.HasKey(ctgId)) { return false; } CTGConfig ctgConfig = CTGConfig.Get(ctgId); bool hasRechargeCount = RechargeManager.Instance.TryGetRechargeCount(ctgId, out RechargeCount _rechargeCount); bool isBuy = hasRechargeCount && _rechargeCount.weekPayCount >= ctgConfig.WeekBuyCount; return isBuy; } public bool IsDayGiftBuy(int ctgId) { if (!CTGConfig.HasKey(ctgId)) { return false; } CTGConfig ctgConfig = CTGConfig.Get(ctgId); bool hasRechargeCount = RechargeManager.Instance.TryGetRechargeCount(ctgId, out RechargeCount _rechargeCount); bool isBuy = hasRechargeCount && _rechargeCount.todayCount >= ctgConfig.DailyBuyCount; return isBuy; } public readonly Dictionary FunctionOrderToStoreFunc = new Dictionary() { {0, StoreFunc.DailySpecialsFree}, {2, StoreFunc.DailyGiftFree}, {3, StoreFunc.WeeklyGiftFree}, }; public int GetShopIdByFunctionOrder(int functionOrder) { if (FunctionOrderToStoreFunc.TryGetValue(functionOrder, out StoreFunc storeFunc)) { return GetShopIdByStoreFunc(storeFunc); } return 0; } private int GetShopIdByStoreFunc(StoreFunc storeFunc) { return GetFreeShopIDDict().TryGetValue(storeFunc, out int shopId) ? shopId : 0; } Dictionary freeShopIDDict = null; private Dictionary GetFreeShopIDDict() { if (freeShopIDDict.IsNullOrEmpty()) { freeShopIDDict = new Dictionary(); List storeConfigs = StoreConfig.GetValues(); foreach (var storeConfig in storeConfigs) { foreach (var StoreFunc in FunctionOrderToStoreFunc.Values) { if (storeConfig.ShopType == (int)StoreFunc) { freeShopIDDict[StoreFunc] = storeConfig.ID; } } } } return freeShopIDDict; } public bool IsReceived(int shopId) { if (!StoreConfig.HasKey(shopId)) { return false; } StoreConfig storeConfig = StoreConfig.Get(shopId); int boughtCount = StoreModel.Instance.GetShopLimitBuyCount(shopId); return boughtCount >= storeConfig.LimitCnt; } public string GetCountdownToNextDay() { int remainSeconds = TimeUtility.GetTodayRemainSeconds(); return TimeUtility.SecondsToShortDHMS(remainSeconds); } public string GetCountdownToWeekEnd() { DateTime now = TimeUtility.ServerNow; int daysUntilMonday = (int)DayOfWeek.Monday - (int)now.DayOfWeek; if (daysUntilMonday <= 0) { daysUntilMonday += 7; // 下周一 } DateTime nextMonday = now.AddDays(daysUntilMonday); DateTime weekEndTime = new DateTime(nextMonday.Year, nextMonday.Month, nextMonday.Day); int remainSeconds = (int)(weekEndTime - now).TotalSeconds; return TimeUtility.SecondsToShortDHMS(remainSeconds); } public bool TryGetDailyCtgIdByIndex(int index, out int ctgId) { ctgId = 0; if (dailyRechargeIds.IsNullOrEmpty()) { return false; } if (index < 0 || index >= dailyRechargeIds.Length) { return false; } ctgId = dailyRechargeIds[index]; return true; } /// 检查是否有任意单独商品已购买 public bool HasAnySingleItemBought() { if (dailyRechargeIds.IsNullOrEmpty()) { return false; } for (int i = 0; i < dailyRechargeIds.Length; i++) { int singleCtgId = dailyRechargeIds[i]; if (rechargeManager.TryGetRechargeCount(singleCtgId, out RechargeCount singleRechargeCount)) { if (singleRechargeCount.todayCount > 0) { return true; } } } return false; } #region 红点 public Redpoint parentRedpoint = new Redpoint(MainRedDot.DailyTehui); public Dictionary tabRedpoints = new Dictionary(); public void InitRedpoints() { tabRedpoints.Clear(); var enumValues = Enum.GetValues(typeof(DailySpecialsTabEnum)); foreach (DailySpecialsTabEnum tab in enumValues) { int tabRedponitId = GetTabRedponitId((int)tab); tabRedpoints[tabRedponitId] = new Redpoint(MainRedDot.DailyTehui, tabRedponitId); } } public int GetTabRedponitId(int functionOrder) { if (!Enum.IsDefined(typeof(DailySpecialsTabEnum), functionOrder)) { return 0; } return MainRedDot.DailyTehui * 10 + functionOrder + 1; } public void UpdateRedPoint() { parentRedpoint.state = RedPointState.None; foreach (DailySpecialsTabEnum tab in Enum.GetValues(typeof(DailySpecialsTabEnum))) { int redpointId = GetTabRedponitId((int)tab); if (tabRedpoints.ContainsKey(redpointId)) { tabRedpoints[redpointId].state = RedPointState.None; } } // 功能没开 if (!FuncOpen.Instance.IsFuncOpen((int)FuncOpenEnum.DailySpecials)) return; foreach (DailySpecialsTabEnum tab in Enum.GetValues(typeof(DailySpecialsTabEnum))) { int redpointId = GetTabRedponitId((int)tab); if (!tabRedpoints.ContainsKey(redpointId)) { continue; } if (tab == DailySpecialsTabEnum.DailySpecials || tab == DailySpecialsTabEnum.DailyGift || tab == DailySpecialsTabEnum.WeeklyGift) { int shopId = GetShopIdByFunctionOrder((int)tab); bool isReceived = IsReceived(shopId); if (!isReceived) { tabRedpoints[redpointId].state = RedPointState.Simple; } } else if (tab == DailySpecialsTabEnum.SpecialStore) { Dictionary> freeShopDict = StoreModel.Instance.freeShopDict; bool isFlag = false; if (!freeShopDict.IsNullOrEmpty() && freeShopDict.ContainsKey((int)StoreFunc.SpecialStore)) { var shopList = freeShopDict[(int)StoreFunc.SpecialStore]; for (int i = 0; i < shopList.Count; i++) { var shopId = shopList[i]; bool isReceived = IsReceived(shopId); if (!isReceived) { isFlag = true; break; } } if (isFlag) { tabRedpoints[redpointId].state = RedPointState.Simple; } } } } } #endregion } public enum DailySpecialsTabEnum { DailySpecials = 0, // 每日特惠 SpecialStore = 1, // 特惠商城 DailyGift = 2, // 每日礼包 WeeklyGift = 3, // 每周礼包 }