Revamp UI a whole lot

This commit is contained in:
2026-11-18 19:42:44 +01:00
parent 260abc2c98
commit fdde7f9d80
57 changed files with 2667 additions and 935 deletions
+78 -14
View File
@@ -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;
}
+28
View File
@@ -32,4 +32,32 @@ namespace KernelPanic.Meta
guaranteedDistroIds ??= new List<string>();
}
}
/// <summary>Persistent, bounded receipt rendered by <c>git log --pulls</c>.</summary>
[Serializable]
public sealed class GachaPullHistoryEntry
{
public string pulledUtc;
public string bannerId;
public int currencySpent;
public int entropySpent;
public List<GachaPullHistoryRewardEntry> rewards = new();
public void EnsureLists()
{
rewards ??= new List<GachaPullHistoryRewardEntry>();
}
}
[Serializable]
public sealed class GachaPullHistoryRewardEntry
{
public int stars;
public string displayName;
public GachaRewardType rewardType;
public PullOutcomeKind outcomeKind;
public int duplicateValue;
public bool guaranteed;
public bool pityTriggered;
}
}
+191 -1
View File
@@ -17,7 +17,11 @@ namespace KernelPanic.Meta
public const int BeginnerTenPullCost = 8;
public const int StandardSinglePullCost = 1;
public const int StandardTenPullCost = 10;
public const int LimitedSinglePullCost = 1;
public const int LimitedTenPullCost = 10;
public const int StandardFiveStarSelectorInterval = 200;
public const int MaxPullHistoryEntries = 100;
public const string LimitedFeaturedFiveStarDistroId = "nixos";
public const int FourStarHardPity = 10;
public const int FiveStarSoftPityStart = 66;
public const int FiveStarHardPity = 80;
@@ -32,10 +36,12 @@ namespace KernelPanic.Meta
private const double LimitedStandardFiveStarChance = 1d / 3d;
private readonly List<DistroDefinition> _bannerPool = new();
private readonly List<GachaPullHistoryEntry> _pullHistory = new();
private readonly Dictionary<GachaCurrencyType, int> _currencyBalances = new();
private readonly Random _random;
private GachaBannerState _beginnerState = new(BeginnerBannerId);
private GachaBannerState _standardState = new(StandardBannerId);
private GachaBannerState _limitedState = new(LimitedBannerId);
public GachaService()
: this(new Random())
@@ -54,6 +60,8 @@ namespace KernelPanic.Meta
public IReadOnlyList<DistroDefinition> BannerPool => _bannerPool;
public GachaBannerState BeginnerState => _beginnerState;
public GachaBannerState StandardState => _standardState;
public GachaBannerState LimitedState => _limitedState;
public IReadOnlyList<GachaPullHistoryEntry> PullHistory => _pullHistory;
public bool IsBeginnerBannerAvailable => !_beginnerState.exhausted && _beginnerState.totalPulls < BeginnerMaxPulls && _bannerPool.Count > 0;
public int PendingStandardFiveStarSelectors => Math.Max(0, _standardState.totalPulls / StandardFiveStarSelectorInterval - _standardState.fiveStarSelectorsClaimed);
@@ -86,6 +94,19 @@ namespace KernelPanic.Meta
_standardState.fiveStarPityCounter = Math.Max(0, _standardState.fiveStarPityCounter);
_standardState.fiveStarSelectorsClaimed = Math.Max(0, _standardState.fiveStarSelectorsClaimed);
_limitedState = data.limitedBannerState ?? new GachaBannerState(LimitedBannerId);
_limitedState.bannerId = LimitedBannerId;
_limitedState.EnsureLists();
_limitedState.pityCounter = Math.Max(0, _limitedState.pityCounter);
_limitedState.fiveStarPityCounter = Math.Max(0, _limitedState.fiveStarPityCounter);
_pullHistory.Clear();
for (int i = 0; i < data.gachaPullHistory.Count && i < MaxPullHistoryEntries; i++)
{
GachaPullHistoryEntry entry = CloneHistoryEntry(data.gachaPullHistory[i]);
if (entry != null) _pullHistory.Add(entry);
}
Changed?.Invoke();
}
@@ -101,6 +122,10 @@ namespace KernelPanic.Meta
data.commitsBalance = GetCurrencyBalance(GachaCurrencyType.StandardPull);
data.beginnerBannerState = CloneState(_beginnerState);
data.standardBannerState = CloneState(_standardState);
data.limitedBannerState = CloneState(_limitedState);
data.gachaPullHistory.Clear();
for (int i = 0; i < _pullHistory.Count && i < MaxPullHistoryEntries; i++)
data.gachaPullHistory.Add(CloneHistoryEntry(_pullHistory[i]));
}
public int GetCurrencyBalance(GachaCurrencyType currencyType)
@@ -235,7 +260,7 @@ namespace KernelPanic.Meta
return false;
}
}
else if (bannerId != StandardBannerId)
else if (bannerId != StandardBannerId && bannerId != LimitedBannerId)
{
failureReason = $"banner '{bannerId}' not implemented yet";
return false;
@@ -271,6 +296,11 @@ namespace KernelPanic.Meta
return pullCount == 10 ? StandardTenPullCost : StandardSinglePullCost;
}
if (bannerId == LimitedBannerId)
{
return pullCount == 10 ? LimitedTenPullCost : LimitedSinglePullCost;
}
return pullCount;
}
@@ -370,6 +400,64 @@ namespace KernelPanic.Meta
return new GachaPullResult(true, StandardBannerId, GachaCurrencyType.StandardPull, commitSpend, entropySpent, rewards, null);
}
public GachaPullResult PerformLimitedPull(int pullCount, EntropyWallet wallet, PullPaymentSource source)
{
if (!CanAffordPull(pullCount, wallet, source, LimitedBannerId, out string failureReason))
{
return GachaPullResult.Failed(LimitedBannerId, failureReason);
}
if (!PayForPull(pullCount, wallet, source, LimitedBannerId, out int commitSpend, out int entropySpent, out failureReason))
{
return GachaPullResult.Failed(LimitedBannerId, failureReason);
}
List<GachaReward> rewards = new();
for (int i = 0; i < pullCount; i++)
{
_limitedState.totalPulls++;
rewards.Add(RollLimitedReward(_limitedState));
}
Changed?.Invoke();
return new GachaPullResult(true, LimitedBannerId, GachaCurrencyType.StandardPull, commitSpend, entropySpent, rewards, null);
}
public void RecordPullHistory(GachaPullResult result, IReadOnlyList<CompletedGachaReward> completedRewards, DateTime utcNow)
{
if (!result.Success || completedRewards == null || completedRewards.Count == 0)
{
return;
}
GachaPullHistoryEntry entry = new()
{
pulledUtc = utcNow.ToUniversalTime().ToString("O"),
bannerId = result.BannerId,
currencySpent = Math.Max(0, result.CurrencySpent),
entropySpent = Math.Max(0, result.EntropySpent)
};
for (int i = 0; i < completedRewards.Count; i++)
{
CompletedGachaReward reward = completedRewards[i];
entry.rewards.Add(new GachaPullHistoryRewardEntry
{
stars = reward.Stars,
displayName = reward.DisplayName,
rewardType = reward.RewardType,
outcomeKind = reward.OutcomeKind,
duplicateValue = reward.MergesAwarded,
guaranteed = reward.Guaranteed,
pityTriggered = reward.PityTriggered
});
}
_pullHistory.Insert(0, entry);
if (_pullHistory.Count > MaxPullHistoryEntries)
_pullHistory.RemoveRange(MaxPullHistoryEntries, _pullHistory.Count - MaxPullHistoryEntries);
Changed?.Invoke();
}
public int GetStandardFiveStarSelectorProgress()
{
return _standardState.totalPulls % StandardFiveStarSelectorInterval;
@@ -526,6 +614,50 @@ namespace KernelPanic.Meta
return GachaReward.Package(4, "4-star package", pityTriggered, false);
}
private GachaReward RollLimitedReward(GachaBannerState state)
{
if (TryRollFiveStar(state, out bool fiveStarPityTriggered))
{
if (!ResolveFeaturedTierIsDistro())
{
return GachaReward.Package(5, "5-star package", fiveStarPityTriggered, false);
}
bool featuredWasGuaranteed = state.featuredFiveStarGuaranteed;
bool useStandardPool = ResolveLimitedFiveStarUsesStandardPool(state);
DistroDefinition distro = useStandardPool
? FindRandomBannerPoolDistroByStarsExcept(5, LimitedFeaturedFiveStarDistroId)
: FindBannerPoolDistroByStars(LimitedFeaturedFiveStarDistroId, 5) ?? FindRandomBannerPoolDistroByStars(5);
if (distro == null)
{
return GachaReward.Package(5, "5-star package", fiveStarPityTriggered, false);
}
return GachaReward.DistroReward(distro, 5, fiveStarPityTriggered, featuredWasGuaranteed,
featuredWasGuaranteed ? "feature-branch guarantee" : null);
}
bool pityTriggered = state.pityCounter >= FourStarHardPity - 1;
bool hitFourStar = pityTriggered || _random.NextDouble() < FourStarBaseChance;
if (!hitFourStar)
{
state.pityCounter++;
return GachaReward.Package(3, "3-star package", false, false);
}
state.pityCounter = 0;
if (ResolveFeaturedTierIsDistro())
{
DistroDefinition distro = FindLimitedFourStarDistro();
if (distro != null)
{
return GachaReward.DistroReward(distro, 4, pityTriggered, false);
}
}
return GachaReward.Package(4, "4-star package", pityTriggered, false);
}
private bool TryRollFiveStar(GachaBannerState state, out bool pityTriggered)
{
state ??= _beginnerState;
@@ -668,6 +800,35 @@ namespace KernelPanic.Meta
return eligible.Count == 0 ? null : eligible[_random.Next(eligible.Count)];
}
private DistroDefinition FindRandomBannerPoolDistroByStarsExcept(int stars, string excludedId)
{
List<DistroDefinition> eligible = new();
for (int i = 0; i < _bannerPool.Count; i++)
{
DistroDefinition distro = _bannerPool[i];
if (distro != null && GetDistroStars(distro) == stars
&& !string.Equals(distro.Id, excludedId, StringComparison.OrdinalIgnoreCase))
{
eligible.Add(distro);
}
}
return eligible.Count == 0 ? FindRandomBannerPoolDistroByStars(stars) : eligible[_random.Next(eligible.Count)];
}
private DistroDefinition FindLimitedFourStarDistro()
{
string[] featured = { "fedora", "ubuntu" };
List<DistroDefinition> eligible = new();
for (int i = 0; i < featured.Length; i++)
{
DistroDefinition distro = FindBannerPoolDistroByStars(featured[i], 4);
if (distro != null) eligible.Add(distro);
}
return eligible.Count == 0 ? FindRandomBannerPoolDistroByStars(4) : eligible[_random.Next(eligible.Count)];
}
private static int GetDistroStars(DistroDefinition distro)
{
return DistroRarity.Stars(distro);
@@ -694,6 +855,35 @@ namespace KernelPanic.Meta
clone.guaranteedDistroIds.AddRange(state.guaranteedDistroIds);
return clone;
}
private static GachaPullHistoryEntry CloneHistoryEntry(GachaPullHistoryEntry source)
{
if (source == null || string.IsNullOrWhiteSpace(source.bannerId)) return null;
source.EnsureLists();
GachaPullHistoryEntry clone = new()
{
pulledUtc = source.pulledUtc,
bannerId = source.bannerId,
currencySpent = Math.Max(0, source.currencySpent),
entropySpent = Math.Max(0, source.entropySpent)
};
for (int i = 0; i < source.rewards.Count; i++)
{
GachaPullHistoryRewardEntry reward = source.rewards[i];
if (reward == null) continue;
clone.rewards.Add(new GachaPullHistoryRewardEntry
{
stars = Math.Max(3, reward.stars),
displayName = reward.displayName,
rewardType = reward.rewardType,
outcomeKind = reward.outcomeKind,
duplicateValue = Math.Max(0, reward.duplicateValue),
guaranteed = reward.guaranteed,
pityTriggered = reward.pityTriggered
});
}
return clone;
}
}
/// <summary>
+21 -1
View File
@@ -16,7 +16,7 @@ namespace KernelPanic.Meta
public sealed class SaveService
{
private const string SaveFileName = "kernel-panic-save.json";
public const int CurrentSchemaVersion = 10;
public const int CurrentSchemaVersion = 11;
private static readonly object FileLock = new();
public string SavePath { get; }
@@ -300,6 +300,8 @@ namespace KernelPanic.Meta
public List<string> bannerPoolIds = new();
public GachaBannerState beginnerBannerState = new(GachaService.BeginnerBannerId);
public GachaBannerState standardBannerState = new(GachaService.StandardBannerId);
public GachaBannerState limitedBannerState = new(GachaService.LimitedBannerId);
public List<GachaPullHistoryEntry> gachaPullHistory = new();
public LastRunLoadoutSaveEntry lastRunLoadout = new();
public List<RunBuildDraftSaveEntry> runBuildDrafts = new();
public string lastSetupDistroId;
@@ -344,6 +346,24 @@ namespace KernelPanic.Meta
standardBannerState ??= new GachaBannerState(GachaService.StandardBannerId);
standardBannerState.bannerId = GachaService.StandardBannerId;
standardBannerState.EnsureLists();
limitedBannerState ??= new GachaBannerState(GachaService.LimitedBannerId);
limitedBannerState.bannerId = GachaService.LimitedBannerId;
limitedBannerState.EnsureLists();
gachaPullHistory ??= new List<GachaPullHistoryEntry>();
for (int i = gachaPullHistory.Count - 1; i >= 0; i--)
{
GachaPullHistoryEntry entry = gachaPullHistory[i];
if (entry == null || string.IsNullOrWhiteSpace(entry.bannerId))
{
gachaPullHistory.RemoveAt(i);
continue;
}
entry.EnsureLists();
}
if (gachaPullHistory.Count > GachaService.MaxPullHistoryEntries)
gachaPullHistory.RemoveRange(GachaService.MaxPullHistoryEntries,
gachaPullHistory.Count - GachaService.MaxPullHistoryEntries);
lastRunLoadout ??= new LastRunLoadoutSaveEntry();
lastRunLoadout.EnsureLists();
runBuildDrafts ??= new List<RunBuildDraftSaveEntry>();