Hotfix: Fix AntagRandomSpawn location preview (#35864)
fix AntagRandomSpawn location preview
This commit is contained in:
@@ -1,4 +1,5 @@
|
||||
using Content.Server.Antag.Components;
|
||||
using Content.Shared.GameTicking.Components;
|
||||
using Content.Server.GameTicking.Rules;
|
||||
|
||||
namespace Content.Server.Antag;
|
||||
@@ -14,9 +15,20 @@ public sealed class AntagRandomSpawnSystem : GameRuleSystem<AntagRandomSpawnComp
|
||||
SubscribeLocalEvent<AntagRandomSpawnComponent, AntagSelectLocationEvent>(OnSelectLocation);
|
||||
}
|
||||
|
||||
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))
|
||||
comp.Coords = coords;
|
||||
}
|
||||
|
||||
private void OnSelectLocation(Entity<AntagRandomSpawnComponent> ent, ref AntagSelectLocationEvent args)
|
||||
{
|
||||
if (TryFindRandomTile(out _, out _, out _, out var coords))
|
||||
args.Coordinates.Add(_transform.ToMapCoordinates(coords));
|
||||
if (ent.Comp.Coords != null)
|
||||
args.Coordinates.Add(_transform.ToMapCoordinates(ent.Comp.Coords.Value));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -393,6 +393,11 @@ public sealed partial class AntagSelectionSystem : GameRuleSystem<AntagSelection
|
||||
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)
|
||||
|
||||
@@ -1,3 +1,5 @@
|
||||
using Robust.Shared.Map;
|
||||
|
||||
namespace Content.Server.Antag.Components;
|
||||
|
||||
/// <summary>
|
||||
@@ -5,4 +7,11 @@ namespace Content.Server.Antag.Components;
|
||||
/// 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;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user