using Content.Shared.FixedPoint;
using Robust.Shared.Network;
using Robust.Shared.Utility;
namespace Content.Shared.Points;
///
/// This handles modifying point counts for
///
public abstract class SharedPointSystem : EntitySystem
{
///
/// Adds the specified point value to a player.
///
public void AdjustPointValue(NetUserId userId, FixedPoint2 value, EntityUid uid, PointManagerComponent? component = null)
{
if (!Resolve(uid, ref component))
return;
if (!component.Points.TryGetValue(userId, out var current))
current = 0;
SetPointValue(userId, current + value, uid, component);
}
///
/// Sets the amount of points for a player
///
public void SetPointValue(NetUserId userId, FixedPoint2 value, EntityUid uid, PointManagerComponent? component = null)
{
if (!Resolve(uid, ref component))
return;
if (component.Points.TryGetValue(userId, out var current) && current == value)
return;
component.Points[userId] = value;
component.Scoreboard = GetScoreboard(uid, component);
Dirty(uid, component);
var ev = new PlayerPointChangedEvent(userId, value);
RaiseLocalEvent(uid, ref ev, true);
}
///
/// Gets the amount of points for a given player
///
public FixedPoint2 GetPointValue(NetUserId userId, EntityUid uid, PointManagerComponent? component = null)
{
if (!Resolve(uid, ref component))
return FixedPoint2.Zero;
return component.Points.TryGetValue(userId, out var value)
? value
: FixedPoint2.Zero;
}
///
/// Ensures that a player is being tracked by the PointManager, giving them a default score of 0.
///
public void EnsurePlayer(NetUserId userId, EntityUid uid, PointManagerComponent? component = null)
{
if (!Resolve(uid, ref component))
return;
if (component.Points.ContainsKey(userId))
return;
SetPointValue(userId, FixedPoint2.Zero, uid, component);
}
///
/// Returns a formatted message containing a ranking of all the currently online players and their scores.
///
public virtual FormattedMessage GetScoreboard(EntityUid uid, PointManagerComponent? component = null)
{
return new FormattedMessage();
}
}
///
/// Event raised on the point manager entity and broadcasted whenever a player's points change.
///
///
///
[ByRefEvent]
public readonly record struct PlayerPointChangedEvent(NetUserId Player, FixedPoint2 Points);