Skip to content

Commit

Permalink
Apply RoleLoadout MinLimit fix to EnsureValid too (#29358)
Browse files Browse the repository at this point in the history
Apply MinLimit fix to EnsureValid too
  • Loading branch information
Tayrtahn authored Jun 23, 2024
1 parent 0546c9b commit c2f8984
Showing 1 changed file with 6 additions and 5 deletions.
11 changes: 6 additions & 5 deletions Content.Shared/Preferences/Loadouts/RoleLoadout.cs
Original file line number Diff line number Diff line change
Expand Up @@ -124,9 +124,12 @@ public void EnsureValid(HumanoidCharacterProfile profile, ICommonSession session
// 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++)
foreach (var protoId in groupProto.Loadouts)
{
if (!protoManager.TryIndex(groupProto.Loadouts[i], out var loadoutProto))
if (loadouts.Count >= groupProto.MinLimit)
break;

if (!protoManager.TryIndex(protoId, out var loadoutProto))
continue;

var defaultLoadout = new Loadout()
Expand Down Expand Up @@ -193,11 +196,10 @@ public void SetDefault(HumanoidCharacterProfile? profile, ICommonSession? sessio
if (groupProto.MinLimit > 0)
{
// Apply any loadouts we can.
var addedCount = 0;
foreach (var protoId in groupProto.Loadouts)
{
// Reached the limit, time to stop
if (addedCount >= groupProto.MinLimit)
if (loadouts.Count >= groupProto.MinLimit)
break;

if (!protoManager.TryIndex(protoId, out var loadoutProto))
Expand All @@ -214,7 +216,6 @@ public void SetDefault(HumanoidCharacterProfile? profile, ICommonSession? sessio

loadouts.Add(defaultLoadout);
Apply(loadoutProto);
addedCount++;
}
}
}
Expand Down

0 comments on commit c2f8984

Please sign in to comment.