Implement dungeon completion

This commit is contained in:
KingRainbow44 2023-05-01 01:10:15 -04:00
parent aadbc05061
commit 916db0f408
No known key found for this signature in database
GPG Key ID: FC2CB64B00D257BE
3 changed files with 30 additions and 3 deletions

View File

@ -271,6 +271,20 @@ public final class DungeonManager {
} }
public void finishDungeon() { 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); notifyEndDungeon(true);
endDungeon(BaseDungeonResult.DungeonEndReason.COMPLETED); endDungeon(BaseDungeonResult.DungeonEndReason.COMPLETED);
} }

View File

@ -4,6 +4,9 @@ import dev.morphia.annotations.Entity;
import it.unimi.dsi.fastutil.ints.Int2IntOpenHashMap; import it.unimi.dsi.fastutil.ints.Int2IntOpenHashMap;
import it.unimi.dsi.fastutil.ints.Int2ObjectOpenHashMap; import it.unimi.dsi.fastutil.ints.Int2ObjectOpenHashMap;
import java.util.Map; import java.util.Map;
import it.unimi.dsi.fastutil.ints.IntArrayList;
import it.unimi.dsi.fastutil.ints.IntList;
import lombok.Getter; import lombok.Getter;
import lombok.NoArgsConstructor; import lombok.NoArgsConstructor;
import lombok.Setter; 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 */ /** Tracks progress the player made in the world, like obtained items, seen characters and more */
@Entity @Entity
public class PlayerProgress { public class PlayerProgress {
@Getter private Map<Integer, ItemEntry> itemHistory; @Getter private Map<Integer, ItemEntry> 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 // 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 // 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 // it will be hard to loop and compare
@ -22,6 +30,7 @@ public class PlayerProgress {
public PlayerProgress() { public PlayerProgress() {
this.questProgressCountMap = new Int2IntOpenHashMap(); this.questProgressCountMap = new Int2IntOpenHashMap();
this.completedDungeons = new IntArrayList();
this.itemHistory = new Int2ObjectOpenHashMap<>(); this.itemHistory = new Int2ObjectOpenHashMap<>();
} }

View File

@ -6,13 +6,17 @@ import emu.grasscutter.data.excels.QuestData;
import emu.grasscutter.game.quest.GameQuest; import emu.grasscutter.game.quest.GameQuest;
import emu.grasscutter.game.quest.QuestValueContent; import emu.grasscutter.game.quest.QuestValueContent;
import java.util.stream.Collectors;
@QuestValueContent(QUEST_CONTENT_FINISH_DUNGEON) @QuestValueContent(QUEST_CONTENT_FINISH_DUNGEON)
public class ContentFinishDungeon extends BaseContent { public class ContentFinishDungeon extends BaseContent {
// params[0] dungeon ID, params[1] unknown // params[0] dungeon ID, params[1] unknown
@Override @Override
public boolean execute( public boolean execute(
GameQuest quest, QuestData.QuestContentCondition condition, String paramStr, int... params) { 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);
} }
} }