Skip to content

Commit aa2c36d

Browse files
moonheart08EmoGarbage404
authored andcommitted
Fix pirates. Whoops. (space-wizards#8623)
* Fix pirates. Whoops. * Remove debug logs.
1 parent 876212b commit aa2c36d

3 files changed

Lines changed: 289 additions & 282 deletions

File tree

Content.Server/GameTicking/Rules/PiratesRuleSystem.cs

Lines changed: 33 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -34,15 +34,22 @@ public sealed class PiratesRuleSystem : GameRuleSystem
3434
[Dependency] private readonly RoundEndSystem _roundEndSystem = default!;
3535
[Dependency] private readonly PricingSystem _pricingSystem = default!;
3636

37+
[ViewVariables]
3738
private List<Mind.Mind> _pirates = new();
39+
[ViewVariables]
3840
private EntityUid _pirateShip = EntityUid.Invalid;
41+
[ViewVariables]
42+
private HashSet<EntityUid> _initialItems = new();
43+
[ViewVariables]
3944
private double _initialShipValue;
4045

4146
public override string Prototype => "Pirates";
4247

4348
/// <inheritdoc/>
4449
public override void Initialize()
4550
{
51+
base.Initialize();
52+
4653
SubscribeLocalEvent<RulePlayerSpawningEvent>(OnPlayerSpawningEvent);
4754
SubscribeLocalEvent<RoundEndTextAppendEvent>(OnRoundEndTextEvent);
4855
}
@@ -72,6 +79,9 @@ private void OnRoundEndTextEvent(RoundEndTextAppendEvent ev)
7279
return true;
7380
}, (uid, price) =>
7481
{
82+
if (_initialItems.Contains(uid))
83+
return;
84+
7585
mostValuableThefts.Add((price, uid));
7686
mostValuableThefts.Sort((i1, i2) => i2.Item1.CompareTo(i1.Item1));
7787
if (mostValuableThefts.Count > 5)
@@ -86,14 +96,26 @@ private void OnRoundEndTextEvent(RoundEndTextAppendEvent ev)
8696

8797
var score = finalValue - _initialShipValue;
8898

89-
ev.AddLine(Loc.GetString("pirates-final-score", ("finalPrice", $"{finalValue:F2}"),
90-
("score", $"{score:F2}")));
99+
ev.AddLine(Loc.GetString("pirates-final-score", ("score", $"{score:F2}")));
100+
ev.AddLine(Loc.GetString("pirates-final-score-2", ("finalPrice", $"{finalValue:F2}")));
101+
102+
ev.AddLine("");
103+
ev.AddLine(Loc.GetString("pirates-most-valuable"));
104+
105+
foreach (var (price, obj) in mostValuableThefts)
106+
{
107+
ev.AddLine(Loc.GetString("pirates-stolen-item-entry", ("entity", obj), ("credits", $"{price:F2}")));
108+
}
109+
110+
if (mostValuableThefts.Count == 0)
111+
ev.AddLine(Loc.GetString("pirates-stole-nothing"));
91112
}
92113

114+
ev.AddLine("");
93115
ev.AddLine(Loc.GetString("pirates-list-start"));
94116
foreach (var pirates in _pirates)
95117
{
96-
ev.AddLine($"- {pirates.CharacterName} ({pirates.Session?.Name}");
118+
ev.AddLine($"- {pirates.CharacterName} ({pirates.Session?.Name})");
97119
}
98120
}
99121

@@ -105,9 +127,12 @@ private void OnPlayerSpawningEvent(RulePlayerSpawningEvent ev)
105127
{
106128
// Forgive me for copy-pasting nukies.
107129
if (!Enabled)
130+
{
108131
return;
132+
}
109133

110134
_pirates.Clear();
135+
_initialItems.Clear();
111136

112137
// Between 1 and <max pirate count>: needs at least n players per op.
113138
var numOps = Math.Max(1,
@@ -190,7 +215,11 @@ private void OnPlayerSpawningEvent(RulePlayerSpawningEvent ev)
190215
GameTicker.PlayerJoinGame(session);
191216
}
192217

193-
_initialShipValue = _pricingSystem.AppraiseGrid(_pirateShip); // Include the players in the appraisal.
218+
_initialShipValue = _pricingSystem.AppraiseGrid(_pirateShip, uid =>
219+
{
220+
_initialItems.Add(uid);
221+
return true;
222+
}); // Include the players in the appraisal.
194223
}
195224

196225
private void OnStartAttempt(RoundStartAttemptEvent ev)

Resources/Locale/en-US/game-ticking/game-presets/preset-pirates.ftl

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,9 @@
22
pirates-description = A group of privateers has approached your lowly station. Hostile or not, their sole goal is to end the round with as many knicknacks on their ship as they can get.
33
44
pirates-no-ship = Through unknown circumstances, the privateer's ship was completely and utterly destroyed. No score.
5-
pirates-final-score = The privateers successfully obtained {$score} credits worth of knicknacks, with their vessel being worth {$finalPrice} by the end.
5+
pirates-final-score = The privateers successfully obtained {$score} credits worth
6+
pirates-final-score-2 = of knicknacks, with a total of {$finalPrice} credits.
67
pirates-list-start = The privateers were:
78
pirates-most-valuable = The most valuable stolen items were:
9+
pirates-stolen-item-entry = {$entity} ({$credits} credits)
10+
pirates-stole-nothing = - The pirates stole absolutely nothing at all. Point and laugh.

0 commit comments

Comments
 (0)