mirror of
https://github.com/Grasscutters/Grasscutter.git
synced 2026-02-07 02:26:43 +01:00
Persist Tower Data && Set The Tower Schedule
This commit is contained in:
@@ -9,10 +9,12 @@ import emu.grasscutter.game.dungeons.TowerDungeonSettleListener;
|
||||
import emu.grasscutter.game.player.Player;
|
||||
import emu.grasscutter.server.packet.send.PacketCanUseSkillNotify;
|
||||
import emu.grasscutter.server.packet.send.PacketTowerCurLevelRecordChangeNotify;
|
||||
|
||||
import emu.grasscutter.server.packet.send.PacketTowerEnterLevelRsp;
|
||||
import emu.grasscutter.server.packet.send.PacketTowerLevelStarCondNotify;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
@Entity
|
||||
public class TowerManager {
|
||||
@@ -26,11 +28,19 @@ public class TowerManager {
|
||||
this.player = player;
|
||||
}
|
||||
|
||||
/**
|
||||
* the floor players chose
|
||||
*/
|
||||
private int currentFloorId;
|
||||
private int currentLevel;
|
||||
@Transient
|
||||
private int currentLevelId;
|
||||
|
||||
/**
|
||||
* floorId - Record
|
||||
*/
|
||||
private Map<Integer, TowerLevelRecord> recordMap;
|
||||
|
||||
@Transient
|
||||
private int entryScene;
|
||||
|
||||
@@ -38,7 +48,26 @@ public class TowerManager {
|
||||
return currentFloorId;
|
||||
}
|
||||
|
||||
public int getCurrentLevelId(){
|
||||
return this.currentLevelId + currentLevel;
|
||||
}
|
||||
|
||||
/**
|
||||
* form 1-3
|
||||
*/
|
||||
public int getCurrentLevel(){
|
||||
return currentLevel + 1;
|
||||
}
|
||||
private static final List<DungeonSettleListener> towerDungeonSettleListener = List.of(new TowerDungeonSettleListener());
|
||||
|
||||
public Map<Integer, TowerLevelRecord> getRecordMap() {
|
||||
if(recordMap == null){
|
||||
recordMap = new HashMap<>();
|
||||
recordMap.put(1001, new TowerLevelRecord(1001));
|
||||
}
|
||||
return recordMap;
|
||||
}
|
||||
|
||||
public void teamSelect(int floor, List<List<Long>> towerTeams) {
|
||||
var floorData = GameData.getTowerFloorDataMap().get(floor);
|
||||
|
||||
@@ -54,51 +83,73 @@ public class TowerManager {
|
||||
entryScene = player.getSceneId();
|
||||
}
|
||||
|
||||
|
||||
player.getTeamManager().setupTemporaryTeam(towerTeams);
|
||||
}
|
||||
|
||||
|
||||
public void enterLevel(int enterPointId) {
|
||||
var levelData = GameData.getTowerLevelDataMap().get(currentLevelId + currentLevel);
|
||||
var levelData = GameData.getTowerLevelDataMap().get(getCurrentLevelId());
|
||||
|
||||
this.currentLevel++;
|
||||
var id = levelData.getDungeonId();
|
||||
var dungeonId = levelData.getDungeonId();
|
||||
|
||||
notifyCurLevelRecordChange();
|
||||
// use team user choose
|
||||
player.getTeamManager().useTemporaryTeam(0);
|
||||
player.getServer().getDungeonManager().handoffDungeon(player, id,
|
||||
player.getServer().getDungeonManager().handoffDungeon(player, dungeonId,
|
||||
towerDungeonSettleListener);
|
||||
|
||||
// make sure user can exit dungeon correctly
|
||||
player.getScene().setPrevScene(entryScene);
|
||||
player.getScene().setPrevScenePoint(enterPointId);
|
||||
|
||||
player.getSession().send(new PacketTowerEnterLevelRsp(currentFloorId, currentLevel));
|
||||
player.getSession().send(new PacketTowerEnterLevelRsp(currentFloorId, getCurrentLevel()));
|
||||
// stop using skill
|
||||
player.getSession().send(new PacketCanUseSkillNotify(false));
|
||||
// notify the cond of stars
|
||||
player.getSession().send(new PacketTowerLevelStarCondNotify(currentFloorId, getCurrentLevel()));
|
||||
}
|
||||
|
||||
public void notifyCurLevelRecordChange(){
|
||||
player.getSession().send(new PacketTowerCurLevelRecordChangeNotify(currentFloorId, currentLevel));
|
||||
player.getSession().send(new PacketTowerCurLevelRecordChangeNotify(currentFloorId, getCurrentLevel()));
|
||||
}
|
||||
public void notifyCurLevelRecordChangeWhenDone(){
|
||||
player.getSession().send(new PacketTowerCurLevelRecordChangeNotify(currentFloorId, currentLevel + 1));
|
||||
public void notifyCurLevelRecordChangeWhenDone(int stars){
|
||||
if(!recordMap.containsKey(currentFloorId)){
|
||||
recordMap.put(currentFloorId,
|
||||
new TowerLevelRecord(currentFloorId).setLevelStars(getCurrentLevelId(),stars));
|
||||
}else{
|
||||
recordMap.put(currentFloorId,
|
||||
recordMap.get(currentFloorId).setLevelStars(getCurrentLevelId(),stars));
|
||||
}
|
||||
|
||||
this.currentLevel++;
|
||||
|
||||
if(!hasNextLevel()){
|
||||
// set up the next floor
|
||||
recordMap.put(getNextFloorId(), new TowerLevelRecord(getNextFloorId()));
|
||||
player.getSession().send(new PacketTowerCurLevelRecordChangeNotify(getNextFloorId(), 1));
|
||||
}else{
|
||||
player.getSession().send(new PacketTowerCurLevelRecordChangeNotify(currentFloorId, getCurrentLevel()));
|
||||
}
|
||||
}
|
||||
public boolean hasNextLevel(){
|
||||
return this.currentLevel < 3;
|
||||
}
|
||||
|
||||
public int getNextFloorId() {
|
||||
if(hasNextLevel()){
|
||||
return 0;
|
||||
}
|
||||
this.currentFloorId++;
|
||||
return this.currentFloorId;
|
||||
return player.getServer().getTowerScheduleManager().getNextFloorId(this.currentFloorId);
|
||||
}
|
||||
public boolean hasNextFloor(){
|
||||
return player.getServer().getTowerScheduleManager().getNextFloorId(this.currentFloorId) > 0;
|
||||
}
|
||||
|
||||
public void clearEntry() {
|
||||
this.entryScene = 0;
|
||||
}
|
||||
|
||||
public boolean canEnterScheduleFloor(){
|
||||
if(!recordMap.containsKey(player.getServer().getTowerScheduleManager().getLastEntranceFloor())){
|
||||
return false;
|
||||
}
|
||||
return recordMap.get(player.getServer().getTowerScheduleManager().getLastEntranceFloor())
|
||||
.getStarCount() >= 6;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user