mirror of
https://github.com/Grasscutters/Grasscutter.git
synced 2025-12-17 17:34:39 +01:00
Persist Tower Data && Set The Tower Schedule
This commit is contained in:
@@ -12,12 +12,18 @@ public class TowerDungeonSettleListener implements DungeonSettleListener {
|
||||
scene.setAutoCloseTime(Utils.getCurrentSeconds() + 1000);
|
||||
var towerManager = scene.getPlayers().get(0).getTowerManager();
|
||||
|
||||
towerManager.notifyCurLevelRecordChangeWhenDone();
|
||||
scene.broadcastPacket(new PacketTowerFloorRecordChangeNotify(towerManager.getCurrentFloorId()));
|
||||
scene.broadcastPacket(new PacketDungeonSettleNotify(scene.getChallenge(),
|
||||
true,
|
||||
towerManager.notifyCurLevelRecordChangeWhenDone(3);
|
||||
scene.broadcastPacket(new PacketTowerFloorRecordChangeNotify(
|
||||
towerManager.getCurrentFloorId(),
|
||||
3,
|
||||
towerManager.canEnterScheduleFloor()
|
||||
));
|
||||
|
||||
scene.broadcastPacket(new PacketDungeonSettleNotify(
|
||||
scene.getChallenge(),
|
||||
towerManager.hasNextFloor(),
|
||||
towerManager.hasNextLevel(),
|
||||
towerManager.getNextFloorId()
|
||||
towerManager.hasNextLevel() ? 0 : towerManager.getNextFloorId()
|
||||
));
|
||||
|
||||
}
|
||||
|
||||
@@ -0,0 +1,64 @@
|
||||
package emu.grasscutter.game.tower;
|
||||
|
||||
import dev.morphia.annotations.Entity;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
@Entity
|
||||
public class TowerLevelRecord {
|
||||
/**
|
||||
* floorId in config
|
||||
*/
|
||||
private int floorId;
|
||||
/**
|
||||
* LevelId - Stars
|
||||
*/
|
||||
private Map<Integer, Integer> passedLevelMap;
|
||||
|
||||
private int floorStarRewardProgress;
|
||||
|
||||
public TowerLevelRecord setLevelStars(int levelId, int stars){
|
||||
passedLevelMap.put(levelId, stars);
|
||||
return this;
|
||||
}
|
||||
|
||||
public int getStarCount() {
|
||||
return passedLevelMap.values().stream().mapToInt(Integer::intValue).sum();
|
||||
}
|
||||
|
||||
public TowerLevelRecord(){
|
||||
|
||||
}
|
||||
|
||||
public TowerLevelRecord(int floorId){
|
||||
this.floorId = floorId;
|
||||
this.passedLevelMap = new HashMap<>();
|
||||
this.floorStarRewardProgress = 0;
|
||||
}
|
||||
|
||||
public int getFloorId() {
|
||||
return floorId;
|
||||
}
|
||||
|
||||
public void setFloorId(int floorId) {
|
||||
this.floorId = floorId;
|
||||
}
|
||||
|
||||
public Map<Integer, Integer> getPassedLevelMap() {
|
||||
return passedLevelMap;
|
||||
}
|
||||
|
||||
public void setPassedLevelMap(Map<Integer, Integer> passedLevelMap) {
|
||||
this.passedLevelMap = passedLevelMap;
|
||||
}
|
||||
|
||||
public int getFloorStarRewardProgress() {
|
||||
return floorStarRewardProgress;
|
||||
}
|
||||
|
||||
public void setFloorStarRewardProgress(int floorStarRewardProgress) {
|
||||
this.floorStarRewardProgress = floorStarRewardProgress;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -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;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,35 @@
|
||||
package emu.grasscutter.game.tower;
|
||||
|
||||
import java.util.Date;
|
||||
|
||||
public class TowerScheduleConfig {
|
||||
private int scheduleId;
|
||||
|
||||
private Date scheduleStartTime;
|
||||
private Date nextScheduleChangeTime;
|
||||
|
||||
|
||||
public int getScheduleId() {
|
||||
return scheduleId;
|
||||
}
|
||||
|
||||
public void setScheduleId(int scheduleId) {
|
||||
this.scheduleId = scheduleId;
|
||||
}
|
||||
|
||||
public Date getScheduleStartTime() {
|
||||
return scheduleStartTime;
|
||||
}
|
||||
|
||||
public void setScheduleStartTime(Date scheduleStartTime) {
|
||||
this.scheduleStartTime = scheduleStartTime;
|
||||
}
|
||||
|
||||
public Date getNextScheduleChangeTime() {
|
||||
return nextScheduleChangeTime;
|
||||
}
|
||||
|
||||
public void setNextScheduleChangeTime(Date nextScheduleChangeTime) {
|
||||
this.nextScheduleChangeTime = nextScheduleChangeTime;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,75 @@
|
||||
package emu.grasscutter.game.tower;
|
||||
|
||||
import emu.grasscutter.Grasscutter;
|
||||
import emu.grasscutter.data.GameData;
|
||||
import emu.grasscutter.data.def.TowerScheduleData;
|
||||
import emu.grasscutter.server.game.GameServer;
|
||||
|
||||
import java.io.FileReader;
|
||||
import java.util.List;
|
||||
|
||||
public class TowerScheduleManager {
|
||||
private final GameServer gameServer;
|
||||
|
||||
public GameServer getGameServer() {
|
||||
return gameServer;
|
||||
}
|
||||
|
||||
public TowerScheduleManager(GameServer gameServer) {
|
||||
this.gameServer = gameServer;
|
||||
this.load();
|
||||
}
|
||||
|
||||
private TowerScheduleConfig towerScheduleConfig;
|
||||
|
||||
public synchronized void load(){
|
||||
try (FileReader fileReader = new FileReader(Grasscutter.getConfig().DATA_FOLDER + "TowerSchedule.json")) {
|
||||
towerScheduleConfig = Grasscutter.getGsonFactory().fromJson(fileReader, TowerScheduleConfig.class);
|
||||
|
||||
} catch (Exception e) {
|
||||
Grasscutter.getLogger().error("Unable to load tower schedule config.", e);
|
||||
}
|
||||
}
|
||||
|
||||
public TowerScheduleConfig getTowerScheduleConfig() {
|
||||
return towerScheduleConfig;
|
||||
}
|
||||
|
||||
public TowerScheduleData getCurrentTowerScheduleData(){
|
||||
var data = GameData.getTowerScheduleDataMap().get(towerScheduleConfig.getScheduleId());
|
||||
if(data == null){
|
||||
Grasscutter.getLogger().error("Could not get current tower schedule data by config:{}", towerScheduleConfig);
|
||||
}
|
||||
return data;
|
||||
}
|
||||
|
||||
public List<Integer> getScheduleFloors() {
|
||||
return getCurrentTowerScheduleData().getSchedules().get(0).getFloorList();
|
||||
}
|
||||
|
||||
public int getNextFloorId(int floorId){
|
||||
var entranceFloors = getCurrentTowerScheduleData().getEntranceFloorId();
|
||||
var nextId = 0;
|
||||
// find in entrance floors first
|
||||
for(int i=0;i<entranceFloors.size()-1;i++){
|
||||
if(floorId == entranceFloors.get(i)){
|
||||
nextId = entranceFloors.get(i+1);
|
||||
}
|
||||
}
|
||||
if(nextId != 0){
|
||||
return nextId;
|
||||
}
|
||||
var scheduleFloors = getScheduleFloors();
|
||||
// find in schedule floors
|
||||
for(int i=0;i<scheduleFloors.size()-1;i++){
|
||||
if(floorId == scheduleFloors.get(i)){
|
||||
nextId = scheduleFloors.get(i+1);
|
||||
}
|
||||
}
|
||||
return nextId;
|
||||
}
|
||||
|
||||
public Integer getLastEntranceFloor() {
|
||||
return getCurrentTowerScheduleData().getEntranceFloorId().get(getCurrentTowerScheduleData().getEntranceFloorId().size()-1);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user