using Snxxz.UI; using System; using System.Collections.Generic; using System.Linq; using TableConfig; using UnityEngine; using LitJson; public class BuyShopItemLimit { public uint ItemIndex; public ushort BuyCnt; // 今日已购买次数 public int isReset; //是否属于每月重置 0 不重置 1重置 } public struct ShopItemInfo { public int itemId; public int count; public int isBind; public ShopItemInfo(int id,int count,int isBind) { this.itemId = id; this.count = count; this.isBind = isBind; } } public class StoreModel : Model,IBeforePlayerDataInitialize,IAfterPlayerDataInitialize,IPlayerLoginOk { public int[] normalBuyCoinsTypes { get; private set; } public string UNIONSTORESAVE_KEY { get; private set; } public string StoreEffectRecord_Key { get; private set; } public List shoplist; public Dictionary> JobReplaceIdDict = new Dictionary>(); public Dictionary resetTimeDict { get; private set; } public Dictionary showCoinsUIDict { get; private set; } public int[] StoreRedIdlist { get; private set;} public override void Init() { FuncConfigConfig buyItemHinit = ConfigManager.Instance.GetTemplate("BuyItemHinit"); normalBuyCoinsTypes = ConfigParse.GetMultipleStr(buyItemHinit.Numerical1); FuncConfigConfig restTimeConfig = ConfigManager.Instance.GetTemplate("RefreshText"); resetTimeDict = ConfigParse.GetDic(restTimeConfig.Numerical1); FuncConfigConfig mallCurrency = ConfigManager.Instance.GetTemplate("MallCurrency"); showCoinsUIDict = ConfigParse.GetDic(mallCurrency.Numerical1); FuncConfigConfig mallPush = ConfigManager.Instance.GetTemplate("MallPush"); StoreRedIdlist = ConfigParse.GetMultipleStr(mallPush.Numerical2); } public void OnBeforePlayerDataInitialize() { shopItemlimitDict.Clear(); tagTowerModel = null; storeFuncType = StoreFunc.WeekStore; tcbRefreshDict.Clear(); } public void OnAfterPlayerDataInitialize() { UNIONSTORESAVE_KEY = StringUtility.Contact(PlayerDatas.Instance.baseData.PlayerID, LocalSaveStoreType.UnionStore); StoreEffectRecord_Key = StringUtility.Contact(PlayerDatas.Instance.baseData.PlayerID, "StoreEffectRecord"); } public void OnPlayerLoginOk() { PlayerDatas.Instance.fairyData.OnRefreshFairyInfo -= RefreshFamilyLv; PlayerDatas.Instance.fairyData.OnRefreshFairyInfo += RefreshFamilyLv; FuncOpen.Instance.OnFuncStateChangeEvent -= FuncStateChange; FuncOpen.Instance.OnFuncStateChangeEvent += FuncStateChange; RefreshTCBPlayerDataEvent -= RefreshPlayerLv; RefreshTCBPlayerDataEvent += RefreshPlayerLv; TimeMgr.Instance.OnHourEvent -= RefreshServerHour; TimeMgr.Instance.OnHourEvent += RefreshServerHour; shoplist = null; CheckWeekStoreIsShopBuy(out shoplist); ControllerRedPoint(); SetShopRedpoint(); CheckShopRedpoint(); SetJobReplaceIDDict(); } public string GetStoreRefreshTimeByType(int type) { if (resetTimeDict == null || !resetTimeDict.ContainsKey(type)) return string.Empty; switch(type) { case 7: int willRefreshTime = GetWillRefreshTime(); return Language.Get(resetTimeDict[type],UIHelper.GetTextColorByItemColor(TextColType.Green, TimeUtility.SecondsToHMS(willRefreshTime),true)); //if(willRefreshTime == 0) //{ // return Language.Get("StoreWin201"); //} //else //{ // return Language.Get(resetTimeDict[type],willRefreshTime); //} default: return Language.Get(resetTimeDict[type]); } } private int GetWillRefreshTime() { int willRefresh = (3 - TimeUtility.OpenDay % 3); if (willRefresh == 3) { if(TimeUtility.ServerNow.Hour < 5) { willRefresh = 0; } } int remainHour = 5 - TimeUtility.ServerNow.Hour; int remainMinute = 0 - TimeUtility.ServerNow.Minute; int remainSecond = willRefresh * 24 * 60 * 60 + remainHour * 60 * 60 + remainMinute * 60 - TimeUtility.ServerNow.Second; return remainSecond; } private void RefreshPlayerLv(PlayerDataRefresh type) { switch(type) { case PlayerDataRefresh.LV: case PlayerDataRefresh.VIPLv: case PlayerDataRefresh.Gold: case PlayerDataRefresh.GoldPaper: case PlayerDataRefresh.FBHelpPoint: CheckShopRedpoint(); break; } } public override void UnInit() { } ItemTipsModel _itemTipsModel; ItemTipsModel itemTipsModel { get { return _itemTipsModel ?? (_itemTipsModel = ModelCenter.Instance.GetModel()); } } #region 职业替换商品逻辑处理 public void SetJobReplaceIDDict() { JobReplaceIdDict.Clear(); List storeConfigs = ConfigManager.Instance.GetAllValues(); for(int i = 0; i < storeConfigs.Count; i++) { Dictionary replaceItemDict = new Dictionary(); JobReplaceIdDict.Add(storeConfigs[i].ID,replaceItemDict); AnalysisJobReplace(storeConfigs[i]); List shopItems = GetShopItemlistByIndex(storeConfigs[i]); for(int j = 0; j < shopItems.Count; j++) { foreach (var index in jobReplaceDic.Keys) { if (jobReplaceDic[index].Contains(shopItems[j].itemId)) { int replaceIndex = PlayerDatas.Instance.baseData.Job - 1; int replaceId = jobReplaceDic[index][replaceIndex]; replaceItemDict.Add(shopItems[j].itemId,replaceId); break; } } } } } Dictionary> jobReplaceDic = new Dictionary>(); private void AnalysisJobReplace(StoreConfig storeConfig) { jobReplaceDic.Clear(); JsonData jsonData = JsonMapper.ToObject(storeConfig.JobItem); if (jsonData.IsArray) { for (int i = 0; i < jsonData.Count; i++) { List idlist = new List(); jobReplaceDic.Add(i, idlist); if (jsonData[i].IsArray) { for (int j = 0; j < jsonData[i].Count; j++) { int itemId = int.Parse(jsonData[i][j].ToString()); idlist.Add(itemId); } } } } } public int ReplaceItemIdByJob(int storeId,int itemId) { if(JobReplaceIdDict.ContainsKey(storeId)) { if(JobReplaceIdDict[storeId].ContainsKey(itemId)) { return JobReplaceIdDict[storeId][itemId]; } } return itemId; } #endregion private void RefreshFamilyLv() { int familyLv = PlayerDatas.Instance.fairyData.fairy.FamilyLV; if(familyLv > GetSaveFairyLV()) { ControllerRedPoint(); } } private void RefreshServerHour() { ControllerRedPoint(); } public Action RefreshBuyShopLimitEvent; public StoreFunc storeFuncType = StoreFunc.WeekStore; private Dictionary shopItemlimitDict = new Dictionary(); private Dictionary tagTowerModel; /// /// 得到物品购买次数 /// /// public void RefreshBuyShopLimitModel(HA802_tagMCShopItemDayBuyCntInfo buylimit) { DebugEx.Log("RefreshBuyShopLimitModel" + buylimit.Count); if (buylimit.Count > 0) { int i = 0; for (i = 0; i < buylimit.Count; i++) { if (!shopItemlimitDict.ContainsKey(buylimit.DayBuyCntList[i].ItemIndex)) { BuyShopItemLimit shopItemLimit = new BuyShopItemLimit(); shopItemLimit.ItemIndex = buylimit.DayBuyCntList[i].ItemIndex; shopItemLimit.BuyCnt = buylimit.DayBuyCntList[i].BuyCnt; shopItemLimit.isReset = buylimit.DayBuyCntList[i].IsReset; shopItemlimitDict.Add(shopItemLimit.ItemIndex, shopItemLimit); } else { shopItemlimitDict[buylimit.DayBuyCntList[i].ItemIndex].BuyCnt = buylimit.DayBuyCntList[i].BuyCnt; shopItemlimitDict[buylimit.DayBuyCntList[i].ItemIndex]. isReset = buylimit.DayBuyCntList[i].IsReset; } } } CheckShopRedpoint(); if (RefreshBuyShopLimitEvent != null) RefreshBuyShopLimitEvent(); } public BuyShopItemLimit GetBuyShopLimit(uint itemIndex) { if (shopItemlimitDict.ContainsKey(itemIndex)) { return shopItemlimitDict[itemIndex]; } return null; } private RuneConfig _tagRuneModel = null; public RuneTowerFloorConfig SetRuneSource(int itemId) { _tagRuneModel = ConfigManager.Instance.GetTemplate(itemId); if (_tagRuneModel == null) return null; var _tagRuneTowerModel = ConfigManager.Instance.GetTemplate(_tagRuneModel.TowerID); return _tagRuneTowerModel; } List shopItemlist = new List(); public List GetShopItemlistByIndex(StoreConfig storeConfig) { if (storeConfig == null) return null; shopItemlist.Clear(); ShopItemInfo shopItem = new ShopItemInfo(storeConfig.ItemID, storeConfig.ItemCnt, storeConfig.IsBind); shopItemlist.Add(shopItem); JsonData extraItem = JsonMapper.ToObject(storeConfig.ItemListEx); if (extraItem.IsArray) { for (int i = 0; i < extraItem.Count; i++) { if (extraItem[i].IsArray) { if (extraItem[i].Count > 0) { ShopItemInfo shop = new ShopItemInfo(int.Parse(extraItem[i][0].ToString()), int.Parse(extraItem[i][1].ToString()), int.Parse(extraItem[i][2].ToString())); shopItemlist.Add(shop); } } } } return shopItemlist; } public bool TryGetShopItemInfo(StoreFunc _type, int _id, out List _shopItems) { _shopItems = null; var _list = StoreConfig.GetTypeStoreModel((int)_type, true); var _index = _list.FindIndex((x) => { return x.ID == _id; }); if (_index == -1) { return false; } _shopItems = GetShopItemlistByIndex(_list[_index]); return _shopItems != null; } #region 0418 数据处理 private Dictionary tcbRefreshDict = new Dictionary(); public event Action RefreshTCBPlayerDataEvent; public void RefreshTCBPlayerData(H0418_tagObjInfoRefresh info) { if(!tcbRefreshDict.ContainsKey((PlayerDataRefresh)info.RefreshType)) { tcbRefreshDict.Add((PlayerDataRefresh)info.RefreshType,(int)info.Value); } else { tcbRefreshDict[(PlayerDataRefresh)info.RefreshType] = (int)info.Value; } if(RefreshTCBPlayerDataEvent != null) { RefreshTCBPlayerDataEvent((PlayerDataRefresh)info.RefreshType); } } public int GetTCBPlayerData(PlayerDataRefresh tCDBPlayer) { int value = 0; tcbRefreshDict.TryGetValue(tCDBPlayer,out value); return value; } #endregion #region 点击商店物品逻辑 public void OnClickShopCell(StoreConfig shopInfo) { BuyItemPopModel.Instance.SetModel(shopInfo.ID); //SetOpenBuyType(chinModel); ItemAttrData attrData = new ItemAttrData(ReplaceItemIdByJob(shopInfo.ID,shopInfo.ItemID),true, (ulong)shopInfo.ItemCnt,-1,shopInfo.IsBind,true,PackType.rptDeleted ,"",null,ItemTipChildType.Buy); itemTipsModel.SetItemTipsModel(attrData); } #endregion private ulong _price; public void SendBuyShopItem(StoreConfig model, int count) { if ((StoreFunc)model.ShopType == StoreFunc.RuneStore) { _tagRuneModel = ConfigManager.Instance.GetTemplate(model.ItemID); if (_tagRuneModel != null) { if (!IsCanBuyItem(_tagRuneModel.TowerID)) { MessageWin.Inst.ShowFixedTip(Language.Get("Store101")); return; } } } _price = (ulong)(model.MoneyNumber * count); if (MoneyIsEnough(model.MoneyType, _price)) { C0803_tagCBuyItemList buyShop = new C0803_tagCBuyItemList(); buyShop.NPCID = 0; buyShop.BuyItemIndex = (ushort)model.ID; buyShop.BuyCount = (ushort)count; GameNetSystem.Instance.SendInfo(buyShop); } else { switch(model.MoneyType) { case 1: if (VersionConfig.Get().isBanShu) { SysNotifyMgr.Instance.ShowTip("GoldErr"); return; } WindowCenter.Instance.Open(); break; case 25: SysNotifyMgr.Instance.ShowTip("LackXBMoney", model.MoneyType); break; default: SysNotifyMgr.Instance.ShowTip("LackMoney", model.MoneyType); break; } } } public event Action RefreshBuyResultEvent; public void GetBuyResult(HA811_tagMCShoppingResult result) { DebugEx.Log("GetBuyResult"); StoreConfig tagStore = ConfigManager.Instance.GetTemplate((int)result.ItemIndex); if (tagStore != null) { ItemConfig chinModel = ConfigManager.Instance.GetTemplate(ReplaceItemIdByJob(tagStore.ID, tagStore.ItemID)); if (!normalBuyCoinsTypes.Contains(tagStore.MoneyType)) { if (tagStore.RemindSuccess == 0) { return; } BuySuccessModel.Instance.SetBuySuccessModel(chinModel.ID, (int)result.ItemCnt, tagStore.IsBind); if (!WindowCenter.Instance.CheckOpen()) { WindowCenter.Instance.Open(); } } else { float costMoney = tagStore.MoneyNumber; SysNotifyMgr.Instance.ShowTip("BuyItemHinit",costMoney,tagStore.MoneyType, chinModel.ItemName); } if (RefreshBuyResultEvent != null) { RefreshBuyResultEvent(chinModel.ID); } } } /// /// 用于判断符文塔兑换是否满足条件 /// /// /// public bool IsCanBuyItem(int limitTower) { int playerTower = (int)ModelCenter.Instance.GetModel().RuneTowerOpenLV; int offset = playerTower - limitTower; if (offset >= 0) return true; else return false; } public bool MoneyIsEnough(int moneyType, ulong money) { if (UIHelper.GetMoneyCnt(moneyType) < money) { return false; } else { return true; } } public int jumpToItemId { get;set;} public void SetJumpToModel(int itemId) { jumpToItemId = itemId; } #region 仙盟商店逻辑处理 #region 仙盟红点逻辑处理 private bool CheckIsBuyNewItem(int fairyLv) { if(fairyLv > GetSaveFairyLV()) { if (StoreConfig.GetCanBuyShopModel((int)StoreFunc.ToolStore, fairyLv).Count > 0 || StoreConfig.GetCanBuyShopModel((int)StoreFunc.MountStoneStore, fairyLv).Count > 0 || StoreConfig.GetCanBuyShopModel((int)StoreFunc.MountSkillBookStore, fairyLv).Count > 0) { return true; } } return false; } private bool CheckIsNewMonth() { GetSaveDateTime(); if(datelist.Count > 0) { if(TimeUtility.ServerNow.Month == datelist[0]) { if(TimeUtility.ServerNow.Day >= 1 && TimeUtility.ServerNow.Hour >= 5 && datelist[1] <= 1 && datelist[2] < 5) { return true; } } else { if(TimeUtility.ServerNow.Day >= 1 && TimeUtility.ServerNow.Hour >= 5) { return true; } } } else { return true; } return false; } List datelist = new List(); public List GetSaveDateTime() { datelist.Clear(); int[] unionArray = LocalSave.GetIntArray(UNIONSTORESAVE_KEY); if (unionArray != null && unionArray.Length >= 4) { datelist.Add(unionArray[1]); datelist.Add(unionArray[2]); datelist.Add(unionArray[3]); } return datelist; } public int GetSaveFairyLV() { int[] unionArray = LocalSave.GetIntArray(UNIONSTORESAVE_KEY); int fairyLv = 0; if(unionArray != null) { return unionArray[0]; } return fairyLv; } //1仙盟等级 2 月份 3 号 4 几点 public void SetStoreLocalSave(LocalSaveStoreType saveStoreType,params int[] infos) { string key = StringUtility.Contact(PlayerDatas.Instance.baseData.PlayerID, saveStoreType); LocalSave.SetIntArray(key,infos); } public void ControllerRedPoint(bool isLook = false) { MainRedDot.Instance.fairyStoreRedPoint.state = RedPointState.None; if(!ModelCenter.Instance.GetModel().fairyStoreOpen) { return; } int familyLv = PlayerDatas.Instance.fairyData.fairy.FamilyLV; if(!isLook) { if (CheckIsBuyNewItem(familyLv)) { MainRedDot.Instance.fairyStoreRedPoint.state = RedPointState.Simple; return; } if (CheckIsNewMonth()) { MainRedDot.Instance.fairyStoreRedPoint.state = RedPointState.Simple; return; } } SetStoreLocalSave(LocalSaveStoreType.UnionStore, familyLv, TimeUtility.ServerNow.Month, TimeUtility.ServerNow.Day, TimeUtility.ServerNow.Hour); } #endregion #endregion public event Action StoreFuncOpenAct; private void FuncStateChange(int funcId) { if (funcId != (int)FuncOpenEnum.Store) return; shoplist = null; CheckWeekStoreIsShopBuy(out shoplist); if(shoplist.Count > 0) { if (StoreFuncOpenAct != null) { StoreFuncOpenAct(); } } SetShopRedpoint(); CheckShopRedpoint(); } public bool CheckWeekStoreIsShopBuy(out List buylist) { buylist = new List(); if (!IsNewDay()) return false; List shoplist = StoreConfig.GetTypeStoreModel((int)StoreFunc.WeekStore); for(int i = 0; i < shoplist.Count; i++) { int canBuyCnt = 0; int addBuyCnt = 0; bool isLimitBuy = BuyItemPopModel.Instance.CheckIsLimitBuyCnt(shoplist[i], out canBuyCnt, out addBuyCnt); BuyShopItemLimit shopItemLimit = GetBuyShopLimit((uint)shoplist[i].ID); if (isLimitBuy) { int remainNum = canBuyCnt; if (shopItemLimit != null) { remainNum = canBuyCnt - shopItemLimit.BuyCnt; } if (remainNum > 0) { buylist.Add(shoplist[i]); } } else { buylist.Add(shoplist[i]); } } if(buylist.Count > 0) { return true; } else { return false; } } private bool IsNewDay() { if (!FuncOpen.Instance.IsFuncOpen((int)FuncOpenEnum.Store)) return false; if (PlayerPrefs.HasKey(StoreEffectRecord_Key)) { int day = LocalSave.GetInt(StoreEffectRecord_Key); if(day != TimeUtility.ServerNow.Day) { LocalSave.SetInt(StoreEffectRecord_Key,TimeUtility.ServerNow.Day); return true; } else { return false; } } else { LocalSave.SetInt(StoreEffectRecord_Key, TimeUtility.ServerNow.Day); return true; } } /// /// 检测唯一商品是否已售罄 /// /// /// /// public bool CheckTheOnlyShopSellOut(int shopIndex,out bool isTheOnlyShop) { StoreConfig storeConfig = ConfigManager.Instance.GetTemplate(shopIndex); isTheOnlyShop = false; if (storeConfig == null) return false; if(storeConfig.TheOnlyShop == 1) { if(StoreConfig.GetTheOnlyShopDict().ContainsKey(storeConfig.ItemID)) { List storelist = StoreConfig.GetTheOnlyShopDict()[storeConfig.ItemID]; for(int i = 0; i < storelist.Count; i++) { BuyShopItemLimit shoplimit = GetBuyShopLimit((uint)storelist[i].ID); if(shoplimit != null && shoplimit.BuyCnt >= storelist[i].PurchaseNumber[0]) { return true; } } } } return false; } #region 商城红点 public const int StoreFunc_RedKey = 22; public const int StoreFunc1_RedKey = 2201; public const int StoreFunc2_RedKey = 2202; public const int StoreFunc3_RedKey = 2203; public const int StoreFunc4_RedKey = 2204; public const int StoreFunc5_RedKey = 2205; public Redpoint storeFuncPoint = new Redpoint(MainRedDot.RedPoint_UpFuncBase,StoreFunc_RedKey); public Redpoint storeFunc1Point = new Redpoint(StoreFunc_RedKey,StoreFunc1_RedKey); public Redpoint storeFunc2Point = new Redpoint(StoreFunc_RedKey,StoreFunc2_RedKey); public Redpoint storeFunc3Point = new Redpoint(StoreFunc_RedKey,StoreFunc3_RedKey); public Redpoint storeFunc4Point = new Redpoint(StoreFunc_RedKey,StoreFunc4_RedKey); public Redpoint storeFunc5Point = new Redpoint(StoreFunc_RedKey,StoreFunc5_RedKey); public Dictionary shopRedDict = new Dictionary(); public void SetShopRedpoint() { shopRedDict.Clear(); if (!FuncOpen.Instance.IsFuncOpen((int)FuncOpenEnum.Store)) return; List storelist = StoreConfig.GetAllShoplist(); for(int i = 0; i < storelist.Count; i++) { StoreConfig storeConfig = storelist[i]; int redKey = 0; Redpoint redpoint = null; switch (storeConfig.ShopType) { case 1: redKey = StoreFunc1_RedKey*10000 + storeConfig.ID; redpoint = new Redpoint(StoreFunc1_RedKey,redKey); break; case 2: redKey = StoreFunc2_RedKey * 10000 + storeConfig.ID; redpoint = new Redpoint(StoreFunc2_RedKey, redKey); break; case 3: redKey = StoreFunc3_RedKey * 10000 + storeConfig.ID; redpoint = new Redpoint(StoreFunc3_RedKey, redKey); break; case 4: redKey = StoreFunc4_RedKey * 10000 + storeConfig.ID; redpoint = new Redpoint(StoreFunc4_RedKey, redKey); break; case 5: redKey = StoreFunc5_RedKey * 10000 + storeConfig.ID; redpoint = new Redpoint(StoreFunc5_RedKey, redKey); break; } shopRedDict.Add(storeConfig.ID,redpoint); } } public void CheckShopRedpoint() { if (!FuncOpen.Instance.IsFuncOpen((int)FuncOpenEnum.Store)) return; foreach(var key in shopRedDict.Keys) { StoreConfig storeConfig = ConfigManager.Instance.GetTemplate(key); if (storeConfig.MoneyNumber == 0) { if(CheckShopIsCanBuy(storeConfig)) { shopRedDict[storeConfig.ID].state = RedPointState.Simple; } else { shopRedDict[storeConfig.ID].state = RedPointState.None; } } else { if(CheckScoreStoreIsCanBuy(storeConfig)) { shopRedDict[storeConfig.ID].state = RedPointState.Simple; } else { shopRedDict[storeConfig.ID].state = RedPointState.None; } } } } public bool CheckScoreStoreIsCanBuy(StoreConfig storeConfig) { List list = StoreConfig.GetSellShoplist(); if(StoreRedIdlist.Contains(storeConfig.ID)) { if (CheckShopIsCanBuy(storeConfig)) { if(UIHelper.GetMoneyCnt(storeConfig.MoneyType) >= (ulong)storeConfig.MoneyNumber) { return true; } } } return false; } public bool CheckShopIsCanBuy(StoreConfig storeConfig) { int canBuyCnt = 0; int addBuyCnt = 0; bool isLimitBuy = BuyItemPopModel.Instance.CheckIsLimitBuyCnt(storeConfig, out canBuyCnt, out addBuyCnt); BuyShopItemLimit shopItemLimit = GetBuyShopLimit((uint)storeConfig.ID); int remainNum = canBuyCnt; if (shopItemLimit != null) { remainNum -= shopItemLimit.BuyCnt; } List list = StoreConfig.GetSellShoplist(); if (remainNum > 0 && list.Contains(storeConfig)) { return true; } return false; } #endregion } public enum StoreFunc { WeekStore = 1, //1:每周限购 CommonStore = 2, //2:常用道具 GrowStrongerStore = 3, //3:成长变强 BindStore = 4, //4:绑玉商城 IntegralStore = 5, //5:积分商城 BagStore = 6, //6:随身商店 RuneStore = 7, //7:符印商店 ToolStore = 8, // 道具商店 MountStoneStore = 9, //坐骑魂石商店 MountSkillBookStore = 10,//坐骑技能书商店 XBEquipStore = 11, //寻宝装备商店 XBRuneStore = 12, //寻宝符印商店 XBToolStore = 13, //寻宝道具商店 OSGift = 14,//开服礼包 OSTimeLimitGift = 15,//限时特惠 DanDrugStore = 30, //丹药回收商店 } public enum LocalSaveStoreType { UnionStore, //仙盟商店 }