From 7ae6d0a348dab5d31839a2a4206e4beedb9ecd56 Mon Sep 17 00:00:00 2001 From: Ottermandias Date: Tue, 28 Feb 2023 15:48:45 +0100 Subject: [PATCH] Add collection groups for Children and Elderly. --- Penumbra.Api | 2 +- Penumbra/Collections/CollectionType.cs | 20 ++++++++++++++----- .../Resolver/PathResolver.Identification.cs | 18 +++++++++++++---- 3 files changed, 30 insertions(+), 10 deletions(-) diff --git a/Penumbra.Api b/Penumbra.Api index 97dc16ba..1f62ae97 160000 --- a/Penumbra.Api +++ b/Penumbra.Api @@ -1 +1 @@ -Subproject commit 97dc16ba32bf78c4d3a4d210a08010cd6d4eec3c +Subproject commit 1f62ae970e02e48f686a41a2cecdb79e0af87994 diff --git a/Penumbra/Collections/CollectionType.cs b/Penumbra/Collections/CollectionType.cs index 6b7f7638..de9d80c4 100644 --- a/Penumbra/Collections/CollectionType.cs +++ b/Penumbra/Collections/CollectionType.cs @@ -13,6 +13,8 @@ public enum CollectionType : byte FemalePlayerCharacter = Api.Enums.ApiCollectionType.FemalePlayerCharacter, MaleNonPlayerCharacter = Api.Enums.ApiCollectionType.MaleNonPlayerCharacter, FemaleNonPlayerCharacter = Api.Enums.ApiCollectionType.FemaleNonPlayerCharacter, + NonPlayerChild = Api.Enums.ApiCollectionType.NonPlayerChild, + NonPlayerElderly = Api.Enums.ApiCollectionType.NonPlayerElderly, MaleMidlander = Api.Enums.ApiCollectionType.MaleMidlander, FemaleMidlander = Api.Enums.ApiCollectionType.FemaleMidlander, @@ -97,15 +99,15 @@ public enum CollectionType : byte Default = Api.Enums.ApiCollectionType.Default, // The default collection was changed Interface = Api.Enums.ApiCollectionType.Interface, // The ui collection was changed Current = Api.Enums.ApiCollectionType.Current, // The current collection was changed - Individual, // An individual collection was changed - Inactive, // A collection was added or removed - Temporary, // A temporary collections was set or deleted via IPC + Individual, // An individual collection was changed + Inactive, // A collection was added or removed + Temporary, // A temporary collections was set or deleted via IPC } public static class CollectionTypeExtensions { public static bool IsSpecial( this CollectionType collectionType ) - => collectionType is >= CollectionType.Yourself and < CollectionType.Default; + => collectionType < CollectionType.Default; public static readonly (CollectionType, string, string)[] Special = Enum.GetValues< CollectionType >() .Where( IsSpecial ) @@ -265,6 +267,8 @@ public static class CollectionTypeExtensions => collectionType switch { CollectionType.Yourself => "Your Character", + CollectionType.NonPlayerChild => "Non-Player Children", + CollectionType.NonPlayerElderly => "Non-Player Elderly", CollectionType.MalePlayerCharacter => "Male Player Characters", CollectionType.MaleNonPlayerCharacter => "Male Non-Player Characters", CollectionType.MaleMidlander => $"Male {SubRace.Midlander.ToName()}", @@ -345,7 +349,13 @@ public static class CollectionTypeExtensions => collectionType switch { CollectionType.Yourself => "This collection applies to your own character, regardless of its name.\n" - + "It takes precedence before all other collections except for explicitly named character collections.", + + "It takes precedence before all other collections except for explicitly named individual collections.", + CollectionType.NonPlayerChild => + "This collection applies to all non-player characters with a child body-type.\n" + + "It takes precedence before all other collections except for explicitly named individual collections.", + CollectionType.NonPlayerElderly => + "This collection applies to all non-player characters with an elderly body-type.\n" + + "It takes precedence before all other collections except for explicitly named individual collections.", CollectionType.MalePlayerCharacter => "This collection applies to all male player characters that do not have a more specific character or racial collections associated.", CollectionType.MaleNonPlayerCharacter => diff --git a/Penumbra/Interop/Resolver/PathResolver.Identification.cs b/Penumbra/Interop/Resolver/PathResolver.Identification.cs index 9ddb9941..cbd91b4f 100644 --- a/Penumbra/Interop/Resolver/PathResolver.Identification.cs +++ b/Penumbra/Interop/Resolver/PathResolver.Identification.cs @@ -133,12 +133,22 @@ public unsafe partial class PathResolver var character = ( Character* )actor; if( character->ModelCharaId >= 0 && character->ModelCharaId < ValidHumanModels.Count && ValidHumanModels[ character->ModelCharaId ] ) { - var race = ( SubRace )character->CustomizeData[ 4 ]; - var gender = ( Gender )( character->CustomizeData[ 1 ] + 1 ); - var isNpc = actor->ObjectKind != ( byte )ObjectKind.Player; + var bodyType = character->CustomizeData[2]; + var collection = bodyType switch + { + 3 => Penumbra.CollectionManager.ByType( CollectionType.NonPlayerElderly ), + 4 => Penumbra.CollectionManager.ByType( CollectionType.NonPlayerChild ), + _ => null, + }; + if( collection != null ) + return collection; + + var race = ( SubRace )character->CustomizeData[ 4 ]; + var gender = ( Gender )( character->CustomizeData[ 1 ] + 1 ); + var isNpc = actor->ObjectKind != ( byte )ObjectKind.Player; var type = CollectionTypeExtensions.FromParts( race, gender, isNpc ); - var collection = Penumbra.CollectionManager.ByType( type ); + collection = Penumbra.CollectionManager.ByType( type ); collection ??= Penumbra.CollectionManager.ByType( CollectionTypeExtensions.FromParts( gender, isNpc ) ); return collection; }