mirror of
https://github.com/Grasscutters/Grasscutter.git
synced 2025-01-25 04:43:51 +08:00
Mark dungeons as completed and trigger the event
the event & completion were moved to the same location
This commit is contained in:
parent
62f7fa639a
commit
1786169782
@ -273,17 +273,8 @@ public final class DungeonManager {
|
|||||||
public void finishDungeon() {
|
public void finishDungeon() {
|
||||||
// Mark the dungeon has completed for the players.
|
// Mark the dungeon has completed for the players.
|
||||||
var dungeonId = this.getDungeonData().getId();
|
var dungeonId = this.getDungeonData().getId();
|
||||||
this.getScene().getPlayers().forEach(player -> {
|
this.getScene().getPlayers().forEach(player -> player
|
||||||
var dungeons = player.getPlayerProgress().getCompletedDungeons();
|
.getPlayerProgress().markDungeonAsComplete(dungeonId));
|
||||||
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);
|
||||||
@ -294,13 +285,11 @@ public final class DungeonManager {
|
|||||||
.getPlayers()
|
.getPlayers()
|
||||||
.forEach(
|
.forEach(
|
||||||
p -> {
|
p -> {
|
||||||
// Quest trigger
|
// Trigger the fail event if needed.
|
||||||
p.getQuestManager()
|
if (!successfully) {
|
||||||
.queueEvent(
|
p.getQuestManager().queueEvent(
|
||||||
successfully
|
QuestContent.QUEST_CONTENT_FAIL_DUNGEON, dungeonData.getId());
|
||||||
? QuestContent.QUEST_CONTENT_FINISH_DUNGEON
|
}
|
||||||
: QuestContent.QUEST_CONTENT_FAIL_DUNGEON,
|
|
||||||
dungeonData.getId());
|
|
||||||
|
|
||||||
// Battle pass trigger
|
// Battle pass trigger
|
||||||
if (dungeonData.getType().isCountsToBattlepass() && successfully) {
|
if (dungeonData.getType().isCountsToBattlepass() && successfully) {
|
||||||
|
@ -255,7 +255,7 @@ public class Player {
|
|||||||
this.unlockedSceneAreas = new HashMap<>();
|
this.unlockedSceneAreas = new HashMap<>();
|
||||||
this.unlockedScenePoints = new HashMap<>();
|
this.unlockedScenePoints = new HashMap<>();
|
||||||
this.chatEmojiIdList = new ArrayList<>();
|
this.chatEmojiIdList = new ArrayList<>();
|
||||||
this.playerProgress = new PlayerProgress();
|
this.playerProgress = new PlayerProgress(this);
|
||||||
this.activeQuestTimers = new HashSet<>();
|
this.activeQuestTimers = new HashSet<>();
|
||||||
|
|
||||||
this.attackResults = new LinkedBlockingQueue<>();
|
this.attackResults = new LinkedBlockingQueue<>();
|
||||||
|
@ -1,6 +1,9 @@
|
|||||||
package emu.grasscutter.game.player;
|
package emu.grasscutter.game.player;
|
||||||
|
|
||||||
import dev.morphia.annotations.Entity;
|
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.Int2IntOpenHashMap;
|
||||||
import it.unimi.dsi.fastutil.ints.Int2ObjectOpenHashMap;
|
import it.unimi.dsi.fastutil.ints.Int2ObjectOpenHashMap;
|
||||||
import java.util.Map;
|
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 */
|
/** Tracks progress the player made in the world, like obtained items, seen characters and more */
|
||||||
@Entity
|
@Entity
|
||||||
public class PlayerProgress {
|
public class PlayerProgress {
|
||||||
|
@Getter @Transient private final Player player;
|
||||||
|
|
||||||
@Getter private Map<Integer, ItemEntry> itemHistory;
|
@Getter private Map<Integer, ItemEntry> itemHistory;
|
||||||
|
|
||||||
/*
|
/*
|
||||||
@ -27,12 +32,35 @@ public class PlayerProgress {
|
|||||||
// it will be hard to loop and compare
|
// it will be hard to loop and compare
|
||||||
private Map<Integer, Integer> questProgressCountMap;
|
private Map<Integer, Integer> questProgressCountMap;
|
||||||
|
|
||||||
public PlayerProgress() {
|
public PlayerProgress(Player player) {
|
||||||
|
this.player = player;
|
||||||
|
|
||||||
this.questProgressCountMap = new Int2IntOpenHashMap();
|
this.questProgressCountMap = new Int2IntOpenHashMap();
|
||||||
this.completedDungeons = new IntArrayList();
|
this.completedDungeons = new IntArrayList();
|
||||||
this.itemHistory = new Int2ObjectOpenHashMap<>();
|
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) {
|
public boolean hasPlayerObtainedItemHistorically(int itemId) {
|
||||||
return itemHistory.containsKey(itemId);
|
return itemHistory.containsKey(itemId);
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user