use of com.shatteredpixel.shatteredpixeldungeon.items.weapon.missiles.darts.PoisonDart in project shattered-pixel-dungeon-gdx by 00-Evan.
the class PoisonDartTrap method activate.
@Override
public void activate() {
Char target = Actor.findChar(pos);
// find the closest char that can be aimed at
if (target == null) {
for (Char ch : Actor.chars()) {
Ballistica bolt = new Ballistica(pos, ch.pos, Ballistica.PROJECTILE);
if (bolt.collisionPos == ch.pos && (target == null || Dungeon.level.trueDistance(pos, ch.pos) < Dungeon.level.trueDistance(pos, target.pos))) {
target = ch;
}
}
}
if (target != null) {
final Char finalTarget = target;
final PoisonDartTrap trap = this;
if (Dungeon.level.heroFOV[pos] || Dungeon.level.heroFOV[target.pos]) {
Actor.add(new Actor() {
{
// it's a visual effect, gets priority no matter what
actPriority = VFX_PRIO;
}
@Override
protected boolean act() {
final Actor toRemove = this;
((MissileSprite) ShatteredPixelDungeon.scene().recycle(MissileSprite.class)).reset(pos, finalTarget.sprite, new PoisonDart(), new Callback() {
@Override
public void call() {
int dmg = Random.NormalIntRange(1, 4) - finalTarget.drRoll();
finalTarget.damage(dmg, trap);
if (finalTarget == Dungeon.hero && !finalTarget.isAlive()) {
Dungeon.fail(trap.getClass());
}
Buff.affect(finalTarget, Poison.class).set(4 + Dungeon.depth);
Sample.INSTANCE.play(Assets.SND_HIT, 1, 1, Random.Float(0.8f, 1.25f));
finalTarget.sprite.bloodBurstA(finalTarget.sprite.center(), dmg);
finalTarget.sprite.flash();
Actor.remove(toRemove);
next();
}
});
return false;
}
});
} else {
finalTarget.damage(Random.NormalIntRange(1, 4) - finalTarget.drRoll(), trap);
Buff.affect(finalTarget, Poison.class).set(4 + Dungeon.depth);
}
}
}
Aggregations