use of com.shatteredpixel.shatteredpixeldungeon.items.Heap in project shattered-pixel-dungeon-gdx by 00-Evan.
the class RegularLevel method createItems.
@Override
protected void createItems() {
// drops 3/4/5 items 60%/30%/10% of the time
int nItems = 3 + Random.chances(new float[] { 6, 3, 1 });
for (int i = 0; i < nItems; i++) {
Heap.Type type = null;
switch(Random.Int(20)) {
case 0:
type = Heap.Type.SKELETON;
break;
case 1:
case 2:
case 3:
case 4:
type = Heap.Type.CHEST;
break;
case 5:
type = Dungeon.depth > 1 ? Heap.Type.MIMIC : Heap.Type.CHEST;
break;
default:
type = Heap.Type.HEAP;
}
int cell = randomDropCell();
if (map[cell] == Terrain.HIGH_GRASS) {
map[cell] = Terrain.GRASS;
losBlocking[cell] = false;
}
Item toDrop = Generator.random();
if (toDrop == null)
continue;
if ((toDrop instanceof Artifact && Random.Int(2) == 0) || (toDrop.isUpgradable() && Random.Int(4 - toDrop.level()) == 0)) {
Heap dropped = drop(toDrop, cell);
if (heaps.get(cell) == dropped) {
dropped.type = Heap.Type.LOCKED_CHEST;
addItemToSpawn(new GoldenKey(Dungeon.depth));
}
} else {
drop(toDrop, cell).type = type;
}
}
for (Item item : itemsToSpawn) {
int cell = randomDropCell();
drop(item, cell).type = Heap.Type.HEAP;
if (map[cell] == Terrain.HIGH_GRASS) {
map[cell] = Terrain.GRASS;
losBlocking[cell] = false;
}
}
Item item = Bones.get();
if (item != null) {
int cell = randomDropCell();
if (map[cell] == Terrain.HIGH_GRASS) {
map[cell] = Terrain.GRASS;
losBlocking[cell] = false;
}
drop(item, cell).type = Heap.Type.REMAINS;
}
// guide pages
Collection<String> allPages = Document.ADVENTURERS_GUIDE.pages();
ArrayList<String> missingPages = new ArrayList<>();
for (String page : allPages) {
if (!Document.ADVENTURERS_GUIDE.hasPage(page)) {
missingPages.add(page);
}
}
// these are dropped specially
missingPages.remove(Document.GUIDE_INTRO_PAGE);
missingPages.remove(Document.GUIDE_SEARCH_PAGE);
int foundPages = allPages.size() - (missingPages.size() + 2);
// chance to find a page scales with pages missing and depth
if (missingPages.size() > 0 && Random.Float() < (Dungeon.depth / (float) (foundPages + 1))) {
GuidePage p = new GuidePage();
p.page(missingPages.get(0));
int cell = randomDropCell();
if (map[cell] == Terrain.HIGH_GRASS) {
map[cell] = Terrain.GRASS;
losBlocking[cell] = false;
}
drop(p, cell);
}
}
use of com.shatteredpixel.shatteredpixeldungeon.items.Heap in project shattered-pixel-dungeon-gdx by 00-Evan.
the class MassGraveRoom method paint.
public void paint(Level level) {
Door entrance = entrance();
entrance.set(Door.Type.BARRICADE);
level.addItemToSpawn(new PotionOfLiquidFlame());
Painter.fill(level, this, Terrain.WALL);
Painter.fill(level, this, 1, Terrain.EMPTY_SP);
Bones b = new Bones();
b.setRect(left + 1, top, width() - 2, height() - 1);
level.customTiles.add(b);
// 50% 1 skeleton, 50% 2 skeletons
for (int i = 0; i <= Random.Int(2); i++) {
Skeleton skele = new Skeleton();
int pos;
do {
pos = level.pointToCell(random());
} while (level.map[pos] != Terrain.EMPTY_SP || level.findMob(pos) != null);
skele.pos = pos;
level.mobs.add(skele);
}
ArrayList<Item> items = new ArrayList<>();
// 100% corpse dust, 2x100% 1 coin, 2x30% coins, 1x60% random item, 1x30% armor
items.add(new CorpseDust());
items.add(new Gold(1));
items.add(new Gold(1));
if (Random.Float() <= 0.3f)
items.add(new Gold());
if (Random.Float() <= 0.3f)
items.add(new Gold());
if (Random.Float() <= 0.6f)
items.add(Generator.random());
if (Random.Float() <= 0.3f)
items.add(Generator.randomArmor());
for (Item item : items) {
int pos;
do {
pos = level.pointToCell(random());
} while (level.map[pos] != Terrain.EMPTY_SP || level.heaps.get(pos) != null);
Heap h = level.drop(item, pos);
h.type = Heap.Type.SKELETON;
}
}
use of com.shatteredpixel.shatteredpixeldungeon.items.Heap in project shattered-pixel-dungeon-gdx by 00-Evan.
the class Dungeon method observe.
public static void observe(int dist) {
if (level == null) {
return;
}
level.updateFieldOfView(hero, level.heroFOV);
int x = hero.pos % level.width();
int y = hero.pos / level.width();
// left, right, top, bottom
int l = Math.max(0, x - dist);
int r = Math.min(x + dist, level.width() - 1);
int t = Math.max(0, y - dist);
int b = Math.min(y + dist, level.height() - 1);
int width = r - l + 1;
int height = b - t + 1;
int pos = l + t * level.width();
for (int i = t; i <= b; i++) {
BArray.or(level.visited, level.heroFOV, pos, width, level.visited);
pos += level.width();
}
GameScene.updateFog(l, t, width, height);
if (hero.buff(MindVision.class) != null) {
for (Mob m : level.mobs.toArray(new Mob[0])) {
BArray.or(level.visited, level.heroFOV, m.pos - 1 - level.width(), 3, level.visited);
BArray.or(level.visited, level.heroFOV, m.pos, 3, level.visited);
BArray.or(level.visited, level.heroFOV, m.pos - 1 + level.width(), 3, level.visited);
// updates adjacent cells too
GameScene.updateFog(m.pos, 2);
}
}
if (hero.buff(Awareness.class) != null) {
for (Heap h : level.heaps.values()) {
BArray.or(level.visited, level.heroFOV, h.pos - 1 - level.width(), 3, level.visited);
BArray.or(level.visited, level.heroFOV, h.pos - 1, 3, level.visited);
BArray.or(level.visited, level.heroFOV, h.pos - 1 + level.width(), 3, level.visited);
GameScene.updateFog(h.pos, 2);
}
}
GameScene.afterObserve();
}
use of com.shatteredpixel.shatteredpixeldungeon.items.Heap in project shattered-pixel-dungeon-gdx by 00-Evan.
the class ImpShopkeeper method flee.
@Override
public void flee() {
for (Heap heap : Dungeon.level.heaps.values()) {
if (heap.type == Heap.Type.FOR_SALE) {
CellEmitter.get(heap.pos).burst(ElmoParticle.FACTORY, 4);
heap.destroy();
}
}
destroy();
sprite.emitter().burst(Speck.factory(Speck.WOOL), 15);
sprite.killAndErase();
}
use of com.shatteredpixel.shatteredpixeldungeon.items.Heap in project shattered-pixel-dungeon-gdx by 00-Evan.
the class NPC method throwItem.
protected void throwItem() {
Heap heap = Dungeon.level.heaps.get(pos);
if (heap != null) {
int n;
do {
n = pos + PathFinder.NEIGHBOURS8[Random.Int(8)];
} while (!Dungeon.level.passable[n] && !Dungeon.level.avoid[n]);
Dungeon.level.drop(heap.pickUp(), n).sprite.drop(pos);
}
}
Aggregations