Search in sources :

Example 16 with Mob

use of com.watabou.pixeldungeon.actors.mobs.Mob in project pixel-dungeon by watabou.

the class SummoningTrap method trigger.

// 0x770088
public static void trigger(int pos, Char c) {
    if (Dungeon.bossLevel()) {
        return;
    }
    if (c != null) {
        Actor.occupyCell(c);
    }
    int nMobs = 1;
    if (Random.Int(2) == 0) {
        nMobs++;
        if (Random.Int(2) == 0) {
            nMobs++;
        }
    }
    ArrayList<Integer> candidates = new ArrayList<Integer>();
    for (int i = 0; i < Level.NEIGHBOURS8.length; i++) {
        int p = pos + Level.NEIGHBOURS8[i];
        if (Actor.findChar(p) == null && (Level.passable[p] || Level.avoid[p])) {
            candidates.add(p);
        }
    }
    ArrayList<Integer> respawnPoints = new ArrayList<Integer>();
    while (nMobs > 0 && candidates.size() > 0) {
        int index = Random.index(candidates);
        DUMMY.pos = candidates.get(index);
        Actor.occupyCell(DUMMY);
        respawnPoints.add(candidates.remove(index));
        nMobs--;
    }
    for (Integer point : respawnPoints) {
        Mob mob = Bestiary.mob(Dungeon.depth);
        mob.state = mob.WANDERING;
        GameScene.add(mob, DELAY);
        WandOfBlink.appear(mob, point);
    }
}
Also used : Mob(com.watabou.pixeldungeon.actors.mobs.Mob) ArrayList(java.util.ArrayList)

Example 17 with Mob

use of com.watabou.pixeldungeon.actors.mobs.Mob in project pixel-dungeon by watabou.

the class Level method restoreFromBundle.

@Override
public void restoreFromBundle(Bundle bundle) {
    mobs = new HashSet<Mob>();
    heaps = new SparseArray<Heap>();
    blobs = new HashMap<Class<? extends Blob>, Blob>();
    plants = new SparseArray<Plant>();
    map = bundle.getIntArray(MAP);
    visited = bundle.getBooleanArray(VISITED);
    mapped = bundle.getBooleanArray(MAPPED);
    entrance = bundle.getInt(ENTRANCE);
    exit = bundle.getInt(EXIT);
    weakFloorCreated = false;
    adjustMapSize();
    Collection<Bundlable> collection = bundle.getCollection(HEAPS);
    for (Bundlable h : collection) {
        Heap heap = (Heap) h;
        if (resizingNeeded) {
            heap.pos = adjustPos(heap.pos);
        }
        heaps.put(heap.pos, heap);
    }
    collection = bundle.getCollection(PLANTS);
    for (Bundlable p : collection) {
        Plant plant = (Plant) p;
        if (resizingNeeded) {
            plant.pos = adjustPos(plant.pos);
        }
        plants.put(plant.pos, plant);
    }
    collection = bundle.getCollection(MOBS);
    for (Bundlable m : collection) {
        Mob mob = (Mob) m;
        if (mob != null) {
            if (resizingNeeded) {
                mob.pos = adjustPos(mob.pos);
            }
            mobs.add(mob);
        }
    }
    collection = bundle.getCollection(BLOBS);
    for (Bundlable b : collection) {
        Blob blob = (Blob) b;
        blobs.put(blob.getClass(), blob);
    }
    buildFlagMaps();
    cleanWalls();
}
Also used : Mob(com.watabou.pixeldungeon.actors.mobs.Mob) Blob(com.watabou.pixeldungeon.actors.blobs.Blob) Plant(com.watabou.pixeldungeon.plants.Plant) Bundlable(com.watabou.utils.Bundlable) HeroClass(com.watabou.pixeldungeon.actors.hero.HeroClass) Heap(com.watabou.pixeldungeon.items.Heap)

Example 18 with Mob

use of com.watabou.pixeldungeon.actors.mobs.Mob in project pixel-dungeon by watabou.

the class Level method updateFieldOfView.

public boolean[] updateFieldOfView(Char c) {
    int cx = c.pos % WIDTH;
    int cy = c.pos / WIDTH;
    boolean sighted = c.buff(Blindness.class) == null && c.buff(Shadows.class) == null && c.isAlive();
    if (sighted) {
        ShadowCaster.castShadow(cx, cy, fieldOfView, c.viewDistance);
    } else {
        Arrays.fill(fieldOfView, false);
    }
    int sense = 1;
    if (c.isAlive()) {
        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) {
            Arrays.fill(fieldOfView, pos, pos + len, true);
        }
        for (int i = 0; i < LENGTH; i++) {
            fieldOfView[i] &= discoverable[i];
        }
    }
    if (c.isAlive()) {
        if (c.buff(MindVision.class) != null) {
            for (Mob mob : mobs) {
                int p = mob.pos;
                fieldOfView[p] = true;
                fieldOfView[p + 1] = true;
                fieldOfView[p - 1] = true;
                fieldOfView[p + WIDTH + 1] = true;
                fieldOfView[p + WIDTH - 1] = true;
                fieldOfView[p - WIDTH + 1] = true;
                fieldOfView[p - WIDTH - 1] = true;
                fieldOfView[p + WIDTH] = true;
                fieldOfView[p - WIDTH] = true;
            }
        } else if (c == Dungeon.hero && ((Hero) c).heroClass == HeroClass.HUNTRESS) {
            for (Mob mob : mobs) {
                int p = mob.pos;
                if (distance(c.pos, p) == 2) {
                    fieldOfView[p] = true;
                    fieldOfView[p + 1] = true;
                    fieldOfView[p - 1] = true;
                    fieldOfView[p + WIDTH + 1] = true;
                    fieldOfView[p + WIDTH - 1] = true;
                    fieldOfView[p - WIDTH + 1] = true;
                    fieldOfView[p - WIDTH - 1] = true;
                    fieldOfView[p + WIDTH] = true;
                    fieldOfView[p - WIDTH] = true;
                }
            }
        }
        if (c.buff(Awareness.class) != null) {
            for (Heap heap : heaps.values()) {
                int p = heap.pos;
                fieldOfView[p] = true;
                fieldOfView[p + 1] = true;
                fieldOfView[p - 1] = true;
                fieldOfView[p + WIDTH + 1] = true;
                fieldOfView[p + WIDTH - 1] = true;
                fieldOfView[p - WIDTH + 1] = true;
                fieldOfView[p - WIDTH - 1] = true;
                fieldOfView[p + WIDTH] = true;
                fieldOfView[p - WIDTH] = true;
            }
        }
    }
    return fieldOfView;
}
Also used : Shadows(com.watabou.pixeldungeon.actors.buffs.Shadows) Mob(com.watabou.pixeldungeon.actors.mobs.Mob) Awareness(com.watabou.pixeldungeon.actors.buffs.Awareness) Blindness(com.watabou.pixeldungeon.actors.buffs.Blindness) Buff(com.watabou.pixeldungeon.actors.buffs.Buff) MindVision(com.watabou.pixeldungeon.actors.buffs.MindVision) Heap(com.watabou.pixeldungeon.items.Heap)

Example 19 with Mob

use of com.watabou.pixeldungeon.actors.mobs.Mob in project pixel-dungeon by watabou.

the class Level method respawner.

public Actor respawner() {
    return new Actor() {

        @Override
        protected boolean act() {
            if (mobs.size() < nMobs()) {
                Mob mob = Bestiary.mutable(Dungeon.depth);
                mob.state = mob.WANDERING;
                mob.pos = randomRespawnCell();
                if (Dungeon.hero.isAlive() && mob.pos != -1) {
                    GameScene.add(mob);
                    if (Statistics.amuletObtained) {
                        mob.beckon(Dungeon.hero.pos);
                    }
                }
            }
            spend(Dungeon.nightMode || Statistics.amuletObtained ? TIME_TO_RESPAWN / 2 : TIME_TO_RESPAWN);
            return true;
        }
    };
}
Also used : Mob(com.watabou.pixeldungeon.actors.mobs.Mob) Actor(com.watabou.pixeldungeon.actors.Actor)

Example 20 with Mob

use of com.watabou.pixeldungeon.actors.mobs.Mob in project pixel-dungeon by watabou.

the class RegularLevel method createMobs.

@Override
protected void createMobs() {
    int nMobs = nMobs();
    for (int i = 0; i < nMobs; i++) {
        Mob mob = Bestiary.mob(Dungeon.depth);
        do {
            mob.pos = randomRespawnCell();
        } while (mob.pos == -1);
        mobs.add(mob);
        Actor.occupyCell(mob);
    }
}
Also used : Mob(com.watabou.pixeldungeon.actors.mobs.Mob)

Aggregations

Mob (com.watabou.pixeldungeon.actors.mobs.Mob)29 Heap (com.watabou.pixeldungeon.items.Heap)6 Blob (com.watabou.pixeldungeon.actors.blobs.Blob)4 Flare (com.watabou.pixeldungeon.effects.Flare)3 Plant (com.watabou.pixeldungeon.plants.Plant)3 Char (com.watabou.pixeldungeon.actors.Char)2 HeroClass (com.watabou.pixeldungeon.actors.hero.HeroClass)2 Item (com.watabou.pixeldungeon.items.Item)2 HeroSprite (com.watabou.pixeldungeon.sprites.HeroSprite)2 Point (com.watabou.utils.Point)2 ArrayList (java.util.ArrayList)2 Group (com.watabou.noosa.Group)1 SkinnedBlock (com.watabou.noosa.SkinnedBlock)1 AlphaTweener (com.watabou.noosa.tweeners.AlphaTweener)1 DungeonTilemap (com.watabou.pixeldungeon.DungeonTilemap)1 FogOfWar (com.watabou.pixeldungeon.FogOfWar)1 Actor (com.watabou.pixeldungeon.actors.Actor)1 Awareness (com.watabou.pixeldungeon.actors.buffs.Awareness)1 Blindness (com.watabou.pixeldungeon.actors.buffs.Blindness)1 Buff (com.watabou.pixeldungeon.actors.buffs.Buff)1