Skip to content

Commit

Permalink
Статистика конца раунда (#239)
Browse files Browse the repository at this point in the history
  • Loading branch information
VigersRay authored Jul 24, 2024
1 parent d28db84 commit f1aef2e
Show file tree
Hide file tree
Showing 22 changed files with 1,079 additions and 3 deletions.
3 changes: 2 additions & 1 deletion Content.Client/RoundEnd/RoundEndSummaryUIController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ public sealed class RoundEndSummaryUIController : UIController,
IOnSystemLoaded<ClientGameTicker>
{
[Dependency] private readonly IInputManager _input = default!;
[Dependency] private readonly ISharedPlayerManager _playerManager = default!;

private RoundEndSummaryWindow? _window;

Expand All @@ -40,7 +41,7 @@ public void OpenRoundEndSummaryWindow(RoundEndMessageEvent message)
return;

_window = new RoundEndSummaryWindow(message.GamemodeTitle, message.RoundEndText,
message.RoundDuration, message.RoundId, message.AllPlayersEndInfo, EntityManager);
message.RoundDuration, message.RoundId, message.AllPlayersEndInfo, message.RoundEndStats, message.StatisticEntries, EntityManager, _playerManager); // Sunrise-Edit
}

public void OnSystemLoaded(ClientGameTicker system)
Expand Down
82 changes: 80 additions & 2 deletions Content.Client/RoundEnd/RoundEndSummaryWindow.cs
Original file line number Diff line number Diff line change
@@ -1,9 +1,12 @@
using System.Linq;
using System.Numerics;
using Content.Client._Sunrise.StatsBoard;
using Content.Client.Message;
using Content.Shared._Sunrise.StatsBoard;
using Content.Shared.GameTicking;
using Robust.Client.UserInterface.Controls;
using Robust.Client.UserInterface.CustomControls;
using Robust.Shared.Player;
using Robust.Shared.Utility;
using static Robust.Client.UserInterface.Controls.BoxContainer;

Expand All @@ -12,14 +15,16 @@ namespace Content.Client.RoundEnd
public sealed class RoundEndSummaryWindow : DefaultWindow
{
private readonly IEntityManager _entityManager;
private readonly ISharedPlayerManager _playerManager;
public int RoundId;

public RoundEndSummaryWindow(string gm, string roundEnd, TimeSpan roundTimeSpan, int roundId,
RoundEndMessageEvent.RoundEndPlayerInfo[] info, IEntityManager entityManager)
RoundEndMessageEvent.RoundEndPlayerInfo[] info, string roundEndStats, StatisticEntry[] statisticEntries, IEntityManager entityManager, ISharedPlayerManager playerManager) // Sunrise-Edit
{
_entityManager = entityManager;
_playerManager = playerManager; // Sunrise-Edit

MinSize = SetSize = new Vector2(520, 580);
MinSize = SetSize = new Vector2(700, 600); // Sunrise-Edit

Title = Loc.GetString("round-end-summary-window-title");

Expand All @@ -31,6 +36,8 @@ public RoundEndSummaryWindow(string gm, string roundEnd, TimeSpan roundTimeSpan,

RoundId = roundId;
var roundEndTabs = new TabContainer();
roundEndTabs.AddChild(MakeRoundEndStatsTab(roundEndStats)); // Sunrise-End
roundEndTabs.AddChild(MakeRoundEndMyStatsTab(statisticEntries)); // Sunrise-End
roundEndTabs.AddChild(MakeRoundEndSummaryTab(gm, roundEnd, roundTimeSpan, roundId));
roundEndTabs.AddChild(MakePlayerManifestTab(info));

Expand Down Expand Up @@ -166,6 +173,77 @@ private BoxContainer MakePlayerManifestTab(RoundEndMessageEvent.RoundEndPlayerIn

return playerManifestTab;
}

// Sunrise-Start
private BoxContainer MakeRoundEndStatsTab(string stats)
{
var roundEndSummaryTab = new BoxContainer
{
Orientation = LayoutOrientation.Vertical,
Name = Loc.GetString("round-end-summary-window-stats-tab-title")
};

var roundEndSummaryContainerScrollbox = new ScrollContainer
{
VerticalExpand = true,
Margin = new Thickness(10)
};
var roundEndSummaryContainer = new BoxContainer
{
Orientation = LayoutOrientation.Vertical
};

//Round end text
if (!string.IsNullOrEmpty(stats))
{
var statsLabel = new RichTextLabel();
statsLabel.SetMarkup(stats);
roundEndSummaryContainer.AddChild(statsLabel);
}

roundEndSummaryContainerScrollbox.AddChild(roundEndSummaryContainer);
roundEndSummaryTab.AddChild(roundEndSummaryContainerScrollbox);

return roundEndSummaryTab;
}

private BoxContainer MakeRoundEndMyStatsTab(StatisticEntry[] statisticEntries)
{
var roundEndSummaryTab = new BoxContainer
{
Orientation = LayoutOrientation.Vertical,
Name = Loc.GetString("round-end-summary-window-my-stats-tab-title")
};

var roundEndSummaryContainerScrollbox = new ScrollContainer
{
VerticalExpand = true,
Margin = new Thickness(10),
};

var statsEntries = new StatsEntries();
foreach (var statisticEntry in statisticEntries)
{
if (statisticEntry.FirstActor != _playerManager.LocalSession!.UserId)
continue;

var statsEntry = new StatsEntry(statisticEntry.Name, statisticEntry.TotalTakeDamage,
statisticEntry.TotalTakeHeal, statisticEntry.TotalInflictedDamage,
statisticEntry.TotalInflictedHeal, statisticEntry.SlippedCount,
statisticEntry.CreamedCount, statisticEntry.DoorEmagedCount, statisticEntry.ElectrocutedCount,
statisticEntry.CuffedCount, statisticEntry.AbsorbedPuddleCount, statisticEntry.SpentTk ?? 0,
statisticEntry.DeadCount, statisticEntry.HumanoidKillCount, statisticEntry.KilledMouseCount,
statisticEntry.CuffedTime, statisticEntry.SpaceTime, statisticEntry.SleepTime,
statisticEntry.IsInteractedCaptainCard ? "Да" : "Нет");
statsEntries.AddEntry(statsEntry);
}

roundEndSummaryContainerScrollbox.AddChild(statsEntries);
roundEndSummaryTab.AddChild(roundEndSummaryContainerScrollbox);

return roundEndSummaryTab;
}
// Sunrise-End
}

}
10 changes: 10 additions & 0 deletions Content.Client/_Sunrise/StatsBoard/StatsEntries.xaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<BoxContainer xmlns="https://spacestation14.io"
Margin="0 0 0 0"
HorizontalExpand="True"
Visible="True">
<BoxContainer Name="EntriesContainer"
Orientation="Vertical"
StyleClasses="transparentItemList"
VerticalExpand="True"
HorizontalExpand="True"/>
</BoxContainer>
20 changes: 20 additions & 0 deletions Content.Client/_Sunrise/StatsBoard/StatsEntries.xaml.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
using Robust.Client.AutoGenerated;
using Robust.Client.UserInterface.Controls;
using Robust.Client.UserInterface.XAML;

namespace Content.Client._Sunrise.StatsBoard;

[GenerateTypedNameReferences]
public sealed partial class StatsEntries : BoxContainer
{
public StatsEntries()
{
RobustXamlLoader.Load(this);
IoCManager.InjectDependencies(this);
}

public void AddEntry(StatsEntry entry)
{
EntriesContainer.AddChild(entry);
}
}
14 changes: 14 additions & 0 deletions Content.Client/_Sunrise/StatsBoard/StatsEntry.xaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
<BoxContainer xmlns="https://spacestation14.io"
Margin="10 10 10 0"
HorizontalExpand="True"
Visible="True">
<PanelContainer StyleClasses="AngleRect" HorizontalExpand="True">
<BoxContainer Orientation="Vertical" HorizontalExpand="True" HorizontalAlignment="Left">
<BoxContainer Orientation="Horizontal" >
<Label Text="Персонаж: " StyleClasses="LabelKeyText"/>
<RichTextLabel Name="NameLabel"/>
</BoxContainer>
<RichTextLabel Name="StatsLabel"/>
</BoxContainer>
</PanelContainer>
</BoxContainer>
61 changes: 61 additions & 0 deletions Content.Client/_Sunrise/StatsBoard/StatsEntry.xaml.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
using Content.Client.Message;
using Robust.Client.AutoGenerated;
using Robust.Client.UserInterface.Controls;
using Robust.Client.UserInterface.XAML;

namespace Content.Client._Sunrise.StatsBoard;

[GenerateTypedNameReferences]
public sealed partial class StatsEntry : BoxContainer
{
public StatsEntry(string entityName, float takeDamage, float takeHeal, float inflictedDamage, float inflictedHeal,
float slippedCount, float creamedCount, float doorEmagedCount, float electrocutedCount, float cuffedCount,
float absorbedPuddleCount, int spentTk, float deadCount, float humanoidKillCount, float killedMouseCount,
TimeSpan cuffedTime, TimeSpan spaceTime, TimeSpan sleepTime, string interactedCaptainCard)
{
RobustXamlLoader.Load(this);
IoCManager.InjectDependencies(this);

NameLabel.SetMarkup($"{entityName}");
var statsText = "";

if (takeDamage > 0)
statsText += $"Получил урона: {takeDamage}\n";
if (takeHeal > 0)
statsText += $"Получил лечения: {takeHeal}\n";
if (inflictedDamage > 0)
statsText += $"Нанес урона: {inflictedDamage}\n";
if (inflictedHeal > 0)
statsText += $"Вылечил урона: {inflictedHeal}\n";
if (slippedCount > 0)
statsText += $"Подскользнулся {slippedCount} раз\n";
if (creamedCount > 0)
statsText += $"Кремирован {creamedCount} раз\n";
if (doorEmagedCount > 0)
statsText += $"Емагнул {doorEmagedCount} дверей\n";
if (electrocutedCount > 0)
statsText += $"Шокирован {electrocutedCount} раз\n";
if (cuffedCount > 0)
statsText += $"Закован {cuffedCount} раз\n";
if (absorbedPuddleCount > 0)
statsText += $"Убрано {absorbedPuddleCount} луж\n";
if (spentTk > 0)
statsText += $"Потрачено {spentTk} ТК\n";
if (deadCount > 0)
statsText += $"Погиб {deadCount} раз\n";
if (humanoidKillCount > 0)
statsText += $"Убил {humanoidKillCount} гуманоидов\n";
if (killedMouseCount > 0)
statsText += $"Убито мышей {killedMouseCount}\n";
if (cuffedTime > TimeSpan.Zero)
statsText += $"Был в наручниках [color=yellow]{cuffedTime.ToString("hh\\:mm\\:ss")}[/color]\n";
if (spaceTime > TimeSpan.Zero)
statsText += $"Был в космосе [color=yellow]{spaceTime.ToString("hh\\:mm\\:ss")}[/color]\n";
if (sleepTime > TimeSpan.Zero)
statsText += $"Проспал [color=yellow]{sleepTime.ToString("hh\\:mm\\:ss")}[/color]\n";

statsText += $"Трогал карту капитана: {interactedCaptainCard}";

StatsLabel.SetMarkup($"{statsText}");
}
}
5 changes: 5 additions & 0 deletions Content.Server/Construction/ConstructionSystem.Initial.cs
Original file line number Diff line number Diff line change
Expand Up @@ -395,6 +395,11 @@ public async Task<bool> TryStartItemConstruction(string prototype, EntityUid use
Transform(user).Coordinates) is not { Valid: true } item)
return false;

// Sunrise-Start
var ev = new ItemConstructionCreated(item);
RaiseLocalEvent(user, ref ev);
// Sunrise-End

// Just in case this is a stack, attempt to merge it. If it isn't a stack, this will just normally pick up
// or drop the item as normal.
_stackSystem.TryMergeToHands(item, user);
Expand Down
5 changes: 5 additions & 0 deletions Content.Server/Fluids/EntitySystems/AbsorbentSystem.cs
Original file line number Diff line number Diff line change
Expand Up @@ -323,6 +323,11 @@ private bool TryPuddleInteract(EntityUid user, EntityUid used, EntityUid target,

_melee.DoLunge(user, used, Angle.Zero, localPos, null, false);

// Sunrise-Start
var ev = new AbsorberPudleEvent(user);
RaiseLocalEvent(user, ref ev);
// Sunrise-End

return true;
}
}
9 changes: 9 additions & 0 deletions Content.Server/GameTicking/GameTicker.RoundFlow.cs
Original file line number Diff line number Diff line change
Expand Up @@ -20,13 +20,15 @@
using Robust.Shared.Player;
using Robust.Shared.Random;
using Robust.Shared.Utility;
using Content.Server.StatsBoard;

namespace Content.Server.GameTicking
{
public sealed partial class GameTicker
{
[Dependency] private readonly DiscordWebhook _discord = default!;
[Dependency] private readonly ITaskManager _taskManager = default!;
[Dependency] private readonly StatsBoardSystem _statsBoardSystem = default!;

private static readonly Counter RoundNumberMetric = Metrics.CreateCounter(
"ss14_round_number",
Expand Down Expand Up @@ -428,13 +430,20 @@ public void ShowRoundEndScoreboard(string text = "")
var listOfPlayerInfoFinal = listOfPlayerInfo.OrderBy(pi => pi.PlayerOOCName).ToArray();
var sound = RoundEndSoundCollection == null ? null : _audio.GetSound(new SoundCollectionSpecifier(RoundEndSoundCollection));

// Sunrise-Start
var roundStats = _statsBoardSystem.GetRoundStats();
var statisticEntries = _statsBoardSystem.GetStatisticEntries();
// Sunrise-End

var roundEndMessageEvent = new RoundEndMessageEvent(
gamemodeTitle,
roundEndText,
roundDuration,
RoundId,
listOfPlayerInfoFinal.Length,
listOfPlayerInfoFinal,
roundStats, // Sunrise-Edit
statisticEntries, // Sunrise-Edit
sound
);
RaiseNetworkEvent(roundEndMessageEvent);
Expand Down
10 changes: 10 additions & 0 deletions Content.Server/Nutrition/EntitySystems/CreamPieSystem.cs
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,12 @@ protected override void CreamedEntity(EntityUid uid, CreamPiedComponent creamPie
{
otherPlayers.RemovePlayer(actor.PlayerSession);
}

// Sunrise-Start
var ev = new CreamedEvent(args.Target);
RaiseLocalEvent(args.Target, ref ev);
// Sunrise-End

_popup.PopupEntity(Loc.GetString("cream-pied-component-on-hit-by-message-others", ("owner", uid), ("thrower", args.Thrown)), uid, otherPlayers, false);
}

Expand All @@ -105,3 +111,7 @@ private void OnRejuvenate(Entity<CreamPiedComponent> entity, ref RejuvenateEvent
}
}
}

// Sunrise-Edit
[ByRefEvent]
public readonly record struct CreamedEvent(EntityUid Target);
Loading

0 comments on commit f1aef2e

Please sign in to comment.