Refactor alot of stuff

This commit is contained in:
2026-10-29 22:54:29 +01:00
parent c23b666ee4
commit 260abc2c98
138 changed files with 2835 additions and 466 deletions
+33 -1
View File
@@ -91,6 +91,32 @@ namespace KernelPanic.Combat
: $"{s.Name}{(s.Name == "async def" ? " / " + s.Payload.Card.Definition.DisplayName : "")}: {s.Remaining} runs remaining"));
public void Bind(CombatManager combat) => _combat = combat;
internal SavedPython CaptureSnapshot(CombatSnapshotWriter writer)
{
var state = new SavedPython { round = _round, damage = DamageThisPhase, automated = AutomationRan,
loops = new List<int>(_loops), areas = new List<int>(_areas) };
foreach (var entry in _temporaryDiscounts) state.discounts.Add(new SavedDiscount { card = writer.Card(entry.Key), cost = entry.Value });
foreach (var script in _scripts)
state.scripts.Add(new SavedScript { name = script.Name, owner = writer.Card(script.Owner), waiting = script.Waiting,
restore = script.Restore, firstRound = script.FirstRound, remaining = script.Remaining, uptime = script.Uptime, lastRunRound = script.LastRunRound, hasPayload = script.Payload != null,
payload = script.Payload == null ? null : new SavedPayload { card = writer.Card(script.Payload.Card), damage = script.Payload.Damage,
shield = script.Payload.Shield, all = script.Payload.All, target = writer.State(script.Payload.Target) } });
return state;
}
internal void RestoreSnapshot(SavedPython state, CombatSnapshotGraph graph)
{
_choose = null; _afterChoice = null; Choices = Array.Empty<PythonChoiceOption>(); ChoiceTitle = null;
_round = state.round; DamageThisPhase = state.damage; AutomationRan = state.automated;
_loops.Clear(); _loops.AddRange(state.loops); _areas.Clear(); _areas.AddRange(state.areas);
_temporaryDiscounts.Clear();
foreach (var entry in state.discounts) _temporaryDiscounts.Add(graph.Cards[entry.card], entry.cost);
_scripts.Clear();
foreach (var script in state.scripts)
_scripts.Add(new Script { Name = script.name, Owner = graph.Cards[script.owner], Waiting = script.waiting,
Restore = script.restore, FirstRound = script.firstRound, Remaining = script.remaining, Uptime = script.uptime, LastRunRound = script.lastRunRound,
Payload = script.payload == null ? null : new Payload { Card = graph.Cards[script.payload.card], Damage = script.payload.damage,
Shield = script.payload.shield, All = script.payload.all, Target = graph.State(script.payload.target) } });
}
public void Clear()
{
ExpireDiscounts();
@@ -103,6 +129,12 @@ namespace KernelPanic.Combat
foreach (var entry in _temporaryDiscounts) entry.Key.TemporaryCostDelta = entry.Value;
_temporaryDiscounts.Clear();
}
internal void DiscountForTurn(CardInstance card, int amount)
{
if (amount <= 0) return;
if (!_temporaryDiscounts.ContainsKey(card)) _temporaryDiscounts[card] = card.TemporaryCostDelta;
card.TemporaryCostDelta -= amount;
}
public bool Choose(int index)
{
if (!HasChoice || index < 0 || index >= Choices.Count || !Choices[index].Enabled) return false;
@@ -120,7 +152,7 @@ namespace KernelPanic.Combat
if (HasChoice) _afterChoice += action;
else action();
}
private void Offer(string title, IEnumerable<PythonChoiceOption> options, Action<int> choose)
internal void Offer(string title, IEnumerable<PythonChoiceOption> options, Action<int> choose)
{
if (HasChoice) throw new InvalidOperationException("Resolve the current Python choice first.");
ChoiceTitle = title; Choices = Array.AsReadOnly(options.ToArray()); _choose = choose;