Java Code Examples for com.watabou.utils.Random#IntRange

The following examples show how to use com.watabou.utils.Random#IntRange . 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: 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 2
Source File: StoneOfFlock.java    From shattered-pixel-dungeon-gdx with GNU General Public License v3.0 6 votes vote down vote up
@Override
protected void activate(int cell) {

	for (int i : PathFinder.NEIGHBOURS9){
		
		if (!Dungeon.level.solid[cell + i]
				&& !Dungeon.level.pit[cell + i]
				&& Actor.findChar(cell + i) == null) {
			
			Sheep sheep = new Sheep();
			sheep.lifespan = Random.IntRange(5, 8);
			sheep.pos = cell + i;
			GameScene.add(sheep);
			Dungeon.level.occupyCell(sheep);
			
			CellEmitter.get(sheep.pos).burst(Speck.factory(Speck.WOOL), 4);
		}
	}
	CellEmitter.get(cell).burst(Speck.factory(Speck.WOOL), 4);
	Sample.INSTANCE.play(Assets.SND_PUFF);
	
}
 
Example 3
Source File: Dirk.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;
		Char enemy = hero.enemy();
		if (enemy instanceof Mob && ((Mob) enemy).surprisedBy(hero)) {
			//deals 67% 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.67f),
					max()));
			int exStr = hero.STR() - STRReq();
			if (exStr > 0) {
				damage += Random.IntRange(0, exStr);
			}
			return damage;
		}
	}
	return super.damageRoll(owner);
}
 
Example 4
Source File: CavesBossLevel.java    From pixel-dungeon with GNU General Public License v3.0 5 votes vote down vote up
@Override
protected void createItems() {
	Item item = Bones.get();
	if (item != null) {
		int pos;
		do {
			pos = Random.IntRange( ROOM_LEFT, ROOM_RIGHT ) + Random.IntRange( ROOM_TOP + 1, ROOM_BOTTOM ) * WIDTH;
		} while (pos == entrance || map[pos] == Terrain.SIGN);
		drop( item, pos ).type = Heap.Type.SKELETON;
	}
}
 
Example 5
Source File: HallsBossLevel.java    From pixel-dungeon with GNU General Public License v3.0 5 votes vote down vote up
@Override
protected void createItems() {
	Item item = Bones.get();
	if (item != null) {
		int pos;
		do {
			pos = Random.IntRange( ROOM_LEFT, ROOM_RIGHT ) + Random.IntRange( ROOM_TOP + 1, ROOM_BOTTOM ) * WIDTH;
		} while (pos == entrance || map[pos] == Terrain.SIGN);
		drop( item, pos ).type = Heap.Type.SKELETON;
	}
}
 
Example 6
Source File: Weapon.java    From unleashed-pixel-dungeon with GNU General Public License v3.0 5 votes vote down vote up
@Override
public int damageRoll( Hero hero ) {
	
	int damage = super.damageRoll( hero );
	
	if (this instanceof MeleeWeapon || (this instanceof MissileWeapon && hero.heroClass == HeroClass.HUNTRESS)) {
		int exStr = hero.STR() - STR;
		if (exStr > 0) {
			damage += Random.IntRange( 0, exStr );
		}
	}
	
	return Math.round(damage * (imbue == Imbue.LIGHT ? 0.7f : (imbue == Imbue.HEAVY ? 1.5f : 1f)));
}
 
Example 7
Source File: RingOfThorns.java    From remixed-dungeon with GNU General Public License v3.0 5 votes vote down vote up
@Override
public int defenceProc(Char defender, Char enemy, int damage) {
	int dmg = Random.IntRange(0, damage);
	if (dmg > 0) {
		enemy.damage(dmg, this);
	}
	return damage;
}
 
Example 8
Source File: HallsBossLevel.java    From YetAnotherPixelDungeon with GNU General Public License v3.0 5 votes vote down vote up
@Override
protected void createItems() {
	Item item = Bones.get();
	if (item != null) {
		int pos;
		do {
			pos = Random.IntRange( ROOM_LEFT, ROOM_RIGHT ) + Random.IntRange( ROOM_TOP + 1, ROOM_BOTTOM ) * WIDTH;
		} while (pos == entrance || map[pos] == Terrain.SIGN);
		drop( item, pos ).type = Heap.Type.BONES;
	}
}
 
Example 9
Source File: OldCavesBossLevel.java    From shattered-pixel-dungeon with GNU General Public License v3.0 5 votes vote down vote up
@Override
protected void createItems() {
	Item item = Bones.get();
	if (item != null) {
		int pos;
		do {
			pos = Random.IntRange( ROOM_LEFT, ROOM_RIGHT ) + Random.IntRange( ROOM_TOP + 1, ROOM_BOTTOM ) * width();
		} while (pos == entrance);
		drop( item, pos ).setHauntedIfCursed().type = Heap.Type.REMAINS;
	}
}
 
Example 10
Source File: SecretLibraryRoom.java    From shattered-pixel-dungeon-gdx with GNU General Public License v3.0 5 votes vote down vote up
public void paint( Level level ) {
	
	Painter.fill( level, this, Terrain.WALL );
	Painter.fill( level, this, 1, Terrain.BOOKSHELF );
	
	Painter.fillEllipse(level, this, 2, Terrain.EMPTY_SP);
	
	Door entrance = entrance();
	if (entrance.x == left || entrance.x == right){
		Painter.drawInside(level, this, entrance, (width() - 3) / 2, Terrain.EMPTY_SP);
	} else {
		Painter.drawInside(level, this, entrance, (height() - 3) / 2, Terrain.EMPTY_SP);
	}
	entrance.set( Door.Type.HIDDEN );
	
	int n = Random.IntRange( 2, 3 );
	HashMap<Class<? extends Scroll>, Float> chances = new HashMap<>(scrollChances);
	for (int i=0; i < n; i++) {
		int pos;
		do {
			pos = level.pointToCell(random());
		} while (level.map[pos] != Terrain.EMPTY_SP || level.heaps.get( pos ) != null);
		
		Class<?extends Scroll> scrollCls = Random.chances(chances);
		chances.put(scrollCls, 0f);
		level.drop( Reflection.newInstance(scrollCls), pos );
	}
}
 
Example 11
Source File: DwarvenKing.java    From YetAnotherPixelDungeon with GNU General Public License v3.0 5 votes vote down vote up
private void sacrificeAllMinions() {
    int healthRestored = 0;

    for (Mob mob : (Iterable<Mob>) Dungeon.level.mobs.clone()) {
        if (mob instanceof Undead ) {

            healthRestored += Random.IntRange( mob.HP / 3, mob.HP / 2 );

            if (sprite.visible || mob.sprite.visible) {
                sprite.parent.add( new DrainLife( mob.pos, pos, null ) );
                new Flare( 6, 16 ).color( SpellSprite.COLOUR_DARK, true).show( mob.sprite, 2f );
            }

            mob.die( this );
        }
    }

    healthRestored = Math.min( healthRestored, HT - HP );

    if( healthRestored > 0 ) {

        HP += healthRestored;

        if (sprite.visible) {
            sprite.emitter().burst(Speck.factory(Speck.HEALING), (int) Math.sqrt(healthRestored));
            sprite.showStatus(CharSprite.POSITIVE, Integer.toString(healthRestored));
        }
    }
}
 
Example 12
Source File: Tinkerer.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 ((!Level.adjacent(pos, enemy.pos)) && Random.Int( 2 ) == 0) {
        Buff.prolong(enemy, Cripple.class, Cripple.DURATION);
        damage += Random.IntRange(4, 20);
    }

    return damage;
}
 
Example 13
Source File: SpiritBow.java    From shattered-pixel-dungeon with GNU General Public License v3.0 5 votes vote down vote up
@Override
public int damageRoll(Char owner) {
	int damage = augment.damageFactor(super.damageRoll(owner));
	
	if (owner instanceof Hero) {
		int exStr = ((Hero)owner).STR() - STRReq();
		if (exStr > 0) {
			damage += Random.IntRange( 0, exStr );
		}
	}
	
	if (sniperSpecial){
		switch (augment){
			case NONE:
				damage = Math.round(damage * 0.667f);
				break;
			case SPEED:
				damage = Math.round(damage * 0.5f);
				break;
			case DAMAGE:
				//as distance increases so does damage, capping at 3x:
				//1.20x|1.35x|1.52x|1.71x|1.92x|2.16x|2.43x|2.74x|3.00x
				int distance = Dungeon.level.distance(owner.pos, targetPos) - 1;
				float multiplier = Math.min(2.5f, 1.2f * (float)Math.pow(1.125f, distance));
				damage = Math.round(damage * multiplier);
				break;
		}
	}
	
	return damage;
}
 
Example 14
Source File: NewHallsBossLevel.java    From shattered-pixel-dungeon with GNU General Public License v3.0 4 votes vote down vote up
@Override
protected boolean build() {

	setSize(WIDTH, HEIGHT);

	for (int i = 0; i < 5; i++) {

		int top;
		int bottom;

		if (i == 0 || i == 4){
			top = Random.IntRange(ROOM_TOP-1, ROOM_TOP+3);
			bottom = Random.IntRange(ROOM_BOTTOM+2, ROOM_BOTTOM+6);
		} else if (i == 1 || i == 3){
			top = Random.IntRange(ROOM_TOP-5, ROOM_TOP-1);
			bottom = Random.IntRange(ROOM_BOTTOM+6, ROOM_BOTTOM+10);
		} else {
			top = Random.IntRange(ROOM_TOP-6, ROOM_TOP-3);
			bottom = Random.IntRange(ROOM_BOTTOM+8, ROOM_BOTTOM+12);
		}

		Painter.fill(this, 4 + i * 5, top, 5, bottom - top + 1, Terrain.EMPTY);

		if (i == 2) {
			entrance = (6 + i * 5) + (bottom - 1) * width();
		}

	}

	boolean[] patch = Patch.generate(width, height, 0.20f, 0, true);
	for (int i = 0; i < length(); i++) {
		if (map[i] == Terrain.EMPTY && patch[i]) {
			map[i] = Terrain.STATUE;
		}
	}

	map[entrance] = Terrain.ENTRANCE;

	Painter.fill(this, ROOM_LEFT-1, ROOM_TOP-1, 11, 11, Terrain.EMPTY );

	patch = Patch.generate(width, height, 0.30f, 3, true);
	for (int i = 0; i < length(); i++) {
		if ((map[i] == Terrain.EMPTY || map[i] == Terrain.STATUE) && patch[i]) {
			map[i] = Terrain.WATER;
		}
	}

	for (int i = 0; i < length(); i++) {
		if (map[i] == Terrain.EMPTY && Random.Int(4) == 0) {
			map[i] = Terrain.EMPTY_DECO;
		}
	}

	Painter.fill(this, ROOM_LEFT, ROOM_TOP, 9, 9, Terrain.EMPTY_SP );

	Painter.fill(this, ROOM_LEFT, ROOM_TOP, 9, 2, Terrain.WALL_DECO );
	Painter.fill(this, ROOM_LEFT, ROOM_BOTTOM-1, 2, 2, Terrain.WALL_DECO );
	Painter.fill(this, ROOM_RIGHT-1, ROOM_BOTTOM-1, 2, 2, Terrain.WALL_DECO );

	Painter.fill(this, ROOM_LEFT+3, ROOM_TOP+2, 3, 4, Terrain.EMPTY );

	exit = width/2 + ((ROOM_TOP+1) * width);

	CustomTilemap vis = new CenterPieceVisuals();
	vis.pos(ROOM_LEFT, ROOM_TOP+1);
	customTiles.add(vis);

	vis = new CenterPieceWalls();
	vis.pos(ROOM_LEFT, ROOM_TOP);
	customWalls.add(vis);

	//basic version of building flag maps for the pathfinder test
	for (int i = 0; i < length; i++){
		passable[i]	= ( Terrain.flags[map[i]] & Terrain.PASSABLE) != 0;
	}

	//ensures a path to the exit exists
	return (PathFinder.getStep(entrance, exit, passable) != -1);
}
 
Example 15
Source File: Weapon.java    From YetAnotherPixelDungeon with GNU General Public License v3.0 4 votes vote down vote up
public int damageRoll( Hero hero ) {

		int dmg = Math.max( 0, Random.NormalIntRange( min(), max() ) );


        int exStr = hero.STR() - strShown( true );

        if (exStr > 0) {
            dmg += Random.IntRange( 0, exStr );
        }

        if( enchantment instanceof Heroic) {
            dmg += bonus >= 0
                    ? dmg * (hero.HT - hero.HP) * (bonus + 1) / hero.HT / 8
                    : dmg * (hero.HT - hero.HP) * (bonus) / hero.HT / 6;
        }

        return dmg;

	}
 
Example 16
Source File: Dungeon.java    From remixed-dungeon with GNU General Public License v3.0 4 votes vote down vote up
public static void init() {
    SaveUtils.deleteLevels(heroClass);

    gameId = String.valueOf(SystemTime.now());

    LuaEngine.reset();
    Treasury.reset();

    setChallenges(RemixedDungeon.challenges());

    Scroll.initLabels();
    Potion.initColors();
    Wand.initWoods();
    Ring.initGems();

    Statistics.reset();
    Journal.reset();

    depth = 0;

    potionOfStrength = 0;
    scrollsOfUpgrade = 0;
    arcaneStyli = 0;
    dewVial = true;
    transmutation = Random.IntRange(6, 14);

    chapters = new HashSet<>();

    Ghost.Quest.reset();
    WandMaker.Quest.reset();
    Blacksmith.Quest.reset();
    Imp.Quest.reset();
    ScarecrowNPC.Quest.reset();
    AzuterronNPC.Quest.reset();
    CagedKobold.Quest.reset();
    PlagueDoctorNPC.Quest.reset();

    Room.shuffleTypes();

    hero = new Hero(difficulty);

    Badges.reset();

    heroClass.initHero(hero);

    hero.levelId = DungeonGenerator.getEntryLevel();

    realtime = RemixedDungeon.realtime();
    moveTimeoutIndex = RemixedDungeon.limitTimeoutIndex(RemixedDungeon.moveTimeout());
}
 
Example 17
Source File: Affection.java    From remixed-dungeon with GNU General Public License v3.0 4 votes vote down vote up
@Override
public int defenceProc(Armor armor, Char attacker, Char defender, int damage) {

	int level = (int) GameMath.gate(0, armor.level(), 6);

	if (Dungeon.level.adjacent(attacker.getPos(), defender.getPos()) && Random.Int(level / 2 + 5) >= 4) {

		int duration = Random.IntRange(2, 5);

		Buff.affect(attacker, Charm.class, Charm.durationFactor(attacker) * duration);
		attacker.getSprite().centerEmitter().start(Speck.factory(Speck.HEART), 0.2f, 5);

		Buff.affect(defender, Charm.class, Random.Float(Charm.durationFactor(defender) * duration / 2, duration));
		defender.getSprite().centerEmitter().start(Speck.factory(Speck.HEART), 0.2f, 5);
	}

	return damage;
}
 
Example 18
Source File: DwarvenKing.java    From YetAnotherPixelDungeon with GNU General Public License v3.0 4 votes vote down vote up
private static int spawnDelay( int breaks ) {
    return Random.IntRange( 10, 15 ) - Random.IntRange( breaks * 1, breaks * 2 ); // 10-15 8-12 6-9 4-6
}
 
Example 19
Source File: OldTengu.java    From shattered-pixel-dungeon-gdx with GNU General Public License v3.0 4 votes vote down vote up
private void jump() {
	
	Level level = Dungeon.level;
	
	//incase tengu hasn't had a chance to act yet
	if (fieldOfView == null || fieldOfView.length != Dungeon.level.length()){
		fieldOfView = new boolean[Dungeon.level.length()];
		Dungeon.level.updateFieldOfView( this, fieldOfView );
	}
	
	if (enemy == null) enemy = chooseEnemy();
	if (enemy == null) return;

	int newPos;
	//if we're in phase 1, want to warp around within the room
	if (((OldPrisonBossLevel)Dungeon.level).state() == OldPrisonBossLevel.State.FIGHT_START) {
		
		//place new traps
		int tries;
		for (int i=0; i < 4; i++) {
			int trapPos;
			tries = 15;
			do {
				trapPos = Random.Int( level.length() );
			} while (tries-- > 0 && level.map[trapPos] != Terrain.INACTIVE_TRAP
					&& level.map[trapPos] != Terrain.TRAP);
			
			if (level.map[trapPos] == Terrain.INACTIVE_TRAP) {
				level.setTrap( new GrippingTrap().reveal(), trapPos );
				Level.set( trapPos, Terrain.TRAP );
				ScrollOfMagicMapping.discover( trapPos );
			}
		}
		
		tries = 50;
		do {
			newPos = Random.IntRange(3, 7) + 32*Random.IntRange(26, 30);
		} while ( (level.adjacent(newPos, enemy.pos) || Actor.findChar(newPos) != null)
				&& --tries > 0);
		if (tries <= 0) return;

	//otherwise go wherever, as long as it's a little bit away
	} else {
		do {
			newPos = Random.Int(level.length());
		} while (
				level.solid[newPos] ||
				level.distance(newPos, enemy.pos) < 8 ||
				Actor.findChar(newPos) != null);
	}
	
	if (level.heroFOV[pos]) CellEmitter.get( pos ).burst( Speck.factory( Speck.WOOL ), 6 );

	sprite.move( pos, newPos );
	move( newPos );
	
	if (level.heroFOV[newPos]) CellEmitter.get( newPos ).burst( Speck.factory( Speck.WOOL ), 6 );
	Sample.INSTANCE.play( Assets.SND_PUFF );
	
	spend( 1 / speed() );
}
 
Example 20
Source File: Room.java    From shattered-pixel-dungeon with GNU General Public License v3.0 4 votes vote down vote up
public Point random( int m ) {
	return new Point( Random.IntRange( left + m, right - m ),
			Random.IntRange( top + m, bottom - m ));
}