use of com.nyrds.android.util.TrackedRuntimeException in project pixel-dungeon-remix by NYRDS.
the class ChaosStaff method onZap.
@Override
protected void onZap(int cell) {
ChaosCommon.doChaosMark(cell, 10 + level() * 10 + charge);
charge = 0;
if (Math.random() < 0.1f) {
Char ch = Actor.findChar(cell);
if (ch instanceof Mob) {
Mob mob = (Mob) ch;
if ((mob instanceof Boss) || (mob instanceof NPC)) {
return;
}
switch(Random.Int(0, 4)) {
case 0:
mob.die(getCurUser());
break;
case 1:
Mob.makePet(mob, getCurUser());
break;
case 2:
int nextCell = Dungeon.level.getEmptyCellNextTo(cell);
if (Dungeon.level.cellValid(nextCell)) {
try {
Mob newMob = mob.getClass().newInstance();
Dungeon.level.spawnMob(newMob);
} catch (Exception e) {
throw new TrackedRuntimeException(e);
}
}
break;
case 3:
WandOfTeleportation.teleport(mob);
break;
case 4:
PotionOfHealing.heal(ch, 1);
break;
}
}
}
}
use of com.nyrds.android.util.TrackedRuntimeException in project pixel-dungeon-remix by NYRDS.
the class Level method fillAreaWith.
public void fillAreaWith(Class<? extends Blob> blobClass, int x, int y, int xs, int ys, int amount) {
Blob blob = Dungeon.level.blobs.get(blobClass);
if (blob == null) {
try {
blob = blobClass.newInstance();
} catch (Exception e) {
throw new TrackedRuntimeException(e);
}
GameScene.add(blob);
}
for (int i = x; i <= x + xs; i++) {
for (int j = y; j <= y + ys; j++) {
if (cellValid(i, j)) {
blob.seed(i, j, amount);
}
}
}
blobs.put(blobClass, blob);
}
use of com.nyrds.android.util.TrackedRuntimeException in project pixel-dungeon-remix by NYRDS.
the class MagicWellPainter method paint.
public static void paint(Level level, Room room) {
fill(level, room, Terrain.WALL);
fill(level, room, 1, Terrain.EMPTY);
Point c = room.center();
set(level, c.x, c.y, Terrain.WELL);
@SuppressWarnings("unchecked") Class<? extends WellWater> waterClass = Dungeon.depth >= Dungeon.transmutation ? WaterOfTransmutation.class : (Class<? extends WellWater>) Random.element(WATERS);
if (waterClass == WaterOfTransmutation.class) {
Dungeon.transmutation = Integer.MAX_VALUE;
}
WellWater water = (WellWater) level.blobs.get(waterClass);
if (water == null) {
try {
water = waterClass.newInstance();
} catch (Exception e) {
throw new TrackedRuntimeException(e);
}
}
water.seed(c.x + level.getWidth() * c.y, 1);
level.blobs.put(waterClass, water);
room.entrance().set(Room.Door.Type.REGULAR);
}
use of com.nyrds.android.util.TrackedRuntimeException in project pixel-dungeon-remix by NYRDS.
the class DungeonGenerator method createLevel.
public static Level createLevel(Position pos) {
Class<? extends Level> levelClass = mLevelKindList.get(getLevelKind(pos.levelId));
if (levelClass == null) {
GLog.w("Unknown level type: %s", getLevelKind(pos.levelId));
return createLevel(pos);
}
try {
Level ret;
String levelId = pos.levelId;
if (levelClass == PredesignedLevel.class) {
String levelFile = mLevels.getJSONObject(levelId).getString("file");
ret = new PredesignedLevel(levelFile);
} else if (levelClass == RandomLevel.class) {
String levelFile = mLevels.getJSONObject(levelId).getString("file");
ret = new RandomLevel(levelFile);
} else {
ret = levelClass.newInstance();
}
ret.levelId = levelId;
JSONObject levelDesc = mLevels.getJSONObject(pos.levelId);
int xs = 32;
int ys = 32;
if (levelDesc.has("size")) {
JSONArray levelSize = levelDesc.getJSONArray("size");
xs = levelSize.optInt(0, 32);
ys = levelSize.optInt(1, 32);
}
ret.create(xs, ys);
return ret;
} catch (InstantiationException | IllegalAccessException | JSONException e) {
throw new TrackedRuntimeException(e);
}
}
use of com.nyrds.android.util.TrackedRuntimeException in project pixel-dungeon-remix by NYRDS.
the class DungeonGenerator method descendOrAscend.
private static Position descendOrAscend(Position current, boolean descend) {
try {
if (current.levelId.equals("unknown")) {
current.levelId = "1";
}
JSONArray currentLevel = mGraph.getJSONArray(current.levelId);
JSONArray nextLevelSet = currentLevel.getJSONArray(descend ? 0 : 1);
Position next = new Position();
int index = 0;
next.cellId = -1;
if (descend && !current.levelId.equals(getEntryLevel())) {
if (Dungeon.level != null) {
// not first descend
if (Dungeon.level.isExit(current.cellId)) {
index = Dungeon.level.exitIndex(current.cellId);
next.cellId = -(index + 1);
}
}
}
if (!descend) {
if (currentLevel.length() > 2) {
int exitIndex = currentLevel.getJSONArray(2).getInt(0);
next.cellId = -exitIndex;
}
}
if (index >= nextLevelSet.length()) {
index = 0;
EventCollector.logEvent("DungeonGenerator", "wrong next level index");
}
mCurrentLevelId = nextLevelSet.optString(index, "0");
JSONObject nextLevelDesc = mLevels.getJSONObject(mCurrentLevelId);
next.levelId = mCurrentLevelId;
mCurrentLevelDepth = nextLevelDesc.optInt("depth", 0);
mCurrentLevelKind = getLevelKind(next.levelId);
return next;
} catch (JSONException e) {
throw new TrackedRuntimeException(e);
}
}
Aggregations