Skip to content

Commit

Permalink
Added SQL output for conditional quest texts (#830)
Browse files Browse the repository at this point in the history
  • Loading branch information
meji46 authored Mar 1, 2024
1 parent e740174 commit 4052fef
Show file tree
Hide file tree
Showing 5 changed files with 177 additions and 10 deletions.
56 changes: 56 additions & 0 deletions WowPacketParser/SQL/Builders/QuestMisc.cs
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,62 @@ public static string QuestRequestItems()
return SQLUtil.Compare(Storage.QuestRequestItems, templatesDb, StoreNameType.Quest);
}

[BuilderMethod]
public static string QuestDescriptionConditional()
{
if (!Settings.SQLOutputFlag.HasAnyFlagBit(SQLOutput.quest_template))
return string.Empty;

if (Storage.QuestDescriptionConditional.IsEmpty())
return string.Empty;

var templatesDb = SQLDatabase.Get(Storage.QuestDescriptionConditional);

return SQLUtil.Compare(Storage.QuestDescriptionConditional, templatesDb, StoreNameType.Quest);
}

[BuilderMethod]
public static string QuestCompletionLogConditional()
{
if (!Settings.SQLOutputFlag.HasAnyFlagBit(SQLOutput.quest_template))
return string.Empty;

if (Storage.QuestCompletionLogConditional.IsEmpty())
return string.Empty;

var templatesDb = SQLDatabase.Get(Storage.QuestCompletionLogConditional);

return SQLUtil.Compare(Storage.QuestCompletionLogConditional, templatesDb, StoreNameType.Quest);
}

[BuilderMethod]
public static string QuestOfferRewardConditional()
{
if (!Settings.SQLOutputFlag.HasAnyFlagBit(SQLOutput.quest_template))
return string.Empty;

if (Storage.QuestOfferRewardConditional.IsEmpty())
return string.Empty;

var templatesDb = SQLDatabase.Get(Storage.QuestOfferRewardConditional);

return SQLUtil.Compare(Storage.QuestOfferRewardConditional, templatesDb, StoreNameType.Quest);
}

[BuilderMethod]
public static string QuestRequestItemsConditional()
{
if (!Settings.SQLOutputFlag.HasAnyFlagBit(SQLOutput.quest_template))
return string.Empty;

if (Storage.QuestRequestItemsConditional.IsEmpty())
return string.Empty;

var templatesDb = SQLDatabase.Get(Storage.QuestRequestItemsConditional);

return SQLUtil.Compare(Storage.QuestRequestItemsConditional, templatesDb, StoreNameType.Quest);
}

[BuilderMethod]
public static string CreatureQuestStarters()
{
Expand Down
69 changes: 69 additions & 0 deletions WowPacketParser/Store/Objects/QuestTextConditional.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
using WowPacketParser.Enums;
using WowPacketParser.Misc;
using WowPacketParser.SQL;

namespace WowPacketParser.Store.Objects
{
public record QuestTextConditional : IDataModel
{
[DBFieldName("QuestId", true)]
public int? QuestId;

[DBFieldName("PlayerConditionId", true)]
public int? PlayerConditionId;

[DBFieldName("QuestgiverCreatureId", true)]
public int? QuestgiverCreatureId;

[DBFieldName("locale", true)]
public string Locale = ClientLocale.PacketLocaleString;

[DBFieldName("Text")]
public string Text;

[DBFieldName("OrderIndex")]
public int? OrderIndex;

[DBFieldName("VerifiedBuild")]
public int? VerifiedBuild = ClientVersion.BuildInt;

public QuestTextConditional(QuestTextConditional questTextConditional)
{
QuestId = questTextConditional.QuestId;
PlayerConditionId = questTextConditional.PlayerConditionId;
QuestgiverCreatureId = questTextConditional.QuestgiverCreatureId;
Locale = ClientLocale.PacketLocaleString;
Text = questTextConditional.Text;
OrderIndex = questTextConditional.OrderIndex;
VerifiedBuild = ClientVersion.BuildInt;
}
}

[DBTableName("quest_description_conditional", TargetedDatabaseFlag.SinceDragonflight)]
public sealed record QuestDescriptionConditional : QuestTextConditional
{
public QuestDescriptionConditional() { }
public QuestDescriptionConditional(QuestTextConditional questTextConditional) : base(questTextConditional) { }
}

[DBTableName("quest_completion_log_conditional", TargetedDatabaseFlag.SinceDragonflight)]
public sealed record QuestCompletionLogConditional : QuestTextConditional
{
public QuestCompletionLogConditional() { }
public QuestCompletionLogConditional(QuestTextConditional questTextConditional) : base(questTextConditional) { }
}

[DBTableName("quest_offer_reward_conditional", TargetedDatabaseFlag.SinceDragonflight)]
public sealed record QuestOfferRewardConditional : QuestTextConditional
{
public QuestOfferRewardConditional() { }
public QuestOfferRewardConditional(QuestTextConditional questTextConditional) : base(questTextConditional) { }
}

[DBTableName("quest_request_items_conditional", TargetedDatabaseFlag.SinceDragonflight)]
public sealed record QuestRequestItemsConditional : QuestTextConditional
{
public QuestRequestItemsConditional() { }
public QuestRequestItemsConditional(QuestTextConditional questTextConditional) : base(questTextConditional) { }
}
}
8 changes: 8 additions & 0 deletions WowPacketParser/Store/Storage.cs
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,10 @@ public static class Storage
public static readonly DataBag<QuestGreeting> QuestGreetings = new DataBag<QuestGreeting>(new List<SQLOutput> { SQLOutput.quest_template });
public static readonly DataBag<QuestDetails> QuestDetails = new DataBag<QuestDetails>(new List<SQLOutput> { SQLOutput.quest_template });
public static readonly DataBag<QuestRequestItems> QuestRequestItems = new DataBag<QuestRequestItems>(new List<SQLOutput> { SQLOutput.quest_template });
public static readonly DataBag<QuestDescriptionConditional> QuestDescriptionConditional = new DataBag<QuestDescriptionConditional>(new List<SQLOutput> { SQLOutput.quest_template });
public static readonly DataBag<QuestCompletionLogConditional> QuestCompletionLogConditional = new DataBag<QuestCompletionLogConditional>(new List<SQLOutput> { SQLOutput.quest_template });
public static readonly DataBag<QuestOfferRewardConditional> QuestOfferRewardConditional = new DataBag<QuestOfferRewardConditional>(new List<SQLOutput> { SQLOutput.quest_template });
public static readonly DataBag<QuestRequestItemsConditional> QuestRequestItemsConditional = new DataBag<QuestRequestItemsConditional>(new List<SQLOutput> { SQLOutput.quest_template });

// Names
public static readonly DataBag<ObjectName> ObjectNames = new DataBag<ObjectName>();
Expand Down Expand Up @@ -1206,6 +1210,10 @@ public static void ClearContainers()
QuestGreetings.Clear();
QuestDetails.Clear();
QuestRequestItems.Clear();
QuestDescriptionConditional.Clear();
QuestCompletionLogConditional.Clear();
QuestOfferRewardConditional.Clear();
QuestRequestItemsConditional.Clear();

ObjectNames.Clear();

Expand Down
4 changes: 2 additions & 2 deletions WowPacketParserModule.V10_0_0_46181/Parsers/QueryHandler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -236,10 +236,10 @@ public static void HandleQuestQueryResponse(Packet packet)
quest.QuestCompletionLog = packet.ReadWoWString("QuestCompletionLog", questCompletionLogLen);

for (int i = 0; i < conditionalQuestDescriptionCount; i++)
QuestHandler.ReadConditionalQuestText(packet, "ConditionalQuestDescription", i);
QuestHandler.ReadConditionalQuestText(packet, id.Key, i, QuestHandler.ConditionalTextType.Description, i, "ConditionalDescriptionText");

for (int i = 0; i < conditionalQuestCompletionLogCount; i++)
QuestHandler.ReadConditionalQuestText(packet, "ConditionalQuestCompletionLog", i);
QuestHandler.ReadConditionalQuestText(packet, id.Key, i, QuestHandler.ConditionalTextType.CompletionLog, i, "ConditionalCompletionLogText");

ObjectName objectName = new ObjectName
{
Expand Down
50 changes: 42 additions & 8 deletions WowPacketParserModule.V10_0_0_46181/Parsers/QuestHandler.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@

using Org.BouncyCastle.Crypto.Operators;
using WowPacketParser.Enums;
using WowPacketParser.Misc;
using WowPacketParser.Parsing;
Expand All @@ -12,14 +11,49 @@ namespace WowPacketParserModule.V10_0_0_46181.Parsers
{
public static class QuestHandler
{
public static void ReadConditionalQuestText(Packet packet, params object[] indexes)
public enum ConditionalTextType
{
packet.ReadInt32("PlayerConditionID", indexes);
packet.ReadInt32("QuestGiverCreatureID", indexes);
Description = 0,
CompletionLog = 1,
OfferReward = 2,
RequestItems = 3
}

public static void ReadConditionalQuestText(Packet packet, int questId, int idx, ConditionalTextType type, params object[] indexes)
{
var playerConditionId = packet.ReadInt32("PlayerConditionID", indexes);
var questgiverCreatureId = packet.ReadInt32("QuestGiverCreatureID", indexes);

packet.ResetBitReader();
var textLength = packet.ReadBits(12);
packet.ReadWoWString("Text", textLength, indexes);
var text = packet.ReadWoWString("Text", textLength, indexes);

QuestTextConditional questTextConditional = new QuestTextConditional
{
QuestId = questId,
PlayerConditionId = playerConditionId,
QuestgiverCreatureId = questgiverCreatureId,
Text = text,
OrderIndex = idx
};

switch (type)
{
case ConditionalTextType.Description:
Storage.QuestDescriptionConditional.Add(new QuestDescriptionConditional(questTextConditional), packet.TimeSpan);
break;
case ConditionalTextType.CompletionLog:
Storage.QuestCompletionLogConditional.Add(new QuestCompletionLogConditional(questTextConditional), packet.TimeSpan);
break;
case ConditionalTextType.OfferReward:
Storage.QuestOfferRewardConditional.Add(new QuestOfferRewardConditional(questTextConditional), packet.TimeSpan);
break;
case ConditionalTextType.RequestItems:
Storage.QuestRequestItemsConditional.Add(new QuestRequestItemsConditional(questTextConditional), packet.TimeSpan);
break;
default:
break;
}
}

[Parser(Opcode.SMSG_QUEST_GIVER_QUEST_DETAILS)]
Expand Down Expand Up @@ -100,7 +134,7 @@ public static void HandleQuestGiverQuestDetails(Packet packet)
packet.ReadWoWString("PortraitTurnInName", portraitTurnInNameLen);

for (int i = 0; i < conditionalDescriptionTextCount; i++)
ReadConditionalQuestText(packet, "ConditionalDescriptionText");
ReadConditionalQuestText(packet, id, i, ConditionalTextType.Description, i, "ConditionalDescriptionText");

Storage.QuestDetails.Add(questDetails, packet.TimeSpan);
}
Expand Down Expand Up @@ -177,7 +211,7 @@ public static void HandleQuestGiverRequestItems(Packet packet)
completionTextLen = packet.ReadBits(12);

for (int i = 0; i < conditionalCompletionTextCount; i++)
ReadConditionalQuestText(packet, "ConditionalCompletionText");
ReadConditionalQuestText(packet, id, i, ConditionalTextType.RequestItems, i, "ConditionalCompletionText");

requestItems.QuestTitle = packet.ReadWoWString("QuestTitle", questTitleLen);
string completionText = requestItems.CompletionText = packet.ReadWoWString("CompletionText", completionTextLen);
Expand Down Expand Up @@ -258,7 +292,7 @@ public static void QuestGiverOfferReward(Packet packet)
uint portraitTurnInNameLen = packet.ReadBits(8);

for (int i = 0; i < conditionalRewardTextCount; i++)
ReadConditionalQuestText(packet, "ConditionalRewardText");
ReadConditionalQuestText(packet, (int)questOfferReward.ID, i, ConditionalTextType.OfferReward, i, "ConditionalRewardText");

packet.ReadWoWString("QuestTitle", questTitleLen);
questOfferReward.RewardText = packet.ReadWoWString("RewardText", rewardTextLen);
Expand Down

0 comments on commit 4052fef

Please sign in to comment.