using System.Collections.Generic; using System.Linq; using KernelPanic.Core; using KernelPanic.Data; namespace KernelPanic.Combat { public sealed class DealDamageEffect : ICardEffect { private readonly int _minAmount; private readonly int _maxAmount; private readonly Language _language; private readonly bool _trueDamage; private readonly bool _canCrit; private readonly bool _allEnemies; public DealDamageEffect(int minAmount, int maxAmount, Language language, bool trueDamage = false, bool canCrit = true, bool allEnemies = false) { _minAmount = minAmount; _maxAmount = maxAmount; _language = language; _trueDamage = trueDamage; _canCrit = canCrit; _allEnemies = allEnemies; } public void Execute(CombatContext context) { CardDamageExecutor.Execute(context, () => RollDamageAmount(context), _language, _trueDamage, _canCrit, _allEnemies); } private int RollDamageAmount(CombatContext context) { int minAmount = CardDamageExecutor.ScaleAmount(_minAmount, context); int maxAmount = CardDamageExecutor.ScaleAmount(_maxAmount, context); int amount = minAmount == maxAmount ? minAmount : RandomRoll.RollRange(minAmount, maxAmount, new RollContext(context.Source)); return amount; } } public sealed class ShieldEffect : ICardEffect { private readonly int _amount; public ShieldEffect(int amount) { _amount = amount; } public void Execute(CombatContext context) { CardShieldExecutor.Execute(context, CardShieldExecutor.ScaleAmount(_amount, context)); } } public sealed class FirstCardShieldEffect : ICardEffect { private readonly int _baseAmount; private readonly int _firstCardBonus; public FirstCardShieldEffect(int baseAmount, int firstCardBonus) { _baseAmount = baseAmount; _firstCardBonus = firstCardBonus; } public void Execute(CombatContext context) { int amount = _baseAmount + (context.Card != null && context.Card.WasFirstCardThisTurn ? _firstCardBonus : 0); CardShieldExecutor.Execute(context, CardShieldExecutor.ScaleAmount(amount, context)); } } public sealed class ChanceDamageEffect : ICardEffect { private readonly int _damageAmount; private readonly int _successPercent; private readonly Language _language; public ChanceDamageEffect(int damageAmount, int successPercent, Language language) { _damageAmount = damageAmount; _successPercent = successPercent; _language = language; } public void Execute(CombatContext context) { CardDamageExecutor.Execute(context, () => { int roll = context.Source != null && context.Source.ForceMaxRolls ? 1 : RandomRoll.RollRange(1, 100, RollContext.None); // A miss still enters the pipeline with zero base damage, preserving language flat bonuses. return roll <= _successPercent ? CardDamageExecutor.ScaleAmount(_damageAmount, context) : 0; }, _language, reportHit: amount => context.CombatManager.ReportEffectResult(amount == 0 ? "typeof -> NaN (0)" : $"typeof -> {amount}")); } } public sealed class QueuedGrowthDamageEffect : ICardEffect { private readonly int _baseAmount; private readonly Language _language; public QueuedGrowthDamageEffect(int baseAmount, Language language) { _baseAmount = baseAmount; _language = language; } public void Execute(CombatContext context) { int queueGrowth = UnityEngine.Mathf.Max(0, (context.Card?.QueuePlayCount ?? 1) - 1); int amount = _baseAmount + queueGrowth; new DealDamageEffect(amount, amount, _language).Execute(context); } } public sealed class PreviousLanguageDamageEffect : ICardEffect { private readonly int _baseAmount; private readonly int _matchingAmount; private readonly Language _language; public PreviousLanguageDamageEffect(int baseAmount, int matchingAmount, Language language) { _baseAmount = baseAmount; _matchingAmount = matchingAmount; _language = language; } public void Execute(CombatContext context) { bool matches = context.Source != null && context.Source.HasPreviousPlayedCardLanguage && context.Source.PreviousPlayedCardLanguage == _language; int amount = matches ? _matchingAmount : _baseAmount; new DealDamageEffect(amount, amount, _language).Execute(context); } } public sealed class BtwScaledDamageEffect : ICardEffect { private readonly int _baseAmount; private readonly int _perBtw; private readonly Language _language; public BtwScaledDamageEffect(int baseAmount, int perBtw, Language language) { _baseAmount = baseAmount; _perBtw = perBtw; _language = language; } public void Execute(CombatContext context) { int btw = UnityEngine.Mathf.Max(0, context.Source?.ArchBtwStacks ?? 0); int perBtw = UnityEngine.Mathf.Max(_perBtw, context.Source?.ArchMakepkgBtwMultiplier ?? _perBtw); int amount = _baseAmount + (btw * perBtw); new DealDamageEffect(amount, amount, _language).Execute(context); } } public sealed class RandomCommonLanguageCardEffect : ICardEffect { public void Execute(CombatContext context) { Language language = RandomRoll.RollRange(0, 1, new RollContext(context.Source)) == 0 ? Language.C : Language.Rust; if (!context.CombatManager.TryCreateGeneratedCard(language, Rarity.Common, out CardInstance generated)) { context.CombatManager.ReportEffectResult("TODO card-generation: no C/Rust common available"); return; } generated.TemporaryCostDelta -= CombatManager.GetCardCost(generated); if (context.HandController.Add(generated)) { context.CombatManager.ReportEffectResult($"AUR helper: generated {GetCardName(generated)} at 0c"); } else { context.CombatManager.ReportEffectResult("AUR helper: hand full"); } } private static string GetCardName(CardInstance card) { return card?.Definition == null || string.IsNullOrWhiteSpace(card.Definition.DisplayName) ? card?.Definition?.Id ?? "--" : card.Definition.DisplayName; } } public sealed class MinimalInstallEffect : ICardEffect { internal const int MaxExhaust = 2; internal const int ShieldPerCard = 3; internal const int CyclesPerCard = 1; public void Execute(CombatContext context) { int exhausted = 0; List candidates = context.HandController.Cards.Where(card => card != null).Take(MaxExhaust).ToList(); for (int i = 0; i < candidates.Count; i++) { CardInstance card = candidates[i]; if (!context.HandController.Remove(card)) { continue; } context.DeckController.Exhaust(card); context.CombatManager.HandleCardExhausted(card); exhausted++; } if (exhausted <= 0) { context.CombatManager.ReportEffectResult("minimal install: no hand cards to exhaust"); return; } int shield = exhausted * ShieldPerCard; // Fixed per-card rewards omit flat and magnitude bonuses, but retain explicit Shield multipliers. CardShieldExecutor.Execute(context, shield, "minimal install"); context.Source.Cycles += exhausted * CyclesPerCard; context.CombatManager.ReportEffectResult($"minimal install: exhausted {exhausted}, +{exhausted * CyclesPerCard} Cycle"); } } public sealed class SizeofDamageEffect : ICardEffect { internal const int DamagePerCard = 5; public void Execute(CombatContext context) { int cCards = context.HandController.Cards.Count(card => card?.Definition != null && card.Definition.Language == Language.C); int amount = DamagePerCard * cCards; new DealDamageEffect(amount, amount, Language.C).Execute(context); } } public sealed class ConsultWikiEffect : ICardEffect { internal const int FallbackDamage = 6; internal const int DrawCount = 1; public void Execute(CombatContext context) { CardInstance broken = context.HandController.Cards.FirstOrDefault(card => card != null && card.IsBroken); if (broken != null) { broken.IsBroken = false; context.CombatManager.DrawCards(DrawCount, "consult the wiki"); context.CombatManager.ReportEffectResult("fixed a broken card"); return; } new DealDamageEffect(FallbackDamage, FallbackDamage, Language.Rust).Execute(context); } } /// Repairs a bounded number of corrupted cards without drawing or moving them. public sealed class RepairCorruptedCardsEffect : ICardEffect { private readonly int _count; public RepairCorruptedCardsEffect(int count) { _count = count; } public void Execute(CombatContext context) { // Repair capacity benefits from card upgrades, not damage/Shield or Compilation modifiers. int count = UpgradeMath.ScaleAmount(_count, context.Card); context.CombatManager.RepairCorruptedCards(count); } } public sealed class ApplyStatusEffect : ICardEffect { private readonly StatusType _statusType; private readonly int _stacks; private readonly int _duration; private readonly bool _targetSelf; private readonly bool _skipNextTick; public ApplyStatusEffect(StatusType statusType, int stacks, int duration, bool targetSelf, bool skipNextTick = false) { _statusType = statusType; _stacks = stacks; _duration = duration; _targetSelf = targetSelf; _skipNextTick = skipNextTick; } public void Execute(CombatContext context) { if (_targetSelf) { if (StatusEffectController.GetDescriptor(_statusType).IsBeneficial && !context.CombatManager.CanPlayerReceiveCardBuff(context.Card)) { context.CombatManager.ReportEffectResult($"{_statusType} blocked"); return; } context.StatusEffects.Apply(context.Source, _statusType, UpgradeMath.ScaleAmount(UpgradeMath.ApplySourceFlatBonus(_stacks, context), context.Card), _duration, context.Source, _skipNextTick); return; } for (int i = 0; i < context.Targets.Count; i++) { context.StatusEffects.Apply(context.Targets[i], _statusType, UpgradeMath.ScaleAmount(UpgradeMath.ApplySourceFlatBonus(_stacks, context), context.Card), _duration, context.Source, _skipNextTick); } } } public sealed class CleanseEffect : ICardEffect { private readonly bool _harmfulOnly; public CleanseEffect(bool harmfulOnly) { _harmfulOnly = harmfulOnly; } public void Execute(CombatContext context) { if (_harmfulOnly) { context.StatusEffects.CleanseHarmful(context.Source); } else { context.StatusEffects.Cleanse(context.Source, _ => true); } } } public sealed class DrawEffect : ICardEffect { private readonly int _count; public DrawEffect(int count) { _count = count; } public void Execute(CombatContext context) { int room = context.HandController.RemainingRam; if (room <= 0) { context.CombatManager.ReportEffectResult("hand full: drew 0"); return; } int requested = UpgradeMath.ScaleAmount(UpgradeMath.ApplySourceFlatBonus(_count, context), context.Card); int added = 0; // Stop at the first card that cannot fit; do not skip it or rearrange the draw pile. while (added < requested && context.DeckController.TryDrawToHand(context.HandController, out _)) { added++; } string capped = added < requested && context.DeckController.AvailableToDrawCount > 0 ? " (not enough RAM)" : string.Empty; context.CombatManager.ReportEffectResult($"drew {added}{capped}"); } } public sealed class AskUbuntuEffect : ICardEffect { internal const int BaseDrawCount = 2; internal const int VersionBonusDrawCount = 3; public void Execute(CombatContext context) { var config = context.CombatManager.RunConfig; bool versionBonus = string.Equals(config?.Distro?.Id, "ubuntu", System.StringComparison.OrdinalIgnoreCase) && config.DistroVersion >= 3; new DrawEffect(versionBonus ? VersionBonusDrawCount : BaseDrawCount).Execute(context); } } public sealed class NextTurnCycleEffect : ICardEffect { private readonly int _amount; public NextTurnCycleEffect(int amount) { _amount = amount; } public void Execute(CombatContext context) { int amount = UpgradeMath.ScaleAmount(_amount, context.Card); context.CombatManager.AddNextTurnCycleBonus(amount); context.CombatManager.ReportEffectResult($"next turn +{amount} cycle"); } } public sealed class QueueRepeatEffect : ICardEffect { private readonly int _count; public QueueRepeatEffect(int count) { _count = count; } public void Execute(CombatContext context) { context.CombatManager.AddQueuedRepeatCharges(UpgradeMath.ScaleAmount(_count, context.Card)); } } public sealed class CopyLowestCostHandCardEffect : ICardEffect { public void Execute(CombatContext context) { if (context.HandController.RemainingRam <= 0) { context.CombatManager.ReportEffectResult("hand full: copied 0"); return; } CardInstance selected = null; int selectedCost = int.MaxValue; for (int i = 0; i < context.HandController.Cards.Count; i++) { CardInstance candidate = context.HandController.Cards[i]; if (candidate == null || candidate.Definition == null) { continue; } int cost = context.CombatManager.GetEffectiveCardCost(candidate); if (cost < selectedCost) { selected = candidate; selectedCost = cost; } } if (selected == null) { context.CombatManager.ReportEffectResult("no card to copy"); return; } CardInstance copy = selected.CopyForCombat(); if (!context.HandController.CanAdd(copy)) { context.CombatManager.ReportEffectResult("not enough RAM to copy"); return; } if (context.HandController.Add(copy)) { string name = string.IsNullOrWhiteSpace(copy.Definition.DisplayName) ? copy.Definition.Id : copy.Definition.DisplayName; context.CombatManager.ReportEffectResult($"copied {name}"); } } } public sealed class UpgradeHandCardsEffect : ICardEffect { private readonly int _minCount; private readonly int _maxCount; public UpgradeHandCardsEffect(int minCount, int maxCount) { _minCount = minCount; _maxCount = maxCount; } public void Execute(CombatContext context) { int minCount = UpgradeMath.ScaleAmount(UpgradeMath.ApplySourceFlatBonus(_minCount, context), context.Card); int maxCount = UpgradeMath.ScaleAmount(UpgradeMath.ApplySourceFlatBonus(_maxCount, context), context.Card); int targetCount = minCount == maxCount ? minCount : RandomRoll.RollRange(minCount, maxCount, new RollContext(context.Source)); List candidates = context.HandController.Cards .Where(card => card != null && card.CanUpgrade) .ToList(); int upgraded = 0; while (upgraded < targetCount && candidates.Count > 0) { int index = RandomRoll.RollRange(0, candidates.Count - 1, new RollContext(context.Source)); CardInstance card = candidates[index]; candidates.RemoveAt(index); if (card.Upgrade()) { upgraded++; } } context.CombatManager.ReportEffectResult(upgraded == 0 ? "no cards upgraded" : $"upgraded {upgraded} card(s)"); } } public sealed class ShuffleTokenIntoDrawPileEffect : ICardEffect { private readonly string _tokenId; public ShuffleTokenIntoDrawPileEffect(string tokenId) { _tokenId = tokenId; } public void Execute(CombatContext context) { if (context.CombatManager.TryCreateGeneratedCardById(_tokenId, out CardInstance token)) { context.DeckController.AddToDrawPile(token, shuffle: true); context.CombatManager.ReportEffectResult($"shuffled {GetCardName(token)} into draw pile"); } else { context.CombatManager.ReportEffectResult($"token {_tokenId} unavailable"); } } private static string GetCardName(CardInstance card) { return string.IsNullOrWhiteSpace(card?.Definition?.DisplayName) ? card?.Definition?.Id ?? "--" : card.Definition.DisplayName; } } public sealed class GenerateCardEffect : ICardEffect { private readonly Language _language; private readonly Rarity _rarity; public GenerateCardEffect(Language language, Rarity rarity) { _language = language; _rarity = rarity; } public void Execute(CombatContext context) { if (context.HandController.RemainingRam <= 0) { context.CombatManager.ReportEffectResult("hand full: generated 0"); return; } if (!context.CombatManager.TryCreateGeneratedCard(_language, _rarity, out CardInstance generatedCard)) { context.CombatManager.ReportEffectResult($"no {_rarity.ToString().ToLowerInvariant()} {_language} card pool"); return; } if (!context.HandController.CanAdd(generatedCard)) { context.CombatManager.ReportEffectResult("not enough RAM: generated 0"); } else if (context.HandController.Add(generatedCard)) { context.CombatManager.ReportEffectResult($"generated {GetCardName(generatedCard)} at 0c"); } else { context.CombatManager.ReportEffectResult("hand full: generated 0"); } } private static string GetCardName(CardInstance card) { if (card?.Definition == null) { return "--"; } return string.IsNullOrWhiteSpace(card.Definition.DisplayName) ? card.Definition.Id : card.Definition.DisplayName; } } public sealed class OverkillToShieldDamageEffect : ICardEffect { private readonly int _amount; private readonly Language _language; public OverkillToShieldDamageEffect(int amount, Language language) { _amount = amount; _language = language; } public void Execute(CombatContext context) { CardDamageExecutor.Execute(context, () => CardDamageExecutor.ScaleAmount(_amount, context), _language, overkillToShield: true); } } public sealed class ConditionalShieldRepeatDamageEffect : ICardEffect { private readonly int _amount; private readonly Language _language; public ConditionalShieldRepeatDamageEffect(int amount, Language language) { _amount = amount; _language = language; } public void Execute(CombatContext context) { int repeats = context.Source.Shield > 0 ? 2 : 1; for (int repeat = 0; repeat < repeats; repeat++) { new DealDamageEffect(_amount, _amount, _language).Execute(context); } } } public sealed class FirstToPackageEffect : ICardEffect { private readonly int _amount; public FirstToPackageEffect(int amount) { _amount = amount; } public void Execute(CombatContext context) { new DealDamageEffect(_amount, _amount, Language.Java).Execute(context); context.CombatManager.AddJavaCostDiscountThisTurn(1); } } public sealed class DnfAutoremoveEffect : ICardEffect { private readonly int _damageAmount; private readonly int _cycleGain; public DnfAutoremoveEffect(int damageAmount, int cycleGain) { _damageAmount = damageAmount; _cycleGain = cycleGain; } public void Execute(CombatContext context) { CardInstance junk = FindJunkCard(context); if (junk == null) { context.CombatManager.ReportEffectResult("dnf autoremove: no orphaned package"); return; } new DealDamageEffect(_damageAmount, _damageAmount, Language.Rust).Execute(context); if (context.HandController.Remove(junk)) { context.DeckController.Exhaust(junk); context.CombatManager.HandleCardExhausted(junk); int cycleGain = UpgradeMath.ScaleAmount(_cycleGain, context.Card); context.Source.Cycles += cycleGain; context.CombatManager.ReportEffectResult($"autoremove exhausted {GetCardName(junk)}: +{cycleGain} cycle"); } } private static CardInstance FindJunkCard(CombatContext context) { return CardEligibility.FindAutoremoveTarget(context.HandController?.Cards, context.Card); } private static string GetCardName(CardInstance card) { return string.IsNullOrWhiteSpace(card?.Definition?.DisplayName) ? card?.Definition?.Id ?? "--" : card.Definition.DisplayName; } } public sealed class UpdateManagerEffect : ICardEffect { private readonly int _amount; public UpdateManagerEffect(int amount) { _amount = amount; } public void Execute(CombatContext context) { // Capture flat and magnitude bonuses once, before either hit or its callbacks can mutate state. // The repeat uses this amount with future combat modifiers and defenses, and no Lazy multiplier. int amount = CardDamageExecutor.ScaleAmount(_amount, context); CardDamageExecutor.Execute(context, () => amount, Language.Python, allEnemies: true); context.CombatManager.ScheduleUpdateManagerRepeat(amount); } } public sealed class TimeshiftSnapshotEffect : ICardEffect { public void Execute(CombatContext context) { context.CombatManager.ScheduleTimeshiftRestore(context.Source.CurrentUptime); } } public sealed class RawhideEffect : ICardEffect { internal const int DrawCount = 2; public void Execute(CombatContext context) { new DrawEffect(DrawCount).Execute(context); context.CombatManager.GrantRawhideBonus(1); context.CombatManager.ReportEffectResult("rawhide armed next card"); } } public sealed class IncomingAttackHalveEffect : ICardEffect { private readonly int _charges; public IncomingAttackHalveEffect(int charges) { _charges = charges; } public void Execute(CombatContext context) { context.CombatManager.AddIncomingAttackHalfCharges(UpgradeMath.ScaleAmount(_charges, context.Card)); } } public sealed class NoOpCardEffect : ICardEffect { private readonly string _message; public NoOpCardEffect(string message) { _message = message; } public void Execute(CombatContext context) { context.CombatManager.LogEffectTodo(context.Card, _message); } } internal static class SegfaultRecoil { private const int DefaultPercent = 25; private const int DefaultUptimeDamage = 3; public static void TryApply(CombatContext context, Language damageLanguage, bool dealtDamage) { if (!dealtDamage || context == null || context.SegfaultRecoilRolled || context.Source == null || context.Source.IsDefeated || context.Card?.Definition?.Language != Language.C || damageLanguage != Language.C) { return; } context.SegfaultRecoilRolled = true; GetProfile(context.Card, out int percent, out int uptimeDamage, out bool drawOnSegfault); if (RandomRoll.RollRange(1, 100, new RollContext(context.Source)) > percent) { return; } DamageResult result = context.DamagePipeline.DealDamage(new DamageRequest(null, context.Source, uptimeDamage, Language.C, true, false) .WithCause($"{context.Card.Definition.DisplayName}: C segfault recoil")); context.CombatManager.ReportEffectResult($"segfault: uptime -{result.FinalAmount}"); context.CombatManager.TryCorruptRandomHandCard("segfault"); if (drawOnSegfault) { context.CombatManager.DrawCards(2, "free() recoil"); } } private static void GetProfile(CardInstance card, out int percent, out int uptimeDamage, out bool drawOnSegfault) { percent = DefaultPercent; uptimeDamage = DefaultUptimeDamage; drawOnSegfault = false; switch (card?.Definition?.Id) { case "shop_c_free": drawOnSegfault = true; break; case "shop_c_kernel_exploit": percent = 50; uptimeDamage = 8; break; } } } public static class CardEffectFactory { public static IReadOnlyList CreateEffects(CardDefinition definition) { if (HasSerializedEffects(definition)) { return CreateSerializedEffects(definition); } return CardCatalog.TryGet(definition?.Id, out CardCatalogEntry entry) ? entry.CreateEffects() : new ICardEffect[] { new NoOpCardEffect("card effect is not authored") }; } public static bool RequiresSingleTarget(CardDefinition definition) { return GetTargeting(definition) == CardTargeting.SingleEnemy; } public static bool CanReceiveBleedingEdgeDamageBonus(CardDefinition definition) { return definition != null && definition.ResolutionTrack == ResolutionTrack.Native && CardCatalog.TryGet(definition.Id, out CardCatalogEntry entry) && entry.BleedingEdgeEligible; } public static bool TargetsAllEnemies(CardDefinition definition) { return GetTargeting(definition) == CardTargeting.AllEnemies; } private static bool HasSerializedEffects(CardDefinition definition) { return definition?.Effects != null && definition.Effects.Any(effect => effect != null); } private static CardTargeting GetTargeting(CardDefinition definition) { if (!HasSerializedEffects(definition)) { return CardCatalog.TryGet(definition?.Id, out CardCatalogEntry entry) ? entry.Targeting : CardTargeting.None; } CardTargeting targeting = CardTargeting.None; foreach (CardEffectDefinition effect in definition.Effects) { if (effect == null) continue; // Preserve the player's selection for mixed cards. All-enemy effects resolve // their own living enemy list instead of expanding the single-target snapshot. if (effect.Targeting == CardTargeting.SingleEnemy) return CardTargeting.SingleEnemy; if (effect.Targeting == CardTargeting.AllEnemies) targeting = CardTargeting.AllEnemies; } return targeting; } private static List CreateSerializedEffects(CardDefinition definition) { List effects = new(); if (definition?.Effects == null) { return effects; } for (int i = 0; i < definition.Effects.Count; i++) { CardEffectDefinition authored = definition.Effects[i]; if (authored == null) continue; ICardEffect effect = authored.CreateRuntimeEffect(); if (effect == null) { // Fail the whole override: never execute a partial card or fall back to its catalog entry. string diagnostic = $"Card '{definition.Id}': serialized effect {i + 1} '{authored.name}' " + $"({authored.GetType().Name}) returned no runtime effect; card effects were not executed."; // Include the card asset as Console context so the author can locate the invalid slot. UnityEngine.Debug.LogWarning(diagnostic, definition); return new List { new NoOpCardEffect(diagnostic) }; } effects.Add(effect); } return effects; } public static string GetRulesText(CardInstance card) { if (card?.Definition == null) { return "--"; } // A serialized override may perform arbitrary actions; its author-provided description // takes precedence over rules for a different built-in implementation with the same ID. if (HasSerializedEffects(card.Definition)) { string customDescription = string.IsNullOrWhiteSpace(card.Definition.Description) ? "custom serialized effect." : card.Definition.Description; return customDescription + (card.UpgradeLevel > 0 ? " [upgraded]" : string.Empty); } if (CardCatalog.TryGet(card.Definition.Id, out CardCatalogEntry entry)) { return entry.GetRulesText(card); } return string.IsNullOrWhiteSpace(card.Definition.Description) ? "effect not authored." : card.Definition.Description + (card.UpgradeLevel > 0 ? " [upgraded]" : string.Empty); } } public static class UpgradeMath { public static int ScaleAmount(int baseAmount, CardInstance card) { return CardScaling.Add(baseAmount, card?.MagnitudeBonus ?? 0); } public static int ScaleShield(int baseAmount, CardInstance card) { return CardScaling.Add(baseAmount, card?.MagnitudeBonus ?? 0); } public static int ApplySourceFlatBonus(int amount, CombatContext context) { return CardScaling.Add(amount, context?.Source?.FlatEffectBonus ?? 0); } } }