diff --git a/src/main/java/emu/grasscutter/game/dungeons/DungeonManager.java b/src/main/java/emu/grasscutter/game/dungeons/DungeonManager.java index 771b45be4..23b66312f 100644 --- a/src/main/java/emu/grasscutter/game/dungeons/DungeonManager.java +++ b/src/main/java/emu/grasscutter/game/dungeons/DungeonManager.java @@ -273,17 +273,8 @@ public final class DungeonManager { public void finishDungeon() { // Mark the dungeon has completed for the players. var dungeonId = this.getDungeonData().getId(); - this.getScene().getPlayers().forEach(player -> { - var dungeons = player.getPlayerProgress().getCompletedDungeons(); - if (!dungeons.contains(dungeonId)) { - dungeons.add(dungeonId); - Grasscutter.getLogger().debug("Dungeon {} has been marked completed for {}.", - dungeonId, player.getUid()); - } else { - Grasscutter.getLogger().trace("Player {} already has dungeon {} completed.", - player.getUid(), dungeonId); - } - }); + this.getScene().getPlayers().forEach(player -> player + .getPlayerProgress().markDungeonAsComplete(dungeonId)); notifyEndDungeon(true); endDungeon(BaseDungeonResult.DungeonEndReason.COMPLETED); @@ -294,13 +285,11 @@ public final class DungeonManager { .getPlayers() .forEach( p -> { - // Quest trigger - p.getQuestManager() - .queueEvent( - successfully - ? QuestContent.QUEST_CONTENT_FINISH_DUNGEON - : QuestContent.QUEST_CONTENT_FAIL_DUNGEON, - dungeonData.getId()); + // Trigger the fail event if needed. + if (!successfully) { + p.getQuestManager().queueEvent( + QuestContent.QUEST_CONTENT_FAIL_DUNGEON, dungeonData.getId()); + } // Battle pass trigger if (dungeonData.getType().isCountsToBattlepass() && successfully) { diff --git a/src/main/java/emu/grasscutter/game/player/Player.java b/src/main/java/emu/grasscutter/game/player/Player.java index 41fa751b8..524a6e78b 100644 --- a/src/main/java/emu/grasscutter/game/player/Player.java +++ b/src/main/java/emu/grasscutter/game/player/Player.java @@ -255,7 +255,7 @@ public class Player { this.unlockedSceneAreas = new HashMap<>(); this.unlockedScenePoints = new HashMap<>(); this.chatEmojiIdList = new ArrayList<>(); - this.playerProgress = new PlayerProgress(); + this.playerProgress = new PlayerProgress(this); this.activeQuestTimers = new HashSet<>(); this.attackResults = new LinkedBlockingQueue<>(); diff --git a/src/main/java/emu/grasscutter/game/player/PlayerProgress.java b/src/main/java/emu/grasscutter/game/player/PlayerProgress.java index 5e2bcac0f..eb0d558e8 100644 --- a/src/main/java/emu/grasscutter/game/player/PlayerProgress.java +++ b/src/main/java/emu/grasscutter/game/player/PlayerProgress.java @@ -1,6 +1,9 @@ package emu.grasscutter.game.player; import dev.morphia.annotations.Entity; +import dev.morphia.annotations.Transient; +import emu.grasscutter.Grasscutter; +import emu.grasscutter.game.quest.enums.QuestContent; import it.unimi.dsi.fastutil.ints.Int2IntOpenHashMap; import it.unimi.dsi.fastutil.ints.Int2ObjectOpenHashMap; import java.util.Map; @@ -14,6 +17,8 @@ import lombok.val; /** Tracks progress the player made in the world, like obtained items, seen characters and more */ @Entity public class PlayerProgress { + @Getter @Transient private final Player player; + @Getter private Map itemHistory; /* @@ -27,12 +32,35 @@ public class PlayerProgress { // it will be hard to loop and compare private Map questProgressCountMap; - public PlayerProgress() { + public PlayerProgress(Player player) { + this.player = player; + this.questProgressCountMap = new Int2IntOpenHashMap(); this.completedDungeons = new IntArrayList(); this.itemHistory = new Int2ObjectOpenHashMap<>(); } + /** + * Marks a dungeon as completed. + * Triggers the quest event. + * + * @param dungeonId The dungeon which was completed. + */ + public void markDungeonAsComplete(int dungeonId) { + if (this.getCompletedDungeons().contains(dungeonId)) + return; + + // Mark the dungeon as completed. + this.getCompletedDungeons().add(dungeonId); + // Trigger the completion event. + this.getPlayer().getQuestManager().queueEvent( + QuestContent.QUEST_CONTENT_FINISH_DUNGEON, dungeonId + ); + + Grasscutter.getLogger().debug("Dungeon {} has been marked complete for {}.", + dungeonId, this.getPlayer().getUid()); + } + public boolean hasPlayerObtainedItemHistorically(int itemId) { return itemHistory.containsKey(itemId); }