fix: resolve various casting and equality check mistakes
This commit is contained in:
parent
e10fbb15eb
commit
e90b8f4562
@ -137,7 +137,7 @@ public class GameLogic {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
case RealityStone -> {
|
case RealityStone -> {
|
||||||
if(data.originEntity == data.targetEntity) { // => place stone
|
if(data.originEntity.equals(data.targetEntity)) { // => place stone
|
||||||
if(state.entities.findByPosition(data.targetField).size() != 0) {
|
if(state.entities.findByPosition(data.targetField).size() != 0) {
|
||||||
throw new InvalidRequestException();
|
throw new InvalidRequestException();
|
||||||
}
|
}
|
||||||
@ -170,7 +170,7 @@ public class GameLogic {
|
|||||||
case SoulStone -> {
|
case SoulStone -> {
|
||||||
Character target = getCharacter(state, data.targetField, data.targetEntity);
|
Character target = getCharacter(state, data.targetField, data.targetEntity);
|
||||||
|
|
||||||
if(data.originEntity == data.targetEntity) {
|
if(data.originEntity.equals(data.targetEntity)) {
|
||||||
throw new InvalidRequestException();
|
throw new InvalidRequestException();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -203,7 +203,7 @@ public class GameLogic {
|
|||||||
*/
|
*/
|
||||||
private static Character getCharacter(GameState state, IntVector2 position, EntityID entityID) throws InvalidRequestException {
|
private static Character getCharacter(GameState state, IntVector2 position, EntityID entityID) throws InvalidRequestException {
|
||||||
Entity entity = state.entities.findEntity(entityID);
|
Entity entity = state.entities.findEntity(entityID);
|
||||||
if(entity == null || entity.getPosition() != position || !(entity instanceof Character) || entity.id.type == EntityType.NPC) {
|
if(entity == null || !entity.getPosition().equals(position) || !(entity instanceof Character) || entity.id.type == EntityType.NPC) {
|
||||||
throw new InvalidRequestException();
|
throw new InvalidRequestException();
|
||||||
}
|
}
|
||||||
try {
|
try {
|
||||||
@ -217,7 +217,7 @@ public class GameLogic {
|
|||||||
* Verifies that a {@link Character} has a turn.
|
* Verifies that a {@link Character} has a turn.
|
||||||
*/
|
*/
|
||||||
private static void requireTurn(GameState state, Character entity) throws InvalidRequestException {
|
private static void requireTurn(GameState state, Character entity) throws InvalidRequestException {
|
||||||
if(entity.id != state.activeCharacter) {
|
if(!entity.id.equals(state.activeCharacter)) {
|
||||||
throw new InvalidRequestException();
|
throw new InvalidRequestException();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -505,14 +505,18 @@ public class GameLogic {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
case ConsumedAPEvent -> {
|
case ConsumedAPEvent -> {
|
||||||
CharacterEvent data = (CharacterEvent)event;
|
EntityEvent data = (EntityEvent)event;
|
||||||
|
|
||||||
((Character)state.entities.findEntity(data.targetEntity)).ap.decreaseValue(data.amount);
|
((Character)state.entities.findEntity(data.targetEntity)).ap.decreaseValue(data.amount);
|
||||||
}
|
}
|
||||||
case ConsumedMPEvent -> {
|
case ConsumedMPEvent -> {
|
||||||
CharacterEvent data = (CharacterEvent)event;
|
EntityEvent data = (EntityEvent)event;
|
||||||
|
|
||||||
((NPC)state.entities.findEntity(data.targetEntity)).mp.decreaseValue(data.amount);
|
if(data.targetEntity.type != EntityType.NPC) {
|
||||||
|
((Character)state.entities.findEntity(data.targetEntity)).mp.decreaseValue(data.amount);
|
||||||
|
}else {
|
||||||
|
((NPC)state.entities.findEntity(data.targetEntity)).mp.decreaseValue(data.amount);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
case TurnEvent -> {
|
case TurnEvent -> {
|
||||||
GameEvent data = (GameEvent)event;
|
GameEvent data = (GameEvent)event;
|
||||||
@ -537,15 +541,27 @@ public class GameLogic {
|
|||||||
case MoveEvent -> {
|
case MoveEvent -> {
|
||||||
CharacterEvent data = (CharacterEvent)event;
|
CharacterEvent data = (CharacterEvent)event;
|
||||||
|
|
||||||
NPC target = (NPC)state.entities.findEntity(data.originEntity);
|
if(data.originEntity.type != EntityType.NPC) {
|
||||||
for(Entity entity: state.entities.findByPosition(data.targetField)) {
|
Character target = (Character)state.entities.findEntity(data.originEntity);
|
||||||
if(entity instanceof InfinityStone) {
|
for(Entity entity: state.entities.findByPosition(data.targetField)) {
|
||||||
target.inventory.addStone(((InfinityStone)entity).type);
|
if(entity instanceof InfinityStone) {
|
||||||
|
target.inventory.addStone(((InfinityStone)entity).type);
|
||||||
|
|
||||||
state.winConditions.updateValue(target.id.type, WinCondition.MaxStones, target.inventory.getSize());
|
state.winConditions.updateValue(target.id.type, WinCondition.MaxStones, target.inventory.getSize());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
target.setPosition(data.targetField);
|
||||||
|
}else {
|
||||||
|
NPC target = (NPC)state.entities.findEntity(data.originEntity);
|
||||||
|
for(Entity entity: state.entities.findByPosition(data.targetField)) {
|
||||||
|
if(entity instanceof InfinityStone) {
|
||||||
|
target.inventory.addStone(((InfinityStone)entity).type);
|
||||||
|
|
||||||
|
state.winConditions.updateValue(target.id.type, WinCondition.MaxStones, target.inventory.getSize());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
target.setPosition(data.targetField);
|
||||||
}
|
}
|
||||||
target.setPosition(data.targetField);
|
|
||||||
}
|
}
|
||||||
case UseInfinityStoneEvent -> {
|
case UseInfinityStoneEvent -> {
|
||||||
state.stoneCooldown.setCooldown(((CharacterEvent)event).stoneType);
|
state.stoneCooldown.setCooldown(((CharacterEvent)event).stoneType);
|
||||||
@ -716,7 +732,9 @@ public class GameLogic {
|
|||||||
* @return The list of resulting {@link Event Events}
|
* @return The list of resulting {@link Event Events}
|
||||||
*/
|
*/
|
||||||
protected static ArrayList<Event> startRound(GameState state) {
|
protected static ArrayList<Event> startRound(GameState state) {
|
||||||
return handleRoundStart(state);
|
ArrayList<Event> result = handleRoundStart(state);
|
||||||
|
result.addAll(handleTurnStart(state));
|
||||||
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -29,7 +29,6 @@ public class JSON {
|
|||||||
* or an empty {@link Optional} if the deserialization failed
|
* or an empty {@link Optional} if the deserialization failed
|
||||||
*/
|
*/
|
||||||
public Optional<BasicMessage> parse(String input) {
|
public Optional<BasicMessage> parse(String input) {
|
||||||
BasicMessage result = null;
|
|
||||||
try {
|
try {
|
||||||
return Optional.of(mapper.readValue(input, BasicMessage.class));
|
return Optional.of(mapper.readValue(input, BasicMessage.class));
|
||||||
} catch (JsonProcessingException e) {
|
} catch (JsonProcessingException e) {
|
||||||
|
Loading…
Reference in New Issue
Block a user