NLDClient-yudde/ProjectNLD/Assets/Code/Scripts/Gameplay/Draw/DrawInfo.cs

174 lines
4.8 KiB
C#

using cfg.ActorCfg;
using Gameplay.Net;
using System.Collections.Generic;
/// <summary>
/// 卡池数据
/// </summary>
public sealed class DrawInfo
{
#region 属性
/// <summary>
/// 卡池配置数据
/// </summary>
public DataGacha Cfg { get; private set; }
/// <summary>
/// 卡池累计抽取数据
/// </summary>
public RaffleCount ServerData { get; private set; }
/// <summary>
/// 有可以抽取的
/// </summary>
public bool IsDraw
{
get
{
for (int i = 0; i < Cfg.DrawType.Length; ++i)
{
if (ListDrawButtonData[i].IsDraw)
return true;
}
return false;
}
}
/// <summary>
/// 抽卡按钮数据
/// </summary>
public List<DrawButtonData> ListDrawButtonData { get; private set; }
/// <summary>
/// 剩余免费单抽次数
/// </summary>
public int FreeOneCount
{
get
{
if (null == ServerData)
return Cfg.DailyFreeCount;
if (Cfg.DailyFreeCount <= ServerData.FreeCount)
return 0;
else
return Cfg.DailyFreeCount - (int)ServerData.FreeCount;
}
}
/// <summary>
/// 剩余限定单抽次数
/// </summary>
public int LimitOneCount
{
get
{
if (null == ServerData)
return Cfg.LimitOneCount;
if (Cfg.LimitOneCount <= ServerData.LimitOne)
return 0;
else
return Cfg.LimitOneCount - (int)ServerData.LimitOne;
}
}
/// <summary>
/// 是否可以免费单抽
/// </summary>
public bool IsFreeOne
{
get { return FreeOneCount > 0; }
}
/// <summary>
/// 是否可以限定单抽
/// </summary>
public bool IsLimitOne
{
get { return LimitOneCount > 0; }
}
/// <summary>
/// 剩余限定十连抽次数
/// </summary>
public int LimitTenCount
{
get
{
if (null == ServerData)
return Cfg.LimitTenCount;
if (Cfg.LimitTenCount <= ServerData.LimitTen)
return 0;
else
return Cfg.LimitTenCount - (int)ServerData.LimitTen;
}
}
/// <summary>
/// 是否可以限定十连抽
/// </summary>
public bool IsLimitTen
{
get { return LimitTenCount >= 1; }
}
#endregion
public DrawInfo(DataGacha cfg)
{
Cfg = cfg;
ListDrawButtonData = new(4)
{
new DrawButtonData(),
new DrawButtonData(),
new DrawButtonData(),
new DrawButtonData(),
};
}
public void Refresh()
{
ServerData = Actor.Instance.Raffle.GetRaffleInfo((uint)Cfg.Id);
for (int i = 0; i < Cfg.DrawType.Length; ++i)
{
GachaDrawType gachaDrawType = Cfg.DrawType[i];
switch (gachaDrawType)
{
case GachaDrawType.NormalOne:
{
int count = (int)E_DrawCount.One;
if (Actor.Instance.Item.GetItemCount(Cfg.TicketItemID) >= (uint)E_DrawCount.One)
ListDrawButtonData[i] = new(gachaDrawType, E_DrawCount.One, true, IsFreeOne, Cfg.TicketItemID, count, false);
else
ListDrawButtonData[i] = new(gachaDrawType, E_DrawCount.One, true, IsFreeOne, Cfg.Cost[i].Id, Cfg.Cost[i].Count, true);
}
break;
case GachaDrawType.NormalTen:
{
int count = (int)E_DrawCount.Ten;
if (Actor.Instance.Item.GetItemCount(Cfg.TicketItemID) >= (uint)E_DrawCount.Ten)
ListDrawButtonData[i] = new(gachaDrawType, E_DrawCount.Ten, true, false, Cfg.TicketItemID, count, false);
else
ListDrawButtonData[i] = new(gachaDrawType, E_DrawCount.Ten, true, false, Cfg.Cost[i].Id, Cfg.Cost[i].Count, true);
}
break;
case GachaDrawType.LimitOne:
{
ListDrawButtonData[i] = new(gachaDrawType, E_DrawCount.One, IsLimitOne, false, Cfg.Cost[i].Id, Cfg.Cost[i].Count, true);
}
break;
case GachaDrawType.LimitTen:
{
ListDrawButtonData[i] = new(gachaDrawType, E_DrawCount.Ten, IsLimitTen, false, Cfg.Cost[i].Id, Cfg.Cost[i].Count, true);
}
break;
default:
throw new System.Exception("未处理类型");
}
}
}
}