123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242 |
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using ET;
- namespace GFGGame
- {
- public class RechargeStoreType
- {
- public static int RECHARGE = 0;
- public static int GIFT = 1;
- public static int EXCHANGE = 2;
- }
- public class LockType
- {
- public static int NONE = 0;
- public static int STORY_LV = 1;
- public static int ROLE_LV = 2;
- }
- public class RefreshType
- {
- public static int NONE = 0;
- public static int DAY = 1;
- public static int WEEK = 2;
- public static int MONTH = 3;
- }
- public class CostType
- {
- public static int FREE = 0;
- public static int MONEY = 1;
- public static int RMB = 2;
- public static int ITEM = 3;
- }
- public class RechargeDataManager : SingletonBase<RechargeDataManager>
- {
- public string[] refreshType = { "", "日", "周", "月" };
- private Dictionary<int, int> _rechargeDic = new Dictionary<int, int>();
- private Dictionary<int, int> _giftDic = new Dictionary<int, int>();
- private Dictionary<int, int> _exchangeDic = new Dictionary<int, int>();
- public void Clear()
- {
- _rechargeDic.Clear();
- _giftDic.Clear();
- _exchangeDic.Clear();
- }
- public void UpdateRechargeData(int rechargeId, int num)
- {
- if (!_rechargeDic.ContainsKey(rechargeId))
- {
- _rechargeDic.Add(rechargeId, num);
- }
- else
- {
- _rechargeDic[rechargeId] = num;
- }
- }
- public void UpdateGiftData(int giftId, int num)
- {
- if (!_giftDic.ContainsKey(giftId))
- {
- _giftDic.Add(giftId, num);
- }
- else
- {
- _giftDic[giftId] = num;
- }
- }
- public void UpdateExchangeData(int exchangeId, int num)
- {
- if (!_exchangeDic.ContainsKey(exchangeId))
- {
- _exchangeDic.Add(exchangeId, num);
- }
- else
- {
- _exchangeDic[exchangeId] = num;
- }
- }
- /// <summary>
- /// 根据充值id获取购买次数
- /// </summary>
- /// <param name="rechargeId"></param>
- /// <returns></returns>
- public int GetRechargeBuyNumById(int rechargeId)
- {
- return !_rechargeDic.ContainsKey(rechargeId) ? 0 : _giftDic[rechargeId];
- }
- /// <summary>
- /// 根据礼包id获取购买次数
- /// </summary>
- /// <param name="giftId"></param>
- /// <returns></returns>
- public int GetGiftBuyNumById(int giftId)
- {
- return !_giftDic.ContainsKey(giftId) ? 0 : _giftDic[giftId];
- }
- /// <summary>
- /// 根据充值id获取购买次数
- /// </summary>
- /// <param name="exchangeId"></param>
- /// <returns></returns>
- public int GetExchangeBuyNumById(int exchangeId)
- {
- return !_exchangeDic.ContainsKey(exchangeId) ? 0 : _giftDic[exchangeId];
- }
- public List<GiftBagCfg> GetGiftBagCfgs()
- {
- List<GiftBagCfg> giftBagCfgs = new List<GiftBagCfg>();
- List<GiftBagCfg> noneGiftBagCfgs = GetNoneGiftCfg();
- giftBagCfgs = giftBagCfgs.Concat(noneGiftBagCfgs).ToList<GiftBagCfg>();
- GiftBagCfg StoryLvGiftCfg = GetStoryLvGiftCfg();
- if (StoryLvGiftCfg != null) giftBagCfgs.Add(StoryLvGiftCfg);
- GiftBagCfg RoleLvGiftCfg = GetRoleLvGiftCfg();
- if (RoleLvGiftCfg != null) giftBagCfgs.Add(RoleLvGiftCfg);
- SortGiftBagCfgs(giftBagCfgs);
- return giftBagCfgs;
- }
- private List<GiftBagCfg> SortGiftBagCfgs(List<GiftBagCfg> giftBagCfgs)
- {
- giftBagCfgs.Sort((GiftBagCfg a, GiftBagCfg b) =>
- {
- // if (GetGiftBuyNumById(a.id) < a.maxBuyNum && GetGiftBuyNumById(b.id) < b.maxBuyNum)
- // {
- // return -1;
- // }
- // else if (GetGiftBuyNumById(a.id) < a.maxBuyNum && GetGiftBuyNumById(b.id) < b.maxBuyNum)
- int buyTypeA = a.maxBuyNum - GetGiftBuyNumById(a.id) > 0 ? 1 : a.maxBuyNum - GetGiftBuyNumById(a.id) == 0 ? 0 : -1;
- int buyTypeB = b.maxBuyNum - GetGiftBuyNumById(b.id) > 0 ? 1 : b.maxBuyNum - GetGiftBuyNumById(b.id) == 0 ? 0 : -1;
- return buyTypeA.CompareTo(buyTypeB);
- });
- return giftBagCfgs;
- }
- private List<GiftBagCfg> GetNoneGiftCfg()
- {
- List<GiftBagCfg> giftBagCfgs = new List<GiftBagCfg>(GiftBagCfgArray.Instance.GetCfgs(LockType.NONE));
- for (int i = giftBagCfgs.Count - 1; i >= 0; i--)
- {
- if (giftBagCfgs[i].startTime != "" && !TimeUtil.IsBeforeCurTime(giftBagCfgs[i].startTime) || giftBagCfgs[i].endTime != "" && !TimeUtil.IsLaterCurTime(giftBagCfgs[i].endTime))
- {
- giftBagCfgs.RemoveAt(i);
- }
- }
- return giftBagCfgs;
- }
- private GiftBagCfg GetStoryLvGiftCfg()
- {
- List<GiftBagCfg> giftBagCfgs = GiftBagCfgArray.Instance.GetCfgs(LockType.STORY_LV);
- if (giftBagCfgs.Count == 0) return null;
- giftBagCfgs.Sort((GiftBagCfg a, GiftBagCfg b) =>
- {
- if (a.storyLevelId.CompareTo(b.storyLevelId) != 0)
- {
- return a.storyLevelId.CompareTo(b.storyLevelId);
- }
- return -1;
- });
- for (int i = 0; i < giftBagCfgs.Count; i++)
- {
- if (GetGiftStateById(giftBagCfgs[i].id) && (GetGiftBuyNumById(giftBagCfgs[i].id) < giftBagCfgs[i].maxBuyNum)) return giftBagCfgs[i];
- }
- return giftBagCfgs[0];
- }
- private GiftBagCfg GetRoleLvGiftCfg()
- {
- List<GiftBagCfg> giftBagCfgs = GiftBagCfgArray.Instance.GetCfgs(LockType.ROLE_LV);
- if (giftBagCfgs.Count == 0) return null;
- giftBagCfgs.Sort((GiftBagCfg a, GiftBagCfg b) =>
- {
- if (a.lv.CompareTo(b.lv) != 0)
- {
- return a.lv.CompareTo(b.lv);
- }
- return -1;
- });
- for (int i = 0; i < giftBagCfgs.Count; i++)
- {
- if (GetGiftStateById(giftBagCfgs[i].id) && (GetGiftBuyNumById(giftBagCfgs[i].id) < giftBagCfgs[i].maxBuyNum)) return giftBagCfgs[i];
- }
- return giftBagCfgs[0];
- }
- /// <summary>
- /// 根据礼包Id获取礼包解锁状态
- /// /// </summary>
- /// <param name="giftId"></param>
- /// <returns></returns>
- public bool GetGiftStateById(int giftId)
- {
- GiftBagCfg cfg = GiftBagCfgArray.Instance.GetCfg(giftId);
- if (cfg.lockType == LockType.NONE)
- {
- return true;
- }
- else if (cfg.lockType == LockType.STORY_LV)
- {
- return InstanceZonesDataManager.CheckLevelPass(cfg.storyLevelId);
- }
- else
- {
- return GameGlobal.myNumericComponent.GetAsInt(NumericType.Lvl) >= cfg.lv;
- }
- }
- /// <summary>
- /// 根据礼包id获取剩余刷新时间
- /// </summary>
- /// <param name="giftId"></param>
- /// <returns></returns>
- public string GetRefreshTime(int giftId)
- {
- int endTime = 0;
- GiftBagCfg cfg = GiftBagCfgArray.Instance.GetCfg(giftId);
- if (cfg.refreshType == RefreshType.NONE)
- {
- return "";
- }
- else if (cfg.refreshType == RefreshType.DAY)
- {
- endTime = TimeUtil.GetTomorrowTime(GlobalCfgArray.globalCfg.refreshTime);
- }
- else if (cfg.refreshType == RefreshType.WEEK)
- {
- endTime = TimeUtil.GetNextWeekTime(GlobalCfgArray.globalCfg.refreshTime);
- }
- if (cfg.refreshType == RefreshType.MONTH)
- {
- endTime = TimeUtil.GetNextMonthTime(GlobalCfgArray.globalCfg.refreshTime);
- }
- return TimeUtil.FormattingTime(TimeHelper.ServerNowSecs, endTime);
- }
- }
- }
|