예제 #1
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;
    }
  }
예제 #2
0
  private void circleBack(int from, Hero owner) {

    ((MissileSprite) curUser.sprite.parent.recycle(MissileSprite.class))
        .reset(from, curUser.pos, curItem, null);

    if (throwEquiped) {
      owner.belongings.weapon = this;
      owner.spend(-TIME_TO_EQUIP);
    } else if (!collect(curUser.belongings.backpack)) {
      Dungeon.level.drop(this, owner.pos).sprite.drop();
    }
  }
예제 #3
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;
    }
  }
예제 #4
0
    @Override
    public void execute(Hero hero, String action) {
      if (action.equals(AC_PLANT)) {

        hero.spend(TIME_TO_PLANT);
        hero.busy();
        ((Seed) detach(hero.belongings.backpack)).onThrow(hero.pos);

        hero.getSprite().operate(hero.pos);

      } else if (action.equals(Food.AC_EAT)) {
        detach(hero.belongings.backpack);

        hero.getSprite().operate(hero.pos);
        hero.busy();

        SpellSprite.show(hero, SpellSprite.FOOD);
        Sample.INSTANCE.play(Assets.SND_EAT);

        hero.spend(Food.TIME_TO_EAT);
      }

      super.execute(hero, action);
    }
예제 #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 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;
      }
    }
  }
예제 #7
0
  @Override
  public boolean act() {

    super.act();

    if (paralysed) {

      curAction = null;

      spendAndNext(TICK);
      return false;
    }

    checkVisibleMobs();
    AttackIndicator.updateState();

    if (curAction == null) {

      if (restoreHealth) {
        if (isStarving() || HP >= HT) {
          restoreHealth = false;
        } else {
          spend(TIME_TO_REST);
          next();
          return false;
        }
      }

      ready();
      return false;

    } else {

      restoreHealth = false;

      ready = false;

      if (curAction instanceof HeroAction.Move) {

        return actMove((HeroAction.Move) curAction);

      } else if (curAction instanceof HeroAction.Interact) {

        return actInteract((HeroAction.Interact) curAction);

      } else if (curAction instanceof HeroAction.Buy) {

        return actBuy((HeroAction.Buy) curAction);

      } else if (curAction instanceof HeroAction.PickUp) {

        return actPickUp((HeroAction.PickUp) curAction);

      } else if (curAction instanceof HeroAction.OpenChest) {

        return actOpenChest((HeroAction.OpenChest) curAction);

      } else if (curAction instanceof HeroAction.Unlock) {

        return actUnlock((HeroAction.Unlock) curAction);

      } else if (curAction instanceof HeroAction.Descend) {

        return actDescend((HeroAction.Descend) curAction);

      } else if (curAction instanceof HeroAction.Ascend) {

        return actAscend((HeroAction.Ascend) curAction);

      } else if (curAction instanceof HeroAction.Attack) {

        return actAttack((HeroAction.Attack) curAction);

      } else if (curAction instanceof HeroAction.Cook) {

        return actCook((HeroAction.Cook) curAction);
      }
    }

    return false;
  }
예제 #8
0
 public void spendAndNext(float time) {
   busy();
   spend(time);
   next();
 }