Search in sources :

Example 11 with Heap

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

the class Hero method handle.

public boolean handle(int cell) {
    if (cell == -1) {
        return false;
    }
    Char ch;
    Heap heap;
    if (Dungeon.level.map[cell] == Terrain.ALCHEMY && cell != pos) {
        curAction = new HeroAction.Alchemy(cell);
    } else if (fieldOfView[cell] && (ch = Actor.findChar(cell)) instanceof Mob) {
        if (ch instanceof NPC) {
            curAction = new HeroAction.Interact((NPC) ch);
        } else {
            curAction = new HeroAction.Attack(ch);
        }
    } else if ((heap = Dungeon.level.heaps.get(cell)) != null && // moving to an item doesn't auto-pickup when enemies are near...
    (visibleEnemies.size() == 0 || cell == pos || // ...but only for standard heaps, chests and similar open as normal.
    (heap.type != Type.HEAP && heap.type != Type.FOR_SALE))) {
        switch(heap.type) {
            case HEAP:
                curAction = new HeroAction.PickUp(cell);
                break;
            case FOR_SALE:
                curAction = heap.size() == 1 && heap.peek().price() > 0 ? new HeroAction.Buy(cell) : new HeroAction.PickUp(cell);
                break;
            default:
                curAction = new HeroAction.OpenChest(cell);
        }
    } else if (Dungeon.level.map[cell] == Terrain.LOCKED_DOOR || Dungeon.level.map[cell] == Terrain.LOCKED_EXIT) {
        curAction = new HeroAction.Unlock(cell);
    } else if (cell == Dungeon.level.exit && Dungeon.depth < 26) {
        curAction = new HeroAction.Descend(cell);
    } else if (cell == Dungeon.level.entrance) {
        curAction = new HeroAction.Ascend(cell);
    } else {
        curAction = new HeroAction.Move(cell);
        lastAction = null;
    }
    if (ready)
        return act();
    else
        return false;
}
Also used : NPC(com.shatteredpixel.shatteredpixeldungeon.actors.mobs.npcs.NPC) Mob(com.shatteredpixel.shatteredpixeldungeon.actors.mobs.Mob) Heap(com.shatteredpixel.shatteredpixeldungeon.items.Heap) Char(com.shatteredpixel.shatteredpixeldungeon.actors.Char)

Example 12 with Heap

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

the class Hero method actOpenChest.

private boolean actOpenChest(HeroAction.OpenChest action) {
    int dst = action.dst;
    if (Dungeon.level.adjacent(pos, dst) || pos == dst) {
        Heap heap = Dungeon.level.heaps.get(dst);
        if (heap != null && (heap.type != Type.HEAP && heap.type != Type.FOR_SALE)) {
            if ((heap.type == Type.LOCKED_CHEST && Notes.keyCount(new GoldenKey(Dungeon.depth)) < 1) || (heap.type == Type.CRYSTAL_CHEST && Notes.keyCount(new CrystalKey(Dungeon.depth)) < 1)) {
                GLog.w(Messages.get(this, "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:
                case REMAINS:
                    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;
    }
}
Also used : CrystalKey(com.shatteredpixel.shatteredpixeldungeon.items.keys.CrystalKey) GoldenKey(com.shatteredpixel.shatteredpixeldungeon.items.keys.GoldenKey) Heap(com.shatteredpixel.shatteredpixeldungeon.items.Heap)

Example 13 with Heap

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

the class Level method drop.

public Heap drop(Item item, int cell) {
    if (item == null || Challenges.isItemBlocked(item)) {
        // create a dummy heap, give it a dummy sprite, don't add it to the game, and return it.
        // effectively nullifies whatever the logic calling this wants to do, including dropping items.
        Heap heap = new Heap();
        ItemSprite sprite = heap.sprite = new ItemSprite();
        sprite.link(heap);
        return heap;
    }
    Heap heap = heaps.get(cell);
    if (heap == null) {
        heap = new Heap();
        heap.seen = Dungeon.level == this && heroFOV[cell];
        heap.pos = cell;
        heap.drop(item);
        if (map[cell] == Terrain.CHASM || (Dungeon.level != null && pit[cell])) {
            Dungeon.dropToChasm(item);
            GameScene.discard(heap);
        } else {
            heaps.put(cell, heap);
            GameScene.add(heap);
        }
    } else if (heap.type == Heap.Type.LOCKED_CHEST || heap.type == Heap.Type.CRYSTAL_CHEST) {
        int n;
        do {
            n = cell + PathFinder.NEIGHBOURS8[Random.Int(8)];
        } while (!passable[n] && !avoid[n]);
        return drop(item, n);
    } else {
        heap.drop(item);
    }
    if (Dungeon.level != null) {
        press(cell, null, true);
    }
    return heap;
}
Also used : ItemSprite(com.shatteredpixel.shatteredpixeldungeon.sprites.ItemSprite) Heap(com.shatteredpixel.shatteredpixeldungeon.items.Heap)

Example 14 with Heap

use of com.shatteredpixel.shatteredpixeldungeon.items.Heap 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 15 with Heap

use of com.shatteredpixel.shatteredpixeldungeon.items.Heap 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)

Aggregations

Heap (com.shatteredpixel.shatteredpixeldungeon.items.Heap)33 Item (com.shatteredpixel.shatteredpixeldungeon.items.Item)14 Char (com.shatteredpixel.shatteredpixeldungeon.actors.Char)13 Mob (com.shatteredpixel.shatteredpixeldungeon.actors.mobs.Mob)11 Hero (com.shatteredpixel.shatteredpixeldungeon.actors.hero.Hero)5 GoldenKey (com.shatteredpixel.shatteredpixeldungeon.items.keys.GoldenKey)4 Plant (com.shatteredpixel.shatteredpixeldungeon.plants.Plant)4 ArrayList (java.util.ArrayList)4 CrystalKey (com.shatteredpixel.shatteredpixeldungeon.items.keys.CrystalKey)3 Blob (com.shatteredpixel.shatteredpixeldungeon.actors.blobs.Blob)2 Awareness (com.shatteredpixel.shatteredpixeldungeon.actors.buffs.Awareness)2 Chill (com.shatteredpixel.shatteredpixeldungeon.actors.buffs.Chill)2 Frost (com.shatteredpixel.shatteredpixeldungeon.actors.buffs.Frost)2 MindVision (com.shatteredpixel.shatteredpixeldungeon.actors.buffs.MindVision)2 IronKey (com.shatteredpixel.shatteredpixeldungeon.items.keys.IronKey)2 SkeletonKey (com.shatteredpixel.shatteredpixeldungeon.items.keys.SkeletonKey)2 Trap (com.shatteredpixel.shatteredpixeldungeon.levels.traps.Trap)2 CustomTiledVisual (com.shatteredpixel.shatteredpixeldungeon.tiles.CustomTiledVisual)2 WndInfoMob (com.shatteredpixel.shatteredpixeldungeon.windows.WndInfoMob)2 WndInfoPlant (com.shatteredpixel.shatteredpixeldungeon.windows.WndInfoPlant)2