Skip to content
This repository has been archived by the owner on Nov 1, 2024. It is now read-only.

Commit

Permalink
Shuttle records system (new-frontiers-14#2212)
Browse files Browse the repository at this point in the history
  • Loading branch information
GreaseMonk authored Oct 23, 2024
1 parent eac776d commit b14b480
Show file tree
Hide file tree
Showing 9 changed files with 192 additions and 72 deletions.
143 changes: 80 additions & 63 deletions Content.Server/Shipyard/Systems/ShipyardSystem.Consoles.cs

Large diffs are not rendered by default.

15 changes: 8 additions & 7 deletions Content.Server/Shipyard/Systems/ShipyardSystem.cs
Original file line number Diff line number Diff line change
Expand Up @@ -113,11 +113,12 @@ private void SetShipyardEnabled(bool value)
/// </summary>
/// <param name="stationUid">The ID of the station to dock the shuttle to</param>
/// <param name="shuttlePath">The path to the shuttle file to load. Must be a grid file!</param>
public bool TryPurchaseShuttle(EntityUid stationUid, string shuttlePath, [NotNullWhen(true)] out ShuttleComponent? shuttle)
/// <param name="shuttleEntityUid">The EntityUid of the shuttle that was purchased</param>
public bool TryPurchaseShuttle(EntityUid stationUid, string shuttlePath, [NotNullWhen(true)] out EntityUid? shuttleEntityUid)
{
if (!TryComp<StationDataComponent>(stationUid, out var stationData) || !TryAddShuttle(shuttlePath, out var shuttleGrid) || !TryComp<ShuttleComponent>(shuttleGrid, out shuttle))
if (!TryComp<StationDataComponent>(stationUid, out var stationData) || !TryAddShuttle(shuttlePath, out var shuttleGrid) || !TryComp<ShuttleComponent>(shuttleGrid, out var shuttleComponent))
{
shuttle = null;
shuttleEntityUid = null;
return false;
}

Expand All @@ -128,14 +129,14 @@ public bool TryPurchaseShuttle(EntityUid stationUid, string shuttlePath, [NotNul
if (targetGrid == null) //how are we even here with no station grid
{
_mapManager.DeleteGrid((EntityUid) shuttleGrid);
shuttle = null;
shuttleEntityUid = null;
return false;
}

_sawmill.Info($"Shuttle {shuttlePath} was purchased at {ToPrettyString((EntityUid) stationUid)} for {price:f2}");
_sawmill.Info($"Shuttle {shuttlePath} was purchased at {ToPrettyString(stationUid)} for {price:f2}");
//can do TryFTLDock later instead if we need to keep the shipyard map paused
_shuttle.TryFTLDock(shuttleGrid.Value, shuttle, targetGrid.Value);

_shuttle.TryFTLDock(shuttleGrid.Value, shuttleComponent, targetGrid.Value);
shuttleEntityUid = shuttleGrid;
return true;
}

Expand Down
1 change: 0 additions & 1 deletion Content.Server/_NF/Market/Systems/MarketSystem.cs
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@ public sealed partial class MarketSystem: SharedMarketSystem
[Dependency] private readonly PricingSystem _pricingSystem = default!;
[Dependency] private readonly StackSystem _stackSystem = default!;
[Dependency] private readonly SharedPopupSystem _popup = default!;
[Dependency] private readonly SectorServiceSystem _sectorService = default!;
[Dependency] private readonly EntProtoIdWhitelistSystem _protoIdWhitelist = default!;
[Dependency] private readonly SharedAudioSystem _audio = default!;
[Dependency] private readonly StationSystem _station = default!;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
using Content.Shared._NF.ShuttleRecords;

namespace Content.Server._NF.ShuttleRecords.Components;

/// <summary>
/// A component that stores records for all shuttle purchases in the sector.
/// Note: all purchases are currently added, will need to be filtered appropriately by viewing clients.
/// </summary>
[RegisterComponent]
[Access(typeof(ShuttleRecordsSystem))]
public sealed partial class SectorShuttleRecordsComponent : Component
{
[DataField]
public List<ShuttleRecord> ShuttleRecordsList = [];
}
39 changes: 39 additions & 0 deletions Content.Server/_NF/ShuttleRecords/ShuttleRecordsSystem.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
using System.Diagnostics.CodeAnalysis;
using Content.Server._NF.SectorServices;
using Content.Server._NF.ShuttleRecords.Components;
using Content.Shared._NF.ShuttleRecords;

namespace Content.Server._NF.ShuttleRecords;

public sealed partial class ShuttleRecordsSystem : SharedShuttleRecordsSystem
{
[Dependency] private readonly IEntityManager _entityManager = default!;
[Dependency] private readonly SectorServiceSystem _sectorService = default!;


/**
* Adds a record to the shuttle records list.
* <param name="record">The record to add.</param>
*/
public void AddRecord(ShuttleRecord record)
{
if (!TryGetShuttleRecordsDataComponent(out var component))
return;

component.ShuttleRecordsList.Add(record);
}

private bool TryGetShuttleRecordsDataComponent([NotNullWhen(true)] out SectorShuttleRecordsComponent? component)
{
if (_entityManager.EnsureComponent<SectorShuttleRecordsComponent>(
uid: _sectorService.GetServiceEntity(),
out var shuttleRecordsComponent))
{
component = shuttleRecordsComponent;
return true;
}

component = null;
return false;
}
}
3 changes: 2 additions & 1 deletion Content.Shared/Shipyard/Components/ShuttleDeedComponent.cs
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
using Content.Shared._NF.ShuttleRecords;
using Robust.Shared.GameStates;

namespace Content.Shared.Shipyard.Components;

/// <summary>
/// Tied to an ID card when a ship is purchased. 1 ship per captain.
/// </summary>
[RegisterComponent, NetworkedComponent, Access(typeof(SharedShipyardSystem))]
[RegisterComponent, NetworkedComponent, Access(typeof(SharedShipyardSystem), typeof(SharedShuttleRecordsSystem))]
public sealed partial class ShuttleDeedComponent : Component
{
public const int MaxNameLength = 30;
Expand Down
11 changes: 11 additions & 0 deletions Content.Shared/_NF/ShuttleRecords/SharedShuttleRecordsSystem.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
using Content.Shared.Containers.ItemSlots;
using Robust.Shared.Audio.Systems;

namespace Content.Shared._NF.ShuttleRecords;

public abstract class SharedShuttleRecordsSystem : EntitySystem
{
// These dependencies are eventually needed for the consoles that are made for this system.
[Dependency] protected readonly ItemSlotsSystem _itemSlotsSystem = default!;
[Dependency] protected readonly SharedAudioSystem _audioSystem = default!;
}
32 changes: 32 additions & 0 deletions Content.Shared/_NF/ShuttleRecords/ShuttleRecord.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
using Robust.Shared.Serialization;

namespace Content.Shared._NF.ShuttleRecords;

/**
* A record of a shuttle that had been purchased.
* This class is NOT a indication that the shuttle is still in the game, merely a transaction record of it.
*/
[Virtual, NetSerializable, Serializable]
public class ShuttleRecord(
string name,
string suffix,
string ownerName,
NetEntity entityUid
)
{
[ViewVariables]
public string Name { get; set; } = name;

[ViewVariables]
public string? Suffix { get; set; } = suffix;

[ViewVariables]
public string OwnerName { get; set; } = ownerName;

/**
* Entity is deleted when the ship gets sold.
* Use EntityManager.EntityExists(EntityUid) to check if the entity still exists.
*/
[ViewVariables]
public NetEntity EntityUid { get; set; } = entityUid;
}
5 changes: 5 additions & 0 deletions Resources/Prototypes/_NF/SectorServices/services.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,8 @@
id: MailMetrics
components:
- type: SectorLogisticStats

- type: sectorService
id: ShuttleRecords
components:
- type: SectorShuttleRecords

0 comments on commit b14b480

Please sign in to comment.