fix: make thanos also knock out characters he walks over, adapt for new UseInfinityStoneRequest

This commit is contained in:
punchready 2021-06-24 20:41:37 +02:00
parent 7334b234d4
commit 7b1ce8af8f

View File

@ -139,22 +139,7 @@ public class GameLogic {
} }
} }
case RealityStone -> { case RealityStone -> {
if(data.originEntity.equals(data.targetEntity)) { // => place stone // no check done
if(state.entities.findByPosition(data.targetField).size() != 0) {
throw new InvalidRequestException("Invalid reality stone target (rock already there)");
}
}else { // => destroy stone
boolean hasRock = false;
for(Entity entity: state.entities.findByPosition(data.targetField)) {
if(entity.id.isSameType(EntityType.Rocks)) {
hasRock = true;
break;
}
}
if(!hasRock) {
throw new InvalidRequestException("Invalid reality stone target (no rock found)");
}
}
} }
case PowerStone -> { case PowerStone -> {
Character target = getCharacter(state, data.targetField, data.targetEntity); Character target = getCharacter(state, data.targetField, data.targetEntity);
@ -420,15 +405,22 @@ public class GameLogic {
} }
} }
case RealityStone -> { case RealityStone -> {
if(data.originEntity == data.targetEntity) { // => place stone EntityID target = null;
for(Entity entity: state.entities.findByPosition(data.targetField)) {
if(entity.id.type == EntityType.Rocks) {
target = entity.id;
break;
}
}
if(target == null) {
result.add(new EventBuilder(EventType.SpawnEntityEvent) result.add(new EventBuilder(EventType.SpawnEntityEvent)
.withTargetField(data.targetField) .withTargetField(data.targetField)
.withEntity(new Rock(new EntityID(EntityType.Rocks, state.entities.findFreeRockSlot()), data.targetField, 100)) .withEntity(new Rock(new EntityID(EntityType.Rocks, state.entities.findFreeRockSlot()), data.targetField, 100))
.buildEntityEvent()); .buildEntityEvent());
}else { // => destroy stone }else {
result.add(new EventBuilder(EventType.DestroyedEntityEvent) result.add(new EventBuilder(EventType.DestroyedEntityEvent)
.withTargetField(data.targetField) .withTargetField(data.targetField)
.withTargetEntity(data.targetEntity) .withTargetEntity(target)
.buildEntityEvent()); .buildEntityEvent());
} }
} }
@ -1149,28 +1141,26 @@ public class GameLogic {
.withAmount(1) .withAmount(1)
.buildEntityEvent()); .buildEntityEvent());
if(pos.equals(picked)) { for(Entity entity: state.entities.findByPosition(pos)) {
for(Entity entity: state.entities.findByPosition(pos)) { if(entity instanceof Character) {
if(entity instanceof Character) { result.add(new EventBuilder(EventType.MoveEvent)
result.add(new EventBuilder(EventType.MoveEvent) .withOriginEntity(entity.id)
.withOriginEntity(entity.id) .withOriginField(pos)
.withOriginField(pos) .withTargetField(current)
.withTargetField(current) .buildCharacterEvent());
.buildCharacterEvent()); result.add(new EventBuilder(EventType.TakenDamageEvent)
result.add(new EventBuilder(EventType.TakenDamageEvent) .withTargetEntity(entity.id)
.withTargetEntity(entity.id) .withTargetField(current)
.withTargetField(current) .withAmount(((Character)entity).hp.getValue())
.withAmount(((Character)entity).hp.getValue()) .buildEntityEvent());
.buildEntityEvent()); break;
break; }
} if(entity instanceof InfinityStone) {
if(entity instanceof InfinityStone) { result.add(new EventBuilder(EventType.DestroyedEntityEvent)
result.add(new EventBuilder(EventType.DestroyedEntityEvent) .withTargetEntity(entity.id)
.withTargetEntity(entity.id) .withTargetField(pos)
.withTargetField(pos) .buildEntityEvent());
.buildEntityEvent()); break;
break;
}
} }
} }