712 lines
34 KiB
C#
712 lines
34 KiB
C#
using System;
|
|
using System.Collections;
|
|
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 KernelPanic.UI;
|
|
using NUnit.Framework;
|
|
using UnityEditor;
|
|
using UnityEngine;
|
|
using UnityEngine.TestTools;
|
|
using UnityEngine.UIElements;
|
|
|
|
public class GentooHaskellTests
|
|
{
|
|
const BindingFlags Private = BindingFlags.Instance | BindingFlags.NonPublic;
|
|
GameObject _owner;
|
|
CombatManager _combat;
|
|
RunManager _run;
|
|
CardDatabase _cards;
|
|
DistroDefinition _gentoo;
|
|
UnityEngine.Random.State _random;
|
|
bool _motion;
|
|
static object Call(object owner, string method, params object[] args) => owner.GetType().GetMethod(method, Private).Invoke(owner, args);
|
|
static void Set(object owner, string field, object value) => owner.GetType().GetField(field, Private).SetValue(owner, value);
|
|
static T Asset<T>(string path) where T : UnityEngine.Object => AssetDatabase.LoadAssetAtPath<T>(path);
|
|
CardInstance Card(string id) { var def = _cards.FindById(id); Assert.That(def, Is.Not.Null, id); return new CardInstance(def); }
|
|
CombatantState Player => _combat.PlayerState;
|
|
EnemyInstance Target => _combat.Enemies[0];
|
|
|
|
[SetUp]
|
|
public void SetUp()
|
|
{
|
|
_random = UnityEngine.Random.state;
|
|
_motion = UIPreferences.ReducedMotion;
|
|
UIPreferences.ReducedMotion = true;
|
|
_cards = Asset<CardDatabase>("Assets/Data/Cards/CardDatabase.asset");
|
|
_gentoo = Asset<DistroDefinition>("Assets/Data/Distros/Gentoo.asset");
|
|
Assert.That(_gentoo, Is.Not.Null);
|
|
_owner = new GameObject("Gentoo Haskell integration");
|
|
_run = _owner.AddComponent<RunManager>();
|
|
_combat = _owner.AddComponent<CombatManager>();
|
|
Call(_combat, "OnDisable"); Call(_combat, "Awake"); Call(_combat, "OnEnable");
|
|
Configure(1);
|
|
AddEnemy("memory_leak", 10000);
|
|
}
|
|
|
|
void Configure(int version, DistroDefinition distro = null, params PackageInstance[] packages)
|
|
{
|
|
var config = new RunConfig(distro ?? _gentoo, Language.Haskell, Language.C,
|
|
_gentoo.ExclusiveCards.Take(4).ToArray(), packages, 17, version);
|
|
_run.StartRun(config);
|
|
Set(_combat, "_runConfig", config);
|
|
Set(_combat, "_runManager", _run);
|
|
Set(_combat, "_playerState", new CombatantState(55, 32, 100));
|
|
Set(_combat, "_handController", new HandController(32));
|
|
Set(_combat, "currentPhase", TurnPhase.Execute);
|
|
Call(_combat, "ApplyVersionState", Player);
|
|
Call(_combat, "ApplyPackageState", Player);
|
|
Player.ForceMaxRolls = true; // No crit/recoil; does NOT bypass damage modifiers.
|
|
_combat.Compilation.BeginWave(distro == null || distro.Id == "gentoo" ? version : 0);
|
|
}
|
|
|
|
[TearDown]
|
|
public void TearDown()
|
|
{
|
|
if (_combat != null) Call(_combat, "OnDisable");
|
|
UnityEngine.Object.DestroyImmediate(_owner);
|
|
UnityEngine.Random.state = _random;
|
|
UIPreferences.ReducedMotion = _motion;
|
|
}
|
|
|
|
EnemyInstance AddEnemy(string id, int hp)
|
|
{
|
|
var enemy = new EnemyInstance(EnemyArchetypeCatalog.Get(id), hp);
|
|
enemy.State.MaxUptime = hp; enemy.State.CurrentUptime = hp;
|
|
((List<EnemyInstance>)_combat.Enemies).Add(enemy);
|
|
return enemy;
|
|
}
|
|
|
|
CombatContext Context(CardInstance card, int multiplier = 100)
|
|
{
|
|
var context = new CombatContext(card, Player, new[] { Target.State }, _combat, _combat.DamagePipeline,
|
|
new StatusEffectController(), _combat.DeckController, _combat.HandController, _combat.Enemies);
|
|
typeof(CombatContext).GetProperty("LazyMultiplierPercent").SetValue(context, multiplier);
|
|
return context;
|
|
}
|
|
|
|
void Effect(CardInstance card, int multiplier = 100)
|
|
{
|
|
var context = Context(card, multiplier);
|
|
foreach (var effect in CardEffectFactory.CreateEffects(card.Definition)) effect.Execute(context);
|
|
}
|
|
|
|
void FillDrawPile() => _combat.DeckController.Initialize(Enumerable.Range(0, 24).Select(_ => Card("lang_hs_map")));
|
|
|
|
void Play(CardInstance card)
|
|
{
|
|
Assert.That(_combat.HandController.Add(card), Is.True);
|
|
_combat.SelectEnemy(0);
|
|
Assert.That(_combat.PlayCard(card), Is.True);
|
|
}
|
|
|
|
void Drain(string method = "EvaluateLazyStackSequenced")
|
|
{
|
|
Set(_combat, "currentPhase", TurnPhase.Interpret);
|
|
Finish((IEnumerator)Call(_combat, method));
|
|
}
|
|
|
|
static void Finish(IEnumerator routine)
|
|
{
|
|
int steps = 0;
|
|
while (routine.MoveNext())
|
|
{
|
|
Assert.That(++steps, Is.LessThan(2000), "Finite authoritative resolution");
|
|
if (routine.Current is IEnumerator child) Finish(child);
|
|
}
|
|
}
|
|
|
|
[TestCase("gentoo_emerge_sync", 1, 0, 6, 2, true, false)]
|
|
[TestCase("gentoo_ebuild", 1, 0, 6, 2, true, false)]
|
|
[TestCase("gentoo_use_flags", 0, 0, 0, 0, true, false)]
|
|
[TestCase("gentoo_make_j4", 1, 1, 0, 0, true, false)]
|
|
[TestCase("gentoo_emerge_world", 2, 1, 6, 2, true, false)]
|
|
[TestCase("lang_hs_map", 0, 0, 6, 2, false, false)]
|
|
[TestCase("lang_hs_foldr", 1, 0, 6, 2, false, false)]
|
|
[TestCase("lang_hs_thunk", 1, 0, 6, 2, false, false)]
|
|
[TestCase("shop_hs_filter", 1, 0, 6, 2, false, true)]
|
|
[TestCase("shop_hs_fmap", 0, 0, 6, 2, false, true)]
|
|
[TestCase("shop_hs_zipwith", 1, 0, 6, 2, false, true)]
|
|
[TestCase("shop_hs_maybe", 1, 0, 6, 2, false, true)]
|
|
[TestCase("shop_hs_sequence", 1, 0, 6, 2, false, true)]
|
|
[TestCase("shop_hs_const", 0, 0, 6, 2, false, true)]
|
|
[TestCase("shop_hs_scanl", 1, 1, 6, 2, false, true)]
|
|
[TestCase("shop_hs_foldmap", 2, 1, 6, 2, false, true)]
|
|
[TestCase("shop_hs_deepseq", 2, 1, 6, 2, false, true)]
|
|
[TestCase("shop_hs_dollar_bang", 1, 1, 6, 2, false, true)]
|
|
public void EveryNewDefinitionIsRegisteredAndExecutable(string id, int cost, int rarity, int language, int track, bool exclusive, bool shop)
|
|
{
|
|
var card = Card(id).Definition;
|
|
Assert.That(card.CycleCost, Is.EqualTo(cost));
|
|
Assert.That((int)card.Rarity, Is.EqualTo(rarity));
|
|
Assert.That((int)card.Language, Is.EqualTo(language));
|
|
Assert.That((int)card.ResolutionTrack, Is.EqualTo(track));
|
|
Assert.That(card.DistroExclusive, Is.EqualTo(exclusive));
|
|
Assert.That(card.IsRunOnly, Is.EqualTo(shop));
|
|
Assert.That(card.IsToken, Is.False);
|
|
Assert.That(CardEffectFactory.CreateEffects(card).All(e => e is not NoOpCardEffect), Is.True);
|
|
}
|
|
|
|
[Test]
|
|
public void RegistriesContainOnlyRealDefinitionsIncludingTheTwoRepairedPythonCards()
|
|
{
|
|
Assert.That(_cards.AllCards, Has.Count.EqualTo(110));
|
|
Assert.That(_cards.AllCards.All(c => c != null), Is.True);
|
|
Assert.That(_cards.AllCards.Select(c => c.Id).Distinct().Count(), Is.EqualTo(110));
|
|
Assert.That(Card("shop_py_list_append").Definition.DisplayName, Is.Not.Empty);
|
|
Assert.That(Card("shop_py_async_def").Definition.DisplayName, Is.Not.Empty);
|
|
var distros = Asset<DistroDatabase>("Assets/Data/Distros/DistroDatabase.asset");
|
|
Assert.That(distros.FindById("gentoo"), Is.SameAs(_gentoo));
|
|
Assert.That(_gentoo.ExclusiveCards.Count, Is.EqualTo(5));
|
|
Assert.That((_gentoo.BaseUptime, _gentoo.BaseRam, _gentoo.BaseCyclesPerTurn), Is.EqualTo((55,6,3)));
|
|
Assert.That((_gentoo.PrimaryLanguage, _gentoo.SecondaryLanguage), Is.EqualTo((Language.Haskell,Language.C)));
|
|
Assert.That(_gentoo.Passive.Id, Is.EqualTo("gentoo_emerge_world"));
|
|
Assert.That(_gentoo.AsciiArt.text.Split('\n').Length, Is.GreaterThan(8));
|
|
}
|
|
|
|
[TestCase(1,0,4,85)] [TestCase(2,0,4,95)] [TestCase(3,1,4,100)]
|
|
[TestCase(4,1,4,100)] [TestCase(5,1,6,100)]
|
|
public void VersionsInitializeProgressAndReset(int version, int start, int cap, int percent)
|
|
{
|
|
var state = _combat.Compilation;
|
|
state.BeginWave(version);
|
|
Assert.That((state.Level, state.Maximum, state.DamagePercent), Is.EqualTo((start,cap,percent)));
|
|
for (int round = 1; round <= 20; round++)
|
|
{
|
|
int before = state.Level;
|
|
state.CompleteRound(round);
|
|
Assert.That(state.Level, Is.EqualTo(Math.Min(cap,before+1)));
|
|
Assert.That(state.CompleteRound(round), Is.False);
|
|
}
|
|
Assert.That(state.DamagePercent, Is.EqualTo(version == 5 ? 150 : 130));
|
|
state.BeginWave(version);
|
|
Assert.That(state.Level, Is.EqualTo(start));
|
|
Assert.That(state.CompleteRound(1), Is.True);
|
|
}
|
|
|
|
[TestCase(1,0,85)] [TestCase(2,0,95)] [TestCase(1,1,100)]
|
|
[TestCase(1,2,110)] [TestCase(1,3,120)] [TestCase(1,4,130)]
|
|
[TestCase(5,4,140)] [TestCase(5,5,150)]
|
|
public void DirectDamageReadsCurrentCompilation(int version, int completedRounds, int expected)
|
|
{
|
|
_combat.Compilation.BeginWave(version);
|
|
for (int i=1;i<=completedRounds;i++) _combat.Compilation.CompleteRound(i);
|
|
var ctx = Context(Card("lang_hs_thunk"));
|
|
var result = _combat.DamagePipeline.DealDamage(DamageRequest.FromCard(ctx, Target.State, 100, Language.Haskell, false, false));
|
|
Assert.That(result.IncomingAmount, Is.EqualTo(expected));
|
|
}
|
|
|
|
[Test]
|
|
public void GarbageCollectionIsTheOnlyRoundProgressionAndIsIdempotent()
|
|
{
|
|
Set(_combat, "_turnNumberThisWave", 1);
|
|
Call(_combat, "GarbageCollect");
|
|
Assert.That(_combat.Compilation.Level, Is.EqualTo(1));
|
|
Call(_combat, "GarbageCollect");
|
|
Assert.That(_combat.Compilation.Level, Is.EqualTo(1));
|
|
Set(_combat, "_turnNumberThisWave", 2);
|
|
Call(_combat, "GarbageCollect");
|
|
Assert.That(_combat.Compilation.Level, Is.EqualTo(2));
|
|
}
|
|
|
|
[TestCase(1,0)] [TestCase(5,1)]
|
|
public void RealWaveStartClearsPendingSnapshotsAndResetsCompilation(int version, int expected)
|
|
{
|
|
Configure(version);
|
|
Play(Card("lang_hs_map"));
|
|
for (int i=1;i<=8;i++) _combat.Compilation.CompleteRound(i);
|
|
Finish((IEnumerator)Call(_combat, "StartWaveSequenced", true));
|
|
Assert.That(_combat.Compilation.Level, Is.EqualTo(expected));
|
|
Assert.That(_combat.LazyStack.Count, Is.Zero);
|
|
Assert.That(_combat.InterpreterQueue.Count, Is.Zero);
|
|
Assert.That(Player.FlatEffectBonus, Is.Zero);
|
|
}
|
|
|
|
[Test]
|
|
public void SnapshotCountsOnlyHaskellAndSurvivesPopsAndCopies()
|
|
{
|
|
var stack = new LazyStack();
|
|
stack.Enqueue(Card("lang_py_print"));
|
|
var cards = Enumerable.Range(0,6).Select(_ => Card("lang_hs_map")).ToArray();
|
|
for (int i=0;i<cards.Length;i++)
|
|
{
|
|
stack.Enqueue(cards[i]);
|
|
Assert.That(stack.Entries[0].MultiplierPercent, Is.EqualTo(new[] {150,175,200,250,250,250}[i]));
|
|
}
|
|
int[] expected = {250,250,250,200,175,150,100};
|
|
foreach (int percent in expected)
|
|
{
|
|
Assert.That(stack.TryPopEntry(out var entry), Is.True);
|
|
Assert.That(entry.MultiplierPercent, Is.EqualTo(percent));
|
|
}
|
|
stack.Enqueue(cards[3].CopyForCombat());
|
|
Assert.That(stack.Entries[0].MultiplierPercent, Is.EqualTo(150));
|
|
stack.Enqueue(stack.Cards[0]);
|
|
Assert.That(stack.Count, Is.EqualTo(1), "Same pending instance cannot be pushed twice");
|
|
}
|
|
|
|
[TestCase(false)] [TestCase(true)]
|
|
public void RealLifoResolutionEventsRidersAndDisposalAreExactlyOnce(bool reducedMotion)
|
|
{
|
|
UIPreferences.ReducedMotion = reducedMotion;
|
|
_combat.Compilation.BeginWave(0);
|
|
FillDrawPile();
|
|
string[] ids = {"lang_hs_map","lang_hs_foldr","gentoo_ebuild","lang_hs_thunk"};
|
|
var cards = ids.Select(Card).ToArray();
|
|
cards[3].ApplyDrawRider(1);
|
|
var played = new List<CardInstance>();
|
|
var resolved = new List<CardInstance>();
|
|
var resolving = new List<CardInstance>();
|
|
Action<CardPlayedEvent> onPlay = e => played.Add(e.Card);
|
|
Action<CardResolvedEvent> onStart = e => resolving.Add(e.Card);
|
|
Action<CardResolvedEvent> onEnd = e => { resolved.Add(e.Card); _combat.EvaluateLazyStack(); };
|
|
GameEvents.CardPlayed += onPlay; GameEvents.CardResolving += onStart; GameEvents.CardResolved += onEnd;
|
|
try
|
|
{
|
|
foreach (var card in cards) Play(card);
|
|
Assert.That(Target.CurrentUptime, Is.EqualTo(10000));
|
|
Assert.That(Player.Cycles, Is.EqualTo(97));
|
|
Drain(); Drain();
|
|
CollectionAssert.AreEqual(cards, played);
|
|
CollectionAssert.AreEqual(cards.Reverse().ToArray(), resolving);
|
|
CollectionAssert.AreEqual(resolving, resolved);
|
|
Assert.That(Target.CurrentUptime, Is.EqualTo(9979)); // 10 + 8 + 3
|
|
Assert.That(Player.Shield, Is.EqualTo(5)); // 3 * 1.75, nearest-even
|
|
Assert.That(_combat.HandController.Cards.Count, Is.EqualTo(2)); // draw + rider, not multiplied
|
|
foreach (var card in cards)
|
|
{
|
|
Assert.That(_combat.DeckController.DiscardPile.Count(c => c == card), Is.EqualTo(1));
|
|
Assert.That(card.TargetSnapshot, Is.Empty);
|
|
}
|
|
Assert.That(_combat.LazyStack.Count, Is.Zero);
|
|
}
|
|
finally { GameEvents.CardPlayed -= onPlay; GameEvents.CardResolving -= onStart; GameEvents.CardResolved -= onEnd; }
|
|
}
|
|
|
|
[Test]
|
|
public void QueueBeforeStackAndDeferredDamageUsesResolutionLevel()
|
|
{
|
|
Play(Card("lang_hs_thunk")); Play(Card("shop_py_list_append"));
|
|
for(int i=1;i<=4;i++) _combat.Compilation.CompleteRound(i);
|
|
var order = new List<string>();
|
|
Action<CardResolvedEvent> observe = e => order.Add(e.Card.Definition.Id);
|
|
GameEvents.CardResolved += observe;
|
|
try
|
|
{
|
|
Drain("InterpretQueueSequenced"); Drain();
|
|
CollectionAssert.AreEqual(new[]{"shop_py_list_append","lang_hs_thunk"},order);
|
|
Assert.That(Target.CurrentUptime, Is.EqualTo(9984)); // round(6*1.3) + round(4*1.5*1.3); resolution-time Compilation.
|
|
}
|
|
finally { GameEvents.CardResolved -= observe; }
|
|
}
|
|
|
|
[TestCase("gentoo_emerge_sync",0,2,1)]
|
|
[TestCase("gentoo_ebuild",4,0,0)]
|
|
[TestCase("gentoo_use_flags",0,4,0)]
|
|
[TestCase("gentoo_make_j4",8,0,0)]
|
|
[TestCase("gentoo_emerge_world",3,2,0)]
|
|
[TestCase("lang_hs_map",2,0,0)]
|
|
[TestCase("lang_hs_foldr",0,3,1)]
|
|
[TestCase("lang_hs_thunk",4,0,0)]
|
|
[TestCase("shop_hs_filter",4,0,0)]
|
|
[TestCase("shop_hs_fmap",0,2,0)]
|
|
[TestCase("shop_hs_zipwith",2,0,0)]
|
|
[TestCase("shop_hs_maybe",0,4,0)]
|
|
[TestCase("shop_hs_sequence",0,0,2)]
|
|
[TestCase("shop_hs_const",2,0,0)]
|
|
[TestCase("shop_hs_scanl",0,4,1)]
|
|
[TestCase("shop_hs_foldmap",4,0,0)]
|
|
[TestCase("shop_hs_deepseq",9,0,0)]
|
|
[TestCase("shop_hs_dollar_bang",5,2,0)]
|
|
public void EveryCardHasItsExactBaseEffect(string id, int damage, int shield, int draw)
|
|
{
|
|
_combat.Compilation.BeginWave(0); FillDrawPile();
|
|
var card = Card(id); Effect(card);
|
|
Assert.That(10000 - Target.CurrentUptime, Is.EqualTo(damage));
|
|
Assert.That(Player.Shield, Is.EqualTo(shield));
|
|
Assert.That(_combat.HandController.Cards.Count, Is.EqualTo(draw));
|
|
}
|
|
|
|
[Test]
|
|
public void ConditionsAreCheckedAtExecutionAndBonusesAreSingleHits()
|
|
{
|
|
FillDrawPile();
|
|
_combat.Compilation.CompleteRound(1); _combat.Compilation.CompleteRound(2);
|
|
Effect(Card("gentoo_use_flags"));
|
|
Assert.That(_combat.HandController.Cards.Count, Is.EqualTo(1));
|
|
_combat.Compilation.CompleteRound(3);
|
|
int hits=0; Action<DamageDealtEvent> observe=e=>{ if(e.Target==Target.State) hits++; };
|
|
GameEvents.DamageDealt+=observe;
|
|
try { Effect(Card("gentoo_make_j4")); Assert.That(10000-Target.CurrentUptime, Is.EqualTo(13)); Assert.That(hits,Is.EqualTo(1)); }
|
|
finally { GameEvents.DamageDealt-=observe; }
|
|
_combat.Compilation.BeginWave(0);
|
|
new StatusEffectController().Apply(Target.State, StatusType.MemoryLeak,1,2);
|
|
int before=Target.CurrentUptime; Effect(Card("shop_hs_filter"),250);
|
|
Assert.That(before-Target.CurrentUptime, Is.EqualTo(15));
|
|
}
|
|
|
|
[Test]
|
|
public void MaybeHealingDrawAndCyclesNeverReceiveLazyOrCompilationMultipliers()
|
|
{
|
|
_combat.Compilation.BeginWave(5);
|
|
for(int i=1;i<=5;i++) _combat.Compilation.CompleteRound(i);
|
|
Player.CurrentUptime=40;
|
|
Effect(Card("shop_hs_maybe"),250);
|
|
Assert.That(Player.CurrentUptime, Is.EqualTo(43));
|
|
Assert.That(Player.Shield,Is.Zero);
|
|
FillDrawPile(); Effect(Card("shop_hs_sequence"),250);
|
|
Assert.That(_combat.HandController.Cards.Count,Is.EqualTo(2));
|
|
new NextTurnCycleEffect(1).Execute(Context(Card("shop_hs_sequence"),250));
|
|
Assert.That(typeof(CombatManager).GetField("_nextTurnCycleBonus",Private).GetValue(_combat),Is.EqualTo(1));
|
|
Player.CurrentUptime=55; Effect(Card("shop_hs_maybe"),250);
|
|
Assert.That(Player.Shield,Is.EqualTo(13)); // 4*2.5*1.3
|
|
}
|
|
|
|
[TestCase(1,0,250,8)] [TestCase(1,2,250,11)] [TestCase(5,5,250,15)]
|
|
public void GentooHaskellDamageBenchmarks(int version,int rounds,int multiplier,int expected)
|
|
{
|
|
_combat.Compilation.BeginWave(version);
|
|
for(int i=1;i<=rounds;i++) _combat.Compilation.CompleteRound(i);
|
|
Effect(Card("lang_hs_thunk"),multiplier);
|
|
Assert.That(10000-Target.CurrentUptime,Is.EqualTo(expected));
|
|
}
|
|
|
|
[Test]
|
|
public void MagnitudeBeforeMultiplicationCostFloorAndRiderIndependence()
|
|
{
|
|
_combat.Compilation.BeginWave(0);
|
|
var card=Card("lang_hs_thunk");
|
|
card.ApplyMagnitudeUpgrade(2); card.ApplyCostUpgrade(-1); card.ApplyCostUpgrade(-1);
|
|
Assert.That(CombatManager.GetCardCost(card),Is.Zero);
|
|
Effect(card,250);
|
|
Assert.That(10000-Target.CurrentUptime,Is.EqualTo(15));
|
|
FillDrawPile();
|
|
var foldr=Card("lang_hs_foldr"); foldr.ApplyMagnitudeUpgrade(2);
|
|
Effect(foldr,250);
|
|
Assert.That(Player.Shield,Is.EqualTo(12)); // nearest-even(5*2.5)
|
|
Assert.That(_combat.HandController.Cards.Count,Is.EqualTo(3), "Existing +Magnitude draw semantics, not x2.5");
|
|
}
|
|
|
|
[TestCase(1,4,100)] [TestCase(4,3,120)] [TestCase(5,5,130)]
|
|
public void OnlyExplicitCardShieldGetsCompilation(int version,int rounds,int expectedPercent)
|
|
{
|
|
_combat.Compilation.BeginWave(version);
|
|
for(int i=1;i<=rounds;i++) _combat.Compilation.CompleteRound(i);
|
|
new ShieldEffect(100).Execute(Context(Card("shop_hs_fmap")));
|
|
Assert.That(Player.Shield,Is.EqualTo(expectedPercent));
|
|
_combat.GrantPlayerShield(100,"package");
|
|
Assert.That(Player.Shield,Is.EqualTo(expectedPercent+100));
|
|
var status=new StatusEffectController();
|
|
status.Apply(Player,StatusType.UnattendedUpgrades,4,1);
|
|
status.Tick(Player,StatusTickTiming.EndOfTurn,Player,_combat.DamagePipeline);
|
|
Assert.That(Player.Shield,Is.EqualTo(expectedPercent+104));
|
|
}
|
|
|
|
[Test]
|
|
public void EnemyRecoilDotAndPreScaledSpillDoNotInheritCardMultipliers()
|
|
{
|
|
_combat.Compilation.BeginWave(5); for(int i=1;i<=5;i++) _combat.Compilation.CompleteRound(i);
|
|
Assert.That(_combat.DamagePipeline.DealDamage(new DamageRequest(null,Player,3,Language.C,true,false)).IncomingAmount,Is.EqualTo(3));
|
|
Assert.That(_combat.DamagePipeline.DealDamage(new DamageRequest(Target.State,Player,10,Language.C,false,false)).IncomingAmount,Is.EqualTo(10));
|
|
var status=new StatusEffectController();
|
|
status.Apply(Target.State,StatusType.MemoryLeak,5,2,Player);
|
|
status.Tick(Target.State,StatusTickTiming.StartOfTurn,Player,_combat.DamagePipeline);
|
|
Assert.That(Target.CurrentUptime,Is.EqualTo(9995));
|
|
Assert.That(_combat.DamagePipeline.DealDamage(new DamageRequest(Player,Target.State,10,Language.C,false,false,false)).IncomingAmount,Is.EqualTo(10));
|
|
}
|
|
|
|
[Test]
|
|
public void CritIsAfterCompilationAndClampsSafely()
|
|
{
|
|
Player.ForceMaxRolls=false;
|
|
_combat.Compilation.BeginWave(5); for(int i=1;i<=5;i++) _combat.Compilation.CompleteRound(i);
|
|
bool found=false;
|
|
for(int seed=1;seed<100&&!found;seed++)
|
|
{
|
|
RandomRoll.Seed(seed);
|
|
var result=_combat.DamagePipeline.DealDamage(DamageRequest.FromCard(Context(Card("gentoo_make_j4")),Target.State,100,Language.C,false,true));
|
|
if(result.WasCritical) { Assert.That(result.IncomingAmount,Is.EqualTo(225)); found=true; }
|
|
}
|
|
Assert.That(found,Is.True);
|
|
Assert.That(CardScaling.Scale(int.MaxValue,250,150),Is.EqualTo(int.MaxValue));
|
|
Assert.That(CardScaling.Scale(3,150),Is.EqualTo(4));
|
|
Assert.That(CardScaling.Scale(5,150),Is.EqualTo(8));
|
|
Assert.That(CardScaling.Scale(-1,250),Is.Zero);
|
|
}
|
|
|
|
[Test]
|
|
public void HaskellIsIndependentOnUbuntuAndMintRestrictionsRemainIntact()
|
|
{
|
|
Configure(1,Asset<DistroDefinition>("Assets/Data/Distros/Ubuntu.asset"));
|
|
Effect(Card("lang_hs_thunk"),250);
|
|
Assert.That(10000-Target.CurrentUptime,Is.EqualTo(10));
|
|
Configure(1,Asset<DistroDefinition>("Assets/Data/Distros/Mint.asset"));
|
|
int before=Target.CurrentUptime;
|
|
Effect(Card("lang_hs_thunk"),250); Effect(Card("shop_hs_fmap"),250);
|
|
Assert.That(before-Target.CurrentUptime,Is.EqualTo(4),"Mint deliberately ignores multiplicative damage buffs");
|
|
Assert.That(Player.Shield,Is.Zero,"Mint still blocks foreign card buffs");
|
|
}
|
|
|
|
[Test]
|
|
public void AoeAndMultiHitApplyOnceToEachGenuineHit()
|
|
{
|
|
_combat.Compilation.BeginWave(5); for(int i=1;i<=5;i++) _combat.Compilation.CompleteRound(i);
|
|
var other=AddEnemy("memory_leak",10000);
|
|
Effect(Card("gentoo_emerge_world"),250);
|
|
Assert.That(10000-Target.CurrentUptime,Is.EqualTo(11));
|
|
Assert.That(10000-other.CurrentUptime,Is.EqualTo(11));
|
|
Assert.That(Player.Shield,Is.EqualTo(6)); // nearest-even(2*2.5*1.3)
|
|
int before=Target.CurrentUptime;
|
|
Effect(Card("shop_js_promise_all"));
|
|
Assert.That(before-Target.CurrentUptime,Is.EqualTo(45)); // max 10*1.5, three hits
|
|
}
|
|
|
|
[Test]
|
|
public void DeadSnapshotRetargetsAndRapidInputCannotReexecute()
|
|
{
|
|
_combat.Compilation.BeginWave(0);
|
|
var card=Card("lang_hs_thunk"); Play(card);
|
|
Assert.That(_combat.PlayCard(card),Is.False);
|
|
var other=AddEnemy("memory_leak",10000);
|
|
var dead=Target; dead.State.IsDefeated=true;
|
|
((List<EnemyInstance>)_combat.Enemies).Remove(dead);
|
|
Drain(); Drain();
|
|
Assert.That(other.CurrentUptime,Is.EqualTo(9994)); // One 4 * 1.5 hit after retargeting.
|
|
Assert.That(_combat.DeckController.DiscardPile.Count(c=>c==card),Is.EqualTo(1));
|
|
}
|
|
|
|
[Test]
|
|
public void RootkitResistanceIsAfterBothMultipliers()
|
|
{
|
|
((List<EnemyInstance>)_combat.Enemies).Clear();
|
|
var rootkit=AddEnemy("rootkit",10000); AddEnemy("memory_leak",10000);
|
|
_combat.Compilation.BeginWave(5); for(int i=1;i<=5;i++) _combat.Compilation.CompleteRound(i);
|
|
Effect(Card("lang_hs_thunk"),250);
|
|
Assert.That(10000-rootkit.CurrentUptime,Is.EqualTo(2)); // ceil(15*0.1)
|
|
}
|
|
|
|
[Test]
|
|
public void PendingRevivalDoesNotEndWaveOrConsumeRemainingCardsWithoutResolution()
|
|
{
|
|
((List<EnemyInstance>)_combat.Enemies).Clear();
|
|
// At 1 maximum Uptime the existing ceil(25%) reap threshold is also 1.
|
|
// Use a healthy 4-Uptime process so the first lethal hit really schedules revival.
|
|
var zombie=AddEnemy("zombie_process",4);
|
|
Play(Card("lang_hs_map")); Play(Card("lang_hs_thunk"));
|
|
Drain();
|
|
Assert.That(zombie.PendingRevive,Is.True);
|
|
Assert.That(_combat.AwaitingWaveContinue,Is.False);
|
|
Assert.That(_combat.LazyStack.Count,Is.Zero);
|
|
Assert.That(_combat.DeckController.DiscardPile.Count,Is.EqualTo(2));
|
|
Call(_combat,"RevivePendingEnemies");
|
|
Assert.That(zombie.HasRevived,Is.True);
|
|
}
|
|
|
|
[Test]
|
|
public void WaveCompletionDefeatAndShutdownCleanPendingCardsWithoutFalseResolutions()
|
|
{
|
|
var a=Card("lang_hs_map"); var b=Card("lang_hs_thunk");
|
|
Play(a); Play(b);
|
|
((List<EnemyInstance>)_combat.Enemies).Clear();
|
|
Assert.That((bool)Call(_combat,"CheckWin"),Is.True);
|
|
Assert.That(_combat.LazyStack.Count,Is.Zero);
|
|
Assert.That(a.TargetSnapshot,Is.Empty);
|
|
Assert.That(b.TargetSnapshot,Is.Empty);
|
|
Assert.That(_combat.DeckController.DiscardPile.Count,Is.EqualTo(2));
|
|
_combat.LazyStack.Enqueue(a);
|
|
Player.CurrentUptime=0;
|
|
Player.IsDefeated=true;
|
|
Call(_combat,"CheckLoss");
|
|
Assert.That(_combat.LazyStack.Count,Is.Zero);
|
|
_combat.LazyStack.Enqueue(b); Call(_combat,"OnDisable");
|
|
Assert.That(_combat.LazyStack.Count,Is.Zero);
|
|
Assert.That(_combat.Compilation.Active,Is.False);
|
|
}
|
|
|
|
[Test]
|
|
public void HighLevelDnfAndZramKeepExistingPackageSemantics()
|
|
{
|
|
var dnf=new PackageInstance(Asset<PackageDefinition>("Assets/Data/Packages/Dnf.asset"),5);
|
|
var zram=new PackageInstance(Asset<PackageDefinition>("Assets/Data/Packages/Zram.asset"),5);
|
|
Configure(5,null,dnf,zram);
|
|
Assert.That(_run.EffectiveMaxCycles(),Is.EqualTo(9));
|
|
for(int i=1;i<=5;i++) _combat.Compilation.CompleteRound(i);
|
|
for(int i=0;i<4;i++) Play(Card("lang_hs_map"));
|
|
Assert.That(Player.FlatCardDamageBonus,Is.EqualTo(7));
|
|
Assert.That(Player.FlatEffectBonus,Is.Zero,"DNF does not amplify non-damage effects");
|
|
Drain();
|
|
Assert.That(10000-Target.CurrentUptime,Is.EqualTo(105),"DNF is additive before stack/Compilation: 20 + 24 + 27 + 34, not applied twice");
|
|
}
|
|
|
|
[TestCase(0, 2)]
|
|
[TestCase(5, 7)]
|
|
public void DnfPreservesNativeTimingStacksOncePerRoundAndResetsAtWaveBoundary(int level, int amount)
|
|
{
|
|
// V3 starts at Compilation 1 (100% damage), isolating DNF timing from V1's 85% penalty.
|
|
Configure(3, null, new PackageInstance(Asset<PackageDefinition>("Assets/Data/Packages/DNF.asset"), level));
|
|
FillDrawPile();
|
|
Play(Card("gentoo_make_j4"));
|
|
Assert.That(10000 - Target.CurrentUptime, Is.EqualTo(8), "The first Native hit resolves before DNF's hook.");
|
|
Assert.That(Player.FlatCardDamageBonus, Is.EqualTo(amount));
|
|
Assert.That(Player.FlatEffectBonus, Is.Zero);
|
|
Play(Card("gentoo_make_j4"));
|
|
Assert.That(10000 - Target.CurrentUptime, Is.EqualTo(16 + amount));
|
|
Assert.That(Player.FlatCardDamageBonus, Is.EqualTo(amount), "Only the first play adds a stack.");
|
|
Finish((IEnumerator)Call(_combat, "AllocateTurnSequenced"));
|
|
Play(Card("gentoo_make_j4"));
|
|
Assert.That(Player.FlatCardDamageBonus, Is.EqualTo(amount * 2));
|
|
Finish((IEnumerator)Call(_combat, "StartWaveSequenced", true));
|
|
Assert.That(Player.FlatCardDamageBonus, Is.Zero, "DNF stacks last one wave, not the whole run.");
|
|
}
|
|
|
|
[TestCase(0)]
|
|
[TestCase(5)]
|
|
public void DnfLeavesMintsExistingGeneralEffectBonusIntact(int level)
|
|
{
|
|
var mint = Asset<DistroDefinition>("Assets/Data/Distros/Mint.asset");
|
|
Configure(2, mint, new PackageInstance(Asset<PackageDefinition>("Assets/Data/Packages/DNF.asset"), level));
|
|
Play(Card("lang_hs_map"));
|
|
Assert.That(Player.FlatEffectBonus, Is.EqualTo(2));
|
|
Assert.That(Player.FlatCardDamageBonus, Is.EqualTo(2 + level));
|
|
Finish((IEnumerator)Call(_combat, "StartWaveSequenced", true));
|
|
Assert.That(Player.FlatEffectBonus, Is.EqualTo(2));
|
|
Assert.That(Player.FlatCardDamageBonus, Is.Zero);
|
|
}
|
|
|
|
[Test]
|
|
public void CSpillAndRustOverkillShieldAreNotScaledTwice()
|
|
{
|
|
_combat.Compilation.BeginWave(5); for(int i=1;i<=5;i++) _combat.Compilation.CompleteRound(i);
|
|
var first=Target; first.State.CurrentUptime=5;
|
|
var other=AddEnemy("memory_leak",10000);
|
|
Set(_combat,"_enemyExitQueueDraining",true); // Stage exits, as WaveCompletionTests does.
|
|
Effect(Card("gentoo_make_j4")); // 11*1.5 = 16; 11 excess halves to 5, without reapplying Compilation.
|
|
Assert.That(other.CurrentUptime,Is.EqualTo(9995));
|
|
((List<EnemyInstance>)_combat.Enemies).Remove(first);
|
|
other.State.CurrentUptime=1;
|
|
Effect(Card("lang_rs_fn_main")); // 6*1.5 =9; overkill Shield8, not round(8*1.3).
|
|
Assert.That(Player.Shield,Is.EqualTo(8));
|
|
}
|
|
|
|
[Test]
|
|
public void InvalidPlayDoesNotPayOrPushAndSourceSnapshotIsImmutable()
|
|
{
|
|
var card=Card("lang_hs_thunk"); _combat.HandController.Add(card);
|
|
Player.Cycles=0;
|
|
Assert.That(_combat.PlayCard(card),Is.False);
|
|
Assert.That(_combat.LazyStack.Count,Is.Zero);
|
|
Player.Cycles=2;
|
|
Assert.That(_combat.PlayCard(card),Is.False,"Target required");
|
|
Assert.That(Player.Cycles,Is.EqualTo(2));
|
|
_combat.SelectEnemy(0); // Completes pending targeting and plays once.
|
|
Assert.That(_combat.LazyStack.Count,Is.EqualTo(1));
|
|
var captured=_combat.LazyStack.Entries[0].Targets[0];
|
|
card.ClearTargetSnapshot();
|
|
Assert.That(_combat.LazyStack.Entries[0].Targets[0],Is.SameAs(captured));
|
|
Drain();
|
|
Assert.That(10000-Target.CurrentUptime,Is.EqualTo(5)); // round(4 * 1.5 * 0.85).
|
|
}
|
|
|
|
[UnityTest]
|
|
public IEnumerator CombatReadoutsAndSchedulerFitViewportMatrix()
|
|
{
|
|
Configure(5);
|
|
for(int i=1;i<=5;i++) _combat.Compilation.CompleteRound(i);
|
|
foreach(string id in new[]{"lang_hs_map","lang_hs_foldr","gentoo_ebuild","lang_hs_thunk"}) Play(Card(id));
|
|
_combat.HandController.Add(Card("gentoo_make_j4"));
|
|
var window=ScriptableObject.CreateInstance<TerminalFocusTestWindow>();
|
|
var view=_owner.AddComponent<CombatSceneController>();
|
|
try
|
|
{
|
|
window.Show(); var root=window.rootVisualElement;
|
|
Set(view,"_root",root); Set(view,"_runManager",_run); Set(view,"_combatManager",_combat);
|
|
Set(view,"_distroAccent",_gentoo.AccentColor);
|
|
Call(view,"LoadStyles");
|
|
typeof(CombatSceneController).Assembly.GetType("KernelPanic.UI.TerminalTheme").GetMethod("Attach").Invoke(null,new object[]{root});
|
|
Call(view,"BuildLayout");
|
|
foreach(var size in new[]{new Vector2(1920,1080),new Vector2(1366,768),new Vector2(1280,720),new Vector2(1024,768),new Vector2(390,844)})
|
|
{
|
|
root.style.width=size.x; root.style.height=size.y;
|
|
Call(view,"RefreshPlayer"); Call(view,"RefreshTracks"); Call(view,"RefreshEnemies");
|
|
Call(view,"RefreshHand"); Call(view,"RefreshTurnPanel");
|
|
for(int frame=0;frame<5;frame++) yield return null;
|
|
string text=string.Join(" ",root.Query<Label>().ToList().Select(l=>l.text));
|
|
Assert.That(text,Does.Contain("Compilation"));
|
|
Assert.That(text,Does.Contain("6/6"));
|
|
Assert.That(text,Does.Contain("+50%"));
|
|
var multipliers=root.Query<Label>(className:"execution-multiplier").ToList();
|
|
CollectionAssert.AreEqual(new[]{"x2.5","x2.0","x1.75","x1.5"},multipliers.Select(l=>l.text));
|
|
foreach(var label in multipliers)
|
|
Assert.That(label.worldBound.xMax,Is.LessThanOrEqualTo(root.worldBound.xMax+1),size.ToString());
|
|
var end=root.Query<Button>().ToList().Single(b=>b.text=="[E] end turn");
|
|
Assert.That(end.worldBound.yMax,Is.LessThanOrEqualTo(root.worldBound.yMax+1),size.ToString());
|
|
Assert.That(end.worldBound.xMax,Is.LessThanOrEqualTo(root.worldBound.xMax+1),size.ToString());
|
|
}
|
|
}
|
|
finally { Call(view,"OnDisable"); UnityEngine.Object.DestroyImmediate(view); window.Close(); }
|
|
}
|
|
|
|
[Test]
|
|
public void LethalStackHitEndsCombatBeforeTheNextOperationButDisposesBoth()
|
|
{
|
|
_combat.Compilation.BeginWave(0);
|
|
Target.State.CurrentUptime=1;
|
|
var pending=Card("lang_hs_map"); var lethal=Card("lang_hs_thunk");
|
|
Play(pending); Play(lethal);
|
|
var completed=new List<CardInstance>();
|
|
Action<CardResolvedEvent> start=e=>Set(_combat,"_enemyExitQueueDraining",true);
|
|
Action<CardResolvedEvent> end=e=>
|
|
{
|
|
completed.Add(e.Card);
|
|
foreach(var enemy in _combat.Enemies.ToArray())
|
|
GameEvents.RaiseCombatantDeathVisualCompleted(new CombatantDeathVisualCompletedEvent(enemy.State));
|
|
Set(_combat,"_enemyExitQueueDraining",false);
|
|
Finish((IEnumerator)Call(_combat,"DrainEnemyExitQueue"));
|
|
};
|
|
GameEvents.CardResolving+=start; GameEvents.CardResolved+=end;
|
|
try
|
|
{
|
|
Drain();
|
|
CollectionAssert.AreEqual(new[]{lethal},completed);
|
|
Assert.That(_combat.AwaitingWaveContinue,Is.True);
|
|
Assert.That(_combat.LazyStack.Count,Is.Zero);
|
|
Assert.That(_combat.DeckController.DiscardPile.Count(c=>c==pending),Is.EqualTo(1));
|
|
Assert.That(_combat.DeckController.DiscardPile.Count(c=>c==lethal),Is.EqualTo(1));
|
|
}
|
|
finally { GameEvents.CardResolving-=start; GameEvents.CardResolved-=end; }
|
|
}
|
|
|
|
[Test]
|
|
public void DelayedCardCallbackReadsCompilationAndNewBootDropsSnapshots()
|
|
{
|
|
_combat.Compilation.BeginWave(1);
|
|
for(int i=1;i<=4;i++) _combat.Compilation.CompleteRound(i);
|
|
Call(_combat,"DealToAllEnemies",10,Language.Python,"delayed card");
|
|
Assert.That(Target.CurrentUptime,Is.EqualTo(9987));
|
|
var pending=Card("lang_hs_map"); Play(pending);
|
|
Finish((IEnumerator)Call(_combat,"BootCombatSequenced"));
|
|
Assert.That(_combat.Compilation.Level,Is.Zero);
|
|
Assert.That(_combat.LazyStack.Count,Is.Zero);
|
|
Assert.That(pending.TargetSnapshot,Is.Empty);
|
|
}
|
|
|
|
[Test]
|
|
public void PublicBootCancelsStaleEvaluatorGuardsAndPendingEntries()
|
|
{
|
|
var pending=Card("lang_hs_map"); Play(pending);
|
|
Set(_combat,"_interpretingTracks",true);
|
|
Set(_combat,"_evaluatingLazyStack",true);
|
|
_combat.StartCombat();
|
|
Assert.That(_combat.CurrentPhase,Is.EqualTo(TurnPhase.Boot));
|
|
Assert.That(_combat.LazyStack.Count,Is.Zero);
|
|
Assert.That(pending.TargetSnapshot,Is.Empty);
|
|
Assert.That(typeof(CombatManager).GetField("_interpretingTracks",Private).GetValue(_combat),Is.False);
|
|
Assert.That(typeof(CombatManager).GetField("_evaluatingLazyStack",Private).GetValue(_combat),Is.False);
|
|
}
|
|
}
|