Search in sources :

Example 6 with LevelObject

use of com.nyrds.pixeldungeon.levels.objects.LevelObject in project pixel-dungeon-remix by NYRDS.

the class Hero method getCloser.

private boolean getCloser(final int target) {
    if (rooted) {
        return false;
    }
    int step = -1;
    Level level = Dungeon.level;
    Buff wallWalkerBuff = null;
    if (!level.isBossLevel()) {
        wallWalkerBuff = buff(RingOfStoneWalking.StoneWalking.class);
    }
    if (level.adjacent(getPos(), target)) {
        if (Actor.findChar(target) == null) {
            if (!hasBuff(Blindness.class)) {
                if (level.pit[target] && !isFlying() && !Chasm.jumpConfirmed) {
                    Chasm.heroJump(this);
                    interrupt();
                    return false;
                }
                if (TrapHelper.isVisibleTrap(level.map[target]) && !isFlying() && !TrapHelper.stepConfirmed) {
                    TrapHelper.heroTriggerTrap(this);
                    interrupt();
                    return false;
                }
            }
            if (wallWalkerBuff == null && (level.passable[target] || level.avoid[target])) {
                step = target;
            }
            if (wallWalkerBuff != null && level.solid[target]) {
                step = target;
            }
            LevelObject obj = level.getTopLevelObject(target);
            if (obj != null && obj.pushable(this)) {
                interrupt();
                if (!obj.push(this)) {
                    return false;
                }
            }
        }
    } else {
        int len = level.getLength();
        boolean[] p = wallWalkerBuff != null ? level.solid : level.passable;
        boolean[] v = level.visited;
        boolean[] m = level.mapped;
        boolean[] passable = new boolean[len];
        for (int i = 0; i < len; i++) {
            passable[i] = p[i] && (v[i] || m[i]);
        }
        step = Dungeon.findPath(this, getPos(), target, passable, level.fieldOfView);
    }
    if (step != -1) {
        int oldPos = getPos();
        LevelObject obj = level.getTopLevelObject(step);
        if (obj != null) {
            if (step == target) {
                interrupt();
                if (!obj.interact(this)) {
                    return false;
                }
            } else {
                if (!obj.stepOn(this)) {
                    interrupt();
                    return false;
                }
            }
        }
        move(step);
        getSprite().move(oldPos, getPos());
        if (wallWalkerBuff != null) {
            int dmg = hp() / 2 > 2 ? hp() / 2 : 2;
            damage(dmg, wallWalkerBuff);
        }
        spend(1 / speed());
        return true;
    } else {
        return false;
    }
}
Also used : LevelObject(com.nyrds.pixeldungeon.levels.objects.LevelObject) Blindness(com.watabou.pixeldungeon.actors.buffs.Blindness) Level(com.watabou.pixeldungeon.levels.Level) Buff(com.watabou.pixeldungeon.actors.buffs.Buff) RingOfStoneWalking(com.watabou.pixeldungeon.items.rings.RingOfStoneWalking)

Example 7 with LevelObject

use of com.nyrds.pixeldungeon.levels.objects.LevelObject in project pixel-dungeon-remix by NYRDS.

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 searchLevel = intentional ? (2 * awareness - awareness * awareness) : awareness;
    if (distance <= 0) {
        searchLevel /= 2 - distance;
        distance = 1;
    }
    Level level = Dungeon.level;
    int cx = level.cellX(getPos());
    int cy = level.cellY(getPos());
    int ax = cx - distance;
    if (ax < 0) {
        ax = 0;
    }
    int bx = cx + distance;
    if (bx >= level.getWidth()) {
        bx = level.getWidth() - 1;
    }
    int ay = cy - distance;
    if (ay < 0) {
        ay = 0;
    }
    int by = cy + distance;
    if (by >= level.getHeight()) {
        by = level.getHeight() - 1;
    }
    for (int y = ay; y <= by; y++) {
        for (int x = ax, p = ax + y * level.getWidth(); x <= bx; x++, p++) {
            if (Dungeon.visible[p]) {
                if (intentional) {
                    getSprite().getParent().addToBack(new CheckedCell(p));
                }
                if (intentional || Random.Float() < searchLevel) {
                    if (level.secret[p]) {
                        int oldValue = level.map[p];
                        GameScene.discoverTile(p);
                        level.set(p, Terrain.discover(oldValue));
                        GameScene.updateMap(p);
                        ScrollOfMagicMapping.discover(p);
                        smthFound = true;
                    }
                    LevelObject obj = level.getLevelObject(p);
                    if (obj != null && obj.secret()) {
                        obj.discover();
                        smthFound = true;
                    }
                }
            }
        }
    }
    if (intentional) {
        getSprite().showStatus(CharSprite.DEFAULT, TXT_SEARCH);
        getSprite().operate(getPos());
        if (smthFound) {
            spendAndNext(Random.Float() < searchLevel ? 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) LevelObject(com.nyrds.pixeldungeon.levels.objects.LevelObject) RingOfDetection(com.watabou.pixeldungeon.items.rings.RingOfDetection) Level(com.watabou.pixeldungeon.levels.Level) Buff(com.watabou.pixeldungeon.actors.buffs.Buff) RingOfDetection(com.watabou.pixeldungeon.items.rings.RingOfDetection)

Example 8 with LevelObject

use of com.nyrds.pixeldungeon.levels.objects.LevelObject in project pixel-dungeon-remix by NYRDS.

the class Fire method burn.

public static void burn(int pos) {
    Char ch = Actor.findChar(pos);
    if (ch != null) {
        Buff.affect(ch, Burning.class).reignite(ch);
    }
    Heap heap = Dungeon.level.getHeap(pos);
    if (heap != null) {
        heap.burn();
    }
    LevelObject levelObject = Dungeon.level.getLevelObject(pos);
    if (levelObject != null) {
        levelObject.burn();
    }
}
Also used : LevelObject(com.nyrds.pixeldungeon.levels.objects.LevelObject) Char(com.watabou.pixeldungeon.actors.Char) Heap(com.watabou.pixeldungeon.items.Heap) Burning(com.watabou.pixeldungeon.actors.buffs.Burning)

Aggregations

LevelObject (com.nyrds.pixeldungeon.levels.objects.LevelObject)8 Heap (com.watabou.pixeldungeon.items.Heap)4 Level (com.watabou.pixeldungeon.levels.Level)4 Char (com.watabou.pixeldungeon.actors.Char)3 Mob (com.watabou.pixeldungeon.actors.mobs.Mob)3 Blob (com.watabou.pixeldungeon.actors.blobs.Blob)2 Buff (com.watabou.pixeldungeon.actors.buffs.Buff)2 Plant (com.watabou.pixeldungeon.plants.Plant)2 Nullable (android.support.annotation.Nullable)1 ScriptedActor (com.nyrds.pixeldungeon.mechanics.actors.ScriptedActor)1 Group (com.watabou.noosa.Group)1 SkinnedBlock (com.watabou.noosa.SkinnedBlock)1 ClassicDungeonTilemap (com.watabou.pixeldungeon.ClassicDungeonTilemap)1 CustomLayerTilemap (com.watabou.pixeldungeon.CustomLayerTilemap)1 FogOfWar (com.watabou.pixeldungeon.FogOfWar)1 Blindness (com.watabou.pixeldungeon.actors.buffs.Blindness)1 Burning (com.watabou.pixeldungeon.actors.buffs.Burning)1 Hero (com.watabou.pixeldungeon.actors.hero.Hero)1 CheckedCell (com.watabou.pixeldungeon.effects.CheckedCell)1 Flare (com.watabou.pixeldungeon.effects.Flare)1