Merge branch 'final-version' into upupup

This commit is contained in:
Aviu00
2024-02-05 10:24:33 +03:00
1189 changed files with 31542 additions and 354012 deletions

View File

@@ -3,6 +3,7 @@ using Content.Server.Cargo.Components;
using Content.Server.Cargo.Systems;
using Content.Server.GameTicking;
using Content.Server.GameTicking.Rules.Components;
using Content.Server.Station.Components;
using Content.Server.StationEvents.Components;
using Robust.Shared.Prototypes;
@@ -46,7 +47,8 @@ public sealed class CargoGiftsRule : StationEventSystem<CargoGiftsRuleComponent>
component.TimeUntilNextGifts += 30f;
if (!TryGetRandomStation(out var station, HasComp<StationCargoOrderDatabaseComponent>))
if (!TryGetRandomStation(out var station, HasComp<StationCargoOrderDatabaseComponent>) ||
!TryComp<StationDataComponent>(station, out var stationData))
return;
if (!TryComp<StationCargoOrderDatabaseComponent>(station, out var cargoDb))
@@ -72,7 +74,8 @@ public sealed class CargoGiftsRule : StationEventSystem<CargoGiftsRuleComponent>
Loc.GetString(component.Sender),
Loc.GetString(component.Description),
Loc.GetString(component.Dest),
cargoDb
cargoDb,
stationData!
))
{
break;

View File

@@ -29,15 +29,16 @@ public sealed class ClericalErrorRule : StationEventSystem<ClericalErrorRuleComp
var min = (int) Math.Max(1, Math.Round(component.MinToRemove * recordCount));
var max = (int) Math.Max(min, Math.Round(component.MaxToRemove * recordCount));
var toRemove = RobustRandom.Next(min, max);
var keys = new List<StationRecordKey>();
var keys = new List<uint>();
for (var i = 0; i < toRemove; i++)
{
keys.Add(RobustRandom.Pick(stationRecords.Records.Keys));
}
foreach (var key in keys)
foreach (var id in keys)
{
_stationRecords.RemoveRecord(chosenStation.Value, key, stationRecords);
var key = new StationRecordKey(id, chosenStation.Value);
_stationRecords.RemoveRecord(key, stationRecords);
}
}
}

View File

@@ -29,7 +29,6 @@ public abstract partial class StationEventSystem<T> : GameRuleSystem<T> where T
[Dependency] private readonly IGameTiming _timing = default!;
[Dependency] protected readonly IMapManager MapManager = default!;
[Dependency] protected readonly IPrototypeManager PrototypeManager = default!;
[Dependency] protected readonly IRobustRandom RobustRandom = default!;
[Dependency] private readonly AtmosphereSystem _atmosphere = default!;
[Dependency] protected readonly ChatSystem ChatSystem = default!;
[Dependency] protected readonly SharedAudioSystem Audio = default!;
@@ -135,79 +134,6 @@ public abstract partial class StationEventSystem<T> : GameRuleSystem<T> where T
GameTicker.EndGameRule(uid, component);
}
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;
targetCoords = EntityCoordinates.Invalid;
if (!TryGetRandomStation(out targetStation))
{
targetStation = EntityUid.Invalid;
targetGrid = EntityUid.Invalid;
return false;
}
var possibleTargets = Comp<StationDataComponent>(targetStation.Value).Grids;
if (possibleTargets.Count == 0)
{
targetGrid = EntityUid.Invalid;
return false;
}
targetGrid = RobustRandom.Pick(possibleTargets);
if (!TryComp<MapGridComponent>(targetGrid, out var gridComp))
return false;
var found = false;
var (gridPos, _, gridMatrix) = _transform.GetWorldPositionRotationMatrix(targetGrid);
var gridBounds = gridMatrix.TransformBox(gridComp.LocalAABB);
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 (_atmosphere.IsTileSpace(targetGrid, Transform(targetGrid).MapUid, tile,
mapGridComp: gridComp)
|| _atmosphere.IsTileAirBlocked(targetGrid, tile, mapGridComp: gridComp))
{
continue;
}
found = true;
targetCoords = gridComp.GridTileToLocal(tile);
break;
}
return found;
}
public float GetSeverityModifier()
{
var ev = new GetSeverityModifierEvent();