Skip to content

Commit

Permalink
NFSD Access Overhaul (new-frontiers-14#1459)
Browse files Browse the repository at this point in the history
* NFSD Access Overhaul
Fixed ship console refresh on id insert or removal
Added Access to VesselPrototype
Added Filtration to Ship List based off of Access
Added Bailiff and Sergeant Access levels
Added Access levels to all NFSD ship
Added appropriate access groups to NFSD roles

* removed: Atmospherics and Engineering from ID console

* Update IdCardConsoleComponent.cs

Fixing issue where re-sharper removed un-used using statements per request.

* NFSD Access Overhaul
Fixed ship console refresh on id insert or removal
Added Access to VesselPrototype
Added Filtration to Ship List based off of Access
Added Bailiff and Sergeant Access levels
Added Access levels to all NFSD ship
Added appropriate access groups to NFSD roles

* removed: Atmospherics and Engineering from ID console

* Update IdCardConsoleComponent.cs

Fixing issue where re-sharper removed un-used using statements per request.

* Updating Access per request,  fixing SR access to include Srg and Bailiff

* fixing mirge issue

that VS so politly decided to fuck up and then hide the fact that the code would not compile by compiling old code like the little shit that it is.  thank god i dont have to be proffessional with my code comments here like i do at work because i ant shit talk VS or Git when i am working so i shall unleach all my rage in this commnet for the 2 of them (git and VS) for being dicks and wasting everybody's time

* ShipyardSystem cleanup, LINQ removal, vessel proto

* Access: prefer NFSD accesses outright to groups

* Shipyard console: fix condition, check accessgroup

* ShipyardSystem: comment skipping for no access

---------

Co-authored-by: neuPanda <[email protected]>
Co-authored-by: Whatstone <[email protected]>
  • Loading branch information
3 people authored Jul 7, 2024
1 parent f7fca87 commit 9cd2e22
Show file tree
Hide file tree
Showing 26 changed files with 112 additions and 40 deletions.
77 changes: 54 additions & 23 deletions Content.Server/Shipyard/Systems/ShipyardSystem.Consoles.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@
using Content.Shared.Shipyard;
using Robust.Server.GameObjects;
using Robust.Shared.Containers;
using Robust.Shared.Player;
using Robust.Shared.Prototypes;
using Content.Shared.Radio;
using System.Linq;
Expand All @@ -21,7 +20,6 @@
using Content.Shared.Mobs.Components;
using Content.Shared.Mobs.Systems;
using Content.Server.Maps;
using Content.Server.UserInterface;
using Content.Shared.StationRecords;
using Content.Server.Chat.Systems;
using Content.Server.Forensics;
Expand All @@ -39,6 +37,7 @@
using Content.Shared.UserInterface;
using Robust.Shared.Audio;
using Robust.Shared.Audio.Systems;
using Content.Shared.Access;

namespace Content.Server.Shipyard.Systems;

Expand Down Expand Up @@ -106,7 +105,7 @@ private void OnPurchaseMessage(EntityUid uid, ShipyardConsoleComponent component
return;
}

if (!GetAvailableShuttles(uid).Contains(vessel.ID))
if (!GetAvailableShuttles(uid, targetId: targetId).Contains(vessel.ID))
{
PlayDenySound(uid, component);
_adminLogger.Add(LogType.Action, LogImpact.Medium, $"{ToPrettyString(player):player} tried to purchase a vessel that was never available.");
Expand Down Expand Up @@ -239,7 +238,7 @@ private void OnPurchaseMessage(EntityUid uid, ShipyardConsoleComponent component

PlayConfirmSound(uid, component);
_adminLogger.Add(LogType.ShipYardUsage, LogImpact.Low, $"{ToPrettyString(player):actor} purchased shuttle {ToPrettyString(shuttle.Owner)} for {vessel.Price} credits via {ToPrettyString(component.Owner)}");
RefreshState(uid, bank.Balance, true, name, sellValue, true, (ShipyardConsoleUiKey) args.UiKey);
RefreshState(uid, bank.Balance, true, name, sellValue, targetId, (ShipyardConsoleUiKey) args.UiKey);
}

private void TryParseShuttleName(ShuttleDeedComponent deed, string name)
Expand Down Expand Up @@ -353,7 +352,7 @@ public void OnSellMessage(EntityUid uid, ShipyardConsoleComponent component, Shi
SendSellMessage(uid, deed.ShuttleOwner!, name, secretChannel, player, secret: true);

_adminLogger.Add(LogType.ShipYardUsage, LogImpact.Low, $"{ToPrettyString(player):actor} sold {shuttleName} for {bill} credits via {ToPrettyString(component.Owner)}");
RefreshState(uid, bank.Balance, true, null, 0, true, (ShipyardConsoleUiKey) args.UiKey);
RefreshState(uid, bank.Balance, true, null, 0, targetId, (ShipyardConsoleUiKey) args.UiKey);
}

private void OnConsoleUIOpened(EntityUid uid, ShipyardConsoleComponent component, BoundUIOpenedEvent args)
Expand Down Expand Up @@ -392,7 +391,7 @@ private void OnConsoleUIOpened(EntityUid uid, ShipyardConsoleComponent component
sellValue -= CalculateSalesTax(component, sellValue);

var fullName = deed != null ? GetFullName(deed) : null;
RefreshState(uid, bank.Balance, true, fullName, sellValue, targetId.HasValue, (ShipyardConsoleUiKey) args.UiKey);
RefreshState(uid, bank.Balance, true, fullName, sellValue, targetId, (ShipyardConsoleUiKey) args.UiKey);
}

private void ConsolePopup(EntityUid uid, string text)
Expand Down Expand Up @@ -482,7 +481,14 @@ private void OnItemSlotChanged(EntityUid uid, ShipyardConsoleComponent component
sellValue -= CalculateSalesTax(component, sellValue);

var fullName = deed != null ? GetFullName(deed) : null;
RefreshState(uid, bank.Balance, true, fullName, sellValue, targetId.HasValue, (ShipyardConsoleUiKey) uiComp.Key);
RefreshState(uid,
bank.Balance,
true,
fullName,
sellValue,
targetId,
(ShipyardConsoleUiKey) uiComp.Key);

}
}

Expand Down Expand Up @@ -519,7 +525,8 @@ private void OnItemSlotChanged(EntityUid uid, ShipyardConsoleComponent component
/// <summary>
/// Returns all shuttle prototype IDs the given shipyard console can offer.
/// </summary>
public List<string> GetAvailableShuttles(EntityUid uid, ShipyardConsoleUiKey? key = null, ShipyardListingComponent? listing = null)
public List<string> GetAvailableShuttles(EntityUid uid, ShipyardConsoleUiKey? key = null,
ShipyardListingComponent? listing = null, EntityUid? targetId = null)
{
var availableShuttles = new List<string>();

Expand All @@ -536,30 +543,54 @@ public List<string> GetAvailableShuttles(EntityUid uid, ShipyardConsoleUiKey? ke
}
}

// Add all prototypes matching the ui key
if (key != null && key != ShipyardConsoleUiKey.Custom && ShipyardGroupMapping.TryGetValue(key.Value, out var group))
TryComp<AccessComponent>(targetId, out var accessComponent);
foreach (var vessel in _prototypeManager.EnumeratePrototypes<VesselPrototype>())
{
var protos = _prototypeManager.EnumeratePrototypes<VesselPrototype>();
foreach (var proto in protos)
// If the vessel needs access to be bought, check the user's access.
if (!string.IsNullOrEmpty(vessel.Access))
{
if (proto.Group == group)
availableShuttles.Add(proto.ID);
bool hasAccess = false;
// Check tags
if (accessComponent?.Tags.Contains(vessel.Access) ?? false)
hasAccess = true;

// Check each group if we haven't found access already.
if (!hasAccess)
{
var groupIds = accessComponent?.Groups ?? new HashSet<ProtoId<AccessGroupPrototype>>();
foreach (var groupId in groupIds)
{
var groupProto = _prototypeManager.Index(groupId);
if (groupProto?.Tags.Contains(vessel.Access) ?? false)
{
hasAccess = true;
break;
}
}
}

// No access to this vessel, skip to the next one.
if (!hasAccess)
continue;
}
}

// Add all prototypes specified in ShipyardListing
if (listing != null || TryComp(uid, out listing))
{
foreach (var shuttle in listing.Shuttles)
// Check that the listing contains the shuttle or that the shuttle is in the group that the console is looking for
if ((listing?.Shuttles.Contains(vessel.ID) ?? false) ||
// if the listing contains the shuttle, add it to the list or

// if the shuttle is in the group that the console is looking for
(key != null && key != ShipyardConsoleUiKey.Custom &&
ShipyardGroupMapping.TryGetValue(key.Value, out var group) && vessel.Group == group))
{
availableShuttles.Add(shuttle);
availableShuttles.Add(vessel.ID);
}

}

return availableShuttles;
}

private void RefreshState(EntityUid uid, int balance, bool access, string? shipDeed, int shipSellValue, bool isTargetIdPresent, ShipyardConsoleUiKey uiKey)
private void RefreshState(EntityUid uid, int balance, bool access, string? shipDeed, int shipSellValue, EntityUid? targetId, ShipyardConsoleUiKey uiKey)
{
var listing = TryComp<ShipyardListingComponent>(uid, out var comp) ? comp : null;

Expand All @@ -568,9 +599,9 @@ private void RefreshState(EntityUid uid, int balance, bool access, string? shipD
access,
shipDeed,
shipSellValue,
isTargetIdPresent,
targetId.HasValue,
((byte)uiKey),
GetAvailableShuttles(uid, uiKey, listing),
GetAvailableShuttles(uid, uiKey, listing, targetId),
uiKey.ToString());

_ui.SetUiState(uid, uiKey, newState);
Expand Down
4 changes: 4 additions & 0 deletions Content.Shared/Access/Components/IdCardConsoleComponent.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
using Robust.Shared.GameStates;
using Robust.Shared.Prototypes;
using Robust.Shared.Serialization;
using Robust.Shared.Serialization.TypeSerializers.Implementations.Custom.Prototype.List;
using Robust.Shared.Prototypes;

namespace Content.Shared.Access.Components;

Expand Down Expand Up @@ -46,6 +48,7 @@ public WriteToTargetIdMessage(string fullName, string jobTitle, List<ProtoId<Acc
{
"Armory",
//"Atmospherics",
"Bailiff", // Frontier
//"Bar",
"Brig",
"Detective",
Expand Down Expand Up @@ -75,6 +78,7 @@ public WriteToTargetIdMessage(string fullName, string jobTitle, List<ProtoId<Acc
//"ResearchDirector",
//"Salvage",
"Security",
"Sergeant", // Frontier
"Service",
"StationTrafficController", // Frontier
//"Theatre",
Expand Down
8 changes: 8 additions & 0 deletions Content.Shared/Shipyard/Prototypes/VesselPrototype.cs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
using Content.Shared.Store;
using Robust.Shared.Prototypes;
using Robust.Shared.Serialization;
using Robust.Shared.Serialization.TypeSerializers.Implementations.Custom.Prototype;
Expand Down Expand Up @@ -39,6 +40,12 @@ public sealed class VesselPrototype : IPrototype
[DataField("group")]
public string Group = string.Empty;

/// <summary>
/// The access required to buy the product. (e.g. Command, Mail, Bailiff, etc.)
/// </summary>
[DataField("access")]
public string Access = string.Empty;

/// Frontier - Add this field for the MapChecker script.
/// <summary>
/// The MapChecker override group for this vessel.
Expand All @@ -51,4 +58,5 @@ public sealed class VesselPrototype : IPrototype
/// </summary>
[DataField("shuttlePath", required: true)]
public ResPath ShuttlePath = default!;

}
4 changes: 3 additions & 1 deletion Resources/Locale/en-US/_NF/prototypes/access/accesses.ftl
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,6 @@ id-card-access-level-frontier = Frontier
id-card-access-level-pilot = Pilot
id-card-access-level-mail = Mail
id-card-access-level-mercenary = Mercenary
id-card-access-level-stc = Station Traffic Controller
id-card-access-level-stc = Station Traffic Controller
id-card-access-level-sergeant = Sergeant
id-card-access-level-bailiff = Bailiff
2 changes: 2 additions & 0 deletions Resources/Prototypes/Access/misc.yml
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@
- Research
- Service
- StationTrafficController # Frontier
- Sergeant # Frontier
- Bailiff # Frontier
- Maintenance
- External
- Janitor
Expand Down
17 changes: 16 additions & 1 deletion Resources/Prototypes/_NF/Access/security.yml
Original file line number Diff line number Diff line change
@@ -1,7 +1,22 @@
- type: accessLevel
id: Mercenary
name: id-card-access-level-mercenary
name: id-card-access-level-mercenary

- type: accessLevel
id: Sergeant
name: id-card-access-level-sergeant

- type: accessLevel
id: Bailiff
name: id-card-access-level-bailiff

- type: accessGroup
id: CadetNfsdAccess
tags:
- Maintenance
- External
- Security

- type: accessGroup
id: GeneralNfsdAccess
tags:
Expand Down
11 changes: 4 additions & 7 deletions Resources/Prototypes/_NF/Roles/Jobs/Nfsd/bailiff.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,14 +17,11 @@
supervisors: job-supervisors-sheriff
canBeAntag: false
access:
- Maintenance
- External
- Command
- Brig
- Security
- Mercenary # Frontier
- Captain # Frontier
- Armory
- Sergeant # Frontier
- Bailiff # Frontier
accessGroups: # Frontier
- GeneralNfsdAccess # Frontier
special:
- !type:AddImplantSpecial
implants: [ MindShieldImplant, TrackingImplant ] # Frontier
Expand Down
2 changes: 1 addition & 1 deletion Resources/Prototypes/_NF/Roles/Jobs/Nfsd/cadet.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
supervisors: job-supervisors-cadet
canBeAntag: false
accessGroups: # Frontier
- GeneralNfsdAccess # Frontier
- CadetNfsdAccess # Frontier
special:
- !type:AddImplantSpecial
implants: [ MindShieldImplant, TrackingImplant ]
Expand Down
9 changes: 2 additions & 7 deletions Resources/Prototypes/_NF/Roles/Jobs/Nfsd/detectivenf.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,14 +14,9 @@
supervisors: job-supervisors-bailiff
canBeAntag: false
access:
- Maintenance
- External
- Command
- Brig
- Security
- Mercenary # Frontier
- Captain # Frontier
- Detective
accessGroups: # Frontier
- GeneralNfsdAccess # Frontier
special:
- !type:AddImplantSpecial
implants: [ MindShieldImplant, TrackingImplant ]
Expand Down
2 changes: 2 additions & 0 deletions Resources/Prototypes/_NF/Roles/Jobs/Nfsd/senior_officer.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@
icon: "JobIconSeniorOfficer" # Frontier
supervisors: job-supervisors-bailiff
canBeAntag: false
access:
- Sergeant # Frontier
accessGroups: # Frontier
- GeneralNfsdAccess # Frontier
special:
Expand Down
1 change: 1 addition & 0 deletions Resources/Prototypes/_NF/Shipyard/Nfsd/broadhead.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
price: 50000
category: Medium
group: Security
access: Detective
shuttlePath: /Maps/_NF/Shuttles/Nfsd/broadhead.yml

- type: gameMap
Expand Down
1 change: 1 addition & 0 deletions Resources/Prototypes/_NF/Shipyard/Nfsd/cleric.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
price: 11800 #Appraisal is 10500
category: Small
group: None
access: Security
mapchecker_group_override: Security # Treat this as a security vessel for mapchecker purposes
shuttlePath: /Maps/_NF/Shuttles/Nfsd/cleric.yml

Expand Down
1 change: 1 addition & 0 deletions Resources/Prototypes/_NF/Shipyard/Nfsd/empress.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
price: 170000 #Appraisal value is 150000
category: Large
group: Security
access: Bailiff
shuttlePath: /Maps/_NF/Shuttles/Nfsd/empress.yml

- type: gameMap
Expand Down
1 change: 1 addition & 0 deletions Resources/Prototypes/_NF/Shipyard/Nfsd/enforcer.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
# price: 21350
# category: Small
# group: Security
# access: Bailiff
# shuttlePath: /Maps/_NF/Shuttles/Nfsd/enforcer.yml

# - type: gameMap
Expand Down
1 change: 1 addition & 0 deletions Resources/Prototypes/_NF/Shipyard/Nfsd/fighter.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
price: 9000 #not sure how much mark up % to add but the appraisal is 7150$ now
category: Small
group: None
access: Security
mapchecker_group_override: Security # Treat this as a security vessel for mapchecker purposes
shuttlePath: /Maps/_NF/Shuttles/Nfsd/fighter.yml

Expand Down
1 change: 1 addition & 0 deletions Resources/Prototypes/_NF/Shipyard/Nfsd/hospitaller.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
price: 28220
category: Small
group: Security
access: Security
shuttlePath: /Maps/_NF/Shuttles/Nfsd/hospitaller.yml

- type: gameMap
Expand Down
1 change: 1 addition & 0 deletions Resources/Prototypes/_NF/Shipyard/Nfsd/inquisitor.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
price: 29000
category: Small
group: Security
access: Detective
shuttlePath: /Maps/_NF/Shuttles/Nfsd/inquisitor.yml

- type: gameMap
Expand Down
1 change: 1 addition & 0 deletions Resources/Prototypes/_NF/Shipyard/Nfsd/interceptor.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
price: 21350
category: Small
group: Security
access: Detective
shuttlePath: /Maps/_NF/Shuttles/Nfsd/interceptor.yml

- type: gameMap
Expand Down
1 change: 1 addition & 0 deletions Resources/Prototypes/_NF/Shipyard/Nfsd/marauder.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
price: 80000
category: Large
group: Security
access: Bailiff
shuttlePath: /Maps/_NF/Shuttles/Nfsd/marauder.yml

- type: gameMap
Expand Down
1 change: 1 addition & 0 deletions Resources/Prototypes/_NF/Shipyard/Nfsd/opportunity.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
# price: 70000
# category: Medium
# group: Security
# access: Bailiff
# shuttlePath: /Maps/_NF/Shuttles/Nfsd/opportunity.yml

# - type: gameMap
Expand Down
1 change: 1 addition & 0 deletions Resources/Prototypes/_NF/Shipyard/Nfsd/prowler.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
price: 49220
category: Medium
group: Security
access: Sergeant
shuttlePath: /Maps/_NF/Shuttles/Nfsd/prowler.yml

- type: gameMap
Expand Down
Loading

0 comments on commit 9cd2e22

Please sign in to comment.