Java Code Examples for com.watabou.utils.PathFinder#NEIGHBOURS8

The following examples show how to use com.watabou.utils.PathFinder#NEIGHBOURS8 . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: Goo.java    From shattered-pixel-dungeon with GNU General Public License v3.0 6 votes vote down vote up
@Override
public void die( Object cause ) {
	
	super.die( cause );
	
	Dungeon.level.unseal();
	
	GameScene.bossSlain();
	Dungeon.level.drop( new SkeletonKey( Dungeon.depth ), pos ).sprite.drop();
	
	//60% chance of 2 blobs, 30% chance of 3, 10% chance for 4. Average of 2.5
	int blobs = Random.chances(new float[]{0, 0, 6, 3, 1});
	for (int i = 0; i < blobs; i++){
		int ofs;
		do {
			ofs = PathFinder.NEIGHBOURS8[Random.Int(8)];
		} while (!Dungeon.level.passable[pos + ofs]);
		Dungeon.level.drop( new GooBlob(), pos + ofs ).sprite.drop( pos );
	}
	
	Badges.validateBossSlain();
	
	yell( Messages.get(this, "defeated") );
}
 
Example 2
Source File: CrystalMimic.java    From shattered-pixel-dungeon with GNU General Public License v3.0 6 votes vote down vote up
@Override
public int attackProc(Char enemy, int damage) {
	if (alignment == Alignment.NEUTRAL && enemy == Dungeon.hero){
		steal( Dungeon.hero );

	} else {
		ArrayList<Integer> candidates = new ArrayList<>();
		for (int i : PathFinder.NEIGHBOURS8){
			if (Dungeon.level.passable[pos+i] && Actor.findChar(pos+i) == null){
				candidates.add(pos + i);
			}
		}

		if (!candidates.isEmpty()){
			ScrollOfTeleportation.appear(enemy, Random.element(candidates));
		}

		if (alignment == Alignment.ENEMY) state = FLEEING;
	}
	return super.attackProc(enemy, damage);
}
 
Example 3
Source File: Goo.java    From shattered-pixel-dungeon-gdx with GNU General Public License v3.0 6 votes vote down vote up
@Override
public void die( Object cause ) {
	
	super.die( cause );
	
	Dungeon.level.unseal();
	
	GameScene.bossSlain();
	Dungeon.level.drop( new SkeletonKey( Dungeon.depth ), pos ).sprite.drop();
	
	//60% chance of 2 blobs, 30% chance of 3, 10% chance for 4. Average of 2.5
	int blobs = Random.chances(new float[]{0, 0, 6, 3, 1});
	for (int i = 0; i < blobs; i++){
		int ofs;
		do {
			ofs = PathFinder.NEIGHBOURS8[Random.Int(8)];
		} while (!Dungeon.level.passable[pos + ofs]);
		Dungeon.level.drop( new GooBlob(), pos + ofs ).sprite.drop( pos );
	}
	
	Badges.validateBossSlain();
	
	yell( Messages.get(this, "defeated") );
}
 
Example 4
Source File: WandOfRegrowth.java    From shattered-pixel-dungeon-gdx with GNU General Public License v3.0 6 votes vote down vote up
@Override
public void activate( Char ch ) {

	int nSeeds = Random.NormalIntRange(2, 4);

	ArrayList<Integer> candidates = new ArrayList<>();
	for (int i : PathFinder.NEIGHBOURS8){
		if (Dungeon.level.passable[pos+i]
				&& pos+i != Dungeon.level.entrance
				&& pos+i != Dungeon.level.exit){
			candidates.add(pos+i);
		}
	}

	for (int i = 0; i < nSeeds && !candidates.isEmpty(); i++){
		Integer c = Random.element(candidates);
		Dungeon.level.drop(Generator.random(Generator.Category.SEED), c).sprite.drop(pos);
		candidates.remove(c);
	}

}
 
Example 5
Source File: WandOfRegrowth.java    From shattered-pixel-dungeon with GNU General Public License v3.0 6 votes vote down vote up
@Override
public void activate( Char ch ) {

	int nDrops = Random.NormalIntRange(3, 6);

	ArrayList<Integer> candidates = new ArrayList<>();
	for (int i : PathFinder.NEIGHBOURS8){
		if (Dungeon.level.passable[pos+i]
				&& pos+i != Dungeon.level.entrance
				&& pos+i != Dungeon.level.exit){
			candidates.add(pos+i);
		}
	}

	for (int i = 0; i < nDrops && !candidates.isEmpty(); i++){
		Integer c = Random.element(candidates);
		Dungeon.level.drop(new Dewdrop(), c).sprite.drop(pos);
		candidates.remove(c);
	}

}
 
Example 6
Source File: Mob.java    From shattered-pixel-dungeon-gdx with GNU General Public License v3.0 6 votes vote down vote up
public static void restoreAllies( Level level, int pos ){
	if (!heldAllies.isEmpty()){
		
		ArrayList<Integer> candidatePositions = new ArrayList<>();
		for (int i : PathFinder.NEIGHBOURS8) {
			if (!Dungeon.level.solid[i+pos] && level.findMob(i+pos) == null){
				candidatePositions.add(i+pos);
			}
		}
		Collections.shuffle(candidatePositions);
		
		for (Mob ally : heldAllies) {
			level.mobs.add(ally);
			ally.state = ally.WANDERING;
			
			if (!candidatePositions.isEmpty()){
				ally.pos = candidatePositions.remove(0);
			} else {
				ally.pos = pos;
			}
			
		}
	}
	heldAllies.clear();
}
 
Example 7
Source File: OldDM300.java    From shattered-pixel-dungeon with GNU General Public License v3.0 5 votes vote down vote up
@Override
public void die( Object cause ) {
	
	super.die( cause );
	
	GameScene.bossSlain();
	Dungeon.level.drop( new SkeletonKey( Dungeon.depth  ), pos ).sprite.drop();
	
	//60% chance of 2 shards, 30% chance of 3, 10% chance for 4. Average of 2.5
	int shards = Random.chances(new float[]{0, 0, 6, 3, 1});
	for (int i = 0; i < shards; i++){
		int ofs;
		do {
			ofs = PathFinder.NEIGHBOURS8[Random.Int(8)];
		} while (!Dungeon.level.passable[pos + ofs]);
		Dungeon.level.drop( new MetalShard(), pos + ofs ).sprite.drop( pos );
	}
	
	Badges.validateBossSlain();

	LloydsBeacon beacon = Dungeon.hero.belongings.getItem(LloydsBeacon.class);
	if (beacon != null) {
		beacon.upgrade();
	}
	
	yell( Messages.get(this, "defeated") );
}
 
Example 8
Source File: CausticSlime.java    From shattered-pixel-dungeon with GNU General Public License v3.0 5 votes vote down vote up
@Override
public void rollToDropLoot() {
	if (Dungeon.hero.lvl > maxLvl + 2) return;
	
	super.rollToDropLoot();
	
	int ofs;
	do {
		ofs = PathFinder.NEIGHBOURS8[Random.Int(8)];
	} while (!Dungeon.level.passable[pos + ofs]);
	Dungeon.level.drop( new GooBlob(), pos + ofs ).sprite.drop( pos );
}
 
Example 9
Source File: DemonSpawner.java    From shattered-pixel-dungeon with GNU General Public License v3.0 5 votes vote down vote up
@Override
protected boolean act() {
	if (!spawnRecorded){
		Statistics.spawnersAlive++;
		spawnRecorded = true;
	}

	spawnCooldown--;
	if (spawnCooldown <= 0){
		ArrayList<Integer> candidates = new ArrayList<>();
		for (int n : PathFinder.NEIGHBOURS8) {
			if (Dungeon.level.passable[pos+n] && Actor.findChar( pos+n ) == null) {
				candidates.add( pos+n );
			}
		}

		if (!candidates.isEmpty()) {
			RipperDemon spawn = new RipperDemon();

			spawn.pos = Random.element( candidates );
			spawn.state = spawn.HUNTING;

			Dungeon.level.occupyCell(spawn);

			GameScene.add( spawn, 1 );
			if (sprite.visible) {
				Actor.addDelayed(new Pushing(spawn, pos, spawn.pos), -1);
			}

			spawnCooldown += 60;
			if (Dungeon.depth > 21){
				//60/53.33/46.67/40 turns to spawn on floor 21/22/23/24
				spawnCooldown -= Math.min(20, (Dungeon.depth-21)*6.67);
			}
		}
	}
	return super.act();
}
 
Example 10
Source File: Bomb.java    From shattered-pixel-dungeon with GNU General Public License v3.0 5 votes vote down vote up
@Override
protected void onThrow( int cell ) {
	if (!Dungeon.level.pit[ cell ] && lightingFuse) {
		Actor.addDelayed(fuse = new Fuse().ignite(this), 2);
	}
	if (Actor.findChar( cell ) != null && !(Actor.findChar( cell ) instanceof Hero) ){
		ArrayList<Integer> candidates = new ArrayList<>();
		for (int i : PathFinder.NEIGHBOURS8)
			if (Dungeon.level.passable[cell + i])
				candidates.add(cell + i);
		int newCell = candidates.isEmpty() ? cell : Random.element(candidates);
		Dungeon.level.drop( this, newCell ).sprite.drop( cell );
	} else
		super.onThrow( cell );
}
 
Example 11
Source File: Yog.java    From shattered-pixel-dungeon with GNU General Public License v3.0 5 votes vote down vote up
public void spawnFists() {
	RottingFist fist1 = new RottingFist();
	BurningFist fist2 = new BurningFist();
	
	do {
		fist1.pos = pos + PathFinder.NEIGHBOURS8[Random.Int( 8 )];
		fist2.pos = pos + PathFinder.NEIGHBOURS8[Random.Int( 8 )];
	} while (!Dungeon.level.passable[fist1.pos] || !Dungeon.level.passable[fist2.pos] || fist1.pos == fist2.pos);
	
	GameScene.add( fist1 );
	GameScene.add( fist2 );

	notice();
}
 
Example 12
Source File: NPC.java    From shattered-pixel-dungeon-gdx with GNU General Public License v3.0 5 votes vote down vote up
protected void throwItem() {
	Heap heap = Dungeon.level.heaps.get( pos );
	if (heap != null) {
		int n;
		do {
			n = pos + PathFinder.NEIGHBOURS8[Random.Int( 8 )];
		} while (!Dungeon.level.passable[n] && !Dungeon.level.avoid[n]);
		Dungeon.level.drop( heap.pickUp(), n ).sprite.drop( pos );
	}
}
 
Example 13
Source File: NewPrisonBossLevel.java    From shattered-pixel-dungeon with GNU General Public License v3.0 5 votes vote down vote up
@Override
public int randomRespawnCell( Char ch ) {
	int pos = ENTRANCE_POS; //random cell adjacent to the entrance.
	int cell;
	do {
		cell = pos + PathFinder.NEIGHBOURS8[Random.Int(8)];
	} while (!passable[cell]
			|| (Char.hasProp(ch, Char.Property.LARGE) && !openSpace[cell])
			|| Actor.findChar(cell) != null);
	return cell;
}
 
Example 14
Source File: DM201.java    From shattered-pixel-dungeon with GNU General Public License v3.0 5 votes vote down vote up
@Override
public void rollToDropLoot() {
	if (Dungeon.hero.lvl > maxLvl + 2) return;

	super.rollToDropLoot();

	int ofs;
	do {
		ofs = PathFinder.NEIGHBOURS8[Random.Int(8)];
	} while (!Dungeon.level.passable[pos + ofs]);
	Dungeon.level.drop( new MetalShard(), pos + ofs ).sprite.drop( pos );
}
 
Example 15
Source File: RotGardenRoom.java    From shattered-pixel-dungeon with GNU General Public License v3.0 5 votes vote down vote up
private static void placePlant(Level level, int pos, Mob plant){
	plant.pos = pos;
	level.mobs.add( plant );

	for(int i : PathFinder.NEIGHBOURS8) {
		if (level.map[pos + i] == Terrain.GRASS){
			Painter.set(level, pos + i, Terrain.HIGH_GRASS);
		}
	}
}
 
Example 16
Source File: Pylon.java    From shattered-pixel-dungeon with GNU General Public License v3.0 5 votes vote down vote up
@Override
protected boolean act() {
	spend(TICK);

	Heap heap = Dungeon.level.heaps.get( pos );
	if (heap != null) {
		int n;
		do {
			n = pos + PathFinder.NEIGHBOURS8[Random.Int( 8 )];
		} while (!Dungeon.level.passable[n] && !Dungeon.level.avoid[n]);
		Dungeon.level.drop( heap.pickUp(), n ).sprite.drop( pos );
	}

	if (alignment == Alignment.NEUTRAL){
		return true;
	}

	int cell1 = pos + PathFinder.CIRCLE8[targetNeighbor];
	int cell2 = pos + PathFinder.CIRCLE8[(targetNeighbor+4)%8];

	sprite.flash();
	if (Dungeon.level.heroFOV[pos] || Dungeon.level.heroFOV[cell1] || Dungeon.level.heroFOV[cell2]) {
		sprite.parent.add(new Lightning(DungeonTilemap.raisedTileCenterToWorld(cell1),
				DungeonTilemap.raisedTileCenterToWorld(cell2), null));
		CellEmitter.get(cell1).burst(SparkParticle.FACTORY, 3);
		CellEmitter.get(cell2).burst(SparkParticle.FACTORY, 3);
		Sample.INSTANCE.play( Assets.Sounds.LIGHTNING );
	}

	shockChar(Actor.findChar(cell1));
	shockChar(Actor.findChar(cell2));

	targetNeighbor = (targetNeighbor+1)%8;

	return true;
}
 
Example 17
Source File: NewPrisonBossLevel.java    From shattered-pixel-dungeon-gdx with GNU General Public License v3.0 5 votes vote down vote up
@Override
public int randomRespawnCell() {
	int pos = ENTRANCE_POS; //random cell adjacent to the entrance.
	int cell;
	do {
		cell = pos + PathFinder.NEIGHBOURS8[Random.Int(8)];
	} while (!passable[cell] || Actor.findChar(cell) != null);
	return cell;
}
 
Example 18
Source File: NewTengu.java    From shattered-pixel-dungeon with GNU General Public License v3.0 4 votes vote down vote up
public static boolean throwShocker(final Char thrower, final Char target){
	
	int targetCell = -1;
	
	//Targets closest cell which is adjacent to target, and not adjacent to thrower or another shocker
	for (int i : PathFinder.NEIGHBOURS8){
		int cell = target.pos + i;
		if (Dungeon.level.distance(cell, thrower.pos) >= 2 && !Dungeon.level.solid[cell]){
			boolean validTarget = true;
			for (ShockerAbility s : thrower.buffs(ShockerAbility.class)){
				if (Dungeon.level.distance(cell, s.shockerPos) < 2){
					validTarget = false;
					break;
				}
			}
			if (validTarget && Dungeon.level.trueDistance(cell, thrower.pos) < Dungeon.level.trueDistance(targetCell, thrower.pos)){
				targetCell = cell;
			}
		}
	}
	
	if (targetCell == -1){
		return false;
	}
	
	final int finalTargetCell = targetCell;
	throwingChar = thrower;
	final ShockerAbility.ShockerItem item = new ShockerAbility.ShockerItem();
	thrower.sprite.zap(finalTargetCell);
	((MissileSprite) thrower.sprite.parent.recycle(MissileSprite.class)).
			reset(thrower.sprite,
					finalTargetCell,
					item,
					new Callback() {
						@Override
						public void call() {
							item.onThrow(finalTargetCell);
							thrower.next();
						}
					});
	return true;
}
 
Example 19
Source File: Ghoul.java    From shattered-pixel-dungeon with GNU General Public License v3.0 4 votes vote down vote up
@Override
public boolean act() {
	ghoul.sprite.visible = Dungeon.level.heroFOV[ghoul.pos];

	if (target.fieldOfView == null){
		target.fieldOfView = new boolean[Dungeon.level.length()];
		Dungeon.level.updateFieldOfView( target, target.fieldOfView );
	}

	if (!target.fieldOfView[ghoul.pos] && Dungeon.level.distance(ghoul.pos, target.pos) >= 4){
		detach();
		return true;
	}

	turnsToRevive--;
	if (turnsToRevive <= 0){
		ghoul.HP = Math.round(ghoul.HT/10f);
		if (Actor.findChar( ghoul.pos ) != null) {
			ArrayList<Integer> candidates = new ArrayList<>();
			for (int n : PathFinder.NEIGHBOURS8) {
				int cell = ghoul.pos + n;
				if (Dungeon.level.passable[cell] && Actor.findChar( cell ) == null) {
					candidates.add( cell );
				}
			}
			if (candidates.size() > 0) {
				int newPos = Random.element( candidates );
				Actor.addDelayed( new Pushing( ghoul, ghoul.pos, newPos ), -1 );
				ghoul.pos = newPos;

			} else {
				spend(TICK);
				return true;
			}
		}
		Actor.add(ghoul);
		ghoul.spend(-ghoul.cooldown());
		Dungeon.level.mobs.add(ghoul);
		Dungeon.level.occupyCell( ghoul );
		ghoul.sprite.idle();
		super.detach();
		return true;
	}

	spend(TICK);
	return true;
}
 
Example 20
Source File: PrismaticGuard.java    From shattered-pixel-dungeon with GNU General Public License v3.0 4 votes vote down vote up
@Override
public boolean act() {
	
	Hero hero = (Hero)target;
	
	Mob closest = null;
	int v = hero.visibleEnemies();
	for (int i=0; i < v; i++) {
		Mob mob = hero.visibleEnemy( i );
		if ( mob.isAlive() && mob.state != mob.PASSIVE && mob.state != mob.WANDERING && mob.state != mob.SLEEPING && !hero.mindVisionEnemies.contains(mob)
				&& (closest == null || Dungeon.level.distance(hero.pos, mob.pos) < Dungeon.level.distance(hero.pos, closest.pos))) {
			closest = mob;
		}
	}
	
	if (closest != null && Dungeon.level.distance(hero.pos, closest.pos) < 5){
		//spawn guardian
		int bestPos = -1;
		for (int i = 0; i < PathFinder.NEIGHBOURS8.length; i++) {
			int p = hero.pos + PathFinder.NEIGHBOURS8[i];
			if (Actor.findChar( p ) == null && Dungeon.level.passable[p]) {
				if (bestPos == -1 || Dungeon.level.trueDistance(p, closest.pos) < Dungeon.level.trueDistance(bestPos, closest.pos)){
					bestPos = p;
				}
			}
		}
		if (bestPos != -1) {
			PrismaticImage pris = new PrismaticImage();
			pris.duplicate(hero, (int)Math.floor(HP) );
			pris.state = pris.HUNTING;
			GameScene.add(pris, 1);
			ScrollOfTeleportation.appear(pris, bestPos);
			
			detach();
		} else {
			spend( TICK );
		}
		
		
	} else {
		spend(TICK);
	}
	
	LockedFloor lock = target.buff(LockedFloor.class);
	if (HP < maxHP() && (lock == null || lock.regenOn())){
		HP += 0.1f;
	}
	
	return true;
}