using Content.Server.Antag.Components;
+using Content.Shared.GameTicking.Components;
using Content.Server.GameTicking.Rules;
namespace Content.Server.Antag;
SubscribeLocalEvent<AntagRandomSpawnComponent, AntagSelectLocationEvent>(OnSelectLocation);
}
- private void OnSelectLocation(Entity<AntagRandomSpawnComponent> ent, ref AntagSelectLocationEvent args)
+ protected override void Added(EntityUid uid, AntagRandomSpawnComponent comp, GameRuleComponent gameRule, GameRuleAddedEvent args)
{
+ base.Added(uid, comp, gameRule, args);
+
+ // we have to select this here because AntagSelectLocationEvent is raised twice because MakeAntag is called twice
+ // once when a ghost role spawner is created and once when someone takes the ghost role
+
if (TryFindRandomTile(out _, out _, out _, out var coords))
- args.Coordinates.Add(_transform.ToMapCoordinates(coords));
+ comp.Coords = coords;
+ }
+
+ private void OnSelectLocation(Entity<AntagRandomSpawnComponent> ent, ref AntagSelectLocationEvent args)
+ {
+ if (ent.Comp.Coords != null)
+ args.Coordinates.Add(_transform.ToMapCoordinates(ent.Comp.Coords.Value));
}
}
return;
}
+ // TODO: This is really messy because this part runs twice for midround events.
+ // Once when the ghostrole spawner is created and once when a player takes it.
+ // Therefore any component subscribing to this has to make sure both subscriptions return the same value
+ // or the ghost role raffle location preview will be wrong.
+
var getPosEv = new AntagSelectLocationEvent(session, ent);
RaiseLocalEvent(ent, ref getPosEv, true);
if (getPosEv.Handled)
+using Robust.Shared.Map;
+
namespace Content.Server.Antag.Components;
/// <summary>
/// Requires <see cref="AntagSelectionComponent"/>.
/// </summary>
[RegisterComponent]
-public sealed partial class AntagRandomSpawnComponent : Component;
+public sealed partial class AntagRandomSpawnComponent : Component
+{
+ /// <summary>
+ /// Location that was picked.
+ /// </summary>
+ [DataField]
+ public EntityCoordinates? Coords;
+}