Revamp UI a whole lot
This commit is contained in:
@@ -26,13 +26,24 @@ namespace KernelPanic.Meta
|
||||
/// <summary>One persistent, rolling 24-hour window. All time comes from the caller for deterministic tests.</summary>
|
||||
public static class DailyQuests
|
||||
{
|
||||
public const int Count = 3;
|
||||
public const int Count = 5;
|
||||
public const int CompletionBonusBandwidth = 250;
|
||||
public const int CompletionBonusEntropy = 125;
|
||||
public const int CompletionBonusCommits = 2;
|
||||
public const long PeriodTicks = TimeSpan.TicksPerDay;
|
||||
public static readonly IReadOnlyList<DailyQuestKind> Pool = Array.AsReadOnly((DailyQuestKind[])Enum.GetValues(typeof(DailyQuestKind)));
|
||||
private static readonly DailyQuestKind[] LegacySelection = { DailyQuestKind.Waves, DailyQuestKind.Cards, DailyQuestKind.Damage };
|
||||
private const int CompletionBonusBit = 1 << 8;
|
||||
private static readonly DailyQuestKind[] FallbackSelection =
|
||||
{
|
||||
DailyQuestKind.Waves,
|
||||
DailyQuestKind.Cards,
|
||||
DailyQuestKind.Damage,
|
||||
DailyQuestKind.BlockDamage,
|
||||
DailyQuestKind.NativeCards
|
||||
};
|
||||
|
||||
public static IReadOnlyList<DailyQuestKind> Active(DailyQuestState state) =>
|
||||
ValidSelection(state.selectedQuests) ? state.selectedQuests : LegacySelection;
|
||||
ValidSelection(state.selectedQuests) ? state.selectedQuests : FallbackSelection;
|
||||
|
||||
public static bool IsActive(DailyQuestState state, DailyQuestKind kind)
|
||||
{
|
||||
@@ -51,6 +62,28 @@ namespace KernelPanic.Meta
|
||||
return true;
|
||||
}
|
||||
|
||||
private static bool EnsureFiveQuestSelection(DailyQuestState state)
|
||||
{
|
||||
if (ValidSelection(state.selectedQuests)) return false;
|
||||
var expanded = new List<DailyQuestKind>(Count);
|
||||
if (state.selectedQuests != null)
|
||||
{
|
||||
foreach (var kind in state.selectedQuests)
|
||||
{
|
||||
if (!Enum.IsDefined(typeof(DailyQuestKind), kind) || expanded.Contains(kind)) continue;
|
||||
expanded.Add(kind);
|
||||
if (expanded.Count == Count) break;
|
||||
}
|
||||
}
|
||||
foreach (var kind in Pool)
|
||||
{
|
||||
if (!expanded.Contains(kind)) expanded.Add(kind);
|
||||
if (expanded.Count == Count) break;
|
||||
}
|
||||
state.selectedQuests = expanded.ToArray();
|
||||
return true;
|
||||
}
|
||||
|
||||
private static void PickQuests(DailyQuestState state)
|
||||
{
|
||||
if (state.selectionSeed == 0)
|
||||
@@ -101,6 +134,20 @@ namespace KernelPanic.Meta
|
||||
_ => throw new ArgumentOutOfRangeException(nameof(kind))
|
||||
};
|
||||
|
||||
// Commits are earned by objectives that represent sustained play or a run milestone.
|
||||
public static int CommitReward(DailyQuestKind kind) => kind switch
|
||||
{
|
||||
DailyQuestKind.Waves => 1,
|
||||
DailyQuestKind.ShieldDamage => 1,
|
||||
DailyQuestKind.SurviveRounds => 1,
|
||||
DailyQuestKind.WaveFive => 2,
|
||||
DailyQuestKind.Cards => 0,
|
||||
DailyQuestKind.NativeCards => 0,
|
||||
DailyQuestKind.Damage => 0,
|
||||
DailyQuestKind.BlockDamage => 0,
|
||||
_ => throw new ArgumentOutOfRangeException(nameof(kind))
|
||||
};
|
||||
|
||||
public static string Description(DailyQuestKind kind) => kind switch
|
||||
{
|
||||
DailyQuestKind.Waves => "Clear 3 waves",
|
||||
@@ -130,19 +177,25 @@ namespace KernelPanic.Meta
|
||||
public static bool Claimed(DailyQuestState state, DailyQuestKind kind) =>
|
||||
(state.claimedMask & (1 << (int)kind)) != 0;
|
||||
|
||||
public static bool CompletionBonusClaimed(DailyQuestState state) =>
|
||||
(state.claimedMask & CompletionBonusBit) != 0;
|
||||
|
||||
public static bool AllClaimed(DailyQuestState state)
|
||||
{
|
||||
foreach (var kind in Active(state)) if (!Claimed(state, kind)) return false;
|
||||
return true;
|
||||
}
|
||||
|
||||
public static bool Refresh(DailyQuestState state, DateTime utcNow)
|
||||
{
|
||||
long now = utcNow.ToUniversalTime().Ticks;
|
||||
if (state.refreshAtUtcTicks > now && state.refreshAtUtcTicks <= DateTime.MaxValue.Ticks)
|
||||
{
|
||||
if (ValidSelection(state.selectedQuests)) return false;
|
||||
// Schema 7 had three fixed quests. Preserve that day's progress and rewards.
|
||||
state.selectedQuests = (DailyQuestKind[])LegacySelection.Clone();
|
||||
return true;
|
||||
// Expand older three-task periods in place so their progress and claims survive migration.
|
||||
return EnsureFiveQuestSelection(state);
|
||||
}
|
||||
// Advance by whole periods, retaining the original reset time even after days away.
|
||||
if (state.refreshAtUtcTicks > 0 && !ValidSelection(state.selectedQuests))
|
||||
state.selectedQuests = (DailyQuestKind[])LegacySelection.Clone();
|
||||
if (state.refreshAtUtcTicks > 0) EnsureFiveQuestSelection(state);
|
||||
state.refreshAtUtcTicks = state.refreshAtUtcTicks > 0 && state.refreshAtUtcTicks <= now
|
||||
? state.refreshAtUtcTicks + ((now - state.refreshAtUtcTicks) / PeriodTicks + 1) * PeriodTicks
|
||||
: now + PeriodTicks;
|
||||
@@ -181,11 +234,22 @@ namespace KernelPanic.Meta
|
||||
if (!Enum.IsDefined(typeof(DailyQuestKind), kind) || !IsActive(data.dailyQuests, kind) || data.dailyQuests.refreshAtUtcTicks != expectedRefresh
|
||||
|| Claimed(data.dailyQuests, kind) || Progress(data.dailyQuests, kind) < Target(kind)) return false;
|
||||
var reward = Reward(kind);
|
||||
if (data.bandwidthBalance > int.MaxValue - reward.Bandwidth
|
||||
|| data.entropyBalance > int.MaxValue - reward.Entropy) return false;
|
||||
data.dailyQuests.claimedMask |= 1 << (int)kind;
|
||||
data.bandwidthBalance += reward.Bandwidth;
|
||||
data.entropyBalance += reward.Entropy;
|
||||
int commits = CommitReward(kind);
|
||||
int questBit = 1 << (int)kind;
|
||||
int nextMask = data.dailyQuests.claimedMask | questBit;
|
||||
bool awardsCompletionBonus = !CompletionBonusClaimed(data.dailyQuests);
|
||||
foreach (var activeKind in Active(data.dailyQuests))
|
||||
awardsCompletionBonus &= (nextMask & (1 << (int)activeKind)) != 0;
|
||||
int bandwidth = reward.Bandwidth + (awardsCompletionBonus ? CompletionBonusBandwidth : 0);
|
||||
int entropy = reward.Entropy + (awardsCompletionBonus ? CompletionBonusEntropy : 0);
|
||||
int totalCommits = commits + (awardsCompletionBonus ? CompletionBonusCommits : 0);
|
||||
if (data.bandwidthBalance > int.MaxValue - bandwidth
|
||||
|| data.entropyBalance > int.MaxValue - entropy
|
||||
|| data.commitsBalance > int.MaxValue - totalCommits) return false;
|
||||
data.dailyQuests.claimedMask = nextMask | (awardsCompletionBonus ? CompletionBonusBit : 0);
|
||||
data.bandwidthBalance += bandwidth;
|
||||
data.entropyBalance += entropy;
|
||||
data.commitsBalance += totalCommits;
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user