Files
back_cantanBuilding/Assets/Scripts/UI/ScratchTicket/Data/EventScratchTicketChainPackData.cs
2026-05-26 16:15:54 +08:00

106 lines
3.5 KiB
C#

using asap.core;
using cfg;
using GameCore;
using System;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.Assertions;
namespace game
{
public class EventScratchTicketChainPackData : IChainPackData
{
private const int SlotCount = 6;
private List<int> ChainList { get; set; }
private Pack[] Packs { get; set; }
public bool IsEndGame => ChainProgress > ChainList.Count - SlotCount;
public int ChainListCount => ChainList.Count;
private int m_ChainProgress = 0;
public int ChainProgress
{
set
{
EventScratchTicketDataManager dataManager = GContext.container.Resolve<EventScratchTicketDataManager>();
m_ChainProgress = value;
dataManager.SetChainProgress(m_ChainProgress);
}
get
{
EventScratchTicketDataManager dataManager = GContext.container.Resolve<EventScratchTicketDataManager>();
m_ChainProgress = dataManager.GetChainProgress();
return m_ChainProgress;
}
}
//public int ChainProgress { get; set; }
public int EventId { get; set; }
private DateTime ExpireTime { get; set; }
public TimeSpan RemainingTime => ExpireTime - ZZTimeHelper.UtcNow();
public bool IsChainPackDepleted => ChainProgress >= ChainListCount;
public bool DoNeedPackRedPoint
{
get
{
if (!IsChainPackDepleted && ChainProgress < ChainListCount)
return Packs[ChainProgress].IAPID == 0;
return false;
}
}
public string RedPointKey => RedPointName.Home_ScratchTicket + ".pack";
public EventScratchTicketChainPackData(List<int> chainList, DateTime expireTime, Pack[] packs, int eventId, int chainProgress)
{
ChainList = chainList;
ChainProgress = chainProgress;
EventId = eventId;
ExpireTime = expireTime;
Packs = packs;
}
public Pack GetChainPackByChainProgress(int chainProgress)
{
// Debug.Log($"[EventBreak] chainProgress: {chainProgress}");
return Packs[chainProgress];
}
public int GetChainProgressBySlotIdx(int slotIdx)
{
int res;
if (ChainProgress > ChainList.Count - SlotCount)
res = ChainList.Count - SlotCount + slotIdx;
else
res = ChainProgress + slotIdx;
Assert.IsTrue(res < ChainList.Count, $"Progress {res} out of range: {ChainListCount}");
// Debug.Log($"[EventBreak] slotIdx: {slotIdx}, chainProgress: {res}");
return res;
}
// Is this needed or what?
public List<int> GetTokenProgressRewardAfterAddingToken(int tokenAdded)
{
throw new NotImplementedException();
}
public void UploadData()
{
EventScratchTicketDataManager dataManager = GContext.container.Resolve<EventScratchTicketDataManager>();
dataManager.ScratchTicketData.ChainPackProgress = ChainProgress;
dataManager.SyncData();
}
public void OnBuySuccess()
{
ChainProgress++;
UploadData();
}
public List<ItemData> GetItemsByPackDropId(int dropId)
{
throw new NotImplementedException();
}
}
}