Java Code Examples for com.watabou.utils.Random#Int
The following examples show how to use
com.watabou.utils.Random#Int .
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: Char.java From unleashed-pixel-dungeon with GNU General Public License v3.0 | 6 votes |
public void move( int step ) { if (Level.adjacent( step, pos ) && buff( Vertigo.class ) != null) { step = pos + Level.NEIGHBOURS8[Random.Int( 8 )]; if (!(Level.passable[step] || Level.avoid[step]) || Actor.findChar( step ) != null) return; } if (Dungeon.level.map[pos] == Terrain.OPEN_DOOR) { Door.leave( pos ); } pos = step; if (flying && Dungeon.level.map[pos] == Terrain.DOOR) { Door.enter( pos ); } if (this != Dungeon.hero) { sprite.visible = Dungeon.visible[pos]; } }
Example 2
Source File: ItemStatusHandler.java From remixed-dungeon with GNU General Public License v3.0 | 6 votes |
private void restore( Bundle bundle, Integer[] allImages ) { ArrayList<Integer> imagesLeft = new ArrayList<>(Arrays.asList(allImages)); for (int i=0; i < items.length; i++) { Class<? extends T> item = items[i]; String itemName = item.toString(); if (bundle.contains( itemName + PFX_IMAGE )) { Integer image = bundle.getInt( itemName + PFX_IMAGE ); images.put( item, image ); imagesLeft.remove( image ); if (bundle.getBoolean( itemName + PFX_KNOWN )) { known.add( item ); } } else { int index = Random.Int( imagesLeft.size() ); images.put( item, imagesLeft.get( index ) ); imagesLeft.remove( index ); } } }
Example 3
Source File: Slow.java From pixel-dungeon with GNU General Public License v3.0 | 6 votes |
@Override public boolean proc( Weapon weapon, Char attacker, Char defender, int damage ) { // lvl 0 - 25% // lvl 1 - 40% // lvl 2 - 50% int level = Math.max( 0, weapon.effectiveLevel() ); if (Random.Int( level + 4 ) >= 3) { Buff.prolong( defender, com.watabou.pixeldungeon.actors.buffs.Slow.class, Random.Float( 1, 1.5f + level ) ); return true; } else { return false; } }
Example 4
Source File: WandOfWarding.java From shattered-pixel-dungeon with GNU General Public License v3.0 | 6 votes |
@Override public void onHit(MagesStaff staff, Char attacker, Char defender, int damage) { int level = Math.max( 0, staff.buffedLvl() ); // lvl 0 - 20% // lvl 1 - 33% // lvl 2 - 43% if (Random.Int( level + 5 ) >= 4) { for (Char ch : Actor.chars()){ if (ch instanceof Ward){ ((Ward) ch).wandHeal(staff.buffedLvl()); ch.sprite.emitter().burst(MagicMissile.WardParticle.UP, ((Ward) ch).tier); } } } }
Example 5
Source File: PlatformRoom.java From shattered-pixel-dungeon with GNU General Public License v3.0 | 5 votes |
private void splitPlatforms( Rect curPlatform, ArrayList<Rect> allPlatforms ){ int curArea = (curPlatform.width()+1) * (curPlatform.height()+1); //chance to split scales between 0% and 100% between areas of 25 and 36 if (Random.Float() < (curArea-25)/11f){ if (curPlatform.width() > curPlatform.height() || (curPlatform.width() == curPlatform.height() && Random.Int(2) == 0)){ //split the platform int splitX = Random.IntRange( curPlatform.left+2, curPlatform.right-2); splitPlatforms( new Rect( curPlatform.left, curPlatform.top, splitX-1, curPlatform.bottom) , allPlatforms); splitPlatforms( new Rect( splitX+1, curPlatform.top, curPlatform.right, curPlatform.bottom) , allPlatforms); //add a bridge between int bridgeY = Random.NormalIntRange(curPlatform.top, curPlatform.bottom); allPlatforms.add( new Rect( splitX - 1, bridgeY, splitX + 1, bridgeY)); } else { //split the platform int splitY = Random.IntRange( curPlatform.top+2, curPlatform.bottom-2); splitPlatforms( new Rect( curPlatform.left, curPlatform.top, curPlatform.right, splitY-1) , allPlatforms); splitPlatforms( new Rect( curPlatform.left, splitY+1, curPlatform.right, curPlatform.bottom) , allPlatforms); //add a bridge between int bridgeX = Random.NormalIntRange(curPlatform.left, curPlatform.right); allPlatforms.add( new Rect( bridgeX, splitY-1, bridgeX, splitY+1)); } } else { allPlatforms.add(curPlatform); } }
Example 6
Source File: ScrollOfPolymorph.java From shattered-pixel-dungeon with GNU General Public License v3.0 | 5 votes |
@Override public void doRead() { new Flare( 5, 32 ).color( 0xFFFFFF, true ).show( curUser.sprite, 2f ); Sample.INSTANCE.play( Assets.Sounds.READ ); Invisibility.dispel(); for (Mob mob : Dungeon.level.mobs.toArray( new Mob[0] )) { if (mob.alignment != Char.Alignment.ALLY && Dungeon.level.heroFOV[mob.pos]) { if (!mob.properties().contains(Char.Property.BOSS) && !mob.properties().contains(Char.Property.MINIBOSS)){ Sheep sheep = new Sheep(); sheep.lifespan = 10; sheep.pos = mob.pos; //awards half exp for each sheep-ified mob //50% chance to round up, 50% to round down if (mob.EXP % 2 == 1) mob.EXP += Random.Int(2); mob.EXP /= 2; mob.destroy(); mob.sprite.killAndErase(); Dungeon.level.mobs.remove(mob); TargetHealthIndicator.instance.target(null); GameScene.add(sheep); CellEmitter.get(sheep.pos).burst(Speck.factory(Speck.WOOL), 4); } } } setKnown(); readAnimation(); }
Example 7
Source File: MysteryMeat.java From remixed-dungeon with GNU General Public License v3.0 | 5 votes |
@Override public void execute(@NotNull Char chr, @NotNull String action ) { super.execute(chr, action ); if (action.equals( CommonActions.AC_EAT )) { switch (Random.Int( 5 )) { case 0: GLog.w(Game.getVar(R.string.MysteryMeat_Info1)); Buff.affect(chr, Burning.class ).reignite(chr); break; case 1: GLog.w(Game.getVar(R.string.MysteryMeat_Info2)); Buff.prolong(chr, Roots.class, Paralysis.duration(chr) ); break; case 2: GLog.w(Game.getVar(R.string.MysteryMeat_Info3)); Buff.affect(chr, Poison.class,Poison.durationFactor(chr) * chr.ht() / 5 ); break; case 3: GLog.w(Game.getVar(R.string.MysteryMeat_Info4)); Buff.prolong(chr, Slow.class, Slow.duration(chr) ); break; } } }
Example 8
Source File: CavesBossLevel.java From pixel-dungeon with GNU General Public License v3.0 | 5 votes |
@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 9
Source File: Monk.java From remixed-dungeon with GNU General Public License v3.0 | 5 votes |
@Override public int attackProc(@NotNull Char enemy, int damage ) { if (Random.Int( 6 ) == 0) { EquipableItem weapon = enemy.getBelongings().weapon; if (!(weapon instanceof Knuckles) && !weapon.isCursed() && enemy.getBelongings().drop(weapon)) { GLog.w( Game.getVar(R.string.Monk_Disarm), getName(), weapon.name() ); } } return damage; }
Example 10
Source File: SpiderGuard.java From remixed-dungeon with GNU General Public License v3.0 | 5 votes |
@Override public int attackProc(@NotNull Char enemy, int damage ) { if (Random.Int( 10 ) == 0) { Buff.prolong( enemy, Paralysis.class, 3); } return damage; }
Example 11
Source File: Frozen.java From YetAnotherPixelDungeon with GNU General Public License v3.0 | 5 votes |
@Override public boolean act() { if( Level.water[ target.pos ] && !target.flying && Random.Int( 2 ) == 0 ) { duration++; } return super.act(); }
Example 12
Source File: Skeleton.java From YetAnotherPixelDungeon with GNU General Public License v3.0 | 5 votes |
@Override public int attackProc( Char enemy, int damage, boolean blocked ) { if( !blocked && Random.Int( 10 ) < tier ) { BuffActive.addFromDamage( enemy, Withered.class, damage * 2 ); } return damage; }
Example 13
Source File: WandOfBlastWave.java From YetAnotherPixelDungeon with GNU General Public License v3.0 | 4 votes |
private void rocksFall( int cell, int damage ) { int size = 2; Sample.INSTANCE.play( Assets.SND_ROCKS ); Camera.main.shake(3, 0.07f * (3 + size)); PathFinder.buildDistanceMap( cell, BArray.not( Level.solid, null ), size ); Ballistica.distance = Math.min( Ballistica.distance, 2 ); for (int i=0; i < Level.LENGTH; i++) { int d = PathFinder.distance[i]; if ( d < Integer.MAX_VALUE ) { boolean wall = false; for(int n : Level.NEIGHBOURS4) { if( Level.solid[ i + n ] ) { wall = true; } } if( wall || Random.Int( d * 2 + 1 ) == 0) { Char ch = Actor.findChar(i); if (ch != null ) { int dmg = Char.absorb( ch == curUser ? damage / 2 : damage , ch.armorClass() ); ch.damage(dmg, curUser, Element.PHYSICAL); if ( ch.isAlive() ) { BuffActive.addFromDamage( ch, Vertigo.class, dmg ); } } Heap heap = Dungeon.level.heaps.get( i ); if (heap != null) { heap.shatter(); } Dungeon.level.press(i, null); CellEmitter.get(i).start(Speck.factory(Speck.ROCK), 0.1f, 3 + (size - d)); } } } for (Mob mob : Dungeon.level.mobs) { if (Level.distance( cell, mob.pos ) <= 6 ) { mob.beckon( cell ); } } }
Example 14
Source File: CityBossLevel.java From shattered-pixel-dungeon-gdx with GNU General Public License v3.0 | 4 votes |
@Override protected boolean build() { setSize(32, 32); Painter.fill( this, LEFT, TOP, HALL_WIDTH, HALL_HEIGHT, Terrain.EMPTY ); Painter.fill( this, CENTER, TOP, 1, HALL_HEIGHT, Terrain.EMPTY_SP ); int y = TOP + 1; while (y < TOP + HALL_HEIGHT) { map[y * width() + CENTER - 2] = Terrain.STATUE_SP; map[y * width() + CENTER + 2] = Terrain.STATUE_SP; y += 2; } int left = pedestal( true ); int right = pedestal( false ); map[left] = map[right] = Terrain.PEDESTAL; for (int i=left+1; i < right; i++) { map[i] = Terrain.EMPTY_SP; } exit = (TOP - 1) * width() + CENTER; map[exit] = Terrain.LOCKED_EXIT; arenaDoor = (TOP + HALL_HEIGHT) * width() + CENTER; map[arenaDoor] = Terrain.DOOR; Painter.fill( this, LEFT, TOP + HALL_HEIGHT + 1, HALL_WIDTH, CHAMBER_HEIGHT, Terrain.EMPTY ); Painter.fill( this, LEFT, TOP + HALL_HEIGHT + 1, HALL_WIDTH, 1, Terrain.BOOKSHELF); map[arenaDoor + width()] = Terrain.EMPTY; Painter.fill( this, LEFT, TOP + HALL_HEIGHT + 1, 1, CHAMBER_HEIGHT, Terrain.BOOKSHELF ); Painter.fill( this, LEFT + HALL_WIDTH - 1, TOP + HALL_HEIGHT + 1, 1, CHAMBER_HEIGHT, Terrain.BOOKSHELF ); entrance = (TOP + HALL_HEIGHT + 3 + Random.Int( CHAMBER_HEIGHT - 2 )) * width() + LEFT + (/*1 +*/ Random.Int( HALL_WIDTH-2 )); map[entrance] = Terrain.ENTRANCE; for (int i=0; i < length() - width(); i++) { if (map[i] == Terrain.EMPTY && Random.Int( 10 ) == 0) { map[i] = Terrain.EMPTY_DECO; } else if (map[i] == Terrain.WALL && DungeonTileSheet.floorTile(map[i + width()]) && Random.Int( 21 - Dungeon.depth ) == 0) { map[i] = Terrain.WALL_DECO; } } return true; }
Example 15
Source File: WellWater.java From remixed-dungeon with GNU General Public License v3.0 | 4 votes |
protected boolean affect() { Heap heap; if (pos == Dungeon.hero.getPos() && affectHero( Dungeon.hero )) { volume = off[pos] = cur[pos] = 0; return true; } else if ((heap = Dungeon.level.getHeap( pos )) != null) { Item oldItem = heap.peek(); Item newItem = affectItem( oldItem ); if (newItem != null) { if (newItem != oldItem) { if (oldItem.quantity() > 1) { oldItem.quantity( oldItem.quantity() - 1 ); heap.drop( newItem ); } else { heap.replace( oldItem, newItem ); } } heap.sprite.link(); volume = off[pos] = cur[pos] = 0; return true; } else { int newPlace; do { newPlace = pos + Level.NEIGHBOURS8[Random.Int( 8 )]; } while (!Dungeon.level.passable[newPlace] && !Dungeon.level.avoid[newPlace]); Dungeon.level.animatedDrop( heap.pickUp(), newPlace ); return false; } } else { return false; } }
Example 16
Source File: Burning.java From shattered-pixel-dungeon-gdx with GNU General Public License v3.0 | 4 votes |
@Override public boolean act() { if (target.isAlive() && !target.isImmune(getClass())) { int damage = Random.NormalIntRange( 1, 3 + Dungeon.depth/4 ); Buff.detach( target, Chill.class); if (target instanceof Hero) { Hero hero = (Hero)target; hero.damage( damage, this ); burnIncrement++; //at 4+ turns, there is a (turns-3)/3 chance an item burns if (Random.Int(3) < (burnIncrement - 3)){ burnIncrement = 0; ArrayList<Item> burnable = new ArrayList<>(); //does not reach inside of containers for (Item i : hero.belongings.backpack.items){ if ((i instanceof Scroll && !(i instanceof ScrollOfUpgrade)) || i instanceof MysteryMeat){ burnable.add(i); } } if (!burnable.isEmpty()){ Item toBurn = Random.element(burnable).detach(hero.belongings.backpack); GLog.w( Messages.get(this, "burnsup", Messages.capitalize(toBurn.toString())) ); if (toBurn instanceof MysteryMeat){ ChargrilledMeat steak = new ChargrilledMeat(); if (!steak.collect( hero.belongings.backpack )) { Dungeon.level.drop( steak, hero.pos ).sprite.drop(); } } Heap.burnFX( hero.pos ); } } } else { target.damage( damage, this ); } if (target instanceof Thief) { Item item = ((Thief) target).item; if (item instanceof Scroll && !(item instanceof ScrollOfUpgrade)) { target.sprite.emitter().burst( ElmoParticle.FACTORY, 6 ); ((Thief)target).item = null; } else if (item instanceof MysteryMeat) { target.sprite.emitter().burst( ElmoParticle.FACTORY, 6 ); ((Thief)target).item = new ChargrilledMeat(); } } } else { detach(); } if (Dungeon.level.flamable[target.pos] && Blob.volumeAt(target.pos, Fire.class) == 0) { GameScene.add( Blob.seed( target.pos, 4, Fire.class ) ); } spend( TICK ); left -= TICK; if (left <= 0 || (Dungeon.level.water[target.pos] && !target.flying)) { detach(); } return true; }
Example 17
Source File: Friendly.java From shattered-pixel-dungeon with GNU General Public License v3.0 | 4 votes |
@Override public int proc(Weapon weapon, Char attacker, Char defender, int damage ) { if (Random.Int(10) == 0){ Buff.affect( attacker, Charm.class, Charm.DURATION ).object = defender.id(); attacker.sprite.centerEmitter().start( Speck.factory( Speck.HEART ), 0.2f, 5 ); //5 turns will be reduced by the attack, so effectively lasts for Charm.DURATION-5 turns Buff.affect( defender, Charm.class, Charm.DURATION ).object = attacker.id(); defender.sprite.centerEmitter().start( Speck.factory( Speck.HEART ), 0.2f, 5 ); } return damage; }
Example 18
Source File: Tamahawk.java From unleashed-pixel-dungeon with GNU General Public License v3.0 | 4 votes |
@Override public Item random() { quantity = Random.Int( 5, 12 ); return this; }
Example 19
Source File: StandardPainter.java From remixed-dungeon with GNU General Public License v3.0 | 4 votes |
public static void paint( Level level, Room room ) { fill( level, room, Terrain.WALL ); for (Room.Door door : room.connected.values()) { door.set( Room.Door.Type.REGULAR ); } if (!level.isBossLevel() && Random.Int( 5 ) == 0) { switch (Random.Int( 6 )) { case 0: if (level.getFeeling() != Level.Feeling.GRASS) { if (Math.min( room.width(), room.height() ) >= 4 && Math.max( room.width(), room.height() ) >= 6) { paintGraveyard( level, room ); return; } break; } else { // Burned room } case 1: if (Dungeon.depth > 1) { paintBurned( level, room ); return; } break; case 2: if (Math.max( room.width(), room.height() ) >= 4) { paintStriped( level, room ); return; } break; case 3: if (room.width() >= 6 && room.height() >= 6) { paintStudy( level, room ); return; } break; case 4: if (level.getFeeling() != Level.Feeling.WATER) { if (room.connected.size() == 2 && room.width() >= 4 && room.height() >= 4) { paintBridge( level, room ); return; } break; } else { // Fissure } case 5: if (!level.isBossLevel() && Math.min( room.width(), room.height() ) >= 5) { paintFissure( level, room ); return; } break; } } fill( level, room, 1, Terrain.EMPTY ); }
Example 20
Source File: Armor.java From unleashed-pixel-dungeon with GNU General Public License v3.0 | 4 votes |
@Override public Item random() { int upgrade_odds; switch (Dungeon.difficultyLevel) { case Dungeon.DIFF_TUTOR: case Dungeon.DIFF_EASY: upgrade_odds = 4; break; case Dungeon.DIFF_NORM: upgrade_odds = 3; break; case Dungeon.DIFF_HARD: upgrade_odds = 2; break; case Dungeon.DIFF_NTMARE: upgrade_odds = 2; break; default: upgrade_odds = 3; break; } if (Random.Float() < 0.4) { int n = 1; if (Random.Int( 3 ) == 0) { n++; if (Random.Int( 5 ) == 0) { n++; } } if (Random.Int( 6 ) <= upgrade_odds) { upgrade( n ); } else { degrade( n ); cursed = true; } } if (Random.Int( 10 ) == 0) { inscribe(); } return this; }