feat(game): Quest model, QuestLog, START_QUEST effect
Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
This commit is contained in:
@@ -27,6 +27,7 @@ public final class Effects {
|
||||
}
|
||||
case REMOVE_ITEM -> ctx.getPlayer().removeItem(e.arg());
|
||||
case SAY -> ctx.getIo().write(e.arg());
|
||||
case START_QUEST -> ctx.getQuestLog().start(e.arg());
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -26,4 +26,7 @@ public class GameContext {
|
||||
|
||||
/** Mutable world flags. Created fresh per context; not a constructor arg. */
|
||||
private final GameState state = new GameState();
|
||||
|
||||
/** Runtime quest progress. Created fresh per context; not a constructor arg. */
|
||||
private final QuestLog questLog = new QuestLog();
|
||||
}
|
||||
|
||||
@@ -0,0 +1,49 @@
|
||||
package thb.jeanluc.adventure.game;
|
||||
|
||||
import java.util.Collections;
|
||||
import java.util.LinkedHashMap;
|
||||
import java.util.LinkedHashSet;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
|
||||
/** Runtime quest progress: current stage per active quest, plus completed ids. */
|
||||
public class QuestLog {
|
||||
|
||||
private final Map<String, Integer> stageIndex = new LinkedHashMap<>();
|
||||
private final Set<String> completed = new LinkedHashSet<>();
|
||||
|
||||
public void start(String id) {
|
||||
if (!completed.contains(id)) {
|
||||
stageIndex.putIfAbsent(id, 0);
|
||||
}
|
||||
}
|
||||
|
||||
public boolean isActive(String id) {
|
||||
return stageIndex.containsKey(id);
|
||||
}
|
||||
|
||||
public boolean isCompleted(String id) {
|
||||
return completed.contains(id);
|
||||
}
|
||||
|
||||
public int stageIndex(String id) {
|
||||
return stageIndex.getOrDefault(id, 0);
|
||||
}
|
||||
|
||||
public void advance(String id) {
|
||||
stageIndex.merge(id, 1, Integer::sum);
|
||||
}
|
||||
|
||||
public void complete(String id) {
|
||||
stageIndex.remove(id);
|
||||
completed.add(id);
|
||||
}
|
||||
|
||||
public Set<String> active() {
|
||||
return Collections.unmodifiableSet(stageIndex.keySet());
|
||||
}
|
||||
|
||||
public Set<String> completed() {
|
||||
return Collections.unmodifiableSet(completed);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user