feat: add description to request denial error
This commit is contained in:
parent
e90b8f4562
commit
4eb71fa972
@ -45,20 +45,20 @@ public class GameLogic {
|
||||
|
||||
if(request.type == RequestType.MeleeAttackRequest) {
|
||||
if(origin.meleeDamage != data.value) {
|
||||
throw new InvalidRequestException();
|
||||
throw new InvalidRequestException("Invalid melee damage");
|
||||
}
|
||||
if(data.originField.distanceChebyshev(data.targetField) != 1) {
|
||||
throw new InvalidRequestException();
|
||||
throw new InvalidRequestException("Invalid melee target distance");
|
||||
}
|
||||
}else if(request.type == RequestType.RangedAttackRequest) {
|
||||
if(origin.rangedDamage != data.value) {
|
||||
throw new InvalidRequestException();
|
||||
throw new InvalidRequestException("Invalid ranged damage");
|
||||
}
|
||||
if(data.originField.distanceChebyshev(data.targetField) > origin.attackRange) {
|
||||
throw new InvalidRequestException();
|
||||
throw new InvalidRequestException("Invalid ranged distance (too far)");
|
||||
}
|
||||
if(data.originField.distanceChebyshev(data.targetField) <= 1) {
|
||||
throw new InvalidRequestException();
|
||||
throw new InvalidRequestException("Invalid ranged distance (too short)");
|
||||
}
|
||||
requireLineOfSight(state, data.originField, data.targetField);
|
||||
}
|
||||
@ -77,11 +77,11 @@ public class GameLogic {
|
||||
verifyCoordinates(state, data.targetField);
|
||||
|
||||
if(data.originField.distanceChebyshev(data.targetField) != 1) {
|
||||
throw new InvalidRequestException();
|
||||
throw new InvalidRequestException("Invalid move distance");
|
||||
}
|
||||
|
||||
if(state.entities.blocksMovement(data.targetField)) {
|
||||
throw new InvalidRequestException();
|
||||
throw new InvalidRequestException("Moving into blocked field");
|
||||
}
|
||||
|
||||
return true;
|
||||
@ -100,7 +100,7 @@ public class GameLogic {
|
||||
requireInfinityStone(origin, data.stoneType);
|
||||
|
||||
if(data.originField.distanceChebyshev(data.targetField) != 1) {
|
||||
throw new InvalidRequestException();
|
||||
throw new InvalidRequestException("Invalid infinity stone exchange distance");
|
||||
}
|
||||
|
||||
return true;
|
||||
@ -117,7 +117,7 @@ public class GameLogic {
|
||||
requireInfinityStone(origin, data.stoneType);
|
||||
|
||||
if(state.stoneCooldown.onCooldown(data.stoneType)) {
|
||||
throw new InvalidRequestException();
|
||||
throw new InvalidRequestException("Using infinity stone on cooldown");
|
||||
}
|
||||
|
||||
switch(((CharacterRequest) request).stoneType) {
|
||||
@ -125,21 +125,21 @@ public class GameLogic {
|
||||
verifyCoordinates(state, data.targetField);
|
||||
|
||||
if(state.entities.blocksMovement(data.targetField)) {
|
||||
throw new InvalidRequestException();
|
||||
throw new InvalidRequestException("Using space stone onto blocked field");
|
||||
}
|
||||
}
|
||||
case MindStone -> {
|
||||
if(data.originField == data.targetField) {
|
||||
throw new InvalidRequestException();
|
||||
throw new InvalidRequestException("Invalid mind stone target field");
|
||||
}
|
||||
if(data.value != state.partyConfig.mindStoneDMG) {
|
||||
throw new InvalidRequestException();
|
||||
throw new InvalidRequestException("Invalid mind stone damage");
|
||||
}
|
||||
}
|
||||
case RealityStone -> {
|
||||
if(data.originEntity.equals(data.targetEntity)) { // => place stone
|
||||
if(state.entities.findByPosition(data.targetField).size() != 0) {
|
||||
throw new InvalidRequestException();
|
||||
throw new InvalidRequestException("Invalid reality stone target (rock already there)");
|
||||
}
|
||||
}else { // => destroy stone
|
||||
boolean hasRock = false;
|
||||
@ -150,7 +150,7 @@ public class GameLogic {
|
||||
}
|
||||
}
|
||||
if(!hasRock) {
|
||||
throw new InvalidRequestException();
|
||||
throw new InvalidRequestException("Invalid reality stone target (no rock found)");
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -161,7 +161,7 @@ public class GameLogic {
|
||||
requireOppositeTeam(origin, target);
|
||||
|
||||
if(origin.rangedDamage * 2 != data.value) {
|
||||
throw new InvalidRequestException();
|
||||
throw new InvalidRequestException("Invalid power stone damage");
|
||||
}
|
||||
}
|
||||
case TimeStone -> {
|
||||
@ -171,11 +171,11 @@ public class GameLogic {
|
||||
Character target = getCharacter(state, data.targetField, data.targetEntity);
|
||||
|
||||
if(data.originEntity.equals(data.targetEntity)) {
|
||||
throw new InvalidRequestException();
|
||||
throw new InvalidRequestException("Invalid soul stone target (same as origin)");
|
||||
}
|
||||
|
||||
if(target.isAlive()) {
|
||||
throw new InvalidRequestException();
|
||||
throw new InvalidRequestException("Invalid soul stone target (already alive)");
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -186,6 +186,8 @@ public class GameLogic {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}catch(InvalidRequestException exception) {
|
||||
return false;
|
||||
}catch(Exception ignored) {
|
||||
return false;
|
||||
}
|
||||
@ -204,12 +206,12 @@ public class GameLogic {
|
||||
private static Character getCharacter(GameState state, IntVector2 position, EntityID entityID) throws InvalidRequestException {
|
||||
Entity entity = state.entities.findEntity(entityID);
|
||||
if(entity == null || !entity.getPosition().equals(position) || !(entity instanceof Character) || entity.id.type == EntityType.NPC) {
|
||||
throw new InvalidRequestException();
|
||||
throw new InvalidRequestException("Invalid origin or target character");
|
||||
}
|
||||
try {
|
||||
return (Character)entity;
|
||||
}catch(Exception ignored) {
|
||||
throw new InvalidRequestException();
|
||||
throw new InvalidRequestException("Invalid origin or target character (cast failed)");
|
||||
}
|
||||
}
|
||||
|
||||
@ -218,7 +220,7 @@ public class GameLogic {
|
||||
*/
|
||||
private static void requireTurn(GameState state, Character entity) throws InvalidRequestException {
|
||||
if(!entity.id.equals(state.activeCharacter)) {
|
||||
throw new InvalidRequestException();
|
||||
throw new InvalidRequestException("Target does not have the turn");
|
||||
}
|
||||
}
|
||||
|
||||
@ -227,7 +229,7 @@ public class GameLogic {
|
||||
*/
|
||||
private static void requireOppositeTeam(Character a, Character b) throws InvalidRequestException {
|
||||
if(a.id.type == b.id.type) {
|
||||
throw new InvalidRequestException();
|
||||
throw new InvalidRequestException("Origin and target are not on opposite team");
|
||||
}
|
||||
}
|
||||
|
||||
@ -236,7 +238,7 @@ public class GameLogic {
|
||||
*/
|
||||
private static void requireSameTeam(Character a, Character b) throws InvalidRequestException {
|
||||
if(a.id.type != b.id.type || a.id.id == b.id.id) {
|
||||
throw new InvalidRequestException();
|
||||
throw new InvalidRequestException("Origin and target are not on same team");
|
||||
}
|
||||
}
|
||||
|
||||
@ -245,7 +247,7 @@ public class GameLogic {
|
||||
*/
|
||||
private static void requireAlive(Character entity) throws InvalidRequestException {
|
||||
if(!entity.isAlive()) {
|
||||
throw new InvalidRequestException();
|
||||
throw new InvalidRequestException("Character is not alive");
|
||||
}
|
||||
}
|
||||
|
||||
@ -254,7 +256,7 @@ public class GameLogic {
|
||||
*/
|
||||
private static void requireAP(Character entity, int ap) throws InvalidRequestException {
|
||||
if(entity.ap.getValue() < ap) {
|
||||
throw new InvalidRequestException();
|
||||
throw new InvalidRequestException("Character does not have enough ap");
|
||||
}
|
||||
}
|
||||
|
||||
@ -263,7 +265,7 @@ public class GameLogic {
|
||||
*/
|
||||
private static void requireMP(Character entity, int mp) throws InvalidRequestException {
|
||||
if(entity.mp.getValue() < mp) {
|
||||
throw new InvalidRequestException();
|
||||
throw new InvalidRequestException("Character does not have enough mp");
|
||||
}
|
||||
}
|
||||
|
||||
@ -272,7 +274,7 @@ public class GameLogic {
|
||||
*/
|
||||
private static void requireInfinityStone(Character entity, StoneType stone) throws InvalidRequestException {
|
||||
if(stone == null || !entity.inventory.hasStone(stone)) {
|
||||
throw new InvalidRequestException();
|
||||
throw new InvalidRequestException("Character does not have the infinity stone");
|
||||
}
|
||||
}
|
||||
|
||||
@ -281,7 +283,7 @@ public class GameLogic {
|
||||
*/
|
||||
private static void verifyCoordinates(GameState state, IntVector2 position) throws InvalidRequestException {
|
||||
if(position.getX() < 0 || position.getX() >= state.mapSize.getX() || position.getY() < 0 || position.getY() >= state.mapSize.getY()) {
|
||||
throw new InvalidRequestException();
|
||||
throw new InvalidRequestException("Out of bounds coordinates");
|
||||
}
|
||||
}
|
||||
|
||||
@ -290,7 +292,7 @@ public class GameLogic {
|
||||
*/
|
||||
private static void requireLineOfSight(GameState state, IntVector2 start, IntVector2 end) throws InvalidRequestException {
|
||||
if(!checkLineOfSight(state, start, end)) {
|
||||
throw new InvalidRequestException();
|
||||
throw new InvalidRequestException("Character does not have line of sight to target");
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -4,5 +4,11 @@ import uulm.teamname.marvelous.gamelibrary.requests.Request;
|
||||
|
||||
/** Represents an exception thrown when a {@link Request} is invalid. */
|
||||
public class InvalidRequestException extends Exception {
|
||||
public InvalidRequestException(String message) {
|
||||
super(message);
|
||||
}
|
||||
|
||||
public InvalidRequestException() {
|
||||
super();
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user