make some small changes to merging
This commit is contained in:
@@ -90,7 +90,7 @@ namespace KernelPanic.Meta
|
||||
owned.version = version;
|
||||
bool overflow = version >= GachaTuning.MaxVersion;
|
||||
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)
|
||||
{
|
||||
context.SaveData.standardPullCurrency += GachaTuning.DupeConsolationBandwidth;
|
||||
|
||||
@@ -62,6 +62,8 @@ namespace KernelPanic.Meta
|
||||
public int rootCredits = GachaService.TestRootCreditsBalance;
|
||||
public int standardPullCurrency;
|
||||
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 List<OwnedUnitSaveEntry> ownedUnits = new();
|
||||
public List<string> ownedUnitIds = new();
|
||||
@@ -87,6 +89,7 @@ namespace KernelPanic.Meta
|
||||
merges = Math.Max(0, merges);
|
||||
MigrateLegacyOwnedUnitIds();
|
||||
NormalizeOwnedUnits();
|
||||
MigrateLegacyGlobalMerges();
|
||||
}
|
||||
|
||||
public OwnedUnitSaveEntry FindOwnedUnit(string id)
|
||||
@@ -169,6 +172,31 @@ namespace KernelPanic.Meta
|
||||
}
|
||||
|
||||
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 int version = 1;
|
||||
public int merges;
|
||||
}
|
||||
|
||||
[Serializable]
|
||||
|
||||
@@ -48,16 +48,17 @@ namespace KernelPanic.Meta
|
||||
|
||||
int targetVersion = currentVersion + 1;
|
||||
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);
|
||||
}
|
||||
|
||||
state.merges -= cost;
|
||||
entry.merges = merges - cost;
|
||||
entry.version = 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);
|
||||
return result;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user