mirror of
https://github.com/Melledy/Grasscutter.git
synced 2024-11-23 13:37:42 +00:00
Fix inconformity of Player Object at TowerManager (#1226)
* Fix inconformity of Player Object at TowerManager Fix inconformity of Player Object at TowerManager class from GameSession * fix with a reasonable resolution * Make sure towerManager'player is online player * Make sure towerManager'player is online player * Obsolete storage * Fix build * fix build * fix build * add @Entity * set record map * replace tab with space * add Entity to TowerData * make infomater more accurate * move player register to onLogin
This commit is contained in:
parent
992742d746
commit
f67649e56f
@ -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);
|
||||
|
@ -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;
|
||||
@ -480,6 +482,10 @@ public class Player {
|
||||
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() {
|
||||
|
25
src/main/java/emu/grasscutter/game/tower/TowerData.java
Normal file
25
src/main/java/emu/grasscutter/game/tower/TowerData.java
Normal file
@ -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<Integer, TowerLevelRecord> recordMap;
|
||||
|
||||
@Transient
|
||||
int entryScene;
|
||||
}
|
@ -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<Integer, TowerLevelRecord> 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<DungeonSettleListener> towerDungeonSettleListener = List.of(new TowerDungeonSettleListener());
|
||||
|
||||
public Map<Integer, TowerLevelRecord> getRecordMap() {
|
||||
if(recordMap == null){
|
||||
Map<Integer, TowerLevelRecord> 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<List<Long>> 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<Integer, TowerLevelRecord> 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<Integer, TowerLevelRecord> recordMap = getRecordMap();
|
||||
if(!recordMap.containsKey(player.getServer().getTowerScheduleManager().getLastEntranceFloor())){
|
||||
return false;
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user