151 lines
4.7 KiB
C#
151 lines
4.7 KiB
C#
using cfg.ActorCfg;
|
|
using Framework;
|
|
using Gameplay.Net;
|
|
using PhxhSDK;
|
|
using System.Collections;
|
|
using System.Collections.Generic;
|
|
using UnityEngine;
|
|
|
|
/// <summary>
|
|
/// 抽卡管理器
|
|
/// </summary>
|
|
public class RaffleManager : Singlenton<RaffleManager>, IInitable
|
|
{
|
|
/// <summary>
|
|
/// 按钮数量,最多
|
|
/// </summary>
|
|
public const int RAFFLE_BUTTON_COUNT = 2;
|
|
|
|
/// <summary>
|
|
/// 抽卡券道具id集合
|
|
/// </summary>
|
|
private HashSet<int> setRaffleItemId;
|
|
/// <summary>
|
|
/// 所有卡池数据字典
|
|
/// </summary>
|
|
public Dictionary<int, RaffleData> DicRaffleData { get; private set; }
|
|
|
|
/// <summary>
|
|
/// 显示的卡池数据列表
|
|
/// </summary>
|
|
public List<RaffleData> ListShowRaffle { get; private set; }
|
|
|
|
public void Init()
|
|
{
|
|
DicRaffleData = new Dictionary<int, RaffleData>();
|
|
ListShowRaffle = new List<RaffleData>();
|
|
setRaffleItemId = new HashSet<int>();
|
|
|
|
EventManager.Instance.Register(EventManager.EventName.AllConfigLoad, LoadRaffleData);
|
|
EventManager.Instance.Register(EventManager.EventName.RaffleRefresh, RefreshData);
|
|
EventManager.Instance.Register<uint>(EventManager.EventName.ItemChange, CheckRefreshData);
|
|
}
|
|
|
|
public void Release()
|
|
{
|
|
EventManager.Instance.Unregister<uint>(EventManager.EventName.ItemChange, CheckRefreshData);
|
|
EventManager.Instance.Unregister(EventManager.EventName.RaffleRefresh, RefreshData);
|
|
EventManager.Instance.Unregister(EventManager.EventName.AllConfigLoad, LoadRaffleData);
|
|
|
|
if (null != ListShowRaffle)
|
|
{
|
|
ListShowRaffle.Clear();
|
|
ListShowRaffle = null;
|
|
}
|
|
|
|
if (null != DicRaffleData)
|
|
{
|
|
DicRaffleData.Clear();
|
|
DicRaffleData = null;
|
|
}
|
|
|
|
if (null != setRaffleItemId)
|
|
{
|
|
setRaffleItemId.Clear();
|
|
setRaffleItemId = null;
|
|
}
|
|
}
|
|
|
|
/// <summary>
|
|
/// 抽卡
|
|
/// </summary>
|
|
public void Raffle(RaffleButtonData data)
|
|
{
|
|
if (data.IsFreeOne || data.IsTicketRaffle)
|
|
{
|
|
NetHelper.Raffle((uint)data.Cfg.Id, data.IsFreeOne, (uint)data.Count);
|
|
return;
|
|
}
|
|
|
|
|
|
|
|
/*DataItem itemData = TableManager.Instance.Tables.Item.Get(data.CostId);
|
|
if (Actor.Instance.Item.GetItemCount(data.CostId) < (uint)data.SingleCost)
|
|
{
|
|
if (null != itemData)
|
|
{
|
|
UITipsManager.ShowConfirmOne(CommonUtils.GetLocalizeText("ui_tip"), // 提示
|
|
string.Format(CommonUtils.GetLocalizeText("Gacha_ItemNotEnough"), CommonUtils.GetLocalizeText(itemData.NameLocal)),
|
|
null); // 准尉,您的{0}和{1}目前储量不足,请通过商店补给后再来进行招募吧
|
|
}
|
|
return;
|
|
}
|
|
|
|
if (null == drawData)
|
|
drawData = new(curTab.RaffleData.Cfg);
|
|
else
|
|
drawData.Reset(curTab.RaffleData.Cfg);
|
|
|
|
if (data.IsMoney)
|
|
{
|
|
UITipsManager.ShowConfirmTwo(CommonUtils.GetLocalizeText("ui_tip"), // 提示
|
|
string.Format(CommonUtils.GetLocalizeText("Gacha_DiamondDrawTip"), CommonUtils.GetLocalizeText(itemData.NameLocal), data.SingleCost), // 是否花费{0}x{1}抽取
|
|
CommonUtils.GetLocalizeText("ui_yes"), // 是
|
|
CommonUtils.GetLocalizeText("ui_no"), // 否
|
|
() => { NetHelper.Raffle((uint)curTab.RaffleData.Cfg.Id, data.IsFreeOne, (uint)data.ServerData); });
|
|
}
|
|
else
|
|
{
|
|
NetHelper.Raffle((uint)curTab.RaffleData.Cfg.Id, data.IsFreeOne, (uint)data.ServerData);
|
|
}*/
|
|
}
|
|
|
|
/// <summary>
|
|
/// 加载卡池数据
|
|
/// </summary>
|
|
private void LoadRaffleData()
|
|
{
|
|
for (int i = 0; i < TableManager.Instance.Tables.Gacha.DataList.Count; ++i)
|
|
{
|
|
DataGacha dataGacha = TableManager.Instance.Tables.Gacha.DataList[i];
|
|
DicRaffleData[TableManager.Instance.Tables.Gacha.DataList[i].Id] = new RaffleData(dataGacha);
|
|
setRaffleItemId.Add(dataGacha.TicketItemID);
|
|
}
|
|
}
|
|
|
|
/// <summary>
|
|
/// 刷新数据
|
|
/// </summary>
|
|
private void RefreshData()
|
|
{
|
|
ListShowRaffle.Clear();
|
|
foreach (RaffleData raffleData in DicRaffleData.Values)
|
|
{
|
|
raffleData.Refresh();
|
|
if (raffleData.CanRaffle)
|
|
ListShowRaffle.Add(raffleData);
|
|
}
|
|
}
|
|
|
|
/// <summary>
|
|
/// 检测是否刷新数据
|
|
/// </summary>
|
|
/// <returns></returns>
|
|
private void CheckRefreshData(uint itemID)
|
|
{
|
|
if (!setRaffleItemId.Contains((int)itemID)) // 只有抽卡券才刷新数据
|
|
return;
|
|
|
|
RefreshData();
|
|
}
|
|
} |