private boolean actOpenChest(HeroAction.OpenChest action) {
    int dst = action.dst;
    if (Level.adjacent(pos, dst) || pos == dst) {

      Heap heap = Dungeon.level.heaps.get(dst);
      if (heap != null
          && (heap.type == Type.CHEST
              || heap.type == Type.TOMB
              || heap.type == Type.SKELETON
              || heap.type == Type.LOCKED_CHEST
              || heap.type == Type.CRYSTAL_CHEST)) {

        theKey = null;

        if (heap.type == Type.LOCKED_CHEST || heap.type == Type.CRYSTAL_CHEST) {

          theKey = belongings.getKey(GoldenKey.class, Dungeon.depth);

          if (theKey == null) {
            GLog.w(TXT_LOCKED_CHEST);
            ready();
            return false;
          }
        }

        switch (heap.type) {
          case TOMB:
            Sample.INSTANCE.play(Assets.SND_TOMB);
            Camera.main.shake(1, 0.5f);
            break;
          case SKELETON:
            break;
          default:
            Sample.INSTANCE.play(Assets.SND_UNLOCK);
        }

        spend(Key.TIME_TO_UNLOCK);
        sprite.operate(dst);

      } else {
        ready();
      }

      return false;

    } else if (getCloser(dst)) {

      return true;

    } else {
      ready();
      return false;
    }
  }
  private boolean actDescend(HeroAction.Descend action) {
    int stairs = action.dst;
    if (pos == stairs && pos == Dungeon.level.exit) {

      curAction = null;

      Hunger hunger = buff(Hunger.class);
      if (hunger != null && !hunger.isStarving()) {
        hunger.satisfy(-Hunger.STARVING / 10);
      }

      InterlevelScene.mode = InterlevelScene.Mode.DESCEND;
      Game.switchScene(InterlevelScene.class);

      return false;

    } else if (getCloser(stairs)) {

      return true;

    } else {
      ready();
      return false;
    }
  }
  private boolean actCook(HeroAction.Cook action) {
    int dst = action.dst;
    if (Dungeon.visible[dst]) {

      ready();
      AlchemyPot.operate(this, dst);
      return false;

    } else if (getCloser(dst)) {

      return true;

    } else {
      ready();
      return false;
    }
  }
  private boolean actPickUp(HeroAction.PickUp action) {
    int dst = action.dst;
    if (pos == dst) {

      Heap heap = Dungeon.level.heaps.get(pos);
      if (heap != null) {
        Item item = heap.pickUp();
        if (item.doPickUp(this)) {

          if (item instanceof Dewdrop) {

          } else {
            if ((item instanceof ScrollOfUpgrade && ((ScrollOfUpgrade) item).isKnown())
                || (item instanceof PotionOfStrength && ((PotionOfStrength) item).isKnown())) {
              GLog.p(TXT_YOU_NOW_HAVE, item.name());
            } else {
              GLog.i(TXT_YOU_NOW_HAVE, item.name());
            }
          }

          if (!heap.isEmpty()) {
            GLog.i(TXT_SOMETHING_ELSE);
          }
          curAction = null;
        } else {
          Dungeon.level.drop(item, pos).sprite.drop();
          ready();
        }
      } else {
        ready();
      }

      return false;

    } else if (getCloser(dst)) {

      return true;

    } else {
      ready();
      return false;
    }
  }
  private boolean actAscend(HeroAction.Ascend action) {
    int stairs = action.dst;
    if (pos == stairs && pos == Dungeon.level.entrance) {

      if (Dungeon.depth == 1) {

        if (belongings.getItem(Amulet.class) == null) {
          GameScene.show(new WndMessage(TXT_LEAVE));
          ready();
        } else {
          Dungeon.win(ResultDescriptions.WIN);
          Dungeon.deleteGame(Dungeon.hero.heroClass, true);
          Game.switchScene(SurfaceScene.class);
        }

      } else {

        curAction = null;

        Hunger hunger = buff(Hunger.class);
        if (hunger != null && !hunger.isStarving()) {
          hunger.satisfy(-Hunger.STARVING / 10);
        }

        InterlevelScene.mode = InterlevelScene.Mode.ASCEND;
        Game.switchScene(InterlevelScene.class);
      }

      return false;

    } else if (getCloser(stairs)) {

      return true;

    } else {
      ready();
      return false;
    }
  }
  private boolean actUnlock(HeroAction.Unlock action) {
    int doorCell = action.dst;
    if (Level.adjacent(pos, doorCell)) {

      theKey = null;
      int door = Dungeon.level.map[doorCell];

      if (door == Terrain.LOCKED_DOOR) {

        theKey = belongings.getKey(IronKey.class, Dungeon.depth);

      } else if (door == Terrain.LOCKED_EXIT) {

        theKey = belongings.getKey(SkeletonKey.class, Dungeon.depth);
      }

      if (theKey != null) {

        spend(Key.TIME_TO_UNLOCK);
        sprite.operate(doorCell);

        Sample.INSTANCE.play(Assets.SND_UNLOCK);

      } else {
        GLog.w(TXT_LOCKED_DOOR);
        ready();
      }

      return false;

    } else if (getCloser(doorCell)) {

      return true;

    } else {
      ready();
      return false;
    }
  }
  private boolean actBuy(HeroAction.Buy action) {
    int dst = action.dst;
    if (pos == dst || Level.adjacent(pos, dst)) {

      ready();

      Heap heap = Dungeon.level.heaps.get(dst);
      if (heap != null && heap.type == Type.FOR_SALE && heap.size() == 1) {
        GameScene.show(new WndTradeItem(heap, true));
      }

      return false;

    } else if (getCloser(dst)) {

      return true;

    } else {
      ready();
      return false;
    }
  }
  private boolean actInteract(HeroAction.Interact action) {

    NPC npc = action.npc;

    if (Level.adjacent(pos, npc.pos)) {

      ready();
      sprite.turnTo(pos, npc.pos);
      npc.interact();
      return false;

    } else {

      if (Level.fieldOfView[npc.pos] && getCloser(npc.pos)) {

        return true;

      } else {
        ready();
        return false;
      }
    }
  }
  private boolean actMove(HeroAction.Move action) {

    if (getCloser(action.dst)) {

      return true;

    } else {
      if (Dungeon.level.map[pos] == Terrain.SIGN) {
        GameScene.show(new WndMessage(Dungeon.tip()));
      }
      ready();
      return false;
    }
  }
Beispiel #10
0
  private boolean actAttack(HeroAction.Attack action) {

    enemy = action.target;

    if (Level.adjacent(pos, enemy.pos) && enemy.isAlive() && !pacified) {

      spend(attackDelay());
      sprite.attack(enemy.pos);

      return false;

    } else {

      if (Level.fieldOfView[enemy.pos] && getCloser(enemy.pos)) {

        return true;

      } else {
        ready();
        return false;
      }
    }
  }
Beispiel #11
0
  @Override
  public boolean act() {

    super.act();

    if (paralysed) {

      curAction = null;

      spendAndNext(TICK);
      return false;
    }

    checkVisibleMobs();
    AttackIndicator.updateState();

    if (curAction == null) {

      if (restoreHealth) {
        if (isStarving() || HP >= HT) {
          restoreHealth = false;
        } else {
          spend(TIME_TO_REST);
          next();
          return false;
        }
      }

      ready();
      return false;

    } else {

      restoreHealth = false;

      ready = false;

      if (curAction instanceof HeroAction.Move) {

        return actMove((HeroAction.Move) curAction);

      } else if (curAction instanceof HeroAction.Interact) {

        return actInteract((HeroAction.Interact) curAction);

      } else if (curAction instanceof HeroAction.Buy) {

        return actBuy((HeroAction.Buy) curAction);

      } else if (curAction instanceof HeroAction.PickUp) {

        return actPickUp((HeroAction.PickUp) curAction);

      } else if (curAction instanceof HeroAction.OpenChest) {

        return actOpenChest((HeroAction.OpenChest) curAction);

      } else if (curAction instanceof HeroAction.Unlock) {

        return actUnlock((HeroAction.Unlock) curAction);

      } else if (curAction instanceof HeroAction.Descend) {

        return actDescend((HeroAction.Descend) curAction);

      } else if (curAction instanceof HeroAction.Ascend) {

        return actAscend((HeroAction.Ascend) curAction);

      } else if (curAction instanceof HeroAction.Attack) {

        return actAttack((HeroAction.Attack) curAction);

      } else if (curAction instanceof HeroAction.Cook) {

        return actCook((HeroAction.Cook) curAction);
      }
    }

    return false;
  }