v2.5.0: code improvements to pitfall trap effects
This commit is contained in:
@@ -38,6 +38,8 @@ import com.shatteredpixel.shatteredpixeldungeon.utils.GLog;
|
||||
import com.watabou.utils.Bundle;
|
||||
import com.watabou.utils.PathFinder;
|
||||
|
||||
import java.util.ArrayList;
|
||||
|
||||
public class PitfallTrap extends Trap {
|
||||
|
||||
{
|
||||
@@ -56,13 +58,15 @@ public class PitfallTrap extends Trap {
|
||||
DelayedPit p = Buff.append(Dungeon.hero, DelayedPit.class, 1);
|
||||
p.depth = Dungeon.depth;
|
||||
p.branch = Dungeon.branch;
|
||||
p.pos = pos;
|
||||
|
||||
ArrayList<Integer> positions = new ArrayList<>();
|
||||
for (int i : PathFinder.NEIGHBOURS9){
|
||||
if (!Dungeon.level.solid[pos+i] || Dungeon.level.passable[pos+i]){
|
||||
CellEmitter.floor(pos+i).burst(PitfallParticle.FACTORY4, 8);
|
||||
positions.add(i);
|
||||
}
|
||||
}
|
||||
p.setPositions(positions);
|
||||
|
||||
if (pos == Dungeon.hero.pos){
|
||||
GLog.n(Messages.get(this, "triggered_hero"));
|
||||
@@ -78,27 +82,38 @@ public class PitfallTrap extends Trap {
|
||||
revivePersists = true;
|
||||
}
|
||||
|
||||
int pos;
|
||||
int depth;
|
||||
int branch;
|
||||
public int[] positions = new int[0];
|
||||
public int depth;
|
||||
public int branch;
|
||||
|
||||
public boolean ignoreAllies = false;
|
||||
|
||||
@Override
|
||||
public boolean act() {
|
||||
|
||||
boolean herofell = false;
|
||||
if (depth == Dungeon.depth && branch == Dungeon.branch) {
|
||||
for (int i : PathFinder.NEIGHBOURS9) {
|
||||
if (depth == Dungeon.depth && branch == Dungeon.branch && positions != null) {
|
||||
for (int cell : positions) {
|
||||
|
||||
int cell = pos + i;
|
||||
|
||||
if (Dungeon.level.solid[pos+i] && !Dungeon.level.passable[pos+i]){
|
||||
if (Dungeon.level.solid[cell] && !Dungeon.level.passable[cell]){
|
||||
continue;
|
||||
}
|
||||
|
||||
CellEmitter.floor(pos+i).burst(PitfallParticle.FACTORY8, 12);
|
||||
CellEmitter.floor(cell).burst(PitfallParticle.FACTORY8, 12);
|
||||
|
||||
Char ch = Actor.findChar(cell);
|
||||
//don't trigger on flying chars, or immovable neutral chars
|
||||
if (ch != null && !ch.flying
|
||||
&& !(ch.alignment == Char.Alignment.NEUTRAL && Char.hasProp(ch, Char.Property.IMMOVABLE))
|
||||
&& !(ch.alignment == Char.Alignment.ALLY && ignoreAllies)) {
|
||||
if (ch == Dungeon.hero) {
|
||||
herofell = true;
|
||||
} else {
|
||||
Chasm.mobFall((Mob) ch);
|
||||
}
|
||||
}
|
||||
|
||||
Heap heap = Dungeon.level.heaps.get(cell);
|
||||
|
||||
if (heap != null && heap.type != Heap.Type.FOR_SALE
|
||||
&& heap.type != Heap.Type.LOCKED_CHEST
|
||||
&& heap.type != Heap.Type.CRYSTAL_CHEST) {
|
||||
@@ -111,44 +126,47 @@ public class PitfallTrap extends Trap {
|
||||
Dungeon.level.heaps.remove(cell);
|
||||
}
|
||||
|
||||
Char ch = Actor.findChar(cell);
|
||||
|
||||
//don't trigger on flying chars, or immovable neutral chars
|
||||
if (ch != null && !ch.flying
|
||||
&& !(ch.alignment == Char.Alignment.NEUTRAL && Char.hasProp(ch, Char.Property.IMMOVABLE))) {
|
||||
if (ch == Dungeon.hero) {
|
||||
Chasm.heroFall(cell);
|
||||
herofell = true;
|
||||
} else {
|
||||
Chasm.mobFall((Mob) ch);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
//process hero falling last
|
||||
if (herofell){
|
||||
Chasm.heroFall(Dungeon.hero.pos);
|
||||
}
|
||||
|
||||
detach();
|
||||
return !herofell;
|
||||
}
|
||||
|
||||
private static final String POS = "pos";
|
||||
public void setPositions(ArrayList<Integer> positions){
|
||||
this.positions = new int[positions.size()];
|
||||
for (int i = 0; i < this.positions.length; i++){
|
||||
this.positions[i] = positions.get(i);
|
||||
}
|
||||
}
|
||||
|
||||
private static final String POSITIONS = "positions";
|
||||
private static final String DEPTH = "depth";
|
||||
private static final String BRANCH = "branch";
|
||||
|
||||
private static final String IGNORE_ALLIES = "ignore_allies";
|
||||
|
||||
@Override
|
||||
public void storeInBundle(Bundle bundle) {
|
||||
super.storeInBundle(bundle);
|
||||
bundle.put(POS, pos);
|
||||
bundle.put(POSITIONS, positions);
|
||||
bundle.put(DEPTH, depth);
|
||||
bundle.put(BRANCH, branch);
|
||||
bundle.put(IGNORE_ALLIES, ignoreAllies);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void restoreFromBundle(Bundle bundle) {
|
||||
super.restoreFromBundle(bundle);
|
||||
pos = bundle.getInt(POS);
|
||||
positions = bundle.getIntArray(POSITIONS);
|
||||
depth = bundle.getInt(DEPTH);
|
||||
branch = bundle.getInt(BRANCH);
|
||||
ignoreAllies = bundle.getBoolean(IGNORE_ALLIES);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user