Stop loadouts from saving or trusting dangling weapon-group indices (Cut 10 fix)
Entity.TryUnequip does not clear WeaponGroups, so Capture saved -1 for a grouped item that was no longer equipped, and Materialize later threw IndexOutOfRangeException after every other check passed. Capture now skips group items that are not equipped. Materialize reports every weapon-group index outside the loadout's slots as a failure before building anything, so a stale or hand-edited record builds nothing and charges nothing. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
This commit is contained in:
parent
5e5c304e37
commit
61fc863e6b
2 changed files with 35 additions and 1 deletions
|
|
@ -51,7 +51,7 @@ public static class Loadouts
|
|||
Design = cache.RefOf(itemManager.GetData(item.EquippableItem))
|
||||
}).ToList(),
|
||||
WeaponGroups = entity.WeaponGroups
|
||||
.Select(group => group.items.Select(item => items.IndexOf(item)).ToArray())
|
||||
.Select(group => group.items.Select(item => items.IndexOf(item)).Where(index => index >= 0).ToArray()) // skips unequipped items
|
||||
.ToArray()
|
||||
};
|
||||
}
|
||||
|
|
@ -92,6 +92,8 @@ public static class Loadouts
|
|||
|
||||
var hullProduct = Resolve(loadout.Hull, "hull");
|
||||
var slotProducts = loadout.Slots.Select(slot => Resolve(slot.Design, Cell(slot))).ToArray();
|
||||
foreach (var index in (loadout.WeaponGroups ?? new int[0][]).SelectMany(group => group))
|
||||
if (index < 0 || index >= loadout.Slots.Count) failures.Add($"weapon group: no slot {index}");
|
||||
if (failures.Count > reported) return null;
|
||||
|
||||
var hull = (EquippableItem) itemManager.CreateInstance(hullProduct);
|
||||
|
|
|
|||
Loading…
Reference in a new issue