feat: conditional NPC dialogue
Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
This commit is contained in:
@@ -0,0 +1,37 @@
|
||||
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.DialogueLine;
|
||||
import thb.jeanluc.adventure.model.Npc;
|
||||
import thb.jeanluc.adventure.model.Player;
|
||||
import thb.jeanluc.adventure.model.Room;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
|
||||
class DialogueTest {
|
||||
@Test
|
||||
void dialogueSwitchesWithFlagElseGreeting() {
|
||||
Room room = new Room("k", "K", "d");
|
||||
Npc man = Npc.shell("man", "Old Man", "stooped", "Hello there.");
|
||||
man.addDialogue(new DialogueLine(
|
||||
List.of(new Condition(Condition.Type.FLAG, "power_on")),
|
||||
"The lights are back, bless you!"));
|
||||
room.addNpc(man);
|
||||
Player player = new Player(room, 0);
|
||||
TestIO io = new TestIO();
|
||||
GameContext ctx = new GameContext(null, player, io);
|
||||
|
||||
new TalkCommand().execute(ctx, List.of("man"));
|
||||
assertThat(io.allOutput()).contains("Hello there");
|
||||
|
||||
io.outputs().clear();
|
||||
ctx.getState().set("power_on");
|
||||
new TalkCommand().execute(ctx, List.of("man"));
|
||||
assertThat(io.allOutput()).contains("lights are back").doesNotContain("Hello there");
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user