TowerSystem.java 2.71 KB
Newer Older
1
2
3
package emu.grasscutter.game.tower;

import emu.grasscutter.Grasscutter;
4
import emu.grasscutter.data.DataLoader;
5
import emu.grasscutter.data.GameData;
Melledy's avatar
Melledy committed
6
import emu.grasscutter.data.excels.TowerScheduleData;
7
import emu.grasscutter.server.game.BaseGameSystem;
8
9
import emu.grasscutter.server.game.GameServer;

10
import java.util.ArrayList;
11
12
import java.util.List;

13
public class TowerSystem extends BaseGameSystem {
github-actions's avatar
github-actions committed
14

15
16
    public TowerSystem(GameServer server) {
        super(server);
17
18
19
20
21
        this.load();
    }

    private TowerScheduleConfig towerScheduleConfig;

github-actions's avatar
github-actions committed
22
    public synchronized void load() {
23
24
        try {
            towerScheduleConfig = DataLoader.loadClass("TowerSchedule.json", TowerScheduleConfig.class);
25
26
27
28
29
30
31
32
33
        } catch (Exception e) {
            Grasscutter.getLogger().error("Unable to load tower schedule config.", e);
        }
    }

    public TowerScheduleConfig getTowerScheduleConfig() {
        return towerScheduleConfig;
    }

github-actions's avatar
github-actions committed
34
    public TowerScheduleData getCurrentTowerScheduleData() {
35
        var data = GameData.getTowerScheduleDataMap().get(towerScheduleConfig.getScheduleId());
github-actions's avatar
github-actions committed
36
        if (data == null) {
Akka's avatar
Akka committed
37
38
            Grasscutter.getLogger().error("Could not get current tower schedule data by schedule id {}, please check your resource files",
                    towerScheduleConfig.getScheduleId());
39
        }
github-actions's avatar
github-actions committed
40

41
42
43
        return data;
    }

44
45
46
47
48
49
    public List<Integer> getAllFloors() {
        List<Integer> floors = new ArrayList<>(this.getCurrentTowerScheduleData().getEntranceFloorId());
        floors.addAll(this.getScheduleFloors());
        return floors;
    }

50
51
52
53
    public List<Integer> getScheduleFloors() {
        return getCurrentTowerScheduleData().getSchedules().get(0).getFloorList();
    }

github-actions's avatar
github-actions committed
54
    public int getNextFloorId(int floorId) {
55
        var entranceFloors = getCurrentTowerScheduleData().getEntranceFloorId();
56
        var scheduleFloors = getScheduleFloors();
57
        var nextId = 0;
github-actions's avatar
github-actions committed
58

59
        // find in entrance floors first
github-actions's avatar
github-actions committed
60
61
        for (int i=0;i<entranceFloors.size()-1;i++) {
            if (floorId == entranceFloors.get(i)) {
62
63
64
                nextId = entranceFloors.get(i+1);
            }
        }
github-actions's avatar
github-actions committed
65
66

        if (floorId == entranceFloors.get(entranceFloors.size()-1)) {
67
68
            nextId = scheduleFloors.get(0);
        }
github-actions's avatar
github-actions committed
69
70

        if (nextId != 0) {
71
72
            return nextId;
        }
github-actions's avatar
github-actions committed
73

74
        // find in schedule floors
github-actions's avatar
github-actions committed
75
76
        for (int i=0; i < scheduleFloors.size() - 1; i++) {
            if (floorId == scheduleFloors.get(i)) {
77
                nextId = scheduleFloors.get(i + 1);
78
            }
79
        }return nextId;
80
81
82
    }

    public Integer getLastEntranceFloor() {
83
        return getCurrentTowerScheduleData().getEntranceFloorId().get(getCurrentTowerScheduleData().getEntranceFloorId().size() - 1);
84
85
    }
}