Skip to content

Commit

Permalink
feat: add run buffs tags
Browse files Browse the repository at this point in the history
  • Loading branch information
DorielRivalet committed Feb 8, 2024
1 parent 1f37698 commit d9242d2
Show file tree
Hide file tree
Showing 3 changed files with 135 additions and 6 deletions.
66 changes: 64 additions & 2 deletions MHFZ_Overlay/Services/DatabaseService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2041,23 +2041,50 @@ FinalTimeValue ASC

sql = @"INSERT INTO QuestsRunBuffs (
RunBuffs,
RunBuffsTag,
RunID
) VALUES (
@RunBuffs,
@RunBuffsTag,
@RunID
)";

using (var cmd = new SQLiteCommand(sql, conn))
{
// 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");



Expand Down Expand Up @@ -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))
{
Expand Down Expand Up @@ -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();
Expand Down Expand Up @@ -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)
)";
Expand Down Expand Up @@ -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)
)";
Expand Down
73 changes: 70 additions & 3 deletions MHFZ_Overlay/ViewModels/Windows/AddressModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1675,7 +1675,7 @@ public string GetFinalOverlayModeForDisplay()
{
if (OverlayModeDictionary.Last().Value == "Speedrun")
{
return "Speedrun+" + $" ({(uint)GetRunBuffs()})";
return "Speedrun+" + $" ({GetRunBuffsTag(GetRunBuffs())})";
}

return OverlayModeDictionary.Last().Value + "+";
Expand All @@ -1684,7 +1684,7 @@ public string GetFinalOverlayModeForDisplay()
{
if (OverlayModeDictionary.First().Value == "Speedrun")
{
return "Speedrun+" + $" ({(uint)GetRunBuffs()})";
return "Speedrun+" + $" ({GetRunBuffsTag(GetRunBuffs())})";
}

return OverlayModeDictionary.First().Value + "+";
Expand Down Expand Up @@ -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),
};
}

/// <summary>
/// TODO test
/// </summary>
/// <param name="runBuffs"></param>
/// <returns></returns>
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();
}

/// <summary>
/// Gets the run buffs
/// </summary>
Expand Down Expand Up @@ -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);

Expand Down
2 changes: 1 addition & 1 deletion MHFZ_Overlay/Views/Windows/ConfigWindow.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -1558,7 +1558,7 @@
<ui:ToggleSwitch HorizontalAlignment="Center" Grid.Row="3" Grid.Column="1" IsChecked="{Binding Source={StaticResource Settings}, Path=EnableInputLogging}"/>
<StackPanel Margin="5" Orientation="Horizontal" Grid.Row="4" Grid.Column="0" >
<ui:SymbolIcon Symbol="Info28" FontSize="28" Foreground="{StaticResource Blue}" Margin="0,0,5,0" ToolTip="Required for Speedrun Modes"/>
<TextBlock ToolTip="Show a watermark that displays the overlay mode. If using speedrun mode, also shows the run buffs value." Style="{StaticResource ConfigTextBox}" Text="Overlay Mode Watermark" />
<TextBlock ToolTip="Show a watermark that displays the overlay mode. If using speedrun mode, also shows the run buffs value. See the FAQ for the values of TA, FDS, FDP, FST and FCA." Style="{StaticResource ConfigTextBox}" Text="Overlay Mode Watermark" />
</StackPanel>
<ui:ToggleSwitch HorizontalAlignment="Center" Grid.Row="4" Grid.Column="1" IsChecked="{Binding Source={StaticResource Settings}, Path=OverlayModeWatermarkShown}"/>

Expand Down

0 comments on commit d9242d2

Please sign in to comment.