Search in sources :

Example 1 with Trap

use of com.shatteredpixel.shatteredpixeldungeon.levels.traps.Trap in project shattered-pixel-dungeon-gdx by 00-Evan.

the class GameScene method examineCell.

public static void examineCell(Integer cell) {
    if (cell == null || cell < 0 || cell > Dungeon.level.length() || (!Dungeon.level.visited[cell] && !Dungeon.level.mapped[cell])) {
        return;
    }
    ArrayList<String> names = new ArrayList<>();
    final ArrayList<Object> objects = new ArrayList<>();
    if (cell == Dungeon.hero.pos) {
        objects.add(Dungeon.hero);
        names.add(Dungeon.hero.className().toUpperCase(Locale.ENGLISH));
    } else {
        if (Dungeon.level.heroFOV[cell]) {
            Mob mob = (Mob) Actor.findChar(cell);
            if (mob != null) {
                objects.add(mob);
                names.add(Messages.titleCase(mob.name));
            }
        }
    }
    Heap heap = Dungeon.level.heaps.get(cell);
    if (heap != null && heap.seen) {
        objects.add(heap);
        names.add(Messages.titleCase(heap.toString()));
    }
    Plant plant = Dungeon.level.plants.get(cell);
    if (plant != null) {
        objects.add(plant);
        names.add(Messages.titleCase(plant.plantName));
    }
    Trap trap = Dungeon.level.traps.get(cell);
    if (trap != null && trap.visible) {
        objects.add(trap);
        names.add(Messages.titleCase(trap.name));
    }
    if (objects.isEmpty()) {
        GameScene.show(new WndInfoCell(cell));
    } else if (objects.size() == 1) {
        examineObject(objects.get(0));
    } else {
        GameScene.show(new WndOptions(Messages.get(GameScene.class, "choose_examine"), Messages.get(GameScene.class, "multiple_examine"), names.toArray(new String[names.size()])) {

            @Override
            protected void onSelect(int index) {
                examineObject(objects.get(index));
            }
        });
    }
}
Also used : WndOptions(com.shatteredpixel.shatteredpixeldungeon.windows.WndOptions) Mob(com.shatteredpixel.shatteredpixeldungeon.actors.mobs.Mob) WndInfoMob(com.shatteredpixel.shatteredpixeldungeon.windows.WndInfoMob) Plant(com.shatteredpixel.shatteredpixeldungeon.plants.Plant) WndInfoPlant(com.shatteredpixel.shatteredpixeldungeon.windows.WndInfoPlant) ArrayList(java.util.ArrayList) Trap(com.shatteredpixel.shatteredpixeldungeon.levels.traps.Trap) WndInfoTrap(com.shatteredpixel.shatteredpixeldungeon.windows.WndInfoTrap) WndInfoCell(com.shatteredpixel.shatteredpixeldungeon.windows.WndInfoCell) Heap(com.shatteredpixel.shatteredpixeldungeon.items.Heap)

Example 2 with Trap

use of com.shatteredpixel.shatteredpixeldungeon.levels.traps.Trap in project shattered-pixel-dungeon-gdx by 00-Evan.

the class Level method discover.

public void discover(int cell) {
    set(cell, Terrain.discover(map[cell]));
    Trap trap = traps.get(cell);
    if (trap != null)
        trap.reveal();
    GameScene.updateMap(cell);
}
Also used : Trap(com.shatteredpixel.shatteredpixeldungeon.levels.traps.Trap)

Example 3 with Trap

use of com.shatteredpixel.shatteredpixeldungeon.levels.traps.Trap in project shattered-pixel-dungeon-gdx by 00-Evan.

the class Level method press.

// a 'soft' press ignores hidden traps
// a 'hard' press triggers all things
// generally a 'hard' press should be forced is something is moving forcefully (e.g. thrown)
public void press(int cell, Char ch, boolean hard) {
    if (ch != null && pit[cell] && !ch.flying) {
        if (ch == Dungeon.hero) {
            Chasm.heroFall(cell);
        } else if (ch instanceof Mob) {
            Chasm.mobFall((Mob) ch);
        }
        return;
    }
    Trap trap = null;
    switch(map[cell]) {
        case Terrain.SECRET_TRAP:
            if (hard) {
                trap = traps.get(cell);
                GLog.i(Messages.get(Level.class, "hidden_trap", trap.name));
            }
            break;
        case Terrain.TRAP:
            trap = traps.get(cell);
            break;
        case Terrain.HIGH_GRASS:
            HighGrass.trample(this, cell, ch);
            break;
        case Terrain.WELL:
            WellWater.affectCell(cell);
            break;
        case Terrain.DOOR:
            Door.enter(cell);
            break;
    }
    if (trap != null) {
        TimekeepersHourglass.timeFreeze timeFreeze = ch != null ? ch.buff(TimekeepersHourglass.timeFreeze.class) : null;
        if (timeFreeze == null) {
            if (ch == Dungeon.hero) {
                Dungeon.hero.interrupt();
            }
            trap.trigger();
        } else {
            Sample.INSTANCE.play(Assets.SND_TRAP);
            discover(cell);
            timeFreeze.setDelayedPress(cell);
        }
    }
    Plant plant = plants.get(cell);
    if (plant != null) {
        plant.trigger();
    }
}
Also used : Mob(com.shatteredpixel.shatteredpixeldungeon.actors.mobs.Mob) Plant(com.shatteredpixel.shatteredpixeldungeon.plants.Plant) TimekeepersHourglass(com.shatteredpixel.shatteredpixeldungeon.items.artifacts.TimekeepersHourglass) Trap(com.shatteredpixel.shatteredpixeldungeon.levels.traps.Trap)

Example 4 with Trap

use of com.shatteredpixel.shatteredpixeldungeon.levels.traps.Trap 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 5 with Trap

use of com.shatteredpixel.shatteredpixeldungeon.levels.traps.Trap in project shattered-pixel-dungeon-gdx by 00-Evan.

the class Level method setTrap.

public Trap setTrap(Trap trap, int pos) {
    Trap existingTrap = traps.get(pos);
    if (existingTrap != null) {
        traps.remove(pos);
    }
    trap.set(pos);
    traps.put(pos, trap);
    GameScene.updateMap(pos);
    return trap;
}
Also used : Trap(com.shatteredpixel.shatteredpixeldungeon.levels.traps.Trap)

Aggregations

Trap (com.shatteredpixel.shatteredpixeldungeon.levels.traps.Trap)8 Mob (com.shatteredpixel.shatteredpixeldungeon.actors.mobs.Mob)3 Plant (com.shatteredpixel.shatteredpixeldungeon.plants.Plant)3 Heap (com.shatteredpixel.shatteredpixeldungeon.items.Heap)2 ArrayList (java.util.ArrayList)2 Blob (com.shatteredpixel.shatteredpixeldungeon.actors.blobs.Blob)1 TimekeepersHourglass (com.shatteredpixel.shatteredpixeldungeon.items.artifacts.TimekeepersHourglass)1 Room (com.shatteredpixel.shatteredpixeldungeon.levels.rooms.Room)1 EmptyRoom (com.shatteredpixel.shatteredpixeldungeon.levels.rooms.standard.EmptyRoom)1 GrippingTrap (com.shatteredpixel.shatteredpixeldungeon.levels.traps.GrippingTrap)1 ToxicTrap (com.shatteredpixel.shatteredpixeldungeon.levels.traps.ToxicTrap)1 CustomTiledVisual (com.shatteredpixel.shatteredpixeldungeon.tiles.CustomTiledVisual)1 WndInfoCell (com.shatteredpixel.shatteredpixeldungeon.windows.WndInfoCell)1 WndInfoMob (com.shatteredpixel.shatteredpixeldungeon.windows.WndInfoMob)1 WndInfoPlant (com.shatteredpixel.shatteredpixeldungeon.windows.WndInfoPlant)1 WndInfoTrap (com.shatteredpixel.shatteredpixeldungeon.windows.WndInfoTrap)1 WndOptions (com.shatteredpixel.shatteredpixeldungeon.windows.WndOptions)1 Bundlable (com.watabou.utils.Bundlable)1 Point (com.watabou.utils.Point)1 Rect (com.watabou.utils.Rect)1