Space Kudzu (#5472)

This commit is contained in:
Moony
2021-11-28 20:25:36 -06:00
committed by GitHub
parent 30c87ca6b2
commit 9075cf6163
30 changed files with 617 additions and 42 deletions

View File

@@ -92,7 +92,7 @@ namespace Content.Server.StationEvents.Events
base.Startup();
// Essentially we'll pick out a target amount of gas to leak, then a rate to leak it at, then work out the duration from there.
if (TryFindRandomTile(out _targetTile))
if (TryFindRandomTile(out _targetTile, out _targetStation, out _targetGrid, out _targetCoords))
{
_foundTile = true;
@@ -168,40 +168,5 @@ namespace Content.Server.StationEvents.Events
SoundSystem.Play(Filter.Pvs(_targetCoords), "/Audio/Effects/sparks4.ogg", _targetCoords);
}
}
private bool TryFindRandomTile(out Vector2i tile)
{
tile = default;
_targetStation = _robustRandom.Pick(_entityManager.EntityQuery<StationComponent>().ToArray()).Station;
var possibleTargets = _entityManager.EntityQuery<StationComponent>()
.Where(x => x.Station == _targetStation).ToArray();
_targetGrid = _robustRandom.Pick(possibleTargets).Owner;
if (!_entityManager.TryGetComponent<IMapGridComponent>(_targetGrid!.Uid, out var gridComp))
return false;
var grid = gridComp.Grid;
var atmosphereSystem = EntitySystem.Get<AtmosphereSystem>();
var found = false;
var gridBounds = grid.WorldBounds;
var gridPos = grid.WorldPosition;
for (var i = 0; i < 10; i++)
{
var randomX = _robustRandom.Next((int) gridBounds.Left, (int) gridBounds.Right);
var randomY = _robustRandom.Next((int) gridBounds.Bottom, (int) gridBounds.Top);
tile = new Vector2i(randomX - (int) gridPos.X, randomY - (int) gridPos.Y);
if (atmosphereSystem.IsTileSpace(grid, tile) || atmosphereSystem.IsTileAirBlocked(grid, tile)) continue;
found = true;
_targetCoords = grid.GridTileToLocal(tile);
break;
}
if (!found) return false;
return true;
}
}
}

View File

@@ -0,0 +1,55 @@
using Content.Shared.Station;
using Robust.Shared.GameObjects;
using Robust.Shared.IoC;
using Robust.Shared.Localization;
using Robust.Shared.Log;
using Robust.Shared.Map;
using Robust.Shared.Maths;
using Robust.Shared.Random;
namespace Content.Server.StationEvents.Events;
public class KudzuGrowth : StationEvent
{
[Dependency] private IRobustRandom _robustRandom = default!;
[Dependency] private IEntityManager _entityManager = default!;
public override string Name => "KudzuGrowth";
public override string? StartAnnouncement =>
Loc.GetString("station-event-kudzu-growth-start-announcement");
public override string? StartAudio => "/Audio/Announcements/bloblarm.ogg";
public override int EarliestStart => 15;
public override int MinimumPlayers => 15;
// Get players to scatter a bit looking for it.
protected override float StartAfter => 50f;
// Give crew at least 9 minutes to either have it gone, or to suffer another event. Kudzu is not actually required to be dead for another event to roll.
protected override float EndAfter => 60*4;
private IEntity? _targetGrid;
private Vector2i _targetTile;
private EntityCoordinates _targetCoords;
public override void Startup()
{
base.Startup();
// Pick a place to plant the kudzu.
if (TryFindRandomTile(out _targetTile, out _, out _targetGrid, out _targetCoords, _robustRandom, _entityManager))
{
_entityManager.SpawnEntity("Kudzu", _targetCoords);
Logger.InfoS("stationevents", $"Spawning a Kudzu at {_targetTile} on {_targetGrid}");
}
// If the kudzu tile selection fails we just let the announcement happen anyways because it's funny and people
// will be hunting the non-existent, dangerous plant.
}
}

View File

@@ -1,11 +1,18 @@
using System.Linq;
using Content.Server.Administration.Logs;
using Content.Server.Atmos.EntitySystems;
using Content.Server.Chat.Managers;
using Content.Server.Station;
using Content.Shared.Administration.Logs;
using Content.Shared.Station;
using Content.Shared.Database;
using Robust.Shared.Audio;
using Robust.Shared.GameObjects;
using Robust.Shared.IoC;
using Robust.Shared.Map;
using Robust.Shared.Maths;
using Robust.Shared.Player;
using Robust.Shared.Random;
namespace Content.Server.StationEvents.Events
{
@@ -178,5 +185,45 @@ namespace Content.Server.StationEvents.Events
Running = false;
}
}
public static bool TryFindRandomTile(out Vector2i tile, out StationId targetStation, out IEntity? targetGrid, out EntityCoordinates targetCoords, IRobustRandom? robustRandom = null, IEntityManager? entityManager = null)
{
tile = default;
robustRandom ??= IoCManager.Resolve<IRobustRandom>();
entityManager ??= IoCManager.Resolve<IEntityManager>();
targetCoords = EntityCoordinates.Invalid;
targetStation = robustRandom.Pick(entityManager.EntityQuery<StationComponent>().ToArray()).Station;
var t = targetStation; // thanks C#
var possibleTargets = entityManager.EntityQuery<StationComponent>()
.Where(x => x.Station == t).ToArray();
targetGrid = robustRandom.Pick(possibleTargets).Owner;
if (!entityManager.TryGetComponent<IMapGridComponent>(targetGrid!.Uid, out var gridComp))
return false;
var grid = gridComp.Grid;
var atmosphereSystem = EntitySystem.Get<AtmosphereSystem>();
var found = false;
var gridBounds = grid.WorldBounds;
var gridPos = grid.WorldPosition;
for (var i = 0; i < 10; i++)
{
var randomX = robustRandom.Next((int) gridBounds.Left, (int) gridBounds.Right);
var randomY = robustRandom.Next((int) gridBounds.Bottom, (int) gridBounds.Top);
tile = new Vector2i(randomX - (int) gridPos.X, randomY - (int) gridPos.Y);
if (atmosphereSystem.IsTileSpace(grid, tile) || atmosphereSystem.IsTileAirBlocked(grid, tile)) continue;
found = true;
targetCoords = grid.GridTileToLocal(tile);
break;
}
if (!found) return false;
return true;
}
}
}