mirror of
https://github.com/Grasscutters/Grasscutter.git
synced 2025-12-20 02:45:52 +01:00
Show available story dungeons to the player
This commit is contained in:
@@ -61,16 +61,27 @@ public class DungeonSystem extends BaseGameSystem {
|
||||
}
|
||||
}
|
||||
|
||||
public void getEntryInfo(Player player, int pointId) {
|
||||
ScenePointEntry entry = GameData.getScenePointEntryById(player.getScene().getId(), pointId);
|
||||
|
||||
/**
|
||||
* Sends the entry info for the given dungeon point to the player.
|
||||
*
|
||||
* @param player The player to send the entry info to.
|
||||
* @param pointId The dungeon point ID.
|
||||
*/
|
||||
public void sendEntryInfoFor(Player player, int pointId) {
|
||||
var entry = GameData.getScenePointEntryById(player.getScene().getId(), pointId);
|
||||
if (entry == null) {
|
||||
// Error
|
||||
// An invalid point ID was sent.
|
||||
player.sendPacket(new PacketDungeonEntryInfoRsp());
|
||||
return;
|
||||
}
|
||||
|
||||
player.sendPacket(new PacketDungeonEntryInfoRsp(player, entry.getPointData()));
|
||||
// Check if the player has quests with dungeon IDs.
|
||||
var questDungeons = player.getQuestManager().questsForDungeon(entry);
|
||||
if (questDungeons.size() > 0) {
|
||||
player.sendPacket(new PacketDungeonEntryInfoRsp(entry.getPointData(), questDungeons));
|
||||
} else {
|
||||
player.sendPacket(new PacketDungeonEntryInfoRsp(entry.getPointData()));
|
||||
}
|
||||
}
|
||||
|
||||
public boolean triggerCondition(
|
||||
|
||||
@@ -21,8 +21,11 @@ import emu.grasscutter.server.packet.send.PacketDelQuestNotify;
|
||||
import emu.grasscutter.server.packet.send.PacketQuestListUpdateNotify;
|
||||
import emu.grasscutter.utils.Utils;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import javax.script.Bindings;
|
||||
|
||||
import it.unimi.dsi.fastutil.ints.IntIntImmutablePair;
|
||||
import lombok.Getter;
|
||||
import lombok.Setter;
|
||||
import lombok.val;
|
||||
@@ -281,6 +284,26 @@ public class GameQuest {
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return A list of dungeon IDs associated with the quest's 'QUEST_CONTENT_ENTER_DUNGEON' triggers.
|
||||
* The first element of the pair is the dungeon ID.
|
||||
* The second element of the pair is the dungeon's scene point.
|
||||
*/
|
||||
public List<IntIntImmutablePair> getDungeonIds() {
|
||||
var conditions = this.getQuestData().getFinishCond().stream()
|
||||
.filter(cond -> cond.getType() == QuestContent.QUEST_CONTENT_ENTER_DUNGEON)
|
||||
.toList();
|
||||
|
||||
return conditions.stream()
|
||||
.map(condition -> {
|
||||
var params = condition.getParam();
|
||||
// The first parameter is the ID of the dungeon.
|
||||
// The second parameter is the dungeon entry's scene point.
|
||||
// ex. [1, 1] = dungeon ID 1, scene point 1 or 'KaeyaDungeon'.
|
||||
return new IntIntImmutablePair(params[0], params[1]);
|
||||
}).toList();
|
||||
}
|
||||
|
||||
public void save() {
|
||||
getMainQuest().save();
|
||||
}
|
||||
|
||||
@@ -3,6 +3,7 @@ package emu.grasscutter.game.quest;
|
||||
import emu.grasscutter.Grasscutter;
|
||||
import emu.grasscutter.data.GameData;
|
||||
import emu.grasscutter.data.binout.MainQuestData;
|
||||
import emu.grasscutter.data.binout.ScenePointEntry;
|
||||
import emu.grasscutter.data.excels.QuestData;
|
||||
import emu.grasscutter.database.DatabaseHelper;
|
||||
import emu.grasscutter.game.player.BasePlayerManager;
|
||||
@@ -13,6 +14,7 @@ import emu.grasscutter.utils.Position;
|
||||
import io.netty.util.concurrent.FastThreadLocalThread;
|
||||
import it.unimi.dsi.fastutil.ints.Int2ObjectMap;
|
||||
import it.unimi.dsi.fastutil.ints.Int2ObjectOpenHashMap;
|
||||
import it.unimi.dsi.fastutil.ints.IntIntImmutablePair;
|
||||
import lombok.Getter;
|
||||
import lombok.val;
|
||||
|
||||
@@ -443,4 +445,35 @@ public class QuestManager extends BasePlayerManager {
|
||||
public List<GameMainQuest> getActiveMainQuests() {
|
||||
return getMainQuests().values().stream().filter(p -> !p.isFinished()).toList();
|
||||
}
|
||||
|
||||
/**
|
||||
* Fetches dungeon IDs for quests which have a dungeon.
|
||||
*
|
||||
* @param point The associated scene point of the dungeon.
|
||||
* @return A list of dungeon IDs, or an empty list if none are found.
|
||||
*/
|
||||
public List<Integer> questsForDungeon(ScenePointEntry point) {
|
||||
var pointId = point.getPointData().getId();
|
||||
// Get the active quests.
|
||||
return this.getActiveMainQuests().stream()
|
||||
// Get the sub-quests of the main quest.
|
||||
.map(GameMainQuest::getChildQuests)
|
||||
// Get the values of the sub-quests map.
|
||||
.map(Map::values)
|
||||
.map(quests -> quests.stream()
|
||||
// Get the dungeon IDs of each quest.
|
||||
.map(GameQuest::getDungeonIds)
|
||||
.map(ids -> ids.stream()
|
||||
// Find entry points which match this dungeon.
|
||||
.filter(id -> id.rightInt() == pointId)
|
||||
.toList())
|
||||
.map(ids -> ids.stream()
|
||||
// Of the remaining dungeons, find the ID of the quest dungeon.
|
||||
.map(IntIntImmutablePair::leftInt)
|
||||
.toList())
|
||||
.flatMap(Collection::stream)
|
||||
.toList())
|
||||
.flatMap(Collection::stream)
|
||||
.toList();
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user