Esempio n. 1
0
  @Override
  public void onOperateComplete() {

    if (curAction instanceof HeroAction.Unlock) {

      if (theKey != null) {
        theKey.detach(belongings.backpack);
        theKey = null;
      }

      int doorCell = ((HeroAction.Unlock) curAction).dst;
      int door = Dungeon.level.map[doorCell];

      Level.set(doorCell, door == Terrain.LOCKED_DOOR ? Terrain.DOOR : Terrain.UNLOCKED_EXIT);
      GameScene.updateMap(doorCell);

    } else if (curAction instanceof HeroAction.OpenChest) {

      if (theKey != null) {
        theKey.detach(belongings.backpack);
        theKey = null;
      }

      Heap heap = Dungeon.level.heaps.get(((HeroAction.OpenChest) curAction).dst);
      if (heap.type == Type.SKELETON) {
        Sample.INSTANCE.play(Assets.SND_BONES);
      }
      heap.open(this);
    }
    curAction = null;

    super.onOperateComplete();
  }
Esempio n. 2
0
  public void handle(int cell) {

    if (cell == -1) {
      return;
    }

    Char ch;
    Heap heap;

    if (Dungeon.level.map[cell] == Terrain.ALCHEMY && cell != pos) {

      curAction = new HeroAction.Cook(cell);

    } else if (Level.fieldOfView[cell] && (ch = Actor.findChar(cell)) instanceof Mob) {

      if (ch instanceof Mob.NPC) {
        curAction = new HeroAction.Interact((Mob.NPC) ch);
      } else {
        curAction = new HeroAction.Attack(ch);
      }

    } else if ((heap = Dungeon.level.heaps.get(cell)) != null) {

      switch (heap.type) {
        case HEAP:
          curAction = new HeroAction.PickUp(cell);
          break;
        case FOR_SALE:
          curAction =
              heap.size() == 1 && heap.peek().price() > 0
                  ? new HeroAction.Buy(cell)
                  : new HeroAction.PickUp(cell);
          break;
        default:
          curAction = new HeroAction.OpenChest(cell);
      }

    } else if (Dungeon.level.map[cell] == Terrain.LOCKED_DOOR
        || Dungeon.level.map[cell] == Terrain.LOCKED_EXIT) {

      curAction = new HeroAction.Unlock(cell);

    } else if (cell == Dungeon.level.exit) {

      curAction = new HeroAction.Descend(cell);

    } else if (cell == Dungeon.level.entrance) {

      curAction = new HeroAction.Ascend(cell);

    } else {

      curAction = new HeroAction.Move(cell);
      lastAction = null;
    }

    act();
  }
Esempio n. 3
0
  private void 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));
      }

    } else if (getCloser(dst)) {

    } else {
      ready();
    }
  }
Esempio n. 4
0
  private void 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();
      }

    } else if (getCloser(dst)) {

    } else {
      ready();
    }
  }