Skip to content

Commit

Permalink
feat: add quest restrictions info
Browse files Browse the repository at this point in the history
  • Loading branch information
DorielRivalet committed Feb 22, 2024
1 parent eb89589 commit 5e18c6e
Show file tree
Hide file tree
Showing 4 changed files with 174 additions and 12 deletions.
48 changes: 48 additions & 0 deletions MHFZ_Overlay/Models/QuestRestriction.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
// © 2023 The mhfz-overlay developers.
// Use of this source code is governed by a MIT license that can be
// found in the LICENSE file.

namespace MHFZ_Overlay.Models;

using System;

// TODO: ORM
public sealed class QuestRestriction
{
public bool HalkPot { get; set; }

public bool CourseAttack { get; set; }

public bool Halk { get; set; }

public bool PoogieCuff { get; set; }

public bool ActiveFeature { get; set; }

public bool SecretTechnique { get; set; }

public bool Transcend { get; set; }

public bool DivaPrayerGem { get; set; }

public bool TwinHiden { get; set; }

public bool Rasta { get; set; }

public bool Partner { get; set; }

public bool Partnya { get; set; }

public bool SoulRevival { get; set; }

public bool DivaSkill { get; set; }

public bool QuestBonusReward { get; set; }

public bool SimpleMode { get; set; }

public bool GPSkill { get; set; }

public bool Sigil { get; set; }

}
2 changes: 1 addition & 1 deletion MHFZ_Overlay/Models/Structures/Bitfields.cs
Original file line number Diff line number Diff line change
Expand Up @@ -291,7 +291,7 @@ public enum QuestVariant2 : uint
/// </summary>
Level9999 = 64,
/// <summary>
/// no rasta, partnya, halk, soul revival or similar, halk pot, diva skill, diva prayer gem
/// no rasta, partner, partnya, halk, soul revival or similar, halk pot, diva skill, diva prayer gem
/// </summary>
Road = 128,
All = 255,
Expand Down
113 changes: 113 additions & 0 deletions MHFZ_Overlay/Services/DatabaseService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8181,6 +8181,119 @@ public QuestsGamePatch GetQuestsGamePatch(long runID)
return data;
}

public QuestRestriction GetQuestRestrictions(long runID)
{
QuestRestriction data = new();
if (string.IsNullOrEmpty(this.dataSource))
{
Logger.Warn(CultureInfo.InvariantCulture, "Cannot get quest restrictions. dataSource: {0}", this.dataSource);
return data;
}

// Use a SQL query to retrieve the Quest for the specific RunID from the database
using (var conn = new SQLiteConnection(this.dataSource))
{
conn.Open();
using (var transaction = conn.BeginTransaction())
{
try
{
using (var cmd = new SQLiteCommand("SELECT * FROM QuestsQuestVariant WHERE RunID = @runID", conn))
{
cmd.Parameters.AddWithValue("@runID", runID);

using (var reader = cmd.ExecuteReader())
{
if (reader.Read())
{
var questVariant2 = long.Parse(reader["QuestVariant2"]?.ToString() ?? "0", CultureInfo.InvariantCulture);
var questVariant3 = long.Parse(reader["QuestVariant3"]?.ToString() ?? "0", CultureInfo.InvariantCulture);

data = GetQuestRestrictions((QuestVariant2)questVariant2, (QuestVariant3)questVariant3);
}
}
}

transaction.Commit();
}
catch (Exception ex)
{
HandleError(transaction, ex);
}
}
}

return data;
}

private QuestRestriction GetQuestRestrictions(QuestVariant2 questVariant2, QuestVariant3 questVariant3)
{
QuestRestriction restrictions = new();

if (questVariant2.HasFlag(QuestVariant2.DisableHalkPoogieCuff))
{
restrictions.HalkPot = true;
restrictions.CourseAttack = true;
}

if (questVariant2.HasFlag(QuestVariant2.DisableHalkPoogieCuff))
{
restrictions.Halk = true;
restrictions.PoogieCuff = true;
}

if (questVariant2.HasFlag(QuestVariant2.DisableActiveFeature))
{
restrictions.ActiveFeature = true;
}

if (questVariant2.HasFlag(QuestVariant2.Level9999))
{
restrictions.SecretTechnique = true;
restrictions.Transcend = true;
restrictions.HalkPot = true;
restrictions.CourseAttack = true;
restrictions.DivaPrayerGem = true;
restrictions.TwinHiden = true;
}

if (questVariant2.HasFlag(QuestVariant2.Road))
{
restrictions.Rasta = true;
restrictions.Partner = true;
restrictions.Partnya = true;
restrictions.Halk = true;
restrictions.SoulRevival = true;
restrictions.HalkPot = true;
restrictions.DivaSkill = true;
restrictions.DivaPrayerGem = true;
}

if (questVariant3.HasFlag(QuestVariant3.DisableRewardBonus))
{
restrictions.QuestBonusReward = true;
}

if (questVariant3.HasFlag(QuestVariant3.NoSimpleMode))
{
restrictions.SimpleMode = true;
}

if (questVariant3.HasFlag(QuestVariant3.NoGPSkills))
{
restrictions.Transcend = true;
restrictions.GPSkill = true;
restrictions.DivaSkill = true;
}

if (questVariant3.HasFlag(QuestVariant3.DisabledSigil))
{
restrictions.Sigil = true;
}

return restrictions;
}

private Quest GetLastQuest(SQLiteConnection conn)
{
Quest quest = new();
Expand Down
23 changes: 12 additions & 11 deletions MHFZ_Overlay/ViewModels/Windows/AddressModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8468,6 +8468,7 @@ public string GenerateGearStats(long? runID = null)

var courseInfo = $"Main: {GetMainCourses(courses.Rights)}\nAdditional: {GetAdditionalCourses(courses.Rights)}";
var patchInfo = DatabaseManagerInstance.GetQuestsGamePatch((long)runID);
var questRestrictions = DatabaseManagerInstance.GetQuestRestrictions((long)runID);

// TODO: fix
// TODO partnyaBagItems
Expand All @@ -8477,13 +8478,13 @@ public string GenerateGearStats(long? runID = null)
$@"{createdBy} {weaponClass}({gender}){metadata}

Set Name: {gearName}
{weaponName}: {realweaponName}
{weaponName}{(questRestrictions.Sigil ? " (disabled sigils)" : string.Empty)}: {realweaponName}
Head: {head}
Chest: {chest}
Arms: {arms}
Waist: {waist}
Legs: {legs}
Cuffs: {cuffs}
Cuffs: {cuffs}{(questRestrictions.PoogieCuff ? " (disabled cuffs)" : string.Empty)}

Run Date: {date} | Run Hash: {hash}

Expand All @@ -8493,24 +8494,24 @@ public string GenerateGearStats(long? runID = null)
Automatic Skills:
{automaticSkillsList}

Active Skills{gouBoost}:
Active Skills{(questRestrictions.GPSkill ? " (disabled GP Skills)" : string.Empty)}{gouBoost}:
{armorSkills}

Caravan Skills:
{caravanSkillsList}

Diva:
{(divaSkill == "None" ? "No Skill" : divaSkill)}
{(divaSkill == "None" ? "No Skill" : divaSkill)}{(questRestrictions.DivaSkill ? " (disabled skill)" : string.Empty)}
Song {(diva.DivaSongBuffOn > 0 ? "ON" : "OFF")}

Diva Prayer Gems:
Diva Prayer Gems{(questRestrictions.DivaPrayerGem ? " (disabled gems)" : string.Empty)}:
{GetDivaPrayerGems(diva)}

Guild:
{guildFood}
{GetGuildPoogieEffect(guildPoogie)}

Style Rank:
Style Rank{(questRestrictions.SecretTechnique ? " (disabled secret technique)" : string.Empty)}{(questRestrictions.SoulRevival ? " (disabled soul revival)" : string.Empty)}{(questRestrictions.TwinHiden ? " (disabled twin hiden)" : string.Empty)}:
{styleRankSkillsList}

Items:
Expand All @@ -8525,19 +8526,19 @@ public string GenerateGearStats(long? runID = null)
Road/Duremudira Skills:
{roadDureSkillsList}

Quest: {questName}
Quest{(questRestrictions.QuestBonusReward ? " (disabled bonus reward)" : string.Empty)}: {questName}
{questObjectiveType} {questObjectiveQuantity} {questObjectiveName}
Category: {questCategory}
Party Size: {partySize}
Mode: {toggleModeName}
Active Feature {(activeFeatureState == true ? "ON" : "OFF")}
Active Feature {(activeFeatureState == true ? "ON" : "OFF")}{(questRestrictions.ActiveFeature ? " (disabled active feature)" : string.Empty)}

Courses:
Courses{(questRestrictions.CourseAttack ? " (disabled course attack)" : string.Empty)}:
{courseInfo}

Halk:
{(halk.HalkOn > 0 ? "Active" : "Inactive")}
Halk Pot {(halk.HalkPotEffectOn > 0 ? "ON" : "OFF")}
{(halk.HalkOn > 0 ? "Active" : "Inactive")}{(questRestrictions.Halk ? " (disabled halk)" : string.Empty)}
Halk Pot {(halk.HalkPotEffectOn > 0 ? "ON" : "OFF")}{(questRestrictions.Sigil ? " (disabled halk pot)" : string.Empty)}
LV{halk.HalkLevel}
Element Type {GetHalkElement(halk)}
Status Type {GetHalkStatus(halk)}
Expand Down

0 comments on commit 5e18c6e

Please sign in to comment.