* Give moldy food the "Trash" tag (#29380) Make moldy food items have the "Trash" tag, so they can be collected. * Add "Structure" tag to switches, buttons, and levers (#29378) shit Co-authored-by: Eoin Mcloughlin <helloworld@eoinrul.es> * Revamped Meteor Swarm (#28974) * meteor code and balanced values * Meteor Swarms * Update meteors.yml * Update meteors.yml * HOO! (fix overkill bug and buff space dust) * undo BloodstreamComponent.cs changes * DamageDistribution -> DamageTypes * part 2. * meteor fixes * improve meteor spawning (#29057) * Decrease meteor frequency (#29194) * Make Projectiles Only Hit a Variety of Station Objects Unless Clicked on (#28571) * Revert "Make Projectiles Only Hit a Variety of Station Objects Unless Clicked on (#28571)" This reverts commit 4f934f02f17ce55cabc03b965eb1df7738d63148. * Makes machine parts stackable, removes unused field in stack prototypes (#28434) * Makes machine parts stacks, removes unused field in stack prototypes * forgor * Fix tests * Fixes lathe construction. Yes. This sucks but there's no better way that doesnt involve refactoring machine parts completely * detail * a * Add pressure and temperature warning text to firelocks (#28341) * fix firelocks * missing nukies can be filled in by ghost roles (#28316) * Revert "missing nukies can be filled in by ghost roles (#28316)" This reverts commit 99f13e1e45bc778a4941316fde5d89d7b91337ce. * welding gas mask (#27108) * welding gas mask * eek * Canes + Cane Blade for Syndicate Librarians (#25873) * Cane + Cane Blade * Add - type: ContainerContainer * Add another - type: ContainerContainer * Fix and add proper ContainerContainer component * Add UserInterface component * Remove Space * Stat Changes * review --------- Co-authored-by: metalgearsloth <comedian_vs_clown@hotmail.com> * Fix stupid NPC. (#26868) * init commit * Review --------- Co-authored-by: metalgearsloth <comedian_vs_clown@hotmail.com> * fixes --------- Co-authored-by: VeritableCalamity <34698192+Veritable-Calamity@users.noreply.github.com> Co-authored-by: eoineoineoin <github@eoinrul.es> Co-authored-by: Nemanja <98561806+EmoGarbage404@users.noreply.github.com> Co-authored-by: Cojoke <83733158+Cojoke-dot@users.noreply.github.com> Co-authored-by: AJCM-git <60196617+AJCM-git@users.noreply.github.com> Co-authored-by: ShadowCommander <10494922+ShadowCommander@users.noreply.github.com> Co-authored-by: deltanedas <39013340+deltanedas@users.noreply.github.com> Co-authored-by: Ps3Moira <113228053+ps3moira@users.noreply.github.com> Co-authored-by: metalgearsloth <comedian_vs_clown@hotmail.com> Co-authored-by: Vigers Ray <60344369+VigersRay@users.noreply.github.com>
150 lines
4.6 KiB
C#
150 lines
4.6 KiB
C#
using System.Diagnostics.CodeAnalysis;
|
|
using System.Linq;
|
|
using Content.Server.GameTicking.Rules.Components;
|
|
using Content.Server.Station.Components;
|
|
using Robust.Shared.Collections;
|
|
using Robust.Shared.Map;
|
|
using Robust.Shared.Map.Components;
|
|
using Robust.Shared.Random;
|
|
|
|
namespace Content.Server.GameTicking.Rules;
|
|
|
|
public abstract partial class GameRuleSystem<T> where T: IComponent
|
|
{
|
|
protected EntityQueryEnumerator<ActiveGameRuleComponent, T, GameRuleComponent> QueryActiveRules()
|
|
{
|
|
return EntityQueryEnumerator<ActiveGameRuleComponent, T, GameRuleComponent>();
|
|
}
|
|
|
|
protected bool TryRoundStartAttempt(RoundStartAttemptEvent ev, string localizedPresetName)
|
|
{
|
|
var query = EntityQueryEnumerator<ActiveGameRuleComponent, T, GameRuleComponent>();
|
|
while (query.MoveNext(out _, out _, out _, out var gameRule))
|
|
{
|
|
var minPlayers = gameRule.MinPlayers;
|
|
if (!ev.Forced && ev.Players.Length < minPlayers)
|
|
{
|
|
ChatManager.SendAdminAnnouncement(Loc.GetString("preset-not-enough-ready-players",
|
|
("readyPlayersCount", ev.Players.Length), ("minimumPlayers", minPlayers),
|
|
("presetName", localizedPresetName)));
|
|
ev.Cancel();
|
|
continue;
|
|
}
|
|
|
|
if (ev.Players.Length == 0)
|
|
{
|
|
ChatManager.DispatchServerAnnouncement(Loc.GetString("preset-no-one-ready"));
|
|
ev.Cancel();
|
|
}
|
|
}
|
|
|
|
return !ev.Cancelled;
|
|
}
|
|
|
|
/// <summary>
|
|
/// Utility function for finding a random event-eligible station entity
|
|
/// </summary>
|
|
protected bool TryGetRandomStation([NotNullWhen(true)] out EntityUid? station, Func<EntityUid, bool>? filter = null)
|
|
{
|
|
var stations = new ValueList<EntityUid>(Count<StationEventEligibleComponent>());
|
|
|
|
filter ??= _ => true;
|
|
var query = AllEntityQuery<StationEventEligibleComponent>();
|
|
|
|
while (query.MoveNext(out var uid, out _))
|
|
{
|
|
if (!filter(uid))
|
|
continue;
|
|
|
|
stations.Add(uid);
|
|
}
|
|
|
|
if (stations.Count == 0)
|
|
{
|
|
station = null;
|
|
return false;
|
|
}
|
|
|
|
// TODO: Engine PR.
|
|
station = stations[RobustRandom.Next(stations.Count)];
|
|
return true;
|
|
}
|
|
|
|
protected bool TryFindRandomTile(
|
|
out Vector2i tile,
|
|
[NotNullWhen(true)] out EntityUid? targetStation,
|
|
out EntityUid targetGrid,
|
|
out EntityCoordinates targetCoords)
|
|
{
|
|
tile = default;
|
|
targetStation = EntityUid.Invalid;
|
|
targetGrid = EntityUid.Invalid;
|
|
targetCoords = EntityCoordinates.Invalid;
|
|
if (TryGetRandomStation(out targetStation))
|
|
{
|
|
return TryFindRandomTileOnStation((targetStation.Value, Comp<StationDataComponent>(targetStation.Value)),
|
|
out tile,
|
|
out targetGrid,
|
|
out targetCoords);
|
|
}
|
|
|
|
return false;
|
|
}
|
|
|
|
protected bool TryFindRandomTileOnStation(Entity<StationDataComponent> station,
|
|
out Vector2i tile,
|
|
out EntityUid targetGrid,
|
|
out EntityCoordinates targetCoords)
|
|
{
|
|
tile = default;
|
|
targetCoords = EntityCoordinates.Invalid;
|
|
targetGrid = EntityUid.Invalid;
|
|
|
|
var possibleTargets = station.Comp.Grids;
|
|
if (possibleTargets.Count == 0)
|
|
{
|
|
targetGrid = EntityUid.Invalid;
|
|
return false;
|
|
}
|
|
|
|
targetGrid = RobustRandom.Pick(possibleTargets);
|
|
|
|
foreach (var target in possibleTargets.Where(HasComp<BecomesStationComponent>)) // WD
|
|
{
|
|
targetGrid = target;
|
|
break;
|
|
}
|
|
|
|
if (!TryComp<MapGridComponent>(targetGrid, out var gridComp))
|
|
return false;
|
|
|
|
var found = false;
|
|
var aabb = gridComp.LocalAABB;
|
|
|
|
for (var i = 0; i < 10; i++)
|
|
{
|
|
var randomX = RobustRandom.Next((int) aabb.Left, (int) aabb.Right);
|
|
var randomY = RobustRandom.Next((int) aabb.Bottom, (int) aabb.Top);
|
|
|
|
tile = new Vector2i(randomX, randomY);
|
|
if (_atmosphere.IsTileSpace(targetGrid, Transform(targetGrid).MapUid, tile)
|
|
|| _atmosphere.IsTileAirBlocked(targetGrid, tile, mapGridComp: gridComp))
|
|
{
|
|
continue;
|
|
}
|
|
|
|
found = true;
|
|
targetCoords = _map.GridTileToLocal(targetGrid, gridComp, tile);
|
|
break;
|
|
}
|
|
|
|
return found;
|
|
}
|
|
|
|
protected void ForceEndSelf(EntityUid uid, GameRuleComponent? component = null)
|
|
{
|
|
GameTicker.EndGameRule(uid, component);
|
|
}
|
|
|
|
}
|