v0.9.4: trap refactoring and prevented some traps from spawning in halls
This commit is contained in:
parent
12cbb51c06
commit
50a1ea0c62
|
@ -391,30 +391,46 @@ 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);
|
//temporarily use the passable array for the next step
|
||||||
validCells.remove(trapPos); //removes the integer object, not at the index
|
for (int i = 0; i < l.length(); i++){
|
||||||
|
l.passable[i] = (Terrain.flags[l.map[i]] & Terrain.PASSABLE) != 0;
|
||||||
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;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
//4x regular trap count of visible traps on traps level feeling
|
for (int i : validCells){
|
||||||
if (l.feeling == Level.Feeling.TRAPS){
|
if ((l.passable[i+PathFinder.CIRCLE4[0]] || l.passable[i+PathFinder.CIRCLE4[2]])
|
||||||
for (int i = 0; i < 4*nTraps; i++) {
|
&& (l.passable[i+PathFinder.CIRCLE4[1]] || l.passable[i+PathFinder.CIRCLE4[3]])){
|
||||||
|
validNonHallways.add(i);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
Integer trapPos = Random.element(validCells);
|
//no more than one trap every 5 valid tiles.
|
||||||
validCells.remove(trapPos); //removes the integer object, not at the index
|
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 );
|
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;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -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 {
|
||||||
|
|
|
@ -43,6 +43,7 @@ public class DisintegrationTrap extends Trap {
|
||||||
shape = CROSSHAIR;
|
shape = CROSSHAIR;
|
||||||
|
|
||||||
canBeHidden = false;
|
canBeHidden = false;
|
||||||
|
avoidsHallways = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|
|
@ -40,17 +40,9 @@ public class FlashingTrap extends Trap {
|
||||||
{
|
{
|
||||||
color = GREY;
|
color = GREY;
|
||||||
shape = STARS;
|
shape = STARS;
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
disarmedByActivation = false;
|
||||||
public void trigger() {
|
avoidsHallways = true;
|
||||||
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
|
||||||
|
|
|
@ -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() {
|
||||||
|
|
||||||
|
|
|
@ -42,6 +42,7 @@ public class GrimTrap extends Trap {
|
||||||
shape = LARGE_DOT;
|
shape = LARGE_DOT;
|
||||||
|
|
||||||
canBeHidden = false;
|
canBeHidden = false;
|
||||||
|
avoidsHallways = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|
|
@ -38,17 +38,9 @@ public class GrippingTrap extends Trap {
|
||||||
{
|
{
|
||||||
color = GREY;
|
color = GREY;
|
||||||
shape = DOTS;
|
shape = DOTS;
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
disarmedByActivation = false;
|
||||||
public void trigger() {
|
avoidsHallways = true;
|
||||||
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
|
||||||
|
|
|
@ -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(){
|
||||||
|
|
|
@ -49,6 +49,7 @@ public class RockfallTrap extends Trap {
|
||||||
shape = DIAMOND;
|
shape = DIAMOND;
|
||||||
|
|
||||||
canBeHidden = false;
|
canBeHidden = false;
|
||||||
|
avoidsHallways = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|
|
@ -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();
|
||||||
}
|
}
|
||||||
|
|
|
@ -40,6 +40,7 @@ public class WornDartTrap extends Trap {
|
||||||
shape = CROSSHAIR;
|
shape = CROSSHAIR;
|
||||||
|
|
||||||
canBeHidden = false;
|
canBeHidden = false;
|
||||||
|
avoidsHallways = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|
Loading…
Reference in New Issue
Block a user