v2.5.0: code improvements to pitfall trap effects
This commit is contained in:
+43
-25
@@ -38,6 +38,8 @@ import com.shatteredpixel.shatteredpixeldungeon.utils.GLog;
|
|||||||
import com.watabou.utils.Bundle;
|
import com.watabou.utils.Bundle;
|
||||||
import com.watabou.utils.PathFinder;
|
import com.watabou.utils.PathFinder;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
|
|
||||||
public class PitfallTrap extends Trap {
|
public class PitfallTrap extends Trap {
|
||||||
|
|
||||||
{
|
{
|
||||||
@@ -56,13 +58,15 @@ public class PitfallTrap extends Trap {
|
|||||||
DelayedPit p = Buff.append(Dungeon.hero, DelayedPit.class, 1);
|
DelayedPit p = Buff.append(Dungeon.hero, DelayedPit.class, 1);
|
||||||
p.depth = Dungeon.depth;
|
p.depth = Dungeon.depth;
|
||||||
p.branch = Dungeon.branch;
|
p.branch = Dungeon.branch;
|
||||||
p.pos = pos;
|
|
||||||
|
|
||||||
|
ArrayList<Integer> positions = new ArrayList<>();
|
||||||
for (int i : PathFinder.NEIGHBOURS9){
|
for (int i : PathFinder.NEIGHBOURS9){
|
||||||
if (!Dungeon.level.solid[pos+i] || Dungeon.level.passable[pos+i]){
|
if (!Dungeon.level.solid[pos+i] || Dungeon.level.passable[pos+i]){
|
||||||
CellEmitter.floor(pos+i).burst(PitfallParticle.FACTORY4, 8);
|
CellEmitter.floor(pos+i).burst(PitfallParticle.FACTORY4, 8);
|
||||||
|
positions.add(i);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
p.setPositions(positions);
|
||||||
|
|
||||||
if (pos == Dungeon.hero.pos){
|
if (pos == Dungeon.hero.pos){
|
||||||
GLog.n(Messages.get(this, "triggered_hero"));
|
GLog.n(Messages.get(this, "triggered_hero"));
|
||||||
@@ -78,27 +82,38 @@ public class PitfallTrap extends Trap {
|
|||||||
revivePersists = true;
|
revivePersists = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
int pos;
|
public int[] positions = new int[0];
|
||||||
int depth;
|
public int depth;
|
||||||
int branch;
|
public int branch;
|
||||||
|
|
||||||
|
public boolean ignoreAllies = false;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean act() {
|
public boolean act() {
|
||||||
|
|
||||||
boolean herofell = false;
|
boolean herofell = false;
|
||||||
if (depth == Dungeon.depth && branch == Dungeon.branch) {
|
if (depth == Dungeon.depth && branch == Dungeon.branch && positions != null) {
|
||||||
for (int i : PathFinder.NEIGHBOURS9) {
|
for (int cell : positions) {
|
||||||
|
|
||||||
int cell = pos + i;
|
if (Dungeon.level.solid[cell] && !Dungeon.level.passable[cell]){
|
||||||
|
|
||||||
if (Dungeon.level.solid[pos+i] && !Dungeon.level.passable[pos+i]){
|
|
||||||
continue;
|
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);
|
Heap heap = Dungeon.level.heaps.get(cell);
|
||||||
|
|
||||||
if (heap != null && heap.type != Heap.Type.FOR_SALE
|
if (heap != null && heap.type != Heap.Type.FOR_SALE
|
||||||
&& heap.type != Heap.Type.LOCKED_CHEST
|
&& heap.type != Heap.Type.LOCKED_CHEST
|
||||||
&& heap.type != Heap.Type.CRYSTAL_CHEST) {
|
&& heap.type != Heap.Type.CRYSTAL_CHEST) {
|
||||||
@@ -111,44 +126,47 @@ public class PitfallTrap extends Trap {
|
|||||||
Dungeon.level.heaps.remove(cell);
|
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();
|
detach();
|
||||||
return !herofell;
|
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 DEPTH = "depth";
|
||||||
private static final String BRANCH = "branch";
|
private static final String BRANCH = "branch";
|
||||||
|
|
||||||
|
private static final String IGNORE_ALLIES = "ignore_allies";
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void storeInBundle(Bundle bundle) {
|
public void storeInBundle(Bundle bundle) {
|
||||||
super.storeInBundle(bundle);
|
super.storeInBundle(bundle);
|
||||||
bundle.put(POS, pos);
|
bundle.put(POSITIONS, positions);
|
||||||
bundle.put(DEPTH, depth);
|
bundle.put(DEPTH, depth);
|
||||||
bundle.put(BRANCH, branch);
|
bundle.put(BRANCH, branch);
|
||||||
|
bundle.put(IGNORE_ALLIES, ignoreAllies);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void restoreFromBundle(Bundle bundle) {
|
public void restoreFromBundle(Bundle bundle) {
|
||||||
super.restoreFromBundle(bundle);
|
super.restoreFromBundle(bundle);
|
||||||
pos = bundle.getInt(POS);
|
positions = bundle.getIntArray(POSITIONS);
|
||||||
depth = bundle.getInt(DEPTH);
|
depth = bundle.getInt(DEPTH);
|
||||||
branch = bundle.getInt(BRANCH);
|
branch = bundle.getInt(BRANCH);
|
||||||
|
ignoreAllies = bundle.getBoolean(IGNORE_ALLIES);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user