make some small changes to merging
This commit is contained in:
@@ -90,7 +90,7 @@ namespace KernelPanic.Meta
|
|||||||
owned.version = version;
|
owned.version = version;
|
||||||
bool overflow = version >= GachaTuning.MaxVersion;
|
bool overflow = version >= GachaTuning.MaxVersion;
|
||||||
int merges = CalculateDupeMerges(overflow, unit.Id, context.FocusUnitId);
|
int merges = CalculateDupeMerges(overflow, unit.Id, context.FocusUnitId);
|
||||||
context.SaveData.merges = Math.Max(0, context.SaveData.merges) + merges;
|
owned.merges = Math.Max(0, owned.merges) + merges;
|
||||||
if (GachaTuning.DupeConsolationBandwidth > 0)
|
if (GachaTuning.DupeConsolationBandwidth > 0)
|
||||||
{
|
{
|
||||||
context.SaveData.standardPullCurrency += GachaTuning.DupeConsolationBandwidth;
|
context.SaveData.standardPullCurrency += GachaTuning.DupeConsolationBandwidth;
|
||||||
|
|||||||
@@ -62,6 +62,8 @@ namespace KernelPanic.Meta
|
|||||||
public int rootCredits = GachaService.TestRootCreditsBalance;
|
public int rootCredits = GachaService.TestRootCreditsBalance;
|
||||||
public int standardPullCurrency;
|
public int standardPullCurrency;
|
||||||
public int limitedPullCurrency;
|
public int limitedPullCurrency;
|
||||||
|
// Legacy global balance kept only so older saves deserialize cleanly.
|
||||||
|
// New duplicate-pull merges live on OwnedUnitSaveEntry.merges.
|
||||||
public int merges;
|
public int merges;
|
||||||
public List<OwnedUnitSaveEntry> ownedUnits = new();
|
public List<OwnedUnitSaveEntry> ownedUnits = new();
|
||||||
public List<string> ownedUnitIds = new();
|
public List<string> ownedUnitIds = new();
|
||||||
@@ -87,6 +89,7 @@ namespace KernelPanic.Meta
|
|||||||
merges = Math.Max(0, merges);
|
merges = Math.Max(0, merges);
|
||||||
MigrateLegacyOwnedUnitIds();
|
MigrateLegacyOwnedUnitIds();
|
||||||
NormalizeOwnedUnits();
|
NormalizeOwnedUnits();
|
||||||
|
MigrateLegacyGlobalMerges();
|
||||||
}
|
}
|
||||||
|
|
||||||
public OwnedUnitSaveEntry FindOwnedUnit(string id)
|
public OwnedUnitSaveEntry FindOwnedUnit(string id)
|
||||||
@@ -169,6 +172,31 @@ namespace KernelPanic.Meta
|
|||||||
}
|
}
|
||||||
|
|
||||||
entry.version = Math.Max(1, Math.Min(GachaTuning.MaxVersion, entry.version));
|
entry.version = Math.Max(1, Math.Min(GachaTuning.MaxVersion, entry.version));
|
||||||
|
entry.merges = Math.Max(0, entry.merges);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void MigrateLegacyGlobalMerges()
|
||||||
|
{
|
||||||
|
if (merges <= 0 || ownedUnits.Count == 0)
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool hasSpecificMerges = false;
|
||||||
|
for (int i = 0; i < ownedUnits.Count; i++)
|
||||||
|
{
|
||||||
|
if (ownedUnits[i] != null && ownedUnits[i].merges > 0)
|
||||||
|
{
|
||||||
|
hasSpecificMerges = true;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!hasSpecificMerges)
|
||||||
|
{
|
||||||
|
ownedUnits[0].merges = Math.Max(0, ownedUnits[0].merges) + merges;
|
||||||
|
merges = 0;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -192,6 +220,7 @@ namespace KernelPanic.Meta
|
|||||||
{
|
{
|
||||||
public string id;
|
public string id;
|
||||||
public int version = 1;
|
public int version = 1;
|
||||||
|
public int merges;
|
||||||
}
|
}
|
||||||
|
|
||||||
[Serializable]
|
[Serializable]
|
||||||
|
|||||||
@@ -48,16 +48,17 @@ namespace KernelPanic.Meta
|
|||||||
|
|
||||||
int targetVersion = currentVersion + 1;
|
int targetVersion = currentVersion + 1;
|
||||||
int cost = GachaTuning.GetVersionUpgradeCost(targetVersion);
|
int cost = GachaTuning.GetVersionUpgradeCost(targetVersion);
|
||||||
if (state.merges < cost)
|
int merges = Math.Max(0, entry.merges);
|
||||||
|
if (merges < cost)
|
||||||
{
|
{
|
||||||
return VersionUpgradeResult.Failed(unitId, VersionUpgradeFailureReason.InsufficientMerges, currentVersion, targetVersion, cost);
|
return VersionUpgradeResult.Failed(unitId, VersionUpgradeFailureReason.InsufficientMerges, currentVersion, targetVersion, cost);
|
||||||
}
|
}
|
||||||
|
|
||||||
state.merges -= cost;
|
entry.merges = merges - cost;
|
||||||
entry.version = targetVersion;
|
entry.version = targetVersion;
|
||||||
collection?.SetVersionSilently(unitId, targetVersion);
|
collection?.SetVersionSilently(unitId, targetVersion);
|
||||||
|
|
||||||
VersionUpgradeResult result = VersionUpgradeResult.Upgraded(unitId, currentVersion, targetVersion, cost, state.merges);
|
VersionUpgradeResult result = VersionUpgradeResult.Upgraded(unitId, currentVersion, targetVersion, cost, entry.merges);
|
||||||
UnitUpgraded?.Invoke(result);
|
UnitUpgraded?.Invoke(result);
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -24,7 +24,7 @@ namespace KernelPanic.UI
|
|||||||
private LanguageDeckDatabase _languageDeckDatabase;
|
private LanguageDeckDatabase _languageDeckDatabase;
|
||||||
private CardDatabase _cardDatabase;
|
private CardDatabase _cardDatabase;
|
||||||
private PlayerCollection _playerCollection;
|
private PlayerCollection _playerCollection;
|
||||||
private Func<int> _getMergesBalance;
|
private Func<DistroDefinition, int> _getMergesBalance;
|
||||||
private Func<DistroDefinition, VersionUpgradeResult> _tryUpgradeUnit;
|
private Func<DistroDefinition, VersionUpgradeResult> _tryUpgradeUnit;
|
||||||
private IReadOnlyList<DistroDefinition> _units = Array.Empty<DistroDefinition>();
|
private IReadOnlyList<DistroDefinition> _units = Array.Empty<DistroDefinition>();
|
||||||
private IReadOnlyList<LanguageCatalogEntry> _languages = LanguageCatalog.All;
|
private IReadOnlyList<LanguageCatalogEntry> _languages = LanguageCatalog.All;
|
||||||
@@ -38,7 +38,7 @@ namespace KernelPanic.UI
|
|||||||
|
|
||||||
public event Action ViewChanged;
|
public event Action ViewChanged;
|
||||||
|
|
||||||
public void Bind(VisualElement root, FontAsset artFont, LanguageDeckDatabase deckDatabase, CardDatabase cardsDatabase, PlayerCollection collection, Func<int> getMergesBalance = null, Func<DistroDefinition, VersionUpgradeResult> tryUpgradeUnit = null)
|
public void Bind(VisualElement root, FontAsset artFont, LanguageDeckDatabase deckDatabase, CardDatabase cardsDatabase, PlayerCollection collection, Func<DistroDefinition, int> getMergesBalance = null, Func<DistroDefinition, VersionUpgradeResult> tryUpgradeUnit = null)
|
||||||
{
|
{
|
||||||
_monospaceFont = artFont;
|
_monospaceFont = artFont;
|
||||||
_languageDeckDatabase = deckDatabase;
|
_languageDeckDatabase = deckDatabase;
|
||||||
@@ -296,7 +296,7 @@ namespace KernelPanic.UI
|
|||||||
{
|
{
|
||||||
int version = _playerCollection == null ? 1 : Mathf.Clamp(_playerCollection.GetVersion(unit.Id), 1, GachaTuning.MaxVersion);
|
int version = _playerCollection == null ? 1 : Mathf.Clamp(_playerCollection.GetVersion(unit.Id), 1, GachaTuning.MaxVersion);
|
||||||
string release = DistroVersionCatalog.GetReleaseLabel(unit.Id, version);
|
string release = DistroVersionCatalog.GetReleaseLabel(unit.Id, version);
|
||||||
int merges = _getMergesBalance?.Invoke() ?? 0;
|
int merges = _getMergesBalance?.Invoke(unit) ?? 0;
|
||||||
|
|
||||||
VisualElement panel = new();
|
VisualElement panel = new();
|
||||||
panel.AddToClassList("version-upgrade-panel");
|
panel.AddToClassList("version-upgrade-panel");
|
||||||
@@ -308,7 +308,7 @@ namespace KernelPanic.UI
|
|||||||
current.AddToClassList("version-upgrade-current");
|
current.AddToClassList("version-upgrade-current");
|
||||||
summary.Add(current);
|
summary.Add(current);
|
||||||
|
|
||||||
Label wallet = new(version < GachaTuning.MaxVersion ? $"merges {merges} / {GachaTuning.GetVersionUpgradeCost(version + 1)}" : $"merges {merges}");
|
Label wallet = new(version < GachaTuning.MaxVersion ? $"{unit.DisplayName} merges {merges} / {GachaTuning.GetVersionUpgradeCost(version + 1)}" : $"{unit.DisplayName} merges {merges}");
|
||||||
wallet.AddToClassList("version-upgrade-wallet");
|
wallet.AddToClassList("version-upgrade-wallet");
|
||||||
summary.Add(wallet);
|
summary.Add(wallet);
|
||||||
panel.Add(summary);
|
panel.Add(summary);
|
||||||
|
|||||||
@@ -297,8 +297,8 @@ namespace KernelPanic.UI
|
|||||||
return value.Kind switch
|
return value.Kind switch
|
||||||
{
|
{
|
||||||
PullOutcomeKind.Granted => " granted",
|
PullOutcomeKind.Granted => " granted",
|
||||||
PullOutcomeKind.Dupe => $" duplicate +{value.MergesAwarded} merges",
|
PullOutcomeKind.Dupe => $" duplicate +{value.MergesAwarded} {value.UnitId} merges",
|
||||||
PullOutcomeKind.DupeOverflow => $" max-version duplicate +{value.MergesAwarded} merges",
|
PullOutcomeKind.DupeOverflow => $" max-version duplicate +{value.MergesAwarded} {value.UnitId} merges",
|
||||||
_ => string.Empty
|
_ => string.Empty
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -650,6 +650,16 @@ namespace KernelPanic.UI
|
|||||||
{
|
{
|
||||||
_saveData ??= SaveData.CreateDefault();
|
_saveData ??= SaveData.CreateDefault();
|
||||||
_saveData.EnsureLists();
|
_saveData.EnsureLists();
|
||||||
|
Dictionary<string, int> mergeBalances = new(StringComparer.OrdinalIgnoreCase);
|
||||||
|
for (int i = 0; i < _saveData.ownedUnits.Count; i++)
|
||||||
|
{
|
||||||
|
OwnedUnitSaveEntry entry = _saveData.ownedUnits[i];
|
||||||
|
if (entry != null && !string.IsNullOrWhiteSpace(entry.id))
|
||||||
|
{
|
||||||
|
mergeBalances[entry.id] = Mathf.Max(0, entry.merges);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
_saveData.entropyBalance = _wallet == null ? 0 : _wallet.Balance;
|
_saveData.entropyBalance = _wallet == null ? 0 : _wallet.Balance;
|
||||||
_saveData.ownedUnits.Clear();
|
_saveData.ownedUnits.Clear();
|
||||||
_saveData.ownedUnitIds.Clear();
|
_saveData.ownedUnitIds.Clear();
|
||||||
@@ -664,7 +674,8 @@ namespace KernelPanic.UI
|
|||||||
_saveData.ownedUnits.Add(new OwnedUnitSaveEntry
|
_saveData.ownedUnits.Add(new OwnedUnitSaveEntry
|
||||||
{
|
{
|
||||||
id = unit.Id,
|
id = unit.Id,
|
||||||
version = Mathf.Clamp(_playerCollection.GetVersion(unit.Id), 1, GachaTuning.MaxVersion)
|
version = Mathf.Clamp(_playerCollection.GetVersion(unit.Id), 1, GachaTuning.MaxVersion),
|
||||||
|
merges = mergeBalances.TryGetValue(unit.Id, out int merges) ? merges : 0
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -687,11 +698,12 @@ namespace KernelPanic.UI
|
|||||||
return PullResolver.Resolve(pulledDistros, context);
|
return PullResolver.Resolve(pulledDistros, context);
|
||||||
}
|
}
|
||||||
|
|
||||||
private int GetMergesBalance()
|
private int GetMergesBalance(DistroDefinition unit)
|
||||||
{
|
{
|
||||||
_saveData ??= SaveData.CreateDefault();
|
_saveData ??= SaveData.CreateDefault();
|
||||||
_saveData.EnsureLists();
|
_saveData.EnsureLists();
|
||||||
return _saveData.merges;
|
OwnedUnitSaveEntry entry = unit == null ? null : _saveData.FindOwnedUnit(unit.Id);
|
||||||
|
return Math.Max(0, entry?.merges ?? 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
private VersionUpgradeResult UpgradeCollectionUnit(DistroDefinition unit)
|
private VersionUpgradeResult UpgradeCollectionUnit(DistroDefinition unit)
|
||||||
@@ -757,11 +769,24 @@ namespace KernelPanic.UI
|
|||||||
_rootCreditsToEntropyButton?.SetEnabled(true);
|
_rootCreditsToEntropyButton?.SetEnabled(true);
|
||||||
bool showPullTokens = IsGachaVisible();
|
bool showPullTokens = IsGachaVisible();
|
||||||
_pullTokensLabel.text = showPullTokens
|
_pullTokensLabel.text = showPullTokens
|
||||||
? $"bandwidth={_gachaService.PullTokens} compute-credits={_gachaService.LimitedPullTokens} merges={_saveData.merges}"
|
? $"bandwidth={_gachaService.PullTokens} compute-credits={_gachaService.LimitedPullTokens} distro-merges={GetTotalDistroMerges()}"
|
||||||
: string.Empty;
|
: string.Empty;
|
||||||
_pullTokensLabel.EnableInClassList(HiddenClassName, !showPullTokens);
|
_pullTokensLabel.EnableInClassList(HiddenClassName, !showPullTokens);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private int GetTotalDistroMerges()
|
||||||
|
{
|
||||||
|
_saveData ??= SaveData.CreateDefault();
|
||||||
|
_saveData.EnsureLists();
|
||||||
|
int total = 0;
|
||||||
|
for (int i = 0; i < _saveData.ownedUnits.Count; i++)
|
||||||
|
{
|
||||||
|
total += Mathf.Max(0, _saveData.ownedUnits[i]?.merges ?? 0);
|
||||||
|
}
|
||||||
|
|
||||||
|
return total;
|
||||||
|
}
|
||||||
|
|
||||||
private void RefreshEventBanner()
|
private void RefreshEventBanner()
|
||||||
{
|
{
|
||||||
EventBannerContent banner = _eventBannerSource?.GetBanner();
|
EventBannerContent banner = _eventBannerSource?.GetBanner();
|
||||||
|
|||||||
Reference in New Issue
Block a user