Refactor alot of stuff

This commit is contained in:
2026-10-29 22:54:29 +01:00
parent c23b666ee4
commit 260abc2c98
138 changed files with 2835 additions and 466 deletions
+22 -3
View File
@@ -1,17 +1,36 @@
using System;
using KernelPanic.Data;
using UnityEngine;
namespace KernelPanic.Meta
{
public static class PackageTuning
{
public const int MaxPackageLevel = 5;
// Serialization ceiling; each definition owns its actual upgrade cap.
public const int MaxPackageLevel = 8;
public const float RefundFraction = 1f;
public const float RarityCostMultiplier = 1f;
private static readonly int[] CachePerRarityValues = { 5, 12, 30, 80, 200 };
private static readonly int[] UpgradeCacheCostValues = { 10, 25, 50, 90, 150 };
private static readonly int[] UpgradeBandwidthCostValues = { 20, 50, 100, 180, 300 };
private static readonly int[] UpgradeCacheCostValues = { 10, 25, 50, 90, 150, 230, 330, 450 };
private static readonly int[] UpgradeBandwidthCostValues = { 20, 50, 100, 180, 300, 460, 660, 900 };
public static void ReconcileUpgradeCaps(SaveData save, PackageDatabase database)
{
if (save?.ownedPackages == null || database == null) return;
foreach (var entry in save.ownedPackages)
{
var definition = database.FindById(entry?.id);
if (definition == null || entry.upgradeLevel <= definition.MaxUpgradeLevel) continue;
int previous = entry.upgradeLevel;
int current = definition.MaxUpgradeLevel;
int cache = GetInvestedCache(previous, definition.Rarity) - GetInvestedCache(current, definition.Rarity);
int bandwidth = GetInvestedBandwidth(previous, definition.Rarity) - GetInvestedBandwidth(current, definition.Rarity);
save.cacheBalance = (int)Math.Min(int.MaxValue, (long)save.cacheBalance + cache);
save.bandwidthBalance = (int)Math.Min(int.MaxValue, (long)save.bandwidthBalance + bandwidth);
entry.upgradeLevel = current; // Same save transaction as the refund; safe to retry loading.
}
}
public static int GetCacheForRarity(int rarity)
{