Files
ft/Client/Assets/Scripts/EventMowForTreasure/Data/EventMowForTreasureData.cs
2026-06-29 21:18:33 +08:00

152 lines
5.1 KiB
C#

using asap.core;
using cfg;
using game;
using GameCore;
using Newtonsoft.Json;
using System.Collections.Generic;
using UnityEngine;
namespace EventMowForTreasure
{
public class EventMowForTreasureData : AEventData, IHasChainPack
{
public int GuideStep = 1;
public bool IsCompleteGuide;
public int CompletedStageAmount;
private List<int> _fixedStageList;
private Dictionary<int, int> _toolAmountPairs;
private Dictionary<int, EventMowForTreasureCollectionData> _collectionProgressPairs;
public List<int> FixedStageList => _fixedStageList ??= new List<int>();
/// <summary>
/// toolID Amount
/// </summary>
public Dictionary<int, int> ToolAmountPairs => _toolAmountPairs ??= new Dictionary<int, int>();
/// <summary>
/// collectionID Amount
/// </summary>
public Dictionary<int, EventMowForTreasureCollectionData> CollectionProgressPairs => _collectionProgressPairs ??= new Dictionary<int, EventMowForTreasureCollectionData>();
[JsonConverter(typeof(ObstacleListConverter))]
public List<EventMowForTreasureObstacleData> ObstacleList;
public EventMowForTreasureObstacleData StartObstacle;
public EventMowForTreasureObstacleData EndObstacle;
public override void SetData(IEventData idata)
{
var data = idata as EventMowForTreasureData;
if (data == null)
{
Debug.LogError("EventMowForTreasureData data is null");
return;
}
EventID = data.EventID;
InflationRate = data.InflationRate;
CompletedStageAmount = data.CompletedStageAmount;
IsCompleteGuide = data.IsCompleteGuide;
ChainProgress = data.ChainProgress;
ChainPackID = data.ChainPackID;
_fixedStageList = data.FixedStageList;
_toolAmountPairs = data._toolAmountPairs;
if (StartObstacle != null)
StartObstacle.SetData(data.StartObstacle);
else
StartObstacle = data.StartObstacle;
if (EndObstacle != null)
EndObstacle.SetData(data.EndObstacle);
else
EndObstacle = data.EndObstacle;
if (ObstacleList == null)
{
ObstacleList = data.ObstacleList;
}
else
{
for (int i = 0; i < data.ObstacleList.Count; i++)
{
var obstacleData = data.ObstacleList[i];
if (i >= ObstacleList.Count)
{
Debug.LogError("数据错误 数量不一致");
break;
}
var currentData = ObstacleList[i];
currentData.SetData(obstacleData);
}
}
if (_collectionProgressPairs == null)
_collectionProgressPairs = data._collectionProgressPairs;
else
{
foreach (var collectionProgress in data._collectionProgressPairs)
{
if (_collectionProgressPairs.TryGetValue(collectionProgress.Key, out var currentData))
currentData.SetData(collectionProgress.Value);
else
_collectionProgressPairs.Add(collectionProgress.Key, collectionProgress.Value);
}
}
if (ChainPackID == 0)
{
ChainPackID = EventMain.ChainPackID;
}
}
public void SetChainPackID()
{
if (FishingEventData.Condition_NoRechargeDay())
{
ChainPackID = EventMain.AdPackId;
}
else
{
ChainPackID = EventMain.ChainPackID;
}
}
public override void RefreshCache()
{
base.RefreshCache();
CompletedStageAmount = 0;
_fixedStageList?.Clear();
_toolAmountPairs?.Clear();
_collectionProgressPairs?.Clear();
ObstacleList?.Clear();
_fixedStageList = null;
_toolAmountPairs = null;
_collectionProgressPairs = null;
StartObstacle = null;
ObstacleList = null;
EndObstacle = null;
}
#region json ignore
[JsonIgnore]
public EventMowForTreasureMain EventMain => Tables.TbEventMowForTreasureMain.GetOrDefault(CycleItem?.RedirectID ?? 0);
[JsonIgnore] public bool IsCompletedFixedStage => FixedStageList.Count >= EventMain.FixedStageList.Count;
#endregion json ignore
[JsonIgnore] public int EventId => EventID;
public int ChainProgress;
public int ChainPackID;
public void SetChainProgress(int p)
{
ChainProgress = p;
}
public int GetChainProgress()
{
return ChainProgress;
}
public void Save()
{
GContext.Publish(this);
}
}
}