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 _fixedStageList; private Dictionary _toolAmountPairs; private Dictionary _collectionProgressPairs; public List FixedStageList => _fixedStageList ??= new List(); /// /// toolID Amount /// public Dictionary ToolAmountPairs => _toolAmountPairs ??= new Dictionary(); /// /// collectionID Amount /// public Dictionary CollectionProgressPairs => _collectionProgressPairs ??= new Dictionary(); [JsonConverter(typeof(ObstacleListConverter))] public List 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); } } }