diff --git a/src/main/java/emu/grasscutter/game/dungeons/DungeonManager.java b/src/main/java/emu/grasscutter/game/dungeons/DungeonManager.java index e0cee6a71..771b45be4 100644 --- a/src/main/java/emu/grasscutter/game/dungeons/DungeonManager.java +++ b/src/main/java/emu/grasscutter/game/dungeons/DungeonManager.java @@ -271,6 +271,20 @@ 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); + } + }); + notifyEndDungeon(true); endDungeon(BaseDungeonResult.DungeonEndReason.COMPLETED); } diff --git a/src/main/java/emu/grasscutter/game/player/PlayerProgress.java b/src/main/java/emu/grasscutter/game/player/PlayerProgress.java index 1a3166ed5..7be8239b5 100644 --- a/src/main/java/emu/grasscutter/game/player/PlayerProgress.java +++ b/src/main/java/emu/grasscutter/game/player/PlayerProgress.java @@ -4,6 +4,9 @@ import dev.morphia.annotations.Entity; import it.unimi.dsi.fastutil.ints.Int2IntOpenHashMap; import it.unimi.dsi.fastutil.ints.Int2ObjectOpenHashMap; import java.util.Map; + +import it.unimi.dsi.fastutil.ints.IntArrayList; +import it.unimi.dsi.fastutil.ints.IntList; import lombok.Getter; import lombok.NoArgsConstructor; import lombok.Setter; @@ -12,9 +15,14 @@ import lombok.val; /** Tracks progress the player made in the world, like obtained items, seen characters and more */ @Entity public class PlayerProgress { - @Getter private Map itemHistory; + /* + * A list of dungeon IDs which have been completed. + * This only applies to one-time dungeons. + */ + @Getter private IntList completedDungeons; + // keep track of EXEC_ADD_QUEST_PROGRESS count, will be used in CONTENT_ADD_QUEST_PROGRESS // not sure where to put this, this should be saved to DB but not to individual quest, since // it will be hard to loop and compare @@ -22,6 +30,7 @@ public class PlayerProgress { public PlayerProgress() { this.questProgressCountMap = new Int2IntOpenHashMap(); + this.completedDungeons = new IntArrayList(); this.itemHistory = new Int2ObjectOpenHashMap<>(); } diff --git a/src/main/java/emu/grasscutter/game/quest/content/ContentFinishDungeon.java b/src/main/java/emu/grasscutter/game/quest/content/ContentFinishDungeon.java index 3197fb72d..d6021e787 100644 --- a/src/main/java/emu/grasscutter/game/quest/content/ContentFinishDungeon.java +++ b/src/main/java/emu/grasscutter/game/quest/content/ContentFinishDungeon.java @@ -6,13 +6,17 @@ import emu.grasscutter.data.excels.QuestData; import emu.grasscutter.game.quest.GameQuest; import emu.grasscutter.game.quest.QuestValueContent; +import java.util.stream.Collectors; + @QuestValueContent(QUEST_CONTENT_FINISH_DUNGEON) public class ContentFinishDungeon extends BaseContent { - // params[0] dungeon ID, params[1] unknown + @Override public boolean execute( GameQuest quest, QuestData.QuestContentCondition condition, String paramStr, int... params) { - return condition.getParam()[0] == params[0]; + var dungeonId = condition.getParam()[0]; + return quest.getOwner().getPlayerProgress() + .getCompletedDungeons().contains(dungeonId); } }