261 lines
11 KiB
C#
261 lines
11 KiB
C#
using System;
|
|
using System.Collections.Generic;
|
|
using UnityEngine;
|
|
|
|
namespace KernelPanic.Data
|
|
{
|
|
public enum PackageSlot
|
|
{
|
|
// Keep serialized identities stable for existing assets and saves.
|
|
[InspectorName("System")] Kernel = 0,
|
|
[InspectorName("Tools")] Runtime = 1,
|
|
[InspectorName("Services")] Daemon = 2
|
|
}
|
|
|
|
public static class PackageSlotPresentation
|
|
{
|
|
public static string DisplayName(this PackageSlot slot) => slot switch
|
|
{
|
|
PackageSlot.Kernel => "System",
|
|
PackageSlot.Runtime => "Tools",
|
|
PackageSlot.Daemon => "Services",
|
|
_ => "Unknown"
|
|
};
|
|
}
|
|
|
|
public enum PackageEffectKind
|
|
{
|
|
None = 0,
|
|
MaxUptime = 1,
|
|
MaxCycles = 2,
|
|
WaveDraw = 3,
|
|
WaveGenerateBasicCard = 4,
|
|
FirstCardEachWaveCostReduction = 5,
|
|
EveryNthTurnShield = 6,
|
|
ExhaustShield = 7,
|
|
EveryNthCardEachWaveFree = 8,
|
|
FirstCardsEachTurnCostReduction = 9,
|
|
ThirdCardEachTurnGenerate = 10,
|
|
JavaScriptFlatDamage = 11,
|
|
WaveThresholdRestore = 12,
|
|
FirstShieldEachTurnBonus = 13,
|
|
DnfFedoraPassive = 14,
|
|
WaveStartShield = 15,
|
|
FirstTurnEachWaveShield = 16,
|
|
FirstTurnFirstWaveDraw = 17,
|
|
FirstTurnEachWaveCycle = 18,
|
|
MaxRam = 19,
|
|
FirstNativeCardEachWaveFlatDamage = 20,
|
|
FirstInterpreterQueueCardEachWaveShield = 21,
|
|
EveryNthTurnDraw = 22,
|
|
StartTurnNoDebuffShield = 23,
|
|
EveryNthCardEachWaveCycle = 24,
|
|
FirstCThisTurnDamageMultiplier = 25,
|
|
TurnStartGenerateLanguageCard = 26,
|
|
PortageWaveStartShield = 27,
|
|
// Amount is successful-play Shield; the first accepted card's discount is always 1.
|
|
FirstCardEachRoundDiscountAndShield = 28,
|
|
CompilationAdvancedPreviousRoundCycle = 29,
|
|
AfterFirstRoundShield = 30,
|
|
AfterFirstRoundCompilation = 31
|
|
}
|
|
|
|
[Serializable]
|
|
public struct PackageEffectData
|
|
{
|
|
[SerializeField] private PackageEffectKind kind;
|
|
[SerializeField] private int amount;
|
|
[SerializeField] private int threshold;
|
|
[SerializeField] private bool refundCycle;
|
|
[SerializeField] private bool cleanseDebuffs;
|
|
[SerializeField] private bool enableFedoraSecondCardPassive;
|
|
[SerializeField] private bool persistArchBtw;
|
|
|
|
public PackageEffectData(PackageEffectKind kind, int amount, int threshold, bool refundCycle, bool cleanseDebuffs, bool enableFedoraSecondCardPassive, bool persistArchBtw = false)
|
|
{
|
|
this.kind = kind;
|
|
this.amount = amount;
|
|
this.threshold = threshold;
|
|
this.refundCycle = refundCycle;
|
|
this.cleanseDebuffs = cleanseDebuffs;
|
|
this.enableFedoraSecondCardPassive = enableFedoraSecondCardPassive;
|
|
this.persistArchBtw = persistArchBtw;
|
|
}
|
|
|
|
public PackageEffectKind Kind => kind;
|
|
public int Amount => amount;
|
|
public int Threshold => threshold;
|
|
public bool RefundCycle => refundCycle;
|
|
public bool CleanseDebuffs => cleanseDebuffs;
|
|
public bool EnableFedoraSecondCardPassive => enableFedoraSecondCardPassive;
|
|
public bool PersistArchBtw => persistArchBtw;
|
|
}
|
|
|
|
/// <summary>
|
|
/// Defines persistent meta packages equipped into System/Tools/Services slots.
|
|
/// Package loadouts are meta progression and carry into every run for that distro.
|
|
/// Card loadouts remain run setup only.
|
|
/// </summary>
|
|
public sealed class PackageDefinition : ScriptableObject
|
|
{
|
|
[SerializeField] private string id;
|
|
[SerializeField] private string displayName;
|
|
[SerializeField] private PackageSlot slot;
|
|
[SerializeField] private int legacySlot = -1;
|
|
[SerializeField, Range(1, 5)] private int rarity = 1;
|
|
[SerializeField, Range(0, KernelPanic.Meta.PackageTuning.MaxPackageLevel)] private int maxUpgradeLevel = 5;
|
|
[SerializeField, TextArea] private string description;
|
|
[SerializeField] private string flavourText;
|
|
[SerializeField, TextArea] private string designNotes;
|
|
[SerializeField] private string intendedDistroId;
|
|
[SerializeField] private List<string> requiresSystem = new();
|
|
[SerializeField] private PackageEffectData offDistroEffect;
|
|
[SerializeField] private PackageEffectData onDistroEffect;
|
|
[SerializeField] private List<PackageEffectData> offDistroAdditionalEffects = new();
|
|
[SerializeField] private List<PackageEffectData> onDistroAdditionalEffects = new();
|
|
|
|
public string Id => id;
|
|
public string DisplayName => displayName;
|
|
public PackageSlot Slot => slot;
|
|
public bool AcceptsSavedSlot(PackageSlot savedSlot) => savedSlot == slot
|
|
|| (legacySlot >= 0 && (int)savedSlot == legacySlot);
|
|
public int Rarity => Mathf.Clamp(rarity, 1, 5);
|
|
public int MaxUpgradeLevel => Mathf.Clamp(maxUpgradeLevel, 0, KernelPanic.Meta.PackageTuning.MaxPackageLevel);
|
|
public string Description => description;
|
|
public string FlavourText => flavourText;
|
|
public string FlavorText => flavourText;
|
|
public string DesignNotes => designNotes;
|
|
public string IntendedDistroId => intendedDistroId;
|
|
public IReadOnlyList<string> RequiresSystem => requiresSystem;
|
|
public PackageEffectData OffDistroEffect => offDistroEffect;
|
|
public PackageEffectData OnDistroEffect => onDistroEffect;
|
|
|
|
public bool IsIntendedFor(string distroId)
|
|
{
|
|
return !string.IsNullOrWhiteSpace(intendedDistroId)
|
|
&& string.Equals(intendedDistroId, distroId, StringComparison.OrdinalIgnoreCase);
|
|
}
|
|
|
|
public PackageEffectData EffectFor(string distroId)
|
|
{
|
|
return IsIntendedFor(distroId) ? onDistroEffect : offDistroEffect;
|
|
}
|
|
|
|
// Keep the original serialized primary effects intact for existing assets/saves.
|
|
public IEnumerable<PackageEffectData> EffectsFor(string distroId)
|
|
{
|
|
yield return EffectFor(distroId);
|
|
var additional = IsIntendedFor(distroId) ? onDistroAdditionalEffects : offDistroAdditionalEffects;
|
|
if (additional == null) yield break;
|
|
foreach (var effect in additional) yield return effect;
|
|
}
|
|
}
|
|
|
|
[Serializable]
|
|
public sealed class PackageInstance
|
|
{
|
|
public PackageInstance(PackageDefinition definition, int upgradeLevel)
|
|
{
|
|
Definition = definition;
|
|
SavedSlot = definition == null ? default : definition.Slot;
|
|
UpgradeLevel = Mathf.Clamp(upgradeLevel, 0, definition == null ? 0 : definition.MaxUpgradeLevel);
|
|
}
|
|
|
|
public PackageDefinition Definition { get; }
|
|
// Preserve the original allocation when resuming pre-taxonomy runs.
|
|
public PackageSlot SavedSlot { get; set; }
|
|
public int UpgradeLevel { get; }
|
|
|
|
public IEnumerable<PackageEffectData> EffectsFor(string distroId)
|
|
{
|
|
if (Definition == null) yield break;
|
|
foreach (var effect in Definition.EffectsFor(distroId))
|
|
yield return PackageEffectScaling.Scale(effect, UpgradeLevel);
|
|
}
|
|
|
|
public PackageEffectData EffectFor(string distroId)
|
|
{
|
|
PackageEffectData effect = Definition == null ? default : Definition.EffectFor(distroId);
|
|
return PackageEffectScaling.Scale(effect, UpgradeLevel);
|
|
}
|
|
}
|
|
|
|
public static class PackageEffectScaling
|
|
{
|
|
public static PackageEffectData Scale(PackageEffectData effect, int upgradeLevel)
|
|
{
|
|
int level = Mathf.Clamp(upgradeLevel, 0, KernelPanic.Meta.PackageTuning.MaxPackageLevel);
|
|
if (level <= 0 || effect.Kind == PackageEffectKind.None)
|
|
{
|
|
return effect;
|
|
}
|
|
|
|
int amount = effect.Amount;
|
|
int threshold = effect.Threshold;
|
|
// Counts, trigger intervals, percentages and flags are different units.
|
|
// Explicit cases prevent new effects from accidentally inheriting +1 to everything.
|
|
switch (effect.Kind)
|
|
{
|
|
case PackageEffectKind.MaxUptime:
|
|
amount += Mathf.Clamp(Mathf.CeilToInt(effect.Amount * .5f), 1, 2) * level;
|
|
break;
|
|
case PackageEffectKind.PortageWaveStartShield:
|
|
amount += 2 * level;
|
|
break;
|
|
case PackageEffectKind.WaveStartShield:
|
|
case PackageEffectKind.FirstTurnEachWaveShield:
|
|
case PackageEffectKind.EveryNthTurnShield:
|
|
case PackageEffectKind.ExhaustShield:
|
|
case PackageEffectKind.FirstInterpreterQueueCardEachWaveShield:
|
|
case PackageEffectKind.FirstShieldEachTurnBonus:
|
|
case PackageEffectKind.StartTurnNoDebuffShield:
|
|
case PackageEffectKind.FirstCardEachRoundDiscountAndShield:
|
|
case PackageEffectKind.AfterFirstRoundShield:
|
|
case PackageEffectKind.FirstNativeCardEachWaveFlatDamage:
|
|
case PackageEffectKind.JavaScriptFlatDamage:
|
|
case PackageEffectKind.DnfFedoraPassive:
|
|
amount += level;
|
|
break;
|
|
case PackageEffectKind.MaxCycles:
|
|
case PackageEffectKind.FirstTurnEachWaveCycle:
|
|
case PackageEffectKind.EveryNthCardEachWaveCycle:
|
|
case PackageEffectKind.WaveDraw:
|
|
case PackageEffectKind.WaveGenerateBasicCard:
|
|
case PackageEffectKind.ThirdCardEachTurnGenerate:
|
|
case PackageEffectKind.FirstCardEachWaveCostReduction:
|
|
amount += Math.Min(level, 1);
|
|
break;
|
|
case PackageEffectKind.MaxRam:
|
|
case PackageEffectKind.FirstTurnFirstWaveDraw:
|
|
amount += Math.Min(level, 2);
|
|
break;
|
|
case PackageEffectKind.EveryNthTurnDraw:
|
|
threshold = Math.Max(2, threshold - 1);
|
|
amount += level >= 2 ? 1 : 0;
|
|
break;
|
|
case PackageEffectKind.FirstCardsEachTurnCostReduction:
|
|
// Extend the one-Cycle discount to one more card, never make it six Cycles.
|
|
threshold += Math.Min(level, 1);
|
|
break;
|
|
case PackageEffectKind.EveryNthCardEachWaveFree:
|
|
threshold = Math.Max(2, threshold - level);
|
|
break;
|
|
case PackageEffectKind.FirstCThisTurnDamageMultiplier:
|
|
amount += 10 * level;
|
|
break;
|
|
case PackageEffectKind.WaveThresholdRestore:
|
|
threshold = Math.Min(75, threshold + 5 * level);
|
|
break;
|
|
// AUR's amount is a mode flag. Compilation and its Cycle reward stay fixed.
|
|
case PackageEffectKind.TurnStartGenerateLanguageCard:
|
|
case PackageEffectKind.CompilationAdvancedPreviousRoundCycle:
|
|
case PackageEffectKind.AfterFirstRoundCompilation:
|
|
default:
|
|
break;
|
|
}
|
|
return new PackageEffectData(effect.Kind, amount, threshold, effect.RefundCycle, effect.CleanseDebuffs,
|
|
effect.EnableFedoraSecondCardPassive, effect.PersistArchBtw);
|
|
}
|
|
}
|
|
}
|