Skip to content

Commit

Permalink
Add Secrets inventory loadout
Browse files Browse the repository at this point in the history
  • Loading branch information
Morb0 committed May 15, 2024
1 parent f0dea8a commit 34bfec1
Show file tree
Hide file tree
Showing 8 changed files with 101 additions and 4 deletions.
11 changes: 10 additions & 1 deletion Content.Client/Preferences/UI/LoadoutGroupContainer.xaml.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using System.Linq;
using Content.Corvax.Interfaces.Shared;
using Content.Shared.Clothing;
using Content.Shared.Preferences.Loadouts;
using Robust.Client.AutoGenerated;
Expand Down Expand Up @@ -66,7 +67,15 @@ public void RefreshLoadouts(RoleLoadout loadout, ICommonSession session, IDepend

var selected = loadout.SelectedLoadouts[_groupProto.ID];

foreach (var loadoutProto in _groupProto.Loadouts)
// Corvax-Loadouts-Start
var groupLoadouts = _groupProto.Loadouts;
if (collection.TryResolveType<ISharedLoadoutsManager>(out var loadoutsManager) && _groupProto.ID == "Inventory")
{
groupLoadouts = loadoutsManager.GetClientPrototypes().Select(id => (ProtoId<LoadoutPrototype>)id).ToList();
}
// Corvax-Loadouts-End

foreach (var loadoutProto in groupLoadouts) // Corvax-Loadouts
{
if (!protoMan.TryIndex(loadoutProto, out var loadProto))
continue;
Expand Down
34 changes: 32 additions & 2 deletions Content.Shared/Preferences/Loadouts/RoleLoadout.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
using System.Diagnostics.CodeAnalysis;
using System.Linq;
using Content.Corvax.Interfaces.Shared;
using Content.Shared.Random;
using Robust.Shared.Collections;
using Robust.Shared.Network;
using Robust.Shared.Player;
using Robust.Shared.Prototypes;
using Robust.Shared.Serialization;
Expand Down Expand Up @@ -48,6 +51,7 @@ public void EnsureValid(ICommonSession session, IDependencyCollection collection
{
var groupRemove = new ValueList<string>();
var protoManager = collection.Resolve<IPrototypeManager>();
var netManager = collection.Resolve<INetManager>(); // Corvax-Loadouts

if (!protoManager.TryIndex(Role, out var roleProto))
{
Expand All @@ -67,6 +71,24 @@ public void EnsureValid(ICommonSession session, IDependencyCollection collection
continue;
}

// Corvax-Loadouts-Start
var groupProtoLoadouts = groupProto.Loadouts;
if (collection.TryResolveType<ISharedLoadoutsManager>(out var loadoutsManager) && group.Id == "Inventory")
{
var prototypes = new List<string>();
if (netManager.IsClient)
{
prototypes = loadoutsManager.GetClientPrototypes();
}
else if (loadoutsManager.TryGetServerPrototypes(session.UserId, out var protos))
{
prototypes = protos;
}

groupProtoLoadouts = prototypes.Select(id => (ProtoId<LoadoutPrototype>)id).ToList();
}
// Corvax-Loadouts-End

var loadouts = groupLoadouts[..Math.Min(groupLoadouts.Count, groupProto.MaxLimit)];

// Validate first
Expand All @@ -80,6 +102,14 @@ public void EnsureValid(ICommonSession session, IDependencyCollection collection
continue;
}

// Corvax-Loadouts-Start: Validate if loadout exist in group. It's can't be f real
if (!groupProtoLoadouts.Contains(loadout.Prototype))
{
loadouts.RemoveAt(i);
continue;
}
// Corvax-Loadouts-End

// Validate the loadout can be applied (e.g. points).
if (!IsValid(session, loadout.Prototype, collection, out _))
{
Expand All @@ -95,9 +125,9 @@ public void EnsureValid(ICommonSession session, IDependencyCollection collection
// If you put invalid ones first but that's your fault for not using sensible defaults
if (loadouts.Count < groupProto.MinLimit)
{
for (var i = 0; i < Math.Min(groupProto.MinLimit, groupProto.Loadouts.Count); i++)
for (var i = 0; i < Math.Min(groupProto.MinLimit, groupProtoLoadouts.Count); i++) // Corvax-Loadout: Use groupProtoLoadouts instead of groupProto.Loadouts
{
if (!protoManager.TryIndex(groupProto.Loadouts[i], out var loadoutProto))
if (!protoManager.TryIndex(groupProtoLoadouts[i], out var loadoutProto)) // Corvax-Loadout
continue;

var defaultLoadout = new Loadout()
Expand Down
11 changes: 11 additions & 0 deletions Corvax/Content.Corvax.Interfaces.Shared/ISharedLoadoutsManager.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
using System.Diagnostics.CodeAnalysis;
using Robust.Shared.Network;

namespace Content.Corvax.Interfaces.Shared;

public interface ISharedLoadoutsManager
{
public void Initialize();
public bool TryGetServerPrototypes(NetUserId userId, [NotNullWhen(true)] out List<string>? prototypes);
public List<string> GetClientPrototypes();
}
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
loadout-group-inventory = Мой инвентарь
loadout-group-psychologist-backpack = Рюкзак психолога
7 changes: 7 additions & 0 deletions Resources/Prototypes/Corvax/Loadouts/loadout_groups.yml
Original file line number Diff line number Diff line change
@@ -1,3 +1,10 @@
- type: loadoutGroup
id: Inventory
name: loadout-group-inventory
minLimit: 0
maxLimit: 5
loadouts: []

- type: loadoutGroup
id: PsychologistBackpack
name: loadout-group-psychologist-backpack
Expand Down
1 change: 1 addition & 0 deletions Resources/Prototypes/Corvax/Loadouts/role_loadouts.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,4 @@
- LawyerJumpsuit
- CommonBackpack
- Trinkets
- Inventory # Corvax-Loadouts
Loading

0 comments on commit 34bfec1

Please sign in to comment.