Refactor alot of stuff
This commit is contained in:
@@ -0,0 +1,94 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using KernelPanic.Combat;
|
||||
using KernelPanic.Data;
|
||||
using KernelPanic.Run;
|
||||
using UnityEngine.UIElements;
|
||||
|
||||
namespace KernelPanic.UI
|
||||
{
|
||||
/// <summary>Durable deck composition, independent of current combat buffs or random outcomes.</summary>
|
||||
public static class DeckAnalysisView
|
||||
{
|
||||
public static VisualElement Build(IReadOnlyList<CardInstance> deck)
|
||||
{
|
||||
var panel = new Foldout { text = $"installed deck / {deck.Count} cards", value = false, name = "DeckAnalysis" };
|
||||
panel.AddToClassList("repository-remove");
|
||||
panel.Add(TerminalLayout.BodyText(Summary(deck)));
|
||||
panel.Add(TerminalLayout.BodyText("Permanent costs. Roles overlap; combat buffs and discounts vary."));
|
||||
return panel;
|
||||
}
|
||||
|
||||
public static string Summary(IEnumerable<CardInstance> deck)
|
||||
{
|
||||
var cards = deck.Where(c => c?.Definition != null).ToArray();
|
||||
int Cost(CardInstance c) => Math.Max(0, c.Definition.CycleCost + c.PermanentCostDelta);
|
||||
string curve = string.Join(" | ", Enumerable.Range(0, 5).Select(n =>
|
||||
$"{(n == 4 ? "4+" : n.ToString())}: {cards.Count(c => n == 4 ? Cost(c) >= 4 : Cost(c) == n)}"));
|
||||
int damage = 0, defense = 0, utility = 0;
|
||||
foreach (var card in cards)
|
||||
{
|
||||
var roles = Roles(card);
|
||||
if (roles.damage) damage++;
|
||||
if (roles.defense) defense++;
|
||||
if (roles.utility) utility++;
|
||||
}
|
||||
return "Cycles curve / " + curve
|
||||
+ "\nRAM / " + string.Join(" | ", cards.GroupBy(HandController.GetRamCost).OrderBy(g => g.Key).Select(g => $"{g.Key} RAM: {g.Count()}"))
|
||||
+ $"\nRoles / damage {damage} | defense {defense} | utility/setup {utility}"
|
||||
+ "\nLanguages / " + string.Join(" | ", cards.GroupBy(c => c.Definition.Language).OrderBy(g => g.Key.ToString()).Select(g => $"{LanguageCatalog.Get(g.Key).DisplayName}: {g.Count()}"));
|
||||
}
|
||||
|
||||
public static (bool damage, bool defense, bool utility) Roles(CardInstance card)
|
||||
{
|
||||
if (!CardCatalog.TryGet(card.Definition.Id, out var entry) || card.Definition.Effects.Any(e => e != null))
|
||||
return (false, false, true);
|
||||
bool damage = false, defense = false, utility = card.DrawRider > 0;
|
||||
foreach (var effect in entry.Effects)
|
||||
{
|
||||
switch (effect.Kind)
|
||||
{
|
||||
case CardEffectKind.Damage: case CardEffectKind.ChanceDamage: case CardEffectKind.PreviousLanguageDamage:
|
||||
case CardEffectKind.QueuedGrowthDamage: case CardEffectKind.BtwScaledDamage: case CardEffectKind.SizeofDamage:
|
||||
case CardEffectKind.ShieldRepeatDamage: damage = true; break;
|
||||
case CardEffectKind.Shield: case CardEffectKind.IncomingAttackHalve: defense = true; break;
|
||||
case CardEffectKind.Python:
|
||||
var python = (PythonOperation)effect.SecondaryAmount;
|
||||
damage |= python is PythonOperation.Print or PythonOperation.List or PythonOperation.Update or PythonOperation.Zip;
|
||||
defense |= python is PythonOperation.Shield or PythonOperation.Cinnamon or PythonOperation.Loop or PythonOperation.Unattended or PythonOperation.Timeshift;
|
||||
utility |= python is not (PythonOperation.Print or PythonOperation.List or PythonOperation.Shield);
|
||||
break;
|
||||
case CardEffectKind.Go:
|
||||
var go = (GoOperation)effect.SecondaryAmount;
|
||||
damage |= go is GoOperation.Deploy or GoOperation.Select;
|
||||
defense |= go is GoOperation.WaitGroup or GoOperation.Cancel or GoOperation.Gosched or GoOperation.Rollback;
|
||||
utility |= go != GoOperation.Deploy;
|
||||
break;
|
||||
default: utility = true; break;
|
||||
}
|
||||
}
|
||||
return (damage, defense, utility);
|
||||
}
|
||||
|
||||
public static string UpgradeComparison(RepositoryOffer offer, RunConfig config)
|
||||
{
|
||||
if (offer.TargetCard?.Definition == null) return offer.Description;
|
||||
var before = offer.TargetCard;
|
||||
if (offer.Sold) return "Installed. " + CardEffectFactory.GetRulesText(before, config);
|
||||
var after = before.CopyForCombat();
|
||||
after.TemporaryCostDelta = 0;
|
||||
switch (offer.CardUpgradeKind)
|
||||
{
|
||||
case CardUpgradeKind.CostDown: after.ApplyCostUpgrade(-1); break;
|
||||
case CardUpgradeKind.MagnitudeUp: after.ApplyMagnitudeUpgrade(CombatTuning.UpgradeMagnitudeBonus); break;
|
||||
case CardUpgradeKind.DrawRider: after.ApplyDrawRider(1); break;
|
||||
}
|
||||
return $"Cycles: {Math.Max(0, before.Definition.CycleCost + before.PermanentCostDelta)} -> {Math.Max(0, after.Definition.CycleCost + after.PermanentCostDelta)}"
|
||||
+ $"\nMagnitude bonus: +{before.MagnitudeBonus} -> +{after.MagnitudeBonus}"
|
||||
+ $"\nDraw rider: {before.DrawRider} -> {after.DrawRider}"
|
||||
+ "\nBefore: " + CardEffectFactory.GetRulesText(before, config)
|
||||
+ "\nAfter: " + CardEffectFactory.GetRulesText(after, config);
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user