com.watabou.utils.Callback Java Examples

The following examples show how to use com.watabou.utils.Callback. 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: DriedRose.java    From shattered-pixel-dungeon-gdx with GNU General Public License v3.0 6 votes vote down vote up
@Override
public boolean interact() {
	updateRose();
	if (rose != null && !rose.talkedTo){
		rose.talkedTo = true;
		Game.runOnRenderThread(new Callback() {
			@Override
			public void call() {
				GameScene.show(new WndQuest(GhostHero.this, Messages.get(GhostHero.this, "introduce") ));
			}
		});
		return false;
	} else {
		return super.interact();
	}
}
 
Example #2
Source File: WandOfLightning.java    From remixed-dungeon with GNU General Public License v3.0 6 votes vote down vote up
@Override
protected void fx( int cell, Callback callback ) {
	
	nPoints = 0;
	points[nPoints++] = getOwner().getPos();
	
	Char ch = Actor.findChar( cell );
	if (ch != null) {
		
		affected.clear();
		int lvl = effectiveLevel();
		hit( ch, Random.Int( 5 + lvl / 2, 10 + lvl ) );

	} else {
		
		points[nPoints++] = cell;
		CellEmitter.center( cell ).burst( SparkParticle.FACTORY, 3 );
		
	}
	getOwner().getSprite().getParent().add( new Lightning( points, nPoints, callback ) );
}
 
Example #3
Source File: FistSprite.java    From shattered-pixel-dungeon with GNU General Public License v3.0 6 votes vote down vote up
public void zap( int cell ) {

		turnTo( ch.pos , cell );
		play( zap );

		MagicMissile.boltFromChar( parent,
				boltType,
				this,
				cell,
				new Callback() {
					@Override
					public void call() {
						//pre-0.8.0 saves
						if (ch instanceof Yog.BurningFist){
							((Yog.BurningFist)ch).onZapComplete();
						} else {
							((YogFist)ch).onZapComplete();
						}
					}
				} );
		Sample.INSTANCE.play( Assets.Sounds.ZAP );
	}
 
Example #4
Source File: TenguSprite.java    From unleashed-pixel-dungeon with GNU General Public License v3.0 6 votes vote down vote up
@Override
public void attack( int cell ) {
	if (!Level.adjacent( cell, ch.pos )) {
		
		((MissileSprite)parent.recycle( MissileSprite.class )).
			reset( ch.pos, cell, new Shuriken(), new Callback() {
				@Override
				public void call() {
					ch.onAttackComplete();
				}
			} );
		
		play( cast );
		turnTo( ch.pos , cell );
		
	} else {
		
		super.attack( cell );
		
	}
}
 
Example #5
Source File: Succubus.java    From YetAnotherPixelDungeon with GNU General Public License v3.0 6 votes vote down vote up
@Override
protected void onRangedAttack( int cell ) {

    MagicMissile.purpleLight(sprite.parent, pos, cell,
            new Callback() {
                @Override
                public void call() {
                    onCastComplete();
                }
            });

    Sample.INSTANCE.play(Assets.SND_ZAP);

    onCastComplete();

    super.onRangedAttack( cell );
}
 
Example #6
Source File: SpinnerSprite.java    From shattered-pixel-dungeon with GNU General Public License v3.0 6 votes vote down vote up
public void zap( int cell ) {
	
	turnTo( ch.pos , cell );
	play( zap );
	
	MagicMissile.boltFromChar( parent,
			MagicMissile.MAGIC_MISSILE,
			this,
			cell,
			new Callback() {
				@Override
				public void call() {
					((Spinner)ch).shootWeb();
				}
			} );
	Sample.INSTANCE.play( Assets.Sounds.MISS );
}
 
Example #7
Source File: WildEnergy.java    From shattered-pixel-dungeon-gdx with GNU General Public License v3.0 6 votes vote down vote up
@Override
protected void affectTarget(Ballistica bolt, final Hero hero) {
	CursedWand.cursedZap(this, hero, bolt, new Callback() {
		@Override
		public void call() {
			ScrollOfRecharging.charge(hero);

			hero.belongings.charge(1f);
			for (int i = 0; i < 4; i++){
				if (hero.belongings.misc1 instanceof Artifact) ((Artifact) hero.belongings.misc1).charge(hero);
				if (hero.belongings.misc2 instanceof Artifact) ((Artifact) hero.belongings.misc2).charge(hero);
			}

			Buff.affect(hero, Recharging.class, 8f);
			Buff.affect(hero, ArtifactRecharge.class).prolong( 8 );
			
			detach( curUser.belongings.backpack );
			updateQuickslot();
			curUser.spendAndNext( 1f );
		}
	});
}
 
Example #8
Source File: MagicMissile.java    From remixed-dungeon with GNU General Public License v3.0 6 votes vote down vote up
public void reset( int from, int to, @Nullable Callback callback ) {
	this.callback = callback;
	
	revive();
	
	PointF pf = DungeonTilemap.tileCenterToWorld( from );
	PointF pt = DungeonTilemap.tileCenterToWorld( to );
	
	x = pf.x;
	y = pf.y;
	width = 0;
	height = 0;
	
	PointF d = PointF.diff( pt, pf ); 
	PointF speed = new PointF( d ).normalize().scale( SPEED );
	sx = speed.x;
	sy = speed.y;
	time = d.length() / SPEED;
}
 
Example #9
Source File: WandOfCorrosion.java    From shattered-pixel-dungeon-gdx with GNU General Public License v3.0 5 votes vote down vote up
@Override
protected void fx(Ballistica bolt, Callback callback) {
	MagicMissile.boltFromChar(
			curUser.sprite.parent,
			MagicMissile.CORROSION,
			curUser.sprite,
			bolt.collisionPos,
			callback);
	Sample.INSTANCE.play(Assets.SND_ZAP);
}
 
Example #10
Source File: HuntressArmor.java    From shattered-pixel-dungeon-gdx with GNU General Public License v3.0 5 votes vote down vote up
@Override
public void doSpecial() {
	
	Item proto = new Shuriken();
	
	for (Mob mob : Dungeon.level.mobs) {
		if (Dungeon.level.distance(curUser.pos, mob.pos) <= 12
			&& Dungeon.level.heroFOV[mob.pos]
			&& mob.alignment != Char.Alignment.ALLY) {
			
			Callback callback = new Callback() {
				@Override
				public void call() {
					curUser.attack( targets.get( this ) );
					targets.remove( this );
					if (targets.isEmpty()) {
						curUser.spendAndNext( curUser.attackDelay() );
					}
				}
			};
			
			((MissileSprite)curUser.sprite.parent.recycle( MissileSprite.class )).
				reset( curUser.pos, mob.pos, proto, callback );
			
			targets.put( callback, mob );
		}
	}
	
	if (targets.size() == 0) {
		GLog.w( Messages.get(this, "no_enemies") );
		return;
	}
	
	curUser.HP -= (curUser.HP / 3);
	
	curUser.sprite.zap( curUser.pos );
	curUser.busy();
}
 
Example #11
Source File: Thief.java    From YetAnotherPixelDungeon with GNU General Public License v3.0 5 votes vote down vote up
@Override
protected void onRangedAttack( int cell ) {
    ((MissileSprite)sprite.parent.recycle( MissileSprite.class )).
            reset(pos, cell, new Knives(), new Callback() {
                @Override
                public void call() {
                    onAttackComplete();
                }
            });

    super.onRangedAttack( cell );
}
 
Example #12
Source File: WandOfLivingEarth.java    From shattered-pixel-dungeon with GNU General Public License v3.0 5 votes vote down vote up
@Override
protected void fx(Ballistica bolt, Callback callback) {
	MagicMissile.boltFromChar(curUser.sprite.parent,
			MagicMissile.EARTH,
			curUser.sprite,
			bolt.collisionPos,
			callback);
	Sample.INSTANCE.play(Assets.Sounds.ZAP);
}
 
Example #13
Source File: MissileSprite.java    From unleashed-pixel-dungeon with GNU General Public License v3.0 5 votes vote down vote up
public void reset( int from, int to, Item item, Callback listener ) {
	if (item == null) {
		reset( from, to, 0, null, listener );
	} else {
		reset( from, to, item.image(), item.glowing(), listener );
	}
}
 
Example #14
Source File: WandOfDisintegration.java    From shattered-pixel-dungeon with GNU General Public License v3.0 5 votes vote down vote up
@Override
protected void fx( Ballistica beam, Callback callback ) {
	
	int cell = beam.path.get(Math.min(beam.dist, distance()));
	curUser.sprite.parent.add(new Beam.DeathRay(curUser.sprite.center(), DungeonTilemap.raisedTileCenterToWorld( cell )));
	callback.call();
}
 
Example #15
Source File: MissileSprite.java    From shattered-pixel-dungeon-gdx with GNU General Public License v3.0 5 votes vote down vote up
public void reset( PointF from, PointF to, Item item, Callback listener) {
	revive();

	if (item == null)   view(0, null);
	else                view( item );

	setup( from,
			to,
			item,
			listener );
}
 
Example #16
Source File: TargetedSpell.java    From shattered-pixel-dungeon-gdx with GNU General Public License v3.0 5 votes vote down vote up
@Override
public void onSelect( Integer target ) {
	
	if (target != null) {
		
		//FIXME this safety check shouldn't be necessary
		//it would be better to eliminate the curItem static variable.
		final TargetedSpell curSpell;
		if (curItem instanceof TargetedSpell) {
			curSpell = (TargetedSpell)curItem;
		} else {
			return;
		}
		
		final Ballistica shot = new Ballistica( curUser.pos, target, curSpell.collisionProperties);
		int cell = shot.collisionPos;
		
		curUser.sprite.zap(cell);
		
		//attempts to target the cell aimed at if something is there, otherwise targets the collision pos.
		if (Actor.findChar(target) != null)
			QuickSlotButton.target(Actor.findChar(target));
		else
			QuickSlotButton.target(Actor.findChar(cell));
		
		curUser.busy();
		Invisibility.dispel();
		
		curSpell.fx(shot, new Callback() {
			public void call() {
				curSpell.affectTarget(shot, curUser);
				curSpell.detach( curUser.belongings.backpack );
				curSpell.updateQuickslot();
				curUser.spendAndNext( 1f );
			}
		});
		
	}
		
}
 
Example #17
Source File: CharSprite.java    From remixed-dungeon with GNU General Public License v3.0 5 votes vote down vote up
public void attack(int cell, Callback callback) {
    ch.ifPresent(chr -> {
        animCallback = callback;
        turnTo(chr.getPos(), cell);
        play(attack);
    });
}
 
Example #18
Source File: Chains.java    From shattered-pixel-dungeon with GNU General Public License v3.0 5 votes vote down vote up
public Chains(PointF from, PointF to, Callback callback){
	super();

	this.callback = callback;

	this.from = from;
	this.to = to;

	float dx = to.x - from.x;
	float dy = to.y - from.y;
	distance = (float)Math.hypot(dx, dy);


	duration = distance/300f + 0.1f;

	rotation = (float)(Math.atan2( dy, dx ) * A) + 90f;

	numChains = Math.round(distance/6f)+1;

	chains = new Image[numChains];
	for (int i = 0; i < chains.length; i++){
		chains[i] = new Image(Effects.get(Effects.Type.CHAIN));
		chains[i].angle = rotation;
		chains[i].origin.set( chains[i].width()/ 2, chains[i].height() );
		add(chains[i]);
	}
}
 
Example #19
Source File: WarriorArmor.java    From pixel-dungeon with GNU General Public License v3.0 5 votes vote down vote up
@Override
public void onSelect( Integer target ) {
	if (target != null && target != curUser.pos) {
		
		int cell = Ballistica.cast( curUser.pos, target, false, true );
		if (Actor.findChar( cell ) != null && cell != curUser.pos) {
			cell = Ballistica.trace[Ballistica.distance - 2];
		}
		
		curUser.HP -= (curUser.HP / 3);
		if (curUser.subClass == HeroSubClass.BERSERKER && curUser.HP <= curUser.HT * Fury.LEVEL) {
			Buff.affect( curUser, Fury.class );
		}
		
		Invisibility.dispel();
		
		final int dest = cell;
		curUser.busy();
		curUser.sprite.jump( curUser.pos, cell, new Callback() {
			@Override
			public void call() {
				curUser.move( dest );
				Dungeon.level.press( dest, curUser );
				Dungeon.observe();
				
				for (int i=0; i < Level.NEIGHBOURS8.length; i++) {
					Char mob = Actor.findChar( curUser.pos + Level.NEIGHBOURS8[i] );
					if (mob != null && mob != curUser) {
						Buff.prolong( mob, Paralysis.class, SHOCK_TIME );
					}
				}
				
				CellEmitter.center( dest ).burst( Speck.factory( Speck.DUST ), 10 );
				Camera.main.shake( 2, 0.5f );
				
				curUser.spendAndNext( LEAP_TIME );
			}
		} );
	}
}
 
Example #20
Source File: HeroSprite.java    From shattered-pixel-dungeon-gdx with GNU General Public License v3.0 5 votes vote down vote up
public void read() {
	animCallback = new Callback() {
		@Override
		public void call() {
			idle();
			ch.onOperateComplete();
		}
	};
	play( read );
}
 
Example #21
Source File: WandOfWarding.java    From shattered-pixel-dungeon-gdx with GNU General Public License v3.0 5 votes vote down vote up
@Override
protected void fx(Ballistica bolt, Callback callback) {
	MagicMissile m = MagicMissile.boltFromChar(curUser.sprite.parent,
			MagicMissile.WARD,
			curUser.sprite,
			bolt.collisionPos,
			callback);
	
	if (bolt.dist > 10){
		m.setSpeed(bolt.dist*20);
	}
	Sample.INSTANCE.play(Assets.SND_ZAP);
}
 
Example #22
Source File: HuntressArmor.java    From remixed-dungeon with GNU General Public License v3.0 5 votes vote down vote up
@Override
public void doSpecial(@NotNull Char user) {

	Item proto = new Shuriken();
	
	for (Mob mob : Dungeon.level.getCopyOfMobsArray()) {
		if (Dungeon.level.fieldOfView[mob.getPos()]) {
			
			Callback callback = new Callback() {	
				@Override
				public void call() {
					user.attack( targets.get( this ) );
					targets.remove( this );
					if (targets.isEmpty()) {
						user.spendAndNext( user.attackDelay() );
					}
				}
			};
			
			((MissileSprite) user.getSprite().getParent().recycle( MissileSprite.class )).
				reset( user.getPos(), mob.getPos(), proto, callback );
			
			targets.put( callback, mob );
		}
	}
	
	if (targets.size() == 0) {
		GLog.w( Game.getVar(R.string.HuntressArmor_NoEnemies) );
		return;
	}

	user.getSprite().zap( user.getPos() );
	user.busy();
}
 
Example #23
Source File: Game.java    From shattered-pixel-dungeon-gdx with GNU General Public License v3.0 5 votes vote down vote up
public static void runOnRenderThread(final Callback c){
	Gdx.app.postRunnable(new Runnable() {
		@Override
		public void run() {
			c.call();
		}
	});
}
 
Example #24
Source File: MissileSprite.java    From pixel-dungeon with GNU General Public License v3.0 5 votes vote down vote up
public void reset( int from, int to, Item item, Callback listener ) {
	if (item == null) {
		reset( from, to, 0, null, listener );
	} else {
		reset( from, to, item.image(), item.glowing(), listener );
	}
}
 
Example #25
Source File: NewTengu.java    From shattered-pixel-dungeon with GNU General Public License v3.0 5 votes vote down vote up
public static boolean throwBomb(final Char thrower, final Char target){
	
	int targetCell = -1;
	
	//Targets closest cell which is adjacent to target, and at least 3 tiles away
	for (int i : PathFinder.NEIGHBOURS8){
		int cell = target.pos + i;
		if (Dungeon.level.distance(cell, thrower.pos) >= 3 && !Dungeon.level.solid[cell]){
			if (targetCell == -1 ||
					Dungeon.level.trueDistance(cell, thrower.pos) < Dungeon.level.trueDistance(targetCell, thrower.pos)){
				targetCell = cell;
			}
		}
	}
	
	if (targetCell == -1){
		return false;
	}
	
	final int finalTargetCell = targetCell;
	throwingChar = thrower;
	final BombAbility.BombItem item = new BombAbility.BombItem();
	thrower.sprite.zap(finalTargetCell);
	((MissileSprite) thrower.sprite.parent.recycle(MissileSprite.class)).
			reset(thrower.sprite,
					finalTargetCell,
					item,
					new Callback() {
						@Override
						public void call() {
							item.onThrow(finalTargetCell);
							thrower.next();
						}
					});
	return true;
}
 
Example #26
Source File: WandOfBlastWave.java    From shattered-pixel-dungeon-gdx with GNU General Public License v3.0 5 votes vote down vote up
@Override
protected void fx(Ballistica bolt, Callback callback) {
	MagicMissile.boltFromChar( curUser.sprite.parent,
			MagicMissile.FORCE,
			curUser.sprite,
			bolt.collisionPos,
			callback);
	Sample.INSTANCE.play(Assets.SND_ZAP);
}
 
Example #27
Source File: Shopkeeper.java    From shattered-pixel-dungeon-gdx with GNU General Public License v3.0 5 votes vote down vote up
@Override
public boolean interact() {
	Game.runOnRenderThread(new Callback() {
		@Override
		public void call() {
			sell();
		}
	});
	return false;
}
 
Example #28
Source File: HuntressArmor.java    From pixel-dungeon with GNU General Public License v3.0 5 votes vote down vote up
@Override
public void doSpecial() {
	
	Item proto = new Shuriken();
	
	for (Mob mob : Dungeon.level.mobs) {
		if (Level.fieldOfView[mob.pos]) {
			
			Callback callback = new Callback() {	
				@Override
				public void call() {
					curUser.attack( targets.get( this ) );
					targets.remove( this );
					if (targets.isEmpty()) {
						curUser.spendAndNext( curUser.attackDelay() );
					}
				}
			};
			
			((MissileSprite)curUser.sprite.parent.recycle( MissileSprite.class )).
				reset( curUser.pos, mob.pos, proto, callback );
			
			targets.put( callback, mob );
		}
	}
	
	if (targets.size() == 0) {
		GLog.w( TXT_NO_ENEMIES );
		return;
	}
	
	curUser.HP -= (curUser.HP / 3);
	
	curUser.sprite.zap( curUser.pos );
	curUser.busy();
}
 
Example #29
Source File: Wand.java    From shattered-pixel-dungeon with GNU General Public License v3.0 5 votes vote down vote up
protected void fx( Ballistica bolt, Callback callback ) {
	MagicMissile.boltFromChar( curUser.sprite.parent,
			MagicMissile.MAGIC_MISSILE,
			curUser.sprite,
			bolt.collisionPos,
			callback);
	Sample.INSTANCE.play( Assets.Sounds.ZAP );
}
 
Example #30
Source File: CharSprite.java    From shattered-pixel-dungeon-gdx with GNU General Public License v3.0 5 votes vote down vote up
public void jump( int from, int to, Callback callback ) {
	jumpCallback = callback;

	int distance = Dungeon.level.distance( from, to );
	jumpTweener = new JumpTweener( this, worldToCamera( to ), distance * 4, distance * 0.1f );
	jumpTweener.listener = this;
	parent.add( jumpTweener );

	turnTo( from, to );
}