Search in sources :

Example 16 with Item

use of com.shatteredpixel.shatteredpixeldungeon.items.Item in project shattered-pixel-dungeon-gdx by 00-Evan.

the class Hero method reallyDie.

public static void reallyDie(Object cause) {
    int length = Dungeon.level.length();
    int[] map = Dungeon.level.map;
    boolean[] visited = Dungeon.level.visited;
    boolean[] discoverable = Dungeon.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) {
                Dungeon.level.discover(i);
            }
        }
    }
    Bones.leave();
    Dungeon.observe();
    GameScene.updateFog();
    Dungeon.hero.belongings.identify();
    int pos = Dungeon.hero.pos;
    ArrayList<Integer> passable = new ArrayList<Integer>();
    for (Integer ofs : PathFinder.NEIGHBOURS8) {
        int cell = pos + ofs;
        if ((Dungeon.level.passable[cell] || Dungeon.level.avoid[cell]) && Dungeon.level.heaps.get(cell) == null) {
            passable.add(cell);
        }
    }
    Collections.shuffle(passable);
    ArrayList<Item> items = new ArrayList<Item>(Dungeon.hero.belongings.backpack.items);
    for (Integer cell : passable) {
        if (items.isEmpty()) {
            break;
        }
        Item item = Random.element(items);
        Dungeon.level.drop(item, cell).sprite.drop(pos);
        items.remove(item);
    }
    GameScene.gameOver();
    if (cause instanceof Hero.Doom) {
        ((Hero.Doom) cause).onDeath();
    }
    Dungeon.deleteGame(GamesInProgress.curSlot, true);
}
Also used : Item(com.shatteredpixel.shatteredpixeldungeon.items.Item) WndTradeItem(com.shatteredpixel.shatteredpixeldungeon.windows.WndTradeItem) ArrayList(java.util.ArrayList)

Example 17 with Item

use of com.shatteredpixel.shatteredpixeldungeon.items.Item in project shattered-pixel-dungeon-gdx by 00-Evan.

the class Level method findPrizeItem.

public Item findPrizeItem(Class<? extends Item> match) {
    if (itemsToSpawn.size() == 0)
        return null;
    if (match == null) {
        Item item = Random.element(itemsToSpawn);
        itemsToSpawn.remove(item);
        return item;
    }
    for (Item item : itemsToSpawn) {
        if (match.isInstance(item)) {
            itemsToSpawn.remove(item);
            return item;
        }
    }
    return null;
}
Also used : Item(com.shatteredpixel.shatteredpixeldungeon.items.Item)

Example 18 with Item

use of com.shatteredpixel.shatteredpixeldungeon.items.Item in project shattered-pixel-dungeon-gdx by 00-Evan.

the class PrisonBossLevel method progress.

public void progress() {
    switch(state) {
        // moving to the beginning of the fight
        case START:
            seal();
            set(5 + 25 * 32, Terrain.LOCKED_DOOR);
            GameScene.updateMap(5 + 25 * 32);
            for (Mob m : mobs) {
                // bring the first ally with you
                if (m.alignment == Char.Alignment.ALLY) {
                    // they should immediately walk out of the door
                    m.pos = 5 + 25 * 32;
                    m.sprite.place(m.pos);
                    break;
                }
            }
            tengu.state = tengu.HUNTING;
            // in the middle of the fight room
            tengu.pos = 5 + 28 * 32;
            GameScene.add(tengu);
            tengu.notice();
            state = State.FIGHT_START;
            break;
        // halfway through, move to the maze
        case FIGHT_START:
            changeMap(MAP_MAZE);
            // clear the entrance
            clearEntities((Room) new Room().set(0, 5, 8, 32));
            Actor.remove(tengu);
            mobs.remove(tengu);
            TargetHealthIndicator.instance.target(null);
            tengu.sprite.kill();
            Room maze = new MazeRoom();
            maze.set(10, 1, 31, 29);
            maze.connected.put(null, new Room.Door(10, 2));
            maze.connected.put(maze, new Room.Door(20, 29));
            maze.paint(this);
            buildFlagMaps();
            cleanWalls();
            GameScene.resetMap();
            GameScene.flash(0xFFFFFF);
            Sample.INSTANCE.play(Assets.SND_BLAST);
            state = State.MAZE;
            break;
        // maze beaten, moving to the arena
        case MAZE:
            Dungeon.hero.interrupt();
            Dungeon.hero.pos += 9 + 3 * 32;
            Dungeon.hero.sprite.interruptMotion();
            Dungeon.hero.sprite.place(Dungeon.hero.pos);
            changeMap(MAP_ARENA);
            // clear all but the area right around the teleport spot
            clearEntities((Room) new Room().set(0, 0, 10, 4));
            // if any allies are left over, move them along the same way as the hero
            for (Mob m : mobs) {
                if (m.alignment == Char.Alignment.ALLY) {
                    m.pos += 9 + 3 * 32;
                    m.sprite().place(m.pos);
                }
            }
            tengu.state = tengu.HUNTING;
            do {
                tengu.pos = Random.Int(length());
            } while (solid[tengu.pos] || distance(tengu.pos, Dungeon.hero.pos) < 8);
            GameScene.add(tengu);
            tengu.notice();
            GameScene.flash(0xFFFFFF);
            Sample.INSTANCE.play(Assets.SND_BLAST);
            state = State.FIGHT_ARENA;
            break;
        // arena ended, fight over.
        case FIGHT_ARENA:
            unseal();
            CustomTiledVisual vis = new exitVisual();
            vis.pos(11, 8);
            customTiles.add(vis);
            ((GameScene) ShatteredPixelDungeon.scene()).addCustomTile(vis);
            vis = new exitVisualWalls();
            vis.pos(11, 8);
            customWalls.add(vis);
            ((GameScene) ShatteredPixelDungeon.scene()).addCustomWall(vis);
            Dungeon.hero.interrupt();
            Dungeon.hero.pos = 5 + 27 * 32;
            Dungeon.hero.sprite.interruptMotion();
            Dungeon.hero.sprite.place(Dungeon.hero.pos);
            tengu.pos = 5 + 28 * 32;
            tengu.sprite.place(5 + 28 * 32);
            // remove all mobs, but preserve allies
            ArrayList<Mob> allies = new ArrayList<>();
            for (Mob m : mobs.toArray(new Mob[0])) {
                if (m.alignment == Char.Alignment.ALLY) {
                    allies.add(m);
                    mobs.remove(m);
                }
            }
            clearEntities(null);
            changeMap(MAP_END);
            for (Mob m : allies) {
                do {
                    m.pos = Random.IntRange(3, 7) + Random.IntRange(26, 30) * 32;
                } while (findMob(m.pos) != null);
                m.sprite().place(m.pos);
                mobs.add(m);
            }
            tengu.die(Dungeon.hero);
            for (Item item : storedItems) drop(item, randomPrisonCell());
            GameScene.flash(0xFFFFFF);
            Sample.INSTANCE.play(Assets.SND_BLAST);
            state = State.WON;
            break;
    }
}
Also used : Mob(com.shatteredpixel.shatteredpixeldungeon.actors.mobs.Mob) Item(com.shatteredpixel.shatteredpixeldungeon.items.Item) CustomTiledVisual(com.shatteredpixel.shatteredpixeldungeon.tiles.CustomTiledVisual) MazeRoom(com.shatteredpixel.shatteredpixeldungeon.levels.rooms.MazeRoom) GameScene(com.shatteredpixel.shatteredpixeldungeon.scenes.GameScene) ArrayList(java.util.ArrayList) Room(com.shatteredpixel.shatteredpixeldungeon.levels.rooms.Room) MazeRoom(com.shatteredpixel.shatteredpixeldungeon.levels.rooms.MazeRoom)

Example 19 with Item

use of com.shatteredpixel.shatteredpixeldungeon.items.Item in project shattered-pixel-dungeon-gdx by 00-Evan.

the class RegularLevel method createItems.

@Override
protected void createItems() {
    // drops 3/4/5 items 60%/30%/10% of the time
    int nItems = 3 + Random.chances(new float[] { 6, 3, 1 });
    for (int i = 0; i < nItems; i++) {
        Heap.Type type = null;
        switch(Random.Int(20)) {
            case 0:
                type = Heap.Type.SKELETON;
                break;
            case 1:
            case 2:
            case 3:
            case 4:
                type = Heap.Type.CHEST;
                break;
            case 5:
                type = Dungeon.depth > 1 ? Heap.Type.MIMIC : Heap.Type.CHEST;
                break;
            default:
                type = Heap.Type.HEAP;
        }
        int cell = randomDropCell();
        if (map[cell] == Terrain.HIGH_GRASS) {
            map[cell] = Terrain.GRASS;
            losBlocking[cell] = false;
        }
        Item toDrop = Generator.random();
        if (toDrop == null)
            continue;
        if ((toDrop instanceof Artifact && Random.Int(2) == 0) || (toDrop.isUpgradable() && Random.Int(4 - toDrop.level()) == 0)) {
            Heap dropped = drop(toDrop, cell);
            if (heaps.get(cell) == dropped) {
                dropped.type = Heap.Type.LOCKED_CHEST;
                addItemToSpawn(new GoldenKey(Dungeon.depth));
            }
        } else {
            drop(toDrop, cell).type = type;
        }
    }
    for (Item item : itemsToSpawn) {
        int cell = randomDropCell();
        drop(item, cell).type = Heap.Type.HEAP;
        if (map[cell] == Terrain.HIGH_GRASS) {
            map[cell] = Terrain.GRASS;
            losBlocking[cell] = false;
        }
    }
    Item item = Bones.get();
    if (item != null) {
        int cell = randomDropCell();
        if (map[cell] == Terrain.HIGH_GRASS) {
            map[cell] = Terrain.GRASS;
            losBlocking[cell] = false;
        }
        drop(item, cell).type = Heap.Type.REMAINS;
    }
    // guide pages
    Collection<String> allPages = Document.ADVENTURERS_GUIDE.pages();
    ArrayList<String> missingPages = new ArrayList<>();
    for (String page : allPages) {
        if (!Document.ADVENTURERS_GUIDE.hasPage(page)) {
            missingPages.add(page);
        }
    }
    // these are dropped specially
    missingPages.remove(Document.GUIDE_INTRO_PAGE);
    missingPages.remove(Document.GUIDE_SEARCH_PAGE);
    int foundPages = allPages.size() - (missingPages.size() + 2);
    // chance to find a page scales with pages missing and depth
    if (missingPages.size() > 0 && Random.Float() < (Dungeon.depth / (float) (foundPages + 1))) {
        GuidePage p = new GuidePage();
        p.page(missingPages.get(0));
        int cell = randomDropCell();
        if (map[cell] == Terrain.HIGH_GRASS) {
            map[cell] = Terrain.GRASS;
            losBlocking[cell] = false;
        }
        drop(p, cell);
    }
}
Also used : Item(com.shatteredpixel.shatteredpixeldungeon.items.Item) GoldenKey(com.shatteredpixel.shatteredpixeldungeon.items.keys.GoldenKey) GuidePage(com.shatteredpixel.shatteredpixeldungeon.items.journal.GuidePage) ArrayList(java.util.ArrayList) Heap(com.shatteredpixel.shatteredpixeldungeon.items.Heap) Artifact(com.shatteredpixel.shatteredpixeldungeon.items.artifacts.Artifact)

Example 20 with Item

use of com.shatteredpixel.shatteredpixeldungeon.items.Item in project shattered-pixel-dungeon-gdx by 00-Evan.

the class MassGraveRoom method paint.

public void paint(Level level) {
    Door entrance = entrance();
    entrance.set(Door.Type.BARRICADE);
    level.addItemToSpawn(new PotionOfLiquidFlame());
    Painter.fill(level, this, Terrain.WALL);
    Painter.fill(level, this, 1, Terrain.EMPTY_SP);
    Bones b = new Bones();
    b.setRect(left + 1, top, width() - 2, height() - 1);
    level.customTiles.add(b);
    // 50% 1 skeleton, 50% 2 skeletons
    for (int i = 0; i <= Random.Int(2); i++) {
        Skeleton skele = new Skeleton();
        int pos;
        do {
            pos = level.pointToCell(random());
        } while (level.map[pos] != Terrain.EMPTY_SP || level.findMob(pos) != null);
        skele.pos = pos;
        level.mobs.add(skele);
    }
    ArrayList<Item> items = new ArrayList<>();
    // 100% corpse dust, 2x100% 1 coin, 2x30% coins, 1x60% random item, 1x30% armor
    items.add(new CorpseDust());
    items.add(new Gold(1));
    items.add(new Gold(1));
    if (Random.Float() <= 0.3f)
        items.add(new Gold());
    if (Random.Float() <= 0.3f)
        items.add(new Gold());
    if (Random.Float() <= 0.6f)
        items.add(Generator.random());
    if (Random.Float() <= 0.3f)
        items.add(Generator.randomArmor());
    for (Item item : items) {
        int pos;
        do {
            pos = level.pointToCell(random());
        } while (level.map[pos] != Terrain.EMPTY_SP || level.heaps.get(pos) != null);
        Heap h = level.drop(item, pos);
        h.type = Heap.Type.SKELETON;
    }
}
Also used : Item(com.shatteredpixel.shatteredpixeldungeon.items.Item) Gold(com.shatteredpixel.shatteredpixeldungeon.items.Gold) PotionOfLiquidFlame(com.shatteredpixel.shatteredpixeldungeon.items.potions.PotionOfLiquidFlame) ArrayList(java.util.ArrayList) Skeleton(com.shatteredpixel.shatteredpixeldungeon.actors.mobs.Skeleton) Heap(com.shatteredpixel.shatteredpixeldungeon.items.Heap) CorpseDust(com.shatteredpixel.shatteredpixeldungeon.items.quest.CorpseDust)

Aggregations

Item (com.shatteredpixel.shatteredpixeldungeon.items.Item)67 Heap (com.shatteredpixel.shatteredpixeldungeon.items.Heap)14 ArrayList (java.util.ArrayList)14 Hero (com.shatteredpixel.shatteredpixeldungeon.actors.hero.Hero)9 Char (com.shatteredpixel.shatteredpixeldungeon.actors.Char)7 Mob (com.shatteredpixel.shatteredpixeldungeon.actors.mobs.Mob)7 Gold (com.shatteredpixel.shatteredpixeldungeon.items.Gold)7 Point (com.watabou.utils.Point)7 IronKey (com.shatteredpixel.shatteredpixeldungeon.items.keys.IronKey)6 EquipableItem (com.shatteredpixel.shatteredpixeldungeon.items.EquipableItem)5 Flare (com.shatteredpixel.shatteredpixeldungeon.effects.Flare)4 Honeypot (com.shatteredpixel.shatteredpixeldungeon.items.Honeypot)4 WndTradeItem (com.shatteredpixel.shatteredpixeldungeon.windows.WndTradeItem)4 Dewdrop (com.shatteredpixel.shatteredpixeldungeon.items.Dewdrop)3 Armor (com.shatteredpixel.shatteredpixeldungeon.items.armor.Armor)3 Potion (com.shatteredpixel.shatteredpixeldungeon.items.potions.Potion)3 Fire (com.shatteredpixel.shatteredpixeldungeon.actors.blobs.Fire)2 Belongings (com.shatteredpixel.shatteredpixeldungeon.actors.hero.Belongings)2 Thief (com.shatteredpixel.shatteredpixeldungeon.actors.mobs.Thief)2 Ankh (com.shatteredpixel.shatteredpixeldungeon.items.Ankh)2