TowerManager.java 3.25 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.PacketCanUseSkillNotify;
11
import emu.grasscutter.server.packet.send.PacketTowerCurLevelRecordChangeNotify;
Akka's avatar
Akka committed
12

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

import java.util.List;

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

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

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

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

    @Transient
    private int entryScene;

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

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

45
46
47
48
49
50
51
52
53
54
55
        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
56

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

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


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

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

        notifyCurLevelRecordChange();
Akka's avatar
Akka committed
69
70
        // use team user choose
        player.getTeamManager().useTemporaryTeam(0);
71
72
73
74
75
76
77
78
        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));
79
80
        // stop using skill
        player.getSession().send(new PacketCanUseSkillNotify(false));
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
    }

    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
100

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