v0.9.0: improved logic for ripper demon leaping

This commit is contained in:
Evan Debenham 2020-09-16 16:05:58 -04:00
parent de9d629a7f
commit 3c4cb08cd2

View File

@ -135,20 +135,21 @@ public class RipperDemon extends Mob {
public boolean act( boolean enemyInFOV, boolean justAlerted ) { public boolean act( boolean enemyInFOV, boolean justAlerted ) {
if (leapPos != -1){ if (leapPos != -1){
//do leap
sprite.visible = Dungeon.level.heroFOV[pos] || Dungeon.level.heroFOV[leapPos];
sprite.jump(pos, leapPos, new Callback() {
@Override
public void call() {
Char ch = Actor.findChar(leapPos); leapCooldown = Random.NormalIntRange(2, 4);
if (ch != null){ Ballistica b = new Ballistica(pos, leapPos, Ballistica.STOP_TARGET | Ballistica.STOP_SOLID);
if (alignment != ch.alignment){
Buff.affect(ch, Bleeding.class).set(0.75f*damageRoll()); //check if leap pos is not obstructed by terrain
ch.sprite.flash(); if (b.collisionPos != leapPos){
Sample.INSTANCE.play(Assets.Sounds.HIT); leapPos = -1;
return true;
} }
//bounce to a random safe pos(if possible)
final Char leapVictim = Actor.findChar(leapPos);
final int endPos;
//ensure there is somewhere to land after leaping
if (leapVictim != null){
int bouncepos = -1; int bouncepos = -1;
for (int i : PathFinder.NEIGHBOURS8){ for (int i : PathFinder.NEIGHBOURS8){
if ((bouncepos == -1 || Dungeon.level.trueDistance(pos, leapPos+i) < Dungeon.level.trueDistance(pos, bouncepos)) if ((bouncepos == -1 || Dungeon.level.trueDistance(pos, leapPos+i) < Dungeon.level.trueDistance(pos, bouncepos))
@ -156,18 +157,34 @@ public class RipperDemon extends Mob {
bouncepos = leapPos+i; bouncepos = leapPos+i;
} }
} }
if (bouncepos != -1) { if (bouncepos == -1) {
pos = bouncepos; leapPos = -1;
Actor.addDelayed(new Pushing(RipperDemon.this, leapPos, bouncepos), -1); return true;
} else { } else {
pos = leapPos; endPos = bouncepos;
} }
} else { } else {
pos = leapPos; endPos = leapPos;
} }
//do leap
sprite.visible = Dungeon.level.heroFOV[pos] || Dungeon.level.heroFOV[leapPos] || Dungeon.level.heroFOV[endPos];
sprite.jump(pos, leapPos, new Callback() {
@Override
public void call() {
if (leapVictim != null && alignment != leapVictim.alignment){
Buff.affect(leapVictim, Bleeding.class).set(0.75f*damageRoll());
leapVictim.sprite.flash();
Sample.INSTANCE.play(Assets.Sounds.HIT);
}
if (endPos != leapPos){
Actor.addDelayed(new Pushing(RipperDemon.this, leapPos, endPos), -1);
}
pos = endPos;
leapPos = -1; leapPos = -1;
leapCooldown = Random.NormalIntRange(2, 4);
sprite.idle(); sprite.idle();
Dungeon.level.occupyCell(RipperDemon.this); Dungeon.level.occupyCell(RipperDemon.this);
next(); next();