forked from Grasscutters/Grasscutter
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Tower Dungeons Handoff between level and floor
- Loading branch information
Showing
14 changed files
with
305 additions
and
29 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
syntax = "proto3"; | ||
|
||
option java_package = "emu.grasscutter.net.proto"; | ||
|
||
import "TowerFloorRecord.proto"; | ||
|
||
message TowerFloorRecordChangeNotify { | ||
enum CmdId { | ||
option allow_alias = true; | ||
NONE = 0; | ||
ENET_CHANNEL_ID = 0; | ||
ENET_IS_RELIABLE = 1; | ||
CMD_ID = 2418; | ||
} | ||
|
||
repeated TowerFloorRecord tower_floor_record_list = 1; | ||
bool is_finished_entrance_floor = 2; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
syntax = "proto3"; | ||
|
||
option java_package = "emu.grasscutter.net.proto"; | ||
import "ItemParam.proto"; | ||
|
||
message TowerLevelEndNotify { | ||
enum CmdId { | ||
option allow_alias = true; | ||
NONE = 0; | ||
ENET_CHANNEL_ID = 0; | ||
ENET_IS_RELIABLE = 1; | ||
CMD_ID = 2456; | ||
} | ||
|
||
enum ContinueStateType { | ||
CONTINUE_STATE_CAN_NOT_CONTINUE = 0; | ||
CONTINUE_STATE_CAN_ENTER_NEXT_LEVEL = 1; | ||
CONTINUE_STATE_CAN_ENTER_NEXT_FLOOR = 2; | ||
} | ||
|
||
bool is_success = 1; | ||
repeated uint32 finished_star_cond_list = 2; | ||
repeated ItemParam reward_item_list = 3; | ||
uint32 continue_state = 4; | ||
uint32 next_floor_id = 5; | ||
} |
14 changes: 14 additions & 0 deletions
14
src/main/java/emu/grasscutter/game/dungeons/BasicDungeonSettleListener.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
package emu.grasscutter.game.dungeons; | ||
|
||
import emu.grasscutter.game.world.Scene; | ||
import emu.grasscutter.server.packet.send.PacketDungeonSettleNotify; | ||
import emu.grasscutter.utils.Utils; | ||
|
||
public class BasicDungeonSettleListener implements DungeonSettleListener { | ||
|
||
@Override | ||
public void onDungeonSettle(Scene scene) { | ||
scene.setAutoCloseTime(Utils.getCurrentSeconds() + 1000); | ||
scene.broadcastPacket(new PacketDungeonSettleNotify(scene.getChallenge())); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
7 changes: 7 additions & 0 deletions
7
src/main/java/emu/grasscutter/game/dungeons/DungeonSettleListener.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
package emu.grasscutter.game.dungeons; | ||
|
||
import emu.grasscutter.game.world.Scene; | ||
|
||
public interface DungeonSettleListener { | ||
void onDungeonSettle(Scene scene); | ||
} |
24 changes: 24 additions & 0 deletions
24
src/main/java/emu/grasscutter/game/dungeons/TowerDungeonSettleListener.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
package emu.grasscutter.game.dungeons; | ||
|
||
import emu.grasscutter.game.world.Scene; | ||
import emu.grasscutter.server.packet.send.PacketDungeonSettleNotify; | ||
import emu.grasscutter.server.packet.send.PacketTowerFloorRecordChangeNotify; | ||
import emu.grasscutter.utils.Utils; | ||
|
||
public class TowerDungeonSettleListener implements DungeonSettleListener { | ||
|
||
@Override | ||
public void onDungeonSettle(Scene scene) { | ||
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.hasNextLevel(), | ||
towerManager.getNextFloorId() | ||
)); | ||
|
||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
76 changes: 68 additions & 8 deletions
76
src/main/java/emu/grasscutter/game/tower/TowerManager.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,40 +1,100 @@ | ||
package emu.grasscutter.game.tower; | ||
|
||
import dev.morphia.annotations.Entity; | ||
import dev.morphia.annotations.Transient; | ||
import emu.grasscutter.data.GameData; | ||
import emu.grasscutter.data.def.TowerLevelData; | ||
import emu.grasscutter.game.dungeons.DungeonSettleListener; | ||
import emu.grasscutter.game.dungeons.TowerDungeonSettleListener; | ||
import emu.grasscutter.game.player.Player; | ||
import emu.grasscutter.server.packet.send.PacketTowerCurLevelRecordChangeNotify; | ||
import emu.grasscutter.server.packet.send.PacketTowerEnterLevelRsp; | ||
|
||
import java.util.List; | ||
|
||
@Entity | ||
public class TowerManager { | ||
private final Player player; | ||
@Transient | ||
private Player player; | ||
|
||
public TowerManager(Player player) { | ||
this.player = player; | ||
} | ||
public void setPlayer(Player player) { | ||
this.player = player; | ||
} | ||
|
||
private int currentFloorId; | ||
private int currentLevel; | ||
private int currentFloor; | ||
@Transient | ||
private int currentLevelId; | ||
|
||
@Transient | ||
private int entryScene; | ||
|
||
public int getCurrentFloorId() { | ||
return currentFloorId; | ||
} | ||
|
||
private static final List<DungeonSettleListener> towerDungeonSettleListener = List.of(new TowerDungeonSettleListener()); | ||
public void teamSelect(int floor, List<List<Long>> towerTeams) { | ||
var floorData = GameData.getTowerFloorDataMap().get(floor); | ||
|
||
this.currentFloor = floorData.getFloorId(); | ||
this.currentLevel = floorData.getLevelId(); | ||
this.currentFloorId = floorData.getFloorId(); | ||
this.currentLevel = 0; | ||
this.currentLevelId = GameData.getTowerLevelDataMap().values().stream() | ||
.filter(x -> x.getLevelId() == floorData.getLevelId() && x.getLevelIndex() == 1) | ||
.findFirst() | ||
.map(TowerLevelData::getID) | ||
.orElse(0); | ||
|
||
if (entryScene == 0){ | ||
entryScene = player.getSceneId(); | ||
} | ||
|
||
player.getTeamManager().setupTemporaryTeam(towerTeams); | ||
} | ||
|
||
|
||
public void enterLevel(int enterPointId) { | ||
var levelData = GameData.getTowerLevelDataMap().get(currentLevel); | ||
var levelData = GameData.getTowerLevelDataMap().get(currentLevelId + currentLevel); | ||
|
||
this.currentLevel++; | ||
var id = levelData.getDungeonId(); | ||
|
||
notifyCurLevelRecordChange(); | ||
// use team user choose | ||
player.getTeamManager().useTemporaryTeam(0); | ||
player.getServer().getDungeonManager() | ||
.enterDungeon(player, enterPointId, id); | ||
player.getServer().getDungeonManager().handoffDungeon(player, id, | ||
towerDungeonSettleListener); | ||
|
||
// make sure user can exit dungeon correctly | ||
player.getScene().setPrevScene(entryScene); | ||
player.getScene().setPrevScenePoint(enterPointId); | ||
|
||
player.getSession().send(new PacketTowerEnterLevelRsp(currentFloorId, currentLevel)); | ||
|
||
} | ||
|
||
public void notifyCurLevelRecordChange(){ | ||
player.getSession().send(new PacketTowerCurLevelRecordChangeNotify(currentFloorId, currentLevel)); | ||
} | ||
public void notifyCurLevelRecordChangeWhenDone(){ | ||
player.getSession().send(new PacketTowerCurLevelRecordChangeNotify(currentFloorId, currentLevel + 1)); | ||
} | ||
public boolean hasNextLevel(){ | ||
return this.currentLevel < 3; | ||
} | ||
|
||
public int getNextFloorId() { | ||
if(hasNextLevel()){ | ||
return 0; | ||
} | ||
this.currentFloorId++; | ||
return this.currentFloorId; | ||
} | ||
|
||
player.getSession().send(new PacketTowerEnterLevelRsp(currentFloor, currentLevel)); | ||
public void clearEntry() { | ||
this.entryScene = 0; | ||
} | ||
} |
Oops, something went wrong.