Add tutorial and QoL improvements
This commit is contained in:
@@ -7,15 +7,12 @@ namespace KernelPanic.Combat
|
||||
{
|
||||
public sealed class DealDamageEffect : ICardEffect
|
||||
{
|
||||
private const int RustOverflowRollMax = 10000000;
|
||||
private const string RustUnsigned64LimitText = "18446744073709551615";
|
||||
|
||||
private readonly int _minAmount;
|
||||
private readonly int _maxAmount;
|
||||
private readonly Language _language;
|
||||
private readonly bool _trueDamage;
|
||||
private readonly bool _canCrit;
|
||||
private readonly bool _allEnemies;
|
||||
private readonly bool _allEnemies;
|
||||
|
||||
public DealDamageEffect(int minAmount, int maxAmount, Language language, bool trueDamage = false, bool canCrit = true, bool allEnemies = false)
|
||||
{
|
||||
@@ -29,142 +26,18 @@ namespace KernelPanic.Combat
|
||||
|
||||
public void Execute(CombatContext context)
|
||||
{
|
||||
IReadOnlyList<CombatantState> targets = _allEnemies
|
||||
? context.Enemies.Where(enemy => enemy.State != null && !enemy.State.IsDefeated).Select(enemy => enemy.State).ToList()
|
||||
: context.Targets;
|
||||
|
||||
if (StatusEffectController.Has(context.Source, StatusType.RaceCondition) && targets.Count > 1)
|
||||
{
|
||||
targets = ShuffleTargets(targets, context.Source);
|
||||
}
|
||||
|
||||
bool dealtDamage = false;
|
||||
for (int i = 0; i < targets.Count; i++)
|
||||
{
|
||||
CombatantState target = targets[i];
|
||||
if (target == null || target.IsDefeated)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
int minAmount = UpgradeMath.ScaleAmount(UpgradeMath.ApplySourceFlatBonus(_minAmount, context), context.Card);
|
||||
int maxAmount = UpgradeMath.ScaleAmount(UpgradeMath.ApplySourceFlatBonus(_maxAmount, context), context.Card);
|
||||
int amount = minAmount == maxAmount
|
||||
? minAmount
|
||||
: RandomRoll.RollRange(minAmount, maxAmount, new RollContext(context.Source));
|
||||
bool rustUnsignedOverflow = IsRustDamage(context)
|
||||
&& RandomRoll.RollRange(1, RustOverflowRollMax, new RollContext(context.Source)) == 1;
|
||||
if (rustUnsignedOverflow)
|
||||
{
|
||||
amount = int.MaxValue;
|
||||
context.CombatManager.ReportEffectResult($"rust unsigned overflow: {RustUnsigned64LimitText}");
|
||||
}
|
||||
|
||||
bool rustOverkillToShield = IsRustDamage(context);
|
||||
bool overkillSpills = IsSpillDamage(context);
|
||||
int survivable = rustOverkillToShield || overkillSpills
|
||||
? GetSurvivableDamage(target, _trueDamage)
|
||||
: 0;
|
||||
DamageResult result = context.DamagePipeline.DealDamage(new DamageRequest(context.Source, target, amount, _language, _trueDamage, _canCrit && !rustUnsignedOverflow));
|
||||
dealtDamage |= result.IncomingAmount > 0;
|
||||
if (rustOverkillToShield)
|
||||
{
|
||||
GrantRustOverkillShield(context, result, survivable);
|
||||
}
|
||||
|
||||
if (result.TargetDefeated)
|
||||
{
|
||||
context.CombatManager.QueueDefeatedCombatantForRemoval(target);
|
||||
}
|
||||
|
||||
if (overkillSpills)
|
||||
{
|
||||
dealtDamage |= SpillOverkillDamage(context, target, result, survivable);
|
||||
}
|
||||
}
|
||||
|
||||
SegfaultRecoil.TryApply(context, _language, dealtDamage);
|
||||
CardDamageExecutor.Execute(context, () => RollDamageAmount(context), _language,
|
||||
_trueDamage, _canCrit, _allEnemies);
|
||||
}
|
||||
|
||||
private bool IsRustDamage(CombatContext context)
|
||||
private int RollDamageAmount(CombatContext context)
|
||||
{
|
||||
return _language == Language.Rust || context.Card?.Definition?.Language == Language.Rust;
|
||||
}
|
||||
|
||||
private bool IsSpillDamage(CombatContext context)
|
||||
{
|
||||
Language cardLanguage = context.Card?.Definition == null ? _language : context.Card.Definition.Language;
|
||||
return _language == Language.C
|
||||
|| _language == Language.Java
|
||||
|| cardLanguage == Language.C
|
||||
|| cardLanguage == Language.Java;
|
||||
}
|
||||
|
||||
private static int GetSurvivableDamage(CombatantState target, bool trueDamage)
|
||||
{
|
||||
return target == null ? 0 : trueDamage ? target.CurrentUptime : target.CurrentUptime + target.Shield;
|
||||
}
|
||||
|
||||
private bool SpillOverkillDamage(CombatContext context, CombatantState firstTarget, DamageResult firstResult, int firstSurvivable)
|
||||
{
|
||||
int remaining = UnityEngine.Mathf.Max(0, firstResult.IncomingAmount - firstSurvivable);
|
||||
if (remaining <= 0)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
bool dealtDamage = false;
|
||||
for (int i = 0; i < context.Enemies.Count && remaining > 0; i++)
|
||||
{
|
||||
CombatantState spillTarget = context.Enemies[i].State;
|
||||
if (spillTarget == null || spillTarget == firstTarget || spillTarget.IsDefeated)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
int survivable = GetSurvivableDamage(spillTarget, _trueDamage);
|
||||
GameEvents.RaiseOverflowDamageTravel(new OverflowDamageTravelEvent(context.Source, firstTarget, spillTarget, remaining, _language));
|
||||
DamageResult spillResult = context.DamagePipeline.DealDamage(new DamageRequest(context.Source, spillTarget, remaining, _language, _trueDamage, false, applySourceModifiers: false));
|
||||
dealtDamage |= spillResult.IncomingAmount > 0;
|
||||
if (spillResult.TargetDefeated)
|
||||
{
|
||||
context.CombatManager.QueueDefeatedCombatantForRemoval(spillTarget);
|
||||
}
|
||||
|
||||
firstTarget = spillTarget;
|
||||
remaining = UnityEngine.Mathf.Max(0, spillResult.IncomingAmount - survivable);
|
||||
}
|
||||
|
||||
return dealtDamage;
|
||||
}
|
||||
|
||||
private static void GrantRustOverkillShield(CombatContext context, DamageResult result, int survivable)
|
||||
{
|
||||
int overkill = UnityEngine.Mathf.Max(0, result.IncomingAmount - survivable);
|
||||
if (overkill <= 0)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
if (!context.CombatManager.CanPlayerReceiveCardShield(context.Card))
|
||||
{
|
||||
context.CombatManager.ReportEffectResult($"overkill shield blocked: {overkill}");
|
||||
return;
|
||||
}
|
||||
|
||||
context.CombatManager.GrantPlayerShield(overkill, "rust overkill");
|
||||
}
|
||||
|
||||
private static IReadOnlyList<CombatantState> ShuffleTargets(IReadOnlyList<CombatantState> targets, CombatantState source)
|
||||
{
|
||||
List<CombatantState> shuffled = targets.ToList();
|
||||
for (int i = shuffled.Count - 1; i > 0; i--)
|
||||
{
|
||||
int swapIndex = RandomRoll.RollRange(0, i, new RollContext(source));
|
||||
(shuffled[i], shuffled[swapIndex]) = (shuffled[swapIndex], shuffled[i]);
|
||||
}
|
||||
|
||||
return shuffled;
|
||||
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;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -179,14 +52,7 @@ namespace KernelPanic.Combat
|
||||
|
||||
public void Execute(CombatContext context)
|
||||
{
|
||||
int amount = UpgradeMath.ScaleShield(UpgradeMath.ApplySourceFlatBonus(_amount, context), context.Card);
|
||||
if (!context.CombatManager.CanPlayerReceiveCardShield(context.Card))
|
||||
{
|
||||
context.CombatManager.ReportEffectResult($"shield blocked: {amount}");
|
||||
return;
|
||||
}
|
||||
|
||||
context.CombatManager.GrantPlayerShield(amount, "card");
|
||||
CardShieldExecutor.Execute(context, CardShieldExecutor.ScaleAmount(_amount, context));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -204,14 +70,7 @@ namespace KernelPanic.Combat
|
||||
public void Execute(CombatContext context)
|
||||
{
|
||||
int amount = _baseAmount + (context.Card != null && context.Card.WasFirstCardThisTurn ? _firstCardBonus : 0);
|
||||
amount = UpgradeMath.ScaleShield(UpgradeMath.ApplySourceFlatBonus(amount, context), context.Card);
|
||||
if (!context.CombatManager.CanPlayerReceiveCardShield(context.Card))
|
||||
{
|
||||
context.CombatManager.ReportEffectResult($"shield blocked: {amount}");
|
||||
return;
|
||||
}
|
||||
|
||||
context.CombatManager.GrantPlayerShield(amount, "card");
|
||||
CardShieldExecutor.Execute(context, CardShieldExecutor.ScaleAmount(amount, context));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -230,23 +89,15 @@ namespace KernelPanic.Combat
|
||||
|
||||
public void Execute(CombatContext context)
|
||||
{
|
||||
for (int i = 0; i < context.Targets.Count; i++)
|
||||
CardDamageExecutor.Execute(context, () =>
|
||||
{
|
||||
CombatantState target = context.Targets[i];
|
||||
if (target == null || target.IsDefeated)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
int roll = context.Source != null && context.Source.ForceMaxRolls
|
||||
? 1
|
||||
: RandomRoll.RollRange(1, 100, RollContext.None);
|
||||
int damageAmount = UpgradeMath.ScaleAmount(UpgradeMath.ApplySourceFlatBonus(_damageAmount, context), context.Card);
|
||||
int amount = roll <= _successPercent ? damageAmount : 0;
|
||||
DamageResult result = context.DamagePipeline.DealDamage(new DamageRequest(context.Source, target, amount, _language, false, true));
|
||||
SegfaultRecoil.TryApply(context, _language, result.IncomingAmount > 0);
|
||||
context.CombatManager.ReportEffectResult(amount == 0 ? "typeof -> NaN (0)" : $"typeof -> {amount}");
|
||||
}
|
||||
// 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}"));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -344,10 +195,14 @@ namespace KernelPanic.Combat
|
||||
|
||||
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<CardInstance> candidates = context.HandController.Cards.Where(card => card != null).Take(2).ToList();
|
||||
List<CardInstance> candidates = context.HandController.Cards.Where(card => card != null).Take(MaxExhaust).ToList();
|
||||
for (int i = 0; i < candidates.Count; i++)
|
||||
{
|
||||
CardInstance card = candidates[i];
|
||||
@@ -367,41 +222,62 @@ namespace KernelPanic.Combat
|
||||
return;
|
||||
}
|
||||
|
||||
int shield = exhausted * 3;
|
||||
if (context.CombatManager.CanPlayerReceiveCardShield(context.Card))
|
||||
{
|
||||
context.CombatManager.GrantPlayerShield(shield, "minimal install");
|
||||
}
|
||||
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;
|
||||
context.CombatManager.ReportEffectResult($"minimal install: exhausted {exhausted}, +{exhausted} Cycle");
|
||||
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 = 5 * cCards;
|
||||
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(1, "consult the wiki");
|
||||
context.CombatManager.DrawCards(DrawCount, "consult the wiki");
|
||||
context.CombatManager.ReportEffectResult("fixed a broken card");
|
||||
return;
|
||||
}
|
||||
|
||||
new DealDamageEffect(6, 6, Language.Rust).Execute(context);
|
||||
new DealDamageEffect(FallbackDamage, FallbackDamage, Language.Rust).Execute(context);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>Repairs a bounded number of corrupted cards without drawing or moving them.</summary>
|
||||
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);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -460,6 +336,10 @@ namespace KernelPanic.Combat
|
||||
{
|
||||
context.StatusEffects.CleanseHarmful(context.Source);
|
||||
}
|
||||
else
|
||||
{
|
||||
context.StatusEffects.Cleanse(context.Source, _ => true);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -481,36 +361,34 @@ namespace KernelPanic.Combat
|
||||
return;
|
||||
}
|
||||
|
||||
// RAM is a hard hand cap. Draw effects only pull cards that can fit; blocked cards stay in the draw pile.
|
||||
int baseCount = _count;
|
||||
if (context.Card?.Definition?.Id == "ubuntu_ask_ubuntu"
|
||||
&& string.Equals(context.CombatManager.RunConfig?.Distro?.Id, "ubuntu", System.StringComparison.OrdinalIgnoreCase)
|
||||
&& context.CombatManager.RunConfig.DistroVersion >= 3)
|
||||
{
|
||||
baseCount = 3;
|
||||
}
|
||||
|
||||
int requested = UpgradeMath.ScaleAmount(UpgradeMath.ApplySourceFlatBonus(baseCount, context), context.Card);
|
||||
int drawCount = UnityEngine.Mathf.Min(requested, room);
|
||||
IReadOnlyList<CardInstance> drawn = context.DeckController.Draw(drawCount);
|
||||
int requested = UpgradeMath.ScaleAmount(UpgradeMath.ApplySourceFlatBonus(_count, context), context.Card);
|
||||
int added = 0;
|
||||
for (int i = 0; i < drawn.Count; i++)
|
||||
// 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 _))
|
||||
{
|
||||
if (context.HandController.Add(drawn[i]))
|
||||
{
|
||||
added++;
|
||||
}
|
||||
else
|
||||
{
|
||||
context.DeckController.AddToDrawPile(drawn[i], shuffle: false);
|
||||
}
|
||||
added++;
|
||||
}
|
||||
|
||||
string capped = drawCount < requested ? " (hand full)" : string.Empty;
|
||||
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;
|
||||
@@ -721,30 +599,8 @@ namespace KernelPanic.Combat
|
||||
|
||||
public void Execute(CombatContext context)
|
||||
{
|
||||
for (int i = 0; i < context.Targets.Count; i++)
|
||||
{
|
||||
CombatantState target = context.Targets[i];
|
||||
if (target == null || target.IsDefeated)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
int amount = UpgradeMath.ScaleAmount(UpgradeMath.ApplySourceFlatBonus(_amount, context), context.Card);
|
||||
int survivable = target.CurrentUptime + target.Shield;
|
||||
DamageResult result = context.DamagePipeline.DealDamage(new DamageRequest(context.Source, target, amount, _language, false, true));
|
||||
SegfaultRecoil.TryApply(context, _language, result.IncomingAmount > 0);
|
||||
int overkill = UnityEngine.Mathf.Max(0, result.IncomingAmount - survivable);
|
||||
if (overkill > 0)
|
||||
{
|
||||
if (!context.CombatManager.CanPlayerReceiveCardShield(context.Card))
|
||||
{
|
||||
context.CombatManager.ReportEffectResult($"overkill shield blocked: {overkill}");
|
||||
continue;
|
||||
}
|
||||
|
||||
context.CombatManager.GrantPlayerShield(overkill, "overkill");
|
||||
}
|
||||
}
|
||||
CardDamageExecutor.Execute(context, () => CardDamageExecutor.ScaleAmount(_amount, context),
|
||||
_language, overkillToShield: true);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -780,8 +636,7 @@ namespace KernelPanic.Combat
|
||||
|
||||
public void Execute(CombatContext context)
|
||||
{
|
||||
int amount = UpgradeMath.ScaleAmount(UpgradeMath.ApplySourceFlatBonus(_amount, context), context.Card);
|
||||
new DealDamageEffect(amount, amount, Language.Java).Execute(context);
|
||||
new DealDamageEffect(_amount, _amount, Language.Java).Execute(context);
|
||||
context.CombatManager.AddJavaCostDiscountThisTurn(1);
|
||||
}
|
||||
}
|
||||
@@ -806,8 +661,7 @@ namespace KernelPanic.Combat
|
||||
return;
|
||||
}
|
||||
|
||||
int damageAmount = UpgradeMath.ScaleAmount(UpgradeMath.ApplySourceFlatBonus(_damageAmount, context), context.Card);
|
||||
new DealDamageEffect(damageAmount, damageAmount, Language.Rust).Execute(context);
|
||||
new DealDamageEffect(_damageAmount, _damageAmount, Language.Rust).Execute(context);
|
||||
if (context.HandController.Remove(junk))
|
||||
{
|
||||
context.DeckController.Exhaust(junk);
|
||||
@@ -820,34 +674,7 @@ namespace KernelPanic.Combat
|
||||
|
||||
private static CardInstance FindJunkCard(CombatContext context)
|
||||
{
|
||||
for (int i = 0; i < context.HandController.Cards.Count; i++)
|
||||
{
|
||||
CardInstance card = context.HandController.Cards[i];
|
||||
if (IsJunk(card))
|
||||
{
|
||||
return card;
|
||||
}
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
private static bool IsJunk(CardInstance card)
|
||||
{
|
||||
if (card == null)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
string id = card.Definition?.Id ?? string.Empty;
|
||||
string name = card.Definition?.DisplayName ?? string.Empty;
|
||||
return card.Definition != null && card.Definition.IsToken
|
||||
|| card.IsBroken
|
||||
|| id.IndexOf("junk", System.StringComparison.OrdinalIgnoreCase) >= 0
|
||||
|| id.IndexOf("nop", System.StringComparison.OrdinalIgnoreCase) >= 0
|
||||
|| name.IndexOf("junk", System.StringComparison.OrdinalIgnoreCase) >= 0
|
||||
|| name.IndexOf("NOP", System.StringComparison.OrdinalIgnoreCase) >= 0
|
||||
|| name.IndexOf("broken", System.StringComparison.OrdinalIgnoreCase) >= 0;
|
||||
return CardEligibility.FindAutoremoveTarget(context.HandController?.Cards, context.Card);
|
||||
}
|
||||
|
||||
private static string GetCardName(CardInstance card)
|
||||
@@ -867,8 +694,10 @@ namespace KernelPanic.Combat
|
||||
|
||||
public void Execute(CombatContext context)
|
||||
{
|
||||
int amount = UpgradeMath.ScaleAmount(UpgradeMath.ApplySourceFlatBonus(_amount, context), context.Card);
|
||||
new DealDamageEffect(amount, amount, Language.Python, allEnemies: true).Execute(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);
|
||||
}
|
||||
}
|
||||
@@ -883,9 +712,11 @@ namespace KernelPanic.Combat
|
||||
|
||||
public sealed class RawhideEffect : ICardEffect
|
||||
{
|
||||
internal const int DrawCount = 2;
|
||||
|
||||
public void Execute(CombatContext context)
|
||||
{
|
||||
new DrawEffect(2).Execute(context);
|
||||
new DrawEffect(DrawCount).Execute(context);
|
||||
context.CombatManager.GrantRawhideBonus(1);
|
||||
context.CombatManager.ReportEffectResult("rawhide armed next card");
|
||||
}
|
||||
@@ -923,7 +754,7 @@ namespace KernelPanic.Combat
|
||||
|
||||
internal static class SegfaultRecoil
|
||||
{
|
||||
private const int DefaultPercent = 20;
|
||||
private const int DefaultPercent = 25;
|
||||
private const int DefaultUptimeDamage = 3;
|
||||
|
||||
public static void TryApply(CombatContext context, Language damageLanguage, bool dealtDamage)
|
||||
@@ -946,7 +777,8 @@ namespace KernelPanic.Combat
|
||||
return;
|
||||
}
|
||||
|
||||
DamageResult result = context.DamagePipeline.DealDamage(new DamageRequest(null, context.Source, uptimeDamage, Language.C, true, false));
|
||||
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)
|
||||
@@ -978,122 +810,57 @@ namespace KernelPanic.Combat
|
||||
{
|
||||
public static IReadOnlyList<ICardEffect> CreateEffects(CardDefinition definition)
|
||||
{
|
||||
List<ICardEffect> serializedEffects = CreateSerializedEffects(definition);
|
||||
if (serializedEffects.Count > 0)
|
||||
if (HasSerializedEffects(definition))
|
||||
{
|
||||
return serializedEffects;
|
||||
return CreateSerializedEffects(definition);
|
||||
}
|
||||
|
||||
return definition?.Id switch
|
||||
{
|
||||
"lang_py_print" => One(new DealDamageEffect(3, 3, Language.Python)),
|
||||
"lang_py_import_antigravity" => One(new DrawEffect(2)),
|
||||
"lang_py_for_loop" => One(new DealDamageEffect(2, 2, Language.Python, allEnemies: true)),
|
||||
"lang_js_console_log" => One(new DealDamageEffect(3, 9, Language.JavaScript)),
|
||||
"lang_js_fetch" => One(new DealDamageEffect(5, 13, Language.JavaScript)),
|
||||
"lang_rs_fn_main" => One(new DealDamageEffect(6, 6, Language.Rust)),
|
||||
"lang_rs_unwrap" => new ICardEffect[]
|
||||
{
|
||||
new DealDamageEffect(9, 9, Language.Rust),
|
||||
new DrawEffect(1)
|
||||
},
|
||||
"lang_rs_borrow" => One(new ShieldEffect(5)),
|
||||
"lang_c_malloc" => One(new DealDamageEffect(12, 12, Language.C)),
|
||||
"lang_c_printf" => One(new DealDamageEffect(7, 7, Language.C)),
|
||||
"lang_c_pointer" => One(new PreviousLanguageDamageEffect(9, 15, Language.C)),
|
||||
"lang_java_public_static_main" => One(new DealDamageEffect(7, 7, Language.Java)),
|
||||
"lang_java_system_out_println" => One(new DealDamageEffect(5, 5, Language.Java)),
|
||||
"lang_java_new_object" => One(new DealDamageEffect(3, 3, Language.Java)),
|
||||
"ubuntu_ask_ubuntu" => One(new DrawEffect(2)),
|
||||
"ubuntu_unattended_upgrades" => new ICardEffect[]
|
||||
{
|
||||
new ShieldEffect(4),
|
||||
new ApplyStatusEffect(StatusType.UnattendedUpgrades, 4, 2, targetSelf: true, skipNextTick: true)
|
||||
},
|
||||
"mint_fix_broken" => new ICardEffect[]
|
||||
{
|
||||
new DealDamageEffect(8, 8, Language.JavaScript),
|
||||
new CleanseEffect(harmfulOnly: true)
|
||||
},
|
||||
"lang_js_typeof" => One(new ChanceDamageEffect(8, 75, Language.JavaScript)),
|
||||
"shop_py_list_append" => One(new QueuedGrowthDamageEffect(4, Language.Python)),
|
||||
"shop_py_async_def" => new ICardEffect[]
|
||||
{
|
||||
new DrawEffect(2),
|
||||
new NextTurnCycleEffect(1)
|
||||
},
|
||||
"shop_py_zip" => One(new QueueRepeatEffect(2)),
|
||||
"shop_js_math_random" => One(new DealDamageEffect(2, 20, Language.JavaScript)),
|
||||
"shop_js_promise_all" => new ICardEffect[]
|
||||
{
|
||||
new DealDamageEffect(4, 10, Language.JavaScript),
|
||||
new DealDamageEffect(4, 10, Language.JavaScript),
|
||||
new DealDamageEffect(4, 10, Language.JavaScript)
|
||||
},
|
||||
"shop_js_spread" => One(new CopyLowestCostHandCardEffect()),
|
||||
"ubuntu_snap_install" => new ICardEffect[]
|
||||
{
|
||||
new DealDamageEffect(6, 14, Language.JavaScript),
|
||||
new ShuffleTokenIntoDrawPileEffect("ubuntu_pro_trial")
|
||||
},
|
||||
"ubuntu_do_release_upgrade" => One(new UpgradeHandCardsEffect(1, 3)),
|
||||
"ubuntu_apt_install" => One(new GenerateCardEffect(Language.Python, Rarity.Common)),
|
||||
"ubuntu_pro_trial" => One(new NoOpCardEffect("ubuntu pro trial is unplayable")),
|
||||
"mint_update_manager" => One(new UpdateManagerEffect(5)),
|
||||
"mint_cinnamon" => new ICardEffect[]
|
||||
{
|
||||
new ShieldEffect(3),
|
||||
new DrawEffect(1)
|
||||
},
|
||||
"mint_nemo" => One(new ConditionalShieldRepeatDamageEffect(6, Language.JavaScript)),
|
||||
"mint_timeshift" => One(new TimeshiftSnapshotEffect()),
|
||||
"fedora_dnf_autoremove" => One(new DnfAutoremoveEffect(7, 1)),
|
||||
"fedora_first_to_package" => One(new FirstToPackageEffect(7)),
|
||||
"fedora_dnf_update" => One(new DealDamageEffect(9, 9, Language.Java)),
|
||||
"fedora_rawhide" => One(new RawhideEffect()),
|
||||
"fedora_selinux" => One(new IncomingAttackHalveEffect(2)),
|
||||
"arch_pacman_syu" => One(new DealDamageEffect(14, 14, Language.C)),
|
||||
"arch_consult_wiki" => One(new ConsultWikiEffect()),
|
||||
"arch_makepkg" => One(new BtwScaledDamageEffect(7, 3, Language.C)),
|
||||
"arch_aur_helper" => One(new RandomCommonLanguageCardEffect()),
|
||||
"arch_minimal_install" => One(new MinimalInstallEffect()),
|
||||
"shop_c_free" => One(new DealDamageEffect(18, 18, Language.C)),
|
||||
"shop_c_sizeof" => One(new SizeofDamageEffect()),
|
||||
"shop_c_kernel_exploit" => One(new DealDamageEffect(36, 36, Language.C, true)),
|
||||
_ => Todo("card effect is not authored")
|
||||
};
|
||||
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 definition?.Id is "lang_js_console_log" or "lang_js_fetch" or "lang_js_typeof" or "mint_fix_broken"
|
||||
or "lang_rs_fn_main" or "lang_rs_unwrap" or "lang_c_malloc" or "lang_c_printf" or "lang_c_pointer" or "lang_java_public_static_main"
|
||||
or "lang_java_system_out_println" or "lang_java_new_object"
|
||||
or "shop_py_list_append" or "shop_js_math_random" or "shop_js_promise_all" or "ubuntu_snap_install"
|
||||
or "mint_nemo" or "fedora_dnf_autoremove" or "fedora_first_to_package" or "fedora_dnf_update"
|
||||
or "arch_pacman_syu" or "arch_consult_wiki" or "arch_makepkg" or "shop_c_free" or "shop_c_sizeof" or "shop_c_kernel_exploit";
|
||||
return GetTargeting(definition) == CardTargeting.SingleEnemy;
|
||||
}
|
||||
|
||||
public static bool CanReceiveBleedingEdgeDamageBonus(CardDefinition definition)
|
||||
{
|
||||
if (definition == null || definition.ResolutionTrack != ResolutionTrack.Native)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
return definition.Id is "lang_js_console_log" or "lang_js_fetch" or "lang_js_typeof" or "mint_fix_broken"
|
||||
or "lang_rs_fn_main" or "lang_rs_unwrap"
|
||||
or "lang_c_malloc" or "lang_c_printf" or "lang_c_pointer"
|
||||
or "lang_java_public_static_main" or "lang_java_system_out_println" or "lang_java_new_object"
|
||||
or "shop_js_math_random" or "shop_js_promise_all" or "ubuntu_snap_install"
|
||||
or "mint_nemo" or "fedora_dnf_autoremove" or "fedora_first_to_package" or "fedora_dnf_update"
|
||||
or "arch_pacman_syu" or "arch_consult_wiki" or "arch_makepkg"
|
||||
or "shop_c_free" or "shop_c_sizeof" or "shop_c_kernel_exploit";
|
||||
return definition != null && definition.ResolutionTrack == ResolutionTrack.Native
|
||||
&& CardCatalog.TryGet(definition.Id, out CardCatalogEntry entry) && entry.BleedingEdgeEligible;
|
||||
}
|
||||
|
||||
public static bool TargetsAllEnemies(CardDefinition definition)
|
||||
{
|
||||
return definition?.Id is "lang_py_for_loop";
|
||||
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<ICardEffect> CreateSerializedEffects(CardDefinition definition)
|
||||
@@ -1106,26 +873,24 @@ namespace KernelPanic.Combat
|
||||
|
||||
for (int i = 0; i < definition.Effects.Count; i++)
|
||||
{
|
||||
ICardEffect effect = definition.Effects[i] == null ? null : definition.Effects[i].CreateRuntimeEffect();
|
||||
if (effect != null)
|
||||
CardEffectDefinition authored = definition.Effects[i];
|
||||
if (authored == null) continue;
|
||||
ICardEffect effect = authored.CreateRuntimeEffect();
|
||||
if (effect == null)
|
||||
{
|
||||
effects.Add(effect);
|
||||
// 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<ICardEffect> { new NoOpCardEffect(diagnostic) };
|
||||
}
|
||||
effects.Add(effect);
|
||||
}
|
||||
|
||||
return effects;
|
||||
}
|
||||
|
||||
private static IReadOnlyList<ICardEffect> One(ICardEffect effect)
|
||||
{
|
||||
return new[] { effect };
|
||||
}
|
||||
|
||||
private static IReadOnlyList<ICardEffect> Todo(string message)
|
||||
{
|
||||
return One(new NoOpCardEffect(message));
|
||||
}
|
||||
|
||||
public static string GetRulesText(CardInstance card)
|
||||
{
|
||||
if (card?.Definition == null)
|
||||
@@ -1133,75 +898,42 @@ namespace KernelPanic.Combat
|
||||
return "--";
|
||||
}
|
||||
|
||||
int level = card.UpgradeLevel;
|
||||
string marker = level > 0 ? " [upgraded]" : string.Empty;
|
||||
return card.Definition.Id switch
|
||||
// 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))
|
||||
{
|
||||
"lang_py_print" => $"queue: deal {UpgradeMath.ScaleAmount(3, card)}.{marker}",
|
||||
"lang_py_import_antigravity" => $"queue: draw {UpgradeMath.ScaleAmount(2, card)}.{marker}",
|
||||
"lang_py_for_loop" => $"queue: deal {UpgradeMath.ScaleAmount(2, card)} to all enemies.{marker}",
|
||||
"lang_js_console_log" => $"deal {UpgradeMath.ScaleAmount(3, card)}-{UpgradeMath.ScaleAmount(9, card)}.{marker}",
|
||||
"lang_js_fetch" => $"deal {UpgradeMath.ScaleAmount(5, card)}-{UpgradeMath.ScaleAmount(13, card)}.{marker}",
|
||||
"lang_js_typeof" => $"75%: deal {UpgradeMath.ScaleAmount(8, card)}. 25%: deal 0.{marker}",
|
||||
"lang_rs_fn_main" => $"deal {UpgradeMath.ScaleAmount(6, card)}. overkill becomes shield.{marker}",
|
||||
"lang_rs_unwrap" => $"deal {UpgradeMath.ScaleAmount(9, card)}. overkill becomes shield. draw {UpgradeMath.ScaleAmount(1, card)}.{marker}",
|
||||
"lang_rs_borrow" => $"gain {UpgradeMath.ScaleShield(5, card)} shield.{marker}",
|
||||
"lang_c_malloc" => $"deal {UpgradeMath.ScaleAmount(12, card)}. overkill spills. 20%: segfault, uptime -3 and corrupt a hand card.{marker}",
|
||||
"lang_c_printf" => $"deal {UpgradeMath.ScaleAmount(7, card)}. overkill spills. 20%: segfault, uptime -3 and corrupt a hand card.{marker}",
|
||||
"lang_c_pointer" => $"deal {UpgradeMath.ScaleAmount(9, card)}; {UpgradeMath.ScaleAmount(15, card)} if the previous card was C. overkill spills. 20%: segfault, uptime -3 and corrupt a hand card.{marker}",
|
||||
"lang_java_public_static_main" => $"uses 2 RAM. deal {UpgradeMath.ScaleAmount(7, card)}. overkill spills. JIT: Java cards cost 1 less this combat each time you play a Java card; discount decays by 1 after each wave.{marker}",
|
||||
"lang_java_system_out_println" => $"uses 2 RAM. deal {UpgradeMath.ScaleAmount(5, card)}. overkill spills. JIT applies; discount decays by 1 after each wave.{marker}",
|
||||
"lang_java_new_object" => $"uses 2 RAM. deal {UpgradeMath.ScaleAmount(3, card)}. overkill spills. JIT applies; discount decays by 1 after each wave.{marker}",
|
||||
"shop_py_list_append" => $"queue: deal {UpgradeMath.ScaleAmount(4 + UnityEngine.Mathf.Max(0, card.QueuePlayCount - 1), card)}; +1 each time re-queued.{marker}",
|
||||
"shop_py_async_def" => $"queue: draw {UpgradeMath.ScaleAmount(2, card)}. gain {UpgradeMath.ScaleAmount(1, card)} cycle next turn.{marker}",
|
||||
"shop_py_zip" => $"next {UpgradeMath.ScaleAmount(2, card)} queued cards resolve twice.{marker}",
|
||||
"shop_js_math_random" => $"deal {UpgradeMath.ScaleAmount(2, card)}-{UpgradeMath.ScaleAmount(20, card)}.{marker}",
|
||||
"shop_js_promise_all" => $"deal {UpgradeMath.ScaleAmount(4, card)}-{UpgradeMath.ScaleAmount(10, card)} three times.{marker}",
|
||||
"shop_js_spread" => $"copy the lowest-cost card in hand.{marker}",
|
||||
"ubuntu_ask_ubuntu" => $"queue: draw {UpgradeMath.ScaleAmount(2, card)}.{marker}",
|
||||
"ubuntu_unattended_upgrades" => $"queue: gain {UpgradeMath.ScaleShield(4, card)} shield now and next 2 turns.{marker}",
|
||||
"ubuntu_snap_install" => $"deal {UpgradeMath.ScaleAmount(6, card)}-{UpgradeMath.ScaleAmount(14, card)}. shuffle an ubuntu pro trial into your draw pile.{marker}",
|
||||
"ubuntu_do_release_upgrade" => $"upgrade {UpgradeMath.ScaleAmount(1, card)}-{UpgradeMath.ScaleAmount(3, card)} random hand cards.{marker}",
|
||||
"ubuntu_apt_install" => $"queue: generate a random common Python card at 0c.{marker}",
|
||||
"mint_fix_broken" => $"deal {UpgradeMath.ScaleAmount(8, card)}. cleanse harmful statuses.{marker}",
|
||||
"mint_update_manager" => $"queue: deal {UpgradeMath.ScaleAmount(5, card)} to all enemies. repeats at the end of your next turn.{marker}",
|
||||
"mint_cinnamon" => $"queue: gain {UpgradeMath.ScaleShield(3, card)} shield. draw {UpgradeMath.ScaleAmount(1, card)}.{marker}",
|
||||
"mint_nemo" => $"deal {UpgradeMath.ScaleAmount(6, card)}. if you have shield, deal it again.{marker}",
|
||||
"mint_timeshift" => $"queue: record uptime now. at end of your next turn, restore to it if lower.{marker}",
|
||||
"fedora_dnf_autoremove" => $"deal {UpgradeMath.ScaleAmount(7, card)}. exhaust a junk/NOP/broken card from hand; if you do, gain {UpgradeMath.ScaleAmount(1, card)} cycle. if not, do nothing.{marker}",
|
||||
"fedora_first_to_package" => $"deal {UpgradeMath.ScaleAmount(7, card)}. Java cards cost 1 less this turn.{marker}",
|
||||
"fedora_dnf_update" => $"deal {UpgradeMath.ScaleAmount(9, card)}. overkill spills. costs 1 less per Java card played this combat.{marker}",
|
||||
"fedora_rawhide" => $"draw {UpgradeMath.ScaleAmount(2, card)}. next card this turn gains bleeding edge.{marker}",
|
||||
"fedora_selinux" => $"next {UpgradeMath.ScaleAmount(2, card)} enemy attacks deal half damage.{marker}",
|
||||
"arch_pacman_syu" => $"deal {UpgradeMath.ScaleAmount(14, card)}. overkill spills. 20%: segfault, uptime -3 and corrupt a hand card.{marker}",
|
||||
"arch_consult_wiki" => $"fix a broken card and draw {UpgradeMath.ScaleAmount(1, card)}; if none, deal {UpgradeMath.ScaleAmount(6, card)}.{marker}",
|
||||
"arch_makepkg" => $"deal {UpgradeMath.ScaleAmount(7, card)} + btw x3; x4 at Arch v3+. overkill spills. 20%: segfault, uptime -3 and corrupt a hand card.{marker}",
|
||||
"arch_aur_helper" => $"add a random C/Rust common card to hand; it costs 0 this turn.{marker}",
|
||||
"arch_minimal_install" => $"exhaust up to 2 hand cards. per card: gain 3 Shield and 1 Cycle.{marker}",
|
||||
"shop_c_free" => $"deal {UpgradeMath.ScaleAmount(18, card)}. overkill spills. 20%: segfault, uptime -3, corrupt a hand card, and draw 2.{marker}",
|
||||
"shop_c_sizeof" => $"deal 5 x C cards in hand. overkill spills. 20%: segfault, uptime -3 and corrupt a hand card.{marker}",
|
||||
"shop_c_kernel_exploit" => $"deal {UpgradeMath.ScaleAmount(36, card)} ignoring Shield. overkill spills. 50%: segfault, uptime -8 and corrupt a hand card.{marker}",
|
||||
_ => string.IsNullOrWhiteSpace(card.Definition.Description) ? "effect not authored." : $"{card.Definition.Description}{marker}"
|
||||
};
|
||||
}
|
||||
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 baseAmount + UnityEngine.Mathf.Max(0, card?.MagnitudeBonus ?? 0);
|
||||
return CardScaling.Add(baseAmount, card?.MagnitudeBonus ?? 0);
|
||||
}
|
||||
|
||||
public static int ScaleShield(int baseAmount, CardInstance card)
|
||||
{
|
||||
return baseAmount + UnityEngine.Mathf.Max(0, card?.MagnitudeBonus ?? 0);
|
||||
return CardScaling.Add(baseAmount, card?.MagnitudeBonus ?? 0);
|
||||
}
|
||||
|
||||
public static int ApplySourceFlatBonus(int amount, CombatContext context)
|
||||
{
|
||||
return amount + UnityEngine.Mathf.Max(0, context?.Source?.FlatEffectBonus ?? 0);
|
||||
return CardScaling.Add(amount, context?.Source?.FlatEffectBonus ?? 0);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -10,6 +10,8 @@ namespace KernelPanic.Combat
|
||||
public sealed class CardInstance
|
||||
{
|
||||
private readonly List<CombatantState> _targetSnapshot = new();
|
||||
private bool _isBroken;
|
||||
private int _corruptionLastRecoveryRound;
|
||||
|
||||
public CardInstance(CardDefinition definition)
|
||||
{
|
||||
@@ -17,6 +19,7 @@ namespace KernelPanic.Combat
|
||||
}
|
||||
|
||||
public CardDefinition Definition { get; }
|
||||
public string InstanceId { get; private set; } = System.Guid.NewGuid().ToString("N");
|
||||
public IReadOnlyList<CombatantState> TargetSnapshot => _targetSnapshot;
|
||||
public int TemporaryCostDelta { get; set; }
|
||||
public int PermanentCostDelta { get; private set; }
|
||||
@@ -26,12 +29,49 @@ namespace KernelPanic.Combat
|
||||
public int QueuePlayCount { get; private set; }
|
||||
public bool WasFirstCardThisTurn { get; private set; }
|
||||
public bool HadFedoraNonCrashBonus { get; private set; }
|
||||
public bool IsBroken { get; set; }
|
||||
public bool IsBroken
|
||||
{
|
||||
get => _isBroken;
|
||||
set
|
||||
{
|
||||
_isBroken = value;
|
||||
if (!value)
|
||||
{
|
||||
CorruptionRoundsRemaining = 0;
|
||||
_corruptionLastRecoveryRound = 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
// Zero on a broken card means untimed corruption from another source.
|
||||
public int CorruptionRoundsRemaining { get; private set; }
|
||||
public bool IsLocked { get; set; }
|
||||
public bool CanUpgrade => UpgradeLevel == 0;
|
||||
public bool CanReceiveRepositoryUpgrade => UpgradeLevel < 3;
|
||||
public bool IsUpgraded => UpgradeLevel > 0;
|
||||
|
||||
public void CorruptForRounds(int rounds, int currentRound)
|
||||
{
|
||||
IsBroken = true;
|
||||
CorruptionRoundsRemaining = System.Math.Max(1, rounds);
|
||||
_corruptionLastRecoveryRound = System.Math.Max(0, currentRound);
|
||||
}
|
||||
|
||||
public bool AdvanceCorruptionRecovery(int round)
|
||||
{
|
||||
if (!IsBroken || CorruptionRoundsRemaining <= 0 || round <= _corruptionLastRecoveryRound) return false;
|
||||
int elapsed = round - _corruptionLastRecoveryRound;
|
||||
_corruptionLastRecoveryRound = round;
|
||||
CorruptionRoundsRemaining = System.Math.Max(0, CorruptionRoundsRemaining - elapsed);
|
||||
return CorruptionRoundsRemaining == 0 && RepairCorruption();
|
||||
}
|
||||
|
||||
public bool RepairCorruption()
|
||||
{
|
||||
if (!IsBroken) return false;
|
||||
IsBroken = false;
|
||||
return true;
|
||||
}
|
||||
|
||||
public bool Upgrade()
|
||||
{
|
||||
if (!CanUpgrade)
|
||||
@@ -125,6 +165,8 @@ namespace KernelPanic.Combat
|
||||
copy.QueuePlayCount = QueuePlayCount;
|
||||
copy.WasFirstCardThisTurn = WasFirstCardThisTurn;
|
||||
copy.HadFedoraNonCrashBonus = HadFedoraNonCrashBonus;
|
||||
copy.CorruptionRoundsRemaining = CorruptionRoundsRemaining;
|
||||
copy._corruptionLastRecoveryRound = _corruptionLastRecoveryRound;
|
||||
copy.SetTargetSnapshot(TargetSnapshot);
|
||||
return copy;
|
||||
}
|
||||
@@ -155,5 +197,16 @@ namespace KernelPanic.Combat
|
||||
IsLocked = false;
|
||||
ClearTargetSnapshot();
|
||||
}
|
||||
|
||||
// Only durable per-card values cross a repository checkpoint. Temporary combat state
|
||||
// is reset by the normal next-wave path, just as it is without suspending.
|
||||
internal void RestoreRunState(string instanceId, int costDelta, int magnitude, int drawRider, int level)
|
||||
{
|
||||
InstanceId = instanceId;
|
||||
PermanentCostDelta = costDelta;
|
||||
MagnitudeBonus = magnitude;
|
||||
DrawRider = drawRider;
|
||||
UpgradeLevel = level;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -40,5 +40,9 @@ namespace KernelPanic.Combat
|
||||
public IReadOnlyList<EnemyInstance> Enemies { get; }
|
||||
|
||||
internal bool SegfaultRecoilRolled { get; set; }
|
||||
public int LazyMultiplierPercent { get; internal set; } = 100;
|
||||
|
||||
public int ScaleExplicitShield(int amount) => CardScaling.Scale(amount,
|
||||
LazyMultiplierPercent, CombatManager?.Compilation.ShieldPercent ?? 100);
|
||||
}
|
||||
}
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
@@ -9,6 +9,8 @@ namespace KernelPanic.Combat
|
||||
public const int OpeningHandSize = 5;
|
||||
public const int DrawPerTurn = 1;
|
||||
public const int MinimumHandFloor = 0;
|
||||
public const int SegfaultCorruptionRecoveryRounds = 3;
|
||||
public const int OrphanSpawnChancePercent = 25;
|
||||
|
||||
public const int BaseEnemyUptimeMin = 5;
|
||||
public const int BaseEnemyUptimeMax = 10;
|
||||
|
||||
@@ -30,6 +30,8 @@ namespace KernelPanic.Combat
|
||||
public bool IgnoreDamageMultipliers { get; set; }
|
||||
public bool AllowFlatDamageBuffs { get; set; }
|
||||
public int FlatEffectBonus { get; set; }
|
||||
// Card-hit amounts only; never increases draw, Shield, healing or status stacks.
|
||||
public int FlatCardDamageBonus { get; set; }
|
||||
public int JavaScriptFlatDamageBonus { get; set; }
|
||||
public int DamageMultiplierPercent { get; set; } = 100;
|
||||
public int CurrentCardDamageMultiplierPercent { get; set; } = 100;
|
||||
|
||||
@@ -21,6 +21,39 @@ namespace KernelPanic.Combat
|
||||
TrueDamage = trueDamage;
|
||||
CanCrit = canCrit;
|
||||
ApplySourceModifiers = applySourceModifiers;
|
||||
LazyMultiplierPercent = 100;
|
||||
CompilationPercent = 100;
|
||||
IsCardDamage = false;
|
||||
Cause = null;
|
||||
}
|
||||
|
||||
// Explicit provenance: DOT, package damage, enemy damage, recoil and spill use the
|
||||
// original constructor, so none can inherit a card's execution modifiers accidentally.
|
||||
public static DamageRequest FromCard(CombatContext context, CombatantState target, int amount,
|
||||
Language language, bool trueDamage, bool canCrit) => new(
|
||||
new DamageRequest(context.Source, target, amount, language, trueDamage, canCrit), context);
|
||||
|
||||
private DamageRequest(DamageRequest request, CombatContext context)
|
||||
: this(request.Source, request.Target, request.Amount, request.Language, request.TrueDamage, request.CanCrit)
|
||||
{
|
||||
IsCardDamage = true;
|
||||
LazyMultiplierPercent = context.LazyMultiplierPercent;
|
||||
CompilationPercent = context.CombatManager?.Compilation.DamagePercent ?? 100;
|
||||
}
|
||||
|
||||
// Preview requests retain card provenance without executing a card or constructing a
|
||||
// mutable combat context. Multipliers describe the prospective execution snapshot.
|
||||
public static DamageRequest PreviewCard(CombatantState source, CombatantState target, int amount,
|
||||
Language language, bool trueDamage, bool canCrit, int lazyPercent, int compilationPercent) =>
|
||||
new(source, target, amount, language, trueDamage, canCrit, lazyPercent, compilationPercent);
|
||||
|
||||
private DamageRequest(CombatantState source, CombatantState target, int amount,
|
||||
Language language, bool trueDamage, bool canCrit, int lazyPercent, int compilationPercent)
|
||||
: this(source, target, amount, language, trueDamage, canCrit)
|
||||
{
|
||||
IsCardDamage = true;
|
||||
LazyMultiplierPercent = lazyPercent;
|
||||
CompilationPercent = compilationPercent;
|
||||
}
|
||||
|
||||
public CombatantState Source { get; }
|
||||
@@ -30,6 +63,22 @@ namespace KernelPanic.Combat
|
||||
public bool TrueDamage { get; }
|
||||
public bool CanCrit { get; }
|
||||
public bool ApplySourceModifiers { get; }
|
||||
public bool IsCardDamage { get; }
|
||||
public int LazyMultiplierPercent { get; }
|
||||
public int CompilationPercent { get; }
|
||||
public string Cause { get; }
|
||||
|
||||
public DamageRequest WithCause(string cause) => new(this, cause);
|
||||
|
||||
private DamageRequest(DamageRequest request, string cause)
|
||||
: this(request.Source, request.Target, request.Amount, request.Language, request.TrueDamage,
|
||||
request.CanCrit, request.ApplySourceModifiers)
|
||||
{
|
||||
IsCardDamage = request.IsCardDamage;
|
||||
LazyMultiplierPercent = request.LazyMultiplierPercent;
|
||||
CompilationPercent = request.CompilationPercent;
|
||||
Cause = cause;
|
||||
}
|
||||
}
|
||||
|
||||
public readonly struct DamageResult
|
||||
@@ -59,7 +108,34 @@ namespace KernelPanic.Combat
|
||||
/// </summary>
|
||||
public sealed class DamagePipeline
|
||||
{
|
||||
public System.Func<DamageRequest, int, int> ResistanceResolver { get; set; }
|
||||
private System.Func<DamageRequest, int, int> _resistanceResolver;
|
||||
public System.Func<DamageRequest, int, int> ResistanceResolver
|
||||
{
|
||||
get => _resistanceResolver;
|
||||
set
|
||||
{
|
||||
if (_resistanceResolver != value) PreviewResistanceResolver = null;
|
||||
_resistanceResolver = value;
|
||||
}
|
||||
}
|
||||
// Only explicitly pure resistance resolvers are usable by a read-only preview. Never
|
||||
// invoke the runtime delegate here: custom runtime hooks may consume resources.
|
||||
public System.Func<DamageRequest, int, int> PreviewResistanceResolver { get; set; }
|
||||
|
||||
public bool CanPreviewResistance => ResistanceResolver == null || PreviewResistanceResolver != null;
|
||||
|
||||
public int PreviewIncomingDamage(DamageRequest request, bool critical = false,
|
||||
int? archStacks = null, int? sourceMultiplierPercent = null, int? cardMultiplierPercent = null)
|
||||
{
|
||||
int amount = Mathf.Max(0, request.Amount);
|
||||
if (request.ApplySourceModifiers)
|
||||
{
|
||||
amount = ApplyFlatAdditions(amount, request, out _, archStacks);
|
||||
amount = ApplyMultipliers(amount, request, sourceMultiplierPercent, cardMultiplierPercent);
|
||||
if (critical && CanRollCritical(request, amount)) amount = ScaleCritical(amount);
|
||||
}
|
||||
return PreviewResistanceResolver == null ? amount : PreviewResistanceResolver(request, amount);
|
||||
}
|
||||
|
||||
public DamageResult DefeatCombatant(CombatantState target, CombatantState source, Language language)
|
||||
{
|
||||
@@ -98,7 +174,7 @@ namespace KernelPanic.Combat
|
||||
int finalAmount = ApplyShieldAndUptime(amount, request, out int absorbedAmount, out int shieldDamage, out int uptimeDamage);
|
||||
ApplyArchRollingReleaseSave(request);
|
||||
bool rollingReleaseSaveTriggered = request.Target != null && request.Target.ArchRollingReleaseRecoveredThisHit;
|
||||
GameEvents.RaiseDamageDealt(new DamageDealtEvent(request.Source, request.Target, finalAmount, request.Language, amount, absorbedAmount, wasCritical, shieldDamage, uptimeDamage, request.TrueDamage, archBtwBonus, rollingReleaseSaveTriggered));
|
||||
GameEvents.RaiseDamageDealt(new DamageDealtEvent(request.Source, request.Target, finalAmount, request.Language, amount, absorbedAmount, wasCritical, shieldDamage, uptimeDamage, request.TrueDamage, archBtwBonus, rollingReleaseSaveTriggered).WithCause(request.Cause));
|
||||
|
||||
bool defeated = false;
|
||||
if (request.Target.CurrentUptime <= 0 && !request.Target.IsDefeated)
|
||||
@@ -111,7 +187,8 @@ namespace KernelPanic.Combat
|
||||
return new DamageResult(finalAmount, defeated, wasCritical, absorbedAmount, shieldDamage, uptimeDamage, amount);
|
||||
}
|
||||
|
||||
private static int ApplyMultipliers(int amount, DamageRequest request)
|
||||
private static int ApplyMultipliers(int amount, DamageRequest request,
|
||||
int? sourceMultiplierPercent = null, int? cardMultiplierPercent = null)
|
||||
{
|
||||
if (amount == int.MaxValue)
|
||||
{
|
||||
@@ -125,12 +202,14 @@ namespace KernelPanic.Combat
|
||||
return amount;
|
||||
}
|
||||
|
||||
int multiplier = request.Source == null ? 100 : Mathf.Max(0, request.Source.DamageMultiplierPercent);
|
||||
int currentCardMultiplier = request.Source == null ? 100 : Mathf.Max(0, request.Source.CurrentCardDamageMultiplierPercent);
|
||||
int multiplier = Mathf.Max(0, sourceMultiplierPercent ?? request.Source?.DamageMultiplierPercent ?? 100);
|
||||
int currentCardMultiplier = Mathf.Max(0, cardMultiplierPercent ?? request.Source?.CurrentCardDamageMultiplierPercent ?? 100);
|
||||
if (request.IsCardDamage && (request.LazyMultiplierPercent != 100 || request.CompilationPercent != 100))
|
||||
return CardScaling.Scale(amount, request.LazyMultiplierPercent, request.CompilationPercent, multiplier, currentCardMultiplier);
|
||||
return Mathf.RoundToInt(amount * (multiplier / 100f) * (currentCardMultiplier / 100f));
|
||||
}
|
||||
|
||||
private static int ApplyFlatAdditions(int amount, DamageRequest request, out int archBtwBonus)
|
||||
private static int ApplyFlatAdditions(int amount, DamageRequest request, out int archBtwBonus, int? archStacks = null)
|
||||
{
|
||||
archBtwBonus = 0;
|
||||
if (amount == int.MaxValue)
|
||||
@@ -145,7 +224,7 @@ namespace KernelPanic.Combat
|
||||
|
||||
if (request.Source != null && (request.Language == Language.C || request.Language == Language.Rust))
|
||||
{
|
||||
archBtwBonus = Mathf.Max(0, request.Source.ArchBtwStacks) * Mathf.Max(1, request.Source.ArchBtwDamagePerStack);
|
||||
archBtwBonus = Mathf.Max(0, archStacks ?? request.Source.ArchBtwStacks) * Mathf.Max(1, request.Source.ArchBtwDamagePerStack);
|
||||
amount += archBtwBonus;
|
||||
}
|
||||
|
||||
@@ -155,16 +234,22 @@ namespace KernelPanic.Combat
|
||||
private static int ApplyCrit(int amount, DamageRequest request, out bool wasCritical)
|
||||
{
|
||||
wasCritical = false;
|
||||
if (!request.CanCrit || amount <= 0 || amount == int.MaxValue || request.Source != null && request.Source.ForceMaxRolls)
|
||||
if (!CanRollCritical(request, amount))
|
||||
{
|
||||
return amount;
|
||||
}
|
||||
|
||||
int critChance = request.Language == Language.C ? 50 : 25;
|
||||
wasCritical = RandomRoll.RollRange(1, 100, new RollContext(request.Source)) <= critChance;
|
||||
return wasCritical ? Mathf.CeilToInt(amount * 1.5f) : amount;
|
||||
return wasCritical ? ScaleCritical(amount) : amount;
|
||||
}
|
||||
|
||||
private static bool CanRollCritical(DamageRequest request, int amount) =>
|
||||
request.CanCrit && amount > 0 && amount != int.MaxValue && !(request.Source?.ForceMaxRolls ?? false);
|
||||
|
||||
private static int ScaleCritical(int amount) =>
|
||||
(int)System.Math.Min(int.MaxValue, ((long)amount * 3 + 1) / 2);
|
||||
|
||||
private static void ApplyArchRollingReleaseSave(DamageRequest request)
|
||||
{
|
||||
CombatantState target = request.Target;
|
||||
|
||||
@@ -70,6 +70,69 @@ namespace KernelPanic.Combat
|
||||
return drawn;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Moves the top card into the hand if its RAM cost fits. A blocked card remains on top,
|
||||
/// so callers should stop drawing on failure instead of skipping to cheaper cards.
|
||||
/// Reshuffles only when the draw pile is empty and the hand has room for a card.
|
||||
/// </summary>
|
||||
public bool TryDrawToHand(HandController hand, out CardInstance card)
|
||||
{
|
||||
card = null;
|
||||
if (hand == null || !TryPeekFittingTop(hand.RemainingRam, out CardInstance top) || !hand.Add(top))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
_drawPile.RemoveAt(_drawPile.Count - 1);
|
||||
card = top;
|
||||
return true;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Reserves a RAM-fitting batch in draw order before presentation yields. Stops at the first
|
||||
/// blocked top card; cards discarded after this call cannot join the reserved batch.
|
||||
/// </summary>
|
||||
public IReadOnlyList<CardInstance> DrawFittingCards(int count, int availableRam)
|
||||
{
|
||||
List<CardInstance> drawn = new();
|
||||
while (drawn.Count < count && TryPeekFittingTop(availableRam, out CardInstance card))
|
||||
{
|
||||
_drawPile.RemoveAt(_drawPile.Count - 1);
|
||||
drawn.Add(card);
|
||||
availableRam -= HandController.GetRamCost(card);
|
||||
}
|
||||
|
||||
return drawn;
|
||||
}
|
||||
|
||||
private bool TryPeekFittingTop(int availableRam, out CardInstance card)
|
||||
{
|
||||
card = null;
|
||||
if (availableRam <= 0)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
if (_drawPile.Count == 0)
|
||||
{
|
||||
ReshuffleDiscardIntoDraw();
|
||||
}
|
||||
|
||||
if (_drawPile.Count == 0)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
CardInstance top = _drawPile[_drawPile.Count - 1];
|
||||
if (HandController.GetRamCost(top) > availableRam)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
card = top;
|
||||
return true;
|
||||
}
|
||||
|
||||
public bool TryDrawCheapestFromTop(int lookCount, out CardInstance card, out IReadOnlyList<PeekedCardInfo> peeked, out bool wasTie)
|
||||
{
|
||||
card = null;
|
||||
|
||||
@@ -22,13 +22,15 @@ namespace KernelPanic.Combat
|
||||
Elite = 1 << 10,
|
||||
RamPressure = 1 << 11,
|
||||
TelemetryCollector = 1 << 12,
|
||||
CardLocker = 1 << 13
|
||||
CardLocker = 1 << 13,
|
||||
BossCycle = 1 << 14
|
||||
}
|
||||
|
||||
public enum EnemyTier
|
||||
{
|
||||
Fodder,
|
||||
Elite
|
||||
Elite,
|
||||
Boss
|
||||
}
|
||||
|
||||
public sealed class EnemyArchetypeDescriptor
|
||||
@@ -228,10 +230,20 @@ namespace KernelPanic.Combat
|
||||
},
|
||||
EnemyTier.Elite);
|
||||
|
||||
private static readonly EnemyArchetypeDescriptor KernelOverseer = new(
|
||||
"kernel_overseer", "Kernel Overseer", 38, 38, EnemyBehaviorFlags.BossCycle,
|
||||
new[]
|
||||
{
|
||||
new EnemyIntent(EnemyIntentKind.Defend, 6, 6, Language.C, "rebuild firewall", "#"),
|
||||
new EnemyIntent(EnemyIntentKind.Attack, 5, 5, Language.C, "probe", "!"),
|
||||
new EnemyIntent(EnemyIntentKind.Attack, 10, 10, Language.C, "heavy interrupt", "!!")
|
||||
}, EnemyTier.Boss);
|
||||
|
||||
public static EnemyArchetypeDescriptor Get(string id)
|
||||
{
|
||||
return id switch
|
||||
{
|
||||
"kernel_overseer" => KernelOverseer,
|
||||
"memory_leak" => MemoryLeak,
|
||||
"fork_bomb" => ForkBomb,
|
||||
"daemon" => Daemon,
|
||||
|
||||
@@ -3,7 +3,7 @@ using System.Collections.Generic;
|
||||
namespace KernelPanic.Combat
|
||||
{
|
||||
/// <summary>
|
||||
/// Runtime-only enemy placeholder used until encounter and EnemyDefinition assets are wired.
|
||||
/// Runtime enemy state and announced intent selection.
|
||||
/// </summary>
|
||||
public sealed class EnemyInstance
|
||||
{
|
||||
@@ -64,6 +64,14 @@ namespace KernelPanic.Combat
|
||||
|
||||
public void PickNextIntent()
|
||||
{
|
||||
if (HasBehavior(EnemyBehaviorFlags.BossCycle) && _intentPool.Count > 0)
|
||||
{
|
||||
CurrentIntent = _intentPool[TurnsAlive % _intentPool.Count];
|
||||
if (State.CurrentUptime <= State.MaxUptime / 2 && CurrentIntent.Kind == EnemyIntentKind.Attack)
|
||||
CurrentIntent = CurrentIntent.WithValues(CurrentIntent.MinValue + 3, CurrentIntent.MaxValue + 3,
|
||||
"overclocked " + CurrentIntent.DisplayLabel);
|
||||
return;
|
||||
}
|
||||
if (PendingRevive)
|
||||
{
|
||||
CurrentIntent = new EnemyIntent(EnemyIntentKind.Special, 0, 0, KernelPanic.Core.Language.C, "reviving", "~", false, KernelPanic.Core.StatusType.MemoryLeak, 0, -1, "next");
|
||||
|
||||
@@ -1,55 +1,70 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using KernelPanic.Core;
|
||||
|
||||
namespace KernelPanic.Combat
|
||||
{
|
||||
/// <summary>
|
||||
/// Stores played cards in LIFO order until explicitly force-evaluated.
|
||||
/// </summary>
|
||||
/// <summary>Immutable execution snapshot, owned by an enqueue, never by a clonable card.</summary>
|
||||
public sealed class LazyStackEntry
|
||||
{
|
||||
public CardInstance Card { get; }
|
||||
public int MultiplierPercent { get; }
|
||||
public IReadOnlyList<CombatantState> Targets { get; }
|
||||
public string MultiplierLabel => $"x{MultiplierPercent / 100}.{MultiplierPercent % 100 / 10}";
|
||||
internal LazyStackEntry(CardInstance card, int multiplierPercent)
|
||||
{
|
||||
Card = card;
|
||||
MultiplierPercent = multiplierPercent;
|
||||
Targets = Array.AsReadOnly(card.TargetSnapshot.ToArray());
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>Top-first immutable snapshots. CombatManager alone executes/disposes cards.</summary>
|
||||
public sealed class LazyStack : IResolutionTrack
|
||||
{
|
||||
private readonly Stack<CardInstance> _stackedCards = new();
|
||||
private readonly List<CardInstance> _stackedView = new();
|
||||
|
||||
public int Count => _stackedCards.Count;
|
||||
public IReadOnlyList<CardInstance> Cards => _stackedView;
|
||||
private readonly List<LazyStackEntry> _entries = new();
|
||||
private readonly List<CardInstance> _cards = new();
|
||||
public int Count => _entries.Count;
|
||||
public IReadOnlyList<CardInstance> Cards => _cards.AsReadOnly();
|
||||
public IReadOnlyList<LazyStackEntry> Entries => _entries.AsReadOnly();
|
||||
|
||||
public void Enqueue(CardInstance card)
|
||||
{
|
||||
if (card == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
_stackedCards.Push(card);
|
||||
_stackedView.Insert(0, card);
|
||||
if (card == null || _cards.Contains(card)) return;
|
||||
int multiplier = 100;
|
||||
if (card.Definition != null && card.Definition.Language == Language.Haskell)
|
||||
multiplier = 100 + 50 * Math.Min(3, _entries.Count(e => e.Card.Definition != null && e.Card.Definition.Language == Language.Haskell));
|
||||
_entries.Insert(0, new LazyStackEntry(card, multiplier));
|
||||
_cards.Insert(0, card);
|
||||
}
|
||||
|
||||
public void Resolve(CombatContext context)
|
||||
{
|
||||
ForceEvaluate(context);
|
||||
}
|
||||
public void Resolve(CombatContext context) => ForceEvaluate(context);
|
||||
public void ForceEvaluate(CombatContext context) => context?.CombatManager?.EvaluateLazyStack();
|
||||
|
||||
public void ForceEvaluate(CombatContext context)
|
||||
public bool TryPopEntry(out LazyStackEntry entry)
|
||||
{
|
||||
while (TryPop(out CardInstance card))
|
||||
{
|
||||
GameEvents.RaiseCardResolved(new CardResolvedEvent(card, ResolutionTrack.LazyStack));
|
||||
}
|
||||
entry = null;
|
||||
if (_entries.Count == 0) return false;
|
||||
entry = _entries[0];
|
||||
_entries.RemoveAt(0);
|
||||
_cards.RemoveAt(0);
|
||||
return true;
|
||||
}
|
||||
|
||||
public bool TryPop(out CardInstance card)
|
||||
{
|
||||
if (_stackedCards.Count == 0)
|
||||
{
|
||||
card = null;
|
||||
return false;
|
||||
}
|
||||
bool popped = TryPopEntry(out var entry);
|
||||
card = entry?.Card;
|
||||
if (popped) GameEvents.RaiseCardResolving(new CardResolvedEvent(card, ResolutionTrack.LazyStack));
|
||||
return popped;
|
||||
}
|
||||
|
||||
card = _stackedCards.Pop();
|
||||
_stackedView.Remove(card);
|
||||
GameEvents.RaiseCardResolving(new CardResolvedEvent(card, ResolutionTrack.LazyStack));
|
||||
return true;
|
||||
public void Clear()
|
||||
{
|
||||
foreach (var card in _cards) card.SetTargetSnapshot(Array.Empty<CombatantState>());
|
||||
_entries.Clear();
|
||||
_cards.Clear();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -22,10 +22,22 @@ namespace KernelPanic.Combat
|
||||
public static class RandomRoll
|
||||
{
|
||||
private static Random _random = new(0);
|
||||
public static int CurrentSeed { get; private set; }
|
||||
public static int DrawCount { get; private set; }
|
||||
|
||||
public static void Seed(int seed)
|
||||
{
|
||||
_random = new Random(seed);
|
||||
CurrentSeed = seed;
|
||||
DrawCount = 0;
|
||||
}
|
||||
|
||||
public static void Restore(int seed, int draws)
|
||||
{
|
||||
if (draws < 0 || draws > 10000000) throw new ArgumentOutOfRangeException(nameof(draws));
|
||||
Seed(seed);
|
||||
for (int i = 0; i < draws; i++) _random.Next();
|
||||
DrawCount = draws;
|
||||
}
|
||||
|
||||
public static int RollRange(int min, int max, RollContext context)
|
||||
@@ -41,7 +53,9 @@ namespace KernelPanic.Combat
|
||||
return max;
|
||||
}
|
||||
|
||||
return _random.Next(min, max + 1);
|
||||
int value = _random.Next(min, max + 1);
|
||||
DrawCount += (long)max + 1 - min > int.MaxValue ? 2 : 1;
|
||||
return value;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -13,7 +13,7 @@ namespace KernelPanic.Combat
|
||||
private static readonly Dictionary<StatusType, StatusDescriptor> Descriptors = new()
|
||||
{
|
||||
[StatusType.MemoryLeak] = new(StatusType.MemoryLeak, "Memory Leak", "leak", false, StatusStackingRule.Intensity, StatusTickTiming.StartOfTurn, "Takes damage equal to stacks at start of turn."),
|
||||
[StatusType.Segfault] = new(StatusType.Segfault, "Segfault", "segv", false, StatusStackingRule.Unique, StatusTickTiming.StartOfTurn, "Loses one cycle this turn. Segfault events corrupt a random hand card until fixed."),
|
||||
[StatusType.Segfault] = new(StatusType.Segfault, "Segfault", "segv", false, StatusStackingRule.Unique, StatusTickTiming.StartOfTurn, "Loses one cycle this turn. Segfault events corrupt a random hand card; that card recovers automatically after 3 rounds, or sooner with repair."),
|
||||
[StatusType.RaceCondition] = new(StatusType.RaceCondition, "Race Condition", "race", false, StatusStackingRule.Refresh, StatusTickTiming.None, "Randomizes multi-target resolution order where supported."),
|
||||
[StatusType.Deprecated] = new(StatusType.Deprecated, "Deprecated", "dep", false, StatusStackingRule.Duration, StatusTickTiming.StartOfTurn, "A temporary positive value decays. Currently reduces shield by 1."),
|
||||
[StatusType.DependencyError] = new(StatusType.DependencyError, "Dependency Error", "deps", false, StatusStackingRule.Unique, StatusTickTiming.None, "Registered for off-support card cost rules. TODO: connect draw-time cost path."),
|
||||
@@ -176,7 +176,8 @@ namespace KernelPanic.Combat
|
||||
switch (status.Type)
|
||||
{
|
||||
case StatusType.MemoryLeak:
|
||||
damagePipeline.DealDamage(new DamageRequest(source, target, status.Stacks, Language.C, false, false));
|
||||
damagePipeline.DealDamage(new DamageRequest(source, target, status.Stacks, Language.C, false, false)
|
||||
.WithCause("Memory Leak status tick"));
|
||||
break;
|
||||
case StatusType.Segfault:
|
||||
target.Cycles = Mathf.Max(0, target.Cycles - 1);
|
||||
|
||||
Reference in New Issue
Block a user