Example #1
0
  private void hit(Char ch, int damage) {

    if (damage < 1) {
      return;
    }

    affected.add(ch);
    ch.damage(
        Level.water[ch.pos] && !ch.flying ? (int) (damage * 2) : damage, LightningTrap.LIGHTNING);

    ch.sprite.centerEmitter().burst(SparkParticle.FACTORY, 3);
    ch.sprite.flash();

    points[nPoints++] = ch.pos;

    HashSet<Char> ns = new HashSet<Char>();
    for (int i = 0; i < Level.NEIGHBOURS8.length; i++) {
      Char n = Actor.findChar(ch.pos + Level.NEIGHBOURS8[i]);
      if (n != null && !affected.contains(n)) {
        ns.add(n);
      }
    }

    if (ns.size() > 0) {
      hit(Random.element(ns), Random.Int(damage / 2, damage));
    }
  }
Example #2
0
  @Override
  public void die(Object cause) {

    curAction = null;

    DewVial.autoDrink(this);
    if (isAlive()) {
      new Flare(8, 32).color(0xFFFF66, true).show(sprite, 2f);
      return;
    }

    Actor.fixTime();
    super.die(cause);

    Ankh ankh = (Ankh) belongings.getItem(Ankh.class);
    if (ankh == null) {

      reallyDie(cause);

    } else {

      Dungeon.deleteGame(Dungeon.hero.heroClass, false);
      GameScene.show(new WndResurrect(ankh, cause));
    }
  }
Example #3
0
  protected void wandEffect(final int cell) {
    setKnown();

    QuickSlot.target(curItem, Actor.findChar(cell));

    if (curCharges > 0) {

      getCurUser().busy();

      fx(
          cell,
          new Callback() {
            @Override
            public void call() {
              onZap(cell);
              wandUsed();
            }
          });

      Invisibility.dispel(getCurUser());
    } else {

      getCurUser().spendAndNext(TIME_TO_ZAP);
      GLog.w(TXT_FIZZLES);
      levelKnown = true;

      if (Random.Int(5) == 0) {
        identify();
      }

      updateQuickslot();
    }
  }
Example #4
0
  @Override
  public boolean attack(Char enemy) {

    for (int i = 1; i < Ballistica.distance; i++) {

      int pos = Ballistica.trace[i];

      Char ch = Actor.findChar(pos);
      if (ch == null) {
        continue;
      }

      if (hit(this, ch, true)) {
        ch.damage(Random.NormalIntRange(14, 20), this);

        if (Dungeon.visible[pos]) {
          ch.getSprite().flash();
          CellEmitter.center(pos).burst(PurpleParticle.BURST, Random.IntRange(1, 2));
        }

        if (!ch.isAlive() && ch == Dungeon.hero) {
          Dungeon.fail(
              Utils.format(ResultDescriptions.MOB, Utils.indefinite(getName()), Dungeon.depth));
          GLog.n(TXT_DEATHGAZE_KILLED, getName());
        }
      } else {
        ch.getSprite().showStatus(CharSprite.NEUTRAL, ch.defenseVerb());
      }
    }

    return true;
  }
Example #5
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());
  }
Example #6
0
  public boolean handle(int cell) {

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

    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 NPC) {
        curAction = new HeroAction.Interact((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;
    }

    return act();
  }
Example #7
0
  public static void resetLevel() {

    Actor.clear();

    Arrays.fill(visible, false);

    level.reset();
    switchLevel(level, level.entrance);
  }
Example #8
0
 @Override
 protected void onZap(int cell) {
   Char ch = Actor.findChar(cell);
   if (ch != null) {
     Buff.affect(ch, Poison.class).set(Poison.durationFactor(ch) * (5 + level()));
   } else {
     GLog.i(Game.getVar(R.string.WandOfPoison_Info1));
   }
 }
Example #9
0
  public static Level loadLevel(HeroClass cl) throws IOException {

    Dungeon.level = null;
    Actor.clear();

    InputStream input = Game.instance.openFileInput(Utils.format(depthFile(cl), depth));
    Bundle bundle = Bundle.read(input);
    input.close();

    return (Level) bundle.get("level");
  }
Example #10
0
  @SuppressWarnings("deprecation")
  public static void switchLevel(final Level level, int pos) {

    nightMode = new Date().getHours() < 7;

    Dungeon.level = level;
    Actor.init();

    Actor respawner = level.respawner();
    if (respawner != null) {
      Actor.add(level.respawner());
    }

    hero.pos = pos != -1 ? pos : level.exit;

    Light light = hero.buff(Light.class);
    hero.viewDistance =
        light == null ? level.viewDistance : Math.max(Light.DISTANCE, level.viewDistance);

    observe();
  }
Example #11
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 #12
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;
    }
  }
Example #13
0
  public static void saveAll() throws IOException {
    if (hero.isAlive()) {

      Actor.fixTime();
      saveGame(gameFile(hero.heroClass));
      saveLevel();

      GamesInProgress.set(hero.heroClass, depth, hero.lvl);

    } else if (WndResurrect.instance != null) {

      WndResurrect.instance.hide();
      Hero.reallyDie(WndResurrect.causeOfDeath);
    }
  }
Example #14
0
  @Override
  protected void evolve() {

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

      int offv = cur[i] > 0 ? cur[i] - 1 : 0;
      off[i] = offv;

      if (offv > 0) {

        volume += offv;

        Char ch = Actor.findChar(i);
        if (ch != null) {
          Buff.prolong(ch, Roots.class, TICK);
        }
      }
    }
  }
Example #15
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 #16
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 #17
0
  public static Level newLevel() {

    Dungeon.level = null;
    Actor.clear();

    depth++;
    if (depth > Statistics.deepestFloor) {
      Statistics.deepestFloor = depth;

      if (Statistics.qualifiedForNoKilling) {
        Statistics.completedWithNoKilling = true;
      } else {
        Statistics.completedWithNoKilling = false;
      }
    }

    Arrays.fill(visible, false);

    Level level;
    switch (depth) {
      case 1:
      case 2:
      case 3:
      case 4:
        level = new SewerLevel();
        break;
      case 5:
        level = new SewerBossLevel();
        break;
      case 6:
      case 7:
      case 8:
      case 9:
        level = new PrisonLevel();
        break;
      case 10:
        level = new PrisonBossLevel();
        break;
      case 11:
      case 12:
      case 13:
      case 14:
        level = new CavesLevel();
        break;
      case 15:
        level = new CavesBossLevel();
        break;
      case 16:
      case 17:
      case 18:
      case 19:
        level = new CityLevel();
        break;
      case 20:
        level = new CityBossLevel();
        break;
      case 21:
        level = new LastShopLevel();
        break;
      case 22:
      case 23:
      case 24:
        level = new HallsLevel();
        break;
      case 25:
        level = new HallsBossLevel();
        break;
      case 26:
        level = new LastLevel();
        break;
      default:
        level = new DeadEndLevel();
        Statistics.deepestFloor--;
    }

    level.create();

    Statistics.qualifiedForNoKilling = !bossLevel();

    return level;
  }