mirror of
https://github.com/Melledy/Nebula.git
synced 2026-09-19 17:19:58 +02:00
Refactor error codes
This commit is contained in:
@@ -33,7 +33,8 @@ import emu.nebula.proto.Public.CharGemSlot;
|
||||
import emu.nebula.proto.Public.UI32;
|
||||
import emu.nebula.proto.PublicStarTower.StarTowerChar;
|
||||
import emu.nebula.proto.PublicStarTower.StarTowerCharGem;
|
||||
import emu.nebula.server.error.ServerException;
|
||||
import emu.nebula.server.error.ErrorCode;
|
||||
import emu.nebula.server.error.NebulaException;
|
||||
import emu.nebula.util.Bitset;
|
||||
import emu.nebula.util.ints.CustomIntArray;
|
||||
import it.unimi.dsi.fastutil.ints.IntArrayList;
|
||||
@@ -667,16 +668,16 @@ public class GameCharacter implements GameDatabaseObject {
|
||||
return true;
|
||||
}
|
||||
|
||||
public synchronized PlayerChangeInfo generateGem(int slotId) throws ServerException {
|
||||
public synchronized PlayerChangeInfo generateGem(int slotId) throws NebulaException {
|
||||
// Get gem slot
|
||||
var slot = this.getGemSlot(slotId);
|
||||
if (slot == null) {
|
||||
throw new ServerException(110105, "Emblem slot doesn't exist");
|
||||
throw new NebulaException(ErrorCode.SERVER_ERROR, "Emblem slot doesn't exist");
|
||||
}
|
||||
|
||||
// Skip if slot is full
|
||||
if (slot.isFull()) {
|
||||
throw new ServerException(110105, "Emblem slots are full");
|
||||
throw new NebulaException(ErrorCode.SERVER_ERROR, "Emblem slots are full");
|
||||
}
|
||||
|
||||
// Get gem data
|
||||
@@ -684,17 +685,17 @@ public class GameCharacter implements GameDatabaseObject {
|
||||
var gemControl = GameData.getCharGemSlotControlDataTable().get(slotId);
|
||||
|
||||
if (gemControl == null) {
|
||||
throw new ServerException(110105, "Emblem slot data doesn't exist");
|
||||
throw new NebulaException(ErrorCode.SERVER_ERROR, "Emblem slot data doesn't exist");
|
||||
}
|
||||
|
||||
// Check character level
|
||||
if (this.getLevel() < gemControl.getUnlockLevel()) {
|
||||
throw new ServerException(110105, "Trekker needs to be at least level " + gemControl.getUnlockLevel());
|
||||
throw new NebulaException(ErrorCode.SERVER_ERROR, "Trekker needs to be at least level " + gemControl.getUnlockLevel());
|
||||
}
|
||||
|
||||
// Make sure the player has the materials to craft the emblem
|
||||
if (!getPlayer().getInventory().hasItem(gemData.getGenerateCostTid(), gemControl.getGeneratenCostQty())) {
|
||||
throw new ServerException(119903);
|
||||
throw new NebulaException(ErrorCode.INSUFFICIENT_RESOURCES);
|
||||
}
|
||||
|
||||
// Generate attributes and create gem
|
||||
@@ -718,11 +719,11 @@ public class GameCharacter implements GameDatabaseObject {
|
||||
}
|
||||
|
||||
@SuppressWarnings("deprecation")
|
||||
public synchronized PlayerChangeInfo refreshGem(int slotId, int gemIndex, RepeatedInt lockedAttributes) throws ServerException {
|
||||
public synchronized PlayerChangeInfo refreshGem(int slotId, int gemIndex, RepeatedInt lockedAttributes) throws NebulaException {
|
||||
// Get gem from slot
|
||||
var gem = this.getGemFromSlot(slotId, gemIndex);
|
||||
if (gem == null) {
|
||||
throw new ServerException(111609);
|
||||
throw new NebulaException(ErrorCode.GEM_NOT_EXIST);
|
||||
}
|
||||
|
||||
// Get gem data
|
||||
@@ -730,17 +731,17 @@ public class GameCharacter implements GameDatabaseObject {
|
||||
var gemControl = GameData.getCharGemSlotControlDataTable().get(slotId);
|
||||
|
||||
if (gemControl == null) {
|
||||
throw new ServerException(110105, "Emblem slot data doesn't exist");
|
||||
throw new NebulaException(ErrorCode.SERVER_ERROR, "Emblem slot data doesn't exist");
|
||||
}
|
||||
|
||||
// Check character level
|
||||
if (this.getLevel() < gemControl.getUnlockLevel()) {
|
||||
throw new ServerException(110105, "Trekker needs to be at least level " + gemControl.getUnlockLevel());
|
||||
throw new NebulaException(ErrorCode.SERVER_ERROR, "Trekker needs to be at least level " + gemControl.getUnlockLevel());
|
||||
}
|
||||
|
||||
// Get locked attributes
|
||||
if (lockedAttributes.length() > gemControl.getLockableNum()) {
|
||||
throw new ServerException(110105, "You can only lock up to " + gemControl.getLockableNum() + " attributes");
|
||||
throw new NebulaException(ErrorCode.SERVER_ERROR, "You can only lock up to " + gemControl.getLockableNum() + " attributes");
|
||||
}
|
||||
|
||||
// Calculate the materials we need
|
||||
|
||||
@@ -11,7 +11,8 @@ import emu.nebula.game.inventory.ItemParamMap;
|
||||
import emu.nebula.game.player.Player;
|
||||
import emu.nebula.game.player.PlayerChangeInfo;
|
||||
import emu.nebula.game.player.PlayerManager;
|
||||
|
||||
import emu.nebula.server.error.ErrorCode;
|
||||
import emu.nebula.server.error.NebulaException;
|
||||
import lombok.Getter;
|
||||
|
||||
@Getter
|
||||
@@ -43,17 +44,17 @@ public class ScoreBossManager extends PlayerManager {
|
||||
return this.ranking;
|
||||
}
|
||||
|
||||
public boolean apply(int levelId, long buildId) {
|
||||
// Get level
|
||||
public boolean apply(int levelId, long buildId) throws NebulaException {
|
||||
// Get level from control data
|
||||
var control = getControlData();
|
||||
if (control == null || !control.getLevelGroup().contains(levelId)) {
|
||||
return false;
|
||||
throw new NebulaException(ErrorCode.SCORE_BOSS_NOT_AVAILABLE);
|
||||
}
|
||||
|
||||
// Get build
|
||||
var build = this.getPlayer().getStarTowerManager().getBuildById(buildId);
|
||||
if (build == null) {
|
||||
return false;
|
||||
throw new NebulaException(ErrorCode.BUILD_NOT_EXIST);
|
||||
}
|
||||
|
||||
// Set
|
||||
|
||||
@@ -0,0 +1,24 @@
|
||||
package emu.nebula.server.error;
|
||||
|
||||
import lombok.Getter;
|
||||
|
||||
// TODO Add rest of the error codes
|
||||
|
||||
@Getter
|
||||
public enum ErrorCode {
|
||||
INVALID_MESSAGE_TOKEN (100101),
|
||||
INVALID_MESSAGE_TIME (100102),
|
||||
INVALID_MESSAGE_COMMAND_NUMBER (100103),
|
||||
SERVER_ERROR (110105),
|
||||
BUILD_NOT_EXIST (111103),
|
||||
SCORE_BOSS_NOT_AVAILABLE (112801),
|
||||
GEM_NOT_EXIST (111609),
|
||||
CONFIG_ERROR (119902),
|
||||
INSUFFICIENT_RESOURCES (119903);
|
||||
|
||||
private int value;
|
||||
|
||||
private ErrorCode(int value) {
|
||||
this.value = value;
|
||||
}
|
||||
}
|
||||
+5
-5
@@ -4,17 +4,17 @@ import lombok.Getter;
|
||||
import emu.nebula.proto.Public.Error;
|
||||
|
||||
@Getter
|
||||
public class ServerException extends Exception {
|
||||
public class NebulaException extends Exception {
|
||||
private static final long serialVersionUID = -8953641375717705518L;
|
||||
private int code;
|
||||
private String[] args;
|
||||
|
||||
public ServerException(int code) {
|
||||
this.code = code;
|
||||
public NebulaException(ErrorCode code) {
|
||||
this.code = code.getValue();
|
||||
}
|
||||
|
||||
public ServerException(int code, String... args) {
|
||||
this.code = code;
|
||||
public NebulaException(ErrorCode code, String... args) {
|
||||
this.code = code.getValue();
|
||||
this.args = args;
|
||||
}
|
||||
|
||||
@@ -4,7 +4,7 @@ import emu.nebula.net.NetHandler;
|
||||
import emu.nebula.net.NetMsgId;
|
||||
import emu.nebula.proto.CharGemGenerate.CharGemGenerateReq;
|
||||
import emu.nebula.proto.CharGemGenerate.CharGemGenerateResp;
|
||||
import emu.nebula.server.error.ServerException;
|
||||
import emu.nebula.server.error.NebulaException;
|
||||
import emu.nebula.net.HandlerId;
|
||||
import emu.nebula.game.character.CharacterGem;
|
||||
import emu.nebula.game.player.PlayerChangeInfo;
|
||||
@@ -29,7 +29,7 @@ public class HandlerCharGemGenerateReq extends NetHandler {
|
||||
|
||||
try {
|
||||
change = character.generateGem(req.getSlotId());
|
||||
} catch (ServerException e) {
|
||||
} catch (NebulaException e) {
|
||||
return session.encodeMsg(NetMsgId.char_gem_generate_failed_ack, e.toProto());
|
||||
}
|
||||
|
||||
|
||||
@@ -4,7 +4,7 @@ import emu.nebula.net.NetHandler;
|
||||
import emu.nebula.net.NetMsgId;
|
||||
import emu.nebula.proto.CharGemRefresh.CharGemRefreshReq;
|
||||
import emu.nebula.proto.CharGemRefresh.CharGemRefreshResp;
|
||||
import emu.nebula.server.error.ServerException;
|
||||
import emu.nebula.server.error.NebulaException;
|
||||
import emu.nebula.net.HandlerId;
|
||||
import emu.nebula.game.character.CharacterGem;
|
||||
import emu.nebula.game.player.PlayerChangeInfo;
|
||||
@@ -30,7 +30,7 @@ public class HandlerCharGemRefreshReq extends NetHandler {
|
||||
|
||||
try {
|
||||
change = character.refreshGem(req.getSlotId(), req.getGemIndex(), req.getLockAttrs());
|
||||
} catch (ServerException e) {
|
||||
} catch (NebulaException e) {
|
||||
return session.encodeMsg(NetMsgId.char_gem_refresh_failed_ack, e.toProto());
|
||||
}
|
||||
|
||||
|
||||
@@ -3,6 +3,7 @@ package emu.nebula.server.handlers;
|
||||
import emu.nebula.net.NetHandler;
|
||||
import emu.nebula.net.NetMsgId;
|
||||
import emu.nebula.proto.ScoreBossApply.ScoreBossApplyReq;
|
||||
import emu.nebula.server.error.NebulaException;
|
||||
import emu.nebula.net.HandlerId;
|
||||
import emu.nebula.net.GameSession;
|
||||
|
||||
@@ -15,10 +16,14 @@ public class HandlerScoreBossApplyReq extends NetHandler {
|
||||
var req = ScoreBossApplyReq.parseFrom(message);
|
||||
|
||||
// Apply
|
||||
boolean success = session.getPlayer().getScoreBossManager().apply(req.getLevelId(), req.getBuildId());
|
||||
try {
|
||||
session.getPlayer().getScoreBossManager().apply(req.getLevelId(), req.getBuildId());
|
||||
} catch (NebulaException e) {
|
||||
return session.encodeMsg(NetMsgId.score_boss_apply_failed_ack, e.toProto());
|
||||
}
|
||||
|
||||
// Encode and send
|
||||
return session.encodeMsg(success ? NetMsgId.score_boss_apply_succeed_ack : NetMsgId.score_boss_apply_failed_ack);
|
||||
return session.encodeMsg(NetMsgId.score_boss_apply_succeed_ack);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user