Volver al índice
src/main/java/ar/com/companeros/horror/HorrorPacingTests.java
package ar.com.companeros.horror;
import ar.com.companeros.Companeros;
import java.util.UUID;
import net.minecraft.gametest.framework.*;
import net.minecraft.nbt.CompoundTag;
import net.minecraftforge.gametest.*;
@GameTestHolder(Companeros.ID)
@PrefixGameTestTemplate(false)
public final class HorrorPacingTests {
@GameTest(template = "empty", timeoutTicks = 20)
public void selectedHuntDurationIsBoundedAnchoredAndPersistent(GameTestHelper helper) {
for (int seconds : new int[]{30, 60, 90, 180}) {
HorrorPacing pacing = new HorrorPacing(); UUID player = UUID.randomUUID(); pacing.intensity(100);
helper.assertTrue(pacing.selectHuntDuration(player, 0, seconds), "Acepta una duración elegida dentro del rango");
helper.assertTrue(!pacing.selectedHuntActive(player, 0), "El reloj espera al inicio físico de la cacería");
pacing.hunting(player, 100);
long end = 100 + seconds * 20L;
helper.assertTrue(pacing.selectHuntDuration(player, 200, seconds), "Repetir la decisión mantiene el intervalo elegido");
HorrorPacing copy = HorrorPacing.load(pacing.save(new CompoundTag()));
helper.assertTrue(copy.mayAttack(player, end - 1, 4) && copy.selectedHuntRemainingTicks(player, end - 1) == 1,
"El intervalo sobrevive al reinicio y permite superar la ventana de acecho sin reiniciar el reloj");
helper.assertTrue(!copy.mayAttack(player, end, 4), "La cacería termina en su límite original");
copy.release(player, end);
helper.assertTrue(!copy.available(player, end + 1) && !copy.selectHuntDuration(player, end + 1, seconds),
"Elegir otro intervalo no anula el descanso posterior");
}
HorrorPacing bounded = new HorrorPacing(); UUID id = UUID.randomUUID();
for (int invalid : new int[]{29, 181}) {
boolean rejected = false;
try { bounded.selectHuntDuration(id, 0, invalid); } catch (IllegalArgumentException expected) { rejected = true; }
helper.assertTrue(rejected, "Rechaza duraciones fuera de30..180 segundos");
}
helper.succeed();
}
@GameTest(template = "empty", timeoutTicks = 20)
public void maximumIntensityEscalatesAnOutdoorStationaryVisit(GameTestHelper helper) {
HorrorPacing pacing = new HorrorPacing(); UUID player = UUID.randomUUID();
pacing.intensity(100); pacing.begin(player, 0);
for (int tick = 0; tick <= 400; tick += 20) pacing.observe(player, tick, false, false);
helper.assertTrue(pacing.mayAttack(player, 400, 4),
"Quedarse quieto al aire libre no impide que una visita a máxima intensidad escale en veinte segundos");
helper.assertTrue(!pacing.mayAttack(player, 400, 1), "La intensidad no salta las etapas de maduración");
helper.succeed();
}
@GameTest(template = "empty", timeoutTicks = 20)
public void realProvocationRenewsAnExpiredVisitWithoutBotheringBystanders(GameTestHelper helper) {
HorrorPacing pacing = new HorrorPacing(); UUID attacker = UUID.randomUUID(), bystander = UUID.randomUUID();
pacing.intensity(100); pacing.begin(attacker, 0); pacing.hunting(attacker, 0); pacing.release(bystander, 2800);
CompoundTag saved = pacing.save(new CompoundTag());
for (net.minecraft.nbt.Tag item : saved.getList("Players", net.minecraft.nbt.Tag.TAG_COMPOUND)) {
CompoundTag row = (CompoundTag)item;
if (row.getUUID("Id").equals(attacker)) row.putFloat("Burden", 80);
}
HorrorPacing restored = HorrorPacing.load(saved);
restored.provoked(attacker, 3000);
helper.assertTrue(restored.mayAttack(attacker, 3000, 4),
"El atacante real no queda protegido por una visita antigua ni por su presupuesto de sustos agotado");
helper.assertTrue(!restored.available(bystander, 3000), "El espectador conserva su descanso");
restored.intensity(0); restored.provoked(attacker, 3020);
helper.assertTrue(!restored.mayAttack(attacker, 3020, 4), "La provocación respeta intensidad cero");
helper.succeed();
}
@GameTest(template = "empty", timeoutTicks = 20)
public void cavesEscalateButHitsDoNotCancelTheHunt(GameTestHelper helper) {
HorrorPacing pacing = new HorrorPacing(); UUID player = UUID.randomUUID();
pacing.intensity(60); pacing.begin(player, 0);
for (int tick = 0; tick <= 1000; tick += 20) pacing.observe(player, tick, true, false);
helper.assertTrue(pacing.mayAttack(player, 1000, 4), "Una visita prolongada a una cueva debe poder convertirse en cacería");
for (int hit = 0; hit < 8; hit++) pacing.hit(player);
helper.assertTrue(pacing.mayAttack(player, 1000, 4), "No existe un límite de dos golpes ni de ocho golpes");
pacing.killed(player, 1000);
helper.assertTrue(!pacing.available(player, 12999) && pacing.available(player, 13000), "La víctima descansa diez minutos tras morir");
helper.succeed();
}
@GameTest(template = "empty", timeoutTicks = 20)
public void spontaneousHuntKeepsItsFullDurationAfterLongStalking(GameTestHelper helper) {
for (int intensity : new int[]{35, 60, 100}) {
HorrorPacing pacing = new HorrorPacing(); UUID player = UUID.randomUUID();
pacing.intensity(intensity); pacing.begin(player, 0);
int start = (int)pacing.windowTicks() - 20;
for (int tick = 0; tick <= start; tick += 20) pacing.observe(player, tick, true, false);
helper.assertTrue(pacing.mayAttack(player, start, 4), "El acecho escala antes de iniciar la cacería");
pacing.hunting(player, start);
long duration = 20L * (intensity < 40 ? 60 : intensity < 75 ? 90 : 180);
HorrorPacing restored = HorrorPacing.load(pacing.save(new CompoundTag()));
for (int hit = 0; hit < 8; hit++) restored.hit(player);
restored.hunting(player, start + 100);
helper.assertTrue(restored.mayAttack(player, start + duration - 1, 4),
"El acecho previo, los golpes y el reinicio no acortan la cacería");
helper.assertTrue(!restored.mayAttack(player, start + duration, 4),
"La cacería termina en el reloj original y no se renueva al avanzar");
}
helper.succeed();
}
@GameTest(template = "empty", timeoutTicks = 20)
public void restartKeepsRestAndSoundBudgetAndZeroIsQuiet(GameTestHelper helper) {
HorrorPacing pacing = new HorrorPacing(); UUID a = UUID.randomUUID(), b = UUID.randomUUID();
pacing.begin(a, 0); helper.assertTrue(pacing.reserveSound(a, 20), "El primer sonido puede entregarse");
pacing.release(a, 30);
HorrorPacing copy = HorrorPacing.load(pacing.save(new CompoundTag()));
helper.assertTrue(!copy.available(a, 40) && copy.available(b, 40), "Dar descanso a una persona no excluye a otra");
helper.assertTrue(!copy.reserveSound(a, 40), "El reinicio no reinicia los avisos");
copy.intensity(0);
helper.assertTrue(!copy.available(b, 50) && !copy.mayAttack(b, 50, 4) && !copy.reserveSound(b, 50), "Cero desactiva ataques y avisos");
helper.succeed();
}
@GameTest(template = "empty", timeoutTicks = 20)
public void sleepBuildsTensionWithoutEveryTickSpamming(GameTestHelper helper) {
HorrorPacing pacing = new HorrorPacing(); UUID player = UUID.randomUUID(); pacing.begin(player, 0);
pacing.observe(player, 0, false, true); String first = pacing.describe(player, 0);
for (int index = 0; index < 100; index++) pacing.observe(player, 0, false, true);
helper.assertTrue(first.equals(pacing.describe(player, 0)), "Dormir no suma el mismo acontecimiento cien veces");
helper.assertTrue(pacing.reserveSound(player, 0) && !pacing.reserveSound(player, 20), "El siguiente segundo no repite el aviso");
helper.assertTrue(!pacing.mayAttack(player, 0, 4), "Dormirse una vez no provoca un ataque inmediato");
helper.succeed();
}
}