Skip to content

Commit

Permalink
Merge branch 'new-frontiers-14:master' into PMChardsuit
Browse files Browse the repository at this point in the history
  • Loading branch information
starch70 authored Sep 20, 2024
2 parents 1f7bfbb + bceffc9 commit 2828dd2
Show file tree
Hide file tree
Showing 358 changed files with 33,879 additions and 2,761 deletions.
6 changes: 6 additions & 0 deletions Content.Client/_NF/Bank/BankSystem.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
using Content.Shared.Bank;

namespace Content.Client.Bank;

// Shared is abstract.
public sealed partial class BankSystem : SharedBankSystem;
4 changes: 2 additions & 2 deletions Content.Server/Administration/Systems/AdminVerbSystem.cs
Original file line number Diff line number Diff line change
Expand Up @@ -180,7 +180,7 @@ private void AddAdminVerbs(GetVerbsEvent<Verb> args)
var stationUid = _stations.GetOwningStation(args.Target);
var profile = _ticker.GetPlayerProfile(targetActor.PlayerSession);
var mobUid = _spawning.SpawnPlayerMob(coords.Value, null, profile, stationUid);
var mobUid = _spawning.SpawnPlayerMob(coords.Value, null, profile, stationUid, session: targetActor.PlayerSession); // Frontier: added session
var targetMind = _mindSystem.GetMind(args.Target);
if (targetMind != null)
Expand Down Expand Up @@ -208,7 +208,7 @@ private void AddAdminVerbs(GetVerbsEvent<Verb> args)
var stationUid = _stations.GetOwningStation(args.Target);
var profile = _ticker.GetPlayerProfile(targetActor.PlayerSession);
_spawning.SpawnPlayerMob(coords.Value, null, profile, stationUid);
_spawning.SpawnPlayerMob(coords.Value, null, profile, stationUid, session: targetActor.PlayerSession); // Frontier: added session
},
ConfirmationPopup = true,
Impact = LogImpact.High,
Expand Down
7 changes: 3 additions & 4 deletions Content.Server/Cloning/CloningSystem.cs
Original file line number Diff line number Diff line change
Expand Up @@ -253,11 +253,10 @@ public bool TryCloning(EntityUid uid, EntityUid bodyToClone, Entity<MindComponen
var mob = Spawn(speciesPrototype.Prototype, _transformSystem.GetMapCoordinates(uid));
_humanoidSystem.CloneAppearance(bodyToClone, mob);

// bank account transfer
if (TryComp<BankAccountComponent>(bodyToClone, out var bank))
// Frontier: bank account transfer
if (HasComp<BankAccountComponent>(bodyToClone))
{
var bankComp = EnsureComp<BankAccountComponent>(mob);
bankComp.Balance = bank.Balance;
EnsureComp<BankAccountComponent>(mob);
}

// Frontier
Expand Down
2 changes: 1 addition & 1 deletion Content.Server/GameTicking/GameTicker.Spawning.cs
Original file line number Diff line number Diff line change
Expand Up @@ -239,7 +239,7 @@ private void SpawnPlayer(ICommonSession player,
spawnPointType = SpawnPointType.Job;
}

var mobMaybe = _stationSpawning.SpawnPlayerCharacterOnStation(station, job, character, spawnPointType: spawnPointType);
var mobMaybe = _stationSpawning.SpawnPlayerCharacterOnStation(station, job, character, spawnPointType: spawnPointType, session: player); // Frontier: add session
DebugTools.AssertNotNull(mobMaybe);
var mob = mobMaybe!.Value;

Expand Down
19 changes: 19 additions & 0 deletions Content.Server/Preferences/Managers/ServerPreferencesManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ public sealed class ServerPreferencesManager : IServerPreferencesManager, IPostI
[Dependency] private readonly IPrototypeManager _protos = default!;
[Dependency] private readonly ILogManager _log = default!;
[Dependency] private readonly UserDbDataManager _userDb = default!;
[Dependency] private readonly IEntityManager _entityManager = default!;

// Cache player prefs on the server so we don't need as much async hell related to them.
private readonly Dictionary<NetUserId, PlayerPrefData> _cachedPlayerPrefs =
Expand Down Expand Up @@ -218,6 +219,10 @@ public void FinishLoad(ICommonSession session)
MaxCharacterSlots = MaxCharacterSlots
};
_netManager.ServerSendMessage(msg, session.Channel);

// Frontier: notify other entities that your player data is loaded.
if (session.AttachedEntity != null)
_entityManager.EventBus.RaiseLocalEvent(session.AttachedEntity.Value, new PreferencesLoadedEvent(session, prefsData.Prefs));
}

public void OnClientDisconnected(ICommonSession session)
Expand Down Expand Up @@ -361,4 +366,18 @@ void IPostInjectInit.PostInject()
_userDb.AddOnPlayerDisconnect(OnClientDisconnected);
}
}

// Frontier: event for notifying that preferences for a particular player have loaded in.
public sealed class PreferencesLoadedEvent : EntityEventArgs
{
public readonly ICommonSession Session;
public readonly PlayerPreferences Prefs;

public PreferencesLoadedEvent(ICommonSession session, PlayerPreferences prefs)
{
Session = session;
Prefs = prefs;
}
}
// End Frontier
}
8 changes: 8 additions & 0 deletions Content.Server/Radio/EntitySystems/RadioDeviceSystem.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
using Content.Shared._NC.Radio; // Nuclear-14
using Robust.Server.GameObjects; // Nuclear-14
using Robust.Shared.Prototypes;
using Content.Shared.Access.Systems; // Frontier

namespace Content.Server.Radio.EntitySystems;

Expand All @@ -30,6 +31,7 @@ public sealed class RadioDeviceSystem : EntitySystem
[Dependency] private readonly InteractionSystem _interaction = default!;
[Dependency] private readonly SharedAppearanceSystem _appearance = default!;
[Dependency] private readonly UserInterfaceSystem _ui = default!;
[Dependency] private readonly AccessReaderSystem _access = default!; // Frontier: access

// Used to prevent a shitter from using a bunch of radios to spam chat.
private HashSet<(string, EntityUid)> _recentlySent = new();
Expand Down Expand Up @@ -250,6 +252,8 @@ private void OnToggleIntercomMic(Entity<IntercomComponent> ent, ref ToggleInterc
{
if (ent.Comp.RequiresPower && !this.IsPowered(ent, EntityManager))
return;
if (!_access.IsAllowed(args.Actor, ent.Owner)) // Frontier
return; // Frontier

SetMicrophoneEnabled(ent, args.Actor, args.Enabled, true);
ent.Comp.MicrophoneEnabled = args.Enabled;
Expand All @@ -260,6 +264,8 @@ private void OnToggleIntercomSpeaker(Entity<IntercomComponent> ent, ref ToggleIn
{
if (ent.Comp.RequiresPower && !this.IsPowered(ent, EntityManager))
return;
if (!_access.IsAllowed(args.Actor, ent.Owner)) // Frontier
return; // Frontier

SetSpeakerEnabled(ent, args.Actor, args.Enabled, true);
ent.Comp.SpeakerEnabled = args.Enabled;
Expand All @@ -270,6 +276,8 @@ private void OnSelectIntercomChannel(Entity<IntercomComponent> ent, ref SelectIn
{
if (ent.Comp.RequiresPower && !this.IsPowered(ent, EntityManager))
return;
if (!_access.IsAllowed(args.Actor, ent.Owner)) // Frontier
return; // Frontier

if (!_protoMan.TryIndex<RadioChannelPrototype>(args.Channel, out var channel) || !ent.Comp.SupportedChannels.Contains(args.Channel)) // Nuclear-14: add channel
return;
Expand Down
3 changes: 2 additions & 1 deletion Content.Server/Shuttles/Systems/ArrivalsSystem.cs
Original file line number Diff line number Diff line change
Expand Up @@ -367,7 +367,8 @@ public void HandlePlayerSpawning(PlayerSpawningEvent ev)
spawnLoc,
ev.Job,
ev.HumanoidCharacterProfile,
ev.Station);
ev.Station,
session: ev.Session); // Frontier

EnsureComp<PendingClockInComponent>(ev.SpawnResult.Value);
EnsureComp<AutoOrientComponent>(ev.SpawnResult.Value);
Expand Down
7 changes: 7 additions & 0 deletions Content.Server/Shuttles/Systems/ShuttleConsoleSystem.cs
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
using Robust.Shared.Map;
using Robust.Shared.Utility;
using Content.Shared.UserInterface;
using Content.Shared.Access.Systems; // Frontier

namespace Content.Server.Shuttles.Systems;

Expand All @@ -37,6 +38,7 @@ public sealed partial class ShuttleConsoleSystem : SharedShuttleConsoleSystem
[Dependency] private readonly TagSystem _tags = default!;
[Dependency] private readonly UserInterfaceSystem _ui = default!;
[Dependency] private readonly SharedContentEyeSystem _eyeSystem = default!;
[Dependency] private readonly AccessReaderSystem _access = default!;

private EntityQuery<MetaDataComponent> _metaQuery;
private EntityQuery<TransformComponent> _xformQuery;
Expand Down Expand Up @@ -78,6 +80,8 @@ public override void Initialize()
SubscribeLocalEvent<FTLDestinationComponent, ComponentShutdown>(OnFtlDestShutdown);

InitializeFTL();

InitializeNFDrone(); // Frontier: add our drone subscriptions
}

private void OnFtlDestStartup(EntityUid uid, FTLDestinationComponent component, ComponentStartup args)
Expand Down Expand Up @@ -178,6 +182,9 @@ private bool TryPilot(EntityUid user, EntityUid uid)
return false;
}

if (!_access.IsAllowed(user, uid)) // Frontier: check access
return false; // Frontier

var pilotComponent = EnsureComp<PilotComponent>(user);
var console = pilotComponent.Console;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,8 @@ public void HandlePlayerSpawning(PlayerSpawningEvent args)
baseCoords,
args.Job,
args.HumanoidCharacterProfile,
args.Station);
args.Station,
session: args.Session); // Frontier

_random.Shuffle(possibleContainers);
foreach (var (uid, spawnPoint, manager, xform) in possibleContainers)
Expand Down
3 changes: 2 additions & 1 deletion Content.Server/Spawners/EntitySystems/SpawnPointSystem.cs
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,7 @@ private void OnPlayerSpawning(PlayerSpawningEvent args)
spawnLoc,
args.Job,
args.HumanoidCharacterProfile,
args.Station);
args.Station,
session: args.Session); // Frontier
}
}
10 changes: 3 additions & 7 deletions Content.Server/Species/Systems/NymphSystem.cs
Original file line number Diff line number Diff line change
Expand Up @@ -51,14 +51,10 @@ private void OnRemovedFromPart(EntityUid uid, NymphComponent comp, ref OrganRemo
// Frontier
EnsureComp<CargoSellBlacklistComponent>(nymph);

// Frontier
// bank account transfer
if (TryComp<BankAccountComponent>(args.OldBody, out var bank))
// Frontier: bank account transfer
if (HasComp<BankAccountComponent>(args.OldBody))
{
// Do this carefully since changing the value of a bank account component on a entity will save the balance immediately through subscribers.
var oldBankBalance = bank.Balance;
var newBank = EnsureComp<BankAccountComponent>(nymph);
newBank.Balance = oldBankBalance;
EnsureComp<BankAccountComponent>(nymph);
}
}

Expand Down
53 changes: 43 additions & 10 deletions Content.Server/Station/Systems/StationSpawningSystem.cs
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,8 @@
using Robust.Shared.Utility;
using Content.Server.Spawners.Components;
using Content.Shared.Bank.Components; // DeltaV
using Content.Server.Bank; // Frontier
using Content.Server.Preferences.Managers; // Frontier

namespace Content.Server.Station.Systems;

Expand All @@ -55,7 +57,9 @@ public sealed class StationSpawningSystem : SharedStationSpawningSystem
[Dependency] private readonly PdaSystem _pdaSystem = default!;
[Dependency] private readonly SharedAccessSystem _accessSystem = default!;
[Dependency] private readonly IDependencyCollection _dependencyCollection = default!; // Frontier
[Dependency] private readonly IServerPreferencesManager _preferences = default!; // Frontier

[Dependency] private readonly BankSystem _bank = default!; // Frontier
private bool _randomizeCharacters;

private Dictionary<SpawnPriorityPreference, Action<PlayerSpawningEvent>> _spawnerCallbacks = new();
Expand Down Expand Up @@ -89,18 +93,20 @@ public override void Initialize()
/// <param name="profile">The character profile to use, if any.</param>
/// <param name="stationSpawning">Resolve pattern, the station spawning component for the station.</param>
/// <param name="spawnPointType">Delta-V: Set desired spawn point type.</param>
/// <param name="session">Frontier: The session associated with the character, if any.</param>
/// <returns>The resulting player character, if any.</returns>
/// <exception cref="ArgumentException">Thrown when the given station is not a station.</exception>
/// <remarks>
/// This only spawns the character, and does none of the mind-related setup you'd need for it to be playable.
/// </remarks>
public EntityUid? SpawnPlayerCharacterOnStation(EntityUid? station, JobComponent? job, HumanoidCharacterProfile? profile, StationSpawningComponent? stationSpawning = null, SpawnPointType spawnPointType = SpawnPointType.Unset)
public EntityUid? SpawnPlayerCharacterOnStation(EntityUid? station, JobComponent? job, HumanoidCharacterProfile? profile, StationSpawningComponent? stationSpawning = null, SpawnPointType spawnPointType = SpawnPointType.Unset, ICommonSession? session = null) // Frontier: add session
{
if (station != null && !Resolve(station.Value, ref stationSpawning))
throw new ArgumentException("Tried to use a non-station entity as a station!", nameof(station));

// Delta-V: Set desired spawn point type.
var ev = new PlayerSpawningEvent(job, profile, station, spawnPointType);
// Frontier: add session
var ev = new PlayerSpawningEvent(job, profile, station, spawnPointType, session);

if (station != null && profile != null)
{
Expand Down Expand Up @@ -146,13 +152,15 @@ public override void Initialize()
/// <param name="profile">Appearance profile to use for the character.</param>
/// <param name="station">The station this player is being spawned on.</param>
/// <param name="entity">The entity to use, if one already exists.</param>
/// <param name="session">Frontier: The session associated with the entity, if one exists.</param>
/// <returns>The spawned entity</returns>
public EntityUid SpawnPlayerMob(
EntityCoordinates coordinates,
JobComponent? job,
HumanoidCharacterProfile? profile,
EntityUid? station,
EntityUid? entity = null)
EntityUid? entity = null,
ICommonSession? session = null) // Frontier
{
_prototypeManager.TryIndex(job?.Prototype ?? string.Empty, out var prototype);

Expand Down Expand Up @@ -194,7 +202,21 @@ public EntityUid SpawnPlayerMob(
}

var jobLoadout = LoadoutSystem.GetJobPrototype(prototype?.ID);
var initialBankBalance = profile!.BankBalance; //Frontier
var bankBalance = profile!.BankBalance; //Frontier
bool hasBalance = false; // Frontier

// Frontier: get bank account, ensure we can make a withdrawal
// Note: since this is stored per character, we don't have a cached
// reference for randomly generated characters.
PlayerPreferences? prefs = null;
if (session != null &&
_preferences.TryGetCachedPreferences(session.UserId, out prefs) &&
prefs.IndexOfCharacter(profile) != -1)
{
hasBalance = true;
}
// End Frontier

if (_prototypeManager.TryIndex(jobLoadout, out RoleLoadoutPrototype? roleProto))
{
Expand Down Expand Up @@ -224,10 +246,11 @@ public EntityUid SpawnPlayerMob(
// Handle any extra data here.

//Frontier - we handle bank stuff so we are wrapping each item spawn inside our own cached check.
//If the user's preferences haven't been loaded, only give them free items or fallbacks.
//This way, we will spawn every item we can afford in the order that they were originally sorted.
if (loadoutProto.Price <= bankBalance)
if (loadoutProto.Price <= bankBalance && (loadoutProto.Price <= 0 || hasBalance))
{
bankBalance -= loadoutProto.Price;
bankBalance -= int.Max(0, loadoutProto.Price); // Treat negatives as zero.
EquipStartingGear(entity.Value, loadoutProto, raiseEvent: false);
equippedItems.Add(loadoutProto.ID);
}
Expand Down Expand Up @@ -268,13 +291,18 @@ public EntityUid SpawnPlayerMob(
// End of modified code.
}

// Frontier: do not re-equip roleLoadout.
// Frontier: DO equip job startingGear.
// Frontier: do not re-equip roleLoadout, make sure we equip job startingGear,
// and deduct loadout costs from a bank account if we have one.
if (prototype?.StartingGear is not null)
EquipStartingGear(entity.Value, prototype.StartingGear, raiseEvent: false);

var bank = EnsureComp<BankAccountComponent>(entity.Value);
bank.Balance = bankBalance;
var bankComp = EnsureComp<BankAccountComponent>(entity.Value);

if (hasBalance)
{
_bank.TryBankWithdraw(session!, prefs!, profile!, initialBankBalance - bankBalance, out var newBalance);
}
// End Frontier
}

var gearEquippedEv = new StartingGearEquippedEvent(entity.Value);
Expand Down Expand Up @@ -380,12 +408,17 @@ public sealed class PlayerSpawningEvent : EntityEventArgs
/// Delta-V: Desired SpawnPointType, if any.
/// </summary>
public readonly SpawnPointType DesiredSpawnPointType;
/// <summary>
/// Frontier: The session associated with the entity, if any.
/// </summary>
public readonly ICommonSession? Session;

public PlayerSpawningEvent(JobComponent? job, HumanoidCharacterProfile? humanoidCharacterProfile, EntityUid? station, SpawnPointType spawnPointType = SpawnPointType.Unset)
public PlayerSpawningEvent(JobComponent? job, HumanoidCharacterProfile? humanoidCharacterProfile, EntityUid? station, SpawnPointType spawnPointType = SpawnPointType.Unset, ICommonSession? session = null) // Frontier: added session
{
Job = job;
HumanoidCharacterProfile = humanoidCharacterProfile;
Station = station;
DesiredSpawnPointType = spawnPointType;
Session = session; // Frontier
}
}
Loading

0 comments on commit 2828dd2

Please sign in to comment.