Skip to content

Commit

Permalink
Merge pull request #1401 from EpicToastTM/revert-1308-vent-critters-r…
Browse files Browse the repository at this point in the history
…ework

Revert "Rework vent critters (port from Delta-V)"
  • Loading branch information
mqole authored Jan 17, 2025
2 parents d51060b + a59a24f commit a900de2
Show file tree
Hide file tree
Showing 7 changed files with 106 additions and 269 deletions.
Original file line number Diff line number Diff line change
@@ -1,50 +1,17 @@
using Content.Server.StationEvents.Events;
using Content.Shared.EntityTable.EntitySelectors;
using Content.Server.StationEvents.Events;
using Content.Shared.Storage;
using Robust.Shared.Map; // DeltaV

namespace Content.Server.StationEvents.Components;

[RegisterComponent, Access(typeof(VentCrittersRule))]
public sealed partial class VentCrittersRuleComponent : Component
{
// DeltaV: Replaced by Table
//[DataField("entries")]
//public List<EntitySpawnEntry> Entries = new();

/// <summary>
/// DeltaV: Table of possible entities to spawn.
/// </summary>
[DataField(required: true)]
public EntityTableSelector Table = default!;
[DataField("entries")]
public List<EntitySpawnEntry> Entries = new();

/// <summary>
/// At least one special entry is guaranteed to spawn
/// </summary>
[DataField("specialEntries")]
public List<EntitySpawnEntry> SpecialEntries = new();

/// <summary>
/// DeltaV: The location of the vent that got picked.
/// </summary>
[ViewVariables]
public EntityCoordinates? Location;

/// <summary>
/// DeltaV: Base minimum number of critters to spawn.
/// </summary>
[DataField]
public int Min = 2;

/// <summary>
/// DeltaV: Base maximum number of critters to spawn.
/// </summary>
[DataField]
public int Max = 3;

/// <summary>
/// DeltaV: Min and max get multiplied by the player count then divided by this.
/// </summary>
[DataField]
public int PlayerRatio = 25;
}
86 changes: 24 additions & 62 deletions Content.Server/StationEvents/Events/VentCrittersRule.cs
Original file line number Diff line number Diff line change
@@ -1,8 +1,4 @@
using Content.Server.Antag;
using Content.Server.GameTicking.Rules.Components;
using Content.Server.Pinpointer;
using Content.Server.StationEvents.Components;
using Content.Shared.EntityTable;
using Content.Shared.GameTicking.Components;
using Content.Shared.Station.Components;
using Content.Shared.Storage;
Expand All @@ -13,13 +9,6 @@

namespace Content.Server.StationEvents.Events;

/// <summary>
/// DeltaV: Reworked vent critters to spawn a number of mobs at a single telegraphed location.
/// This gives players time to run away and let sec do their job.
/// </summary>
/// <remarks>
/// This entire file is rewritten, ignore upstream changes.
/// </remarks>
public sealed class VentCrittersRule : StationEventSystem<VentCrittersRuleComponent>
{
/*
Expand All @@ -28,87 +17,60 @@ public sealed class VentCrittersRule : StationEventSystem<VentCrittersRuleCompon
*/

[Dependency] private readonly AnnouncerSystem _announcer = default!;
[Dependency] private readonly AntagSelectionSystem _antag = default!;
[Dependency] private readonly EntityTableSystem _entityTable = default!;
[Dependency] private readonly ISharedPlayerManager _player = default!;
[Dependency] private readonly NavMapSystem _navMap = default!;
[Dependency] private readonly SharedTransformSystem _transform = default!;

private List<EntityCoordinates> _locations = new();

protected override void Added(EntityUid uid, VentCrittersRuleComponent component, GameRuleComponent gameRule, GameRuleAddedEvent args)
{
base.Added(uid, component, gameRule, args);

PickLocation(component);
if (component.Location is not { } coords)
{
ForceEndSelf(uid, gameRule);
return;
}

var mapCoords = _transform.ToMapCoordinates(coords);
if (!_navMap.TryGetNearestBeacon(mapCoords, out var beacon, out _))
if (!TryGetRandomStation(out var station))
return;

var nearest = beacon?.Comp?.Text!;

_announcer.SendAnnouncement(
_announcer.GetAnnouncementId(args.RuleId),
Filter.Broadcast(),
"station-event-vent-creatures-start-announcement-deltav",
"station-event-vent-creatures-announcement",
null,
Color.Gold,
null, null,
("location", nearest)
Color.Gold
);
}

protected override void Ended(EntityUid uid, VentCrittersRuleComponent comp, GameRuleComponent gameRule, GameRuleEndedEvent args)
protected override void Started(EntityUid uid, VentCrittersRuleComponent component, GameRuleComponent gameRule, GameRuleStartedEvent args)
{
base.Ended(uid, comp, gameRule, args);
base.Started(uid, component, gameRule, args);

if (comp.Location is not { } coords)
if (!TryGetRandomStation(out var station))
return;

var players = _antag.GetTotalPlayerCount(_player.Sessions);
var min = Math.Max(comp.Min, comp.Min * players / comp.PlayerRatio);
var max = Math.Max(comp.Max, comp.Max * players / comp.PlayerRatio);
var count = Math.Max(RobustRandom.Next(min, max), 1);
Log.Info($"Spawning {count} critters for {ToPrettyString(uid):rule}");

for (int i = 0; i < count; i++)
var locations = EntityQueryEnumerator<VentCritterSpawnLocationComponent, TransformComponent>();
var validLocations = new List<EntityCoordinates>();
while (locations.MoveNext(out _, out _, out var transform))
{
foreach (var spawn in _entityTable.GetSpawns(comp.Table))
if (CompOrNull<StationMemberComponent>(transform.GridUid)?.Station == station)
{
Spawn(spawn, coords);
validLocations.Add(transform.Coordinates);
foreach (var spawn in EntitySpawnCollection.GetSpawns(component.Entries, RobustRandom))
{
Spawn(spawn, transform.Coordinates);
}
}
}

if (comp.SpecialEntries.Count == 0)
if (component.SpecialEntries.Count == 0 || validLocations.Count == 0)
{
return;
}

// guaranteed spawn
var specialEntry = RobustRandom.Pick(comp.SpecialEntries);
Spawn(specialEntry.PrototypeId, coords);
}

private void PickLocation(VentCrittersRuleComponent component)
{
if (!TryGetRandomStation(out var station))
return;
var specialEntry = RobustRandom.Pick(component.SpecialEntries);
var specialSpawn = RobustRandom.Pick(validLocations);
Spawn(specialEntry.PrototypeId, specialSpawn);

var locations = EntityQueryEnumerator<VentCritterSpawnLocationComponent, TransformComponent>();
_locations.Clear();
while (locations.MoveNext(out var uid, out _, out var transform))
foreach (var location in validLocations)
{
if (CompOrNull<StationMemberComponent>(transform.GridUid)?.Station == station)
foreach (var spawn in EntitySpawnCollection.GetSpawns(component.SpecialEntries, RobustRandom))
{
_locations.Add(transform.Coordinates);
Spawn(spawn, location);
}
}

if (_locations.Count > 0)
component.Location = RobustRandom.Pick(_locations);
}
}

This file was deleted.

This file was deleted.

This file was deleted.

Loading

0 comments on commit a900de2

Please sign in to comment.