com.watabou.utils.Random Java Examples

The following examples show how to use com.watabou.utils.Random. 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: Holy.java    From unleashed-pixel-dungeon with GNU General Public License v3.0 6 votes vote down vote up
@Override
public boolean proc( Weapon weapon, Char attacker, Char defender, int damage ) {
    int curDamage = 0;
    int level = Math.max( 0, weapon.level );

    if (defender.TYPE_UNDEAD) {
        if (Random.Int(level + 4) >= 3) {
            curDamage += Random.Int(0, damage + weapon.level);
            defender.damage(curDamage, this);
            return true;
        }
    } else if (defender.TYPE_EVIL) {
        if (Random.Int(level + 4) >= 5) {
            curDamage += Random.Int(0, ((damage + weapon.level) / 2));
            defender.damage(curDamage, this);
            return true;
        }
    }
    return false;
}
 
Example #2
Source File: Kunai.java    From shattered-pixel-dungeon-gdx with GNU General Public License v3.0 6 votes vote down vote up
@Override
public int damageRoll(Char owner) {
	if (owner instanceof Hero) {
		Hero hero = (Hero)owner;
		if (enemy instanceof Mob && ((Mob) enemy).surprisedBy(hero)) {
			//deals 60% toward max to max on surprise, instead of min to max.
			int diff = max() - min();
			int damage = augment.damageFactor(Random.NormalIntRange(
					min() + Math.round(diff*0.6f),
					max()));
			int exStr = hero.STR() - STRReq();
			if (exStr > 0) {
				damage += Random.IntRange(0, exStr);
			}
			return damage;
		}
	}
	return super.damageRoll(owner);
}
 
Example #3
Source File: WindParticle.java    From shattered-pixel-dungeon-gdx with GNU General Public License v3.0 6 votes vote down vote up
@Override
public void update() {
	
	if (visible = (pos < Dungeon.level.heroFOV.length && Dungeon.level.heroFOV[pos])) {
		
		super.update();
		
		if ((delay -= Game.elapsed) <= 0) {
			
			delay = Random.Float( 5 );
			
			((WindParticle)recycle( WindParticle.class )).reset(
				x + Random.Float( DungeonTilemap.SIZE ),
				y + Random.Float( DungeonTilemap.SIZE ) );
		}
	}
}
 
Example #4
Source File: CityBossLevel.java    From remixed-dungeon with GNU General Public License v3.0 6 votes vote down vote up
@Override
public void pressHero(int cell, Hero hero ) {
	
	super.pressHero( cell, hero );
	
	if (!enteredArena && outsideEntranceRoom( cell ) && hero == Dungeon.hero) {
		
		enteredArena = true;

		int pos;

		do {
			pos = Random.Int(getLength());
		} while (
				!passable[pos] ||
						!outsideEntranceRoom(pos ) ||
						Dungeon.visible[pos]);

		spawnBoss(pos);
	}
}
 
Example #5
Source File: Lightning.java    From shattered-pixel-dungeon with GNU General Public License v3.0 6 votes vote down vote up
@Override
public void update() {
	float x2 = (start.x + end.x) / 2 + Random.Float( -4, +4 );
	float y2 = (start.y + end.y) / 2 + Random.Float( -4, +4 );

	float dx = x2 - start.x;
	float dy = y2 - start.y;
	arc1.angle = (float)(Math.atan2( dy, dx ) * A);
	arc1.scale.x = (float)Math.sqrt( dx * dx + dy * dy ) / arc1.width;

	dx = end.x - x2;
	dy = end.y - y2;
	arc2.angle = (float)(Math.atan2( dy, dx ) * A);
	arc2.scale.x = (float)Math.sqrt( dx * dx + dy * dy ) / arc2.width;
	arc2.x = x2 - arc2.origin.x;
	arc2.y = y2 - arc2.origin.x;
}
 
Example #6
Source File: Ooze.java    From shattered-pixel-dungeon-gdx with GNU General Public License v3.0 6 votes vote down vote up
@Override
public boolean act() {
	if (target.isAlive()) {
		if (Dungeon.depth > 4)
			target.damage( Dungeon.depth/5, this );
		else if (Random.Int(2) == 0)
			target.damage( 1, this );
		if (!target.isAlive() && target == Dungeon.hero) {
			Dungeon.fail( getClass() );
			GLog.n( Messages.get(this, "ondeath") );
		}
		spend( TICK );
		left -= TICK;
		if (left <= 0){
			detach();
		}
	} else {
		detach();
	}
	if (Dungeon.level.water[target.pos]) {
		detach();
	}
	return true;
}
 
Example #7
Source File: TunnelRoom.java    From shattered-pixel-dungeon-gdx with GNU General Public License v3.0 6 votes vote down vote up
protected final Point getDoorCenter(){
	PointF doorCenter = new PointF(0, 0);

	for (Door door : connected.values()) {
		doorCenter.x += door.x;
		doorCenter.y += door.y;
	}

	Point c = new Point((int)doorCenter.x / connected.size(), (int)doorCenter.y / connected.size());
	if (Random.Float() < doorCenter.x % 1) c.x++;
	if (Random.Float() < doorCenter.y % 1) c.y++;
	c.x = (int)GameMath.gate(left+1, c.x, right-1);
	c.y = (int)GameMath.gate(top+1, c.y, bottom-1);

	return c;
}
 
Example #8
Source File: Gold.java    From shattered-pixel-dungeon with GNU General Public License v3.0 6 votes vote down vote up
@Override
public boolean doPickUp( Hero hero ) {
	
	Dungeon.gold += quantity;
	Statistics.goldCollected += quantity;
	Badges.validateGoldCollected();

	MasterThievesArmband.Thievery thievery = hero.buff(MasterThievesArmband.Thievery.class);
	if (thievery != null)
		thievery.collect(quantity);

	GameScene.pickUp( this, hero.pos );
	hero.sprite.showStatus( CharSprite.NEUTRAL, TXT_VALUE, quantity );
	hero.spendAndNext( TIME_TO_PICK_UP );
	
	Sample.INSTANCE.play( Assets.Sounds.GOLD, 1, 1, Random.Float( 0.9f, 1.1f ) );
	
	return true;
}
 
Example #9
Source File: HallwayRoom.java    From shattered-pixel-dungeon-gdx with GNU General Public License v3.0 6 votes vote down vote up
protected final Point getDoorCenter(){
	PointF doorCenter = new PointF(0, 0);

	for (Door door : connected.values()) {
		doorCenter.x += door.x;
		doorCenter.y += door.y;
	}

	Point c = new Point((int)doorCenter.x / connected.size(), (int)doorCenter.y / connected.size());
	if (Random.Float() < doorCenter.x % 1) c.x++;
	if (Random.Float() < doorCenter.y % 1) c.y++;
	c.x = (int) GameMath.gate(left+2, c.x, right-2);
	c.y = (int)GameMath.gate(top+2, c.y, bottom-2);

	return c;
}
 
Example #10
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 #11
Source File: SewerBossLevel.java    From remixed-dungeon with GNU General Public License v3.0 6 votes vote down vote up
private void placeKingRoom() {
	ArrayList<Room> candidates = new ArrayList<>();
	for (Room r : getRoomExit().neighbours) {
		if (!getRoomExit().connected.containsKey( r ) &&
			(getRoomExit().left == r.right || getRoomExit().right == r.left || getRoomExit().bottom == r.top) &&
			!(r.type == Type.EXIT)) {
			candidates.add( r );
		}
	}

	if (!candidates.isEmpty()) {
		Room kingsRoom = Random.element( candidates );
		kingsRoom.connect(getRoomExit());
		kingsRoom.type = Type.RAT_KING;
	}
}
 
Example #12
Source File: StandardPainter.java    From unleashed-pixel-dungeon with GNU General Public License v3.0 6 votes vote down vote up
private static void paintBurned( Level level, Room room ) {
	for (int i=room.top + 1; i < room.bottom; i++) {
		for (int j=room.left + 1; j < room.right; j++) {
			int cell = i * Level.WIDTH + j;
			int t = Terrain.EMBERS;
			switch (Random.Int( 5 )) {
			case 0:
				t = Terrain.EMPTY;
				break;
			case 1:
				t = Terrain.TRAP;
				level.setTrap(new FireTrap().reveal(), cell);
				break;
			case 2:
				t = Terrain.SECRET_TRAP;
				level.setTrap(new FireTrap().hide(), cell);
				break;
			case 3:
				t = Terrain.INACTIVE_TRAP;
				break;
			}
			level.map[cell] = t;
		}
	}
}
 
Example #13
Source File: Bee.java    From YetAnotherPixelDungeon with GNU General Public License v3.0 6 votes vote down vote up
public Char chooseEnemy() {
	
	if (enemy == null || !enemy.isAlive()) {
		HashSet<Mob> enemies = new HashSet<Mob>();
		for (Mob mob:Dungeon.level.mobs) {
			if (mob.hostile && Level.fieldOfView[mob.pos]) {
				enemies.add( mob );
			}
		}
		
		return enemies.size() > 0 ? Random.element( enemies ) : null;
		
	} else {
		
		return enemy;
		
	}
}
 
Example #14
Source File: Kunai.java    From shattered-pixel-dungeon with GNU General Public License v3.0 6 votes vote down vote up
@Override
public int damageRoll(Char owner) {
	if (owner instanceof Hero) {
		Hero hero = (Hero)owner;
		if (enemy instanceof Mob && ((Mob) enemy).surprisedBy(hero)) {
			//deals 60% toward max to max on surprise, instead of min to max.
			int diff = max() - min();
			int damage = augment.damageFactor(Random.NormalIntRange(
					min() + Math.round(diff*0.6f),
					max()));
			int exStr = hero.STR() - STRReq();
			if (exStr > 0) {
				damage += Random.IntRange(0, exStr);
			}
			return damage;
		}
	}
	return super.damageRoll(owner);
}
 
Example #15
Source File: GoldenMimic.java    From shattered-pixel-dungeon with GNU General Public License v3.0 6 votes vote down vote up
@Override
protected void generatePrize() {
	super.generatePrize();
	//all existing prize items are guaranteed uncursed, and have a 50% chance to be +1 if they were +0
	for (Item i : items){
		if (i instanceof EquipableItem || i instanceof Wand){
			i.cursed = false;
			i.cursedKnown = true;
			if (i instanceof Weapon && ((Weapon) i).hasCurseEnchant()){
				((Weapon) i).enchant(null);
			}
			if (i instanceof Armor && ((Armor) i).hasCurseGlyph()){
				((Armor) i).inscribe(null);
			}
			if (!(i instanceof MissileWeapon) && i.level() == 0 && Random.Int(2) == 0){
				i.upgrade();
			}
		}
	}
}
 
Example #16
Source File: WoollyBomb.java    From shattered-pixel-dungeon with GNU General Public License v3.0 6 votes vote down vote up
@Override
public void explode(int cell) {
	super.explode(cell);
	
	PathFinder.buildDistanceMap( cell, BArray.not( Dungeon.level.solid, null ), 2 );
	for (int i = 0; i < PathFinder.distance.length; i++) {
		if (PathFinder.distance[i] < Integer.MAX_VALUE) {
			if (Dungeon.level.insideMap(i)
					&& Actor.findChar(i) == null
					&& !(Dungeon.level.pit[i])) {
				Sheep sheep = new Sheep();
				sheep.lifespan = Random.NormalIntRange( 8, 16 );
				sheep.pos = i;
				Dungeon.level.occupyCell(sheep);
				GameScene.add(sheep);
				CellEmitter.get(i).burst(Speck.factory(Speck.WOOL), 4);
			}
		}
	}
	
	Sample.INSTANCE.play(Assets.Sounds.PUFF);
	
	
}
 
Example #17
Source File: CavesBossLevel.java    From unleashed-pixel-dungeon with GNU General Public License v3.0 5 votes vote down vote up
@Override
protected void decorate() {
	
	for (int i=WIDTH + 1; i < LENGTH - WIDTH; i++) {
		if (map[i] == Terrain.EMPTY) {
			int n = 0;
			if (map[i+1] == Terrain.WALL) {
				n++;
			}
			if (map[i-1] == Terrain.WALL) {
				n++;
			}
			if (map[i+WIDTH] == Terrain.WALL) {
				n++;
			}
			if (map[i-WIDTH] == Terrain.WALL) {
				n++;
			}
			if (Random.Int( 8 ) <= n) {
				map[i] = Terrain.EMPTY_DECO;
			}
		}
	}
	
	for (int i=0; i < LENGTH; i++) {
		if (map[i] == Terrain.WALL && Random.Int( 8 ) == 0) {
			map[i] = Terrain.WALL_DECO;
		}
	}
	
	int sign;
	do {
		sign = Random.Int( ROOM_LEFT, ROOM_RIGHT ) + Random.Int( ROOM_TOP, ROOM_BOTTOM ) * WIDTH;
	} while (sign == entrance);
	map[sign] = Terrain.SIGN;
}
 
Example #18
Source File: MagicMissile.java    From YetAnotherPixelDungeon with GNU General Public License v3.0 5 votes vote down vote up
public MagicParticle() {
	super();
	
	color( 0x88CCFF );
	lifespan = 0.5f;
	
	speed.set( Random.Float( -10, +10 ), Random.Float( -10, +10 ) );
}
 
Example #19
Source File: Sheep.java    From unleashed-pixel-dungeon with GNU General Public License v3.0 5 votes vote down vote up
@Override
protected boolean act() {
	if (initialized) {
		HP = 0;

		destroy();
		sprite.die();

	} else {
		initialized = true;
		spend( lifespan + Random.Float(2) );
	}
	return true;
}
 
Example #20
Source File: StormWard.java    From YetAnotherPixelDungeon with GNU General Public License v3.0 5 votes vote down vote up
@Override
protected boolean proc_n( Char attacker, Char defender, int damage ) {

    defender.damage(Random.IntRange(damage / 4, damage / 3), this, Element.SHOCK);
    defender.sprite.parent.add( new Lightning( defender.pos, defender.pos ) );

    return true;
}
 
Example #21
Source File: ChaosMage.java    From unleashed-pixel-dungeon with GNU General Public License v3.0 5 votes vote down vote up
@Override
public int attackProc(Char enemy, int damage) {
    if (enemy instanceof Hero){
        corrupt((Hero) enemy);
    }

    if (damage > 0) {
        int healingAmt = Random.Int(0, damage);
        HP = Math.min(HT, HP + healingAmt);
        sprite.emitter().burst(ShadowParticle.UP, 2);
    }

    return damage;
}
 
Example #22
Source File: MonkSprite.java    From unleashed-pixel-dungeon with GNU General Public License v3.0 5 votes vote down vote up
@Override
public void attack( int cell ) {
	super.attack( cell );
	if (Random.Float() < 0.5f) {
		play( kick );
	}
}
 
Example #23
Source File: WoolParticle.java    From YetAnotherPixelDungeon with GNU General Public License v3.0 5 votes vote down vote up
public void reset( float x, float y ) {
	revive();
	
	this.x = x;
	this.y = y;
	
	left = lifespan = Random.Float( 0.6f, 1f );
	size = 5;
	
	speed.set( Random.Float( -10, +10 ), Random.Float( -10, +10 ) );
}
 
Example #24
Source File: ShadowParticle.java    From pixel-dungeon with GNU General Public License v3.0 5 votes vote down vote up
public void reset( float x, float y ) {
	revive();
	
	this.x = x;
	this.y = y;
	
	speed.set( Random.Float( -5, +5 ), Random.Float( -5, +5 ) );
	
	size = 6;
	left = lifespan = 0.5f;
}
 
Example #25
Source File: FissureRoom.java    From shattered-pixel-dungeon-gdx with GNU General Public License v3.0 5 votes vote down vote up
@Override
public void paint(Level level) {
	Painter.fill( level, this, Terrain.WALL );
	for (Door door : connected.values()) {
		door.set( Door.Type.REGULAR );
	}
	Painter.fill( level, this, 1, Terrain.EMPTY );
	
	if (square() <= 25){
		//just fill in one tile if the room is tiny
		Point p = center();
		Painter.set( level, p.x, p.y, Terrain.CHASM);
		
	} else {
		int smallestDim = Math.min(width(), height());
		int floorW = (int)Math.sqrt(smallestDim);
		//chance for a tile at the edge of the floor to remain a floor tile
		float edgeFloorChance = (float)Math.sqrt(smallestDim) % 1;
		//the wider the floor the more edge chances tend toward 50%
		edgeFloorChance = (edgeFloorChance + (floorW-1)*0.5f) / (float)floorW;
		
		for (int i=top + 2; i <= bottom - 2; i++) {
			for (int j=left + 2; j <= right - 2; j++) {
				int v = Math.min( i - top, bottom - i );
				int h = Math.min( j - left, right - j );
				if (Math.min( v, h ) > floorW
						|| (Math.min( v, h ) == floorW && Random.Float() > edgeFloorChance)) {
					Painter.set( level, j, i, Terrain.CHASM );
				}
			}
		}
	}
}
 
Example #26
Source File: DriedRose.java    From shattered-pixel-dungeon with GNU General Public License v3.0 5 votes vote down vote up
@Override
public int damageRoll() {
	int dmg = 0;
	if (rose != null && rose.weapon != null){
		dmg += rose.weapon.damageRoll(this);
	} else {
		dmg += Random.NormalIntRange(0, 5);
	}
	
	return dmg;
}
 
Example #27
Source File: Paralysis.java    From shattered-pixel-dungeon with GNU General Public License v3.0 5 votes vote down vote up
public void processDamage( int damage ){
	if (target == null) return;
	ParalysisResist resist = target.buff(ParalysisResist.class);
	if (resist == null){
		resist = Buff.affect(target, ParalysisResist.class);
	}
	resist.damage += damage;
	if (Random.NormalIntRange(0, resist.damage) >= Random.NormalIntRange(0, target.HP)){
		if (Dungeon.level.heroFOV[target.pos]) {
			target.sprite.showStatus(CharSprite.NEUTRAL, Messages.get(this, "out"));
		}
		detach();
	}
}
 
Example #28
Source File: NewDM300.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.unseal();

	//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 #29
Source File: BloodParticle.java    From unleashed-pixel-dungeon with GNU General Public License v3.0 5 votes vote down vote up
public void resetBurst( float x, float y ) {
	revive();

	this.x = x;
	this.y = y;

	speed.polar( Random.Float(PointF.PI2), Random.Float( 16, 32 ) );
	size = 5;

	left = 0.5f;
}
 
Example #30
Source File: Char.java    From shattered-pixel-dungeon with GNU General Public License v3.0 5 votes vote down vote up
public void move( int step ) {

		if (Dungeon.level.adjacent( step, pos ) && buff( Vertigo.class ) != null) {
			sprite.interruptMotion();
			int newPos = pos + PathFinder.NEIGHBOURS8[Random.Int( 8 )];
			if (!(Dungeon.level.passable[newPos] || Dungeon.level.avoid[newPos])
					|| (properties.contains(Property.LARGE) && !Dungeon.level.openSpace[pos])
					|| Actor.findChar( newPos ) != null)
				return;
			else {
				sprite.move(pos, newPos);
				step = newPos;
			}
		}

		if (Dungeon.level.map[pos] == Terrain.OPEN_DOOR) {
			Door.leave( pos );
		}

		pos = step;
		
		if (this != Dungeon.hero) {
			sprite.visible = Dungeon.level.heroFOV[pos];
		}
		
		Dungeon.level.occupyCell(this );
	}