mirror of
https://github.com/edgegamers/Gangs.git
synced 2025-12-05 20:40:30 -08:00
61 lines
2.1 KiB
C#
61 lines
2.1 KiB
C#
using GangsAPI.Data.Stat;
|
|
using GangsAPI.Services;
|
|
|
|
namespace Mock;
|
|
|
|
public class MockInstanceStatManager(IStatManager mgr)
|
|
: IPlayerStatManager, IGangStatManager {
|
|
private readonly Dictionary<int, Dictionary<string, IStat>> gangStats = [];
|
|
|
|
private readonly Dictionary<ulong, Dictionary<string, IStat>>
|
|
playerStats = [];
|
|
|
|
public Task<IStat<V>?> GetForGang<V>(int key, string id) {
|
|
if (!gangStats.TryGetValue(key, out var gangStatMap))
|
|
return Task.FromResult<IStat<V>?>(null);
|
|
if (!gangStatMap.TryGetValue(id, out var result))
|
|
return Task.FromResult<IStat<V>?>(null);
|
|
return Task.FromResult(result as IStat<V>);
|
|
}
|
|
|
|
public Task<IStat?> GetForGang(int key, string id) {
|
|
if (!gangStats.TryGetValue(key, out var gangStatMap))
|
|
return Task.FromResult<IStat?>(null);
|
|
if (!gangStatMap.TryGetValue(id, out var result))
|
|
return Task.FromResult<IStat?>(null);
|
|
return Task.FromResult(result)!;
|
|
}
|
|
|
|
public async Task<bool> PushToGang<V>(int gangId, string id, V value) {
|
|
if (!gangStats.TryGetValue(gangId, out var gangStatMap))
|
|
gangStats[gangId] = gangStatMap = new Dictionary<string, IStat>();
|
|
var stat = await mgr.GetStat(id);
|
|
if (stat == null) return false;
|
|
gangStatMap[id] = new MockStat<V>(stat, value);
|
|
return true;
|
|
}
|
|
|
|
public Task<IStat<V>?> GetForPlayer<V>(ulong key, string id) {
|
|
if (!playerStats.TryGetValue(key, out var playerStatMap))
|
|
return Task.FromResult<IStat<V>?>(null);
|
|
if (!playerStatMap.TryGetValue(id, out var result))
|
|
return Task.FromResult<IStat<V>?>(null);
|
|
return Task.FromResult(result as IStat<V>);
|
|
}
|
|
|
|
public async Task<bool> PushToPlayer<V>(ulong key, string id, V value) {
|
|
if (!playerStats.TryGetValue(key, out var playerStatMap))
|
|
playerStats[key] = playerStatMap = new Dictionary<string, IStat>();
|
|
var stat = await mgr.GetStat(id);
|
|
if (stat == null) return false;
|
|
playerStatMap[id] = new MockStat<V>(stat, value);
|
|
return true;
|
|
}
|
|
|
|
public void ClearCache() {
|
|
gangStats.Clear();
|
|
playerStats.Clear();
|
|
}
|
|
|
|
public Task Load() { return Task.CompletedTask; }
|
|
} |