using asap.core; using cfg; using GameCore; using Newtonsoft.Json; using System; using System.Collections.Generic; using System.Linq; using UnityEngine; namespace Assets.Scripts.UI.JigsawPuzzle { public class JigsawPuzzleData { public JigsawPuzzleData(Tables tables = null) { if (tables != null) Tables = tables; } #region json ignore [JsonIgnore] public readonly Tables Tables; [JsonIgnore] private FishingEvent FishingEvent => Tables.TbFishingEvent.GetOrDefault(EventID); [JsonIgnore] private FishingEventCycleItem CycleItem => Tables.TbFishingEventCycleItem.GetOrDefault(FishingEvent?.RedirectID??0); [JsonIgnore] public EventJigsawPuzzleMain EventMain => Tables.TbEventJigsawPuzzleMain.GetOrDefault(CycleItem?.RedirectID ?? 0); [JsonIgnore]private bool IsCompleteStartRound => CompletedRoundCount >= EventMain.StartRoundList.Count; [JsonIgnore] private int TargetRound =>IsCompleteStartRound? (CompletedRoundCount-EventMain.StartRoundList.Count) % EventMain.LoopRoundList.Count: CompletedRoundCount; [JsonIgnore] public EventJigsawPuzzleRound RoundConfig=>IsCompleteStartRound? Tables.TbEventJigsawPuzzleRound.GetOrDefault(EventMain.LoopRoundList[TargetRound]): Tables.TbEventJigsawPuzzleRound.GetOrDefault(EventMain.StartRoundList[TargetRound]); [JsonIgnore] private DateTime EndTime=>GContext.container.Resolve().GetEventEndTime(EventID); [JsonIgnore] public TimeSpan RemainingTime => EndTime - ZZTimeHelper.UtcNow().UtcNowOffset(); [JsonIgnore] private DateTime StartTime => DateTime.Parse((FishingEvent.TimeDefinition as LimitedTime)?.StartTime); [JsonIgnore] public bool IsActive => EventID > 0 && RemainingTime.TotalSeconds > 0&&StartTime<=ZZTimeHelper.UtcNow(); [JsonIgnore] public int CompletedPicCount => ProgressPairs.Count(x => (x.Value?.Count ?? 0) == 6); [JsonIgnore] public int SameFragmentExchange =>RoundConfig.SameFragmentExchange; public int FinalReward => RoundConfig.FinalReward; #endregion json ignore public int EventID { get; set; } /// /// pictureID,pieceIndex /// private Dictionary> _progressPairs; public Dictionary> ProgressPairs => _progressPairs ??= new Dictionary>(); private List _fixedInitList; public List FixedInitList => _fixedInitList ??= new List(); public int PieceRepeatAmount; public float InflationRate; public int CompletedRoundCount; public bool TryGetProgressPairsValue(int key, out List pieces) { var isSuccess = this.ProgressPairs.TryGetValue(key, out pieces); if (isSuccess) return true; else { pieces = new List(); return this.ProgressPairs.TryAdd(key, pieces); } } public void RefreshCache() { ProgressPairs?.Clear(); // var piecePuzzleRewards = rewards.FindAll((x) => x.PictureID > 0); // piecePuzzleRewards.Sort((x, y) => x.Quality.CompareTo(y.Quality)); foreach (var id in RoundConfig.PictureList) { if (!ProgressPairs.TryAdd(id, new List())) Debug.LogError($"JigsawPuzzleData RefreshCache error id {id}"); } } public void SetData(JigsawPuzzleData data) { this.EventID = data.EventID; this._progressPairs = data.ProgressPairs; this.PieceRepeatAmount = data.PieceRepeatAmount; this._fixedInitList = data.FixedInitList; this.InflationRate= data.InflationRate; this.CompletedRoundCount = data.CompletedRoundCount; } } }