From d21f7f98cd2b3f3dfe918cba86426fa3f7b9ad5a Mon Sep 17 00:00:00 2001 From: Dinopony Date: Fri, 13 Oct 2023 20:00:32 +0200 Subject: [PATCH] Added a "hint token" system for manually redeeming hints --- HintMachine/Globals.cs | 2 +- HintMachine/HintQuest.cs | 7 +++- HintMachine/HintQuestCounter.cs | 32 +++++++++++---- HintMachine/MainWindow.xaml | 71 +++++++++++++++++++-------------- HintMachine/MainWindow.xaml.cs | 50 ++++++++++++++++++----- 5 files changed, 113 insertions(+), 49 deletions(-) diff --git a/HintMachine/Globals.cs b/HintMachine/Globals.cs index 1767a2b..dd303ae 100644 --- a/HintMachine/Globals.cs +++ b/HintMachine/Globals.cs @@ -19,7 +19,7 @@ internal static class Globals /// /// The minimal duration between two hint queries obtained from quests /// - public const int HintQueueInterval = 2000; + public const int HintQueueInterval = 1000; /// /// The maximal amount of pending hints obtained from quest that can be stored at any given time. diff --git a/HintMachine/HintQuest.cs b/HintMachine/HintQuest.cs index bd74441..ed18978 100644 --- a/HintMachine/HintQuest.cs +++ b/HintMachine/HintQuest.cs @@ -26,7 +26,12 @@ public abstract class HintQuest public HintQuest() {} - public abstract bool CheckCompletion(); + /// + /// A method which checks if quest has been completed, decreases the CurrentValue until the quest reaches a + /// "non-completed" state and returns the number of awarded hints. + /// + /// the number of obtained hints + public abstract int CheckAndCommitCompletion(); public abstract void InitComponents(Grid questsGrid); diff --git a/HintMachine/HintQuestCounter.cs b/HintMachine/HintQuestCounter.cs index 22f32e7..e62e605 100644 --- a/HintMachine/HintQuestCounter.cs +++ b/HintMachine/HintQuestCounter.cs @@ -42,9 +42,18 @@ public long CurrentValue _lastIncrementTime = now; } - long absDiff = Math.Abs(_currentValue - value); - if (MaxIncrease != 0 && absDiff > MaxIncrease && absDiff != GoalValue) - return; + // If value is increasing, check if it does not increase more than the defined MaxIncrease + // (this is mostly used to prevent blatant cheating / bugged value readings) + if(value > _currentValue) + { + long diff = _currentValue - value; + + // If MaxIncrease is not defined for that quest, use a default value of (2 x GoalValue) + long realMaxIncrease = (MaxIncrease > 0) ? MaxIncrease : GoalValue * 2; + + if (diff > realMaxIncrease) + return; + } _currentValue = value; } @@ -72,13 +81,20 @@ public float GetProgression() return (float)CurrentValue / GoalValue; } - public override bool CheckCompletion() + public override int CheckAndCommitCompletion() { - if (CurrentValue < GoalValue) - return false; + int obtainedHints = 0; + + if (GoalValue == 0) + return 0; + + while (CurrentValue >= GoalValue) + { + obtainedHints += AwardedHints; + CurrentValue -= GoalValue; + } - CurrentValue -= GoalValue; - return true; + return obtainedHints; } public override void InitComponents(Grid questsGrid) diff --git a/HintMachine/MainWindow.xaml b/HintMachine/MainWindow.xaml index 5fbb371..b648778 100644 --- a/HintMachine/MainWindow.xaml +++ b/HintMachine/MainWindow.xaml @@ -55,41 +55,54 @@ + + + + + + - + -