Skip to content

Commit

Permalink
Don't offer random commoner/castle quests from children
Browse files Browse the repository at this point in the history
Added helpers to identify children NPC.
Bypass random quest offer when player activates a child NPC, even if one would otherwise be offered.
  • Loading branch information
Interkarma committed Jul 2, 2020
1 parent 4c1850b commit 162d3e1
Show file tree
Hide file tree
Showing 3 changed files with 90 additions and 2 deletions.
22 changes: 22 additions & 0 deletions Assets/Scripts/Game/StaticNPC.cs
Expand Up @@ -61,6 +61,14 @@ public string DisplayName
get { return GetDisplayName(); }
}

/// <summary>
/// Checks if this is a child NPC using texture or faction.
/// </summary>
public bool IsChildNPC
{
get { return CheckChildNPC(); }
}

#endregion

#region Structs & Enums
Expand Down Expand Up @@ -285,6 +293,20 @@ public static int GetPositionHash(int x, int y, int z)
return x ^ y << 2 ^ z >> 2;
}

/// <summary>
/// Check if a known child NPC.
/// </summary>
/// <returns>True if NPC data matches known children textures or faction.</returns>
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
}
}
7 changes: 5 additions & 2 deletions Assets/Scripts/Game/TalkManager.cs
Expand Up @@ -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[]
Expand All @@ -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}));
Expand Down
63 changes: 63 additions & 0 deletions Assets/Scripts/Utility/TextureReader.cs
Expand Up @@ -1208,6 +1208,69 @@ public static void SaveTextureToPNG(Texture2D source, string path)
}
#endif

/// <summary>
/// Checks if sprite is a child NPC sprite texture.
/// </summary>
/// <param name="archive">Texture archive.</param>
/// <param name="record">Texture record.</param>
/// <returns>True if a child NPC sprite texture.</returns>
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
Expand Down

0 comments on commit 162d3e1

Please sign in to comment.