Files
ft/Client/Assets/Scripts/UI/JigsawPuzzle/JigsawPuzzleData.cs
2026-06-29 21:18:33 +08:00

108 lines
4.0 KiB
C#

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<FishingEventData>().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; }
/// <summary>
/// pictureID,pieceIndex
/// </summary>
private Dictionary<int, List<int>> _progressPairs;
public Dictionary<int, List<int>> ProgressPairs => _progressPairs ??= new Dictionary<int, List<int>>();
private List<int> _fixedInitList;
public List<int> FixedInitList => _fixedInitList ??= new List<int>();
public int PieceRepeatAmount;
public float InflationRate;
public int CompletedRoundCount;
public bool TryGetProgressPairsValue(int key, out List<int> pieces)
{
var isSuccess = this.ProgressPairs.TryGetValue(key, out pieces);
if (isSuccess)
return true;
else
{
pieces = new List<int>();
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<int>()))
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;
}
}
}