|
| 1 | +package com.khomsi.game.entity.npc.castle; |
| 2 | + |
| 3 | +import com.khomsi.game.entity.Entity; |
| 4 | +import com.khomsi.game.entity.npc.dungeon.NpcHeavyDungeonRock; |
| 5 | +import com.khomsi.game.main.GameManager; |
| 6 | +import com.khomsi.game.objects.inside.castle.BigDoorClosedObject; |
| 7 | +import com.khomsi.game.objects.inside.castle.BigDoorOpenedObject; |
| 8 | + |
| 9 | +import java.util.Arrays; |
| 10 | +import java.util.List; |
| 11 | +import java.util.stream.IntStream; |
| 12 | + |
| 13 | +import static com.khomsi.game.objects.inside.castle.DoorType.OPENED; |
| 14 | + |
| 15 | +public class NpcHeavyCastleRock extends NpcHeavyDungeonRock { |
| 16 | + public static final String NPC_NAME = "Rock Castle"; |
| 17 | + |
| 18 | + public NpcHeavyCastleRock(GameManager gameManager) { |
| 19 | + super(gameManager); |
| 20 | + name = NPC_NAME; |
| 21 | + } |
| 22 | + |
| 23 | + @Override |
| 24 | + public void moveObj(String direction) { |
| 25 | + this.direction = direction; |
| 26 | + changeDirection(direction); |
| 27 | + detectPlate(); |
| 28 | + } |
| 29 | + |
| 30 | + public void detectPlate() { |
| 31 | + List<Entity> rocks = getEntitiesForPlates(); |
| 32 | + // Count the rocks on plates |
| 33 | + long count = rocks.stream() |
| 34 | + .filter(rock -> rock.linkedEntity != null) |
| 35 | + .count(); |
| 36 | + |
| 37 | + //If all the rocks are on the plates, the door opens |
| 38 | + if (count == rocks.size()) { |
| 39 | + Arrays.stream(gameManager.object[gameManager.currentMap]) |
| 40 | + .filter(BigDoorClosedObject.class::isInstance) |
| 41 | + .findFirst() |
| 42 | + .ifPresent(obj -> { |
| 43 | + int index = IntStream.range(0, gameManager.object[gameManager.currentMap].length) |
| 44 | + .filter(i -> gameManager.object[gameManager.currentMap][i] == obj) |
| 45 | + .findFirst() |
| 46 | + .orElse(-1); |
| 47 | + |
| 48 | + if (index != -1) { |
| 49 | + gameManager.object[gameManager.currentMap][index] |
| 50 | + = new BigDoorOpenedObject(gameManager, OPENED); |
| 51 | + gameManager.object[gameManager.currentMap][index].worldX = GameManager.TILE_SIZE * 74; |
| 52 | + gameManager.object[gameManager.currentMap][index].worldY = GameManager.TILE_SIZE * 52; |
| 53 | + gameManager.playSE(4); |
| 54 | + } |
| 55 | + }); |
| 56 | + } |
| 57 | + } |
| 58 | +} |
0 commit comments