From 162d3e1af5404a5c7dd8817576e1dd25f302ca64 Mon Sep 17 00:00:00 2001 From: Interkarma Date: Thu, 2 Jul 2020 10:49:21 +1000 Subject: [PATCH] Don't offer random commoner/castle quests from children Added helpers to identify children NPC. Bypass random quest offer when player activates a child NPC, even if one would otherwise be offered. --- Assets/Scripts/Game/StaticNPC.cs | 22 +++++++++ Assets/Scripts/Game/TalkManager.cs | 7 ++- Assets/Scripts/Utility/TextureReader.cs | 63 +++++++++++++++++++++++++ 3 files changed, 90 insertions(+), 2 deletions(-) diff --git a/Assets/Scripts/Game/StaticNPC.cs b/Assets/Scripts/Game/StaticNPC.cs index eee25189e7..d6b3bd88b2 100644 --- a/Assets/Scripts/Game/StaticNPC.cs +++ b/Assets/Scripts/Game/StaticNPC.cs @@ -61,6 +61,14 @@ public string DisplayName get { return GetDisplayName(); } } + /// + /// Checks if this is a child NPC using texture or faction. + /// + public bool IsChildNPC + { + get { return CheckChildNPC(); } + } + #endregion #region Structs & Enums @@ -285,6 +293,20 @@ public static int GetPositionHash(int x, int y, int z) return x ^ y << 2 ^ z >> 2; } + /// + /// Check if a known child NPC. + /// + /// True if NPC data matches known children textures or faction. + bool CheckChildNPC() + { + const int childrenFactionID = 514; + + bool isChildNPCTexture = DaggerfallWorkshop.Utility.TextureReader.IsChildNPCTexture(Data.billboardArchiveIndex, Data.billboardRecordIndex); + bool isChildrenFaction = Data.factionID == childrenFactionID; + + return isChildNPCTexture || isChildrenFaction; + } + #endregion } } \ No newline at end of file diff --git a/Assets/Scripts/Game/TalkManager.cs b/Assets/Scripts/Game/TalkManager.cs index e6454cb4c0..bddc1c361f 100644 --- a/Assets/Scripts/Game/TalkManager.cs +++ b/Assets/Scripts/Game/TalkManager.cs @@ -642,9 +642,12 @@ public void TalkToStaticNPC(StaticNPC targetNPC, bool menu = true, bool isSpyMas FactionFile.FactionData npcFactionData; GetStaticNPCFactionData(targetNPC.Data.factionID, GameManager.Instance.PlayerEnterExit.BuildingType, out npcFactionData); + // Check if this is a child NPC + bool isChildNPC = targetNPC.IsChildNPC; + IUserInterfaceManager uiManager = DaggerfallUI.UIManager; - if (IsNpcOfferingQuest(targetNPC.Data.nameSeed)) + if (!isChildNPC && IsNpcOfferingQuest(targetNPC.Data.nameSeed)) { uiManager.PushWindow(UIWindowFactory.GetInstanceWithArgs(UIWindowType.QuestOffer, new object[] @@ -654,7 +657,7 @@ public void TalkToStaticNPC(StaticNPC targetNPC, bool menu = true, bool isSpyMas })); return; } - else if (IsCastleNpcOfferingQuest(targetNPC.Data.nameSeed)) + else if (!isChildNPC && IsCastleNpcOfferingQuest(targetNPC.Data.nameSeed)) { uiManager.PushWindow(UIWindowFactory.GetInstanceWithArgs(UIWindowType.QuestOffer, new object[] {uiManager, targetNPC.Data, (FactionFile.SocialGroups)npcFactionData.sgroup, menu})); diff --git a/Assets/Scripts/Utility/TextureReader.cs b/Assets/Scripts/Utility/TextureReader.cs index e89e26b3fc..babd0e9496 100644 --- a/Assets/Scripts/Utility/TextureReader.cs +++ b/Assets/Scripts/Utility/TextureReader.cs @@ -1208,6 +1208,69 @@ public static void SaveTextureToPNG(Texture2D source, string path) } #endif + /// + /// Checks if sprite is a child NPC sprite texture. + /// + /// Texture archive. + /// Texture record. + /// True if a child NPC sprite texture. + public static bool IsChildNPCTexture(int archive, int record) + { + // Archives known to store child NPC textures + // Records are checked for each individually for a match + const int templePeople = 181; + const int mediumCommonPeople = 182; + const int flatPeople2 = 184; + const int testBigFlats = 186; + const int kludgeTown = 197; + const int wayrestPeople = 346; + const int sentinelPeople = 357; + + if (archive == templePeople) + { + if (record == 3) + return true; + } + + if (archive == mediumCommonPeople) + { + if (record == 4 || record == 18 || record == 38 || record == 42 || record == 43 || record == 52 || record == 53) + return true; + } + + if (archive == flatPeople2) + { + if (record == 15) + return true; + } + + if (archive == testBigFlats) + { + if (record == 5 || record == 19 || record == 39 || record == 43 || record == 44 || record == 53 || record == 54) + return true; + } + + if (archive == kludgeTown) + { + if (record == 3) + return true; + } + + if (archive == wayrestPeople) + { + if (record == 2 || record == 15 || record == 16 || record == 18) + return true; + } + + if (archive == sentinelPeople) + { + if (record == 5 || record == 6 || record == 7) + return true; + } + + return false; + } + #endregion #region Private Methods