using FJson; using Framework.Save; using UnityEngine; namespace System.RandomPool { internal class RandomLogController { internal class RandomLogData : SinglePersistentData { /// /// 随机池抽取记录 /// public LiteDictionary> LocalPoolLog = new LiteDictionary> (); } private static RandomLogData _data; internal static RandomLogData Data { get { if (_data == null) { _data = new RandomLogData(); if (!_data.Load ()) { _data.LocalPoolLog = new LiteDictionary> (); } } return _data; } } internal static LiteDictionary> LocalPoolLog => Data.LocalPoolLog; /// /// 从随机池中取出 /// /// /// /// internal static int PoolPushLog (int poolId, int id) { if (!LocalPoolLog.ContainsKey (poolId)) { LocalPoolLog[poolId] = new LiteDictionary (); } 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]; } /// /// 回收到随机池中 /// /// /// 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 (); } if (!LocalPoolLog[poolId].ContainsKey (id)) { LocalPoolLog[poolId][id] = 0; } return LocalPoolLog[poolId][id]; } /// /// 用于判断是否还可以继续取出指定id /// /// /// /// /// 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; } } }