mirror of
https://github.com/Grasscutters/Grasscutter.git
synced 2024-11-23 04:19:43 +00:00
Add command for listing quests
This commit is contained in:
parent
8291e366b9
commit
10c1db2fe1
@ -1,13 +1,15 @@
|
||||
package emu.grasscutter.command.commands;
|
||||
|
||||
import static emu.grasscutter.utils.lang.Language.translate;
|
||||
|
||||
import emu.grasscutter.command.*;
|
||||
import emu.grasscutter.game.player.Player;
|
||||
import emu.grasscutter.game.quest.GameQuest;
|
||||
import java.util.List;
|
||||
import emu.grasscutter.game.quest.enums.*;
|
||||
|
||||
import java.util.*;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
import static emu.grasscutter.utils.lang.Language.translate;
|
||||
|
||||
@Command(
|
||||
label = "quest",
|
||||
aliases = {"q"},
|
||||
@ -15,27 +17,30 @@ import java.util.stream.Collectors;
|
||||
permission = "player.quest",
|
||||
permissionTargeted = "player.quest.others")
|
||||
public final class QuestCommand implements CommandHandler {
|
||||
private static final List<String> SINGLE_ARG = List.of("dungeons", "list");
|
||||
|
||||
@Override
|
||||
public void execute(Player sender, Player targetPlayer, List<String> args) {
|
||||
if (args.size() != 2 || (args.size() == 1 && !args.get(0).toLowerCase().equals("dungeons"))) {
|
||||
if (args.isEmpty()) {
|
||||
sendUsageMessage(sender);
|
||||
return;
|
||||
}
|
||||
|
||||
String cmd = args.get(0).toLowerCase();
|
||||
int questId;
|
||||
var cmd = args.get(0).toLowerCase();
|
||||
int questId = -1;
|
||||
|
||||
try {
|
||||
questId = Integer.parseInt(args.get(1));
|
||||
} catch (Exception e) {
|
||||
CommandHandler.sendMessage(sender, translate(sender, "commands.quest.invalid_id"));
|
||||
return;
|
||||
if (!SINGLE_ARG.contains(cmd)) {
|
||||
try {
|
||||
questId = Integer.parseInt(args.get(1));
|
||||
} catch (Exception e) {
|
||||
CommandHandler.sendMessage(sender, translate(sender, "commands.quest.invalid_id"));
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
switch (cmd) {
|
||||
case "add" -> {
|
||||
GameQuest quest = targetPlayer.getQuestManager().addQuest(questId);
|
||||
var quest = targetPlayer.getQuestManager().addQuest(questId);
|
||||
|
||||
if (quest != null) {
|
||||
CommandHandler.sendMessage(sender, translate(sender, "commands.quest.added", questId));
|
||||
@ -45,7 +50,7 @@ public final class QuestCommand implements CommandHandler {
|
||||
CommandHandler.sendMessage(sender, translate(sender, "commands.quest.not_found"));
|
||||
}
|
||||
case "finish" -> {
|
||||
GameQuest quest = targetPlayer.getQuestManager().getQuestById(questId);
|
||||
var quest = targetPlayer.getQuestManager().getQuestById(questId);
|
||||
|
||||
if (quest == null) {
|
||||
CommandHandler.sendMessage(sender, translate(sender, "commands.quest.not_found"));
|
||||
@ -112,7 +117,7 @@ public final class QuestCommand implements CommandHandler {
|
||||
var shouldAdd = !loggedQuests.contains(questId);
|
||||
|
||||
if (shouldAdd) loggedQuests.add(questId);
|
||||
else loggedQuests.remove(loggedQuests.indexOf(questId));
|
||||
else loggedQuests.remove(questId);
|
||||
|
||||
CommandHandler.sendMessage(
|
||||
sender,
|
||||
@ -147,6 +152,23 @@ public final class QuestCommand implements CommandHandler {
|
||||
.map(entry -> "%s: %s".formatted(entry.getKey(), entry.getValue()))
|
||||
.collect(Collectors.joining(", ")));
|
||||
}
|
||||
case "list" -> {
|
||||
var questManager = targetPlayer.getQuestManager();
|
||||
var mainQuests = questManager.getActiveMainQuests();
|
||||
var allQuestIds = mainQuests.stream()
|
||||
.filter(quest -> questManager.getLoggedQuests().contains(quest.getParentQuestId()))
|
||||
.filter(quest -> quest.getState() != ParentQuestState.PARENT_QUEST_STATE_FINISHED)
|
||||
.map(quest -> quest.getChildQuests().values())
|
||||
.flatMap(Collection::stream)
|
||||
.filter(quest -> quest.getState() == QuestState.QUEST_STATE_UNFINISHED)
|
||||
.map(GameQuest::getSubQuestId)
|
||||
.map(String::valueOf)
|
||||
.toList();
|
||||
|
||||
CommandHandler.sendMessage(sender, "Quests: " +
|
||||
(allQuestIds.isEmpty() ? "(no active quests)" :
|
||||
String.join(", ", allQuestIds)));
|
||||
}
|
||||
default -> this.sendUsageMessage(sender);
|
||||
}
|
||||
}
|
||||
|
@ -113,7 +113,10 @@ public class QuestManager extends BasePlayerManager {
|
||||
|
||||
47001, 47002, 47003, 47004,
|
||||
|
||||
2010103, 2010144 // Prologue Act 2: Chasing Shadows
|
||||
2010103, 2010144, // Prologue Act 2: Chasing Shadows,
|
||||
|
||||
2012 // This is the main quest ID for Chapter 2 Act 1.
|
||||
// Used for debugging giving items.
|
||||
));
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user