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

The following examples show how to use com.watabou.utils.Random#oneOf() . 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: NewCavesBossLevel.java    From shattered-pixel-dungeon with GNU General Public License v3.0 6 votes vote down vote up
private void buildEntrance(){
	entrance = 16 + 25*width();

	//entrance area
	int NW = entrance - 7 - 7*width();
	int NE = entrance + 7 - 7*width();
	int SE = entrance + 7 + 7*width();
	int SW = entrance - 7 + 7*width();

	short[] entranceTiles = Random.oneOf(entranceVariants);
	for (int i = 0; i < entranceTiles.length; i++){
		if (i % 8 == 0 && i != 0){
			NW += (width() - 8);
			NE += (width() + 8);
			SE -= (width() - 8);
			SW -= (width() + 8);
		}

		if (entranceTiles[i] != n) map[NW] = map[NE] = map[SE] = map[SW] = entranceTiles[i];
		NW++; NE--; SW++; SE--;
	}

	Painter.set(this, entrance, Terrain.ENTRANCE);
}
 
Example 2
Source File: NewCavesBossLevel.java    From shattered-pixel-dungeon with GNU General Public License v3.0 6 votes vote down vote up
private void buildCorners(){
	int NW = 2 + 11*width();
	int NE = 30 + 11*width();
	int SE = 30 + 39*width();
	int SW = 2 + 39*width();

	short[] cornerTiles = Random.oneOf(cornerVariants);
	for(int i = 0; i < cornerTiles.length; i++){
		if (i % 10 == 0 && i != 0){
			NW += (width() - 10);
			NE += (width() + 10);
			SE -= (width() - 10);
			SW -= (width() + 10);
		}

		if (cornerTiles[i] != n) map[NW] = map[NE] = map[SE] = map[SW] = cornerTiles[i];
		NW++; NE--; SW++; SE--;
	}
}
 
Example 3
Source File: WarehousePainter.java    From remixed-dungeon with GNU General Public License v3.0 6 votes vote down vote up
public static void paint( Level level, Room room ) {

		fill( level, room, Terrain.WALL );
		fill( level, room, 1, Terrain.EMPTY_SP );
		
		Room.Door entrance = room.entrance();
		entrance.set( Room.Door.Type.HIDDEN );
		
		for (int i=room.left + 1; i < room.right; i++) {
			for (int j=room.top + 1; j < room.bottom; j++) {
				if(Math.random() < 0.5) {
					level.addLevelObject(new Barrel(level.cell(i, j)));
				} else {
					Item prize = Random.oneOf(Treasury.getLevelTreasury().random(Treasury.Category.BULLETS),
							Treasury.getLevelTreasury().random(Treasury.Category.THROWABLE));
					level.drop(prize, level.cell(i,j), Heap.Type.HEAP);
				}
			}
		}
	}
 
Example 4
Source File: ScrollOfCurse.java    From remixed-dungeon with GNU General Public License v3.0 6 votes vote down vote up
@SuppressWarnings("unchecked")
@Override
protected void doRead(@NotNull Char reader) {
	Invisibility.dispel(reader);

	reader.getSprite().emitter().burst( ShadowParticle.CURSE, 6 );
	Sample.INSTANCE.play( Assets.SND_CURSED );

	Class <? extends FlavourBuff> buffClass = (Class<? extends FlavourBuff>) Random.oneOf(badBuffs);
	Buff.prolong( reader, buffClass, 10);

	reader.getBelongings().curseEquipped();

	setKnown();
	reader.spendAndNext( TIME_TO_READ );
}
 
Example 5
Source File: SewerBossLevel.java    From YetAnotherPixelDungeon with GNU General Public License v3.0 5 votes vote down vote up
public int getRandomSpawnPoint() {

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

        for (int i=0; i < 5; i++) {
            int pos = (TOP + CHAMBER_HEIGHT + 1) * WIDTH + LEFT + i * 2 + 1;

            if( Actor.findChar( pos ) == null ) {
                list.add( pos );
            }
        }

        return list.size() > 0 ? (int)(Random.oneOf( list.toArray() ) ) : 0;
    }
 
Example 6
Source File: ShopPainter.java    From YetAnotherPixelDungeon with GNU General Public License v3.0 5 votes vote down vote up
private static Item generateKits() {
    if( !kits.isEmpty() ) {
        return kits.remove( Random.Int( kits.size() ) );
    } else {
        return Random.oneOf( defaultKits );
    }
}
 
Example 7
Source File: Succubus.java    From shattered-pixel-dungeon with GNU General Public License v3.0 5 votes vote down vote up
@Override
protected Item createLoot() {
	Class<?extends Scroll> loot;
	do{
		loot = (Class<? extends Scroll>) Random.oneOf(Generator.Category.SCROLL.classes);
	} while (loot == ScrollOfIdentify.class || loot == ScrollOfUpgrade.class);

	return Reflection.newInstance(loot);
}
 
Example 8
Source File: Scorpio.java    From shattered-pixel-dungeon with GNU General Public License v3.0 5 votes vote down vote up
@Override
protected Item createLoot() {
	Class<?extends Potion> loot;
	do{
		loot = (Class<? extends Potion>) Random.oneOf(Generator.Category.POTION.classes);
	} while (loot == PotionOfHealing.class || loot == PotionOfStrength.class);

	return Reflection.newInstance(loot);
}
 
Example 9
Source File: SpiderMind.java    From remixed-dungeon with GNU General Public License v3.0 5 votes vote down vote up
@Override
public int zapProc(@NotNull Char enemy, int damage ) {
	Class <? extends FlavourBuff> buffClass = (Class<? extends FlavourBuff>) Random.oneOf(BuffsForEnemy);
	Buff.prolong( enemy, buffClass, 3 );

	return damage;
}
 
Example 10
Source File: SpiderMindAmber.java    From remixed-dungeon with GNU General Public License v3.0 5 votes vote down vote up
@SuppressWarnings("unchecked")
@Override
public int zapProc(@NotNull Char enemy, int damage ) {
	Class <? extends FlavourBuff> buffClass = (Class<? extends FlavourBuff>) Random.oneOf(BuffsForEnemy);
	Buff.prolong( enemy, buffClass, 3 );

	return damage;
}
 
Example 11
Source File: EnslavedSoul.java    From remixed-dungeon with GNU General Public License v3.0 5 votes vote down vote up
@SuppressWarnings("unchecked")
@Override
public int attackProc(@NotNull Char enemy, int damage ) {
    //Buff proc
    if (Random.Int(5) == 1){
        if(enemy instanceof Hero) {
            Class <? extends FlavourBuff> buffClass = (Class<? extends FlavourBuff>) Random.oneOf(BuffsForEnemy);
            Buff.prolong( enemy, buffClass, 3 );
        }
    }

    return damage;
}
 
Example 12
Source File: TrapsRoom.java    From shattered-pixel-dungeon with GNU General Public License v3.0 4 votes vote down vote up
public void paint( Level level ) {
	 
	Painter.fill( level, this, Terrain.WALL );

	Class<? extends Trap> trapClass;
	switch (Random.Int(4)){
		case 0:
			trapClass = null;
			break;
		default:
			trapClass = Random.oneOf(levelTraps[Dungeon.depth/5]);
			break;
	}

	if (trapClass == null){
		Painter.fill(level, this, 1, Terrain.CHASM);
	} else {
		Painter.fill(level, this, 1, Terrain.TRAP);
	}
	
	Door door = entrance();
	door.set( Door.Type.REGULAR );
	
	int lastRow = level.map[left + 1 + (top + 1) * level.width()] == Terrain.CHASM ? Terrain.CHASM : Terrain.EMPTY;

	int x = -1;
	int y = -1;
	if (door.x == left) {
		x = right - 1;
		y = top + height() / 2;
		Painter.fill( level, x, top + 1, 1, height() - 2 , lastRow );
	} else if (door.x == right) {
		x = left + 1;
		y = top + height() / 2;
		Painter.fill( level, x, top + 1, 1, height() - 2 , lastRow );
	} else if (door.y == top) {
		x = left + width() / 2;
		y = bottom - 1;
		Painter.fill( level, left + 1, y, width() - 2, 1 , lastRow );
	} else if (door.y == bottom) {
		x = left + width() / 2;
		y = top + 1;
		Painter.fill( level, left + 1, y, width() - 2, 1 , lastRow );
	}

	for(Point p : getPoints()) {
		int cell = level.pointToCell(p);
		if (level.map[cell] == Terrain.TRAP){
			level.setTrap(Reflection.newInstance(trapClass).reveal(), cell);
		}
	}
	
	int pos = x + y * level.width();
	if (Random.Int( 3 ) == 0) {
		if (lastRow == Terrain.CHASM) {
			Painter.set( level, pos, Terrain.EMPTY );
		}
		level.drop( prize( level ), pos ).type = Heap.Type.CHEST;
	} else {
		Painter.set( level, pos, Terrain.PEDESTAL );
		level.drop( prize( level ), pos );
	}
	
	level.addItemToSpawn( new PotionOfLevitation() );
}
 
Example 13
Source File: TrapsRoom.java    From shattered-pixel-dungeon-gdx with GNU General Public License v3.0 4 votes vote down vote up
public void paint( Level level ) {
	 
	Painter.fill( level, this, Terrain.WALL );

	Class<? extends Trap> trapClass;
	switch (Random.Int(4)){
		case 0:
			trapClass = null;
			break;
		default:
			trapClass = Random.oneOf(levelTraps[Dungeon.depth/5]);
			break;
	}

	if (trapClass == null){
		Painter.fill(level, this, 1, Terrain.CHASM);
	} else {
		Painter.fill(level, this, 1, Terrain.TRAP);
	}
	
	Door door = entrance();
	door.set( Door.Type.REGULAR );
	
	int lastRow = level.map[left + 1 + (top + 1) * level.width()] == Terrain.CHASM ? Terrain.CHASM : Terrain.EMPTY;

	int x = -1;
	int y = -1;
	if (door.x == left) {
		x = right - 1;
		y = top + height() / 2;
		Painter.fill( level, x, top + 1, 1, height() - 2 , lastRow );
	} else if (door.x == right) {
		x = left + 1;
		y = top + height() / 2;
		Painter.fill( level, x, top + 1, 1, height() - 2 , lastRow );
	} else if (door.y == top) {
		x = left + width() / 2;
		y = bottom - 1;
		Painter.fill( level, left + 1, y, width() - 2, 1 , lastRow );
	} else if (door.y == bottom) {
		x = left + width() / 2;
		y = top + 1;
		Painter.fill( level, left + 1, y, width() - 2, 1 , lastRow );
	}

	for(Point p : getPoints()) {
		int cell = level.pointToCell(p);
		if (level.map[cell] == Terrain.TRAP){
			level.setTrap(Reflection.newInstance(trapClass).reveal(), cell);
		}
	}
	
	int pos = x + y * level.width();
	if (Random.Int( 3 ) == 0) {
		if (lastRow == Terrain.CHASM) {
			Painter.set( level, pos, Terrain.EMPTY );
		}
		level.drop( prize( level ), pos ).type = Heap.Type.CHEST;
	} else {
		Painter.set( level, pos, Terrain.PEDESTAL );
		level.drop( prize( level ), pos );
	}
	
	level.addItemToSpawn( new PotionOfLevitation() );
}
 
Example 14
Source File: Shocked.java    From YetAnotherPixelDungeon with GNU General Public License v3.0 3 votes vote down vote up
public void discharge() {

        target.damage(
                Random.IntRange( duration, duration * (int)Math.sqrt( target.totalHealthValue() ) ),
                this, Element.SHOCK_PERIODIC
        );

//        target.sprite.showStatus( CharSprite.NEGATIVE, "ZAP!");

        if( target instanceof Hero ) {

            Camera.main.shake( 2, 0.3f );

            Hero hero = (Hero)target;
            EquipableItem weapon = Random.oneOf( hero.belongings.weap1, hero.belongings.weap2 );

            if( weapon != null && weapon.disarmable() ) {

                GLog.w(TXT_DISARMED, weapon.name());
                weapon.doDrop(hero);

            }

        } else {

            target.delay( Random.IntRange( 1, 2 ) );

        }

        if (target.sprite.visible) {
            target.sprite.centerEmitter().burst( SparkParticle.FACTORY, (int)Math.ceil( duration ) + 1 );
        }

        detach();
    }