397 lines
26 KiB
C#
397 lines
26 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;
|
|
|
|
public class NixGoTests
|
|
{
|
|
const BindingFlags Private = BindingFlags.Instance | BindingFlags.NonPublic;
|
|
GameObject owner;
|
|
CombatManager combat;
|
|
RunManager run;
|
|
CardDatabase cards;
|
|
CombatantState Player => combat.PlayerState;
|
|
CombatantState Target => combat.Enemies[0].State;
|
|
static T Asset<T>(string path) where T : UnityEngine.Object => AssetDatabase.LoadAssetAtPath<T>(path);
|
|
static object Call(object o, string name, params object[] args) => o.GetType().GetMethod(name, Private).Invoke(o, args);
|
|
static void Set(object o, string name, object value) => o.GetType().GetField(name, Private).SetValue(o, value);
|
|
[SetUp] public void Setup()
|
|
{
|
|
owner = new GameObject("NixOS and Go integration");
|
|
run = owner.AddComponent<RunManager>(); combat = owner.AddComponent<CombatManager>();
|
|
Call(combat, "OnDisable"); Call(combat, "Awake"); Call(combat, "OnEnable");
|
|
cards = Asset<CardDatabase>("Assets/Data/Cards/CardDatabase.asset");
|
|
Configure("NixOS", 1);
|
|
var enemies = (List<EnemyInstance>)combat.Enemies;
|
|
enemies.Add(new EnemyInstance("target", 10000, Array.Empty<EnemyIntent>()));
|
|
enemies.Add(new EnemyInstance("other target", 10000, Array.Empty<EnemyIntent>()));
|
|
}
|
|
[TearDown] public void Cleanup() { Call(combat, "OnDisable"); UnityEngine.Object.DestroyImmediate(owner); }
|
|
void Configure(string distro, int version, params PackageInstance[] packages)
|
|
{
|
|
var host = Asset<DistroDefinition>($"Assets/Data/Distros/{distro}.asset");
|
|
var config = new RunConfig(host, Language.Haskell, Language.Go, host.ExclusiveCards.Take(4).ToArray(), packages, 73, version);
|
|
run.StartRun(config); Set(combat, "_runConfig", config); Set(combat, "_runManager", run);
|
|
Set(combat, "_playerState", new CombatantState(60, 32, 30));
|
|
Set(combat, "_handController", new HandController(32));
|
|
Set(combat, "currentPhase", TurnPhase.Execute); Set(combat, "_turnNumberThisWave", 1);
|
|
Call(combat, "ApplyVersionState", Player); Call(combat, "ApplyPackageState", Player);
|
|
Player.ForceMaxRolls = true;
|
|
combat.Nix.BeginWave(distro == "NixOS" ? version : 0); Call(combat, "ApplyGovernorModifiers");
|
|
combat.Compilation.BeginWave(distro == "Gentoo" ? version : 0);
|
|
}
|
|
CardInstance Card(string id) => new(cards.FindById(id) ?? throw new Exception(id));
|
|
CardInstance Play(string id)
|
|
{
|
|
var card = Card(id); Assert.That(combat.HandController.Add(card), Is.True);
|
|
combat.SelectEnemy(0); Assert.That(combat.PlayCard(card), Is.True, id); return card;
|
|
}
|
|
CombatContext Context(CardInstance card) => new(card, Player, new[] { Target }, combat,
|
|
combat.DamagePipeline, new StatusEffectController(), combat.DeckController, combat.HandController, combat.Enemies);
|
|
void Tick(int round)
|
|
{
|
|
Set(combat, "_turnNumberThisWave", round);
|
|
foreach (var work in combat.Go.Active.ToArray()) combat.Go.Tick(work, round, g => Call(combat, "ResolveGoroutineTick", g));
|
|
}
|
|
static void Finish(IEnumerator routine)
|
|
{ int limit = 2000; while (routine.MoveNext()) { Assert.That(--limit, Is.GreaterThan(0)); if (routine.Current is IEnumerator child) Finish(child); } }
|
|
|
|
[TestCase(1, NixGovernor.Performance,120,75)] [TestCase(1,NixGovernor.Powersave,80,130)] [TestCase(1,NixGovernor.Schedutil,105,105)]
|
|
[TestCase(2,NixGovernor.Schedutil,110,110)] [TestCase(4,NixGovernor.Performance,130,75)] [TestCase(4,NixGovernor.Powersave,80,140)]
|
|
[TestCase(5,NixGovernor.Schedutil,110,110)]
|
|
public void GovernorsScaleOnlyCardDamageAndExplicitShield(int version, NixGovernor governor, int damage, int shield)
|
|
{
|
|
Configure("NixOS", version);
|
|
if (governor != NixGovernor.Schedutil) Assert.That(combat.TrySwitchGovernor(governor), Is.True);
|
|
Player.Shield = 0;
|
|
var context = Context(Card("shop_go_build"));
|
|
int before = Target.CurrentUptime;
|
|
combat.DamagePipeline.DealDamage(DamageRequest.FromCard(context, Target, 100, Language.Go, false, false));
|
|
Assert.That(before - Target.CurrentUptime, Is.EqualTo(damage));
|
|
new ShieldEffect(100).Execute(context); Assert.That(Player.Shield, Is.EqualTo(shield));
|
|
before = Target.CurrentUptime;
|
|
combat.DamagePipeline.DealDamage(new DamageRequest(Player, Target, 100, Language.Go, false, false));
|
|
Assert.That(before - Target.CurrentUptime, Is.EqualTo(100), "Non-card damage must not inherit governor policy.");
|
|
int prior = Player.Shield; combat.GrantPlayerShield(10, "package"); Assert.That(Player.Shield - prior, Is.EqualTo(10));
|
|
}
|
|
[Test] public void SwitchesAreAtomicOncePerTurnAndFreeOncePerWaveFromV3()
|
|
{
|
|
Configure("NixOS",3); Player.Cycles = 0;
|
|
Assert.That(combat.Nix.Governor, Is.EqualTo(NixGovernor.Schedutil));
|
|
Assert.That(combat.TrySwitchGovernor(NixGovernor.Schedutil), Is.False);
|
|
Assert.That(combat.Nix.FreeSwitchUsed, Is.False);
|
|
Assert.That(combat.TrySwitchGovernor(NixGovernor.Performance), Is.True);
|
|
Assert.That(Player.Cycles, Is.Zero); Assert.That(combat.Nix.FreeSwitchUsed, Is.True);
|
|
Assert.That(combat.TrySwitchGovernor(NixGovernor.Powersave), Is.False);
|
|
Set(combat,"_turnNumberThisWave",2);
|
|
Assert.That(combat.TrySwitchGovernor(NixGovernor.Powersave), Is.False);
|
|
Player.Cycles=1;
|
|
Assert.That(combat.TrySwitchGovernor(NixGovernor.Powersave), Is.True); Assert.That(Player.Cycles, Is.Zero);
|
|
Assert.That(combat.CardsPlayedThisRound, Is.Zero);
|
|
Finish((IEnumerator)Call(combat,"StartWaveSequenced",true));
|
|
Assert.That(combat.Nix.Governor, Is.EqualTo(NixGovernor.Schedutil)); Assert.That(combat.Nix.SwitchCost,Is.Zero);
|
|
}
|
|
[Test] public void InvalidSwitchesNeverConsumeCyclesOrOpportunity()
|
|
{
|
|
Player.Cycles=0; Assert.That(combat.TrySwitchGovernor(NixGovernor.Performance),Is.False);
|
|
Player.Cycles=3; Set(combat,"currentPhase",TurnPhase.Interpret);
|
|
Assert.That(combat.TrySwitchGovernor(NixGovernor.Performance),Is.False);
|
|
Set(combat,"currentPhase",TurnPhase.Execute);
|
|
Assert.That(combat.TrySwitchGovernor((NixGovernor)99),Is.False);
|
|
Assert.That(combat.TrySwitchGovernor(NixGovernor.Schedutil),Is.False);
|
|
Assert.That(combat.TrySwitchGovernor(NixGovernor.Performance),Is.True);
|
|
Assert.That(Player.Cycles,Is.EqualTo(2)); Assert.That(combat.CardsPlayedThisRound,Is.Zero);
|
|
}
|
|
[Test] public void SwitchFeedbackReportsActualBlockInsteadOfGuessingFromCycles()
|
|
{
|
|
var messages = new List<string>();
|
|
combat.CombatLog += messages.Add;
|
|
Player.Cycles = 0;
|
|
Set(combat, "currentPhase", TurnPhase.Interpret);
|
|
Assert.That(combat.GetGovernorSwitchBlockReason(NixGovernor.Performance),
|
|
Is.EqualTo(NixGovernorSwitchBlockReason.OutsideExecutePhase));
|
|
Assert.That(combat.TrySwitchGovernor(NixGovernor.Performance), Is.False);
|
|
Assert.That(messages.Single(), Does.Contain("Execute").And.Not.Contain("Cycles"));
|
|
messages.Clear();
|
|
Set(combat, "currentPhase", TurnPhase.Execute);
|
|
Assert.That(combat.GetGovernorSwitchBlockReason(NixGovernor.Performance),
|
|
Is.EqualTo(NixGovernorSwitchBlockReason.InsufficientCycles));
|
|
Assert.That(combat.TrySwitchGovernor(NixGovernor.Performance), Is.False);
|
|
Assert.That(messages.Single(), Does.Contain("not enough Cycles"));
|
|
Assert.That(combat.Nix.FreeSwitchUsed, Is.False);
|
|
Assert.That(Player.Cycles, Is.Zero);
|
|
}
|
|
[Test] public void SwitchFeedbackHandlesUnavailableCombatAndReentrantCalls()
|
|
{
|
|
Set(combat, "_playerState", null);
|
|
Assert.That(combat.GetGovernorSwitchBlockReason(NixGovernor.Performance),
|
|
Is.EqualTo(NixGovernorSwitchBlockReason.CombatUnavailable));
|
|
Assert.That(combat.CanSwitchGovernor(NixGovernor.Performance), Is.False);
|
|
Configure("NixOS", 5);
|
|
int messages = 0;
|
|
combat.CombatLog += _ =>
|
|
{
|
|
messages++;
|
|
Assert.That(combat.GetGovernorSwitchBlockReason(NixGovernor.Powersave),
|
|
Is.EqualTo(NixGovernorSwitchBlockReason.SwitchingInProgress));
|
|
Assert.That(combat.TrySwitchGovernor(NixGovernor.Powersave), Is.False);
|
|
};
|
|
Assert.That(combat.TrySwitchGovernor(NixGovernor.Performance), Is.True);
|
|
Assert.That(messages, Is.EqualTo(1));
|
|
}
|
|
[Test] public void V5BonusesAreFixedAndRapidOrReentrantInputsCannotRepeatThem()
|
|
{
|
|
Configure("NixOS",5);
|
|
Player.FlatEffectBonus=50; Player.DamageMultiplierPercent=200;
|
|
int before=Target.CurrentUptime, events=0;
|
|
Action<CardPlayedEvent> played=_=>events++; GameEvents.CardPlayed+=played;
|
|
Action recurse=()=>combat.TrySwitchGovernor(NixGovernor.Powersave); combat.StateChanged+=recurse;
|
|
try
|
|
{
|
|
Assert.That(combat.TrySwitchGovernor(NixGovernor.Performance),Is.True);
|
|
Assert.That(Target.CurrentUptime,Is.EqualTo(before-5)); Assert.That(Player.Shield,Is.Zero);
|
|
Assert.That(combat.TrySwitchGovernor(NixGovernor.Performance),Is.False);
|
|
combat.StateChanged-=recurse;
|
|
Set(combat,"_turnNumberThisWave",2); Assert.That(combat.TrySwitchGovernor(NixGovernor.Powersave),Is.True);
|
|
Assert.That(Player.Shield,Is.EqualTo(6));
|
|
combat.DeckController.InitializeInDrawOrder(new[]{Card("lang_go_worker"),Card("lang_go_func")});
|
|
Set(combat,"_turnNumberThisWave",3); Assert.That(combat.TrySwitchGovernor(NixGovernor.Schedutil),Is.True);
|
|
Assert.That(combat.HandController.Cards.Count,Is.EqualTo(1)); Assert.That(events,Is.Zero);
|
|
}
|
|
finally { GameEvents.CardPlayed-=played; combat.StateChanged-=recurse; }
|
|
}
|
|
[Test] public void PerformanceV5UsesFirstLivingFallbackAndRejectsNoTarget()
|
|
{
|
|
Configure("NixOS",5); Target.CurrentUptime=0; Target.IsDefeated=true;
|
|
int before=combat.Enemies[1].State.CurrentUptime;
|
|
Assert.That(combat.TrySwitchGovernor(NixGovernor.Performance),Is.True);
|
|
Assert.That(combat.Enemies[1].State.CurrentUptime,Is.EqualTo(before-5));
|
|
combat.Nix.BeginWave(5); combat.Enemies[1].State.CurrentUptime=0; combat.Enemies[1].State.IsDefeated=true;
|
|
Assert.That(combat.GetGovernorSwitchBlockReason(NixGovernor.Performance), Is.EqualTo(NixGovernorSwitchBlockReason.NoLivingTarget));
|
|
Assert.That(combat.TrySwitchGovernor(NixGovernor.Performance),Is.False); Assert.That(combat.Nix.FreeSwitchUsed,Is.False);
|
|
}
|
|
[Test] public void HaskellKeepsDepthSnapshotButUsesLiveGovernorAndDoesNotSwitchThroughItsCard()
|
|
{
|
|
var card=Play("nixos_rebuild_switch_card");
|
|
int snapshot=combat.LazyStack.Entries.Single().MultiplierPercent;
|
|
Assert.That(combat.Nix.Governor,Is.EqualTo(NixGovernor.Schedutil));
|
|
Assert.That(combat.TrySwitchGovernor(NixGovernor.Powersave),Is.True);
|
|
var context=Context(card); typeof(CombatContext).GetProperty("LazyMultiplierPercent").SetValue(context,snapshot);
|
|
new ShieldEffect(4).Execute(context);
|
|
Assert.That(Player.Shield,Is.EqualTo(CardScaling.Scale(4,snapshot,130)));
|
|
Assert.That(combat.LazyStack.Entries.Single().MultiplierPercent,Is.EqualTo(snapshot));
|
|
int before=Target.CurrentUptime;
|
|
new DealDamageEffect(20,20,Language.Haskell).Execute(context);
|
|
Assert.That(before-Target.CurrentUptime,Is.EqualTo(CardScaling.Scale(20,snapshot,80)));
|
|
var python=Context(Card("lang_py_print")); before=Target.CurrentUptime;
|
|
foreach(var effect in CardEffectFactory.CreateEffects(python.Card.Definition)) effect.Execute(python);
|
|
Assert.That(before-Target.CurrentUptime,Is.EqualTo(CardScaling.Scale(4,80)));
|
|
}
|
|
[Test] public void DeploymentRetainsCardFreesRamRejectsFourthAndTicksExactlyOncePerRound()
|
|
{
|
|
int events=0; Action<CardPlayedEvent> onPlay=_=>events++; GameEvents.CardPlayed+=onPlay;
|
|
try
|
|
{
|
|
var card=Play("lang_go_worker"); Play("lang_go_worker"); Play("lang_go_worker");
|
|
Assert.That(combat.HandController.Cards,Has.No.Member(card)); Assert.That(combat.DeckController.DiscardPile,Has.No.Member(card));
|
|
var rejected=Card("lang_go_func"); combat.HandController.Add(rejected); int cycles=Player.Cycles;
|
|
Assert.That(combat.PlayCard(rejected),Is.False); Assert.That(Player.Cycles,Is.EqualTo(cycles));
|
|
Assert.That(combat.HandController.Cards,Does.Contain(rejected));
|
|
int before=Target.CurrentUptime; Tick(1); Assert.That(Target.CurrentUptime,Is.EqualTo(before));
|
|
Tick(2); Assert.That(before-Target.CurrentUptime,Is.EqualTo(9));
|
|
Tick(2); Assert.That(before-Target.CurrentUptime,Is.EqualTo(9));
|
|
Tick(3); Tick(4); Assert.That(before-Target.CurrentUptime,Is.EqualTo(27));
|
|
Assert.That(combat.Go.Count,Is.Zero); Assert.That(combat.DeckController.DiscardPile,Does.Contain(card));
|
|
Assert.That(events,Is.EqualTo(3)); Assert.That(combat.CardsPlayedThisRound,Is.EqualTo(3));
|
|
}
|
|
finally {GameEvents.CardPlayed-=onPlay;}
|
|
}
|
|
[TestCase("Gentoo",5)] [TestCase("Arch",5)] [TestCase("Fedora",5)] [TestCase("Mint",5)] [TestCase("Ubuntu",1)] [TestCase("NixOS",4)]
|
|
public void TicksUseLivePolicyAndCompilationWithoutCardPlayHooks(string distro,int version)
|
|
{
|
|
Configure(distro,version);
|
|
var card=Card("lang_go_worker"); card.ApplyMagnitudeUpgrade(2); combat.HandController.Add(card); combat.SelectEnemy(0);
|
|
Assert.That(combat.PlayCard(card),Is.True);
|
|
var work=combat.Go.Active.Single(); Assert.That(work.BaseDamage,Is.EqualTo(5));
|
|
card.ApplyMagnitudeUpgrade(10);
|
|
int count=combat.CardsPlayedThisRound, btw=Player.ArchBtwStacks; float crash=combat.FedoraCrashChance;
|
|
if(distro=="NixOS") combat.TrySwitchGovernor(NixGovernor.Performance);
|
|
if(distro=="Gentoo") for(int i=1;i<=5;i++) combat.Compilation.CompleteRound(i);
|
|
int before=Target.CurrentUptime;
|
|
int expected=combat.DamagePipeline.PreviewIncomingDamage(DamageRequest.PreviewCard(Player,Target,combat.GoroutineDamageAmount(work),Language.Go,false,true,100,combat.Compilation.DamagePercent));
|
|
Tick(2); Assert.That(before-Target.CurrentUptime,Is.EqualTo(expected)); Assert.That(work.BaseDamage,Is.EqualTo(5));
|
|
Assert.That(combat.CardsPlayedThisRound,Is.EqualTo(count)); Assert.That(Player.ArchBtwStacks,Is.EqualTo(btw)); Assert.That(combat.FedoraCrashChance,Is.EqualTo(crash));
|
|
}
|
|
[Test] public void SelectedExtensionsAreCappedAndCancellationDiscardsExactlyOnce()
|
|
{
|
|
Play("lang_go_worker"); Play("lang_go_func"); var first=combat.Go.Active[0]; var second=combat.Go.Active[1];
|
|
combat.SelectGoroutine(second.Id); Play("lang_go_context_timeout");
|
|
Assert.That(second.RemainingTicks,Is.EqualTo(4)); Assert.That(first.RemainingTicks,Is.EqualTo(3));
|
|
Player.CurrentUptime=40; combat.SelectGoroutine(second.Id); Play("nixos_rollback");
|
|
Assert.That(second.RemainingTicks,Is.EqualTo(5)); Assert.That(Player.CurrentUptime,Is.EqualTo(44));
|
|
Play("shop_go_channel_send"); Assert.That(first.RemainingTicks,Is.EqualTo(4)); Assert.That(second.RemainingTicks,Is.EqualTo(5));
|
|
combat.SelectGoroutine(first.Id); Play("shop_go_context_cancel");
|
|
Assert.That(combat.Go.Count,Is.EqualTo(1)); Assert.That(first.Active,Is.False); Assert.That(first.Target,Is.Null);
|
|
Assert.That(combat.DeckController.DiscardPile.Count(c=>c==first.SourceCard),Is.EqualTo(1));
|
|
Assert.That(combat.Go.Terminate(first),Is.False);
|
|
Assert.That(second.DeploymentRound,Is.EqualTo(1)); Assert.That(second.BaseDamage,Is.EqualTo(1));
|
|
var timeout=Card("lang_go_context_timeout"); combat.HandController.Add(timeout); int cycles=Player.Cycles;
|
|
Assert.That(combat.PlayCard(timeout),Is.False); Assert.That(Player.Cycles,Is.EqualTo(cycles));
|
|
}
|
|
[Test] public void SelectionDefersPaymentAndRollbackStillHealsWithNoWorker()
|
|
{
|
|
Play("lang_go_worker"); var card=Card("lang_go_context_timeout"); combat.HandController.Add(card); int cycles=Player.Cycles;
|
|
Assert.That(combat.PlayCard(card),Is.False); Assert.That(combat.PendingGoroutineCard,Is.SameAs(card)); Assert.That(Player.Cycles,Is.EqualTo(cycles));
|
|
combat.SelectGoroutine(combat.Go.Active[0].Id); Assert.That(Player.Cycles,Is.EqualTo(cycles-1));
|
|
Assert.That(combat.Go.Active[0].RemainingTicks,Is.EqualTo(5));
|
|
combat.Go.Clear(); Player.CurrentUptime=30; Play("nixos_rollback"); Assert.That(Player.CurrentUptime,Is.EqualTo(34));
|
|
}
|
|
[Test] public void RetargetsDeadInactiveAndRemovedEnemiesAndConsumesTicksWithoutATarget()
|
|
{
|
|
Play("lang_go_worker"); var work=combat.Go.Active.Single();
|
|
Target.CurrentUptime=0; Target.IsDefeated=true;
|
|
Tick(2); Assert.That(work.Target,Is.SameAs(combat.Enemies[1].State));
|
|
((List<EnemyInstance>)combat.Enemies).RemoveAt(1);
|
|
Tick(3); Assert.That(work.Target,Is.Null); Assert.That(work.RemainingTicks,Is.EqualTo(1));
|
|
Target.CurrentUptime=100; Target.IsDefeated=false;
|
|
Tick(4); Assert.That(Target.CurrentUptime,Is.EqualTo(97)); Assert.That(combat.Go.Count,Is.Zero);
|
|
}
|
|
[Test] public void RootkitResistanceIsAppliedThroughTheExistingPipeline()
|
|
{
|
|
((List<EnemyInstance>)combat.Enemies)[0]=new EnemyInstance(EnemyArchetypeCatalog.Get("rootkit"),100);
|
|
Play("lang_go_worker"); int before=Target.CurrentUptime; Tick(2);
|
|
Assert.That(before-Target.CurrentUptime,Is.EqualTo(Math.Max(1,Mathf.CeilToInt(3*EnemyArchetypeCatalog.RootkitMaskedDamagePercent/100f))));
|
|
}
|
|
[Test] public void PendingZombieIsInactiveAndDoesNotReceiveTicks()
|
|
{
|
|
var zombie=new EnemyInstance(EnemyArchetypeCatalog.Get("zombie_process"),20);
|
|
((List<EnemyInstance>)combat.Enemies)[0]=zombie;
|
|
Play("lang_go_worker"); zombie.MarkPendingRevive();
|
|
Tick(2); Assert.That(zombie.State.CurrentUptime,Is.Zero);
|
|
Assert.That(combat.Go.Active.Single().Target,Is.SameAs(combat.Enemies[1].State));
|
|
zombie.ReviveAtHalfUptime(); int health=zombie.State.CurrentUptime;
|
|
Tick(3); Assert.That(zombie.State.CurrentUptime,Is.EqualTo(health),"The surviving replacement target remains selected.");
|
|
}
|
|
[TestCase("nixos_nix_shell",2,3)] [TestCase("lang_go_worker",3,3)]
|
|
[TestCase("lang_go_func",1,2)] [TestCase("shop_go_time_ticker",2,3)]
|
|
public void EveryDeploymentCardExecutesItsAuthoredLifetime(string id,int damage,int ticks)
|
|
{
|
|
Play(id); var work=combat.Go.Active.Single();
|
|
Assert.That(work.BaseDamage,Is.EqualTo(damage)); Assert.That(work.RemainingTicks,Is.EqualTo(ticks));
|
|
int before=Target.CurrentUptime;
|
|
for(int round=2;round<=ticks+1;round++) Tick(round);
|
|
Assert.That(before-Target.CurrentUptime,Is.EqualTo(ticks*CardScaling.Scale(damage,105)));
|
|
Assert.That(work.Active,Is.False);
|
|
}
|
|
[TestCase("nixos_rebuild_switch_card",4)] [TestCase("nixos_store_gc",5)]
|
|
public void NixShieldCardsResolveThroughHaskellAndDrawExactlyOne(string id,int shield)
|
|
{
|
|
combat.DeckController.InitializeInDrawOrder(new[]{Card("lang_go_func"),Card("lang_go_func")});
|
|
Play(id); Finish((IEnumerator)Call(combat,"EvaluateLazyStackSequenced"));
|
|
Assert.That(Player.Shield,Is.EqualTo(CardScaling.Scale(shield,150,105)));
|
|
Assert.That(combat.HandController.Cards.Count,Is.EqualTo(1));
|
|
Assert.That(combat.Nix.Governor,Is.EqualTo(NixGovernor.Schedutil));
|
|
}
|
|
[Test] public void NixFlakeUpdateAndGoBuildExecuteOnTheirDifferentTracks()
|
|
{
|
|
int before=Target.CurrentUptime; Play("nixos_flake_update"); Assert.That(Target.CurrentUptime,Is.EqualTo(before));
|
|
Finish((IEnumerator)Call(combat,"EvaluateLazyStackSequenced")); Assert.That(before-Target.CurrentUptime,Is.EqualTo(CardScaling.Scale(3,150,105)));
|
|
before=Target.CurrentUptime; Play("shop_go_build"); Assert.That(before-Target.CurrentUptime,Is.EqualTo(CardScaling.Scale(7,105)));
|
|
}
|
|
[TestCase("wave")] [TestCase("loss")] [TestCase("terminate")] [TestCase("new wave")]
|
|
public void EveryCombatBoundaryClearsWorkAndTargets(string boundary)
|
|
{
|
|
var card=Play("lang_go_worker"); var work=combat.Go.Active.Single();
|
|
switch(boundary)
|
|
{
|
|
case "wave": foreach(var enemy in combat.Enemies) { enemy.State.CurrentUptime=0; enemy.State.IsDefeated=true; } Call(combat,"CheckWin"); break;
|
|
case "loss": Player.IsDefeated=true; Call(combat,"CheckLoss"); break;
|
|
case "terminate": Call(combat,"OnDisable"); break;
|
|
default: Finish((IEnumerator)Call(combat,"StartWaveSequenced",true)); break;
|
|
}
|
|
Assert.That(combat.Go.Count,Is.Zero); Assert.That(work.Active,Is.False); Assert.That(work.Target,Is.Null); Assert.That(card.TargetSnapshot,Is.Empty);
|
|
}
|
|
[TestCase(0)] [TestCase(1)] [TestCase(2)] [TestCase(3)]
|
|
public void GoNativeEffectsRespectCountsDrawCapsAndNoGovernorHealing(int count)
|
|
{
|
|
for(int i=0;i<count;i++) Play("lang_go_worker");
|
|
Player.Shield=0; Play("shop_go_waitgroup"); Assert.That(Player.Shield,Is.EqualTo(CardScaling.Scale(3*count,105)));
|
|
int before=Target.CurrentUptime; Play("shop_go_select"); Assert.That(before-Target.CurrentUptime,Is.EqualTo(CardScaling.Scale(3*count,105)));
|
|
combat.DeckController.InitializeInDrawOrder(Enumerable.Range(0,10).Select(_=>Card("lang_go_func")));
|
|
var draw=Card("shop_go_num_goroutines"); draw.ApplyMagnitudeUpgrade(50); combat.HandController.Add(draw);
|
|
int hand=combat.HandController.Cards.Count; Assert.That(combat.PlayCard(draw),Is.True);
|
|
Assert.That(combat.HandController.Cards.Count,Is.EqualTo(hand-1+count));
|
|
hand=combat.HandController.Cards.Count; int shield=Player.Shield; Play("shop_go_gosched");
|
|
Assert.That(combat.HandController.Cards.Count,Is.EqualTo(hand+1)); Assert.That(Player.Shield-shield,Is.EqualTo(count>0?1:0));
|
|
}
|
|
[Test] public void DnfAddsOnceToEachTickAndPackagePlayHooksDoNotRepeat()
|
|
{
|
|
Configure("NixOS",1,new PackageInstance(Asset<PackageDefinition>("Assets/Data/Packages/DNF.asset"),0));
|
|
Play("lang_go_worker"); int bonus=Player.FlatCardDamageBonus; Assert.That(bonus,Is.GreaterThan(0));
|
|
int before=Target.CurrentUptime; Tick(2); Tick(3);
|
|
Assert.That(before-Target.CurrentUptime,Is.EqualTo(2*CardScaling.Scale(3+bonus,105)));
|
|
Assert.That(Player.FlatCardDamageBonus,Is.EqualTo(bonus)); Assert.That(combat.CardsPlayedThisRound,Is.EqualTo(1));
|
|
}
|
|
[Test] public void MintGoShieldCardsRespectExistingDefensiveRestrictions()
|
|
{
|
|
Configure("Mint",1); Play("lang_go_worker"); Play("shop_go_waitgroup"); Play("shop_go_gosched");
|
|
Assert.That(Player.Shield,Is.Zero);
|
|
combat.SelectGoroutine(combat.Go.Active.Single().Id); Play("shop_go_context_cancel"); Assert.That(Player.Shield,Is.Zero);
|
|
}
|
|
[TestCase(false)] [TestCase(true)]
|
|
public void InterpretTicksGoBeforePythonThenHaskellRegardlessOfMotion(bool reducedMotion)
|
|
{
|
|
bool previous = UIPreferences.ReducedMotion;
|
|
var order = new List<Language>();
|
|
void Record(DamageDealtEvent hit) { if (hit.Source == Player) order.Add(hit.Language); }
|
|
try
|
|
{
|
|
UIPreferences.ReducedMotion = reducedMotion;
|
|
Play("lang_go_worker"); Play("lang_py_print"); Play("nixos_flake_update");
|
|
GameEvents.DamageDealt += Record;
|
|
Set(combat, "_turnNumberThisWave", 2); Set(combat, "currentPhase", TurnPhase.Interpret);
|
|
Finish((IEnumerator)Call(combat, "InterpretQueueSequenced"));
|
|
Finish((IEnumerator)Call(combat, "EvaluateLazyStackSequenced"));
|
|
Assert.That(order, Is.EqualTo(new[] { Language.Go, Language.Python, Language.Haskell }));
|
|
Assert.That(combat.Go.Active.Single().RemainingTicks, Is.EqualTo(2));
|
|
Finish((IEnumerator)Call(combat, "InterpretQueueSequenced"));
|
|
Assert.That(order.Count, Is.EqualTo(3), "A repeated Interpret entry cannot tick again.");
|
|
Assert.That(combat.CardsPlayedThisRound, Is.EqualTo(3));
|
|
}
|
|
finally { GameEvents.DamageDealt -= Record; UIPreferences.ReducedMotion = previous; }
|
|
}
|
|
[TestCase("Zram")] [TestCase("SystemdCore")] [TestCase("SystemdTimer")]
|
|
[TestCase("Auditd")] [TestCase("CinnamonPackage")] [TestCase("Ccache")]
|
|
public void GoTicksDoNotReplayEquipmentOrCardHooks(string package)
|
|
{
|
|
Configure("NixOS",1,new PackageInstance(Asset<PackageDefinition>($"Assets/Data/Packages/{package}.asset"),0));
|
|
Call(combat, "ApplyPackageTurnStartEffects");
|
|
for (int i=0;i<3;i++)
|
|
{
|
|
var card=Card("lang_go_worker"); int cost=combat.GetDisplayedPlayCost(card); int before=Player.Cycles;
|
|
combat.HandController.Add(card); combat.SelectEnemy(0); Assert.That(combat.PlayCard(card),Is.True);
|
|
Assert.That(Player.Cycles, Is.EqualTo(before-cost+(package=="SystemdTimer" && i==2 ? 1 : 0)));
|
|
}
|
|
int cycles=Player.Cycles, maxCycles=Player.MaxCycles, shield=Player.Shield, uptime=Player.CurrentUptime;
|
|
int hand=combat.HandController.Cards.Count, events=0;
|
|
void OnPlay(CardPlayedEvent _) => events++;
|
|
GameEvents.CardPlayed += OnPlay;
|
|
try { Tick(2); Tick(3); Tick(4); }
|
|
finally { GameEvents.CardPlayed -= OnPlay; }
|
|
Assert.That(events,Is.Zero); Assert.That(combat.CardsPlayedThisRound,Is.EqualTo(3));
|
|
Assert.That(Player.Cycles,Is.EqualTo(cycles)); Assert.That(Player.MaxCycles,Is.EqualTo(maxCycles));
|
|
Assert.That(Player.Shield,Is.EqualTo(shield)); Assert.That(Player.CurrentUptime,Is.EqualTo(uptime));
|
|
Assert.That(combat.HandController.Cards.Count,Is.EqualTo(hand)); Assert.That(combat.Go.Count,Is.Zero);
|
|
}
|
|
}
|