Exemple #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();
  }
Exemple #2
0
  private void 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();
      }

    } else if (getCloser(doorCell)) {

    } else {
      ready();
    }
  }
Exemple #3
0
  public static void reallyDie(Object cause) {

    int length = Level.LENGTH;
    int[] map = Dungeon.level.map;
    boolean[] visited = Dungeon.level.visited;
    boolean[] discoverable = Level.discoverable;

    for (int i = 0; i < length; i++) {

      int terr = map[i];

      if (discoverable[i]) {

        visited[i] = true;
        if ((Terrain.flags[terr] & Terrain.SECRET) != 0) {
          Level.set(i, Terrain.discover(terr));
          GameScene.updateMap(i);
        }
      }
    }

    Bones.leave();

    Dungeon.observe();

    Dungeon.hero.belongings.identify();

    GameScene.gameOver();

    if (cause instanceof Hero.Doom) {
      ((Hero.Doom) cause).onDeath();
    }

    Dungeon.deleteGame(Dungeon.hero.heroClass, true);
  }
  public static void paint(Level level, Room room) {

    fill(level, room, Terrain.WALL);
    fill(level, room, 1, Terrain.EMPTY);

    for (Room.Door door : room.connected.values()) {
      door.set(Room.Door.Type.REGULAR);
    }

    level.exit = room.random(1);
    set(level, level.exit, Terrain.EXIT);
  }
Exemple #5
0
  private void 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;
          }
        }

        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();
      }

    } else if (getCloser(dst)) {

    } else {
      ready();
    }
  }
Exemple #6
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) {

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

      return true;

    } else {

      return false;
    }
  }
Exemple #7
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();
    }
  }
Exemple #8
0
  private void actAttack(HeroAction.Attack action) {

    enemy = action.target;

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

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

    } else {

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

      } else {
        ready();
      }
    }
  }
Exemple #9
0
  @Override
  public int attackSkill(Char target) {

    int bonus = 0;
    for (Buff buff : buffs(RingOfAccuracy.Accuracy.class)) {
      bonus += ((RingOfAccuracy.Accuracy) buff).level;
    }
    float accuracy = (bonus == 0) ? 1 : (float) Math.pow(1.4, bonus);
    if (usingRanged && Level.distance(pos, target.pos) == 1) {
      accuracy *= 0.5f;
    }

    if (belongings.weapon != null) {
      return (int) (attackSkill * accuracy * belongings.weapon.acuracyFactor(this));
    } else {
      return (int) (attackSkill * accuracy);
    }
  }
Exemple #10
0
  private void actInteract(HeroAction.Interact action) {

    Mob.NPC npc = action.npc;

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

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

    } else {

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

      } else {
        ready();
      }
    }
  }
Exemple #11
0
  public boolean search(boolean intentional) {

    boolean smthFound = false;

    int positive = 0;
    int negative = 0;
    for (Buff buff : buffs(RingOfDetection.Detection.class)) {
      int bonus = ((RingOfDetection.Detection) buff).level;
      if (bonus > positive) {
        positive = bonus;
      } else if (bonus < 0) {
        negative += bonus;
      }
    }
    int distance = 1 + positive + negative;

    float level = intentional ? (2 * awareness - awareness * awareness) : awareness;
    if (distance <= 0) {

      level /= 2 - distance;
      distance = 1;
    }

    int cx = pos % Level.WIDTH;
    int cy = pos / Level.WIDTH;
    int ax = cx - distance;
    if (ax < 0) {
      ax = 0;
    }
    int bx = cx + distance;
    if (bx >= Level.WIDTH) {
      bx = Level.WIDTH - 1;
    }
    int ay = cy - distance;
    if (ay < 0) {
      ay = 0;
    }
    int by = cy + distance;
    if (by >= Level.HEIGHT) {
      by = Level.HEIGHT - 1;
    }

    for (int y = ay; y <= by; y++) {
      for (int x = ax, p = ax + y * Level.WIDTH; x <= bx; x++, p++) {

        if (Dungeon.visible[p]) {

          if (intentional) {
            sprite.parent.addToBack(new CheckedCell(p));
          }

          if (Level.secret[p] && (intentional || Random.Float() < level)) {

            int oldValue = Dungeon.level.map[p];

            GameScene.discoverTile(p, oldValue);

            Level.set(p, Terrain.discover(oldValue));

            GameScene.updateMap(p);

            ScrollOfMagicMapping.discover(p);

            smthFound = true;
          }
        }
      }
    }

    if (intentional) {
      sprite.showStatus(CharSprite.DEFAULT, TXT_SEARCH);
      sprite.operate(pos);
      if (smthFound) {
        spendAndNext(Random.Float() < level ? TIME_TO_SEARCH : TIME_TO_SEARCH * 2);
      } else {
        spendAndNext(TIME_TO_SEARCH);
      }
    }

    if (smthFound) {
      GLog.w(TXT_NOTICED_SMTH);
      Sample.INSTANCE.play(Assets.SND_SECRET);
      interrupt();
    }

    return smthFound;
  }