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
{
///
/// 已完成关卡数量
///
public int CompletedStageCount;
///
/// 已打开的格子索引列表
///
private List _openedGrids;
///
/// 收集进度映射 collectionID -> (round, amount)
///
private Dictionary _collectionProgressPairs;
///
/// 格子奖励映射 gridIndex -> ItemData
/// id < 0 表示收集奖励(绝对值为 collectionId),id > 0 表示普通奖励
///
private Dictionary _gridRewardMap;
public List OpenedGrids => _openedGrids ??= new List();
///
/// 格子奖励映射
///
[JsonProperty(ItemConverterType = typeof(ItemDataIgnoreCurCountConverter))]
public Dictionary GridRewardMap => _gridRewardMap ??= new Dictionary();
///
/// 收集进度映射
///
public Dictionary CollectionProgressPairs =>
_collectionProgressPairs ??= new Dictionary();
[JsonIgnore]
public EventSmashMain MainConfig => Tables.TbEventSmashMain.GetOrDefault(CycleItem?.RedirectID ?? 0);
[JsonIgnore]
public override bool IsActive => base.IsActive && MainConfig != null;
///
/// 当前进行中关卡对应的罐子 Spine 皮肤名(与 一致:CompletedStageCount 0=第1关、1=第2关…)。
/// 取自 ,下标为 CompletedStageCount % Count(例如配 6 个皮肤时第 7 关回到第 1 个)。
///
[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;
}
}
///
/// 获取收集数据,不存在则创建
///
public int GetCollectionData(int collectionID)
{
_collectionProgressPairs ??= new Dictionary();
if (_collectionProgressPairs.TryGetValue(collectionID, out var collectionData))
return collectionData.amount;
_collectionProgressPairs.Add(collectionID, (0, 0));
return 0;
}
///
/// 设置收集数据
///
public (int round, int amount) SetCollectionData(int collectionID, int amount, int? round=null)
{
_collectionProgressPairs ??= new Dictionary();
round ??= _collectionProgressPairs.TryGetValue(collectionID, out var pair) ? pair.round : 0;
return _collectionProgressPairs[collectionID] = (round.Value, amount);
}
///
/// 获取所有收集配置
///
public List GetAllCollectionConfigs()
{
return Tables.TbEventSmashCollection.DataList;
}
///
/// 获取所有奖励配置
///
public List 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;
}
}
}