Skip to content

Commit

Permalink
Merge pull request #540 from pacampbell/fix_quest_bugs
Browse files Browse the repository at this point in the history
refactor: Replace VariantId with QuestScheduleId
  • Loading branch information
pacampbell authored Oct 9, 2024
2 parents 235f6ba + 6d22055 commit 3696012
Show file tree
Hide file tree
Showing 57 changed files with 932 additions and 1,087 deletions.
10 changes: 10 additions & 0 deletions Arrowgene.Ddon.Database/Arrowgene.Ddon.Database.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,18 @@
</ContentWithTargetPath>
</ItemGroup>

<ItemGroup>
<ContentWithTargetPath Remove="files\database\script\migration_quest_variant_refactor.sql" />
</ItemGroup>

<ItemGroup>
<ProjectReference Include="..\Arrowgene.Ddon.Shared\Arrowgene.Ddon.Shared.csproj" />
</ItemGroup>

<ItemGroup>
<None Update="Files\Database\Script\migration_quest_variant_refactor.sql">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>
</ItemGroup>

</Project>
2 changes: 1 addition & 1 deletion Arrowgene.Ddon.Database/DdonDatabaseBuilder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ public static class DdonDatabaseBuilder
private static readonly ILogger Logger = LogProvider.Logger<Logger>(typeof(DdonDatabaseBuilder));
private const string DefaultSchemaFile = "Script/schema_sqlite.sql";

public const uint Version = 20;
public const uint Version = 21;

public static IDatabase Build(DatabaseSetting settings)
{
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
ALTER TABLE "ddon_priority_quests"
RENAME COLUMN "quest_id" to "quest_schedule_id";

ALTER TABLE "ddon_reward_box"
RENAME COLUMN "quest_id" to "quest_schedule_id";

ALTER TABLE "ddon_reward_box"
DROP "variant_quest_id";

ALTER TABLE "ddon_quest_progress"
RENAME COLUMN "quest_id" to "quest_schedule_id";

ALTER TABLE "ddon_quest_progress"
DROP "variant_quest_id";
Original file line number Diff line number Diff line change
Expand Up @@ -536,23 +536,21 @@ CREATE TABLE IF NOT EXISTS "ddon_reward_box"
(
"uniq_reward_id" INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL,
"character_common_id" INTEGER NOT NULL,
"quest_id" INTEGER NOT NULL,
"quest_schedule_id" INTEGER NOT NULL,
"num_random_rewards" INTEGER NOT NULL,
"random_reward0_index" INTEGER NOT NULL,
"random_reward1_index" INTEGER NOT NULL,
"random_reward2_index" INTEGER NOT NULL,
"random_reward3_index" INTEGER NOT NULL,
"variant_quest_id" INTEGER NOT NULL DEFAULT 0,
CONSTRAINT "fk_ddon_reward_box_character_common_id" FOREIGN KEY ("character_common_id") REFERENCES "ddon_character_common" ("character_common_id") ON DELETE CASCADE
);

CREATE TABLE IF NOT EXISTS "ddon_quest_progress"
(
"character_common_id" INTEGER NOT NULL,
"quest_type" INTEGER NOT NULL,
"quest_id" INTEGER NOT NULL,
"quest_schedule_id" INTEGER NOT NULL,
"step" INTEGER NOT NULL,
"variant_quest_id" INTEGER NOT NULL,
CONSTRAINT "fk_ddon_quest_progress_character_common_id" FOREIGN KEY ("character_common_id") REFERENCES "ddon_character_common" ("character_common_id") ON DELETE CASCADE
);

Expand All @@ -568,7 +566,7 @@ CREATE TABLE IF NOT EXISTS "ddon_completed_quests"
CREATE TABLE IF NOT EXISTS "ddon_priority_quests"
(
"character_common_id" INTEGER NOT NULL,
"quest_id" INTEGER NOT NULL,
"quest_schedule_id" INTEGER NOT NULL,
CONSTRAINT "fk_ddon_priority_quests_character_common_id" FOREIGN KEY ("character_common_id") REFERENCES "ddon_character_common" ("character_common_id") ON DELETE CASCADE
);

Expand Down
14 changes: 7 additions & 7 deletions Arrowgene.Ddon.Database/IDatabase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -433,16 +433,16 @@ bool ReplaceCompletedQuest(
);

// Quest Progress
bool InsertQuestProgress(uint characterCommonId, QuestId questId, QuestType questType, uint step, uint variantId=0);
bool UpdateQuestProgress(uint characterCommonId, QuestId questId, QuestType questType, uint step);
bool RemoveQuestProgress(uint characterCommonId, QuestId questId, QuestType questType);
bool InsertQuestProgress(uint characterCommonId, uint questScheduleId, QuestType questType, uint step);
bool UpdateQuestProgress(uint characterCommonId, uint questScheduleId, QuestType questType, uint step);
bool RemoveQuestProgress(uint characterCommonId, uint questScheduleId, QuestType questType);
List<QuestProgress> GetQuestProgressByType(uint characterCommonId, QuestType questType);
QuestProgress GetQuestProgressById(uint characterCommonId, QuestId questId);
QuestProgress GetQuestProgressById(uint characterCommonId, uint questScheduleId);

// Quest Priority
bool InsertPriorityQuest(uint characterCommonId, QuestId questId);
List<QuestId> GetPriorityQuests(uint characterCommonId);
bool DeletePriorityQuest(uint characterCommonId, QuestId questId);
bool InsertPriorityQuest(uint characterCommonId, uint questScheduleId);
List<uint> GetPriorityQuestScheduleIds(uint characterCommonId);
bool DeletePriorityQuest(uint characterCommonId, uint questScheduleId);

// System mail
long InsertSystemMailAttachment(SystemMailAttachment attachment);
Expand Down
8 changes: 3 additions & 5 deletions Arrowgene.Ddon.Database/Sql/Core/DdonSqlDbQuestReward.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ public abstract partial class DdonSqlDb<TCon, TCom, TReader> : SqlDb<TCon, TCom,
private readonly int MAX_RANDOM_REWARDS = 4;
protected static readonly string[] RewardBoxFields = new string[]
{
/* uniq_reward_id */ "character_common_id", "quest_id", "num_random_rewards", "random_reward0_index", "random_reward1_index", "random_reward2_index", "random_reward3_index", "variant_quest_id"
/* uniq_reward_id */ "character_common_id", "quest_schedule_id", "num_random_rewards", "random_reward0_index", "random_reward1_index", "random_reward2_index", "random_reward3_index"
};

private readonly string SqlInsertRewardBoxItems = $"INSERT INTO \"ddon_reward_box\" ({BuildQueryField(RewardBoxFields)}) VALUES ({BuildQueryInsert(RewardBoxFields)});";
Expand All @@ -37,9 +37,8 @@ public bool InsertBoxRewardItems(TCon conn, uint commonId, QuestBoxRewards rewar
return ExecuteNonQuery(conn, SqlInsertRewardBoxItems, command =>
{
AddParameter(command, "character_common_id", commonId);
AddParameter(command, "quest_id", (uint) rewards.QuestId);
AddParameter(command, "quest_schedule_id", rewards.QuestScheduleId);
AddParameter(command, "num_random_rewards", rewards.NumRandomRewards);
AddParameter(command, "variant_quest_id", rewards.VariantId);

int i;
for(i = 0; i < rewards.NumRandomRewards; i++)
Expand Down Expand Up @@ -101,9 +100,8 @@ private QuestBoxRewards ReadDatabaseQuestBoxReward(TReader reader)
QuestBoxRewards obj = new QuestBoxRewards();
obj.UniqRewardId = GetUInt32(reader, "uniq_reward_id");
obj.CharacterCommonId = GetUInt32(reader, "character_common_id");
obj.QuestId = (QuestId) GetUInt32(reader, "quest_id");
obj.NumRandomRewards = GetInt32(reader, "num_random_rewards");
obj.VariantId = GetUInt32(reader, "variant_quest_id");
obj.QuestScheduleId = GetUInt32(reader, "quest_schedule_id");

for (int i = 0; i < obj.NumRandomRewards; i++)
{
Expand Down
30 changes: 15 additions & 15 deletions Arrowgene.Ddon.Database/Sql/Core/DdonSqlPriorityQuests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -20,38 +20,38 @@ public abstract partial class DdonSqlDb<TCon, TCom, TReader> : SqlDb<TCon, TCom,
/* ddon_completed_quests */
protected static readonly string[] PriorityQuestFields = new string[]
{
"character_common_id", "quest_id"
"character_common_id", "quest_schedule_id"
};

private readonly string SqlInsertIfNotExistPriorityQuestId = $"INSERT INTO \"ddon_priority_quests\" ({BuildQueryField(PriorityQuestFields)}) SELECT " +
$"{BuildQueryInsert(PriorityQuestFields)} WHERE NOT EXISTS (SELECT 1 FROM \"ddon_priority_quests\" WHERE " +
$"\"character_common_id\" = @character_common_id AND \"quest_id\" = @quest_id);";
$"\"character_common_id\" = @character_common_id AND \"quest_schedule_id\" = @quest_schedule_id);";
private readonly string SqlSelectPriorityQuests = $"SELECT {BuildQueryField(PriorityQuestFields)} FROM \"ddon_priority_quests\" WHERE \"character_common_id\" = @character_common_id;";
private readonly string SqlDeletePriorityQuest = $"DELETE FROM \"ddon_priority_quests\" WHERE \"character_common_id\" = @character_common_id AND \"quest_id\" = @quest_id;";
private readonly string SqlDeletePriorityQuest = $"DELETE FROM \"ddon_priority_quests\" WHERE \"character_common_id\" = @character_common_id AND \"quest_schedule_id\" = @quest_schedule_id;";

public bool InsertPriorityQuest(uint characterCommonId, QuestId questId)
public bool InsertPriorityQuest(uint characterCommonId, uint questScheduleId)
{
using TCon connection = OpenNewConnection();
return InsertPriorityQuest(connection, characterCommonId, questId);
return InsertPriorityQuest(connection, characterCommonId, questScheduleId);
}

public bool InsertPriorityQuest(TCon connection, uint characterCommonId, QuestId questId)
public bool InsertPriorityQuest(TCon connection, uint characterCommonId, uint questScheduleId)
{
return ExecuteNonQuery(connection, SqlInsertIfNotExistPriorityQuestId, command =>
{
AddParameter(command, "character_common_id", characterCommonId);
AddParameter(command, "quest_id", (uint)questId);
AddParameter(command, "quest_schedule_id", questScheduleId);
}) == 1;
}

public List<QuestId> GetPriorityQuests(uint characterCommonId)
public List<uint> GetPriorityQuestScheduleIds(uint characterCommonId)
{
using TCon connection = OpenNewConnection();
return GetPriorityQuests(connection, characterCommonId);
}
public List<QuestId> GetPriorityQuests(TCon connection, uint characterCommonId)
public List<uint> GetPriorityQuests(TCon connection, uint characterCommonId)
{
List<QuestId> results = new List<QuestId>();
List<uint> results = new List<uint>();
ExecuteInTransaction(conn =>
{
ExecuteReader(conn, SqlSelectPriorityQuests,
Expand All @@ -60,25 +60,25 @@ public List<QuestId> GetPriorityQuests(TCon connection, uint characterCommonId)
}, reader => {
while (reader.Read())
{
results.Add((QuestId)GetUInt32(reader, "quest_id"));
results.Add(GetUInt32(reader, "quest_schedule_id"));
}
});
});
return results;
}

public bool DeletePriorityQuest(uint characterCommonId, QuestId questId)
public bool DeletePriorityQuest(uint characterCommonId, uint questScheduleId)
{
using TCon connection = OpenNewConnection();
return DeletePriorityQuest(connection, characterCommonId, questId);
return DeletePriorityQuest(connection, characterCommonId, questScheduleId);
}

public bool DeletePriorityQuest(TCon connection, uint characterCommonId, QuestId questId)
public bool DeletePriorityQuest(TCon connection, uint characterCommonId, uint questScheduleId)
{
return ExecuteNonQuery(connection, SqlDeletePriorityQuest, command =>
{
AddParameter(command, "@character_common_id", characterCommonId);
AddParameter(command, "quest_id", (uint)questId);
AddParameter(command, "quest_schedule_id", questScheduleId);
}) == 1;
}
}
Expand Down
Loading

0 comments on commit 3696012

Please sign in to comment.