Skip to content

Commit

Permalink
Merge branch 'master' into 2024-09-21-better-dock-signage
Browse files Browse the repository at this point in the history
  • Loading branch information
whatston3 committed Sep 21, 2024
2 parents 19dbdfa + 1dda632 commit d9102c8
Show file tree
Hide file tree
Showing 359 changed files with 32,177 additions and 1,125 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
}
2 changes: 1 addition & 1 deletion Content.Server/Salvage/SalvageSystem.ExpeditionConsole.cs
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,7 @@ private void OnSalvageFinishMessage(EntityUid entity, SalvageExpeditionConsoleCo
continue;

// NPC, definitely not a person
if (HasComp<ActiveNPCComponent>(uid) || HasComp<SalvageMobRestrictionsNFComponent>(uid))
if (HasComp<ActiveNPCComponent>(uid) || HasComp<NFSalvageMobRestrictionsComponent>(uid))
continue;

// Hostile ghost role, continue
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
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
}
}
12 changes: 11 additions & 1 deletion Content.Server/StationEvents/Events/BluespaceErrorRule.cs
Original file line number Diff line number Diff line change
Expand Up @@ -77,10 +77,20 @@ protected override void Ended(EntityUid uid, BluespaceErrorRuleComponent compone
var gridValue = _pricing.AppraiseGrid(gridUid, null);

// Handle mobrestrictions getting deleted
var query = AllEntityQuery<SalvageMobRestrictionsNFComponent>();
var query = AllEntityQuery<NFSalvageMobRestrictionsComponent>();

while (query.MoveNext(out var salvUid, out var salvMob))
{
if (!salvMob.DespawnIfOffLinkedGrid)
{
var transform = Transform(salvUid);
if (transform.GridUid != salvMob.LinkedGridEntity)
{
RemComp<NFSalvageMobRestrictionsComponent>(salvUid);
continue;
}
}

if (gridTransform.GridUid == salvMob.LinkedGridEntity)
{
QueueDel(salvUid);
Expand Down
2 changes: 1 addition & 1 deletion Content.Server/Worldgen/Systems/LocalityLoaderSystem.cs
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ private void OnDebrisDespawn(EntityUid entity, SpaceDebrisComponent component, E
if (entity != null)
{
// Handle mobrestrictions getting deleted
var query = AllEntityQuery<SalvageMobRestrictionsNFComponent>();
var query = AllEntityQuery<NFSalvageMobRestrictionsComponent>();

while (query.MoveNext(out var salvUid, out var salvMob))
{
Expand Down
Loading

0 comments on commit d9102c8

Please sign in to comment.