v0.9.1b: code improvements to Tengu's smoke bomb

This commit is contained in:
Evan Debenham
2020-12-28 17:21:27 -05:00
parent a48370b008
commit 9a27edf1e4
2 changed files with 59 additions and 85 deletions
@@ -80,7 +80,6 @@ public class BlobImmunity extends FlavourBuff {
immunities.add( Web.class ); immunities.add( Web.class );
immunities.add(NewTengu.FireAbility.FireBlob.class); immunities.add(NewTengu.FireAbility.FireBlob.class);
immunities.add(NewTengu.BombAbility.BombBlob.class);
} }
@Override @Override
@@ -73,6 +73,7 @@ import com.watabou.utils.PathFinder;
import com.watabou.utils.PointF; import com.watabou.utils.PointF;
import com.watabou.utils.Random; import com.watabou.utils.Random;
import java.util.ArrayList;
import java.util.HashSet; import java.util.HashSet;
public class NewTengu extends Mob { public class NewTengu extends Mob {
@@ -566,82 +567,35 @@ public class NewTengu extends Mob {
public static class BombAbility extends Buff { public static class BombAbility extends Buff {
public int bombPos; public int bombPos = -1;
private int timer = 3; private int timer = 3;
private ArrayList<Emitter> smokeEmitters = new ArrayList<>();
@Override @Override
public boolean act() { public boolean act() {
PointF p = DungeonTilemap.raisedTileCenterToWorld(bombPos); if (smokeEmitters.isEmpty()){
if (timer == 3) {
FloatingText.show(p.x, p.y, bombPos, "3...", CharSprite.NEUTRAL);
PathFinder.buildDistanceMap( bombPos, BArray.not( Dungeon.level.solid, null ), 2 ); PathFinder.buildDistanceMap( bombPos, BArray.not( Dungeon.level.solid, null ), 2 );
for (int i = 0; i < PathFinder.distance.length; i++) { for (int i = 0; i < PathFinder.distance.length; i++) {
if (PathFinder.distance[i] < Integer.MAX_VALUE) { if (PathFinder.distance[i] < Integer.MAX_VALUE) {
GameScene.add(Blob.seed(i, 4, BombBlob.class)); Emitter e = CellEmitter.get(i);
e.pour( SmokeParticle.FACTORY, 0.25f );
smokeEmitters.add(e);
} }
} }
}
PointF p = DungeonTilemap.raisedTileCenterToWorld(bombPos);
if (timer == 3) {
FloatingText.show(p.x, p.y, bombPos, "3...", CharSprite.NEUTRAL);
} else if (timer == 2){ } else if (timer == 2){
FloatingText.show(p.x, p.y, bombPos, "2...", CharSprite.WARNING); FloatingText.show(p.x, p.y, bombPos, "2...", CharSprite.WARNING);
} else if (timer == 1){ } else if (timer == 1){
FloatingText.show(p.x, p.y, bombPos, "1...", CharSprite.NEGATIVE); FloatingText.show(p.x, p.y, bombPos, "1...", CharSprite.NEGATIVE);
} else { } else {
Heap h = Dungeon.level.heaps.get(bombPos); PathFinder.buildDistanceMap( bombPos, BArray.not( Dungeon.level.solid, null ), 2 );
if (h != null){ for (int cell = 0; cell < PathFinder.distance.length; cell++) {
for (Item i : h.items.toArray(new Item[0])){
if (i instanceof BombItem){
h.remove(i);
}
}
}
detach();
return true;
}
timer--;
spend(TICK);
return true;
}
private static final String BOMB_POS = "bomb_pos";
private static final String TIMER = "timer";
@Override
public void storeInBundle(Bundle bundle) {
super.storeInBundle(bundle);
bundle.put( BOMB_POS, bombPos );
bundle.put( TIMER, timer );
}
@Override
public void restoreFromBundle(Bundle bundle) {
super.restoreFromBundle(bundle);
bombPos = bundle.getInt( BOMB_POS );
timer = bundle.getInt( TIMER );
}
public static class BombBlob extends Blob {
{
actPriority = BUFF_PRIO - 1;
alwaysVisible = true;
}
@Override
protected void evolve() {
boolean exploded = false;
int cell;
for (int i = area.left; i < area.right; i++){
for (int j = area.top; j < area.bottom; j++){
cell = i + j* Dungeon.level.width();
off[cell] = cur[cell] > 0 ? cur[cell] - 1 : 0;
if (off[cell] > 0) {
volume += off[cell];
}
if (cur[cell] > 0 && off[cell] == 0){
Char ch = Actor.findChar(cell); Char ch = Actor.findChar(cell);
if (ch != null && !(ch instanceof NewTengu)){ if (ch != null && !(ch instanceof NewTengu)){
@@ -659,36 +613,57 @@ public class NewTengu extends Mob {
Heap h = Dungeon.level.heaps.get(cell); Heap h = Dungeon.level.heaps.get(cell);
if (h != null){ if (h != null){
for (Item it : h.items.toArray(new Item[0])){ for (Item i : h.items.toArray(new Item[0])){
if (it instanceof BombItem){ if (i instanceof BombItem){
h.remove(it); h.remove(i);
} }
} }
} }
exploded = true;
CellEmitter.center(cell).burst(BlastParticle.FACTORY, 2);
} }
}
}
if (exploded){
Sample.INSTANCE.play(Assets.Sounds.BLAST); Sample.INSTANCE.play(Assets.Sounds.BLAST);
detach();
return true;
} }
timer--;
spend(TICK);
return true;
} }
@Override @Override
public void use(BlobEmitter emitter) { public void fx(boolean on) {
super.use(emitter); if (on && bombPos != -1){
PathFinder.buildDistanceMap( bombPos, BArray.not( Dungeon.level.solid, null ), 2 );
for (int i = 0; i < PathFinder.distance.length; i++) {
if (PathFinder.distance[i] < Integer.MAX_VALUE) {
Emitter e = CellEmitter.get(i);
e.pour( SmokeParticle.FACTORY, 0.25f );
smokeEmitters.add(e);
}
}
} else if (!on) {
for (Emitter e : smokeEmitters){
e.burst(BlastParticle.FACTORY, 2);
}
}
}
emitter.pour( SmokeParticle.FACTORY, 0.25f ); private static final String BOMB_POS = "bomb_pos";
private static final String TIMER = "timer";
@Override
public void storeInBundle(Bundle bundle) {
super.storeInBundle(bundle);
bundle.put( BOMB_POS, bombPos );
bundle.put( TIMER, timer );
} }
@Override @Override
public String tileDesc() { public void restoreFromBundle(Bundle bundle) {
return Messages.get(this, "desc"); super.restoreFromBundle(bundle);
} bombPos = bundle.getInt( BOMB_POS );
timer = bundle.getInt( TIMER );
} }
public static class BombItem extends Item { public static class BombItem extends Item {