From d9242d2a1c39640aad47c70796eea9ef3de410a2 Mon Sep 17 00:00:00 2001 From: Doriel Rivalet <100863878+DorielRivalet@users.noreply.github.com> Date: Thu, 8 Feb 2024 01:39:21 -0300 Subject: [PATCH] feat: add run buffs tags --- MHFZ_Overlay/Services/DatabaseService.cs | 66 ++++++++++++++++- .../ViewModels/Windows/AddressModel.cs | 73 ++++++++++++++++++- MHFZ_Overlay/Views/Windows/ConfigWindow.xaml | 2 +- 3 files changed, 135 insertions(+), 6 deletions(-) diff --git a/MHFZ_Overlay/Services/DatabaseService.cs b/MHFZ_Overlay/Services/DatabaseService.cs index e8031267..d0e0c5d8 100644 --- a/MHFZ_Overlay/Services/DatabaseService.cs +++ b/MHFZ_Overlay/Services/DatabaseService.cs @@ -2041,9 +2041,11 @@ FinalTimeValue ASC sql = @"INSERT INTO QuestsRunBuffs ( RunBuffs, + RunBuffsTag, RunID ) VALUES ( @RunBuffs, + @RunBuffsTag, @RunID )"; @@ -2051,13 +2053,38 @@ FinalTimeValue ASC { // TODO test cmd.Parameters.AddWithValue("@RunBuffs", runBuffs); + cmd.Parameters.AddWithValue("@RunBuffsTag", dataLoader.Model.GetRunBuffsTag((RunBuff)runBuffs)); cmd.Parameters.AddWithValue("@RunID", runID); cmd.ExecuteNonQuery(); } Logger.Debug("Inserted into QuestsRunBuffs table"); + sql = @"INSERT INTO QuestsQuestVariant ( + QuestVariant1, + QuestVariant2, + QuestVariant3, + QuestVariant4, + RunID + ) VALUES ( + @QuestVariant1, + @QuestVariant2, + @QuestVariant3, + @QuestVariant4, + @RunID + )"; + using (var cmd = new SQLiteCommand(sql, conn)) + { + cmd.Parameters.AddWithValue("@QuestVariant1", model.QuestVariant1()); + cmd.Parameters.AddWithValue("@QuestVariant2", model.QuestVariant2()); + cmd.Parameters.AddWithValue("@QuestVariant3", model.QuestVariant3()); + cmd.Parameters.AddWithValue("@QuestVariant4", model.QuestVariant4()); + cmd.Parameters.AddWithValue("@RunID", runID); + cmd.ExecuteNonQuery(); + } + + Logger.Debug("Inserted into QuestsQuestVariant table"); @@ -3105,7 +3132,25 @@ AFTER DELETE ON QuestsRunBuffs cmd.ExecuteNonQuery(); } - // TODO run buffs + using (var cmd = new SQLiteCommand(conn)) + { + cmd.CommandText = @"CREATE TRIGGER IF NOT EXISTS prevent_quests_quest_variant_updates + AFTER UPDATE ON QuestsQuestVariant + BEGIN + SELECT RAISE(ROLLBACK, 'Updating rows is not allowed. Keep in mind that all attempted modifications are logged into the central database.'); + END;"; + cmd.ExecuteNonQuery(); + } + + using (var cmd = new SQLiteCommand(conn)) + { + cmd.CommandText = @"CREATE TRIGGER IF NOT EXISTS prevent_quests_quest_variant_deletion + AFTER DELETE ON QuestsQuestVariant + BEGIN + SELECT RAISE(ROLLBACK, 'Updating rows is not allowed. Keep in mind that all attempted modifications are logged into the central database.'); + END;"; + cmd.ExecuteNonQuery(); + } using (var cmd = new SQLiteCommand(conn)) { @@ -3429,8 +3474,9 @@ public void FillRunBuffs(SQLiteConnection conn, DataLoader dataLoader) // Separate command for the insert operation using (var cmd2 = new SQLiteCommand(conn)) { - cmd2.CommandText = "INSERT INTO QuestsRunBuffs(RunBuffs, RunID) VALUES (@RunBuffs, @RunID)"; + cmd2.CommandText = "INSERT INTO QuestsRunBuffs(RunBuffs, RunBuffsTag, RunID) VALUES (@RunBuffs, @RunBuffsTag, @RunID)"; cmd2.Parameters.AddWithValue("@RunBuffs", dataLoader.Model.GetRunBuffs(actualOverlayMode)); + cmd2.Parameters.AddWithValue("@RunBuffsTag", dataLoader.Model.GetRunBuffsTag(dataLoader.Model.GetRunBuffs(actualOverlayMode))); cmd2.Parameters.AddWithValue("@RunID", runID); cmd2.ExecuteNonQuery(); @@ -5952,6 +5998,21 @@ FOREIGN KEY(RunID) REFERENCES Quests(RunID) sql = @"CREATE TABLE IF NOT EXISTS QuestsRunBuffs( QuestsRunBuffsID INTEGER PRIMARY KEY AUTOINCREMENT, RunBuffs INTEGER NOT NULL DEFAULT 0, + RunBuffsTag TEXT NOT NULL DEFAULT '', + RunID INTEGER NOT NULL, + FOREIGN KEY(RunID) REFERENCES Quests(RunID) + )"; + using (var cmd = new SQLiteCommand(sql, conn)) + { + cmd.ExecuteNonQuery(); + } + + sql = @"CREATE TABLE IF NOT EXISTS QuestsQuestVariant( + QuestsQuestVariantID INTEGER PRIMARY KEY AUTOINCREMENT, + QuestVariant1 INTEGER NOT NULL DEFAULT 0, + QuestVariant2 INTEGER NOT NULL DEFAULT 0, + QuestVariant3 INTEGER NOT NULL DEFAULT 0, + QuestVariant4 INTEGER NOT NULL DEFAULT 0, RunID INTEGER NOT NULL, FOREIGN KEY(RunID) REFERENCES Quests(RunID) )"; @@ -17541,6 +17602,7 @@ private void UpdateRunBuffs(SQLiteConnection connection, DataLoader dataLoader) sql = @"CREATE TABLE IF NOT EXISTS QuestsRunBuffs( QuestsRunBuffsID INTEGER PRIMARY KEY AUTOINCREMENT, RunBuffs INTEGER NOT NULL DEFAULT 0, + RunBuffsTag TEXT NOT NULL DEFAULT '', RunID INTEGER NOT NULL, FOREIGN KEY(RunID) REFERENCES Quests(RunID) )"; diff --git a/MHFZ_Overlay/ViewModels/Windows/AddressModel.cs b/MHFZ_Overlay/ViewModels/Windows/AddressModel.cs index 44ad2d2a..804d7f6d 100644 --- a/MHFZ_Overlay/ViewModels/Windows/AddressModel.cs +++ b/MHFZ_Overlay/ViewModels/Windows/AddressModel.cs @@ -1675,7 +1675,7 @@ public string GetFinalOverlayModeForDisplay() { if (OverlayModeDictionary.Last().Value == "Speedrun") { - return "Speedrun+" + $" ({(uint)GetRunBuffs()})"; + return "Speedrun+" + $" ({GetRunBuffsTag(GetRunBuffs())})"; } return OverlayModeDictionary.Last().Value + "+"; @@ -1684,7 +1684,7 @@ public string GetFinalOverlayModeForDisplay() { if (OverlayModeDictionary.First().Value == "Speedrun") { - return "Speedrun+" + $" ({(uint)GetRunBuffs()})"; + return "Speedrun+" + $" ({GetRunBuffsTag(GetRunBuffs())})"; } return OverlayModeDictionary.First().Value + "+"; @@ -2752,6 +2752,57 @@ public bool isHalkPotEquipped() return (PouchItem1ID() == 4952 || PouchItem2ID() == 4952 || PouchItem3ID() == 4952 || PouchItem4ID() == 4952 || PouchItem5ID() == 4952 || PouchItem6ID() == 4952 || PouchItem7ID() == 4952 || PouchItem8ID() == 4952 || PouchItem9ID() == 4952 || PouchItem10ID() == 4952 || PouchItem11ID() == 4952 || PouchItem12ID() == 4952 || PouchItem13ID() == 4952 || PouchItem14ID() == 4952 || PouchItem15ID() == 4952 || PouchItem16ID() == 4952 || PouchItem17ID() == 4952 || PouchItem18ID() == 4952 || PouchItem19ID() == 4952 || PouchItem20ID() == 4952 || PartnyaBagItem1ID() == 4952 || PartnyaBagItem2ID() == 4952 || PartnyaBagItem3ID() == 4952 || PartnyaBagItem4ID() == 4952 || PartnyaBagItem5ID() == 4952 || PartnyaBagItem6ID() == 4952 || PartnyaBagItem7ID() == 4952 || PartnyaBagItem8ID() == 4952 || PartnyaBagItem9ID() == 4952 || PartnyaBagItem10ID() == 4952); } + public string GetRunBuffsTag(RunBuff runBuff) + { + return runBuff switch + { + RunBuff.LeaderboardTimeAttack => "TA", + RunBuff.LeaderboardFreestyleDivaSkill => "FDS", + RunBuff.LeaderboardFreestyleDivaPrayerGem => "FDP", + RunBuff.LeaderboardFreestyleSecretTechnique => "FST", + RunBuff.LeaderboardFreestyleCourseAttackBoost => "FCA", + _ => CalculateRunBuffsTag(runBuff), + }; + } + + /// + /// TODO test + /// + /// + /// + public string CalculateRunBuffsTag(RunBuff runBuffs) + { + var value = (uint)runBuffs; + var all = (uint)RunBuff.All; + + if (IsBitfieldContainingFlag(value, RunBuff.CourseAttackBoost, all)) + { + return "FCA"; + } + + if (IsBitfieldContainingFlag(value, RunBuff.SecretTechnique, all)) + { + return "FST"; + } + + if (IsBitfieldContainingFlag(value, RunBuff.DivaPrayerGem, all)) + { + return "FDP"; + } + + if (IsBitfieldContainingFlag(value, RunBuff.DivaSkill, all)) + { + return "FDS"; + } + + if (!IsBitfieldContainingFlag(value, RunBuff.HalkPotEffect, all)) + { + return "TA"; + } + + return value.ToString(); + } + /// /// Gets the run buffs /// @@ -13379,7 +13430,23 @@ public void ClearGraphCollections() } } - public string OverlayModeWatermarkText => ShowOverlayModeFinalMode() ? GetFinalOverlayModeForDisplay() : GetOverlayModeForStorage() == "Speedrun" ? $"Speedrun ({(uint)GetRunBuffs()})" : GetOverlayModeForStorage(); + public string OverlayModeWatermarkText + { + get + { + if (ShowOverlayModeFinalMode()) + { + return GetFinalOverlayModeForDisplay(); + } + + if (GetOverlayModeForStorage() == "Speedrun") + { + return $"Speedrun ({GetRunBuffsTag(GetRunBuffs())})"; + } + + return GetOverlayModeForStorage(); + } + } public string QuestIDBind => this.QuestID().ToString(CultureInfo.InvariantCulture); diff --git a/MHFZ_Overlay/Views/Windows/ConfigWindow.xaml b/MHFZ_Overlay/Views/Windows/ConfigWindow.xaml index 1302aaca..556505a7 100644 --- a/MHFZ_Overlay/Views/Windows/ConfigWindow.xaml +++ b/MHFZ_Overlay/Views/Windows/ConfigWindow.xaml @@ -1558,7 +1558,7 @@ - +