private void summon() {

    nextPedestal = !nextPedestal;

    sprite.centerEmitter().start(Speck.factory(Speck.SCREAM), 0.4f, 2);
    Sample.INSTANCE.play(Assets.SND_CHALLENGE);

    boolean[] passable = Level.passable.clone();
    for (Char c : Actor.chars()) {
      passable[c.pos] = false;
    }

    int undeadsToSummon = maxArmySize() - Undead.count;

    PathFinder.buildDistanceMap(pos, passable, undeadsToSummon);
    PathFinder.distance[pos] = Integer.MAX_VALUE;
    int dist = 1;

    undeadLabel:
    for (int i = 0; i < undeadsToSummon; i++) {
      do {
        for (int j = 0; j < Level.LENGTH; j++) {
          if (PathFinder.distance[j] == dist) {

            Undead undead = new Undead();
            undead.pos = j;
            GameScene.add(undead);

            ScrollOfTeleportation.appear(undead, j);
            new Flare(3, 32).color(0x000000, false).show(undead.sprite, 2f);

            PathFinder.distance[j] = Integer.MAX_VALUE;

            continue undeadLabel;
          }
        }
        dist++;
      } while (dist < undeadsToSummon);
    }

    yell("Arise, slaves!");
  }
Example #2
0
  public static int flee(Char ch, int cur, int from, boolean pass[], boolean[] visible) {

    if (ch.flying) {
      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;
        }
      }
    }
    passable[cur] = true;

    return PathFinder.getStepBack(cur, from, passable);
  }
Example #3
0
  public static void init() {

    challenges = PixelDungeon.challenges();

    Actor.clear();

    PathFinder.setMapSize(Level.WIDTH, Level.HEIGHT);

    Scroll.initLabels();
    Potion.initColors();
    Wand.initWoods();
    Ring.initGems();

    Statistics.reset();
    Journal.reset();

    depth = 0;
    gold = 0;

    potionOfStrength = 0;
    scrollsOfUpgrade = 0;
    arcaneStyli = 0;
    dewVial = true;
    transmutation = Random.IntRange(6, 14);

    chapters = new HashSet<Integer>();

    Ghost.Quest.reset();
    WandMaker.Quest.reset();
    Blacksmith.Quest.reset();
    Imp.Quest.reset();

    Room.shuffleTypes();

    hero = new Hero();
    hero.live();

    Badges.reset();

    StartScene.curClass.initHero(hero);
  }
Example #4
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);
  }
Example #5
0
  public static void loadGame(String fileName, boolean fullLoad) throws IOException {

    Bundle bundle = gameBundle(fileName);

    Dungeon.challenges = bundle.getInt(CHALLENGES);

    Dungeon.level = null;
    Dungeon.depth = -1;

    if (fullLoad) {
      PathFinder.setMapSize(Level.WIDTH, Level.HEIGHT);
    }

    Scroll.restore(bundle);
    Potion.restore(bundle);
    Wand.restore(bundle);
    Ring.restore(bundle);

    potionOfStrength = bundle.getInt(POS);
    scrollsOfUpgrade = bundle.getInt(SOU);
    arcaneStyli = bundle.getInt(AS);
    dewVial = bundle.getBoolean(DV);
    transmutation = bundle.getInt(WT);

    if (fullLoad) {
      chapters = new HashSet<Integer>();
      int ids[] = bundle.getIntArray(CHAPTERS);
      if (ids != null) {
        for (int id : ids) {
          chapters.add(id);
        }
      }

      Bundle quests = bundle.getBundle(QUESTS);
      if (!quests.isNull()) {
        Ghost.Quest.restoreFromBundle(quests);
        WandMaker.Quest.restoreFromBundle(quests);
        Blacksmith.Quest.restoreFromBundle(quests);
        Imp.Quest.restoreFromBundle(quests);
      } else {
        Ghost.Quest.reset();
        WandMaker.Quest.reset();
        Blacksmith.Quest.reset();
        Imp.Quest.reset();
      }

      Room.restoreRoomsFromBundle(bundle);
    }

    Bundle badges = bundle.getBundle(BADGES);
    if (!badges.isNull()) {
      Badges.loadLocal(badges);
    } else {
      Badges.reset();
    }

    String qsClass = bundle.getString(QUICKSLOT);
    if (qsClass != null) {
      try {
        quickslot = Class.forName(qsClass);
      } catch (ClassNotFoundException e) {
      }
    } else {
      quickslot = null;
    }

    @SuppressWarnings("unused")
    String version = bundle.getString(VERSION);

    hero = null;
    hero = (Hero) bundle.get(HERO);

    gold = bundle.getInt(GOLD);
    depth = bundle.getInt(DEPTH);

    Statistics.restoreFromBundle(bundle);
    Journal.restoreFromBundle(bundle);
  }
  @Override
  public void shatter(int cell) {

    PathFinder.buildDistanceMap(cell, BArray.not(Level.losBlocking, null), DISTANCE);

    boolean procd = false;

    Blob[] blobs = {
      Dungeon.level.blobs.get(ToxicGas.class), Dungeon.level.blobs.get(ParalyticGas.class)
    };

    for (int j = 0; j < blobs.length; j++) {

      Blob blob = blobs[j];
      if (blob == null) {
        continue;
      }

      for (int i = 0; i < Level.LENGTH; i++) {
        if (PathFinder.distance[i] < Integer.MAX_VALUE) {

          int value = blob.cur[i];
          if (value > 0) {

            blob.cur[i] = 0;
            blob.volume -= value;
            procd = true;

            if (Dungeon.visible[i]) {
              CellEmitter.get(i).burst(Speck.factory(Speck.DISCOVER), 1);
            }
          }
        }
      }
    }

    boolean heroAffected = PathFinder.distance[Dungeon.hero.pos] < Integer.MAX_VALUE;

    if (procd) {

      if (Dungeon.visible[cell]) {
        splash(cell);
        Sample.INSTANCE.play(Assets.SND_SHATTER);
      }

      setKnown();

      if (heroAffected) {
        GLog.p(TXT_FRESHNESS);
      }

    } else {

      super.shatter(cell);

      if (heroAffected) {
        GLog.i(TXT_FRESHNESS);
        setKnown();
      }
    }
  }