Volver al índice

src/main/java/ar/com/companeros/runtime/FocalContactInterpretationTests.java

package ar.com.companeros.runtime;

import java.util.UUID;
import net.minecraft.gametest.framework.GameTest;
import net.minecraft.gametest.framework.GameTestHelper;
import net.minecraftforge.gametest.GameTestHolder;
import net.minecraftforge.gametest.PrefixGameTestTemplate;

/** Gestos Minecraft observados: aportan contexto sin borrar ataques ni regalar protección. */
@GameTestHolder("rapsmovement")
@PrefixGameTestTemplate(false)
public final class FocalContactInterpretationTests {
    @GameTest(template = "empty", batch = "focal_contact_01_peace", timeoutTicks = 20)
    public void lightContactThenObservedCrouchStandProducesOneTemporarySignal(GameTestHelper helper) {
        var signals = new ContactInterpretation.PeaceSignals();
        UUID bot = UUID.randomUUID(), human = UUID.randomUUID(), otherBot = UUID.randomUUID();
        helper.assertTrue(!signals.recordHit(bot, human, false, 1, 20, Long.MAX_VALUE, 100, false),
            "Un toque aislado sigue siendo ambiguo, no un ataque confirmado");
        helper.assertTrue(!signals.hasPeaceSignal(bot, human, 101), "Golpear no fabrica una señal de paz");
        signals.observePosture(bot, human, true, 106); signals.observePosture(bot, human, false, 112);
        helper.assertTrue(signals.hasPeaceSignal(bot, human, 112) && !signals.hasPeaceSignal(otherBot, human, 112),
            "El gesto observado pertenece únicamente al bot que recibió el toque");
        helper.assertTrue(signals.consumePeaceSignal(bot, human, 112) && !signals.consumePeaceSignal(bot, human, 113),
            "La misma evidencia no se consume dos veces");
        signals.recordHit(bot, human, false, 1, 20, Long.MAX_VALUE, 300, false);
        signals.observePosture(bot, human, true, 305); signals.observePosture(bot, human, false, 311);
        helper.assertTrue(signals.hasPeaceSignal(bot, human, 410) && !signals.hasPeaceSignal(bot, human, 411),
            "La señal caduca a los cinco segundos sin alterar daño ni memoria");
        helper.succeed();
    }

    @GameTest(template = "empty", batch = "focal_contact_02_hostility", timeoutTicks = 20)
    public void gesturesCannotExcuseRepeatedArmedSeriousOrCriticalHits(GameTestHelper helper) {
        for (int scenario = 0; scenario < 4; scenario++) {
            var signals = new ContactInterpretation.PeaceSignals();
            UUID bot = UUID.randomUUID(), human = UUID.randomUUID();
            signals.recordHit(bot, human, false, 1, 20, Long.MAX_VALUE, 100, false);
            signals.observePosture(bot, human, true, 104); signals.observePosture(bot, human, false, 109);
            boolean hostile = signals.recordHit(bot, human, scenario == 1, scenario == 2 ? 4 : 1,
                scenario == 3 ? 7 : 20, scenario == 0 ? 15 : Long.MAX_VALUE,
                scenario == 0 ? 115 : 300, false);
            long tick = scenario == 0 ? 115 : 300;
            signals.observePosture(bot, human, true, tick + 2); signals.observePosture(bot, human, false, tick + 5);
            helper.assertTrue(hostile && !signals.hasPeaceSignal(bot, human, tick + 5),
                "Armas, repetición, daño serio y salud crítica invalidan la paz previa: " + scenario);
        }
        helper.succeed();
    }

    @GameTest(template = "empty", batch = "focal_contact_03_observation", timeoutTicks = 20)
    public void oldUnobservedAndSlowGesturesDoNotCountAndHistoryIsBounded(GameTestHelper helper) {
        var signals = new ContactInterpretation.PeaceSignals();
        UUID bot = UUID.randomUUID(), human = UUID.randomUUID();
        signals.observePosture(bot, human, true, 10); signals.observePosture(bot, human, false, 12);
        signals.recordHit(bot, human, false, 1, 20, Long.MAX_VALUE, 100, false);
        signals.observePosture(bot, human, true, 105); signals.observePosture(bot, human, false, 145);
        helper.assertTrue(!signals.hasPeaceSignal(bot, human, 145), "Agacharse largo no es el gesto rápido solicitado");
        signals.observePosture(bot, human, true, 161); signals.observePosture(bot, human, false, 163);
        helper.assertTrue(!signals.hasPeaceSignal(bot, human, 163), "Responder fuera de plazo no explica un golpe anterior");
        signals.recordHit(bot, human, false, 1, 20, Long.MAX_VALUE, 300, true);
        signals.observePosture(bot, human, false, 305);
        helper.assertTrue(!signals.hasPeaceSignal(bot, human, 305), "Estar ya agachado antes del golpe no crea una secuencia posterior");
        for (int i = 0; i < ContactInterpretation.PeaceSignals.MAX_HUMANS; i++)
            signals.recordHit(bot, UUID.randomUUID(), false, 1, 20, Long.MAX_VALUE, 300, false);
        helper.assertTrue(!signals.needsPostureObservation(bot, human, 310), "El historial acotado expulsa la entrada más antigua");
        var bounded = new ContactInterpretation.PeaceSignals();
        bounded.recordHit(bot, human, false, 1, 20, Long.MAX_VALUE, 100, false);
        for (int i = 0; i < ContactInterpretation.PeaceSignals.MAX_BOTS_PER_HUMAN; i++)
            bounded.recordHit(UUID.randomUUID(), human, false, 1, 20, Long.MAX_VALUE, 100, false);
        helper.assertTrue(!bounded.needsPostureObservation(bot, human, 110), "Cada humano tiene también un límite de interlocutores");
        helper.succeed();
    }
}