fix: resolve various casting and equality check mistakes

This commit is contained in:
punchready 2021-06-04 05:14:00 +02:00
parent e10fbb15eb
commit e90b8f4562
2 changed files with 32 additions and 15 deletions

View File

@ -137,7 +137,7 @@ public class GameLogic {
}
}
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) {
throw new InvalidRequestException();
}
@ -170,7 +170,7 @@ public class GameLogic {
case SoulStone -> {
Character target = getCharacter(state, data.targetField, data.targetEntity);
if(data.originEntity == data.targetEntity) {
if(data.originEntity.equals(data.targetEntity)) {
throw new InvalidRequestException();
}
@ -203,7 +203,7 @@ 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() != 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();
}
try {
@ -217,7 +217,7 @@ public class GameLogic {
* Verifies that a {@link Character} has a turn.
*/
private static void requireTurn(GameState state, Character entity) throws InvalidRequestException {
if(entity.id != state.activeCharacter) {
if(!entity.id.equals(state.activeCharacter)) {
throw new InvalidRequestException();
}
}
@ -505,14 +505,18 @@ public class GameLogic {
}
}
case ConsumedAPEvent -> {
CharacterEvent data = (CharacterEvent)event;
EntityEvent data = (EntityEvent)event;
((Character)state.entities.findEntity(data.targetEntity)).ap.decreaseValue(data.amount);
}
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 -> {
GameEvent data = (GameEvent)event;
@ -537,15 +541,27 @@ public class GameLogic {
case MoveEvent -> {
CharacterEvent data = (CharacterEvent)event;
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);
if(data.originEntity.type != EntityType.NPC) {
Character target = (Character)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());
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 -> {
state.stoneCooldown.setCooldown(((CharacterEvent)event).stoneType);
@ -716,7 +732,9 @@ public class GameLogic {
* @return The list of resulting {@link Event Events}
*/
protected static ArrayList<Event> startRound(GameState state) {
return handleRoundStart(state);
ArrayList<Event> result = handleRoundStart(state);
result.addAll(handleTurnStart(state));
return result;
}
/**

View File

@ -29,7 +29,6 @@ public class JSON {
* or an empty {@link Optional} if the deserialization failed
*/
public Optional<BasicMessage> parse(String input) {
BasicMessage result = null;
try {
return Optional.of(mapper.readValue(input, BasicMessage.class));
} catch (JsonProcessingException e) {