123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268 |
- 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 : _rechargeDic[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 : _exchangeDic[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) =>
- {
- //未售罄的>未解锁>已售罄的
- int buyTypeA = (a.maxBuyNum == 0 || a.maxBuyNum - GetGiftBuyNumById(a.id) > 0) ? 1 : -1;
- int buyTypeB = (b.maxBuyNum == 0 || b.maxBuyNum - GetGiftBuyNumById(b.id) > 0) ? 1 : -1;
- if (buyTypeA > buyTypeB) return -1;
- if (buyTypeA < buyTypeB) return 1;
- //解锁状态
- int lockA = GetGiftStateById(a.id) ? 1 : -1;
- int lockB = GetGiftStateById(b.id) ? 1 : -1;
- if (lockA > lockB) return -1;
- if (lockA < lockB) return 1;
- //免费>钻石>现金>道具
- if (a.costType < b.costType) return -1;
- if (a.costType > b.costType) return 1;
- //有下架时间的 > 没有下架时间的
- int endTimeA = a.endTime != "" ? 1 : -1;
- int endTimeB = b.endTime != "" ? 1 : -1;
- if (endTimeA > endTimeB) return -1;
- if (endTimeA < endTimeB) return 1;
- int descA = a.desc == "" ? 0 : int.Parse(a.desc);
- int descB = b.desc == "" ? 0 : int.Parse(b.desc);
- if (descA != descB) return descA - descB;
- if (a.price != b.price) return a.price - b.price;
- return 0;
- });
- 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];
- }
- public List<ShopExchangeCfg> GetExchangeCfgs()
- {
- List<ShopExchangeCfg> shopExchangeCfgs = new List<ShopExchangeCfg>(ShopExchangeCfgArray.Instance.dataArray);
- shopExchangeCfgs.Sort((ShopExchangeCfg a, ShopExchangeCfg b) =>
- {
- //未售罄的>已售罄的
- int buyTypeA = (a.num == 0 || a.num - GetExchangeBuyNumById(a.id) > 0) ? 1 : -1;
- int buyTypeB = (b.num == 0 || b.num - GetExchangeBuyNumById(b.id) > 0) ? 1 : -1;
- if (buyTypeA > buyTypeB) return -1;
- if (buyTypeA < buyTypeB) return 1;
- return 0;
- });
- return shopExchangeCfgs;
- }
- /// <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 GetEndTime(int giftId)
- {
- int endTime = 0;
- GiftBagCfg cfg = GiftBagCfgArray.Instance.GetCfg(giftId);
- if (cfg.endTime == "") return "";
- endTime = TimeUtil.DateTimeToTimestamp(cfg.endTime);
- return TimeUtil.FormattingTime(TimeHelper.ServerNowSecs, endTime);
- }
- }
- }
|