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

@ -391,30 +391,46 @@ public abstract class RegularPainter extends Painter {
//no more than one trap every 5 valid tiles.
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
Trap trap = Reflection.newInstance(trapClasses[Random.chances( trapChances )]).hide();
l.setTrap( trap, trapPos );
//some traps will not be hidden
l.map[trapPos] = trap.visible ? Terrain.TRAP : Terrain.SECRET_TRAP;
//temporarily use the passable array for the next step
for (int i = 0; i < l.length(); i++){
l.passable[i] = (Terrain.flags[l.map[i]] & Terrain.PASSABLE) != 0;
}
//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++) {
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);
}
}
Integer trapPos = Random.element(validCells);
validCells.remove(trapPos); //removes the integer object, not at the index
//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();
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;
}
@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
private static ArrayList<Class<?extends ConnectionRoom>> rooms = new ArrayList<>();
static {

View File

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

View File

@ -40,17 +40,9 @@ public class FlashingTrap extends Trap {
{
color = GREY;
shape = STARS;
}
@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();
disarmedByActivation = false;
avoidsHallways = true;
}
@Override

View File

@ -1,6 +1,6 @@
package com.shatteredpixel.shatteredpixeldungeon.levels.traps;
import com.shatteredpixel.shatteredpixeldungeon.Assets;
import com.shatteredpixel.shatteredpixeldungeon.Dungeon;
import com.shatteredpixel.shatteredpixeldungeon.actors.Actor;
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.Item;
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.PathFinder;
import com.watabou.utils.Random;
@ -22,21 +19,13 @@ public class GatewayTrap extends Trap {
{
color = TEAL;
shape = CROSSHAIR;
disarmedByActivation = false;
avoidsHallways = true;
}
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
public void activate() {

View File

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

View File

@ -38,17 +38,9 @@ public class GrippingTrap extends Trap {
{
color = GREY;
shape = DOTS;
}
@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();
disarmedByActivation = false;
avoidsHallways = true;
}
@Override

View File

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

View File

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

View File

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

View File

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