Search in sources :

Example 6 with Heap

use of com.watabou.pixeldungeon.items.Heap in project pixel-dungeon by watabou.

the class Hero method search.

public boolean search(boolean intentional) {
    boolean smthFound = false;
    int positive = 0;
    int negative = 0;
    for (Buff buff : buffs(RingOfDetection.Detection.class)) {
        int bonus = ((RingOfDetection.Detection) buff).level;
        if (bonus > positive) {
            positive = bonus;
        } else if (bonus < 0) {
            negative += bonus;
        }
    }
    int distance = 1 + positive + negative;
    float level = intentional ? (2 * awareness - awareness * awareness) : awareness;
    if (distance <= 0) {
        level /= 2 - distance;
        distance = 1;
    }
    int cx = pos % Level.WIDTH;
    int cy = pos / Level.WIDTH;
    int ax = cx - distance;
    if (ax < 0) {
        ax = 0;
    }
    int bx = cx + distance;
    if (bx >= Level.WIDTH) {
        bx = Level.WIDTH - 1;
    }
    int ay = cy - distance;
    if (ay < 0) {
        ay = 0;
    }
    int by = cy + distance;
    if (by >= Level.HEIGHT) {
        by = Level.HEIGHT - 1;
    }
    for (int y = ay; y <= by; y++) {
        for (int x = ax, p = ax + y * Level.WIDTH; x <= bx; x++, p++) {
            if (Dungeon.visible[p]) {
                if (intentional) {
                    sprite.parent.addToBack(new CheckedCell(p));
                }
                if (Level.secret[p] && (intentional || Random.Float() < level)) {
                    int oldValue = Dungeon.level.map[p];
                    GameScene.discoverTile(p, oldValue);
                    Level.set(p, Terrain.discover(oldValue));
                    GameScene.updateMap(p);
                    ScrollOfMagicMapping.discover(p);
                    smthFound = true;
                }
                if (intentional) {
                    Heap heap = Dungeon.level.heaps.get(p);
                    if (heap != null && heap.type == Type.HIDDEN) {
                        heap.open(this);
                        smthFound = true;
                    }
                }
            }
        }
    }
    if (intentional) {
        sprite.showStatus(CharSprite.DEFAULT, TXT_SEARCH);
        sprite.operate(pos);
        if (smthFound) {
            spendAndNext(Random.Float() < level ? TIME_TO_SEARCH : TIME_TO_SEARCH * 2);
        } else {
            spendAndNext(TIME_TO_SEARCH);
        }
    }
    if (smthFound) {
        GLog.w(TXT_NOTICED_SMTH);
        Sample.INSTANCE.play(Assets.SND_SECRET);
        interrupt();
    }
    return smthFound;
}
Also used : CheckedCell(com.watabou.pixeldungeon.effects.CheckedCell) RingOfDetection(com.watabou.pixeldungeon.items.rings.RingOfDetection) Buff(com.watabou.pixeldungeon.actors.buffs.Buff) RingOfDetection(com.watabou.pixeldungeon.items.rings.RingOfDetection) Heap(com.watabou.pixeldungeon.items.Heap)

Example 7 with Heap

use of com.watabou.pixeldungeon.items.Heap in project pixel-dungeon by watabou.

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.Cook(cell);
    } else if (Level.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 (Level.fieldOfView[cell] && (heap = Dungeon.level.heaps.get(cell)) != null && heap.type != Heap.Type.HIDDEN) {
        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) {
        curAction = new HeroAction.Descend(cell);
    } else if (cell == Dungeon.level.entrance) {
        curAction = new HeroAction.Ascend(cell);
    } else {
        curAction = new HeroAction.Move(cell);
        lastAction = null;
    }
    return act();
}
Also used : NPC(com.watabou.pixeldungeon.actors.mobs.npcs.NPC) Mob(com.watabou.pixeldungeon.actors.mobs.Mob) Heap(com.watabou.pixeldungeon.items.Heap) Char(com.watabou.pixeldungeon.actors.Char)

Example 8 with Heap

use of com.watabou.pixeldungeon.items.Heap in project pixel-dungeon by watabou.

the class ImpShopkeeper method flee.

@Override
protected void flee() {
    for (Heap heap : Dungeon.level.heaps.values()) {
        if (heap.type == Heap.Type.FOR_SALE) {
            CellEmitter.get(heap.pos).burst(ElmoParticle.FACTORY, 4);
            heap.destroy();
        }
    }
    destroy();
    sprite.emitter().burst(Speck.factory(Speck.WOOL), 15);
    sprite.killAndErase();
}
Also used : Heap(com.watabou.pixeldungeon.items.Heap)

Example 9 with Heap

use of com.watabou.pixeldungeon.items.Heap in project pixel-dungeon by watabou.

the class Freezing method affect.

// Returns true, if this cell is visible
public static boolean affect(int cell, Fire fire) {
    Char ch = Actor.findChar(cell);
    if (ch != null) {
        Buff.prolong(ch, Frost.class, Frost.duration(ch) * Random.Float(1.0f, 1.5f));
    }
    if (fire != null) {
        fire.clear(cell);
    }
    Heap heap = Dungeon.level.heaps.get(cell);
    if (heap != null) {
        heap.freeze();
    }
    if (Dungeon.visible[cell]) {
        CellEmitter.get(cell).start(SnowParticle.FACTORY, 0.2f, 6);
        return true;
    } else {
        return false;
    }
}
Also used : Char(com.watabou.pixeldungeon.actors.Char) Heap(com.watabou.pixeldungeon.items.Heap)

Example 10 with Heap

use of com.watabou.pixeldungeon.items.Heap in project pixel-dungeon by watabou.

the class WellWater method affect.

protected boolean affect() {
    Heap heap;
    if (pos == Dungeon.hero.pos && affectHero(Dungeon.hero)) {
        volume = off[pos] = cur[pos] = 0;
        return true;
    } else if ((heap = Dungeon.level.heaps.get(pos)) != null) {
        Item oldItem = heap.peek();
        Item newItem = affectItem(oldItem);
        if (newItem != null) {
            if (newItem == oldItem) {
            } else if (oldItem.quantity() > 1) {
                oldItem.quantity(oldItem.quantity() - 1);
                heap.drop(newItem);
            } else {
                heap.replace(oldItem, newItem);
            }
            heap.sprite.link();
            volume = off[pos] = cur[pos] = 0;
            return true;
        } else {
            int newPlace;
            do {
                newPlace = pos + Level.NEIGHBOURS8[Random.Int(8)];
            } while (!Level.passable[newPlace] && !Level.avoid[newPlace]);
            Dungeon.level.drop(heap.pickUp(), newPlace).sprite.drop(pos);
            return false;
        }
    } else {
        return false;
    }
}
Also used : Item(com.watabou.pixeldungeon.items.Item) Heap(com.watabou.pixeldungeon.items.Heap)

Aggregations

Heap (com.watabou.pixeldungeon.items.Heap)20 Mob (com.watabou.pixeldungeon.actors.mobs.Mob)6 Char (com.watabou.pixeldungeon.actors.Char)4 Item (com.watabou.pixeldungeon.items.Item)3 ScrollOfUpgrade (com.watabou.pixeldungeon.items.scrolls.ScrollOfUpgrade)3 Plant (com.watabou.pixeldungeon.plants.Plant)3 Blob (com.watabou.pixeldungeon.actors.blobs.Blob)2 Buff (com.watabou.pixeldungeon.actors.buffs.Buff)2 HeroClass (com.watabou.pixeldungeon.actors.hero.HeroClass)2 PotionOfStrength (com.watabou.pixeldungeon.items.potions.PotionOfStrength)2 ScrollOfEnchantment (com.watabou.pixeldungeon.items.scrolls.ScrollOfEnchantment)2 WndTradeItem (com.watabou.pixeldungeon.windows.WndTradeItem)2 Awareness (com.watabou.pixeldungeon.actors.buffs.Awareness)1 Blindness (com.watabou.pixeldungeon.actors.buffs.Blindness)1 Burning (com.watabou.pixeldungeon.actors.buffs.Burning)1 MindVision (com.watabou.pixeldungeon.actors.buffs.MindVision)1 Shadows (com.watabou.pixeldungeon.actors.buffs.Shadows)1 Mimic (com.watabou.pixeldungeon.actors.mobs.Mimic)1 NPC (com.watabou.pixeldungeon.actors.mobs.npcs.NPC)1 RatKing (com.watabou.pixeldungeon.actors.mobs.npcs.RatKing)1