Search in sources :

Example 1 with LevelObject

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

the class Level method press.

public void press(int cell, Presser actor) {
    Char chr = null;
    if (actor != null) {
        if (actor instanceof Char) {
            chr = (Char) actor;
            if (pit[cell] && !chr.isFlying()) {
                Chasm.charFall(chr.getPos(), chr);
                return;
            }
            if (actor instanceof Hero) {
                pressHero(cell, (Hero) chr);
            }
        }
        if (actor instanceof LevelObject) {
            if (pit[cell]) {
                ((LevelObject) actor).fall();
                return;
            }
        }
        if (actor instanceof Item || actor instanceof LevelObject) {
            set(cell, Terrain.discover(map[cell]));
        }
        if (actor.affectLevelObjects()) {
            LevelObject levelObject = getTopLevelObject(cell);
            if (levelObject != null && levelObject != actor) {
                levelObject.bump(actor);
            }
        }
    }
    switch(map[cell]) {
        case Terrain.TOXIC_TRAP:
            ToxicTrap.trigger(cell, chr);
            break;
        case Terrain.FIRE_TRAP:
            FireTrap.trigger(cell, chr);
            break;
        case Terrain.PARALYTIC_TRAP:
            ParalyticTrap.trigger(cell, chr);
            break;
        case Terrain.POISON_TRAP:
            PoisonTrap.trigger(cell, chr);
            break;
        case Terrain.ALARM_TRAP:
            AlarmTrap.trigger(cell, chr);
            break;
        case Terrain.LIGHTNING_TRAP:
            LightningTrap.trigger(cell, chr);
            break;
        case Terrain.GRIPPING_TRAP:
            GrippingTrap.trigger(cell, chr);
            break;
        case Terrain.SUMMONING_TRAP:
            SummoningTrap.trigger(cell, chr);
            break;
        case Terrain.DOOR:
            Door.enter(cell);
            break;
    }
    if (!(actor instanceof Mob)) {
        switch(map[cell]) {
            case Terrain.HIGH_GRASS:
                HighGrass.trample(this, cell, chr);
                break;
            case Terrain.WELL:
                WellWater.affectCell(cell);
                break;
            case Terrain.ALCHEMY:
                Alchemy.transmute(cell);
                break;
        }
    }
    if (TerrainFlags.is(map[cell], TerrainFlags.TRAP)) {
        if (Dungeon.visible[cell]) {
            Sample.INSTANCE.play(Assets.SND_TRAP);
        }
        if (actor instanceof Hero) {
            ((Hero) actor).interrupt();
        }
        set(cell, Terrain.INACTIVE_TRAP);
        GameScene.updateMap(cell);
    }
    Plant plant = plants.get(cell);
    if (plant != null) {
        plant.activate(chr);
    }
}
Also used : Item(com.watabou.pixeldungeon.items.Item) Mob(com.watabou.pixeldungeon.actors.mobs.Mob) Plant(com.watabou.pixeldungeon.plants.Plant) LevelObject(com.nyrds.pixeldungeon.levels.objects.LevelObject) Char(com.watabou.pixeldungeon.actors.Char) Hero(com.watabou.pixeldungeon.actors.hero.Hero)

Example 2 with LevelObject

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

the class Level method restoreFromBundle.

@Override
public void restoreFromBundle(Bundle bundle) {
    scripts = new HashSet<>();
    mobs = new HashSet<>();
    heaps = new SparseArray<>();
    blobs = new HashMap<>();
    plants = new SparseArray<>();
    // old levels compat
    width = bundle.optInt(WIDTH, 32);
    height = bundle.optInt(HEIGHT, 32);
    initSizeDependentStuff();
    map = bundle.getIntArray(MAP);
    for (LayerId layerId : LayerId.values()) {
        int[] layer = bundle.getIntArray(layerId.name());
        if (layer.length == map.length) {
            customLayers.put(layerId, layer);
        }
    }
    visited = bundle.getBooleanArray(VISITED);
    mapped = bundle.getBooleanArray(MAPPED);
    entrance = bundle.getInt(ENTRANCE);
    compassTarget = bundle.optInt(COMPASS_TARGET, INVALID_CELL);
    int[] exits = bundle.getIntArray(EXIT);
    if (exits.length > 0) {
        for (int i = 0; i < exits.length; ++i) {
            setExit(exits[i], i);
        }
    } else {
        setExit(bundle.getInt(EXIT), 0);
        int secondaryExit = bundle.optInt(SECONDARY_EXIT, INVALID_CELL);
        if (cellValid(secondaryExit)) {
            setExit(secondaryExit, 1);
        }
    }
    weakFloorCreated = false;
    for (Heap heap : bundle.getCollection(HEAPS, Heap.class)) {
        heaps.put(heap.pos, heap);
    }
    for (Plant plant : bundle.getCollection(PLANTS, Plant.class)) {
        plants.put(plant.pos, plant);
    }
    for (LevelObject object : bundle.getCollection(OBJECTS, LevelObject.class)) {
        putLevelObject(object);
    }
    for (Mob mob : bundle.getCollection(MOBS, Mob.class)) {
        if (mob != null && mob.getPos() != INVALID_CELL) {
            mobs.add(mob);
        }
    }
    for (Blob blob : bundle.getCollection(BLOBS, Blob.class)) {
        blobs.put(blob.getClass(), blob);
    }
    for (ScriptedActor actor : bundle.getCollection(SCRIPTS, ScriptedActor.class)) {
        addScriptedActor(actor);
    }
    buildFlagMaps();
    cleanWalls();
}
Also used : Mob(com.watabou.pixeldungeon.actors.mobs.Mob) ScriptedActor(com.nyrds.pixeldungeon.mechanics.actors.ScriptedActor) Plant(com.watabou.pixeldungeon.plants.Plant) Blob(com.watabou.pixeldungeon.actors.blobs.Blob) LevelObject(com.nyrds.pixeldungeon.levels.objects.LevelObject) Heap(com.watabou.pixeldungeon.items.Heap)

Example 3 with LevelObject

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

the class GameScene method create.

@Override
public void create() {
    playLevelMusic();
    Level level = Dungeon.level;
    PixelDungeon.lastClass(Dungeon.hero.heroClass.ordinal());
    super.create();
    Camera.main.zoom((float) (defaultZoom + PixelDungeon.zoom()));
    scene = this;
    Group terrain = new Group();
    add(terrain);
    water = new SkinnedBlock(level.getWidth() * DungeonTilemap.SIZE, level.getHeight() * DungeonTilemap.SIZE, level.getWaterTex());
    waterSx = DungeonGenerator.getLevelProperty(level.levelId, "waterSx", waterSx);
    waterSy = DungeonGenerator.getLevelProperty(level.levelId, "waterSy", waterSy);
    terrain.add(water);
    ripples = new Group();
    terrain.add(ripples);
    String logicTilesAtlas = level.getProperty("tiles_logic", null);
    if (logicTilesAtlas != null) {
        logicTiles = new ClassicDungeonTilemap(level, logicTilesAtlas);
        terrain.add(logicTiles);
    }
    if (!level.customTiles()) {
        baseTiles = DungeonTilemap.factory(level, level.getTilesetForLayer(Level.LayerId.Base));
    } else {
        CustomLayerTilemap tiles = new CustomLayerTilemap(level, Level.LayerId.Base);
        tiles.addLayer(Level.LayerId.Deco);
        tiles.addLayer(Level.LayerId.Deco2);
        baseTiles = tiles;
        tiles = new CustomLayerTilemap(level, Level.LayerId.Roof_Base);
        tiles.addLayer(Level.LayerId.Roof_Deco);
        tiles.setTransparent(true);
        roofTiles = tiles;
    }
    terrain.add(baseTiles);
    objects = new Group();
    add(objects);
    for (int i = 0; i < level.objects.size(); i++) {
        SparseArray<LevelObject> objectLayer = level.objects.valueAt(i);
        for (int j = 0; j < objectLayer.size(); j++) {
            addLevelObjectSprite(objectLayer.valueAt(j));
        }
    }
    level.addVisuals(this);
    plants = new Group();
    add(plants);
    for (int i = 0; i < level.plants.size(); i++) {
        addPlantSprite(level.plants.valueAt(i));
    }
    heaps = new Group();
    add(heaps);
    for (Heap heap : level.allHeaps()) {
        addHeapSprite(heap);
    }
    emitters = new Group();
    effects = new Group();
    emoicons = new Group();
    mobs = new Group();
    add(mobs);
    // hack to save bugged saves...
    boolean buggedSave = false;
    HashSet<Mob> filteredMobs = new HashSet<>();
    for (Mob mob : level.mobs) {
        if (level.cellValid(mob.getPos())) {
            filteredMobs.add(mob);
        } else {
            buggedSave = true;
        }
    }
    if (buggedSave) {
        EventCollector.logEvent(EventCollector.BUG, "bugged save", "mob.pos==-1");
    }
    level.mobs = filteredMobs;
    for (Mob mob : level.mobs) {
        if (Statistics.amuletObtained) {
            mob.beckon(Dungeon.hero.getPos());
        }
    }
    Dungeon.hero.updateSprite();
    add(emitters);
    add(effects);
    gases = new Group();
    add(gases);
    for (Blob blob : level.blobs.values()) {
        blob.emitter = null;
        addBlobSprite(blob);
    }
    fog = new FogOfWar(level.getWidth(), level.getHeight());
    if (level.noFogOfWar()) {
        level.reveal();
    }
    if (roofTiles != null) {
        add(roofTiles);
    }
    fog.updateVisibility(Dungeon.visible, level.visited, level.mapped);
    add(fog);
    brightness(PixelDungeon.brightness());
    spells = new Group();
    add(spells);
    statuses = new Group();
    add(statuses);
    add(emoicons);
    add(new HealthIndicator());
    add(cellSelector = new CellSelector(baseTiles));
    Dungeon.hero.updateLook();
    sb = new StatusPane(Dungeon.hero, level);
    sb.camera = uiCamera;
    sb.setSize(uiCamera.width, 0);
    add(sb);
    toolbar = new Toolbar();
    toolbar.camera = uiCamera;
    toolbar.setRect(0, uiCamera.height - toolbar.height(), uiCamera.width, toolbar.height());
    add(toolbar);
    attack = new AttackIndicator();
    attack.camera = uiCamera;
    attack.setPos(uiCamera.width - attack.width(), toolbar.top() - attack.height());
    add(attack);
    resume = new ResumeIndicator();
    resume.camera = uiCamera;
    resume.setPos(uiCamera.width - resume.width(), attack.top() - resume.height());
    add(resume);
    log = new GameLog();
    log.camera = uiCamera;
    log.setRect(0, toolbar.top(), attack.left(), 0);
    add(log);
    if (Dungeon.depth < Statistics.deepestFloor) {
        GLog.i(TXT_WELCOME_BACK, Dungeon.depth);
    } else {
        GLog.i(TXT_WELCOME, Dungeon.depth);
        Sample.INSTANCE.play(Assets.SND_DESCEND);
    }
    switch(level.getFeeling()) {
        case CHASM:
            GLog.w(TXT_CHASM);
            break;
        case WATER:
            GLog.w(TXT_WATER);
            break;
        case GRASS:
            GLog.w(TXT_GRASS);
            break;
        default:
    }
    if (level instanceof RegularLevel && ((RegularLevel) level).secretDoors > Random.IntRange(3, 4)) {
        GLog.w(TXT_SECRETS);
    }
    if (Dungeon.nightMode && !Dungeon.bossLevel()) {
        GLog.w(TXT_NIGHT_MODE);
    }
    busy = new BusyIndicator();
    busy.camera = uiCamera;
    busy.x = 1;
    busy.y = sb.bottom() + 18;
    add(busy);
    sceneCreated = true;
    switch(InterlevelScene.mode) {
        case RESURRECT:
            WandOfBlink.appear(Dungeon.hero, level.entrance);
            new Flare(8, 32).color(0xFFFF66, true).show(Dungeon.hero.getHeroSprite(), 2f);
            break;
        case RETURN:
            WandOfBlink.appear(Dungeon.hero, Dungeon.hero.getPos());
            break;
        case FALL:
            Chasm.heroLand();
            break;
        case DESCEND:
            DungeonGenerator.showStory(level);
            if (Dungeon.hero.isAlive() && !level.isSafe() && Dungeon.depth != 22 && Dungeon.depth != 1) {
                Badges.validateNoKilling();
            }
            break;
        default:
    }
    Camera.main.target = Dungeon.hero.getHeroSprite();
    level.activateScripts();
    fadeIn();
    Dungeon.observe();
}
Also used : Group(com.watabou.noosa.Group) StatusPane(com.watabou.pixeldungeon.ui.StatusPane) LevelObject(com.nyrds.pixeldungeon.levels.objects.LevelObject) AttackIndicator(com.watabou.pixeldungeon.ui.AttackIndicator) BusyIndicator(com.watabou.pixeldungeon.ui.BusyIndicator) SkinnedBlock(com.watabou.noosa.SkinnedBlock) GameLog(com.watabou.pixeldungeon.ui.GameLog) HashSet(java.util.HashSet) Toolbar(com.watabou.pixeldungeon.ui.Toolbar) Mob(com.watabou.pixeldungeon.actors.mobs.Mob) FogOfWar(com.watabou.pixeldungeon.FogOfWar) Blob(com.watabou.pixeldungeon.actors.blobs.Blob) Flare(com.watabou.pixeldungeon.effects.Flare) ClassicDungeonTilemap(com.watabou.pixeldungeon.ClassicDungeonTilemap) Heap(com.watabou.pixeldungeon.items.Heap) ResumeIndicator(com.watabou.pixeldungeon.ui.ResumeIndicator) HealthIndicator(com.watabou.pixeldungeon.ui.HealthIndicator) Level(com.watabou.pixeldungeon.levels.Level) RegularLevel(com.watabou.pixeldungeon.levels.RegularLevel) CustomLayerTilemap(com.watabou.pixeldungeon.CustomLayerTilemap) RegularLevel(com.watabou.pixeldungeon.levels.RegularLevel)

Example 4 with LevelObject

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

the class Level method getTopLevelObject.

@Nullable
public LevelObject getTopLevelObject(int pos) {
    LevelObject top = null;
    for (int i = 0; i < objects.size(); i++) {
        SparseArray<LevelObject> objectLayer = objects.valueAt(i);
        LevelObject candidate = objectLayer.get(pos);
        if (top == null) {
            top = candidate;
        } else {
            if (candidate != null && candidate.getLayer() > top.getLayer()) {
                top = candidate;
            }
        }
    }
    return top;
}
Also used : LevelObject(com.nyrds.pixeldungeon.levels.objects.LevelObject) Nullable(android.support.annotation.Nullable)

Example 5 with LevelObject

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

the class WandOfTelekinesis method onZap.

@Override
protected void onZap(int cell) {
    boolean mapUpdated = false;
    int maxDistance = effectiveLevel() + 4;
    Ballistica.distance = Math.min(Ballistica.distance, maxDistance);
    Char ch;
    Heap heap = null;
    Level level = Dungeon.level;
    for (int i = 1; i < Ballistica.distance; i++) {
        int c = Ballistica.trace[i];
        int before = level.map[c];
        if ((ch = Actor.findChar(c)) != null) {
            if (i == Ballistica.distance - 1) {
                ch.damage(maxDistance - 1 - i, this);
            } else {
                int next = Ballistica.trace[i + 1];
                if (ch.isMovable() && (level.passable[next] || level.avoid[next]) && Actor.findChar(next) == null) {
                    Actor.addDelayed(new Pushing(ch, ch.getPos(), next), -1);
                    ch.setPos(next);
                    Actor.freeCell(next);
                    level.press(ch.getPos(), ch);
                } else {
                    ch.damage(maxDistance - 1 - i, this);
                }
            }
        }
        if (heap == null && (heap = level.getHeap(c)) != null) {
            switch(heap.type) {
                case HEAP:
                    transport(heap);
                    break;
                case CHEST:
                case MIMIC:
                    heap.open(getCurUser());
                    break;
                default:
            }
        }
        level.press(c, new Effect());
        if (before == Terrain.OPEN_DOOR && Actor.findChar(c) == null) {
            level.set(c, Terrain.DOOR);
            GameScene.updateMap(c);
        } else if (level.water[c]) {
            GameScene.ripple(c);
        }
        if (!mapUpdated && level.map[c] != before) {
            mapUpdated = true;
        }
        LevelObject levelObject = null;
        if ((levelObject = level.getTopLevelObject(c)) != null) {
            if (levelObject.pushable(getCurUser())) {
                levelObject.push(getCurUser());
            }
        }
    }
    if (mapUpdated) {
        Dungeon.observe();
    }
}
Also used : LevelObject(com.nyrds.pixeldungeon.levels.objects.LevelObject) Char(com.watabou.pixeldungeon.actors.Char) Pushing(com.watabou.pixeldungeon.effects.Pushing) Level(com.watabou.pixeldungeon.levels.Level) Heap(com.watabou.pixeldungeon.items.Heap)

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