using Snxxz.UI;
|
using System;
|
using System.Collections.Generic;
|
using System.Linq;
|
using TableConfig;
|
using UnityEngine;
|
using LitJson;
|
using System.Collections;
|
|
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;
|
}
|
}
|
|
[XLua.LuaCallCSharp]
|
public class StoreModel : Model,IBeforePlayerDataInitialize,IAfterPlayerDataInitialize,IPlayerLoginOk
|
{
|
public int[] normalBuyCoinsTypes { get; private set; }
|
public string UNIONSTORESAVE_KEY { get; private set; }
|
public string MUSTBUYSAVE_KEY { get; private set; }
|
public string StoreEffectRecord_Key { get; private set; }
|
public List<StoreConfig> shoplist;
|
|
public Dictionary<int,Dictionary<int,int>> JobReplaceIdDict = new Dictionary<int, Dictionary<int, int>>();
|
public Dictionary<int, string> resetTimeDict { get; private set; }
|
public Dictionary<int, int> showCoinsUIDict { get; private set; }
|
public int[] StoreRedIdlist { get; private set;}
|
bool isLogin = true;
|
public override void Init()
|
{
|
FuncConfigConfig buyItemHinit = Config.Instance.Get<FuncConfigConfig>("BuyItemHinit");
|
normalBuyCoinsTypes = ConfigParse.GetMultipleStr<int>(buyItemHinit.Numerical1);
|
FuncConfigConfig restTimeConfig = Config.Instance.Get<FuncConfigConfig>("RefreshText");
|
resetTimeDict = ConfigParse.GetDic<int, string>(restTimeConfig.Numerical1);
|
FuncConfigConfig mallCurrency = Config.Instance.Get<FuncConfigConfig>("MallCurrency");
|
showCoinsUIDict = ConfigParse.GetDic<int, int>(mallCurrency.Numerical1);
|
FuncConfigConfig mallPush = Config.Instance.Get<FuncConfigConfig>("MallPush");
|
StoreRedIdlist = ConfigParse.GetMultipleStr<int>(mallPush.Numerical2);
|
MainInterfaceWin.IsCopyOfThePanel += OnMoveTopPart;
|
}
|
|
public void OnBeforePlayerDataInitialize()
|
{
|
IsMustBuyDay = false;
|
isLogin = true;
|
ClearJumpModel();
|
StageManager.Instance.onStageLoadFinish -= OnStageLoadFinish;
|
FuncOpen.Instance.OnFuncStateChangeEvent -= FuncStateChange;
|
WindowCenter.Instance.windowAfterCloseEvent -= windowAfterOpen;
|
WindowCenter.Instance.windowAfterCloseEvent -= windowAfterClose;
|
PlayerDatas.Instance.fairyData.OnRefreshFairyMine -= RefreshServerHour;
|
PlayerDatas.Instance.fairyData.OnRefreshFairyInfo -= RefreshFamilyLv;
|
RefreshTCBPlayerDataEvent -= RefreshPlayerLv;
|
TimeMgr.Instance.OnHourEvent -= RefreshServerHour;
|
NewBieCenter.Instance.guideBeginEvent -= GuidBegin;
|
shopItemlimitDict.Clear();
|
petAndMountPushlist.Clear();
|
ClearPushData();
|
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");
|
MUSTBUYSAVE_KEY = StringUtility.Contact(PlayerDatas.Instance.baseData.PlayerID,"MustBuy");
|
}
|
|
public void OnPlayerLoginOk()
|
{
|
PlayerDatas.Instance.fairyData.OnRefreshFairyInfo += RefreshFamilyLv;
|
PlayerDatas.Instance.fairyData.OnRefreshFairyMine += RefreshServerHour;
|
FuncOpen.Instance.OnFuncStateChangeEvent += FuncStateChange;
|
RefreshTCBPlayerDataEvent += RefreshPlayerLv;
|
TimeMgr.Instance.OnHourEvent += RefreshServerHour;
|
StageManager.Instance.onStageLoadFinish += OnStageLoadFinish;
|
WindowCenter.Instance.windowAfterOpenEvent += windowAfterOpen;
|
WindowCenter.Instance.windowAfterCloseEvent += windowAfterClose;
|
NewBieCenter.Instance.guideBeginEvent += GuidBegin;
|
SetIsMustBuyDay();
|
shoplist = null;
|
CheckWeekStoreIsShopBuy(out shoplist);
|
ControllerRedPoint();
|
SetShopRedpoint();
|
UpdateFreeShopRedpoint();
|
UpdateCanBuyRedpoint();
|
SetJobReplaceIDDict();
|
UpdateMustBuyRedpoint();
|
UpdatePetAndMountPutAwayRedpoint();
|
isLogin = false;
|
}
|
|
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:
|
UpdateFreeShopRedpoint();
|
UpdateCanBuyRedpoint();
|
UpdateMustBuyRedpoint();
|
UpdatePetAndMountPutAwayRedpoint();
|
break;
|
case PlayerDataRefresh.VIPLv:
|
case PlayerDataRefresh.Gold:
|
case PlayerDataRefresh.GoldPaper:
|
case PlayerDataRefresh.FBHelpPoint:
|
UpdateFreeShopRedpoint();
|
UpdateCanBuyRedpoint();
|
break;
|
}
|
}
|
|
public override void UnInit()
|
{
|
MainInterfaceWin.IsCopyOfThePanel -= OnMoveTopPart;
|
}
|
|
ItemTipsModel _itemTipsModel;
|
ItemTipsModel itemTipsModel
|
{
|
get
|
{
|
return _itemTipsModel ?? (_itemTipsModel = ModelCenter.Instance.GetModel<ItemTipsModel>());
|
}
|
}
|
|
#region 职业替换商品逻辑处理
|
public void SetJobReplaceIDDict()
|
{
|
JobReplaceIdDict.Clear();
|
List<StoreConfig> storeConfigs = Config.Instance.GetAllValues<StoreConfig>();
|
for(int i = 0; i < storeConfigs.Count; i++)
|
{
|
Dictionary<int, int> replaceItemDict = new Dictionary<int, int>();
|
JobReplaceIdDict.Add(storeConfigs[i].ID,replaceItemDict);
|
AnalysisJobReplace(storeConfigs[i]);
|
List<ShopItemInfo> 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<int, List<int>> jobReplaceDic = new Dictionary<int, List<int>>();
|
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<int> idlist = new List<int>();
|
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();
|
if (PlayerPrefs.HasKey(MUSTBUYSAVE_KEY))
|
{
|
int[] records = LocalSave.GetIntArray(MUSTBUYSAVE_KEY);
|
if (TimeUtility.ServerNow.Hour >= 5
|
&& ((TimeUtility.ServerNow.Day == records[0] && records[1] < 5)
|
|| TimeUtility.ServerNow.Day != records[0]))
|
{
|
saveTimes[0] = TimeUtility.ServerNow.Day;
|
saveTimes[1] = TimeUtility.ServerNow.Hour;
|
IsMustBuyDay = true;
|
LocalSave.SetIntArray(MUSTBUYSAVE_KEY, saveTimes);
|
UpdateMustBuyRedpoint();
|
}
|
}
|
if(!PlayerDatas.Instance.fairyData.HasFairy)
|
{
|
PlayerPrefs.DeleteKey(UNIONSTORESAVE_KEY);
|
}
|
}
|
|
public event Action RefreshBuyShopLimitEvent;
|
|
public StoreFunc storeFuncType = StoreFunc.WeekStore;
|
private Dictionary<uint, BuyShopItemLimit> shopItemlimitDict = new Dictionary<uint, BuyShopItemLimit>();
|
private Dictionary<string, RuneTowerFloorConfig> tagTowerModel;
|
|
/// <summary>
|
/// 得到物品购买次数
|
/// </summary>
|
/// <param name="buylimit"></param>
|
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;
|
}
|
}
|
|
}
|
|
if(!isLogin)
|
{
|
UpdateFreeShopRedpoint();
|
UpdateCanBuyRedpoint();
|
UpdateMustBuyRedpoint();
|
UpdatePetAndMountPutAwayRedpoint();
|
}
|
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 = Config.Instance.Get<RuneConfig>(itemId);
|
if (_tagRuneModel == null)
|
return null;
|
var _tagRuneTowerModel = Config.Instance.Get<RuneTowerFloorConfig>(_tagRuneModel.TowerID);
|
return _tagRuneTowerModel;
|
}
|
|
List<ShopItemInfo> shopItemlist = new List<ShopItemInfo>();
|
public List<ShopItemInfo> 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<ShopItemInfo> _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<PlayerDataRefresh, int> tcbRefreshDict = new Dictionary<PlayerDataRefresh, int>();
|
public event Action<PlayerDataRefresh> 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,false);
|
attrData.SetTipsFuncBtn(ItemWinBtnType.buy,(ItemWinBtnType type ,string id) => { OnClickBuyBtn(ItemWinBtnType.buy, shopInfo.ID); });
|
itemTipsModel.ShowUICtrl();
|
}
|
|
public int BuyCnt { get; private set; }
|
public void SetBuyCnt(int buyCnt)
|
{
|
BuyCnt = buyCnt;
|
}
|
private void OnClickBuyBtn(ItemWinBtnType type, int shopId)
|
{
|
BuyShopItemLimit shopItemLimit = GetBuyShopLimit((uint)shopId);
|
StoreConfig storeConfig = Config.Instance.Get<StoreConfig>(shopId);
|
int curVipIndex = -1;
|
int nextVipIndex = -1;
|
bool isVipBuy = BuyItemPopModel.Instance.CheckIsVipBuy(storeConfig, out curVipIndex, out nextVipIndex);
|
if (shopItemLimit != null)
|
{
|
int remainNum = 0;
|
if (isVipBuy)
|
{
|
remainNum = storeConfig.PurchaseNumber[curVipIndex] - shopItemLimit.BuyCnt;
|
}
|
else
|
{
|
remainNum = storeConfig.PurchaseNumber[0] - shopItemLimit.BuyCnt;
|
}
|
if (remainNum < 1)
|
{
|
MessageWin.Inst.ShowFixedTip(Language.Get("StoreWin109"));
|
return;
|
}
|
|
}
|
SendBuyShopItem(storeConfig,BuyCnt);
|
}
|
|
#endregion
|
|
private ulong _price;
|
public void SendBuyShopItem(StoreConfig model, int count)
|
{
|
if ((StoreFunc)model.ShopType == StoreFunc.RuneStore)
|
{
|
_tagRuneModel = Config.Instance.Get<RuneConfig>(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<RechargeTipWin>();
|
break;
|
case 25:
|
SysNotifyMgr.Instance.ShowTip("LackXBMoney", model.MoneyType);
|
break;
|
default:
|
SysNotifyMgr.Instance.ShowTip("LackMoney", model.MoneyType);
|
break;
|
}
|
}
|
|
}
|
|
public event Action<int> RefreshBuyResultEvent;
|
|
public void GetBuyResult(HA811_tagMCShoppingResult result)
|
{
|
DebugEx.Log("GetBuyResult");
|
StoreConfig tagStore = Config.Instance.Get<StoreConfig>((int)result.ItemIndex);
|
if (tagStore != null)
|
{
|
ItemConfig chinModel = Config.Instance.Get<ItemConfig>(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.IsOpen<BuySuccessWin>())
|
{
|
WindowCenter.Instance.Open<BuySuccessWin>();
|
}
|
}
|
else
|
{
|
float costMoney = tagStore.MoneyNumber;
|
SysNotifyMgr.Instance.ShowTip("BuyItemHinit",costMoney,tagStore.MoneyType, chinModel.ItemName);
|
}
|
|
if (RefreshBuyResultEvent != null)
|
{
|
RefreshBuyResultEvent(chinModel.ID);
|
}
|
}
|
}
|
|
/// <summary>
|
/// 用于判断符文塔兑换是否满足条件
|
/// </summary>
|
/// <param name="limitTower"></param>
|
/// <returns></returns>
|
public bool IsCanBuyItem(int limitTower)
|
{
|
int playerTower = (int)ModelCenter.Instance.GetModel<RuneModel>().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;
|
}
|
}
|
}
|
return false;
|
}
|
|
List<int> datelist = new List<int>();
|
public List<int> 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<FairyModel>().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();
|
UpdateFreeShopRedpoint();
|
UpdateCanBuyRedpoint();
|
UpdateMustBuyRedpoint();
|
UpdatePetAndMountPutAwayRedpoint();
|
}
|
|
public bool CheckWeekStoreIsShopBuy(out List<StoreConfig> buylist)
|
{
|
buylist = new List<StoreConfig>();
|
if (!IsNewDay(StoreEffectRecord_Key)) return false;
|
|
List<StoreConfig> 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(string recordKey)
|
{
|
if (!FuncOpen.Instance.IsFuncOpen((int)FuncOpenEnum.Store)) return false;
|
|
if (PlayerPrefs.HasKey(recordKey))
|
{
|
int day = LocalSave.GetInt(recordKey);
|
if(day != TimeUtility.ServerNow.Day)
|
{
|
LocalSave.SetInt(recordKey, TimeUtility.ServerNow.Day);
|
return true;
|
}
|
else
|
{
|
return false;
|
}
|
}
|
else
|
{
|
LocalSave.SetInt(recordKey, TimeUtility.ServerNow.Day);
|
return true;
|
}
|
}
|
|
/// <summary>
|
/// 检测唯一商品是否已售罄
|
/// </summary>
|
/// <param name="shopIndex"></param>
|
/// <param name="isTheOnlyShop"></param>
|
/// <returns></returns>
|
public bool CheckTheOnlyShopSellOut(int shopIndex,out bool isTheOnlyShop)
|
{
|
StoreConfig storeConfig = Config.Instance.Get<StoreConfig>(shopIndex);
|
isTheOnlyShop = false;
|
if (storeConfig == null) return false;
|
|
if(storeConfig.TheOnlyShop == 1)
|
{
|
if(StoreConfig.GetTheOnlyShopDict().ContainsKey(storeConfig.ItemID))
|
{
|
List<StoreConfig> 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<int, Redpoint> shopRedDict = new Dictionary<int, Redpoint>();
|
public void SetShopRedpoint()
|
{
|
shopRedDict.Clear();
|
if (!FuncOpen.Instance.IsFuncOpen((int)FuncOpenEnum.Store)) return;
|
|
List<StoreConfig> 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 UpdateFreeShopRedpoint()
|
{
|
if (!FuncOpen.Instance.IsFuncOpen((int)FuncOpenEnum.Store)) return;
|
|
foreach (var key in shopRedDict.Keys)
|
{
|
StoreConfig storeConfig = Config.Instance.Get<StoreConfig>(key);
|
if (storeConfig.MoneyNumber == 0)
|
{
|
if (CheckShopIsCanBuy(storeConfig))
|
{
|
shopRedDict[storeConfig.ID].state = RedPointState.Simple;
|
}
|
else
|
{
|
shopRedDict[storeConfig.ID].state = RedPointState.None;
|
}
|
}
|
}
|
}
|
|
public void UpdateCanBuyRedpoint()
|
{
|
if (!FuncOpen.Instance.IsFuncOpen((int)FuncOpenEnum.Store)) return;
|
|
foreach (var key in shopRedDict.Keys)
|
{
|
StoreConfig storeConfig = Config.Instance.Get<StoreConfig>(key);
|
if (StoreRedIdlist.Contains(storeConfig.ID))
|
{
|
if (CheckShopIsCanBuy(storeConfig))
|
{
|
if (UIHelper.GetMoneyCnt(storeConfig.MoneyType) >= (ulong)storeConfig.MoneyNumber)
|
{
|
shopRedDict[storeConfig.ID].state = RedPointState.Simple;
|
}
|
else
|
{
|
shopRedDict[storeConfig.ID].state = RedPointState.None;
|
}
|
}
|
else
|
{
|
shopRedDict[storeConfig.ID].state = RedPointState.None;
|
}
|
}
|
}
|
}
|
|
public void UpdateMustBuyRedpoint()
|
{
|
if (!FuncOpen.Instance.IsFuncOpen((int)FuncOpenEnum.Store)) return;
|
|
foreach (var key in shopRedDict.Keys)
|
{
|
StoreConfig storeConfig = Config.Instance.Get<StoreConfig>(key);
|
if(mustIdlist.Contains(storeConfig.ItemID))
|
{
|
if (CheckIsMustBuy(storeConfig))
|
{
|
shopRedDict[storeConfig.ID].state = RedPointState.Simple;
|
}
|
else
|
{
|
shopRedDict[storeConfig.ID].state = RedPointState.None;
|
}
|
}
|
}
|
}
|
|
public void ClearMustBuyRedpoint(StoreConfig storeConfig)
|
{
|
if(mustIdlist.Contains(storeConfig.ItemID))
|
{
|
shopRedDict[storeConfig.ID].state = RedPointState.None;
|
IsMustBuyDay = false;
|
}
|
}
|
|
public bool IsMustBuyDay { get; private set; }
|
int[] saveTimes = new int[2];
|
public void SetIsMustBuyDay()
|
{
|
if (IsMustBuyDay) return;
|
|
saveTimes[0] = TimeUtility.ServerNow.Day;
|
saveTimes[1] = TimeUtility.ServerNow.Hour;
|
if (PlayerPrefs.HasKey(MUSTBUYSAVE_KEY))
|
{
|
int[] records = LocalSave.GetIntArray(MUSTBUYSAVE_KEY);
|
if (TimeUtility.ServerNow.Hour >= 5
|
&& ((TimeUtility.ServerNow.Day == records[0] && records[1] < 5)
|
|| TimeUtility.ServerNow.Day != records[0]))
|
{
|
IsMustBuyDay = true;
|
LocalSave.SetIntArray(MUSTBUYSAVE_KEY,saveTimes);
|
}
|
else
|
{
|
IsMustBuyDay = false;
|
}
|
}
|
else
|
{
|
IsMustBuyDay = true;
|
LocalSave.SetIntArray(MUSTBUYSAVE_KEY,saveTimes);
|
}
|
}
|
|
public List<int> mustIdlist = new List<int>() { 4741};
|
public bool CheckIsMustBuy(StoreConfig config)
|
{
|
if(CheckShopIsCanBuy(config) && IsMustBuyDay)
|
{
|
return true;
|
}
|
return false;
|
}
|
|
public bool CheckScoreStoreIsCanBuy(StoreConfig storeConfig)
|
{
|
List<StoreConfig> 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<StoreConfig> list = StoreConfig.GetSellShoplist();
|
if (remainNum > 0 && list.Contains(storeConfig))
|
{
|
return true;
|
}
|
return false;
|
}
|
|
/// <summary>
|
/// 新灵宠坐骑上架红点
|
/// </summary>
|
public void UpdatePetAndMountPutAwayRedpoint()
|
{
|
if (!FuncOpen.Instance.IsFuncOpen((int)FuncOpenEnum.Store)) return;
|
|
List<StoreConfig> storelist = StoreConfig.GetAllShoplist();
|
for(int i = 0; i < storelist.Count; i++)
|
{
|
if (storelist[i].ShopType != (int)StoreFunc.BindStore) continue;
|
|
ItemConfig itemConfig = Config.Instance.Get<ItemConfig>(storelist[i].ItemID);
|
string key = StringUtility.Contact(PlayerDatas.Instance.baseData.PlayerID,"ShopId",storelist[i].ID);
|
switch(itemConfig.Type)
|
{
|
case 26:
|
case 41:
|
if(CheckShopIsCanBuy(storelist[i]))
|
{
|
if (!PlayerPrefs.HasKey(key))
|
{
|
shopRedDict[storelist[i].ID].state = RedPointState.Simple;
|
LocalSave.SetBool(key,true);
|
SetPetAndMountPushData(storelist[i].ID);
|
}
|
else
|
{
|
if(LocalSave.GetBool(key))
|
{
|
shopRedDict[storelist[i].ID].state = RedPointState.Simple;
|
}
|
else
|
{
|
shopRedDict[storelist[i].ID].state = RedPointState.None;
|
}
|
|
}
|
}
|
else
|
{
|
//PlayerPrefs.DeleteKey(key);
|
shopRedDict[storelist[i].ID].state = RedPointState.None;
|
}
|
break;
|
}
|
}
|
|
}
|
|
public void ClearPetAndMountRedpoint(StoreConfig storeConfig)
|
{
|
ItemConfig itemConfig = Config.Instance.Get<ItemConfig>(storeConfig.ItemID);
|
switch (itemConfig.Type)
|
{
|
case 26:
|
case 41:
|
string key = StringUtility.Contact(PlayerDatas.Instance.baseData.PlayerID, "ShopId", storeConfig.ID);
|
if (shopRedDict[storeConfig.ID].state == RedPointState.Simple)
|
{
|
shopRedDict[storeConfig.ID].state = RedPointState.None;
|
LocalSave.SetBool(key,false);
|
}
|
break;
|
}
|
}
|
|
public void ClearAllPetAndMountRedpoint(StoreFunc storeFunc)
|
{
|
if (storeFuncType == StoreFunc.BindStore && storeFunc != StoreFunc.BindStore)
|
{
|
foreach(var key in shopRedDict.Keys)
|
{
|
StoreConfig storeConfig = Config.Instance.Get<StoreConfig>(key);
|
ItemConfig itemConfig = Config.Instance.Get<ItemConfig>(storeConfig.ItemID);
|
switch (itemConfig.Type)
|
{
|
case 26:
|
case 41:
|
if (shopRedDict[key].state != RedPointState.None)
|
{
|
string record = StringUtility.Contact(PlayerDatas.Instance.baseData.PlayerID, "ShopId", key);
|
shopRedDict[key].state = RedPointState.None;
|
LocalSave.SetBool(record, false);
|
}
|
break;
|
}
|
|
}
|
}
|
|
}
|
#endregion
|
|
#region 坐骑灵宠推送
|
|
List<int> petAndMountPushlist = new List<int>();
|
public int currentPushId { get; private set; }
|
public event Action pushRefreshEvent;
|
private void SetPetAndMountPushData(int shopId)
|
{
|
if (!petAndMountPushlist.Contains(shopId))
|
{
|
petAndMountPushlist.Add(shopId);
|
}
|
|
if (currentPushId == 0 || (currentPushId != 0 && currentPushId != shopId))
|
{
|
currentPushId = shopId;
|
if (pushRefreshEvent != null)
|
{
|
pushRefreshEvent();
|
}
|
}
|
if(!isLogin)
|
{
|
SetPushPetAndMountWinState();
|
}
|
}
|
|
private int cacheMapId = 0;
|
private void OnStageLoadFinish()
|
{
|
if (PlayerDatas.Instance.baseData.MapID == cacheMapId)
|
{
|
return;
|
}
|
MapConfig curMapConfig = Config.Instance.Get<MapConfig>(PlayerDatas.Instance.baseData.MapID);
|
if (curMapConfig == null || curMapConfig.MapFBType != 0)
|
{
|
SetPushPetAndMountWinState(true,true);
|
}
|
}
|
|
private void GuidBegin()
|
{
|
PetAndMountPushWin pushWin = WindowCenter.Instance.Get<PetAndMountPushWin>();
|
if(pushWin != null)
|
{
|
SetPushPetAndMountWinState(true, true);
|
}
|
}
|
|
private void OnMoveTopPart(bool isMove)
|
{
|
if(!isLogin)
|
{
|
SetPushPetAndMountWinState(!isMove);
|
}
|
}
|
|
private void windowAfterOpen(Window win)
|
{
|
if (win is FirstTimeRechargeWin)
|
{
|
SetPushPetAndMountWinState(true,true);
|
}
|
}
|
|
private void windowAfterClose(Window win)
|
{
|
if (isLogin) return;
|
|
if(win is MainInterfaceWin)
|
{
|
SetPushPetAndMountWinState(true);
|
}
|
else if(win is RoleParticularsWin
|
|| win is FirstTimeRechargeWin)
|
{
|
SetPushPetAndMountWinState();
|
}
|
}
|
|
public void SetPushPetAndMountWinState(bool isMustClose = false, bool isClearData = false)
|
{
|
if(isClearData)
|
{
|
ClearPushData();
|
WindowCenter.Instance.CloseImmediately<PetAndMountPushWin>();
|
return;
|
}
|
|
if(CheckIsShowPush(isMustClose))
|
{
|
if (!WindowCenter.Instance.IsOpen<PetAndMountPushWin>())
|
{
|
WindowCenter.Instance.Open<PetAndMountPushWin>();
|
}
|
}
|
else
|
{
|
WindowCenter.Instance.CloseImmediately<PetAndMountPushWin>();
|
}
|
}
|
|
public bool CheckIsShowPush(bool isMustClose = false)
|
{
|
bool isShow = false;
|
if (isMustClose)
|
{
|
isShow = false;
|
}
|
else
|
{
|
MapConfig curMapConfig = Config.Instance.Get<MapConfig>(PlayerDatas.Instance.baseData.MapID);
|
|
if ((curMapConfig == null || curMapConfig.MapFBType != 0)
|
|| !WindowCenter.Instance.IsOpen<MainInterfaceWin>()
|
|| NewBieCenter.Instance.inGuiding
|
|| WindowCenter.Instance.IsOpen<FirstTimeRechargeWin>()
|
|| currentPushId == 0
|
|| !ModelCenter.Instance.GetModel<PlayerMainDate>().MainTopPanelShow)
|
{
|
isShow = false;
|
}
|
else
|
{
|
isShow = true;
|
}
|
}
|
return isShow;
|
}
|
|
public void ClearPushData()
|
{
|
currentPushId = 0;
|
petAndMountPushlist.Clear();
|
}
|
|
public void RemovePetAndMountPush(int shopId)
|
{
|
if(petAndMountPushlist.Contains(shopId))
|
{
|
petAndMountPushlist.Remove(shopId);
|
currentPushId = GetPrePetAndMountPushId();
|
if(pushRefreshEvent != null)
|
{
|
pushRefreshEvent();
|
}
|
}
|
else
|
{
|
ClearPushData();
|
}
|
}
|
|
private int GetPrePetAndMountPushId()
|
{
|
currentPushId = 0;
|
for(int i = petAndMountPushlist.Count - 1; i > -1; i--)
|
{
|
currentPushId = petAndMountPushlist[i];
|
break;
|
}
|
return currentPushId;
|
}
|
|
#endregion
|
|
#region 处理跳转数据
|
public int funcOrder { get; private set; }
|
public int jumpShopId { get; private set; }
|
public void SetJumpModel(StoreFunc storeFunc,int shopId)
|
{
|
if (shopId == 0) return;
|
|
funcOrder = (int)storeFunc - 1;
|
jumpShopId = shopId;
|
}
|
|
public void ClearJumpModel()
|
{
|
funcOrder = -1;
|
jumpShopId = 0;
|
}
|
#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, //仙盟商店
|
}
|
|