Files
ft/Client/Assets/Scripts/EventSmash/Manager/EventSmashData.cs
2026-06-29 21:18:33 +08:00

129 lines
4.4 KiB
C#
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
using System.Collections.Generic;
using Activity;
using asap.core;
using cfg;
using EventSmash.Converter;
using GameCore;
using Newtonsoft.Json;
using UnityEngine;
namespace EventSmash.Manager
{
public class EventSmashData : AEventData
{
/// <summary>
/// 已完成关卡数量
/// </summary>
public int CompletedStageCount;
/// <summary>
/// 已打开的格子索引列表
/// </summary>
private List<int> _openedGrids;
/// <summary>
/// 收集进度映射 collectionID -> (round, amount)
/// </summary>
private Dictionary<int, (int round, int amount)> _collectionProgressPairs;
/// <summary>
/// 格子奖励映射 gridIndex -> ItemData
/// id < 0 表示收集奖励(绝对值为 collectionIdid > 0 表示普通奖励
/// </summary>
private Dictionary<int, ItemData> _gridRewardMap;
public List<int> OpenedGrids => _openedGrids ??= new List<int>();
/// <summary>
/// 格子奖励映射
/// </summary>
[JsonProperty(ItemConverterType = typeof(ItemDataIgnoreCurCountConverter))]
public Dictionary<int, ItemData> GridRewardMap => _gridRewardMap ??= new Dictionary<int, ItemData>();
/// <summary>
/// 收集进度映射
/// </summary>
public Dictionary<int, (int round, int amount)> CollectionProgressPairs =>
_collectionProgressPairs ??= new Dictionary<int, (int round, int amount)>();
[JsonIgnore]
public EventSmashMain MainConfig => Tables.TbEventSmashMain.GetOrDefault(CycleItem?.RedirectID ?? 0);
[JsonIgnore]
public override bool IsActive => base.IsActive && MainConfig != null;
/// <summary>
/// 当前进行中关卡对应的罐子 Spine 皮肤名(与 <see cref="EventSmash.Manager.EventSmashManager"/> 一致:<c>CompletedStageCount</c> 0=第1关、1=第2关…
/// 取自 <see cref="EventSmashMain.StageItemIcon"/>,下标为 <c>CompletedStageCount % Count</c>(例如配 6 个皮肤时第 7 关回到第 1 个)。
/// </summary>
[JsonIgnore]
public string CurrentStageItemSkinName
{
get
{
var main = MainConfig;
if (main?.StageItemIcon == null || main.StageItemIcon.Count == 0)
return null;
int n = main.StageItemIcon.Count;
int idx = CompletedStageCount % n;
if (idx < 0) idx += n;
var name = main.StageItemIcon[idx];
return string.IsNullOrEmpty(name) ? null : name;
}
}
/// <summary>
/// 获取收集数据,不存在则创建
/// </summary>
public int GetCollectionData(int collectionID)
{
_collectionProgressPairs ??= new Dictionary<int, (int round, int amount)>();
if (_collectionProgressPairs.TryGetValue(collectionID, out var collectionData))
return collectionData.amount;
_collectionProgressPairs.Add(collectionID, (0, 0));
return 0;
}
/// <summary>
/// 设置收集数据
/// </summary>
public (int round, int amount) SetCollectionData(int collectionID, int amount, int? round=null)
{
_collectionProgressPairs ??= new Dictionary<int, (int round, int amount)>();
round ??= _collectionProgressPairs.TryGetValue(collectionID, out var pair) ? pair.round : 0;
return _collectionProgressPairs[collectionID] = (round.Value, amount);
}
/// <summary>
/// 获取所有收集配置
/// </summary>
public List<EventSmashCollection> GetAllCollectionConfigs()
{
return Tables.TbEventSmashCollection.DataList;
}
/// <summary>
/// 获取所有奖励配置
/// </summary>
public List<EventSmashReward> GetAllRewardConfigs()
{
return Tables.TbEventSmashReward.DataList;
}
public override void RefreshCache()
{
base.RefreshCache();
CompletedStageCount = 0;
_openedGrids?.Clear();
_collectionProgressPairs?.Clear();
_gridRewardMap?.Clear();
_openedGrids = null;
_collectionProgressPairs = null;
_gridRewardMap = null;
}
}
}