TowerManager.java 3.09 KB
Newer Older
Akka's avatar
Akka committed
1
2
3
package emu.grasscutter.game.tower;

import dev.morphia.annotations.Entity;
4
import dev.morphia.annotations.Transient;
Akka's avatar
Akka committed
5
import emu.grasscutter.data.GameData;
6
7
8
import emu.grasscutter.data.def.TowerLevelData;
import emu.grasscutter.game.dungeons.DungeonSettleListener;
import emu.grasscutter.game.dungeons.TowerDungeonSettleListener;
Akka's avatar
Akka committed
9
import emu.grasscutter.game.player.Player;
10
import emu.grasscutter.server.packet.send.PacketTowerCurLevelRecordChangeNotify;
Akka's avatar
Akka committed
11

Akka's avatar
Akka committed
12
13
14
15
16
17
import emu.grasscutter.server.packet.send.PacketTowerEnterLevelRsp;

import java.util.List;

@Entity
public class TowerManager {
Akka's avatar
Akka committed
18
    @Transient private Player player;
Akka's avatar
Akka committed
19

Akka's avatar
Akka committed
20
21
22
    public TowerManager(Player player) {
        this.player = player;
    }
Akka's avatar
Akka committed
23

24
25
26
27
28
    public void setPlayer(Player player) {
        this.player = player;
    }

    private int currentFloorId;
Akka's avatar
Akka committed
29
    private int currentLevel;
30
31
32
33
34
35
36
37
38
    @Transient
    private int currentLevelId;

    @Transient
    private int entryScene;

    public int getCurrentFloorId() {
        return currentFloorId;
    }
Akka's avatar
Akka committed
39

40
    private static final List<DungeonSettleListener> towerDungeonSettleListener = List.of(new TowerDungeonSettleListener());
Akka's avatar
Akka committed
41
42
43
    public void teamSelect(int floor, List<List<Long>> towerTeams) {
        var floorData = GameData.getTowerFloorDataMap().get(floor);

44
45
46
47
48
49
50
51
52
53
54
        this.currentFloorId = floorData.getFloorId();
        this.currentLevel = 0;
        this.currentLevelId = GameData.getTowerLevelDataMap().values().stream()
                .filter(x -> x.getLevelId() == floorData.getLevelId() && x.getLevelIndex() == 1)
                .findFirst()
                .map(TowerLevelData::getID)
                .orElse(0);

        if (entryScene == 0){
            entryScene = player.getSceneId();
        }
Akka's avatar
Akka committed
55

Akka's avatar
Akka committed
56
57
58
59
60
61

        player.getTeamManager().setupTemporaryTeam(towerTeams);
    }


    public void enterLevel(int enterPointId) {
62
63
64
        var levelData = GameData.getTowerLevelDataMap().get(currentLevelId + currentLevel);

        this.currentLevel++;
Akka's avatar
Akka committed
65
        var id = levelData.getDungeonId();
66
67

        notifyCurLevelRecordChange();
Akka's avatar
Akka committed
68
69
        // use team user choose
        player.getTeamManager().useTemporaryTeam(0);
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
        player.getServer().getDungeonManager().handoffDungeon(player, id,
                towerDungeonSettleListener);

        // make sure user can exit dungeon correctly
        player.getScene().setPrevScene(entryScene);
        player.getScene().setPrevScenePoint(enterPointId);

        player.getSession().send(new PacketTowerEnterLevelRsp(currentFloorId, currentLevel));

    }

    public void notifyCurLevelRecordChange(){
        player.getSession().send(new PacketTowerCurLevelRecordChangeNotify(currentFloorId, currentLevel));
    }
    public void notifyCurLevelRecordChangeWhenDone(){
        player.getSession().send(new PacketTowerCurLevelRecordChangeNotify(currentFloorId, currentLevel + 1));
    }
    public boolean hasNextLevel(){
        return this.currentLevel < 3;
    }

    public int getNextFloorId() {
        if(hasNextLevel()){
            return 0;
        }
        this.currentFloorId++;
        return this.currentFloorId;
    }
Akka's avatar
Akka committed
98

99
100
    public void clearEntry() {
        this.entryScene = 0;
Akka's avatar
Akka committed
101
102
    }
}