Java Code Examples for com.watabou.utils.Random#index()

The following examples show how to use com.watabou.utils.Random#index() . 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: SummoningTrap.java    From YetAnotherPixelDungeon with GNU General Public License v3.0 5 votes vote down vote up
public static void trigger( int pos, Char ch ) {

		if (Dungeon.bossLevel()) {
			return;
		}
		
		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 );
			}
		}
		
		while (nMobs > 0 && candidates.size() > 0) {
			int index = Random.index( candidates );

            Mob mob = Bestiary.mob(Dungeon.depth);
            mob.state = mob.HUNTING;
            GameScene.add( mob, DELAY );

            ScrollOfPhaseWarp.appear( mob, candidates.get( index ) );

			Actor.occupyCell( mob );
			
			candidates.remove( index );
			nMobs--;
		}
	}
 
Example 2
Source File: ScrollOfMirrorImage.java    From unleashed-pixel-dungeon with GNU General Public License v3.0 5 votes vote down vote up
@Override
protected void doRead() {
	
	ArrayList<Integer> respawnPoints = new ArrayList<Integer>();
	
	for (int i=0; i < Level.NEIGHBOURS8.length; i++) {
		int p = curUser.pos + Level.NEIGHBOURS8[i];
		if (Actor.findChar( p ) == null && (Level.passable[p] || Level.avoid[p])) {
			respawnPoints.add( p );
		}
	}
	
	int nImages = NIMAGES;
	while (nImages > 0 && respawnPoints.size() > 0) {
		int index = Random.index( respawnPoints );
		
		MirrorImage mob = new MirrorImage();
		mob.duplicate( curUser );
		GameScene.add( mob );
		ScrollOfTeleportation.appear( mob, respawnPoints.get( index ) );
		
		respawnPoints.remove( index );
		nImages--;
	}
	
	if (nImages < NIMAGES) {
		setKnown();
	}
	
	Sample.INSTANCE.play( Assets.SND_READ );
	Invisibility.dispel();
	
	curUser.spendAndNext( TIME_TO_READ );
}
 
Example 3
Source File: ScrollOfMirrorImage.java    From pixel-dungeon with GNU General Public License v3.0 5 votes vote down vote up
@Override
protected void doRead() {
	
	ArrayList<Integer> respawnPoints = new ArrayList<Integer>();
	
	for (int i=0; i < Level.NEIGHBOURS8.length; i++) {
		int p = curUser.pos + Level.NEIGHBOURS8[i];
		if (Actor.findChar( p ) == null && (Level.passable[p] || Level.avoid[p])) {
			respawnPoints.add( p );
		}
	}
	
	int nImages = NIMAGES;
	while (nImages > 0 && respawnPoints.size() > 0) {
		int index = Random.index( respawnPoints );
		
		MirrorImage mob = new MirrorImage();
		mob.duplicate( curUser );
		GameScene.add( mob );
		WandOfBlink.appear( mob, respawnPoints.get( index ) );
		
		respawnPoints.remove( index );
		nImages--;
	}
	
	if (nImages < NIMAGES) {
		setKnown();
	}
	
	Sample.INSTANCE.play( Assets.SND_READ );
	Invisibility.dispel();
	
	readAnimation();
}
 
Example 4
Source File: ScrollOfMirrorImage.java    From shattered-pixel-dungeon with GNU General Public License v3.0 5 votes vote down vote up
public static int spawnImages( Hero hero, int nImages ){
	
	ArrayList<Integer> respawnPoints = new ArrayList<>();
	
	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]) {
			respawnPoints.add( p );
		}
	}
	
	int spawned = 0;
	while (nImages > 0 && respawnPoints.size() > 0) {
		int index = Random.index( respawnPoints );
		
		MirrorImage mob = new MirrorImage();
		mob.duplicate( hero );
		GameScene.add( mob );
		ScrollOfTeleportation.appear( mob, respawnPoints.get( index ) );
		
		respawnPoints.remove( index );
		nImages--;
		spawned++;
	}
	
	return spawned;
}
 
Example 5
Source File: ScrollOfMirrorImage.java    From shattered-pixel-dungeon-gdx with GNU General Public License v3.0 5 votes vote down vote up
public static int spawnImages( Hero hero, int nImages ){
	
	ArrayList<Integer> respawnPoints = new ArrayList<>();
	
	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]) {
			respawnPoints.add( p );
		}
	}
	
	int spawned = 0;
	while (nImages > 0 && respawnPoints.size() > 0) {
		int index = Random.index( respawnPoints );
		
		MirrorImage mob = new MirrorImage();
		mob.duplicate( hero );
		GameScene.add( mob );
		ScrollOfTeleportation.appear( mob, respawnPoints.get( index ) );
		
		respawnPoints.remove( index );
		nImages--;
		spawned++;
	}
	
	return spawned;
}
 
Example 6
Source File: SummoningTrap.java    From unleashed-pixel-dungeon with GNU General Public License v3.0 4 votes vote down vote up
@Override
public void activate() {

	if (Dungeon.bossLevel()) {
		return;
	}

	int nMobs = 1;
	if (Random.Int( 2 ) == 0) {
		nMobs++;
		if (Random.Int( 2 ) == 0) {
			nMobs++;
		}
	}

	// It's complicated here, because these traps can be activated in chain

	ArrayList<Integer> candidates = new ArrayList<>();

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

	while (nMobs > 0 && candidates.size() > 0) {
		int index = Random.index( candidates );

		DUMMY.pos = candidates.get( index );

		respawnPoints.add( candidates.remove( index ) );
		nMobs--;
	}

	for (Integer point : respawnPoints) {
		Mob mob = Bestiary.mob( Dungeon.depth );
		mob.scaleMob();

		mob.state = mob.WANDERING;
		GameScene.add( mob, DELAY );
		ScrollOfTeleportation.appear( mob, point );
	}

}
 
Example 7
Source File: SummoningTrap.java    From pixel-dungeon with GNU General Public License v3.0 4 votes vote down vote up
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 );
	}
}