-
Notifications
You must be signed in to change notification settings - Fork 360
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
deltanedas
committed
Dec 21, 2024
1 parent
aa651e7
commit aacf5a1
Showing
4 changed files
with
94 additions
and
27 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,59 +1,99 @@ | ||
using Content.Server.StationEvents.Components; | ||
using Content.Server.Antag; | ||
using Content.Server.GameTicking.Rules.Components; | ||
using Content.Server.Pinpointer; | ||
using Content.Server.StationEvents.Components; | ||
using Content.Shared.GameTicking.Components; | ||
using Content.Shared.Station.Components; | ||
using Content.Shared.Storage; | ||
using Robust.Shared.Map; | ||
using Robust.Shared.Player; | ||
using Robust.Shared.Random; | ||
|
||
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> | ||
{ | ||
/* | ||
* DO NOT COPY PASTE THIS TO MAKE YOUR MOB EVENT. | ||
* USE THE PROTOTYPE. | ||
*/ | ||
|
||
protected override void Started(EntityUid uid, VentCrittersRuleComponent component, GameRuleComponent gameRule, GameRuleStartedEvent args) | ||
{ | ||
base.Started(uid, component, gameRule, args); | ||
[Dependency] private readonly AntagSelectionSystem _antag = default!; | ||
[Dependency] private readonly ISharedPlayerManager _player = default!; | ||
[Dependency] private readonly NavMapSystem _navMap = default!; | ||
[Dependency] private readonly SharedTransformSystem _transform = default!; | ||
|
||
if (!TryGetRandomStation(out var station)) | ||
private List<EntityCoordinates> _locations = new(); | ||
|
||
protected override void Added(EntityUid uid, VentCrittersRuleComponent component, GameRuleComponent gameRule, GameRuleAddedEvent args) | ||
{ | ||
PickLocation(component); | ||
if (component.Location is not {} coords) | ||
{ | ||
ForceEndSelf(uid, gameRule); | ||
return; | ||
} | ||
|
||
var locations = EntityQueryEnumerator<VentCritterSpawnLocationComponent, TransformComponent>(); | ||
var validLocations = new List<EntityCoordinates>(); | ||
while (locations.MoveNext(out _, out _, out var transform)) | ||
var mapCoords = _transform.ToMapCoordinates(coords); | ||
if (!_navMap.TryGetNearestBeacon(mapCoords, out var beacon, out _)) | ||
return; | ||
|
||
var nearest = beacon?.Comp?.Text!; | ||
Comp<StationEventComponent>(uid).StartAnnouncement = Loc.GetString("station-event-vent-creatures-start-announcement-deltav", ("location", nearest)); | ||
|
||
base.Added(uid, component, gameRule, args); | ||
} | ||
|
||
protected override void Ended(EntityUid uid, VentCrittersRuleComponent comp, GameRuleComponent gameRule, GameRuleEndedEvent args) | ||
{ | ||
base.Ended(uid, comp, gameRule, args); | ||
|
||
if (comp.Location is not {} coords) | ||
return; | ||
|
||
var players = _antag.GetTotalPlayerCount(_player.Sessions); | ||
var min = comp.Min * players / comp.PlayerRatio; | ||
var max = comp.Max * players / comp.PlayerRatio; | ||
var count = Math.Max(RobustRandom.Next(min, max), 1); | ||
for (int i = 0; i < count; i++) | ||
{ | ||
if (CompOrNull<StationMemberComponent>(transform.GridUid)?.Station == station) | ||
foreach (var spawn in EntitySpawnCollection.GetSpawns(comp.Entries, RobustRandom)) | ||
{ | ||
validLocations.Add(transform.Coordinates); | ||
foreach (var spawn in EntitySpawnCollection.GetSpawns(component.Entries, RobustRandom)) | ||
{ | ||
Spawn(spawn, transform.Coordinates); | ||
} | ||
Spawn(spawn, coords); | ||
} | ||
} | ||
|
||
if (component.SpecialEntries.Count == 0 || validLocations.Count == 0) | ||
{ | ||
if (comp.SpecialEntries.Count == 0) | ||
return; | ||
} | ||
|
||
// guaranteed spawn | ||
var specialEntry = RobustRandom.Pick(component.SpecialEntries); | ||
var specialSpawn = RobustRandom.Pick(validLocations); | ||
Spawn(specialEntry.PrototypeId, specialSpawn); | ||
var specialEntry = RobustRandom.Pick(comp.SpecialEntries); | ||
Spawn(specialEntry.PrototypeId, coords); | ||
} | ||
|
||
private void PickLocation(VentCrittersRuleComponent component) | ||
{ | ||
if (!TryGetRandomStation(out var station)) | ||
return; | ||
|
||
foreach (var location in validLocations) | ||
var locations = EntityQueryEnumerator<VentCritterSpawnLocationComponent, TransformComponent>(); | ||
_locations.Clear(); | ||
while (locations.MoveNext(out _, out _, out var transform)) | ||
{ | ||
foreach (var spawn in EntitySpawnCollection.GetSpawns(component.SpecialEntries, RobustRandom)) | ||
if (CompOrNull<StationMemberComponent>(transform.GridUid)?.Station == station) | ||
{ | ||
Spawn(spawn, location); | ||
_locations.Add(transform.Coordinates); | ||
} | ||
} | ||
|
||
if (_locations.Count > 0) | ||
component.Location = RobustRandom.Pick(_locations); | ||
} | ||
} |
1 change: 1 addition & 0 deletions
1
Resources/Locale/en-US/deltav/station-events/events/vent-critters.ftl
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
station-event-vent-creatures-start-announcement-deltav = Attention. A large influx of unknown life forms has been detected in ventilation systems near {$location}. All personnel must vacate the area immediately. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters