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
+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>