v0.9.4: trap refactoring and prevented some traps from spawning in halls

This commit is contained in:
Evan Debenham 2021-08-12 19:47:30 -04:00
parent 12cbb51c06
commit 50a1ea0c62
11 changed files with 57 additions and 66 deletions

View File

@ -390,31 +390,47 @@ public abstract class RegularPainter extends Painter {
//no more than one trap every 5 valid tiles. //no more than one trap every 5 valid tiles.
nTraps = Math.min(nTraps, validCells.size()/5); nTraps = Math.min(nTraps, validCells.size()/5);
for (int i = 0; i < nTraps; i++) { //for traps that want to avoid being in hallways
ArrayList<Integer> validNonHallways = new ArrayList<>();
Integer trapPos = Random.element(validCells);
validCells.remove(trapPos); //removes the integer object, not at the index //temporarily use the passable array for the next step
for (int i = 0; i < l.length(); i++){
Trap trap = Reflection.newInstance(trapClasses[Random.chances( trapChances )]).hide(); l.passable[i] = (Terrain.flags[l.map[i]] & Terrain.PASSABLE) != 0;
}
for (int i : validCells){
if ((l.passable[i+PathFinder.CIRCLE4[0]] || l.passable[i+PathFinder.CIRCLE4[2]])
&& (l.passable[i+PathFinder.CIRCLE4[1]] || l.passable[i+PathFinder.CIRCLE4[3]])){
validNonHallways.add(i);
}
}
//no more than one trap every 5 valid tiles.
nTraps = Math.min(nTraps, validCells.size()/5);
//5x traps on traps level feeling, but the extra traps are all visible
for (int i = 0; i < (l.feeling == Level.Feeling.TRAPS ? 5*nTraps : nTraps); i++) {
Trap trap = Reflection.newInstance(trapClasses[Random.chances( trapChances )]);
Integer trapPos;
if (trap.avoidsHallways && !validNonHallways.isEmpty()){
trapPos = Random.element(validNonHallways);
} else {
trapPos = Random.element(validCells);
}
//removes the integer object, not at the index
validCells.remove(trapPos);
validNonHallways.remove(trapPos);
if (i < nTraps) trap.hide();
else trap.reveal();
l.setTrap( trap, trapPos ); l.setTrap( trap, trapPos );
//some traps will not be hidden //some traps will not be hidden
l.map[trapPos] = trap.visible ? Terrain.TRAP : Terrain.SECRET_TRAP; l.map[trapPos] = trap.visible ? Terrain.TRAP : Terrain.SECRET_TRAP;
} }
//4x regular trap count of visible traps on traps level feeling
if (l.feeling == Level.Feeling.TRAPS){
for (int i = 0; i < 4*nTraps; i++) {
Integer trapPos = Random.element(validCells);
validCells.remove(trapPos); //removes the integer object, not at the index
Trap trap = Reflection.newInstance(trapClasses[Random.chances( trapChances )]).reveal();
l.setTrap( trap, trapPos );
//some traps will not be hidden
l.map[trapPos] = trap.visible ? Terrain.TRAP : Terrain.SECRET_TRAP;
}
}
} }
} }

View File

@ -45,12 +45,6 @@ public abstract class ConnectionRoom extends Room {
else return 0; else return 0;
} }
@Override
public boolean canPlaceTrap(Point p) {
//traps cannot appear in connection rooms on floor 1
return super.canPlaceTrap(p) && Dungeon.depth > 1;
}
//FIXME this is a very messy way of handing variable connection rooms //FIXME this is a very messy way of handing variable connection rooms
private static ArrayList<Class<?extends ConnectionRoom>> rooms = new ArrayList<>(); private static ArrayList<Class<?extends ConnectionRoom>> rooms = new ArrayList<>();
static { static {

View File

@ -43,6 +43,7 @@ public class DisintegrationTrap extends Trap {
shape = CROSSHAIR; shape = CROSSHAIR;
canBeHidden = false; canBeHidden = false;
avoidsHallways = true;
} }
@Override @Override

View File

@ -40,19 +40,11 @@ public class FlashingTrap extends Trap {
{ {
color = GREY; color = GREY;
shape = STARS; shape = STARS;
disarmedByActivation = false;
avoidsHallways = true;
} }
@Override
public void trigger() {
if (Dungeon.level.heroFOV[pos]){
Sample.INSTANCE.play(Assets.Sounds.TRAP);
}
//this trap is not disarmed by being triggered
reveal();
Level.set(pos, Terrain.TRAP);
activate();
}
@Override @Override
public void activate() { public void activate() {

View File

@ -1,6 +1,6 @@
package com.shatteredpixel.shatteredpixeldungeon.levels.traps; package com.shatteredpixel.shatteredpixeldungeon.levels.traps;
import com.shatteredpixel.shatteredpixeldungeon.Assets;
import com.shatteredpixel.shatteredpixeldungeon.Dungeon; import com.shatteredpixel.shatteredpixeldungeon.Dungeon;
import com.shatteredpixel.shatteredpixeldungeon.actors.Actor; import com.shatteredpixel.shatteredpixeldungeon.actors.Actor;
import com.shatteredpixel.shatteredpixeldungeon.actors.Char; import com.shatteredpixel.shatteredpixeldungeon.actors.Char;
@ -8,9 +8,6 @@ import com.shatteredpixel.shatteredpixeldungeon.actors.mobs.Mob;
import com.shatteredpixel.shatteredpixeldungeon.items.Heap; import com.shatteredpixel.shatteredpixeldungeon.items.Heap;
import com.shatteredpixel.shatteredpixeldungeon.items.Item; import com.shatteredpixel.shatteredpixeldungeon.items.Item;
import com.shatteredpixel.shatteredpixeldungeon.items.scrolls.ScrollOfTeleportation; import com.shatteredpixel.shatteredpixeldungeon.items.scrolls.ScrollOfTeleportation;
import com.shatteredpixel.shatteredpixeldungeon.levels.Level;
import com.shatteredpixel.shatteredpixeldungeon.levels.Terrain;
import com.watabou.noosa.audio.Sample;
import com.watabou.utils.Bundle; import com.watabou.utils.Bundle;
import com.watabou.utils.PathFinder; import com.watabou.utils.PathFinder;
import com.watabou.utils.Random; import com.watabou.utils.Random;
@ -22,21 +19,13 @@ public class GatewayTrap extends Trap {
{ {
color = TEAL; color = TEAL;
shape = CROSSHAIR; shape = CROSSHAIR;
disarmedByActivation = false;
avoidsHallways = true;
} }
private int telePos = -1; private int telePos = -1;
@Override
public void trigger() {
if (Dungeon.level.heroFOV[pos]){
Sample.INSTANCE.play(Assets.Sounds.TRAP);
}
//this trap is not disarmed by being triggered
reveal();
Level.set(pos, Terrain.TRAP);
activate();
}
@Override @Override
public void activate() { public void activate() {

View File

@ -42,6 +42,7 @@ public class GrimTrap extends Trap {
shape = LARGE_DOT; shape = LARGE_DOT;
canBeHidden = false; canBeHidden = false;
avoidsHallways = true;
} }
@Override @Override

View File

@ -38,17 +38,9 @@ public class GrippingTrap extends Trap {
{ {
color = GREY; color = GREY;
shape = DOTS; shape = DOTS;
}
disarmedByActivation = false;
@Override avoidsHallways = true;
public void trigger() {
if (Dungeon.level.heroFOV[pos]){
Sample.INSTANCE.play(Assets.Sounds.TRAP);
}
//this trap is not disarmed by being triggered
reveal();
Level.set(pos, Terrain.TRAP);
activate();
} }
@Override @Override

View File

@ -42,6 +42,7 @@ public class PoisonDartTrap extends Trap {
shape = CROSSHAIR; shape = CROSSHAIR;
canBeHidden = false; canBeHidden = false;
avoidsHallways = true;
} }
protected int poisonAmount(){ protected int poisonAmount(){

View File

@ -49,6 +49,7 @@ public class RockfallTrap extends Trap {
shape = DIAMOND; shape = DIAMOND;
canBeHidden = false; canBeHidden = false;
avoidsHallways = true;
} }
@Override @Override

View File

@ -58,10 +58,13 @@ public abstract class Trap implements Bundlable {
public boolean visible; public boolean visible;
public boolean active = true; public boolean active = true;
public boolean disarmedByActivation = true;
public boolean canBeHidden = true; public boolean canBeHidden = true;
public boolean canBeSearched = true; public boolean canBeSearched = true;
public boolean avoidsHallways = false; //whether this trap should avoid being placed in hallways
public Trap set(int pos){ public Trap set(int pos){
this.pos = pos; this.pos = pos;
return this; return this;
@ -88,7 +91,7 @@ public abstract class Trap implements Bundlable {
if (Dungeon.level.heroFOV[pos]) { if (Dungeon.level.heroFOV[pos]) {
Sample.INSTANCE.play(Assets.Sounds.TRAP); Sample.INSTANCE.play(Assets.Sounds.TRAP);
} }
disarm(); if (disarmedByActivation) disarm();
reveal(); reveal();
activate(); activate();
} }

View File

@ -40,6 +40,7 @@ public class WornDartTrap extends Trap {
shape = CROSSHAIR; shape = CROSSHAIR;
canBeHidden = false; canBeHidden = false;
avoidsHallways = true;
} }
@Override @Override