Skip to content
This repository has been archived by the owner on Nov 1, 2024. It is now read-only.

Commit

Permalink
Merge pull request #129 from Corvax-Frontier/feature/balance-monitoring
Browse files Browse the repository at this point in the history
Feature/balance monitoring
  • Loading branch information
Vonsant authored May 6, 2024
2 parents 6a36c05 + 0018ec2 commit 710f439
Show file tree
Hide file tree
Showing 12 changed files with 81 additions and 10 deletions.
3 changes: 2 additions & 1 deletion Content.Client/Administration/AdminNameOverlay.cs
Original file line number Diff line number Diff line change
Expand Up @@ -65,8 +65,9 @@ protected override void Draw(in OverlayDrawArgs args)
{
args.ScreenHandle.DrawString(_font, screenCoordinates + (lineoffset * 2), "ANTAG", Color.OrangeRed);
}
args.ScreenHandle.DrawString(_font, screenCoordinates+lineoffset, playerInfo.Username, playerInfo.Connected ? Color.Yellow : Color.White);
args.ScreenHandle.DrawString(_font, screenCoordinates + lineoffset, playerInfo.Username, playerInfo.Connected ? Color.Yellow : Color.White);
args.ScreenHandle.DrawString(_font, screenCoordinates, playerInfo.CharacterName, playerInfo.Connected ? Color.Aquamarine : Color.White);
args.ScreenHandle.DrawString(_font, screenCoordinates + 3 * lineoffset, $"balance: {playerInfo.Balance}", playerInfo.Connected ? Color.Aquamarine : Color.White);
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,8 @@ private void RefreshPlayerList(IReadOnlyList<PlayerInfo> players)
player.Antag ? "YES" : "NO",
new StyleBoxFlat(useAltColor ? _altColor : _defaultColor),
player.Connected,
player.PlaytimeString);
player.PlaytimeString,
player.Balance);
entry.PlayerEntity = player.NetEntity;
entry.OnKeyBindDown += args => OnEntryKeyBindDown?.Invoke(entry, args);
entry.ToolTip = Loc.GetString("player-tab-entry-tooltip");
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<ContainerButton xmlns="https://spacestation14.io"
<ContainerButton xmlns="https://spacestation14.io"
xmlns:customControls="clr-namespace:Content.Client.Administration.UI.CustomControls">
<PanelContainer Name="BackgroundColorPanel"/>
<BoxContainer Orientation="Horizontal"
Expand Down Expand Up @@ -27,5 +27,9 @@
SizeFlagsStretchRatio="2"
HorizontalExpand="True"
ClipText="True"/>
<Label Name="BalanceLabel"
SizeFlagsStretchRatio="2"
HorizontalExpand="True"
ClipText="True"/>
</BoxContainer>
</ContainerButton>
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
using Robust.Client.AutoGenerated;
using Robust.Client.AutoGenerated;
using Robust.Client.Graphics;
using Robust.Client.UserInterface.Controls;
using Robust.Client.UserInterface.XAML;
Expand All @@ -10,7 +10,7 @@ public sealed partial class PlayerTabEntry : ContainerButton
{
public NetEntity? PlayerEntity;

public PlayerTabEntry(string username, string character, string identity, string job, string antagonist, StyleBox styleBox, bool connected, string overallPlaytime)
public PlayerTabEntry(string username, string character, string identity, string job, string antagonist, StyleBox styleBox, bool connected, string overallPlaytime, int balance)
{
RobustXamlLoader.Load(this);

Expand All @@ -24,5 +24,6 @@ public PlayerTabEntry(string username, string character, string identity, string
AntagonistLabel.Text = antagonist;
BackgroundColorPanel.PanelOverride = styleBox;
OverallPlaytimeLabel.Text = overallPlaytime;
BalanceLabel.Text = balance.ToString();
}
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<Control xmlns="https://spacestation14.io"
<Control xmlns="https://spacestation14.io"
xmlns:cc="clr-namespace:Content.Client.Administration.UI.CustomControls">
<PanelContainer Name="BackgroundColorPanel" Access="Public"/>
<BoxContainer Orientation="Horizontal"
Expand Down Expand Up @@ -31,11 +31,18 @@
ClipText="True"
Text="{Loc player-tab-antagonist}"
MouseFilter="Pass"/>
<cc:VSeparator/>
<Label Name="PlaytimeLabel"
SizeFlagsStretchRatio="2"
HorizontalExpand="True"
ClipText="True"
Text="{Loc player-tab-playtime}"
MouseFilter="Pass"/>
<Label Name="BalanceLabel"
SizeFlagsStretchRatio="2"
HorizontalExpand="True"
ClipText="True"
Text="{Loc player-tab-balance}"
MouseFilter="Pass"/>
</BoxContainer>
</Control>
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
using Robust.Client.AutoGenerated;
using Robust.Client.AutoGenerated;
using Robust.Client.UserInterface;
using Robust.Client.UserInterface.Controls;
using Robust.Client.UserInterface.XAML;
Expand All @@ -20,6 +20,7 @@ public PlayerTabHeader()
JobLabel.OnKeyBindDown += JobClicked;
AntagonistLabel.OnKeyBindDown += AntagonistClicked;
PlaytimeLabel.OnKeyBindDown += PlaytimeClicked;
BalanceLabel.OnKeyBindDown += BalanceClicked;
}

public Label GetHeader(Header header)
Expand All @@ -31,6 +32,7 @@ public Label GetHeader(Header header)
Header.Job => JobLabel,
Header.Antagonist => AntagonistLabel,
Header.Playtime => PlaytimeLabel,
Header.Balance => BalanceLabel,
_ => throw new ArgumentOutOfRangeException(nameof(header), header, null)
};
}
Expand All @@ -42,6 +44,7 @@ public void ResetHeaderText()
JobLabel.Text = Loc.GetString("player-tab-job");
AntagonistLabel.Text = Loc.GetString("player-tab-antagonist");
PlaytimeLabel.Text = Loc.GetString("player-tab-playtime");
BalanceLabel.Text = Loc.GetString("player-tab-balance");
}

private void HeaderClicked(GUIBoundKeyEventArgs args, Header header)
Expand Down Expand Up @@ -79,6 +82,10 @@ private void PlaytimeClicked(GUIBoundKeyEventArgs args)
{
HeaderClicked(args, Header.Playtime);
}
private void BalanceClicked(GUIBoundKeyEventArgs args)
{
HeaderClicked(args, Header.Balance);
}

protected override void Dispose(bool disposing)
{
Expand All @@ -91,6 +98,7 @@ protected override void Dispose(bool disposing)
JobLabel.OnKeyBindDown -= JobClicked;
AntagonistLabel.OnKeyBindDown -= AntagonistClicked;
PlaytimeLabel.OnKeyBindDown -= PlaytimeClicked;
BalanceLabel.OnKeyBindDown -= BalanceClicked;
}
}

Expand All @@ -100,6 +108,7 @@ public enum Header
Character,
Job,
Antagonist,
Playtime
Playtime,
Balance
}
}
18 changes: 17 additions & 1 deletion Content.Server/Administration/Systems/AdminSystem.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,11 @@
using Content.Server.Players.PlayTimeTracking;
using Content.Server.Popups;
using Content.Server.StationRecords.Systems;
using Content.Shared._NF.Bank.Events;
using Content.Shared.Administration;
using Content.Shared.Administration.Events;
using Content.Shared.Bank.Components;
using Content.Shared.Bank.Events;
using Content.Shared.CCVar;
using Content.Shared.GameTicking;
using Content.Shared.Hands.Components;
Expand Down Expand Up @@ -84,6 +87,8 @@ public override void Initialize()
SubscribeLocalEvent<RoleAddedEvent>(OnRoleEvent);
SubscribeLocalEvent<RoleRemovedEvent>(OnRoleEvent);
SubscribeLocalEvent<RoundRestartCleanupEvent>(OnRoundRestartCleanup);
SubscribeLocalEvent<BalanceChangedEvent>(OnBalanceChanged);

}

private void OnRoundRestartCleanup(RoundRestartCleanupEvent ev)
Expand Down Expand Up @@ -182,6 +187,12 @@ private void OnPlayerAttached(PlayerAttachedEvent ev)
_roundActivePlayers.Add(ev.Player.UserId);
UpdatePlayerList(ev.Player);
}
private void OnBalanceChanged(BalanceChangedEvent ev)
{
if (ev.Amount == 0)
return;
UpdatePlayerList(ev.Player);
}

public override void Shutdown()
{
Expand Down Expand Up @@ -210,11 +221,16 @@ private PlayerInfo GetPlayerInfo(SessionData data, ICommonSession? session)
var name = data.UserName;
var entityName = string.Empty;
var identityName = string.Empty;
var balance = 0;

if (session?.AttachedEntity != null)
{
entityName = EntityManager.GetComponent<MetaDataComponent>(session.AttachedEntity.Value).EntityName;
identityName = Identity.Name(session.AttachedEntity.Value, EntityManager);
if(EntityManager.TryGetComponent<BankAccountComponent>(session.AttachedEntity.Value, out var comp))
{
balance = comp.Balance;
}
}

var antag = false;
Expand All @@ -235,7 +251,7 @@ private PlayerInfo GetPlayerInfo(SessionData data, ICommonSession? session)
}

return new PlayerInfo(name, entityName, identityName, startingRole, antag, GetNetEntity(session?.AttachedEntity), data.UserId,
connected, _roundActivePlayers.Contains(data.UserId), overallPlaytime);
connected, _roundActivePlayers.Contains(data.UserId), overallPlaytime, balance);
}

private void OnPanicBunkerChanged(bool enabled)
Expand Down
15 changes: 15 additions & 0 deletions Content.Server/_NF/Bank/BankSystem.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,16 @@
using Robust.Shared.GameStates;
using Robust.Shared.Network;
using Content.Server.Cargo.Components;
using Content.Shared._NF.Bank.Events;
using Robust.Server.Player;

namespace Content.Server.Bank;

public sealed partial class BankSystem : EntitySystem
{
[Dependency] private readonly IServerPreferencesManager _prefsManager = default!;
[Dependency] private readonly IServerDbManager _dbManager = default!;
[Dependency] private readonly IPlayerManager _playerManager = default!;

private ISawmill _log = default!;

Expand All @@ -36,6 +39,10 @@ private void OnPlayerSpawn (PlayerSpawnCompleteEvent args)
var mobUid = args.Mob;
var bank = EnsureComp<BankAccountComponent>(mobUid);
bank.Balance = args.Profile.BankBalance;
if (_playerManager.TryGetSessionByEntity(mobUid, out var player))
{
RaiseLocalEvent(new BalanceChangedEvent(bank.Balance, player));
}
Dirty(bank);
}

Expand Down Expand Up @@ -114,6 +121,10 @@ public bool TryBankWithdraw(EntityUid mobUid, int amount)

bank.Balance -= amount;
_log.Info($"{mobUid} withdrew {amount}");
if (_playerManager.TryGetSessionByEntity(mobUid, out var player))
{
RaiseLocalEvent(new BalanceChangedEvent(bank.Balance, player));
}
Dirty(bank);
return true;
}
Expand All @@ -140,6 +151,10 @@ public bool TryBankDeposit(EntityUid mobUid, int amount)

bank.Balance += amount;
_log.Info($"{mobUid} deposited {amount}");
if (_playerManager.TryGetSessionByEntity(mobUid, out var player))
{
RaiseLocalEvent(new BalanceChangedEvent(bank.Balance, player));
}
Dirty(bank);
return true;
}
Expand Down
3 changes: 2 additions & 1 deletion Content.Shared/Administration/PlayerInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,8 @@ public sealed record PlayerInfo(
NetUserId SessionId,
bool Connected,
bool ActiveThisRound,
TimeSpan? OverallPlaytime)
TimeSpan? OverallPlaytime,
int Balance)
{
private string? _playtimeString;

Expand Down
14 changes: 14 additions & 0 deletions Content.Shared/_NF/Bank/Events/BalanceChangedMessage.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
using Robust.Shared.Player;

namespace Content.Shared._NF.Bank.Events;
public sealed class BalanceChangedEvent : EntityEventArgs
{
public readonly int Amount;
public readonly ICommonSession Player;

public BalanceChangedEvent(int amount, ICommonSession player)
{
Amount = amount;
Player = player;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,4 @@ player-tab-playtime = Playtime
player-tab-show-disconnected = Show Disconnected
player-tab-overlay = Overlay
player-tab-entry-tooltip = Playtime is displayed in days:hours:minutes.
player-tab-balance = Balance
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ player-tab-character = Персонаж
player-tab-job = Должность
player-tab-antagonist = Антагонист
player-tab-playtime = Игровое время
player-tab-balance = Баланс
player-tab-show-disconnected = Показать отключившихся
player-tab-overlay = Оверлей
player-tab-entry-tooltip = Игровое время отображается как дни:часы:минуты.

0 comments on commit 710f439

Please sign in to comment.