@Override
  public void execute(Hero hero, String action) {
    if (action.equals(AC_READ)) {

      if (hero.buff(Blindness.class) != null)
        GLog.w("You cannot read from the book while blinded.");
      else if (!isEquipped(hero)) GLog.i("You need to equip your spellbook to do that.");
      else if (charge == 0) GLog.i("Your spellbook is out of energy for now.");
      else if (cursed) GLog.i("Your cannot read from a cursed spellbook.");
      else {
        charge--;

        Scroll scroll;
        do {
          scroll = (Scroll) Generator.random(Generator.Category.SCROLL);
        } while (scroll == null
            ||
            // gotta reduce the rate on these scrolls or that'll be all the item does.
            ((scroll instanceof ScrollOfIdentify
                    || scroll instanceof ScrollOfRemoveCurse
                    || scroll instanceof ScrollOfMagicMapping)
                && Random.Int(2) == 0));

        scroll.ownedByBook = true;
        scroll.execute(hero, AC_READ);
      }

    } else if (action.equals(AC_ADD)) {
      GameScene.selectItem(itemSelector, mode, inventoryTitle);
    } else super.execute(hero, action);
  }
Ejemplo n.º 2
0
  public Statue() {
    super();

    do {
      weapon = (Weapon) Generator.random(Generator.Category.WEAPON);
    } while (!(weapon instanceof MeleeWeapon) || weapon.cursed);

    weapon.identify();
    weapon.enchant(Enchantment.random());

    HP = HT = 15 + Dungeon.depth * 5;
    defenseSkill = 4 + Dungeon.depth;
  }
  private static void generateItems() {

    itemsToSpawn = new ArrayList<Item>();

    switch (Dungeon.depth) {
      case 6:
        itemsToSpawn.add((Random.Int(2) == 0 ? new Quarterstaff() : new Spear()).identify());
        itemsToSpawn.add(
            Random.Int(2) == 0
                ? new IncendiaryDart().quantity(Random.NormalIntRange(2, 4))
                : new CurareDart().quantity(Random.NormalIntRange(1, 3)));
        itemsToSpawn.add(new LeatherArmor().identify());
        break;

      case 11:
        itemsToSpawn.add((Random.Int(2) == 0 ? new Sword() : new Mace()).identify());
        itemsToSpawn.add(
            Random.Int(2) == 0
                ? new CurareDart().quantity(Random.NormalIntRange(2, 5))
                : new Shuriken().quantity(Random.NormalIntRange(3, 6)));
        itemsToSpawn.add(new MailArmor().identify());
        break;

      case 16:
        itemsToSpawn.add((Random.Int(2) == 0 ? new Longsword() : new BattleAxe()).identify());
        itemsToSpawn.add(
            Random.Int(2) == 0
                ? new Shuriken().quantity(Random.NormalIntRange(4, 7))
                : new Javelin().quantity(Random.NormalIntRange(3, 6)));
        itemsToSpawn.add(new ScaleArmor().identify());
        break;

      case 21:
        itemsToSpawn.add(Random.Int(2) == 0 ? new Glaive().identify() : new WarHammer().identify());
        itemsToSpawn.add(
            Random.Int(2) == 0
                ? new Javelin().quantity(Random.NormalIntRange(4, 7))
                : new Tamahawk().quantity(Random.NormalIntRange(4, 7)));
        itemsToSpawn.add(new PlateArmor().identify());
        itemsToSpawn.add(new Torch());
        itemsToSpawn.add(new Torch());
        break;
    }

    itemsToSpawn.add(new MerchantsBeacon());

    ChooseBag(Dungeon.hero.belongings);

    itemsToSpawn.add(new PotionOfHealing());
    for (int i = 0; i < 3; i++) itemsToSpawn.add(Generator.random(Generator.Category.POTION));

    itemsToSpawn.add(new ScrollOfIdentify());
    itemsToSpawn.add(new ScrollOfRemoveCurse());
    itemsToSpawn.add(new ScrollOfMagicMapping());
    itemsToSpawn.add(Generator.random(Generator.Category.SCROLL));

    for (int i = 0; i < 2; i++)
      itemsToSpawn.add(
          Random.Int(2) == 0
              ? Generator.random(Generator.Category.POTION)
              : Generator.random(Generator.Category.SCROLL));

    itemsToSpawn.add(new OverpricedRation());
    itemsToSpawn.add(new OverpricedRation());

    itemsToSpawn.add(new Bomb().random());
    switch (Random.Int(5)) {
      case 1:
        itemsToSpawn.add(new Bomb());
        break;
      case 2:
        itemsToSpawn.add(new Bomb().random());
        break;
      case 3:
      case 4:
        itemsToSpawn.add(new Honeypot());
        break;
    }

    if (Dungeon.depth == 6) {
      itemsToSpawn.add(new Ankh());
      itemsToSpawn.add(new Weightstone());
    } else {
      itemsToSpawn.add(Random.Int(2) == 0 ? new Ankh() : new Weightstone());
    }

    TimekeepersHourglass hourglass = Dungeon.hero.belongings.getItem(TimekeepersHourglass.class);
    if (hourglass != null) {
      int bags = 0;
      // creates the given float percent of the remaining bags to be dropped.
      // this way players who get the hourglass late can still max it, usually.
      switch (Dungeon.depth) {
        case 6:
          bags = (int) Math.ceil((5 - hourglass.sandBags) * 0.20f);
          break;
        case 11:
          bags = (int) Math.ceil((5 - hourglass.sandBags) * 0.25f);
          break;
        case 16:
          bags = (int) Math.ceil((5 - hourglass.sandBags) * 0.50f);
          break;
        case 21:
          bags = (int) Math.ceil((5 - hourglass.sandBags) * 0.80f);
          break;
      }

      for (int i = 1; i <= bags; i++) {
        itemsToSpawn.add(new TimekeepersHourglass.sandBag());
        hourglass.sandBags++;
      }
    }

    Item rare;
    switch (Random.Int(10)) {
      case 0:
        rare = Generator.random(Generator.Category.WAND);
        rare.level = 0;
        break;
      case 1:
        rare = Generator.random(Generator.Category.RING);
        rare.level = 1;
        break;
      case 2:
        rare = Generator.random(Generator.Category.ARTIFACT).identify();
        break;
      default:
        rare = new Stylus();
    }
    rare.cursed = rare.cursedKnown = false;
    itemsToSpawn.add(rare);

    // this is a hard limit, level gen allows for at most an 8x5 room, can't fit more than 39 items
    // + 1 shopkeeper.
    if (itemsToSpawn.size() > 39)
      throw new RuntimeException("Shop attempted to carry more than 39 items!");

    Collections.shuffle(itemsToSpawn);
  }
 private static Item prize(Level level) {
   return Random.Int(6) == 0
       ? new Bomb().random()
       : Generator.random(Random.oneOf(Generator.Category.ARMOR, Generator.Category.WEAPON));
 }