113 lines
4.0 KiB
C#
113 lines
4.0 KiB
C#
using UnityEngine;
|
|
using System;
|
|
using cfg;
|
|
using asap.core;
|
|
using System.Collections.Generic;
|
|
using GameCore;
|
|
public class SelectionPackData
|
|
{
|
|
private GeneralEventPackData _data = new GeneralEventPackData();
|
|
private Tables _tables = GContext.container.Resolve<Tables>();
|
|
private TbSpecialPack _spp = GContext.container.Resolve<Tables>().TbSpecialPack;
|
|
private TbEventPackManager _epm = GContext.container.Resolve<Tables>().TbEventPackManager;
|
|
public TimeSpan RemainingTime
|
|
{
|
|
get => DateTime.Parse((_tables.TbFishingEvent[_data.currentEventID].TimeDefinition as LimitedTime)
|
|
.EndTime) - ZZTimeHelper.UtcNow();
|
|
}
|
|
public int CurrentEventID => _data.currentEventID;
|
|
public int PurchaseCount { get => _data.purchaseCount; }
|
|
public int MaxPurchaseCount { get => _tables.TbEventPackManager[_data.redirectID].MaxCount; }
|
|
public int IAPID { get => _spp[_epm[_data.redirectID].VIPPackList[_data.VIPLvlWhenEventActivate][0]].IAPID[0]; }
|
|
public bool IsPackActivated
|
|
{
|
|
get
|
|
{
|
|
return _tables.TbFishingEvent.DataMap.ContainsKey(_data.currentEventID)
|
|
&& _epm.DataMap.ContainsKey(_data.redirectID)
|
|
&& _epm[_data.redirectID].PackType == 5
|
|
&& RemainingTime.TotalSeconds > 0
|
|
&& _data.purchaseCount < _epm[_data.redirectID].MaxCount;
|
|
}
|
|
}
|
|
public int RedirectID { get => _data.redirectID; }
|
|
public List<int> Selections => _data.selections;
|
|
public int PackID { get => _epm[_data.redirectID]
|
|
.VIPPackList[_data.VIPLvlWhenEventActivate][0]; }
|
|
public List<int> DropIDList => _spp[_epm[_data.redirectID]
|
|
.VIPPackList[_data.VIPLvlWhenEventActivate][0]].DropID;
|
|
public bool IsFullySelected
|
|
{
|
|
get
|
|
{
|
|
for (int i = 0; i < _spp[PackID].DropID.Count; i++)
|
|
if (_data.selections[i] == -1) return false;
|
|
return true;
|
|
}
|
|
}
|
|
public List<ItemData> RewardSelected
|
|
{
|
|
get
|
|
{
|
|
if (!IsFullySelected)
|
|
return null;
|
|
List<ItemData> res = new List<ItemData>();
|
|
for (int i = 0; i < _spp[PackID].DropID.Count; i++)
|
|
{
|
|
DropPackageList d = _tables.TbDrop[_spp[PackID].DropID[i]].DropList;
|
|
res.Add(new ItemData(d.DropIDList[_data.selections[i]],
|
|
d.DropCountList[_data.selections[i]]));
|
|
}
|
|
return res;
|
|
}
|
|
}
|
|
public void LoadData(GeneralEventPackData data)
|
|
{
|
|
_data = data;
|
|
//Debug.LogError("Debug data process in action!");
|
|
//_data.purchaseCount = 0;
|
|
//_data.selections = new List<int> { -1, -1, -1, -1 };
|
|
if (IsPackActivated)
|
|
{
|
|
GContext.container.Resolve<IFaceUIService>().AddGiftFaceUI(_data.currentEventID,
|
|
UITypes.GiftSelectionPanel, _epm[RedirectID].PackType, true);
|
|
}
|
|
}
|
|
public void SaveData()
|
|
{
|
|
PlayFabMgr.Instance.UpdateUserDataValue("GeneralEventPackData",
|
|
Newtonsoft.Json.JsonConvert.SerializeObject(_data));
|
|
}
|
|
public bool UpdateData(FishingEvent e)
|
|
{
|
|
if (_epm[_tables.TbFishingEvent[e.ID].RedirectID].PackType != 5)
|
|
{
|
|
Debug.LogError($"Fishing event ID {e.ID} is not a rod-select pack event");
|
|
return false;
|
|
}
|
|
if (_data.currentEventID != e.ID)
|
|
{
|
|
//_spp[e.RedirectID].DropID
|
|
_data = new GeneralEventPackData(
|
|
eventID: e.ID,
|
|
redirectID: e.RedirectID,
|
|
purchaseCount: 0,
|
|
vip: GContext.container.Resolve<PlayerData>().PriceLv,
|
|
selections: new List<int>() { -1, -1, -1, -1 });
|
|
SaveData();
|
|
return true;
|
|
}
|
|
return false;
|
|
}
|
|
public void AddPurchase()
|
|
{
|
|
_data.purchaseCount++;
|
|
SaveData();
|
|
}
|
|
public void UpdateSelection(int slotIdx, int rewardIdx)
|
|
{
|
|
_data.selections[slotIdx] = rewardIdx;
|
|
SaveData();
|
|
}
|
|
}
|