using Snxxz.UI; using System; using System.Collections.Generic; using System.Linq; using System.Text; using TableConfig; public class BuyItemPopModel : Singleton { public StoreConfig storeConfig { get; private set; } public void SetModel(int shopId) { storeConfig = Config.Instance.Get(shopId); } public Dictionary vipBuyCntDict = new Dictionary(); public bool CheckIsVipBuy(StoreConfig model,out int curVipIndex,out int nextVipIndex) { vipBuyCntDict.Clear(); curVipIndex = -1; nextVipIndex = -1; bool isVipBuy = false; if (model == null) return isVipBuy; if (model.VIPLV.Length < 2) { if (model.VIPLV[0] != 0) { isVipBuy = true; } else { isVipBuy = false; } } else { isVipBuy = true; } if(isVipBuy) { for (int i = model.VIPLV.Length-1; i > -1; i--) { vipBuyCntDict.Add(model.VIPLV[i], model.PurchaseNumber[i]); } int playerVip = PlayerDatas.Instance.baseData.VIPLv; for (int i = model.VIPLV.Length - 1; i > -1; i--) { if (model.VIPLV[i] > playerVip) { nextVipIndex = i; } else if(model.VIPLV[i] <= playerVip) { curVipIndex = i; break; } } } return isVipBuy; } public bool CheckIsLimitBuyCnt(StoreConfig model,out int canBuyCnt,out int addBuyCnt) { canBuyCnt = 0; addBuyCnt = 0; if (model == null) return false; int[] canBuyNums = model.PurchaseNumber; int curVipIndex = -1; int nexVipIndex = -1; bool isVipBuy = CheckIsVipBuy(model, out curVipIndex, out nexVipIndex); if (isVipBuy) { if (curVipIndex != -1) { canBuyCnt = canBuyNums[curVipIndex]; } if (nexVipIndex != -1) { addBuyCnt = canBuyNums[nexVipIndex] - canBuyCnt; } return true; } else { if (canBuyNums[0] != 0) { canBuyCnt = canBuyNums[0]; return true; } else { return false; } } } public int GetCurBuyCnt(int buyCnt,int canBuyCnt,bool isVipBuy,out bool IsReachUpper) { int count = 0; IsReachUpper = false; if(canBuyCnt == 0) { if(isVipBuy) { IsReachUpper = true; } else { if (buyCnt <= 9999) { count = buyCnt; } else { count = 9999; IsReachUpper = true; } } } else { if(buyCnt <= canBuyCnt) { count = buyCnt; } else { count = canBuyCnt; IsReachUpper = true; } } if(count < 0) { count = 0; } return count; } public int GetBuyPrice(StoreConfig model,int buyCnt) { if (model == null) return 0; int buyItemPrice = model.MoneyNumber * buyCnt; return buyItemPrice; } }