Files
taptap2024_GJ_chidouren/Assets/Scripts/System/RandomPool/RandomLogController.cs

113 lines
3.4 KiB
C#
Raw Normal View History

2024-10-16 00:03:41 +08:00
using FJson;
using Framework.Save;
using UnityEngine;
namespace System.RandomPool
{
internal class RandomLogController
{
internal class RandomLogData : SinglePersistentData<RandomLogData>
{
/// <summary>
/// 随机池抽取记录
/// </summary>
public LiteDictionary<int, LiteDictionary<int, int>> LocalPoolLog =
new LiteDictionary<int, LiteDictionary<int, int>> ();
}
private static RandomLogData _data;
internal static RandomLogData Data
{
get
{
if (_data == null)
{
_data = new RandomLogData();
if (!_data.Load ())
{
_data.LocalPoolLog = new LiteDictionary<int, LiteDictionary<int, int>> ();
}
}
return _data;
}
}
internal static LiteDictionary<int, LiteDictionary<int, int>> LocalPoolLog => Data.LocalPoolLog;
/// <summary>
/// 从随机池中取出
/// </summary>
/// <param name="poolId"></param>
/// <param name="id"></param>
/// <returns></returns>
internal static int PoolPushLog (int poolId, int id)
{
if (!LocalPoolLog.ContainsKey (poolId))
{
LocalPoolLog[poolId] = new LiteDictionary<int, int> ();
}
if (LocalPoolLog[poolId].ContainsKey (id))
{
LocalPoolLog[poolId][id] += 1;
}
else
{
LocalPoolLog[poolId][id] = 1;
}
Data.Save ();
Debug.Log ($"随机池记录增加 池id: {poolId} 物品ID: {id}, 数量: {LocalPoolLog[poolId][id]}");
return LocalPoolLog[poolId][id];
}
/// <summary>
/// 回收到随机池中
/// </summary>
/// <param name="poolId"></param>
/// <param name="id"></param>
internal static void PoolPullLog (int poolId, int id)
{
if (LocalPoolLog.ContainsKey (poolId) && LocalPoolLog[poolId].ContainsKey (id))
{
LocalPoolLog[poolId][id] -= 1;
Debug.Log ($"随机池记录减少 池id: {poolId} 物品ID: {id} , 数量: {LocalPoolLog[poolId][id]}");
}
}
internal static int GetPoolLog (int poolId, int id)
{
if (!LocalPoolLog.ContainsKey (poolId))
{
LocalPoolLog[poolId] = new LiteDictionary<int, int> ();
}
if (!LocalPoolLog[poolId].ContainsKey (id))
{
LocalPoolLog[poolId][id] = 0;
}
return LocalPoolLog[poolId][id];
}
/// <summary>
/// 用于判断是否还可以继续取出指定id
/// </summary>
/// <param name="poolId"></param>
/// <param name="id"></param>
/// <param name="maskCount"></param>
/// <returns></returns>
internal static bool IsPush (int poolId, int id, int maskCount)
{
if (maskCount == -1)
{
return true;
}
var i = GetPoolLog (poolId, id);
return i != -1 && i < maskCount;
}
}
}