192 lines
7.8 KiB
C#
192 lines
7.8 KiB
C#
using System;
|
|
using System.Collections.Generic;
|
|
using System.Linq;
|
|
using System.Reflection;
|
|
using KernelPanic.Combat;
|
|
using KernelPanic.Core;
|
|
using KernelPanic.Data;
|
|
using KernelPanic.Meta;
|
|
using KernelPanic.Run;
|
|
using NUnit.Framework;
|
|
using UnityEditor;
|
|
using UnityEngine;
|
|
|
|
public class PileCostDetailsTests
|
|
{
|
|
private const BindingFlags Private = BindingFlags.Instance | BindingFlags.NonPublic;
|
|
private readonly List<UnityEngine.Object> _temporary = new();
|
|
private GameObject _owner;
|
|
private CombatManager _combat;
|
|
|
|
private static void Set(object target, string field, object value) =>
|
|
target.GetType().GetField(field, Private).SetValue(target, value);
|
|
|
|
[SetUp]
|
|
public void SetUp()
|
|
{
|
|
_owner = new GameObject("Pile cost details tests");
|
|
_combat = _owner.AddComponent<CombatManager>();
|
|
Configure("Gentoo");
|
|
}
|
|
|
|
[TearDown]
|
|
public void TearDown()
|
|
{
|
|
UnityEngine.Object.DestroyImmediate(_owner);
|
|
foreach (var item in _temporary) UnityEngine.Object.DestroyImmediate(item);
|
|
_temporary.Clear();
|
|
}
|
|
|
|
private void Configure(string distro, params string[] packageIds)
|
|
{
|
|
var definition = AssetDatabase.LoadAssetAtPath<DistroDefinition>($"Assets/Data/Distros/{distro}.asset");
|
|
var packages = AssetDatabase.LoadAssetAtPath<PackageDatabase>("Assets/Data/Packages/PackageDatabase.asset");
|
|
var config = new RunConfig(definition, Language.C, Language.Java, Array.Empty<CardDefinition>(),
|
|
packageIds.Select(id => new PackageInstance(packages.FindById(id), 0)).ToArray(), 19, 3);
|
|
Set(_combat, "_runConfig", config);
|
|
Set(_combat, "_playerState", new CombatantState(60, 10, 3));
|
|
Set(_combat, "_handController", new HandController(10));
|
|
}
|
|
|
|
private CardInstance Card(int cost = 3, string id = "pile_cost_test", Language language = Language.C,
|
|
bool token = false, bool junk = false)
|
|
{
|
|
var definition = ScriptableObject.CreateInstance<CardDefinition>();
|
|
_temporary.Add(definition);
|
|
Set(definition, "id", id);
|
|
Set(definition, "cycleCost", cost);
|
|
Set(definition, "language", language);
|
|
Set(definition, "resolutionTrack", ResolutionTrack.Native);
|
|
Set(definition, "isToken", token);
|
|
Set(definition, "isJunk", junk);
|
|
return new CardInstance(definition);
|
|
}
|
|
|
|
[Test]
|
|
public void MissingCardsHaveNoMisleadingZeroCostEstimate()
|
|
{
|
|
Assert.That(_combat.GetPileCostDetails(null), Is.Empty);
|
|
Assert.That(_combat.GetPileCostDetails(new CardInstance(null)), Is.Empty);
|
|
}
|
|
|
|
[Test]
|
|
public void StoredCostIncludesPermanentAndTemporaryCardAdjustments()
|
|
{
|
|
var card = Card(6);
|
|
card.ApplyCostUpgrade(-1);
|
|
card.TemporaryCostDelta = -1;
|
|
|
|
string details = _combat.GetPileCostDetails(card);
|
|
|
|
Assert.That(details, Does.Contain("Current estimate: 4 Cycles (stored 4, base 6)")
|
|
.And.Contain("upgrades: -1").And.Contain("temporary: -1"));
|
|
Assert.That(details, Does.Contain("current hand and ready discounts")
|
|
.And.Contain("Drawing or playing cards can change it"));
|
|
}
|
|
|
|
[Test]
|
|
public void CostsRemainClampedToZeroInPileDetails()
|
|
{
|
|
var card = Card(1);
|
|
card.TemporaryCostDelta = -5;
|
|
Assert.That(_combat.GetPileCostDetails(card), Does.Contain("Current estimate: 0 Cycles (stored 0, base 1)"));
|
|
}
|
|
|
|
[Test]
|
|
public void CurrentEstimateExplainsJavaPackageAndFedoraDiscountsWithoutConsumingThem()
|
|
{
|
|
Configure("Fedora", "pkg_gentoo_ccache");
|
|
var card = Card(5, "lang_java_public_static_main", Language.Java);
|
|
card.ApplyCostUpgrade(-1);
|
|
card.TemporaryCostDelta = -1;
|
|
Set(_combat, "_javaCardsPlayedThisCombat", 2);
|
|
int seed = RandomRoll.CurrentSeed, draws = RandomRoll.DrawCount;
|
|
var random = UnityEngine.Random.state;
|
|
int cycles = _combat.PlayerState.Cycles, shield = _combat.PlayerState.Shield;
|
|
int events = 0;
|
|
_combat.PackageActivated += _ => events++;
|
|
|
|
for (int i = 0; i < 20; i++)
|
|
{
|
|
string details = _combat.GetPileCostDetails(card);
|
|
Assert.That(details, Does.Contain("Current estimate: 0 Cycles (stored 3, base 5)")
|
|
.And.Contain("upgrades: -1").And.Contain("temporary: -1")
|
|
.And.Contain("Java warmup: -1").And.Contain("ccache: -1").And.Contain("Bleeding Edge: -1"));
|
|
}
|
|
|
|
Assert.That(RandomRoll.CurrentSeed, Is.EqualTo(seed));
|
|
Assert.That(RandomRoll.DrawCount, Is.EqualTo(draws));
|
|
Assert.That(UnityEngine.Random.state, Is.EqualTo(random));
|
|
Assert.That(_combat.PlayerState.Cycles, Is.EqualTo(cycles));
|
|
Assert.That(_combat.PlayerState.Shield, Is.EqualTo(shield));
|
|
Assert.That(_combat.CardsPlayedThisRound, Is.Zero);
|
|
Assert.That(_combat.HandController.Cards, Is.Empty, "A pile cost query must not stage the card in hand.");
|
|
Assert.That(card.QueuePlayCount, Is.Zero);
|
|
Assert.That(card.TemporaryCostDelta, Is.EqualTo(-1));
|
|
Assert.That(card.PermanentCostDelta, Is.EqualTo(-1));
|
|
Assert.That(events, Is.Zero);
|
|
}
|
|
|
|
[Test]
|
|
public void CurrentEstimateChangesWhenFirstCardDiscountIsNoLongerReady()
|
|
{
|
|
Configure("Gentoo", "pkg_gentoo_ccache");
|
|
var card = Card(3);
|
|
Assert.That(_combat.GetPileCostDetails(card), Does.Contain("Current estimate: 2 Cycles (stored 3")
|
|
.And.Contain("ccache: -1"));
|
|
|
|
Set(_combat, "_cardsPlayedThisTurn", 1);
|
|
|
|
Assert.That(_combat.GetPileCostDetails(card), Does.Contain("Current estimate: 3 Cycles (stored 3")
|
|
.And.Not.Contain("ccache: -1"));
|
|
}
|
|
|
|
[Test]
|
|
public void AutoremoveEstimateUsesCurrentHandWithoutInventingFutureJunk()
|
|
{
|
|
Configure("Fedora");
|
|
var card = Card(3, "fedora_dnf_autoremove", Language.Rust);
|
|
Assert.That(_combat.GetPileCostDetails(card), Does.Contain("Current estimate: 3 Cycles")
|
|
.And.Not.Contain("Bleeding Edge"));
|
|
|
|
var junk = Card(0, "junk", token: true, junk: true);
|
|
_combat.HandController.Add(junk);
|
|
Assert.That(_combat.GetPileCostDetails(card), Does.Contain("Current estimate: 2 Cycles")
|
|
.And.Contain("Bleeding Edge: -1").And.Contain("current hand"));
|
|
Assert.That(_combat.HandController.Cards, Is.EqualTo(new[] { junk }));
|
|
|
|
_combat.HandController.Remove(junk);
|
|
Assert.That(_combat.GetPileCostDetails(card), Does.Contain("Current estimate: 3 Cycles"));
|
|
}
|
|
|
|
[Test]
|
|
public void ConsultWikiEstimateReflectsCurrentBrokenHandWithoutRepairingIt()
|
|
{
|
|
Configure("Fedora");
|
|
var card = Card(3, "arch_consult_wiki");
|
|
Assert.That(_combat.GetPileCostDetails(card), Does.Contain("Current estimate: 2 Cycles"));
|
|
var broken = Card();
|
|
broken.IsBroken = true;
|
|
_combat.HandController.Add(broken);
|
|
|
|
Assert.That(_combat.GetPileCostDetails(card), Does.Contain("Current estimate: 3 Cycles")
|
|
.And.Not.Contain("Bleeding Edge"));
|
|
Assert.That(broken.IsBroken, Is.True);
|
|
Assert.That(_combat.HandController.Cards, Is.EqualTo(new[] { broken }));
|
|
}
|
|
|
|
[TestCase(true, false, false, "Unplayable token")]
|
|
[TestCase(false, true, false, "Corrupted: cannot play")]
|
|
[TestCase(false, false, true, "Locked: unlocking costs 1 extra Cycle in hand")]
|
|
public void RestrictionsAreSeparateFromQuotedCycleCost(bool token, bool broken, bool locked, string expected)
|
|
{
|
|
var card = Card(0, token: token);
|
|
card.IsBroken = broken;
|
|
card.IsLocked = locked;
|
|
string details = _combat.GetPileCostDetails(card);
|
|
Assert.That(details, Does.Contain("Current estimate: 0 Cycles").And.Contain(expected));
|
|
Assert.That(card.IsBroken, Is.EqualTo(broken));
|
|
Assert.That(card.IsLocked, Is.EqualTo(locked));
|
|
}
|
|
}
|