v0.2.4: Switched to Watabou's much more elegant logic for items falling between floors
This commit is contained in:
parent
61246dcc46
commit
5fcc1a612a
|
@ -19,11 +19,6 @@ package com.shatteredpixel.shatteredpixeldungeon;
|
|||
|
||||
import com.shatteredpixel.shatteredpixeldungeon.actors.Actor;
|
||||
import com.shatteredpixel.shatteredpixeldungeon.actors.Char;
|
||||
import com.shatteredpixel.shatteredpixeldungeon.actors.blobs.Blob;
|
||||
import com.shatteredpixel.shatteredpixeldungeon.actors.blobs.ConfusionGas;
|
||||
import com.shatteredpixel.shatteredpixeldungeon.actors.blobs.Fire;
|
||||
import com.shatteredpixel.shatteredpixeldungeon.actors.blobs.ParalyticGas;
|
||||
import com.shatteredpixel.shatteredpixeldungeon.actors.blobs.ToxicGas;
|
||||
import com.shatteredpixel.shatteredpixeldungeon.actors.buffs.Amok;
|
||||
import com.shatteredpixel.shatteredpixeldungeon.actors.buffs.Light;
|
||||
import com.shatteredpixel.shatteredpixeldungeon.actors.hero.Hero;
|
||||
|
@ -34,11 +29,8 @@ import com.shatteredpixel.shatteredpixeldungeon.actors.mobs.npcs.Imp;
|
|||
import com.shatteredpixel.shatteredpixeldungeon.actors.mobs.npcs.Wandmaker;
|
||||
import com.shatteredpixel.shatteredpixeldungeon.items.Ankh;
|
||||
import com.shatteredpixel.shatteredpixeldungeon.items.Generator;
|
||||
import com.shatteredpixel.shatteredpixeldungeon.items.Item;
|
||||
import com.shatteredpixel.shatteredpixeldungeon.items.potions.Potion;
|
||||
import com.shatteredpixel.shatteredpixeldungeon.items.potions.PotionOfLevitation;
|
||||
import com.shatteredpixel.shatteredpixeldungeon.items.potions.PotionOfLiquidFlame;
|
||||
import com.shatteredpixel.shatteredpixeldungeon.items.potions.PotionOfParalyticGas;
|
||||
import com.shatteredpixel.shatteredpixeldungeon.items.potions.PotionOfToxicGas;
|
||||
import com.shatteredpixel.shatteredpixeldungeon.items.rings.Ring;
|
||||
import com.shatteredpixel.shatteredpixeldungeon.items.scrolls.Scroll;
|
||||
import com.shatteredpixel.shatteredpixeldungeon.items.wands.Wand;
|
||||
|
@ -64,13 +56,16 @@ import com.shatteredpixel.shatteredpixeldungeon.utils.BArray;
|
|||
import com.shatteredpixel.shatteredpixeldungeon.utils.Utils;
|
||||
import com.shatteredpixel.shatteredpixeldungeon.windows.WndResurrect;
|
||||
import com.watabou.noosa.Game;
|
||||
import com.watabou.utils.Bundlable;
|
||||
import com.watabou.utils.Bundle;
|
||||
import com.watabou.utils.PathFinder;
|
||||
import com.watabou.utils.Random;
|
||||
import com.watabou.utils.SparseArray;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.io.OutputStream;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.HashSet;
|
||||
|
||||
|
@ -133,6 +128,8 @@ public class Dungeon {
|
|||
// Hero's field of view
|
||||
public static boolean[] visible = new boolean[Level.LENGTH];
|
||||
|
||||
public static SparseArray<ArrayList<Item>> droppedItems;
|
||||
|
||||
public static int version;
|
||||
|
||||
public static void init() {
|
||||
|
@ -160,6 +157,8 @@ public class Dungeon {
|
|||
depth = 0;
|
||||
gold = 0;
|
||||
|
||||
droppedItems = new SparseArray<ArrayList<Item>>();
|
||||
|
||||
for (limitedDrops a : limitedDrops.values())
|
||||
a.count = 0;
|
||||
|
||||
|
@ -301,24 +300,6 @@ public class Dungeon {
|
|||
Actor.add( level.respawner() );
|
||||
}
|
||||
|
||||
for (Potion potion : level.fallingPotions){
|
||||
|
||||
int cell = level.randomRespawnCell();
|
||||
while (cell == -1)
|
||||
cell = level.randomRespawnCell();
|
||||
|
||||
if (potion instanceof PotionOfLiquidFlame)
|
||||
GameScene.add( Blob.seed( cell, 2, Fire.class));
|
||||
else if (potion instanceof PotionOfToxicGas)
|
||||
GameScene.add( Blob.seed( cell, 1000, ToxicGas.class ) );
|
||||
else if (potion instanceof PotionOfParalyticGas)
|
||||
GameScene.add( Blob.seed( cell, 1000, ParalyticGas.class ) );
|
||||
else if (potion instanceof PotionOfLevitation)
|
||||
GameScene.add( Blob.seed( cell, 1000, ConfusionGas.class ) );
|
||||
|
||||
}
|
||||
level.fallingPotions.clear();
|
||||
|
||||
hero.pos = pos != -1 ? pos : level.exit;
|
||||
|
||||
Light light = hero.buff( Light.class );
|
||||
|
@ -328,11 +309,20 @@ public class Dungeon {
|
|||
try {
|
||||
saveAll();
|
||||
} catch (IOException e) {
|
||||
/*This only catches IO errors. Yes, this means things can do wrong, and they can go wrong catastrophically.
|
||||
/*This only catches IO errors. Yes, this means things can go wrong, and they can go wrong catastrophically.
|
||||
But when they do the user will get a nice 'report this issue' dialogue, and I can fix the bug.*/
|
||||
}
|
||||
}
|
||||
|
||||
public static void dropToChasm( Item item ) {
|
||||
int depth = Dungeon.depth + 1;
|
||||
ArrayList<Item> dropped = (ArrayList<Item>)Dungeon.droppedItems.get( depth );
|
||||
if (dropped == null) {
|
||||
Dungeon.droppedItems.put( depth, dropped = new ArrayList<Item>() );
|
||||
}
|
||||
dropped.add( item );
|
||||
}
|
||||
|
||||
public static boolean posNeeded() {
|
||||
int[] quota = {4, 2, 9, 4, 14, 6, 19, 8, 24, 9};
|
||||
return chance( quota, limitedDrops.strengthPotions.count );
|
||||
|
@ -377,7 +367,7 @@ public class Dungeon {
|
|||
private static final String HERO = "hero";
|
||||
private static final String GOLD = "gold";
|
||||
private static final String DEPTH = "depth";
|
||||
private static final String QUICKSLOT = "quickslot";
|
||||
private static final String DROPPED = "dropped%d";
|
||||
private static final String LEVEL = "level";
|
||||
private static final String LIMDROPS = "limiteddrops";
|
||||
private static final String DV = "dewVial";
|
||||
|
@ -427,6 +417,10 @@ public class Dungeon {
|
|||
bundle.put( GOLD, gold );
|
||||
bundle.put( DEPTH, depth );
|
||||
|
||||
for (int d : droppedItems.keyArray()) {
|
||||
bundle.put(String.format(DROPPED, d), droppedItems.get(d));
|
||||
}
|
||||
|
||||
quickslot.storePlaceholders( bundle );
|
||||
|
||||
bundle.put( WT, transmutation );
|
||||
|
@ -601,6 +595,17 @@ public class Dungeon {
|
|||
Journal.restoreFromBundle( bundle );
|
||||
Generator.restoreFromBundle( bundle );
|
||||
|
||||
droppedItems = new SparseArray<ArrayList<Item>>();
|
||||
for (int i=2; i <= Statistics.deepestFloor + 1; i++) {
|
||||
ArrayList<Item> dropped = new ArrayList<Item>();
|
||||
for (Bundlable b : bundle.getCollection( String.format( DROPPED, i ) ) ) {
|
||||
dropped.add( (Item)b );
|
||||
}
|
||||
if (!dropped.isEmpty()) {
|
||||
droppedItems.put( i, dropped );
|
||||
}
|
||||
}
|
||||
|
||||
//logic for pre 0.2.4 bags, remove when no longer supporting those saves.
|
||||
if (version <= 32){
|
||||
int deepest = Statistics.deepestFloor;
|
||||
|
|
|
@ -51,7 +51,6 @@ import com.shatteredpixel.shatteredpixeldungeon.items.bags.ScrollHolder;
|
|||
import com.shatteredpixel.shatteredpixeldungeon.items.bags.SeedPouch;
|
||||
import com.shatteredpixel.shatteredpixeldungeon.items.food.Blandfruit;
|
||||
import com.shatteredpixel.shatteredpixeldungeon.items.food.Food;
|
||||
import com.shatteredpixel.shatteredpixeldungeon.items.potions.Potion;
|
||||
import com.shatteredpixel.shatteredpixeldungeon.items.potions.PotionOfHealing;
|
||||
import com.shatteredpixel.shatteredpixeldungeon.items.potions.PotionOfMight;
|
||||
import com.shatteredpixel.shatteredpixeldungeon.items.potions.PotionOfStrength;
|
||||
|
@ -155,9 +154,6 @@ public abstract class Level implements Bundlable {
|
|||
|
||||
protected ArrayList<Item> itemsToSpawn = new ArrayList<Item>();
|
||||
|
||||
public ArrayList<Item> fallingItems = new ArrayList<Item>();
|
||||
public ArrayList<Potion> fallingPotions = new ArrayList<Potion>();
|
||||
|
||||
public int color1 = 0x004400;
|
||||
public int color2 = 0x88CC44;
|
||||
|
||||
|
@ -174,7 +170,6 @@ public abstract class Level implements Bundlable {
|
|||
private static final String PLANTS = "plants";
|
||||
private static final String MOBS = "mobs";
|
||||
private static final String BLOBS = "blobs";
|
||||
private static final String FALLING = "falling";
|
||||
private static final String FEELING = "feeling";
|
||||
|
||||
public void create() {
|
||||
|
@ -339,8 +334,6 @@ public abstract class Level implements Bundlable {
|
|||
blobs.put( blob.getClass(), blob );
|
||||
}
|
||||
|
||||
fallingItems = (ArrayList)bundle.getCollection( FALLING );
|
||||
|
||||
feeling = bundle.getEnum( FEELING, Feeling.class );
|
||||
if (feeling == Feeling.DARK)
|
||||
viewDistance = (int)Math.ceil(viewDistance/3f);
|
||||
|
@ -361,7 +354,6 @@ public abstract class Level implements Bundlable {
|
|||
bundle.put( PLANTS, plants.values() );
|
||||
bundle.put( MOBS, mobs );
|
||||
bundle.put( BLOBS, blobs.values() );
|
||||
bundle.put( FALLING, fallingItems);
|
||||
bundle.put( FEELING, feeling );
|
||||
}
|
||||
|
||||
|
@ -634,8 +626,8 @@ public abstract class Level implements Bundlable {
|
|||
heap = new Heap();
|
||||
heap.pos = cell;
|
||||
if (map[cell] == Terrain.CHASM || (Dungeon.level != null && pit[cell])) {
|
||||
Dungeon.dropToChasm( item );
|
||||
GameScene.discard( heap );
|
||||
fallingItems.add(item);
|
||||
} else {
|
||||
heaps.put( cell, heap );
|
||||
GameScene.add( heap );
|
||||
|
|
|
@ -18,8 +18,11 @@
|
|||
package com.shatteredpixel.shatteredpixeldungeon.scenes;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.ArrayList;
|
||||
|
||||
import com.shatteredpixel.shatteredpixeldungeon.*;
|
||||
import com.shatteredpixel.shatteredpixeldungeon.items.Honeypot;
|
||||
import com.shatteredpixel.shatteredpixeldungeon.items.potions.Potion;
|
||||
import com.shatteredpixel.shatteredpixeldungeon.ui.LootIndicator;
|
||||
import com.shatteredpixel.shatteredpixeldungeon.ui.ResumeIndicator;
|
||||
import com.watabou.noosa.Camera;
|
||||
|
@ -307,6 +310,23 @@ public class GameScene extends PixelScene {
|
|||
default:
|
||||
}
|
||||
|
||||
ArrayList<Item> dropped = Dungeon.droppedItems.get( Dungeon.depth );
|
||||
if (dropped != null) {
|
||||
for (Item item : dropped) {
|
||||
int pos = Dungeon.level.randomRespawnCell();
|
||||
if (item instanceof Potion) {
|
||||
((Potion)item).shatter( pos );
|
||||
} else if (item instanceof Plant.Seed) {
|
||||
Dungeon.level.plant( (Plant.Seed)item, pos );
|
||||
} else if (item instanceof Honeypot) {
|
||||
(Honeypot)item.shatter( pos );
|
||||
} else {
|
||||
Dungeon.level.drop( item, pos );
|
||||
}
|
||||
}
|
||||
Dungeon.droppedItems.remove( Dungeon.depth );
|
||||
}
|
||||
|
||||
Camera.main.target = hero;
|
||||
fadeIn();
|
||||
}
|
||||
|
|
|
@ -22,8 +22,6 @@ import com.shatteredpixel.shatteredpixeldungeon.Dungeon;
|
|||
import com.shatteredpixel.shatteredpixeldungeon.Statistics;
|
||||
import com.shatteredpixel.shatteredpixeldungeon.actors.Actor;
|
||||
import com.shatteredpixel.shatteredpixeldungeon.items.Generator;
|
||||
import com.shatteredpixel.shatteredpixeldungeon.items.Item;
|
||||
import com.shatteredpixel.shatteredpixeldungeon.items.potions.Potion;
|
||||
import com.shatteredpixel.shatteredpixeldungeon.levels.Level;
|
||||
import com.shatteredpixel.shatteredpixeldungeon.windows.WndError;
|
||||
import com.shatteredpixel.shatteredpixeldungeon.windows.WndStory;
|
||||
|
@ -35,7 +33,6 @@ import com.watabou.noosa.audio.Sample;
|
|||
|
||||
import java.io.FileNotFoundException;
|
||||
import java.io.IOException;
|
||||
import java.util.ArrayList;
|
||||
|
||||
public class InterlevelScene extends PixelScene {
|
||||
|
||||
|
@ -212,9 +209,6 @@ public class InterlevelScene extends PixelScene {
|
|||
|
||||
private void descend() throws IOException {
|
||||
|
||||
Level level;
|
||||
ArrayList<Item> fallingItems = new ArrayList<Item>();
|
||||
|
||||
Actor.fixTime();
|
||||
if (Dungeon.hero == null) {
|
||||
Dungeon.init();
|
||||
|
@ -223,64 +217,31 @@ public class InterlevelScene extends PixelScene {
|
|||
noStory = false;
|
||||
}
|
||||
} else {
|
||||
level = Dungeon.level;
|
||||
|
||||
fallingItems = level.fallingItems;
|
||||
level.fallingItems = new ArrayList<Item>();
|
||||
|
||||
Dungeon.saveLevel();
|
||||
}
|
||||
|
||||
Level level;
|
||||
if (Dungeon.depth >= Statistics.deepestFloor) {
|
||||
level = Dungeon.newLevel();
|
||||
} else {
|
||||
Dungeon.depth++;
|
||||
level = Dungeon.loadLevel( Dungeon.hero.heroClass );
|
||||
}
|
||||
|
||||
for (Item item : fallingItems){
|
||||
int cell = level.randomRespawnCell();
|
||||
while (cell == -1)
|
||||
cell = level.randomRespawnCell();
|
||||
|
||||
if (!(item instanceof Potion))
|
||||
level.drop(item, cell);
|
||||
else
|
||||
level.fallingPotions.add((Potion)item);
|
||||
}
|
||||
|
||||
Dungeon.switchLevel( level, level.entrance );
|
||||
|
||||
}
|
||||
|
||||
private void fall() throws IOException {
|
||||
|
||||
Level level = Dungeon.level;
|
||||
|
||||
ArrayList<Item> fallingItems = level.fallingItems;
|
||||
level.fallingItems = new ArrayList<Item>();
|
||||
|
||||
Actor.fixTime();
|
||||
Dungeon.saveLevel();
|
||||
|
||||
Level level;
|
||||
if (Dungeon.depth >= Statistics.deepestFloor) {
|
||||
level = Dungeon.newLevel();
|
||||
} else {
|
||||
Dungeon.depth++;
|
||||
level = Dungeon.loadLevel( Dungeon.hero.heroClass );
|
||||
}
|
||||
|
||||
for (Item item : fallingItems){
|
||||
int cell = level.randomRespawnCell();
|
||||
while (cell == -1)
|
||||
cell = level.randomRespawnCell();
|
||||
|
||||
if (!(item instanceof Potion))
|
||||
level.drop(item, cell);
|
||||
else
|
||||
level.fallingPotions.add((Potion)item);
|
||||
}
|
||||
|
||||
Dungeon.switchLevel( level, fallIntoPit ? level.pitCell() : level.randomRespawnCell() );
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue
Block a user