[Raid] Refactor RosterManager into Raid
This commit is contained in:
@@ -6,10 +6,11 @@ public class PlayerInfo
|
||||
|
||||
public ulong Id { get; }
|
||||
|
||||
private readonly uint _fc;
|
||||
public uint Fc
|
||||
{
|
||||
get => _fc;
|
||||
set
|
||||
init
|
||||
{
|
||||
_fc = value;
|
||||
_lastFcUpdate = DateTime.Today;
|
||||
@@ -18,8 +19,7 @@ public class PlayerInfo
|
||||
|
||||
public bool IsFcUpdateRequired => DateTime.Today - _lastFcUpdate > FcUpdateInterval;
|
||||
|
||||
private uint _fc;
|
||||
private DateTime _lastFcUpdate;
|
||||
private readonly DateTime _lastFcUpdate;
|
||||
|
||||
public PlayerInfo(ulong id, uint fc)
|
||||
{
|
||||
|
||||
@@ -6,10 +6,9 @@ public class Raid
|
||||
{
|
||||
public ulong Id { get; }
|
||||
public DateTime DateTime { get; }
|
||||
public IEnumerable<IGrouping<int, RosterPlayer>> Rosters => _players.Select(p => p.Value).GroupBy(p => p.RosterNumber);
|
||||
|
||||
private readonly RosterManager _rosterManager = new();
|
||||
|
||||
public IEnumerable<IGrouping<int, RosterPlayer>> Rosters => _rosterManager.Rosters;
|
||||
private readonly IDictionary<ulong, RosterPlayer> _players = new Dictionary<ulong, RosterPlayer>();
|
||||
|
||||
public Raid(ulong id, DateTime dateTime)
|
||||
{
|
||||
@@ -21,29 +20,39 @@ public class Raid
|
||||
#endif
|
||||
}
|
||||
|
||||
public bool AddPlayer(RosterPlayer player)
|
||||
public bool AddPlayer(RosterPlayer rosterPlayer)
|
||||
{
|
||||
return _rosterManager.AddPlayer(player);
|
||||
// TODO add logic to split player in multiple rosters
|
||||
rosterPlayer.RosterNumber = 1;
|
||||
|
||||
return _players.TryAdd(rosterPlayer.Id, rosterPlayer);
|
||||
}
|
||||
|
||||
public bool UpdatePlayer(RosterPlayer rosterPlayer)
|
||||
{
|
||||
return _rosterManager.UpdatePlayer(rosterPlayer);
|
||||
if (!_players.ContainsKey(rosterPlayer.Id))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
_players[rosterPlayer.Id] = rosterPlayer;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
public RosterPlayer GetPlayer(ulong id)
|
||||
{
|
||||
return _rosterManager.GetPlayer(id);
|
||||
return _players[id];
|
||||
}
|
||||
|
||||
public bool ContainsPlayer(ulong userId)
|
||||
{
|
||||
return _rosterManager.ContainsPlayer(userId);
|
||||
return _players.ContainsKey(userId);
|
||||
}
|
||||
|
||||
public bool RemovePlayer(ulong id)
|
||||
{
|
||||
return _rosterManager.RemovePlayer(id);
|
||||
return _players.Remove(id);
|
||||
}
|
||||
|
||||
public override bool Equals(object? other)
|
||||
|
||||
@@ -1,43 +0,0 @@
|
||||
namespace Cocotte.Modules.Raids;
|
||||
|
||||
public class RosterManager
|
||||
{
|
||||
private readonly IDictionary<ulong, RosterPlayer> _players = new Dictionary<ulong, RosterPlayer>();
|
||||
|
||||
public IEnumerable<IGrouping<int, RosterPlayer>> Rosters => _players.Select(p => p.Value).GroupBy(p => p.RosterNumber);
|
||||
|
||||
public bool AddPlayer(RosterPlayer rosterPlayer)
|
||||
{
|
||||
// TODO add logic to split player in multiple rosters
|
||||
rosterPlayer.RosterNumber = 1;
|
||||
|
||||
return _players.TryAdd(rosterPlayer.Id, rosterPlayer);
|
||||
}
|
||||
|
||||
public bool UpdatePlayer(RosterPlayer rosterPlayer)
|
||||
{
|
||||
if (!_players.ContainsKey(rosterPlayer.Id))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
_players[rosterPlayer.Id] = rosterPlayer;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
public bool RemovePlayer(ulong id)
|
||||
{
|
||||
return _players.Remove(id);
|
||||
}
|
||||
|
||||
public RosterPlayer GetPlayer(ulong id)
|
||||
{
|
||||
return _players[id];
|
||||
}
|
||||
|
||||
public bool ContainsPlayer(ulong userId)
|
||||
{
|
||||
return _players.ContainsKey(userId);
|
||||
}
|
||||
}
|
||||
@@ -1,11 +1,16 @@
|
||||
using System.Numerics;
|
||||
using System.Text;
|
||||
|
||||
namespace Cocotte.Utils;
|
||||
|
||||
public static class NumberUtils
|
||||
{
|
||||
public static string FormatSpaced<T>(this INumber<T> number) where T : INumber<T>?
|
||||
/// <summary>
|
||||
/// Return a string representation of an <see cref="IBinaryInteger{TSelf}" /> with digits separated by spaces
|
||||
/// </summary>
|
||||
/// <param name="number"></param>
|
||||
/// <typeparam name="T"></typeparam>
|
||||
/// <returns></returns>
|
||||
public static string FormatSpaced<T>(this IBinaryInteger<T> number) where T : IBinaryInteger<T>?
|
||||
{
|
||||
var stringNumber = number.ToString(null, null);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user