Skip to content

Commit

Permalink
Shuttle deed spawner (#618)
Browse files Browse the repository at this point in the history
* Testing

* Deed

* Update ShuttleDeedComponent.cs

* Update ShuttleDeedComponent.cs

* Update ShipyardSystem.Consoles.cs

* No Need for this lines

* Fixing

* I used ChatGPT to fix this

* Small change to fix errors

* Update ShipyardSystem.Consoles.cs

* Fix

* Fixing

* Update shuttle.yml

* Working again

* Added owner name to card

* Deed Testing

* Update ShipyardSystem.Consoles.cs

* Working Again.

* Fix

* Fix for ID comp
  • Loading branch information
dvir001 authored Dec 11, 2023
1 parent a508ce1 commit edaca48
Show file tree
Hide file tree
Showing 7 changed files with 100 additions and 26 deletions.
8 changes: 8 additions & 0 deletions Content.Server/Access/Systems/IdCardConsoleSystem.cs
Original file line number Diff line number Diff line change
Expand Up @@ -219,6 +219,14 @@ private void TryWriteToShuttleDeed(EntityUid uid,

if (!EntityManager.TryGetComponent<ShuttleDeedComponent>(targetId, out var shuttleDeed))
return;
else
{
if (Deleted(shuttleDeed!.ShuttleUid))
{
RemComp<ShuttleDeedComponent>(targetId);
return;
}
}

// Ensure the name is valid and follows the convention
var name = newShuttleName.Trim();
Expand Down
86 changes: 64 additions & 22 deletions Content.Server/Shipyard/Systems/ShipyardSystem.Consoles.cs
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,9 @@
using Content.Shared.Database;
using Content.Shared.Preferences;
using static Content.Shared.Shipyard.Components.ShuttleDeedComponent;
using Content.Server.Shuttles.Components;
using Content.Server.Station.Components;
using System.Text.RegularExpressions;

namespace Content.Server.Shipyard.Systems;

Expand Down Expand Up @@ -61,9 +64,7 @@ public void InitializeConsole()
private void OnPurchaseMessage(EntityUid uid, ShipyardConsoleComponent component, ShipyardConsolePurchaseMessage args)
{
if (args.Session.AttachedEntity is not { Valid : true } player)
{
return;
}

if (component.TargetIdSlot.ContainerSlot?.ContainedEntity is not { Valid : true } targetId)
{
Expand Down Expand Up @@ -170,11 +171,12 @@ private void OnPurchaseMessage(EntityUid uid, ShipyardConsoleComponent component

_accessSystem.TrySetTags(targetId, newAccess, newCap);
}

var deedID = EnsureComp<ShuttleDeedComponent>(targetId);
AssignShuttleDeedProperties(deedID, shuttle.Owner, name, player);

var newDeed = EnsureComp<ShuttleDeedComponent>(targetId);
newDeed.ShuttleUid = shuttle.Owner;
TryParseShuttleName(newDeed, name);
newDeed.ShuttleOwner = player;
var deedShuttle = EnsureComp<ShuttleDeedComponent>(shuttle.Owner);
AssignShuttleDeedProperties(deedShuttle, shuttle.Owner, name, player);

var channel = component.ShipyardChannel;

Expand Down Expand Up @@ -221,7 +223,7 @@ private void OnPurchaseMessage(EntityUid uid, ShipyardConsoleComponent component
//if (ShipyardConsoleUiKey.Security == (ShipyardConsoleUiKey) args.UiKey) Enable in the case we force this on every security ship
// EnsureComp<StationEmpImmuneComponent>(shuttle.Owner); Enable in the case we force this on every security ship

int sellValue = 0;
int sellValue = 0;
if (TryComp<ShuttleDeedComponent>(targetId, out var deed))
sellValue = (int) _pricing.AppraiseGrid((EntityUid) (deed?.ShuttleUid!));

Expand Down Expand Up @@ -256,9 +258,7 @@ public void OnSellMessage(EntityUid uid, ShipyardConsoleComponent component, Shi
{

if (args.Session.AttachedEntity is not { Valid: true } player)
{
return;
}

if (component.TargetIdSlot.ContainerSlot?.ContainedEntity is not { Valid: true } targetId)
{
Expand Down Expand Up @@ -349,25 +349,35 @@ public void OnSellMessage(EntityUid uid, ShipyardConsoleComponent component, Shi

private void OnConsoleUIOpened(EntityUid uid, ShipyardConsoleComponent component, BoundUIOpenedEvent args)
{
// kind of cursed. We need to update the UI when an Id is entered, but the UI needs to know the player characters bank account.
if (!TryComp<ActivatableUIComponent>(uid, out var uiComp) || uiComp.Key == null)
return;

if (args.Session.AttachedEntity is not { Valid: true } player)
{
return;
}

// mayhaps re-enable this later for HoS/SA
// var station = _station.GetOwningStation(uid);

if (!TryComp<BankAccountComponent>(player, out var bank))
{
return;
}

var targetId = component.TargetIdSlot.ContainerSlot?.ContainedEntity;
int sellValue = 0;

if (TryComp<ShuttleDeedComponent>(targetId, out var deed))
{
if (Deleted(deed!.ShuttleUid))
{
RemComp<ShuttleDeedComponent>(targetId!.Value);
return;
}
}

int sellValue = 0;
if (deed?.ShuttleUid != null)
sellValue = (int) _pricing.AppraiseGrid((EntityUid) (deed?.ShuttleUid!));

if (ShipyardConsoleUiKey.BlackMarket == (ShipyardConsoleUiKey) args.UiKey)
if (ShipyardConsoleUiKey.BlackMarket == (ShipyardConsoleUiKey) uiComp.Key)
{
var tax = (int) (sellValue * 0.30f);
sellValue -= tax;
Expand Down Expand Up @@ -429,25 +439,30 @@ private void OnItemSlotChanged(EntityUid uid, ShipyardConsoleComponent component
{
// kind of cursed. We need to update the UI when an Id is entered, but the UI needs to know the player characters bank account.
if (!TryComp<ActivatableUIComponent>(uid, out var uiComp) || uiComp.Key == null)
{
return;
}

var shipyardUi = _ui.GetUi(uid, uiComp.Key);
var uiUser = shipyardUi.SubscribedSessions.FirstOrDefault();

if (uiUser?.AttachedEntity is not { Valid: true } player)
{
return;
}

if (!TryComp<BankAccountComponent>(player, out var bank))
{
return;
}

var targetId = component.TargetIdSlot.ContainerSlot?.ContainedEntity;
int sellValue = 0;

if (TryComp<ShuttleDeedComponent>(targetId, out var deed))
{
if (Deleted(deed!.ShuttleUid))
{
RemComp<ShuttleDeedComponent>(targetId!.Value);
return;
}
}

int sellValue = 0;
if (deed?.ShuttleUid != null)
sellValue = (int) _pricing.AppraiseGrid((EntityUid) (deed?.ShuttleUid!));

if (ShipyardConsoleUiKey.BlackMarket == (ShipyardConsoleUiKey) uiComp.Key)
Expand Down Expand Up @@ -490,4 +505,31 @@ private void RefreshState(EntityUid uid, int balance, bool access, string? shipD

_ui.TrySetUiState(uid, uiKey, newState);
}

void AssignShuttleDeedProperties(ShuttleDeedComponent deed, EntityUid? shuttleUid, string? shuttleName, EntityUid? shuttleOwner)
{
deed.ShuttleUid = shuttleUid;
TryParseShuttleName(deed, shuttleName!);
deed.ShuttleOwner = shuttleOwner;
}

private void OnInitDeedSpawner(EntityUid uid, StationDeedSpawnerComponent component, MapInitEvent args)
{
if (!HasComp<IdCardComponent>(uid)) // Test if the deed on an ID
return;

var xform = Transform(uid); // Get the grid the card is on
if (xform.GridUid == null)
return;

if (!TryComp<ShuttleDeedComponent>(xform.GridUid.Value, out var shuttleDeed) || !TryComp<ShuttleComponent>(xform.GridUid.Value, out var shuttle) || !HasComp<TransformComponent>(xform.GridUid.Value) || shuttle == null || ShipyardMap == null)
return;

var shuttleOwner = ToPrettyString(shuttleDeed.ShuttleOwner); // Grab owner name
var output = Regex.Replace($"{shuttleOwner}", @"\s*\([^()]*\)", ""); // Removes content inside parentheses along with parentheses and a preceding space
_idSystem.TryChangeFullName(uid, output); // Update the card with owner name

var deedID = EnsureComp<ShuttleDeedComponent>(uid);
AssignShuttleDeedProperties(deedID, shuttleDeed.ShuttleUid, shuttleDeed.ShuttleName, shuttleDeed.ShuttleOwner);
}
}
1 change: 1 addition & 0 deletions Content.Server/Shipyard/Systems/ShipyardSystem.cs
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ public override void Initialize()
SubscribeLocalEvent<ShipyardConsoleComponent, EntInsertedIntoContainerMessage>(OnItemSlotChanged);
SubscribeLocalEvent<ShipyardConsoleComponent, EntRemovedFromContainerMessage>(OnItemSlotChanged);
SubscribeLocalEvent<RoundRestartCleanupEvent>(OnRoundRestart);
SubscribeLocalEvent<StationDeedSpawnerComponent, MapInitEvent>(OnInitDeedSpawner);
}
public override void Shutdown()
{
Expand Down
10 changes: 10 additions & 0 deletions Content.Server/Station/Components/StationDeedSpawnerComponent.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
namespace Content.Server.Station.Components;

/// <summary>
/// Copy deep of a ship to a new card
/// </summary>
[RegisterComponent]
public sealed partial class StationDeedSpawnerComponent : Component
{

}
6 changes: 3 additions & 3 deletions Content.Shared/Shipyard/Components/ShuttleDeedComponent.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,14 @@ public sealed partial class ShuttleDeedComponent : Component
public const int MaxSuffixLength = 3 + 1 + 4; // 3 digits, dash, up to 4 letters - should be enough

[DataField("shuttleUid")]
public EntityUid? ShuttleUid;
public EntityUid? ShuttleUid = null;

[DataField("shuttleName")]
public string? ShuttleName;
public string? ShuttleName = "Unknown";

[DataField("shuttleSuffix")]
public string? ShuttleNameSuffix;

[DataField("shuttleOwner")]
public EntityUid? ShuttleOwner;
public EntityUid? ShuttleOwner = null;
}
13 changes: 13 additions & 0 deletions Resources/Prototypes/_NF/Entities/Markers/shuttle.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
- type: entity
parent: IDCardStandard
id: ShuttleDeedIDCard
name: shuttle deed
suffix: DO NOT MAP
components:
- type: Sprite
layers:
- state: default
- state: idpassenger
- type: PresetIdCard
job: Captain
- type: StationDeedSpawner
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
- type: entity
id: WarpPointShip
parent: WarpPoint
suffix: Ship
suffix: ship
components:
- type: WarpPoint
useStationName: true

0 comments on commit edaca48

Please sign in to comment.