feat: NPC reactions gated by conditions, applying effects

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
This commit is contained in:
2026-05-31 21:57:23 +02:00
parent 268c24d4e3
commit 258ab4f63b
5 changed files with 70 additions and 1 deletions

View File

@@ -0,0 +1,42 @@
package thb.jeanluc.adventure.command.impl;
import org.junit.jupiter.api.Test;
import thb.jeanluc.adventure.game.GameContext;
import thb.jeanluc.adventure.io.TestIO;
import thb.jeanluc.adventure.model.Condition;
import thb.jeanluc.adventure.model.Effect;
import thb.jeanluc.adventure.model.Npc;
import thb.jeanluc.adventure.model.NpcReaction;
import thb.jeanluc.adventure.model.Player;
import thb.jeanluc.adventure.model.Room;
import thb.jeanluc.adventure.model.item.PlainItem;
import java.util.List;
import static org.assertj.core.api.Assertions.assertThat;
class ReactionEffectsTest {
@Test
void reactionRequiresFlagAndAppliesEffects() {
Room room = new Room("k", "K", "d");
Npc man = Npc.shell("man", "Old Man", "stooped", "hi");
man.putReaction("fuse", NpcReaction.builder()
.requires(List.of(new Condition(Condition.Type.FLAG, "cellar_drained")))
.effects(List.of(new Effect(Effect.Type.SET_FLAG, "fuse_installed")))
.response("Done.")
.build());
room.addNpc(man);
Player player = new Player(room, 0);
player.addItem(PlainItem.builder().id("fuse").name("Fuse").description("d").build());
TestIO io = new TestIO();
GameContext ctx = new GameContext(null, player, io);
new GiveCommand().execute(ctx, List.of("fuse", "man"));
assertThat(ctx.getState().isSet("fuse_installed")).isFalse(); // requires not met
ctx.getState().set("cellar_drained");
new GiveCommand().execute(ctx, List.of("fuse", "man"));
assertThat(ctx.getState().isSet("fuse_installed")).isTrue();
assertThat(io.allOutput()).contains("Done.");
}
}