示例#1
0
  private void jump() {
    timeToJump = JUMP_DELAY;

    for (int i = 0; i < 4; i++) {
      int trapPos;
      do {
        trapPos = Random.Int(Level.LENGTH);
      } while (!Level.fieldOfView[trapPos] || !Level.passable[trapPos]);

      if (Dungeon.level.map[trapPos] == Terrain.INACTIVE_TRAP) {
        Level.set(trapPos, Terrain.POISON_TRAP);
        GameScene.updateMap(trapPos);
        ScrollOfMagicMapping.discover(trapPos);
      }
    }

    int newPos;
    do {
      newPos = Random.Int(Level.LENGTH);
    } while (!Level.fieldOfView[newPos]
        || !Level.passable[newPos]
        || (enemy != null && Level.adjacent(newPos, enemy.pos))
        || Actor.findChar(newPos) != null);

    sprite.move(pos, newPos);
    move(newPos);

    if (Dungeon.visible[newPos]) {
      CellEmitter.get(newPos).burst(Speck.factory(Speck.WOOL), 6);
      Sample.INSTANCE.play(Assets.SND_PUFF);
    }

    spend(1 / speed());
  }
示例#2
0
 @Override
 protected boolean doAttack(Char enemy) {
   timeToJump--;
   if (timeToJump <= 0 && Level.adjacent(pos, enemy.pos)) {
     jump();
     return true;
   } else {
     return super.doAttack(enemy);
   }
 }
示例#3
0
  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;
    }
  }
示例#4
0
  private boolean getCloser(final int target) {

    if (rooted) {
      return false;
    }

    int step = -1;

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

      if (Actor.findChar(target) == null) {
        if (Level.pit[target] && !flying && !Chasm.jumpConfirmed) {
          Chasm.heroJump(this);
          interrupt();
          return false;
        }
        if (Level.passable[target] || Level.avoid[target]) {
          step = target;
        }
      }

    } else {

      int len = Level.LENGTH;
      boolean[] p = Level.passable;
      boolean[] v = Dungeon.level.visited;
      boolean[] m = Dungeon.level.mapped;
      boolean[] passable = new boolean[len];
      for (int i = 0; i < len; i++) {
        passable[i] = p[i] && (v[i] || m[i]);
      }

      step = Dungeon.findPath(this, pos, target, passable, Level.fieldOfView);
    }

    if (step != -1) {

      int oldPos = pos;
      move(step);
      sprite.move(oldPos, pos);
      spend(1 / speed());

      return true;

    } else {

      return false;
    }
  }
示例#5
0
  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;
    }
  }
示例#6
0
  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;
    }
  }
示例#7
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;
      }
    }
  }
示例#8
0
  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;
      }
    }
  }
示例#9
0
  public static int findPath(Char ch, int from, int to, boolean pass[], boolean[] visible) {

    if (Level.adjacent(from, to)) {
      return Actor.findChar(to) == null && (pass[to] || Level.avoid[to]) ? to : -1;
    }

    if (ch.flying || ch.buff(Amok.class) != null) {
      BArray.or(pass, Level.avoid, passable);
    } else {
      System.arraycopy(pass, 0, passable, 0, Level.LENGTH);
    }

    for (Actor actor : Actor.all()) {
      if (actor instanceof Char) {
        int pos = ((Char) actor).pos;
        if (visible[pos]) {
          passable[pos] = false;
        }
      }
    }

    return PathFinder.getStep(from, to, passable);
  }