using Snxxz.UI;
|
using System;
|
using System.Collections.Generic;
|
using System.Linq;
|
using System.Text;
|
|
|
[XLua.LuaCallCSharp]
|
public class BuyItemPopModel : Singleton<BuyItemPopModel>
|
|
{
|
public StoreConfig storeConfig { get; private set; }
|
|
public void SetModel(int shopId)
|
{
|
storeConfig = StoreConfig.Get(shopId);
|
}
|
|
public Dictionary<int, int> vipBuyCntDict = new Dictionary<int, int>();
|
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 remainBuyCnt,out bool IsReachUpper)
|
{
|
int count = 0;
|
IsReachUpper = false;
|
if(remainBuyCnt == 0)
|
{
|
IsReachUpper = true;
|
count = 0;
|
}
|
else
|
{
|
if(buyCnt <= remainBuyCnt)
|
{
|
count = buyCnt;
|
}
|
else
|
{
|
count = remainBuyCnt;
|
IsReachUpper = true;
|
}
|
}
|
|
if(count < 0)
|
{
|
count = 0;
|
}
|
return count;
|
}
|
|
public int GetRemainBuyCnt(int canBuyCnt,BuyShopItemLimit shopItemLimit,bool isVipBuy)
|
{
|
int haveBuyCnt = 0;
|
if (shopItemLimit != null)
|
{
|
haveBuyCnt = shopItemLimit.BuyCnt;
|
}
|
|
if (canBuyCnt <= 0 && !isVipBuy)
|
{
|
canBuyCnt = 9999;
|
}
|
int remainCnt = canBuyCnt - haveBuyCnt;
|
if (remainCnt >= 0)
|
{
|
return remainCnt;
|
}
|
else
|
{
|
return 0;
|
}
|
}
|
public int GetBuyPrice(StoreConfig model,int buyCnt)
|
{
|
if (model == null) return 0;
|
|
int buyItemPrice = model.MoneyNumber * buyCnt;
|
return buyItemPrice;
|
}
|
}
|