DungeonManager.java 2.78 KB
Newer Older
Melledy's avatar
Melledy committed
1
2
package emu.grasscutter.game.dungeons;

Melledy's avatar
Melledy committed
3
4
5
6
7
8
9
10
11
import emu.grasscutter.GameConstants;
import emu.grasscutter.Grasscutter;
import emu.grasscutter.data.GameData;
import emu.grasscutter.data.custom.ScenePointEntry;
import emu.grasscutter.data.def.DungeonData;
import emu.grasscutter.game.player.Player;
import emu.grasscutter.game.props.SceneType;
import emu.grasscutter.net.packet.BasePacket;
import emu.grasscutter.net.packet.PacketOpcodes;
Melledy's avatar
Melledy committed
12
import emu.grasscutter.server.game.GameServer;
Melledy's avatar
Melledy committed
13
14
15
import emu.grasscutter.server.packet.send.PacketDungeonEntryInfoRsp;
import emu.grasscutter.server.packet.send.PacketPlayerEnterDungeonRsp;
import emu.grasscutter.utils.Position;
Melledy's avatar
Melledy committed
16
17
18
19
20
21
22
23
24
25
26

public class DungeonManager {
	private final GameServer server;
	
	public DungeonManager(GameServer server) {
		this.server = server;
	}

	public GameServer getServer() {
		return server;
	}
Melledy's avatar
Melledy committed
27
28
29
30

	public void getEntryInfo(Player player, int pointId) {
		ScenePointEntry entry = GameData.getScenePointEntryById(player.getScene().getId(), pointId);
		
31
		if (entry == null) {
Melledy's avatar
Melledy committed
32
33
34
35
36
37
38
39
			// Error
			player.sendPacket(new PacketDungeonEntryInfoRsp());
			return;
		}
		
		player.sendPacket(new PacketDungeonEntryInfoRsp(player, entry.getPointData()));
	}

40
	public boolean enterDungeon(Player player, int pointId, int dungeonId) {
Melledy's avatar
Melledy committed
41
42
43
		DungeonData data = GameData.getDungeonDataMap().get(dungeonId);
		
		if (data == null) {
44
			return false;
Melledy's avatar
Melledy committed
45
46
		}
		
Melledy's avatar
Melledy committed
47
48
		Grasscutter.getLogger().info(player.getNickname() + " is trying to enter dungeon " + dungeonId);
		
Melledy's avatar
Melledy committed
49
		int sceneId = data.getSceneId();
50
		player.getScene().setPrevScene(sceneId);
Melledy's avatar
Melledy committed
51
52
53
		
		player.getWorld().transferPlayerToScene(player, sceneId, data);
		
54
		player.getScene().setPrevScenePoint(pointId);
Melledy's avatar
Melledy committed
55
		player.sendPacket(new PacketPlayerEnterDungeonRsp(pointId, dungeonId));
56
		return true;
Melledy's avatar
Melledy committed
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
	}
	
	public void exitDungeon(Player player) {
		if (player.getScene().getSceneType() != SceneType.SCENE_DUNGEON) {
			return;
		}
		
		// Get previous scene
		int prevScene = player.getScene().getPrevScene() > 0 ? player.getScene().getPrevScene() : 3;
		
		// Get previous position
		DungeonData dungeonData = player.getScene().getDungeonData();
		Position prevPos = new Position(GameConstants.START_POSITION);
		
		if (dungeonData != null) {
72
			ScenePointEntry entry = GameData.getScenePointEntryById(prevScene, player.getScene().getPrevScenePoint());
Melledy's avatar
Melledy committed
73
74
75
76
77
			
			if (entry != null) {
				prevPos.set(entry.getPointData().getTranPos());
			}
		}
Akka's avatar
Akka committed
78
79
		// clean temp team if it has
		player.getTeamManager().cleanTemporaryTeam();
Melledy's avatar
Melledy committed
80
81
82
83
		// Transfer player back to world
		player.getWorld().transferPlayerToScene(player, prevScene, prevPos);
		player.sendPacket(new BasePacket(PacketOpcodes.PlayerQuitDungeonRsp));
	}
84
85
86
87
88
89
	
	public void updateDailyDungeons() {
		for (ScenePointEntry entry : GameData.getScenePointEntries().values()) {
			entry.getPointData().updateDailyDungeon();
		}
	}
Melledy's avatar
Melledy committed
90
}