mirror of
https://github.com/Melledy/Nebula.git
synced 2025-12-14 13:24:43 +01:00
Implement monolith settle
This commit is contained in:
@@ -1,5 +1,7 @@
|
|||||||
package emu.nebula.data.resources;
|
package emu.nebula.data.resources;
|
||||||
|
|
||||||
|
import java.util.Arrays;
|
||||||
|
|
||||||
import emu.nebula.data.BaseDef;
|
import emu.nebula.data.BaseDef;
|
||||||
import emu.nebula.data.ResourceType;
|
import emu.nebula.data.ResourceType;
|
||||||
import lombok.Getter;
|
import lombok.Getter;
|
||||||
@@ -10,6 +12,8 @@ public class StarTowerDef extends BaseDef {
|
|||||||
private int Id;
|
private int Id;
|
||||||
private int[] FloorNum;
|
private int[] FloorNum;
|
||||||
|
|
||||||
|
private transient int maxFloors;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public int getId() {
|
public int getId() {
|
||||||
return Id;
|
return Id;
|
||||||
@@ -24,4 +28,9 @@ public class StarTowerDef extends BaseDef {
|
|||||||
|
|
||||||
return this.FloorNum[index];
|
return this.FloorNum[index];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onLoad() {
|
||||||
|
this.maxFloors = Arrays.stream(this.FloorNum).reduce(0, Integer::sum);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -35,7 +35,8 @@ public class StarTowerGame {
|
|||||||
private int id;
|
private int id;
|
||||||
|
|
||||||
// Room
|
// Room
|
||||||
private int stage;
|
private int stageNum;
|
||||||
|
private int stageFloor;
|
||||||
private int floor;
|
private int floor;
|
||||||
private int mapId;
|
private int mapId;
|
||||||
private int mapTableId;
|
private int mapTableId;
|
||||||
@@ -93,7 +94,8 @@ public class StarTowerGame {
|
|||||||
this.formationId = req.getFormationId();
|
this.formationId = req.getFormationId();
|
||||||
this.buildId = Snowflake.newUid();
|
this.buildId = Snowflake.newUid();
|
||||||
this.teamLevel = 1;
|
this.teamLevel = 1;
|
||||||
this.stage = 1;
|
this.stageNum = 1;
|
||||||
|
this.stageFloor = 1;
|
||||||
this.floor = 1;
|
this.floor = 1;
|
||||||
this.charHp = -1;
|
this.charHp = -1;
|
||||||
this.chars = new ArrayList<>();
|
this.chars = new ArrayList<>();
|
||||||
@@ -145,7 +147,7 @@ public class StarTowerGame {
|
|||||||
|
|
||||||
// Debug
|
// Debug
|
||||||
var doorCase = this.addCase(new StarTowerCase(CaseType.OpenDoor));
|
var doorCase = this.addCase(new StarTowerCase(CaseType.OpenDoor));
|
||||||
doorCase.setFloorId(this.getFloor() + 1);
|
doorCase.setFloorId(this.getStageFloor() + 1);
|
||||||
|
|
||||||
var nextStage = this.getNextStageData();
|
var nextStage = this.getNextStageData();
|
||||||
if (nextStage != null) {
|
if (nextStage != null) {
|
||||||
@@ -171,10 +173,10 @@ public class StarTowerGame {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public StarTowerStageDef getNextStageData() {
|
public StarTowerStageDef getNextStageData() {
|
||||||
int stage = this.stage;
|
int stage = this.stageNum;
|
||||||
int floor = this.floor + 1;
|
int floor = this.stageFloor + 1;
|
||||||
|
|
||||||
if (floor >= this.getData().getMaxFloor(this.getStage())) {
|
if (floor >= this.getData().getMaxFloor(this.getStageNum())) {
|
||||||
floor = 1;
|
floor = 1;
|
||||||
stage++;
|
stage++;
|
||||||
}
|
}
|
||||||
@@ -353,6 +355,7 @@ public class StarTowerGame {
|
|||||||
|
|
||||||
// Add any items
|
// Add any items
|
||||||
var data = rsp.getMutableData();
|
var data = rsp.getMutableData();
|
||||||
|
|
||||||
if (this.getNewInfos().size() > 0) {
|
if (this.getNewInfos().size() > 0) {
|
||||||
// Add item protos
|
// Add item protos
|
||||||
for (var entry : this.getNewInfos()) {
|
for (var entry : this.getNewInfos()) {
|
||||||
@@ -451,17 +454,25 @@ public class StarTowerGame {
|
|||||||
this.mapTableId = proto.getMapTableId();
|
this.mapTableId = proto.getMapTableId();
|
||||||
this.mapParam = proto.getMapParam();
|
this.mapParam = proto.getMapParam();
|
||||||
this.paramId = proto.getParamId();
|
this.paramId = proto.getParamId();
|
||||||
|
|
||||||
// Next floor
|
|
||||||
this.floor++;
|
this.floor++;
|
||||||
|
|
||||||
if (this.floor >= this.getData().getMaxFloor(this.getStage())) {
|
// Check if we need to settle
|
||||||
this.floor = 1;
|
if (this.floor > this.getData().getMaxFloors()) {
|
||||||
this.stage++;
|
return this.settle(rsp);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Next floor
|
||||||
|
int nextFloor = this.stageFloor + 1;
|
||||||
|
|
||||||
|
if (this.stageFloor >= this.getData().getMaxFloor(this.getStageNum())) {
|
||||||
|
this.stageFloor = 1;
|
||||||
|
this.stageNum++;
|
||||||
|
} else {
|
||||||
|
this.stageFloor = nextFloor;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Calculate stage
|
// Calculate stage
|
||||||
var stageData = this.getStageData(this.getStage(), this.getFloor());
|
var stageData = this.getStageData(this.getStageNum(), this.getStageFloor());
|
||||||
|
|
||||||
if (stageData != null) {
|
if (stageData != null) {
|
||||||
this.roomType = stageData.getRoomType();
|
this.roomType = stageData.getRoomType();
|
||||||
@@ -491,7 +502,7 @@ public class StarTowerGame {
|
|||||||
room.setData(this.toRoomDataProto());
|
room.setData(this.toRoomDataProto());
|
||||||
|
|
||||||
// Handle room type TODO
|
// Handle room type TODO
|
||||||
if (this.roomType <= StarTowerRoomType.EliteBattleRoom.getValue()) {
|
if (this.roomType <= StarTowerRoomType.FinalBossRoom.getValue()) {
|
||||||
var battleCase = new StarTowerCase(CaseType.Battle);
|
var battleCase = new StarTowerCase(CaseType.Battle);
|
||||||
battleCase.setSubNoteSkillNum(Utils.randomRange(1, 3));
|
battleCase.setSubNoteSkillNum(Utils.randomRange(1, 3));
|
||||||
|
|
||||||
@@ -517,6 +528,22 @@ public class StarTowerGame {
|
|||||||
return rsp;
|
return rsp;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public StarTowerInteractResp settle(StarTowerInteractResp rsp) {
|
||||||
|
// End game
|
||||||
|
this.getManager().endGame();
|
||||||
|
|
||||||
|
// Settle info
|
||||||
|
var settle = rsp.getMutableSettle()
|
||||||
|
.setTotalTime(this.getBattleTime())
|
||||||
|
.setBuild(this.getBuild().toProto());
|
||||||
|
|
||||||
|
// Mark change info
|
||||||
|
settle.getMutableChange();
|
||||||
|
|
||||||
|
// Complete
|
||||||
|
return rsp;
|
||||||
|
}
|
||||||
|
|
||||||
// Proto
|
// Proto
|
||||||
|
|
||||||
public StarTowerInfo toProto() {
|
public StarTowerInfo toProto() {
|
||||||
@@ -563,7 +590,7 @@ public class StarTowerGame {
|
|||||||
|
|
||||||
public StarTowerRoomData toRoomDataProto() {
|
public StarTowerRoomData toRoomDataProto() {
|
||||||
var proto = StarTowerRoomData.newInstance()
|
var proto = StarTowerRoomData.newInstance()
|
||||||
.setFloor(this.getFloor())
|
.setFloor(this.getStageFloor())
|
||||||
.setMapId(this.getMapId())
|
.setMapId(this.getMapId())
|
||||||
.setRoomType(this.getRoomType())
|
.setRoomType(this.getRoomType())
|
||||||
.setMapTableId(this.getMapTableId());
|
.setMapTableId(this.getMapTableId());
|
||||||
|
|||||||
@@ -77,19 +77,19 @@ public class StarTowerManager extends PlayerManager implements GameDatabaseObjec
|
|||||||
return this.game;
|
return this.game;
|
||||||
}
|
}
|
||||||
|
|
||||||
public StarTowerGame giveUp() {
|
public StarTowerGame endGame() {
|
||||||
// Cache instance
|
// Cache instance
|
||||||
var instance = this.game;
|
var game = this.game;
|
||||||
|
|
||||||
if (instance != null) {
|
if (game != null) {
|
||||||
// Set last build
|
// Set last build
|
||||||
this.lastBuild = instance.getBuild();
|
this.lastBuild = game.getBuild();
|
||||||
|
|
||||||
// Clear instance
|
// Clear instance
|
||||||
this.game = null;
|
this.game = null;
|
||||||
}
|
}
|
||||||
|
|
||||||
return instance;
|
return game;
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean saveBuild(boolean delete, String name, boolean lock) {
|
public boolean saveBuild(boolean delete, String name, boolean lock) {
|
||||||
|
|||||||
@@ -11,7 +11,7 @@ public class HandlerStarTowerGiveUpReq extends NetHandler {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public byte[] handle(GameSession session, byte[] message) throws Exception {
|
public byte[] handle(GameSession session, byte[] message) throws Exception {
|
||||||
var game = session.getPlayer().getStarTowerManager().giveUp();
|
var game = session.getPlayer().getStarTowerManager().endGame();
|
||||||
|
|
||||||
if (game == null) {
|
if (game == null) {
|
||||||
return session.encodeMsg(NetMsgId.star_tower_give_up_failed_ack);
|
return session.encodeMsg(NetMsgId.star_tower_give_up_failed_ack);
|
||||||
|
|||||||
Reference in New Issue
Block a user