Search in sources :

Example 16 with Mob

use of com.shatteredpixel.shatteredpixeldungeon.actors.mobs.Mob in project shattered-pixel-dungeon-gdx by 00-Evan.

the class Level method restoreFromBundle.

@Override
public void restoreFromBundle(Bundle bundle) {
    version = bundle.getInt(VERSION);
    // saves from before 0.5.0b are not supported
    if (version < ShatteredPixelDungeon.v0_5_0b) {
        throw new RuntimeException("old save");
    }
    setSize(bundle.getInt(WIDTH), bundle.getInt(HEIGHT));
    mobs = new HashSet<>();
    heaps = new SparseArray<>();
    blobs = new HashMap<>();
    plants = new SparseArray<>();
    traps = new SparseArray<>();
    customTiles = new HashSet<>();
    customWalls = new HashSet<>();
    map = bundle.getIntArray(MAP);
    visited = bundle.getBooleanArray(VISITED);
    mapped = bundle.getBooleanArray(MAPPED);
    entrance = bundle.getInt(ENTRANCE);
    exit = bundle.getInt(EXIT);
    locked = bundle.getBoolean(LOCKED);
    // pre-0.6.1 saves
    if (version <= ShatteredPixelDungeon.v0_6_0b) {
        map = Terrain.convertTilesFrom0_6_0b(map);
    }
    Collection<Bundlable> collection = bundle.getCollection(HEAPS);
    for (Bundlable h : collection) {
        Heap heap = (Heap) h;
        if (!heap.isEmpty())
            heaps.put(heap.pos, heap);
    }
    collection = bundle.getCollection(PLANTS);
    for (Bundlable p : collection) {
        Plant plant = (Plant) p;
        plants.put(plant.pos, plant);
    }
    collection = bundle.getCollection(TRAPS);
    for (Bundlable p : collection) {
        Trap trap = (Trap) p;
        traps.put(trap.pos, trap);
    }
    collection = bundle.getCollection(CUSTOM_TILES);
    for (Bundlable p : collection) {
        CustomTiledVisual vis = (CustomTiledVisual) p;
        customTiles.add(vis);
    }
    collection = bundle.getCollection(CUSTOM_WALLS);
    for (Bundlable p : collection) {
        CustomTiledVisual vis = (CustomTiledVisual) p;
        customWalls.add(vis);
    }
    collection = bundle.getCollection(MOBS);
    for (Bundlable m : collection) {
        Mob mob = (Mob) m;
        if (mob != null) {
            mobs.add(mob);
        }
    }
    collection = bundle.getCollection(BLOBS);
    for (Bundlable b : collection) {
        Blob blob = (Blob) b;
        blobs.put(blob.getClass(), blob);
    }
    feeling = bundle.getEnum(FEELING, Feeling.class);
    if (feeling == Feeling.DARK)
        viewDistance = Math.round(viewDistance / 2f);
    buildFlagMaps();
    cleanWalls();
}
Also used : Mob(com.shatteredpixel.shatteredpixeldungeon.actors.mobs.Mob) Bundlable(com.watabou.utils.Bundlable) Blob(com.shatteredpixel.shatteredpixeldungeon.actors.blobs.Blob) Trap(com.shatteredpixel.shatteredpixeldungeon.levels.traps.Trap) Heap(com.shatteredpixel.shatteredpixeldungeon.items.Heap) Plant(com.shatteredpixel.shatteredpixeldungeon.plants.Plant) CustomTiledVisual(com.shatteredpixel.shatteredpixeldungeon.tiles.CustomTiledVisual)

Example 17 with Mob

use of com.shatteredpixel.shatteredpixeldungeon.actors.mobs.Mob in project shattered-pixel-dungeon-gdx by 00-Evan.

the class Level method updateFieldOfView.

public void updateFieldOfView(Char c, boolean[] fieldOfView) {
    int cx = c.pos % width();
    int cy = c.pos / width();
    boolean sighted = c.buff(Blindness.class) == null && c.buff(Shadows.class) == null && c.buff(TimekeepersHourglass.timeStasis.class) == null && c.isAlive();
    if (sighted) {
        ShadowCaster.castShadow(cx, cy, fieldOfView, c.viewDistance);
    } else {
        BArray.setFalse(fieldOfView);
    }
    int sense = 1;
    // Currently only the hero can get mind vision
    if (c.isAlive() && c == Dungeon.hero) {
        for (Buff b : c.buffs(MindVision.class)) {
            sense = Math.max(((MindVision) b).distance, sense);
        }
    }
    if ((sighted && sense > 1) || !sighted) {
        int ax = Math.max(0, cx - sense);
        int bx = Math.min(cx + sense, width() - 1);
        int ay = Math.max(0, cy - sense);
        int by = Math.min(cy + sense, height() - 1);
        int len = bx - ax + 1;
        int pos = ax + ay * width();
        for (int y = ay; y <= by; y++, pos += width()) {
            System.arraycopy(discoverable, pos, fieldOfView, pos, len);
        }
    }
    // Currently only the hero can get mind vision or awareness
    if (c.isAlive() && c == Dungeon.hero) {
        Dungeon.hero.mindVisionEnemies.clear();
        if (c.buff(MindVision.class) != null) {
            for (Mob mob : mobs) {
                int p = mob.pos;
                if (!fieldOfView[p]) {
                    Dungeon.hero.mindVisionEnemies.add(mob);
                }
            }
        } else if (((Hero) c).heroClass == HeroClass.HUNTRESS) {
            for (Mob mob : mobs) {
                int p = mob.pos;
                if (distance(c.pos, p) == 2) {
                    if (!fieldOfView[p]) {
                        Dungeon.hero.mindVisionEnemies.add(mob);
                    }
                }
            }
        }
        for (Mob m : Dungeon.hero.mindVisionEnemies) {
            for (int i : PathFinder.NEIGHBOURS9) {
                fieldOfView[m.pos + i] = true;
            }
        }
        if (c.buff(Awareness.class) != null) {
            for (Heap heap : heaps.values()) {
                int p = heap.pos;
                for (int i : PathFinder.NEIGHBOURS9) fieldOfView[p + i] = true;
            }
        }
    }
    if (c == Dungeon.hero) {
        for (Heap heap : heaps.values()) if (!heap.seen && fieldOfView[heap.pos])
            heap.seen = true;
    }
}
Also used : Mob(com.shatteredpixel.shatteredpixeldungeon.actors.mobs.Mob) Awareness(com.shatteredpixel.shatteredpixeldungeon.actors.buffs.Awareness) Hero(com.shatteredpixel.shatteredpixeldungeon.actors.hero.Hero) Buff(com.shatteredpixel.shatteredpixeldungeon.actors.buffs.Buff) MindVision(com.shatteredpixel.shatteredpixeldungeon.actors.buffs.MindVision) Point(com.watabou.utils.Point) Heap(com.shatteredpixel.shatteredpixeldungeon.items.Heap)

Example 18 with Mob

use of com.shatteredpixel.shatteredpixeldungeon.actors.mobs.Mob in project shattered-pixel-dungeon-gdx by 00-Evan.

the class PrisonBossLevel method restoreFromBundle.

@Override
public void restoreFromBundle(Bundle bundle) {
    super.restoreFromBundle(bundle);
    state = bundle.getEnum(STATE, State.class);
    // in some states tengu won't be in the world, in others he will be.
    if (state == State.START || state == State.MAZE) {
        tengu = (Tengu) bundle.get(TENGU);
    } else {
        for (Mob mob : mobs) {
            if (mob instanceof Tengu) {
                tengu = (Tengu) mob;
                break;
            }
        }
    }
    for (Bundlable item : bundle.getCollection(STORED_ITEMS)) {
        storedItems.add((Item) item);
    }
}
Also used : Mob(com.shatteredpixel.shatteredpixeldungeon.actors.mobs.Mob) Bundlable(com.watabou.utils.Bundlable) Tengu(com.shatteredpixel.shatteredpixeldungeon.actors.mobs.Tengu)

Example 19 with Mob

use of com.shatteredpixel.shatteredpixeldungeon.actors.mobs.Mob 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 20 with Mob

use of com.shatteredpixel.shatteredpixeldungeon.actors.mobs.Mob in project shattered-pixel-dungeon-gdx by 00-Evan.

the class ShopRoom method placeShopkeeper.

protected void placeShopkeeper(Level level) {
    int pos = level.pointToCell(center());
    Mob shopkeeper = new Shopkeeper();
    shopkeeper.pos = pos;
    level.mobs.add(shopkeeper);
}
Also used : Mob(com.shatteredpixel.shatteredpixeldungeon.actors.mobs.Mob) Shopkeeper(com.shatteredpixel.shatteredpixeldungeon.actors.mobs.npcs.Shopkeeper) Point(com.watabou.utils.Point)

Aggregations

Mob (com.shatteredpixel.shatteredpixeldungeon.actors.mobs.Mob)49 Char (com.shatteredpixel.shatteredpixeldungeon.actors.Char)13 Heap (com.shatteredpixel.shatteredpixeldungeon.items.Heap)11 Hero (com.shatteredpixel.shatteredpixeldungeon.actors.hero.Hero)9 Item (com.shatteredpixel.shatteredpixeldungeon.items.Item)7 ArrayList (java.util.ArrayList)6 Plant (com.shatteredpixel.shatteredpixeldungeon.plants.Plant)4 Blob (com.shatteredpixel.shatteredpixeldungeon.actors.blobs.Blob)3 Mimic (com.shatteredpixel.shatteredpixeldungeon.actors.mobs.Mimic)3 Trap (com.shatteredpixel.shatteredpixeldungeon.levels.traps.Trap)3 CustomTiledVisual (com.shatteredpixel.shatteredpixeldungeon.tiles.CustomTiledVisual)3 Point (com.watabou.utils.Point)3 Awareness (com.shatteredpixel.shatteredpixeldungeon.actors.buffs.Awareness)2 Buff (com.shatteredpixel.shatteredpixeldungeon.actors.buffs.Buff)2 Burning (com.shatteredpixel.shatteredpixeldungeon.actors.buffs.Burning)2 MindVision (com.shatteredpixel.shatteredpixeldungeon.actors.buffs.MindVision)2 Terror (com.shatteredpixel.shatteredpixeldungeon.actors.buffs.Terror)2 King (com.shatteredpixel.shatteredpixeldungeon.actors.mobs.King)2 Statue (com.shatteredpixel.shatteredpixeldungeon.actors.mobs.Statue)2 Flare (com.shatteredpixel.shatteredpixeldungeon.effects.Flare)2