diff --git a/src/main/java/emu/grasscutter/game/dungeons/DungeonManager.java b/src/main/java/emu/grasscutter/game/dungeons/DungeonManager.java index 367120bb8..011b233a3 100644 --- a/src/main/java/emu/grasscutter/game/dungeons/DungeonManager.java +++ b/src/main/java/emu/grasscutter/game/dungeons/DungeonManager.java @@ -47,8 +47,7 @@ public class DungeonManager { if (data == null) { return false; } - - Grasscutter.getLogger().info(player.getNickname() + " is trying to enter dungeon " + dungeonId); + Grasscutter.getLogger().info("{}({}) is trying to enter dungeon {}" ,player.getNickname(),player.getUid(),dungeonId); int sceneId = data.getSceneId(); player.getScene().setPrevScene(sceneId); @@ -72,7 +71,7 @@ public class DungeonManager { if (data == null) { return false; } - Grasscutter.getLogger().info(player.getNickname() + " is trying to enter tower dungeon " + dungeonId); + Grasscutter.getLogger().info("{}({}) is trying to enter tower dungeon {}" ,player.getNickname(),player.getUid(),dungeonId); if(player.getWorld().transferPlayerToScene(player, data.getSceneId(), data)){ dungeonSettleListeners.forEach(player.getScene()::addDungeonSettleObserver); diff --git a/src/main/java/emu/grasscutter/game/player/Player.java b/src/main/java/emu/grasscutter/game/player/Player.java index 3b90a45a4..c6c7079a2 100644 --- a/src/main/java/emu/grasscutter/game/player/Player.java +++ b/src/main/java/emu/grasscutter/game/player/Player.java @@ -39,6 +39,7 @@ import emu.grasscutter.game.props.SceneType; import emu.grasscutter.game.quest.QuestManager; import emu.grasscutter.game.shop.ShopLimit; import emu.grasscutter.game.managers.MapMarkManager.*; +import emu.grasscutter.game.tower.TowerData; import emu.grasscutter.game.tower.TowerManager; import emu.grasscutter.game.world.Scene; import emu.grasscutter.game.world.World; @@ -118,7 +119,8 @@ public class Player { private TeamManager teamManager; - private TowerManager towerManager; + @Transient private TowerManager towerManager; + private TowerData towerData; private PlayerGachaInfo gachaInfo; private PlayerProfile playerProfile; private boolean showAvatar; @@ -475,11 +477,15 @@ public class Player { public TeamManager getTeamManager() { return this.teamManager; } - + public TowerManager getTowerManager() { return towerManager; } - + + public TowerData getTowerData() { + return towerData; + } + public QuestManager getQuestManager() { return questManager; } @@ -1220,6 +1226,9 @@ public class Player { // Called from tokenrsp public void loadFromDatabase() { // Make sure these exist + if (this.getTowerManager() == null) { + this.towerManager = new TowerManager(this); + } if (this.getTeamManager() == null) { this.teamManager = new TeamManager(this); } @@ -1229,7 +1238,8 @@ public class Player { if (this.getProfile().getUid() == 0) { this.getProfile().syncWithCharacter(this); } - + //Make sure towerManager's player is online player + this.getTowerManager().setPlayer(this); // Load from db this.getAvatars().loadFromDatabase(); this.getInventory().loadFromDatabase(); @@ -1239,12 +1249,6 @@ public class Player { this.getMailHandler().loadFromDatabase(); this.getQuestManager().loadFromDatabase(); - // Add to gameserver (Always handle last) - if (getSession().isActive()) { - getServer().registerPlayer(this); - getProfile().setPlayer(this); // Set online - } - } public void onLogin() { @@ -1255,7 +1259,6 @@ public class Player { if (quest != null) { quest.finish(); } - getQuestManager().addQuest(35101); this.setSceneId(3); @@ -1299,8 +1302,14 @@ public class Player { // Call join event. PlayerJoinEvent event = new PlayerJoinEvent(this); event.call(); - if(event.isCanceled()) // If event is not cancelled, continue. + if(event.isCanceled()){ // If event is not cancelled, continue. session.close(); + return; + } + + // register + getServer().registerPlayer(this); + getProfile().setPlayer(this); // Set online } public void onLogout() { diff --git a/src/main/java/emu/grasscutter/game/tower/TowerData.java b/src/main/java/emu/grasscutter/game/tower/TowerData.java new file mode 100644 index 000000000..df0e35274 --- /dev/null +++ b/src/main/java/emu/grasscutter/game/tower/TowerData.java @@ -0,0 +1,25 @@ +package emu.grasscutter.game.tower; + +import java.util.Map; + +import dev.morphia.annotations.Entity; +import dev.morphia.annotations.Transient; + +@Entity +public class TowerData{ + /** + * the floor players chose + */ + int currentFloorId; + int currentLevel; + @Transient + int currentLevelId; + + /** + * floorId - Record + */ + Map recordMap; + + @Transient + int entryScene; +} diff --git a/src/main/java/emu/grasscutter/game/tower/TowerManager.java b/src/main/java/emu/grasscutter/game/tower/TowerManager.java index ab5e1cf0c..07459f935 100644 --- a/src/main/java/emu/grasscutter/game/tower/TowerManager.java +++ b/src/main/java/emu/grasscutter/game/tower/TowerManager.java @@ -1,7 +1,5 @@ package emu.grasscutter.game.tower; -import dev.morphia.annotations.Entity; -import dev.morphia.annotations.Transient; import emu.grasscutter.data.GameData; import emu.grasscutter.data.excels.TowerLevelData; import emu.grasscutter.game.dungeons.DungeonSettleListener; @@ -13,71 +11,55 @@ import java.util.HashMap; import java.util.List; import java.util.Map; -@Entity public class TowerManager { - @Transient private Player player; - + private Player player; + private TowerData towerData; public TowerManager(Player player) { - this.player = player; + setPlayer(player); } - public void setPlayer(Player player) { this.player = player; + this.towerData = player.getTowerData(); } - /** - * the floor players chose - */ - private int currentFloorId; - private int currentLevel; - @Transient - private int currentLevelId; - - /** - * floorId - Record - */ - private Map recordMap; - - @Transient - private int entryScene; - public int getCurrentFloorId() { - return currentFloorId; + return towerData.currentFloorId; } public int getCurrentLevelId(){ - return this.currentLevelId + currentLevel; + return towerData.currentLevelId + towerData.currentLevel; } /** * form 1-3 */ public int getCurrentLevel(){ - return currentLevel + 1; + return towerData.currentLevel + 1; } private static final List towerDungeonSettleListener = List.of(new TowerDungeonSettleListener()); - + public Map getRecordMap() { - if(recordMap == null){ + Map recordMap = towerData.recordMap; + if(recordMap == null || recordMap.size()==0){ recordMap = new HashMap<>(); recordMap.put(1001, new TowerLevelRecord(1001)); + towerData.recordMap = recordMap; } return recordMap; } public void teamSelect(int floor, List> towerTeams) { var floorData = GameData.getTowerFloorDataMap().get(floor); - - this.currentFloorId = floorData.getFloorId(); - this.currentLevel = 0; - this.currentLevelId = GameData.getTowerLevelDataMap().values().stream() + towerData.currentFloorId = floorData.getFloorId(); + towerData.currentLevel = 0; + towerData.currentLevelId = GameData.getTowerLevelDataMap().values().stream() .filter(x -> x.getLevelGroupId() == floorData.getLevelGroupId() && x.getLevelIndex() == 1) .findFirst() .map(TowerLevelData::getId) .orElse(0); - if (entryScene == 0){ - entryScene = player.getSceneId(); + if (towerData.entryScene == 0){ + towerData.entryScene = player.getSceneId(); } player.getTeamManager().setupTemporaryTeam(towerTeams); @@ -96,20 +78,22 @@ public class TowerManager { towerDungeonSettleListener); // make sure user can exit dungeon correctly - player.getScene().setPrevScene(entryScene); + player.getScene().setPrevScene(towerData.entryScene); player.getScene().setPrevScenePoint(enterPointId); - player.getSession().send(new PacketTowerEnterLevelRsp(currentFloorId, getCurrentLevel())); + player.getSession().send(new PacketTowerEnterLevelRsp(towerData.currentFloorId, getCurrentLevel())); // stop using skill player.getSession().send(new PacketCanUseSkillNotify(false)); // notify the cond of stars - player.getSession().send(new PacketTowerLevelStarCondNotify(currentFloorId, getCurrentLevel())); + player.getSession().send(new PacketTowerLevelStarCondNotify(towerData.currentFloorId, getCurrentLevel())); } public void notifyCurLevelRecordChange(){ - player.getSession().send(new PacketTowerCurLevelRecordChangeNotify(currentFloorId, getCurrentLevel())); + player.getSession().send(new PacketTowerCurLevelRecordChangeNotify(towerData.currentFloorId, getCurrentLevel())); } public void notifyCurLevelRecordChangeWhenDone(int stars){ + Map recordMap = getRecordMap(); + int currentFloorId = towerData.currentFloorId; if(!recordMap.containsKey(currentFloorId)){ recordMap.put(currentFloorId, new TowerLevelRecord(currentFloorId).setLevelStars(getCurrentLevelId(),stars)); @@ -118,7 +102,7 @@ public class TowerManager { recordMap.get(currentFloorId).setLevelStars(getCurrentLevelId(),stars)); } - this.currentLevel++; + towerData.currentLevel++; if(!hasNextLevel()){ // set up the next floor @@ -129,20 +113,21 @@ public class TowerManager { } } public boolean hasNextLevel(){ - return this.currentLevel < 3; + return towerData.currentLevel < 3; } public int getNextFloorId() { - return player.getServer().getTowerScheduleManager().getNextFloorId(this.currentFloorId); + return player.getServer().getTowerScheduleManager().getNextFloorId(towerData.currentFloorId); } public boolean hasNextFloor(){ - return player.getServer().getTowerScheduleManager().getNextFloorId(this.currentFloorId) > 0; + return player.getServer().getTowerScheduleManager().getNextFloorId(towerData.currentFloorId) > 0; } public void clearEntry() { - this.entryScene = 0; + towerData.entryScene = 0; } public boolean canEnterScheduleFloor(){ + Map recordMap = getRecordMap(); if(!recordMap.containsKey(player.getServer().getTowerScheduleManager().getLastEntranceFloor())){ return false; }