Skip to content

Commit

Permalink
Actually fix all the bugs...
Browse files Browse the repository at this point in the history
  • Loading branch information
Just-a-Unity-Dev committed Dec 18, 2023
1 parent 83f2ff8 commit 377b9fc
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 85 deletions.
4 changes: 2 additions & 2 deletions Content.Server/_FTL/FTLPoints/Tick/StarmapTickSystem.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ namespace Content.Server._FTL.FTLPoints.Tick;

public abstract class StarmapTickSystem<T> : EntitySystem where T : Component
{
private readonly float _tickInterval = 300f;
private readonly float _tickInterval = 0f;
private float _timeSinceLastTick = 300f; // SIN

public override void Initialize()
Expand Down Expand Up @@ -46,6 +46,6 @@ public override void Update(float frameTime)
{
Ticked(uid, component, frameTime);
}
Log.Info("Tick!");
Log.Debug("Tick!");
}
}
107 changes: 24 additions & 83 deletions Content.Server/_FTL/ShipTracker/Systems/ShipTrackerSystem.cs
Original file line number Diff line number Diff line change
@@ -1,20 +1,11 @@
using System.Linq;
using Content.Server._FTL.AutomatedShip.Components;
using Content.Server._FTL.FTLPoints.Components;
using Content.Server._FTL.FTLPoints.Systems;
using Content.Server._FTL.ShipTracker.Components;
using Content.Server.AlertLevel;
using Content.Server.Atmos.EntitySystems;
using Content.Server.Chat.Systems;
using Content.Server.Shuttles.Components;
using Content.Server.Shuttles.Events;
using Content.Server.Station.Systems;
using Content.Shared._FTL.ShipTracker;
using Content.Shared.Pinpointer;
using Robust.Server.GameObjects;
using Robust.Shared.Audio;
using Robust.Shared.Map;
using Robust.Shared.Map.Components;
using Robust.Shared.Random;

namespace Content.Server._FTL.ShipTracker.Systems;

Expand All @@ -23,95 +14,44 @@ namespace Content.Server._FTL.ShipTracker.Systems;
/// </summary>
public sealed partial class ShipTrackerSystem : SharedShipTrackerSystem
{
[Dependency] private readonly AlertLevelSystem _alertLevelSystem = default!;
[Dependency] private readonly AtmosphereSystem _atmosphereSystem = default!;
[Dependency] private readonly TransformSystem _transformSystem = default!;
[Dependency] private readonly StationSystem _stationSystem = default!;
[Dependency] private readonly ChatSystem _chatSystem = default!;
[Dependency] private readonly IRobustRandom _random = default!;

public override void Initialize()
{
base.Initialize();

SubscribeLocalEvent<ShipTrackerComponent, FTLCompletedEvent>(OnFTLCompletedEvent);
SubscribeLocalEvent<ShipTrackerComponent, FTLStartedEvent>(OnFTLStartedEvent);
SubscribeLocalEvent<ShipTrackerComponent, FTLRequestEvent>(OnFTLRequestEvent);
}

private void OnFTLRequestEvent(EntityUid uid, ShipTrackerComponent component, ref FTLRequestEvent args)
{
_chatSystem.DispatchStationAnnouncement(uid, Loc.GetString("ship-ftl-jump-jumped-message"), colorOverride: Color.Gold);
}

private void OnFTLStartedEvent(EntityUid uid, ShipTrackerComponent component, ref FTLStartedEvent args)
{
_chatSystem.DispatchStationAnnouncement(uid, Loc.GetString("ship-ftl-jump-jumped-message"), colorOverride: Color.Gold);
}

private void OnFTLCompletedEvent(EntityUid uid, ShipTrackerComponent component, ref FTLCompletedEvent args)
private void BroadcastToStationsOnSameMap(
MapId map,
string message,
string sender = "Automated Ship",
bool playDefaultSound = true,
SoundSpecifier? announcementSound = null,
Color? colorOverride = null)
{
//wawawawa
// broadcast ONLY to the same map
var activeShips = EntityQuery<ShipTrackerComponent, TransformComponent>()
.Where(tuple => tuple.Item2.MapID == map);

var station = _stationSystem.GetOwningStation(args.Entity);

if (!station.HasValue)
return;

var mapId = Transform(args.MapUid).MapID;
var amount = EntityQuery<AutomatedShipComponent, TransformComponent>().Select(tuple => tuple.Item2.MapID == mapId).Count();
var hostile = EntityQuery<AutomatedShipComponent, TransformComponent>().Select(tuple => tuple.Item1.AiState == AutomatedShipComponent.AiStates.Fighting && tuple.Item2.MapID == mapId).Count();

if (amount > 0)
foreach (var ship in activeShips.ToList())
{
_chatSystem.DispatchGlobalAnnouncement(
Loc.GetString("ship-inbound-message",
("amount", amount),
("hostile", hostile > 0)
)
);

_alertLevelSystem.SetLevel(station.Value, "blue", true, true, false);
}
else
{
_chatSystem.DispatchGlobalAnnouncement(Loc.GetString("ship-ftl-jump-arrival-message"),
colorOverride: Color.Gold);
// rider im not making obsolete code for the LOVE OF GOD
_chatSystem.DispatchStationAnnouncement(ship.Item1.Owner, message, sender, playDefaultSound, announcementSound, colorOverride);
}
}

public bool TryFindRandomTile(EntityUid targetGrid, out Vector2i tile, out EntityCoordinates targetCoords)
private void OnFTLRequestEvent(EntityUid uid, ShipTrackerComponent component, ref FTLRequestEvent args)
{
tile = default;

targetCoords = EntityCoordinates.Invalid;

if (!TryComp<MapGridComponent>(targetGrid, out var gridComp))
return false;

var found = false;
var (gridPos, _, gridMatrix) = _transformSystem.GetWorldPositionRotationMatrix(targetGrid);
var gridBounds = gridMatrix.TransformBox(gridComp.LocalAABB);

for (var i = 0; i < 10; i++)
{
var randomX = _random.Next((int) gridBounds.Left, (int) gridBounds.Right);
var randomY = _random.Next((int) gridBounds.Bottom, (int) gridBounds.Top);

tile = new Vector2i(randomX - (int) gridPos.X, randomY - (int) gridPos.Y);
if (_atmosphereSystem.IsTileSpace(targetGrid, Transform(targetGrid).MapUid, tile,
mapGridComp: gridComp)
|| _atmosphereSystem.IsTileAirBlocked(targetGrid, tile, mapGridComp: gridComp))
{
continue;
}

found = true;
targetCoords = gridComp.GridTileToLocal(tile);
break;
}
BroadcastToStationsOnSameMap(Transform(uid).MapID, Loc.GetString("ship-ftl-jump-jumped-message"), colorOverride: Color.Gold);
}

return found;
private void OnFTLStartedEvent(EntityUid uid, ShipTrackerComponent component, ref FTLStartedEvent args)
{
BroadcastToStationsOnSameMap(Transform(uid).MapID, Loc.GetString("ship-ftl-jump-jumped-message"), colorOverride: Color.Gold);
}

public override void Update(float frameTime)
Expand All @@ -125,10 +65,11 @@ public override void Update(float frameTime)
if (shipTrackerComponent.Destroyed)
continue;

var active = EntityQuery<ShuttleConsoleComponent, TransformComponent>()
var xform = Transform(entity);
var activeShuttleComps = EntityQuery<ShuttleConsoleComponent, TransformComponent>()
.Count(tuple => tuple.Item2.GridUid == entity);

if (active > 0)
if (activeShuttleComps > 0)
{
// not destroyed, aka piloting is there
shipTrackerComponent.SecondsWithoutPiloting = 0f;
Expand All @@ -140,7 +81,7 @@ public override void Update(float frameTime)
continue;
shipTrackerComponent.Destroyed = true;

_chatSystem.DispatchGlobalAnnouncement(Loc.GetString("ship-destroyed-message",
BroadcastToStationsOnSameMap(xform.MapID, Loc.GetString("ship-destroyed-message",
("ship", MetaData(entity).EntityName)));
}
}
Expand Down

0 comments on commit 377b9fc

Please sign in to comment.