|
1 | 1 | using Content.Server.Antag;
|
| 2 | +using Content.Server.Chat.Systems; |
2 | 3 | using Content.Server.GameTicking.Rules.Components;
|
3 | 4 | using Content.Server.Roles;
|
4 | 5 | using Content.Shared.Humanoid;
|
| 6 | +using Content.Server.Communications; |
| 7 | +using Content.Server.Forensics; |
| 8 | +using Content.Server.Station.Systems; |
| 9 | +using Content.Server.StationEvents.Components; |
| 10 | +using Content.Server.StationEvents.Events; |
| 11 | +using Content.Shared.GameTicking.Components; |
| 12 | +using Content.Shared.Ghost; |
| 13 | +using Content.Shared.Hands.EntitySystems; |
| 14 | +using Content.Shared.Humanoid; |
| 15 | +using Content.Shared.Humanoid.Prototypes; |
| 16 | +using Content.Shared.Inventory; |
| 17 | +using Content.Shared.Paper; |
| 18 | +using Content.Shared.Popups; |
| 19 | +using Content.Shared.Random.Helpers; |
| 20 | +using Content.Shared.Storage.EntitySystems; |
| 21 | +using Robust.Shared.Physics.Components; |
| 22 | +using Robust.Shared.Prototypes; |
| 23 | +using Robust.Shared.Utility; |
5 | 24 |
|
6 | 25 | namespace Content.Server.GameTicking.Rules;
|
7 | 26 |
|
8 | 27 | /// <summary>
|
9 | 28 | /// Copy of ThiefRuleSystem
|
10 | 29 | /// </summary>
|
11 |
| -public sealed class RoundstartFugitiveRuleSystem : GameRuleSystem<RoundstartFugitiveRuleComponent> |
| 30 | +public sealed class RoundstartFugitiveRuleSystem : GameRuleSystem<RoundstartFugitiveRuleComponent> //Also need this somehow: StationEventSystem : StationEventSystem<FugitiveRuleComponent> |
12 | 31 | {
|
13 | 32 | [Dependency] private readonly AntagSelectionSystem _antag = default!;
|
| 33 | + [Dependency] private readonly InventorySystem _inventory = default!; |
| 34 | + [Dependency] private readonly PaperSystem _paper = default!; |
| 35 | + [Dependency] private readonly SharedHandsSystem _hands = default!; |
| 36 | + [Dependency] private readonly SharedPopupSystem _popup = default!; |
| 37 | + [Dependency] private readonly SharedStorageSystem _storage = default!; |
| 38 | + |
14 | 39 |
|
15 | 40 | public override void Initialize()
|
16 | 41 | {
|
@@ -52,6 +77,148 @@ private string MakeBriefing(EntityUid ent)
|
52 | 77 | return briefing;
|
53 | 78 | }
|
54 | 79 | // Copy of parts from FugitiveRules below here, hopefully this will cause the Fugitive Fax event to trigger?
|
| 80 | + |
| 81 | + protected override void ActiveTick(EntityUid uid, RoundstartFugitiveRuleComponent comp, GameRuleComponent rule, float frameTime) |
| 82 | + { |
| 83 | + if (comp.NextAnnounce is not {} next || next > Timing.CurTime) |
| 84 | + return; |
| 85 | + |
| 86 | + var announcement = Loc.GetString(comp.Announcement); |
| 87 | + var sender = Loc.GetString(comp.Sender); |
| 88 | + ChatSystem.DispatchGlobalAnnouncement(announcement, sender: sender, colorOverride: comp.Color); |
| 89 | + |
| 90 | + // send the report to every comms console on the station |
| 91 | + var query = EntityQueryEnumerator<TransformComponent, CommunicationsConsoleComponent>(); |
| 92 | + var consoles = new List<TransformComponent>(); |
| 93 | + while (query.MoveNext(out var console, out var xform, out _)) |
| 94 | + { |
| 95 | + if (StationSystem.GetOwningStation(console, xform) != comp.Station || HasComp<GhostComponent>(console)) |
| 96 | + continue; |
| 97 | + |
| 98 | + consoles.Add(xform); |
| 99 | + } |
| 100 | + |
| 101 | + foreach (var xform in consoles) |
| 102 | + { |
| 103 | + SpawnReport(comp, xform); |
| 104 | + } |
| 105 | + |
| 106 | + // prevent any possible funnies |
| 107 | + comp.NextAnnounce = null; |
| 108 | + |
| 109 | + RemCompDeferred(uid, comp); |
| 110 | + } |
| 111 | + |
| 112 | + private void OnEntitySelected(Entity<RoundstartFugitiveRuleComponent> ent, ref AfterAntagEntitySelectedEvent args) |
| 113 | + { |
| 114 | + var (uid, comp) = ent; |
| 115 | + if (comp.NextAnnounce != null) |
| 116 | + { |
| 117 | + Log.Error("Fugitive rule spawning multiple fugitives isn't supported, sorry."); |
| 118 | + return; |
| 119 | + } |
| 120 | + |
| 121 | + var fugi = args.EntityUid; |
| 122 | + comp.Report = GenerateReport(fugi, comp).ToMarkup(); |
| 123 | + comp.Station = StationSystem.GetOwningStation(fugi); |
| 124 | + comp.NextAnnounce = Timing.CurTime + comp.AnnounceDelay; |
| 125 | + |
| 126 | + _popup.PopupEntity(Loc.GetString("fugitive-spawn"), fugi, fugi); |
| 127 | + |
| 128 | + // give the fugi a report so they know what their charges are |
| 129 | + var report = SpawnReport(comp, Transform(fugi)); |
| 130 | + |
| 131 | + // try to insert it into their bag |
| 132 | + if (_inventory.TryGetSlotEntity(fugi, "back", out var backpack)) |
| 133 | + { |
| 134 | + _storage.Insert(backpack.Value, report, out _, playSound: false); |
| 135 | + } |
| 136 | + else |
| 137 | + { |
| 138 | + // no bag somehow, at least pick it up |
| 139 | + _hands.TryPickup(fugi, report); |
| 140 | + } |
| 141 | + } |
| 142 | + |
| 143 | + private Entity<PaperComponent> SpawnReport(RoundstartFugitiveRuleComponent rule, TransformComponent xform) |
| 144 | + { |
| 145 | + var report = Spawn(rule.ReportPaper, xform.Coordinates); |
| 146 | + var paper = Comp<PaperComponent>(report); |
| 147 | + var ent = (report, paper); |
| 148 | + _paper.SetContent(ent, rule.Report); |
| 149 | + return ent; |
| 150 | + } |
| 151 | + |
| 152 | + private FormattedMessage GenerateReport(EntityUid uid, RoundstartFugitiveRuleComponent rule) |
| 153 | + { |
| 154 | + var report = new FormattedMessage(); |
| 155 | + report.PushMarkup(Loc.GetString("fugitive-report-title")); |
| 156 | + report.PushNewline(); |
| 157 | + report.PushMarkup(Loc.GetString("fugitive-report-first-line")); |
| 158 | + report.PushNewline(); |
| 159 | + |
| 160 | + if (!TryComp<HumanoidAppearanceComponent>(uid, out var humanoid)) |
| 161 | + { |
| 162 | + report.AddMarkup(Loc.GetString("fugitive-report-inhuman", ("name", uid))); |
| 163 | + return report; |
| 164 | + } |
| 165 | + |
| 166 | + var species = PrototypeManager.Index(humanoid.Species); |
| 167 | + |
| 168 | + report.PushMarkup(Loc.GetString("fugitive-report-morphotype", ("species", Loc.GetString(species.Name)))); |
| 169 | + report.PushMarkup(Loc.GetString("fugitive-report-age", ("age", humanoid.Age))); |
| 170 | + report.PushMarkup(Loc.GetString("fugitive-report-sex", ("sex", humanoid.Sex.ToString()))); |
| 171 | + |
| 172 | + if (TryComp<PhysicsComponent>(uid, out var physics)) |
| 173 | + report.PushMarkup(Loc.GetString("fugitive-report-weight", ("weight", Math.Round(physics.FixturesMass)))); |
| 174 | + |
| 175 | + // add a random identifying quality that officers can use to track them down |
| 176 | + report.PushMarkup(RobustRandom.Next(0, 2) switch |
| 177 | + { |
| 178 | + 0 => Loc.GetString("fugitive-report-detail-dna", ("dna", GetDNA(uid))), |
| 179 | + _ => Loc.GetString("fugitive-report-detail-prints", ("prints", GetPrints(uid))) |
| 180 | + }); |
| 181 | + |
| 182 | + report.PushNewline(); |
| 183 | + report.PushMarkup(Loc.GetString("fugitive-report-crimes-header")); |
| 184 | + |
| 185 | + // generate some random crimes to avoid this situation |
| 186 | + // "officer what are my charges?" |
| 187 | + // "uh i dunno a piece of paper said to arrest you thats it" |
| 188 | + AddCharges(report, rule); |
| 189 | + |
| 190 | + report.PushNewline(); |
| 191 | + report.AddMarkup(Loc.GetString("fugitive-report-last-line")); |
| 192 | + |
| 193 | + return report; |
| 194 | + } |
| 195 | + |
| 196 | + private string GetDNA(EntityUid uid) |
| 197 | + { |
| 198 | + return CompOrNull<DnaComponent>(uid)?.DNA ?? "?"; |
| 199 | + } |
| 200 | + |
| 201 | + private string GetPrints(EntityUid uid) |
| 202 | + { |
| 203 | + return CompOrNull<FingerprintComponent>(uid)?.Fingerprint ?? "?"; |
| 204 | + } |
| 205 | + |
| 206 | + private void AddCharges(FormattedMessage report, RoundstartFugitiveRuleComponent rule) |
| 207 | + { |
| 208 | + var crimeTypes = PrototypeManager.Index(rule.CrimesDataset); |
| 209 | + var crimes = new HashSet<LocId>(); |
| 210 | + var total = RobustRandom.Next(rule.MinCrimes, rule.MaxCrimes + 1); |
| 211 | + while (crimes.Count < total) |
| 212 | + { |
| 213 | + crimes.Add(RobustRandom.Pick(crimeTypes)); |
| 214 | + } |
| 215 | + |
| 216 | + foreach (var crime in crimes) |
| 217 | + { |
| 218 | + var count = RobustRandom.Next(rule.MinCounts, rule.MaxCounts + 1); |
| 219 | + report.PushMarkup(Loc.GetString("fugitive-report-crime", ("crime", Loc.GetString(crime)), ("count", count))); |
| 220 | + } |
| 221 | + } |
55 | 222 | }
|
56 | 223 |
|
57 | 224 |
|
0 commit comments