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);
}
}
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();
}
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;
}
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;
}
};
}
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);
}
}
Aggregations