v0.7.5: replaced all uses of java reflection with LibGDX reflection
This commit is contained in:
parent
0724717abf
commit
48d2fc77fe
|
@ -24,6 +24,7 @@ package com.watabou.glscripts;
|
||||||
import com.watabou.glwrap.Program;
|
import com.watabou.glwrap.Program;
|
||||||
import com.watabou.glwrap.Shader;
|
import com.watabou.glwrap.Shader;
|
||||||
import com.watabou.noosa.Game;
|
import com.watabou.noosa.Game;
|
||||||
|
import com.watabou.utils.Reflection;
|
||||||
|
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
|
|
||||||
|
@ -42,11 +43,7 @@ public class Script extends Program {
|
||||||
|
|
||||||
Script script = all.get( c );
|
Script script = all.get( c );
|
||||||
if (script == null) {
|
if (script == null) {
|
||||||
try {
|
script = Reflection.newInstance( c );
|
||||||
script = c.newInstance();
|
|
||||||
} catch (Exception e) {
|
|
||||||
Game.reportException(e);
|
|
||||||
}
|
|
||||||
all.put( c, script );
|
all.put( c, script );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -33,6 +33,7 @@ import com.watabou.input.KeyEvent;
|
||||||
import com.watabou.noosa.audio.Music;
|
import com.watabou.noosa.audio.Music;
|
||||||
import com.watabou.noosa.audio.Sample;
|
import com.watabou.noosa.audio.Sample;
|
||||||
import com.watabou.utils.PlatformSupport;
|
import com.watabou.utils.PlatformSupport;
|
||||||
|
import com.watabou.utils.Reflection;
|
||||||
|
|
||||||
import java.io.PrintWriter;
|
import java.io.PrintWriter;
|
||||||
import java.io.StringWriter;
|
import java.io.StringWriter;
|
||||||
|
@ -187,14 +188,10 @@ public class Game implements ApplicationListener {
|
||||||
|
|
||||||
if (requestedReset) {
|
if (requestedReset) {
|
||||||
requestedReset = false;
|
requestedReset = false;
|
||||||
|
|
||||||
try {
|
requestedScene = Reflection.newInstance(sceneClass);
|
||||||
requestedScene = sceneClass.newInstance();
|
if (requestedScene != null){
|
||||||
switchScene();
|
switchScene();
|
||||||
} catch (InstantiationException e){
|
|
||||||
e.printStackTrace();
|
|
||||||
} catch (IllegalAccessException e) {
|
|
||||||
e.printStackTrace();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -23,6 +23,7 @@ package com.watabou.noosa;
|
||||||
|
|
||||||
import com.watabou.noosa.particles.Emitter;
|
import com.watabou.noosa.particles.Emitter;
|
||||||
import com.watabou.utils.Random;
|
import com.watabou.utils.Random;
|
||||||
|
import com.watabou.utils.Reflection;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
|
|
||||||
|
@ -190,11 +191,11 @@ public class Group extends Gizmo {
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
|
|
||||||
try {
|
g = Reflection.newInstance(c);
|
||||||
return add( c.newInstance() );
|
if (g != null) {
|
||||||
} catch (Exception e) {
|
return add(g);
|
||||||
Game.reportException(e);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return null;
|
return null;
|
||||||
|
|
|
@ -97,13 +97,8 @@ public class Bundle {
|
||||||
if (aliases.containsKey( clName )) {
|
if (aliases.containsKey( clName )) {
|
||||||
clName = aliases.get( clName );
|
clName = aliases.get( clName );
|
||||||
}
|
}
|
||||||
try {
|
|
||||||
Class cl = Class.forName( clName );
|
return Reflection.forName( clName );
|
||||||
return cl;
|
|
||||||
} catch (ClassNotFoundException e) {
|
|
||||||
Game.reportException(e);
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
@ -114,30 +109,24 @@ public class Bundle {
|
||||||
|
|
||||||
private Bundlable get() {
|
private Bundlable get() {
|
||||||
if (data == null) return null;
|
if (data == null) return null;
|
||||||
try {
|
|
||||||
String clName = getString( CLASS_NAME );
|
String clName = getString( CLASS_NAME );
|
||||||
if (aliases.containsKey( clName )) {
|
if (aliases.containsKey( clName )) {
|
||||||
clName = aliases.get( clName );
|
clName = aliases.get( clName );
|
||||||
}
|
|
||||||
|
|
||||||
Class<?> cl = Class.forName( clName );
|
|
||||||
if (cl != null && (!cl.isMemberClass() || Modifier.isStatic(cl.getModifiers()))) {
|
|
||||||
Bundlable object = (Bundlable)cl.newInstance();
|
|
||||||
object.restoreFromBundle( this );
|
|
||||||
return object;
|
|
||||||
} else {
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
} catch (ClassNotFoundException e ) {
|
|
||||||
Game.reportException(e);
|
|
||||||
return null;
|
|
||||||
} catch (InstantiationException e ) {
|
|
||||||
Game.reportException(e);
|
|
||||||
return null;
|
|
||||||
} catch (IllegalAccessException e ) {
|
|
||||||
Game.reportException(e);
|
|
||||||
return null;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Class<?> cl = Reflection.forName( clName );
|
||||||
|
//Skip none-static inner classes as they can't be instantiated through bundle restoring
|
||||||
|
//Classes which make use of none-static inner classes must manage instantiation manually
|
||||||
|
if (cl != null && (!Reflection.isMemberClass(cl) || Reflection.isStatic(cl))) {
|
||||||
|
Bundlable object = (Bundlable) Reflection.newInstance(cl);
|
||||||
|
if (object != null) {
|
||||||
|
object.restoreFromBundle(this);
|
||||||
|
return object;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
public Bundlable get( String key ) {
|
public Bundlable get( String key ) {
|
||||||
|
@ -226,13 +215,8 @@ public class Bundle {
|
||||||
if (aliases.containsKey( clName )) {
|
if (aliases.containsKey( clName )) {
|
||||||
clName = aliases.get( clName );
|
clName = aliases.get( clName );
|
||||||
}
|
}
|
||||||
try {
|
Class cl = Reflection.forName( clName );
|
||||||
Class cl = Class.forName( clName );
|
result[i] = cl;
|
||||||
result[i] = cl;
|
|
||||||
} catch (ClassNotFoundException e) {
|
|
||||||
Game.reportException(e);
|
|
||||||
result[i] = null;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
return result;
|
return result;
|
||||||
} catch (JSONException e) {
|
} catch (JSONException e) {
|
||||||
|
@ -404,7 +388,7 @@ public class Bundle {
|
||||||
//Classes which make use of none-static inner classes must manage instantiation manually
|
//Classes which make use of none-static inner classes must manage instantiation manually
|
||||||
if (object != null) {
|
if (object != null) {
|
||||||
Class cl = object.getClass();
|
Class cl = object.getClass();
|
||||||
if (!cl.isMemberClass() || Modifier.isStatic(cl.getModifiers())) {
|
if ((!Reflection.isMemberClass(cl) || Reflection.isStatic(cl))) {
|
||||||
Bundle bundle = new Bundle();
|
Bundle bundle = new Bundle();
|
||||||
bundle.put(CLASS_NAME, cl.getName());
|
bundle.put(CLASS_NAME, cl.getName());
|
||||||
object.storeInBundle(bundle);
|
object.storeInBundle(bundle);
|
||||||
|
|
65
SPD-classes/src/main/java/com/watabou/utils/Reflection.java
Normal file
65
SPD-classes/src/main/java/com/watabou/utils/Reflection.java
Normal file
|
@ -0,0 +1,65 @@
|
||||||
|
/*
|
||||||
|
* Pixel Dungeon
|
||||||
|
* Copyright (C) 2012-2015 Oleg Dolya
|
||||||
|
*
|
||||||
|
* Shattered Pixel Dungeon
|
||||||
|
* Copyright (C) 2014-2019 Evan Debenham
|
||||||
|
*
|
||||||
|
* This program is free software: you can redistribute it and/or modify
|
||||||
|
* it under the terms of the GNU General Public License as published by
|
||||||
|
* the Free Software Foundation, either version 3 of the License, or
|
||||||
|
* (at your option) any later version.
|
||||||
|
*
|
||||||
|
* This program is distributed in the hope that it will be useful,
|
||||||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
* GNU General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU General Public License
|
||||||
|
* along with this program. If not, see <http://www.gnu.org/licenses/>
|
||||||
|
*/
|
||||||
|
|
||||||
|
package com.watabou.utils;
|
||||||
|
|
||||||
|
import com.badlogic.gdx.utils.reflect.ClassReflection;
|
||||||
|
import com.badlogic.gdx.utils.reflect.ReflectionException;
|
||||||
|
import com.watabou.noosa.Game;
|
||||||
|
|
||||||
|
//wrapper for LibGDX reflection
|
||||||
|
public class Reflection {
|
||||||
|
|
||||||
|
public static boolean isMemberClass( Class cls ){
|
||||||
|
return ClassReflection.isMemberClass(cls);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static boolean isStatic( Class cls ){
|
||||||
|
return ClassReflection.isStaticClass(cls);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static <T> T newInstance( Class<T> cls ){
|
||||||
|
try {
|
||||||
|
return ClassReflection.newInstance(cls);
|
||||||
|
} catch (ReflectionException e) {
|
||||||
|
Game.reportException(e);
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public static <T> T newInstanceUnhandled( Class<T> cls ) throws Exception {
|
||||||
|
return ClassReflection.newInstance(cls);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static Class forName( String name ){
|
||||||
|
try {
|
||||||
|
return ClassReflection.forName( name );
|
||||||
|
} catch (ReflectionException e) {
|
||||||
|
Game.reportException(e);
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public static Class forNameUnhandled( String name ) throws Exception {
|
||||||
|
return ClassReflection.forName( name );
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
|
@ -30,6 +30,7 @@ import com.shatteredpixel.shatteredpixeldungeon.items.weapon.missiles.MissileWea
|
||||||
import com.watabou.utils.Bundle;
|
import com.watabou.utils.Bundle;
|
||||||
import com.watabou.utils.FileUtils;
|
import com.watabou.utils.FileUtils;
|
||||||
import com.watabou.utils.Random;
|
import com.watabou.utils.Random;
|
||||||
|
import com.watabou.utils.Reflection;
|
||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
|
@ -145,18 +146,19 @@ public class Bones {
|
||||||
//Enforces artifact uniqueness
|
//Enforces artifact uniqueness
|
||||||
if (item instanceof Artifact){
|
if (item instanceof Artifact){
|
||||||
if (Generator.removeArtifact(((Artifact)item).getClass())) {
|
if (Generator.removeArtifact(((Artifact)item).getClass())) {
|
||||||
try {
|
|
||||||
//generates a new artifact of the same type, always +0
|
//generates a new artifact of the same type, always +0
|
||||||
Artifact artifact = (Artifact)item.getClass().newInstance();
|
Artifact artifact = Reflection.newInstance(((Artifact)item).getClass());
|
||||||
|
|
||||||
artifact.cursed = true;
|
if (artifact == null){
|
||||||
artifact.cursedKnown = true;
|
|
||||||
|
|
||||||
return artifact;
|
|
||||||
} catch (Exception e) {
|
|
||||||
ShatteredPixelDungeon.reportException(e);
|
|
||||||
return new Gold(item.price());
|
return new Gold(item.price());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
artifact.cursed = true;
|
||||||
|
artifact.cursedKnown = true;
|
||||||
|
|
||||||
|
return artifact;
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
return new Gold(item.price());
|
return new Gold(item.price());
|
||||||
}
|
}
|
||||||
|
|
|
@ -28,6 +28,7 @@ import com.shatteredpixel.shatteredpixeldungeon.effects.BlobEmitter;
|
||||||
import com.shatteredpixel.shatteredpixeldungeon.levels.Level;
|
import com.shatteredpixel.shatteredpixeldungeon.levels.Level;
|
||||||
import com.watabou.utils.Bundle;
|
import com.watabou.utils.Bundle;
|
||||||
import com.watabou.utils.Rect;
|
import com.watabou.utils.Rect;
|
||||||
|
import com.watabou.utils.Reflection;
|
||||||
|
|
||||||
public class Blob extends Actor {
|
public class Blob extends Actor {
|
||||||
|
|
||||||
|
@ -223,22 +224,19 @@ public class Blob extends Actor {
|
||||||
|
|
||||||
@SuppressWarnings("unchecked")
|
@SuppressWarnings("unchecked")
|
||||||
public static<T extends Blob> T seed( int cell, int amount, Class<T> type, Level level ) {
|
public static<T extends Blob> T seed( int cell, int amount, Class<T> type, Level level ) {
|
||||||
try {
|
|
||||||
|
T gas = (T)level.blobs.get( type );
|
||||||
T gas = (T)level.blobs.get( type );
|
|
||||||
if (gas == null) {
|
if (gas == null) {
|
||||||
gas = type.newInstance();
|
gas = Reflection.newInstance(type);
|
||||||
level.blobs.put( type, gas );
|
|
||||||
}
|
|
||||||
|
|
||||||
gas.seed( level, cell, amount );
|
|
||||||
|
|
||||||
return gas;
|
|
||||||
|
|
||||||
} catch (Exception e) {
|
|
||||||
ShatteredPixelDungeon.reportException(e);
|
|
||||||
return null;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (gas != null){
|
||||||
|
level.blobs.put( type, gas );
|
||||||
|
gas.seed( level, cell, amount );
|
||||||
|
}
|
||||||
|
|
||||||
|
return gas;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static int volumeAt( int cell, Class<? extends Blob> type){
|
public static int volumeAt( int cell, Class<? extends Blob> type){
|
||||||
|
|
|
@ -44,6 +44,7 @@ import com.shatteredpixel.shatteredpixeldungeon.journal.Notes.Landmark;
|
||||||
import com.shatteredpixel.shatteredpixeldungeon.messages.Messages;
|
import com.shatteredpixel.shatteredpixeldungeon.messages.Messages;
|
||||||
import com.shatteredpixel.shatteredpixeldungeon.plants.Plant;
|
import com.shatteredpixel.shatteredpixeldungeon.plants.Plant;
|
||||||
import com.watabou.utils.Random;
|
import com.watabou.utils.Random;
|
||||||
|
import com.watabou.utils.Reflection;
|
||||||
|
|
||||||
public class WaterOfTransmutation extends WellWater {
|
public class WaterOfTransmutation extends WellWater {
|
||||||
|
|
||||||
|
@ -119,12 +120,7 @@ public class WaterOfTransmutation extends WellWater {
|
||||||
Category c = Generator.wepTiers[w.tier-1];
|
Category c = Generator.wepTiers[w.tier-1];
|
||||||
|
|
||||||
do {
|
do {
|
||||||
try {
|
n = (MeleeWeapon)Reflection.newInstance(c.classes[Random.chances(c.probs)]);
|
||||||
n = (MeleeWeapon)c.classes[Random.chances(c.probs)].newInstance();
|
|
||||||
} catch (Exception e) {
|
|
||||||
ShatteredPixelDungeon.reportException(e);
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
} while (Challenges.isItemBlocked(n) || n.getClass() == w.getClass());
|
} while (Challenges.isItemBlocked(n) || n.getClass() == w.getClass());
|
||||||
|
|
||||||
int level = w.level();
|
int level = w.level();
|
||||||
|
|
|
@ -26,6 +26,7 @@ import com.shatteredpixel.shatteredpixeldungeon.actors.Actor;
|
||||||
import com.shatteredpixel.shatteredpixeldungeon.actors.Char;
|
import com.shatteredpixel.shatteredpixeldungeon.actors.Char;
|
||||||
import com.shatteredpixel.shatteredpixeldungeon.ui.BuffIndicator;
|
import com.shatteredpixel.shatteredpixeldungeon.ui.BuffIndicator;
|
||||||
import com.watabou.noosa.Image;
|
import com.watabou.noosa.Image;
|
||||||
|
import com.watabou.utils.Reflection;
|
||||||
|
|
||||||
import java.text.DecimalFormat;
|
import java.text.DecimalFormat;
|
||||||
import java.util.HashSet;
|
import java.util.HashSet;
|
||||||
|
@ -113,14 +114,9 @@ public class Buff extends Actor {
|
||||||
|
|
||||||
//creates a fresh instance of the buff and attaches that, this allows duplication.
|
//creates a fresh instance of the buff and attaches that, this allows duplication.
|
||||||
public static<T extends Buff> T append( Char target, Class<T> buffClass ) {
|
public static<T extends Buff> T append( Char target, Class<T> buffClass ) {
|
||||||
try {
|
T buff = Reflection.newInstance(buffClass);
|
||||||
T buff = buffClass.newInstance();
|
buff.attachTo( target );
|
||||||
buff.attachTo( target );
|
return buff;
|
||||||
return buff;
|
|
||||||
} catch (Exception e) {
|
|
||||||
ShatteredPixelDungeon.reportException(e);
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public static<T extends FlavourBuff> T append( Char target, Class<T> buffClass, float duration ) {
|
public static<T extends FlavourBuff> T append( Char target, Class<T> buffClass, float duration ) {
|
||||||
|
|
|
@ -63,6 +63,7 @@ import com.watabou.utils.Bundle;
|
||||||
import com.watabou.utils.GameMath;
|
import com.watabou.utils.GameMath;
|
||||||
import com.watabou.utils.PathFinder;
|
import com.watabou.utils.PathFinder;
|
||||||
import com.watabou.utils.Random;
|
import com.watabou.utils.Random;
|
||||||
|
import com.watabou.utils.Reflection;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.Collections;
|
import java.util.Collections;
|
||||||
|
@ -153,13 +154,7 @@ public abstract class Mob extends Char {
|
||||||
}
|
}
|
||||||
|
|
||||||
public CharSprite sprite() {
|
public CharSprite sprite() {
|
||||||
CharSprite sprite = null;
|
return Reflection.newInstance(spriteClass);
|
||||||
try {
|
|
||||||
sprite = spriteClass.newInstance();
|
|
||||||
} catch (Exception e) {
|
|
||||||
ShatteredPixelDungeon.reportException(e);
|
|
||||||
}
|
|
||||||
return sprite;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|
|
@ -28,6 +28,7 @@ import com.shatteredpixel.shatteredpixeldungeon.items.Item;
|
||||||
import com.shatteredpixel.shatteredpixeldungeon.items.weapon.melee.MeleeWeapon;
|
import com.shatteredpixel.shatteredpixeldungeon.items.weapon.melee.MeleeWeapon;
|
||||||
import com.shatteredpixel.shatteredpixeldungeon.sprites.SlimeSprite;
|
import com.shatteredpixel.shatteredpixeldungeon.sprites.SlimeSprite;
|
||||||
import com.watabou.utils.Random;
|
import com.watabou.utils.Random;
|
||||||
|
import com.watabou.utils.Reflection;
|
||||||
|
|
||||||
public class Slime extends Mob {
|
public class Slime extends Mob {
|
||||||
|
|
||||||
|
@ -78,15 +79,10 @@ public class Slime extends Mob {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected Item createLoot() {
|
protected Item createLoot() {
|
||||||
try {
|
Generator.Category c = Generator.Category.WEP_T2;
|
||||||
Generator.Category c = Generator.Category.WEP_T2;
|
MeleeWeapon w = (MeleeWeapon) Reflection.newInstance(c.classes[Random.chances(c.probs)]);
|
||||||
MeleeWeapon w = (MeleeWeapon)c.classes[Random.chances(c.probs)].newInstance();
|
w.random();
|
||||||
w.random();
|
w.level(0);
|
||||||
w.level(0);
|
return w;
|
||||||
return w;
|
|
||||||
} catch (Exception e) {
|
|
||||||
ShatteredPixelDungeon.reportException(e);
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -54,6 +54,7 @@ import com.shatteredpixel.shatteredpixeldungeon.windows.WndSadGhost;
|
||||||
import com.watabou.noosa.audio.Sample;
|
import com.watabou.noosa.audio.Sample;
|
||||||
import com.watabou.utils.Bundle;
|
import com.watabou.utils.Bundle;
|
||||||
import com.watabou.utils.Random;
|
import com.watabou.utils.Random;
|
||||||
|
import com.watabou.utils.Reflection;
|
||||||
|
|
||||||
public class Ghost extends NPC {
|
public class Ghost extends NPC {
|
||||||
|
|
||||||
|
@ -287,15 +288,9 @@ public class Ghost extends NPC {
|
||||||
wepTier = 5;
|
wepTier = 5;
|
||||||
armor = new PlateArmor();
|
armor = new PlateArmor();
|
||||||
}
|
}
|
||||||
|
|
||||||
try {
|
Generator.Category c = Generator.wepTiers[wepTier - 1];
|
||||||
do {
|
weapon = (MeleeWeapon) Reflection.newInstance(c.classes[Random.chances(c.probs)]);
|
||||||
weapon = (Weapon) Generator.wepTiers[wepTier - 1].classes[Random.chances(Generator.wepTiers[wepTier - 1].probs)].newInstance();
|
|
||||||
} while (!(weapon instanceof MeleeWeapon));
|
|
||||||
} catch (Exception e){
|
|
||||||
ShatteredPixelDungeon.reportException(e);
|
|
||||||
weapon = new Shortsword();
|
|
||||||
}
|
|
||||||
|
|
||||||
//50%:+0, 30%:+1, 15%:+2, 5%:+3
|
//50%:+0, 30%:+1, 15%:+2, 5%:+3
|
||||||
float itemLevelRoll = Random.Float();
|
float itemLevelRoll = Random.Float();
|
||||||
|
|
|
@ -171,6 +171,7 @@ import com.shatteredpixel.shatteredpixeldungeon.plants.Swiftthistle;
|
||||||
import com.watabou.utils.Bundle;
|
import com.watabou.utils.Bundle;
|
||||||
import com.watabou.utils.GameMath;
|
import com.watabou.utils.GameMath;
|
||||||
import com.watabou.utils.Random;
|
import com.watabou.utils.Random;
|
||||||
|
import com.watabou.utils.Reflection;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
|
@ -479,42 +480,24 @@ public class Generator {
|
||||||
}
|
}
|
||||||
|
|
||||||
public static Item random( Category cat ) {
|
public static Item random( Category cat ) {
|
||||||
try {
|
switch (cat) {
|
||||||
|
case ARMOR:
|
||||||
switch (cat) {
|
return randomArmor();
|
||||||
case ARMOR:
|
case WEAPON:
|
||||||
return randomArmor();
|
return randomWeapon();
|
||||||
case WEAPON:
|
case MISSILE:
|
||||||
return randomWeapon();
|
return randomMissile();
|
||||||
case MISSILE:
|
case ARTIFACT:
|
||||||
return randomMissile();
|
Item item = randomArtifact();
|
||||||
case ARTIFACT:
|
//if we're out of artifacts, return a ring instead.
|
||||||
Item item = randomArtifact();
|
return item != null ? item : random(Category.RING);
|
||||||
//if we're out of artifacts, return a ring instead.
|
default:
|
||||||
return item != null ? item : random(Category.RING);
|
return ((Item) Reflection.newInstance(cat.classes[Random.chances( cat.probs )])).random();
|
||||||
default:
|
|
||||||
return ((Item)cat.classes[Random.chances( cat.probs )].newInstance()).random();
|
|
||||||
}
|
|
||||||
|
|
||||||
} catch (Exception e) {
|
|
||||||
|
|
||||||
ShatteredPixelDungeon.reportException(e);
|
|
||||||
return null;
|
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public static Item random( Class<? extends Item> cl ) {
|
public static Item random( Class<? extends Item> cl ) {
|
||||||
try {
|
return Reflection.newInstance(cl).random();
|
||||||
|
|
||||||
return ((Item)cl.newInstance()).random();
|
|
||||||
|
|
||||||
} catch (Exception e) {
|
|
||||||
|
|
||||||
ShatteredPixelDungeon.reportException(e);
|
|
||||||
return null;
|
|
||||||
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public static Armor randomArmor(){
|
public static Armor randomArmor(){
|
||||||
|
@ -524,15 +507,10 @@ public class Generator {
|
||||||
public static Armor randomArmor(int floorSet) {
|
public static Armor randomArmor(int floorSet) {
|
||||||
|
|
||||||
floorSet = (int)GameMath.gate(0, floorSet, floorSetTierProbs.length-1);
|
floorSet = (int)GameMath.gate(0, floorSet, floorSetTierProbs.length-1);
|
||||||
|
|
||||||
try {
|
Armor a = (Armor)Reflection.newInstance(Category.ARMOR.classes[Random.chances(floorSetTierProbs[floorSet])]);
|
||||||
Armor a = (Armor)Category.ARMOR.classes[Random.chances(floorSetTierProbs[floorSet])].newInstance();
|
a.random();
|
||||||
a.random();
|
return a;
|
||||||
return a;
|
|
||||||
} catch (Exception e) {
|
|
||||||
ShatteredPixelDungeon.reportException(e);
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public static final Category[] wepTiers = new Category[]{
|
public static final Category[] wepTiers = new Category[]{
|
||||||
|
@ -550,16 +528,11 @@ public class Generator {
|
||||||
public static MeleeWeapon randomWeapon(int floorSet) {
|
public static MeleeWeapon randomWeapon(int floorSet) {
|
||||||
|
|
||||||
floorSet = (int)GameMath.gate(0, floorSet, floorSetTierProbs.length-1);
|
floorSet = (int)GameMath.gate(0, floorSet, floorSetTierProbs.length-1);
|
||||||
|
|
||||||
try {
|
Category c = wepTiers[Random.chances(floorSetTierProbs[floorSet])];
|
||||||
Category c = wepTiers[Random.chances(floorSetTierProbs[floorSet])];
|
MeleeWeapon w = (MeleeWeapon)Reflection.newInstance(c.classes[Random.chances(c.probs)]);
|
||||||
MeleeWeapon w = (MeleeWeapon)c.classes[Random.chances(c.probs)].newInstance();
|
w.random();
|
||||||
w.random();
|
return w;
|
||||||
return w;
|
|
||||||
} catch (Exception e) {
|
|
||||||
ShatteredPixelDungeon.reportException(e);
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public static final Category[] misTiers = new Category[]{
|
public static final Category[] misTiers = new Category[]{
|
||||||
|
@ -578,43 +551,30 @@ public class Generator {
|
||||||
|
|
||||||
floorSet = (int)GameMath.gate(0, floorSet, floorSetTierProbs.length-1);
|
floorSet = (int)GameMath.gate(0, floorSet, floorSetTierProbs.length-1);
|
||||||
|
|
||||||
try {
|
Category c = misTiers[Random.chances(floorSetTierProbs[floorSet])];
|
||||||
Category c = misTiers[Random.chances(floorSetTierProbs[floorSet])];
|
MissileWeapon w = (MissileWeapon)Reflection.newInstance(c.classes[Random.chances(c.probs)]);
|
||||||
MissileWeapon w = (MissileWeapon)c.classes[Random.chances(c.probs)].newInstance();
|
w.random();
|
||||||
w.random();
|
return w;
|
||||||
return w;
|
|
||||||
} catch (Exception e) {
|
|
||||||
ShatteredPixelDungeon.reportException(e);
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
//enforces uniqueness of artifacts throughout a run.
|
//enforces uniqueness of artifacts throughout a run.
|
||||||
public static Artifact randomArtifact() {
|
public static Artifact randomArtifact() {
|
||||||
|
|
||||||
try {
|
Category cat = Category.ARTIFACT;
|
||||||
Category cat = Category.ARTIFACT;
|
int i = Random.chances( cat.probs );
|
||||||
int i = Random.chances( cat.probs );
|
|
||||||
|
|
||||||
//if no artifacts are left, return null
|
//if no artifacts are left, return null
|
||||||
if (i == -1){
|
if (i == -1){
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
Class<?extends Artifact> art = (Class<? extends Artifact>) cat.classes[i];
|
Class<?extends Artifact> art = (Class<? extends Artifact>) cat.classes[i];
|
||||||
|
|
||||||
if (removeArtifact(art)) {
|
if (removeArtifact(art)) {
|
||||||
Artifact artifact = art.newInstance();
|
Artifact artifact = Reflection.newInstance(art);
|
||||||
|
artifact.random();
|
||||||
artifact.random();
|
return artifact;
|
||||||
|
} else {
|
||||||
return artifact;
|
|
||||||
} else {
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
} catch (Exception e) {
|
|
||||||
ShatteredPixelDungeon.reportException(e);
|
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -44,7 +44,9 @@ import com.watabou.noosa.particles.Emitter;
|
||||||
import com.watabou.utils.Bundlable;
|
import com.watabou.utils.Bundlable;
|
||||||
import com.watabou.utils.Bundle;
|
import com.watabou.utils.Bundle;
|
||||||
import com.watabou.utils.Callback;
|
import com.watabou.utils.Callback;
|
||||||
|
import com.watabou.utils.Reflection;
|
||||||
|
|
||||||
|
import java.sql.Ref;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.Collections;
|
import java.util.Collections;
|
||||||
import java.util.Comparator;
|
import java.util.Comparator;
|
||||||
|
@ -219,21 +221,20 @@ public class Item implements Bundlable {
|
||||||
if (amount <= 0 || amount >= quantity()) {
|
if (amount <= 0 || amount >= quantity()) {
|
||||||
return null;
|
return null;
|
||||||
} else {
|
} else {
|
||||||
try {
|
//pssh, who needs copy constructors?
|
||||||
|
Item split = Reflection.newInstance(getClass());
|
||||||
//pssh, who needs copy constructors?
|
|
||||||
Item split = getClass().newInstance();
|
if (split == null){
|
||||||
Bundle copy = new Bundle();
|
|
||||||
this.storeInBundle(copy);
|
|
||||||
split.restoreFromBundle(copy);
|
|
||||||
split.quantity(amount);
|
|
||||||
quantity -= amount;
|
|
||||||
|
|
||||||
return split;
|
|
||||||
} catch (Exception e){
|
|
||||||
ShatteredPixelDungeon.reportException(e);
|
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Bundle copy = new Bundle();
|
||||||
|
this.storeInBundle(copy);
|
||||||
|
split.restoreFromBundle(copy);
|
||||||
|
split.quantity(amount);
|
||||||
|
quantity -= amount;
|
||||||
|
|
||||||
|
return split;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -426,17 +427,12 @@ public class Item implements Bundlable {
|
||||||
}
|
}
|
||||||
|
|
||||||
public Item virtual(){
|
public Item virtual(){
|
||||||
try {
|
Item item = Reflection.newInstance(getClass());
|
||||||
|
if (item == null) return null;
|
||||||
Item item = getClass().newInstance();
|
|
||||||
item.quantity = 0;
|
item.quantity = 0;
|
||||||
item.level = level;
|
item.level = level;
|
||||||
return item;
|
return item;
|
||||||
|
|
||||||
} catch (Exception e) {
|
|
||||||
ShatteredPixelDungeon.reportException(e);
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public Item random() {
|
public Item random() {
|
||||||
|
|
|
@ -57,6 +57,7 @@ import com.shatteredpixel.shatteredpixeldungeon.items.spells.Recycle;
|
||||||
import com.shatteredpixel.shatteredpixeldungeon.items.spells.WildEnergy;
|
import com.shatteredpixel.shatteredpixeldungeon.items.spells.WildEnergy;
|
||||||
import com.shatteredpixel.shatteredpixeldungeon.items.wands.Wand;
|
import com.shatteredpixel.shatteredpixeldungeon.items.wands.Wand;
|
||||||
import com.shatteredpixel.shatteredpixeldungeon.items.weapon.missiles.darts.Dart;
|
import com.shatteredpixel.shatteredpixeldungeon.items.weapon.missiles.darts.Dart;
|
||||||
|
import com.watabou.utils.Reflection;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
|
|
||||||
|
@ -86,15 +87,10 @@ public abstract class Recipe {
|
||||||
//gets a simple list of items based on inputs
|
//gets a simple list of items based on inputs
|
||||||
public ArrayList<Item> getIngredients() {
|
public ArrayList<Item> getIngredients() {
|
||||||
ArrayList<Item> result = new ArrayList<>();
|
ArrayList<Item> result = new ArrayList<>();
|
||||||
try {
|
for (int i = 0; i < inputs.length; i++) {
|
||||||
for (int i = 0; i < inputs.length; i++) {
|
Item ingredient = Reflection.newInstance(inputs[i]);
|
||||||
Item ingredient = inputs[i].newInstance();
|
ingredient.quantity(inQuantity[i]);
|
||||||
ingredient.quantity(inQuantity[i]);
|
result.add(ingredient);
|
||||||
result.add(ingredient);
|
|
||||||
}
|
|
||||||
} catch (Exception e){
|
|
||||||
ShatteredPixelDungeon.reportException( e );
|
|
||||||
return null;
|
|
||||||
}
|
}
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
@ -154,7 +150,7 @@ public abstract class Recipe {
|
||||||
//ingredients are ignored, as output doesn't vary
|
//ingredients are ignored, as output doesn't vary
|
||||||
public final Item sampleOutput(ArrayList<Item> ingredients){
|
public final Item sampleOutput(ArrayList<Item> ingredients){
|
||||||
try {
|
try {
|
||||||
Item result = output.newInstance();
|
Item result = Reflection.newInstance(output);
|
||||||
result.quantity(outQuantity);
|
result.quantity(outQuantity);
|
||||||
return result;
|
return result;
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
|
|
|
@ -65,6 +65,7 @@ import com.watabou.noosa.particles.Emitter;
|
||||||
import com.watabou.utils.Bundlable;
|
import com.watabou.utils.Bundlable;
|
||||||
import com.watabou.utils.Bundle;
|
import com.watabou.utils.Bundle;
|
||||||
import com.watabou.utils.Random;
|
import com.watabou.utils.Random;
|
||||||
|
import com.watabou.utils.Reflection;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
|
@ -621,65 +622,45 @@ public class Armor extends EquipableItem {
|
||||||
|
|
||||||
@SuppressWarnings("unchecked")
|
@SuppressWarnings("unchecked")
|
||||||
public static Glyph randomCommon( Class<? extends Glyph> ... toIgnore ){
|
public static Glyph randomCommon( Class<? extends Glyph> ... toIgnore ){
|
||||||
try {
|
ArrayList<Class<?>> glyphs = new ArrayList<>(Arrays.asList(common));
|
||||||
ArrayList<Class<?>> glyphs = new ArrayList<>(Arrays.asList(common));
|
glyphs.removeAll(Arrays.asList(toIgnore));
|
||||||
glyphs.removeAll(Arrays.asList(toIgnore));
|
if (glyphs.isEmpty()) {
|
||||||
if (glyphs.isEmpty()) {
|
return random();
|
||||||
return random();
|
} else {
|
||||||
} else {
|
return (Glyph) Reflection.newInstance(Random.element(glyphs));
|
||||||
return (Glyph) Random.element(glyphs).newInstance();
|
|
||||||
}
|
|
||||||
} catch (Exception e) {
|
|
||||||
ShatteredPixelDungeon.reportException(e);
|
|
||||||
return null;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@SuppressWarnings("unchecked")
|
@SuppressWarnings("unchecked")
|
||||||
public static Glyph randomUncommon( Class<? extends Glyph> ... toIgnore ){
|
public static Glyph randomUncommon( Class<? extends Glyph> ... toIgnore ){
|
||||||
try {
|
ArrayList<Class<?>> glyphs = new ArrayList<>(Arrays.asList(uncommon));
|
||||||
ArrayList<Class<?>> glyphs = new ArrayList<>(Arrays.asList(uncommon));
|
glyphs.removeAll(Arrays.asList(toIgnore));
|
||||||
glyphs.removeAll(Arrays.asList(toIgnore));
|
if (glyphs.isEmpty()) {
|
||||||
if (glyphs.isEmpty()) {
|
return random();
|
||||||
return random();
|
} else {
|
||||||
} else {
|
return (Glyph) Reflection.newInstance(Random.element(glyphs));
|
||||||
return (Glyph) Random.element(glyphs).newInstance();
|
|
||||||
}
|
|
||||||
} catch (Exception e) {
|
|
||||||
ShatteredPixelDungeon.reportException(e);
|
|
||||||
return null;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@SuppressWarnings("unchecked")
|
@SuppressWarnings("unchecked")
|
||||||
public static Glyph randomRare( Class<? extends Glyph> ... toIgnore ){
|
public static Glyph randomRare( Class<? extends Glyph> ... toIgnore ){
|
||||||
try {
|
ArrayList<Class<?>> glyphs = new ArrayList<>(Arrays.asList(rare));
|
||||||
ArrayList<Class<?>> glyphs = new ArrayList<>(Arrays.asList(rare));
|
glyphs.removeAll(Arrays.asList(toIgnore));
|
||||||
glyphs.removeAll(Arrays.asList(toIgnore));
|
if (glyphs.isEmpty()) {
|
||||||
if (glyphs.isEmpty()) {
|
return random();
|
||||||
return random();
|
} else {
|
||||||
} else {
|
return (Glyph) Reflection.newInstance(Random.element(glyphs));
|
||||||
return (Glyph) Random.element(glyphs).newInstance();
|
|
||||||
}
|
|
||||||
} catch (Exception e) {
|
|
||||||
ShatteredPixelDungeon.reportException(e);
|
|
||||||
return null;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@SuppressWarnings("unchecked")
|
@SuppressWarnings("unchecked")
|
||||||
public static Glyph randomCurse( Class<? extends Glyph> ... toIgnore ){
|
public static Glyph randomCurse( Class<? extends Glyph> ... toIgnore ){
|
||||||
try {
|
ArrayList<Class<?>> glyphs = new ArrayList<>(Arrays.asList(curses));
|
||||||
ArrayList<Class<?>> glyphs = new ArrayList<>(Arrays.asList(curses));
|
glyphs.removeAll(Arrays.asList(toIgnore));
|
||||||
glyphs.removeAll(Arrays.asList(toIgnore));
|
if (glyphs.isEmpty()) {
|
||||||
if (glyphs.isEmpty()) {
|
return random();
|
||||||
return random();
|
} else {
|
||||||
} else {
|
return (Glyph) Reflection.newInstance(Random.element(glyphs));
|
||||||
return (Glyph) Random.element(glyphs).newInstance();
|
|
||||||
}
|
|
||||||
} catch (Exception e) {
|
|
||||||
ShatteredPixelDungeon.reportException(e);
|
|
||||||
return null;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -39,6 +39,7 @@ import com.shatteredpixel.shatteredpixeldungeon.sprites.ItemSprite;
|
||||||
import com.watabou.utils.Bundle;
|
import com.watabou.utils.Bundle;
|
||||||
import com.watabou.utils.PathFinder;
|
import com.watabou.utils.PathFinder;
|
||||||
import com.watabou.utils.Random;
|
import com.watabou.utils.Random;
|
||||||
|
import com.watabou.utils.Reflection;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
|
|
||||||
|
@ -72,30 +73,27 @@ public class Multiplicity extends Armor.Glyph {
|
||||||
|| attacker instanceof Mimic || attacker instanceof Statue){
|
|| attacker instanceof Mimic || attacker instanceof Statue){
|
||||||
m = Dungeon.level.createMob();
|
m = Dungeon.level.createMob();
|
||||||
} else {
|
} else {
|
||||||
try {
|
Actor.fixTime();
|
||||||
Actor.fixTime();
|
|
||||||
|
m = (Mob)Reflection.newInstance(attacker.getClass());
|
||||||
|
|
||||||
|
if (m != null) {
|
||||||
|
|
||||||
m = (Mob)attacker.getClass().newInstance();
|
|
||||||
Bundle store = new Bundle();
|
Bundle store = new Bundle();
|
||||||
attacker.storeInBundle(store);
|
attacker.storeInBundle(store);
|
||||||
m.restoreFromBundle(store);
|
m.restoreFromBundle(store);
|
||||||
m.pos = 0;
|
m.pos = 0;
|
||||||
m.HP = m.HT;
|
m.HP = m.HT;
|
||||||
if (m.buff(PinCushion.class) != null){
|
if (m.buff(PinCushion.class) != null) {
|
||||||
m.remove(m.buff(PinCushion.class));
|
m.remove(m.buff(PinCushion.class));
|
||||||
}
|
}
|
||||||
|
|
||||||
//If a thief has stolen an item, that item is not duplicated.
|
//If a thief has stolen an item, that item is not duplicated.
|
||||||
if (m instanceof Thief){
|
if (m instanceof Thief) {
|
||||||
((Thief) m).item = null;
|
((Thief) m).item = null;
|
||||||
}
|
}
|
||||||
|
|
||||||
} catch (Exception e) {
|
|
||||||
ShatteredPixelDungeon.reportException(e);
|
|
||||||
m = null;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (m != null) {
|
if (m != null) {
|
||||||
|
|
|
@ -46,6 +46,7 @@ import com.shatteredpixel.shatteredpixeldungeon.windows.WndOptions;
|
||||||
import com.watabou.noosa.audio.Sample;
|
import com.watabou.noosa.audio.Sample;
|
||||||
import com.watabou.utils.Bundle;
|
import com.watabou.utils.Bundle;
|
||||||
import com.watabou.utils.Random;
|
import com.watabou.utils.Random;
|
||||||
|
import com.watabou.utils.Reflection;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.Collections;
|
import java.util.Collections;
|
||||||
|
@ -138,13 +139,9 @@ public class UnstableSpellbook extends Artifact {
|
||||||
@Override
|
@Override
|
||||||
protected void onSelect(int index) {
|
protected void onSelect(int index) {
|
||||||
if (index == 1){
|
if (index == 1){
|
||||||
try {
|
Scroll scroll = Reflection.newInstance(ExoticScroll.regToExo.get(fScroll.getClass()));
|
||||||
Scroll scroll = ExoticScroll.regToExo.get(fScroll.getClass()).newInstance();
|
charge--;
|
||||||
charge --;
|
scroll.doRead();
|
||||||
scroll.doRead();
|
|
||||||
} catch ( Exception e) {
|
|
||||||
ShatteredPixelDungeon.reportException(e);
|
|
||||||
}
|
|
||||||
} else {
|
} else {
|
||||||
fScroll.doRead();
|
fScroll.doRead();
|
||||||
}
|
}
|
||||||
|
|
|
@ -55,6 +55,7 @@ import com.watabou.noosa.audio.Sample;
|
||||||
import com.watabou.utils.Bundle;
|
import com.watabou.utils.Bundle;
|
||||||
import com.watabou.utils.PathFinder;
|
import com.watabou.utils.PathFinder;
|
||||||
import com.watabou.utils.Random;
|
import com.watabou.utils.Random;
|
||||||
|
import com.watabou.utils.Reflection;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
|
@ -399,11 +400,7 @@ public class Bomb extends Item {
|
||||||
for (Item i : ingredients){
|
for (Item i : ingredients){
|
||||||
i.quantity(i.quantity()-1);
|
i.quantity(i.quantity()-1);
|
||||||
if (validIngredients.containsKey(i.getClass())){
|
if (validIngredients.containsKey(i.getClass())){
|
||||||
try {
|
result = Reflection.newInstance(validIngredients.get(i.getClass()));
|
||||||
result = validIngredients.get(i.getClass()).newInstance();
|
|
||||||
} catch (Exception e) {
|
|
||||||
ShatteredPixelDungeon.reportException(e);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -414,11 +411,7 @@ public class Bomb extends Item {
|
||||||
public Item sampleOutput(ArrayList<Item> ingredients) {
|
public Item sampleOutput(ArrayList<Item> ingredients) {
|
||||||
for (Item i : ingredients){
|
for (Item i : ingredients){
|
||||||
if (validIngredients.containsKey(i.getClass())){
|
if (validIngredients.containsKey(i.getClass())){
|
||||||
try {
|
return Reflection.newInstance(validIngredients.get(i.getClass()));
|
||||||
return validIngredients.get(i.getClass()).newInstance();
|
|
||||||
} catch (Exception e) {
|
|
||||||
ShatteredPixelDungeon.reportException(e);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return null;
|
return null;
|
||||||
|
|
|
@ -49,6 +49,7 @@ import com.shatteredpixel.shatteredpixeldungeon.sprites.ItemSprite;
|
||||||
import com.shatteredpixel.shatteredpixeldungeon.sprites.ItemSpriteSheet;
|
import com.shatteredpixel.shatteredpixeldungeon.sprites.ItemSpriteSheet;
|
||||||
import com.shatteredpixel.shatteredpixeldungeon.utils.GLog;
|
import com.shatteredpixel.shatteredpixeldungeon.utils.GLog;
|
||||||
import com.watabou.utils.Bundle;
|
import com.watabou.utils.Bundle;
|
||||||
|
import com.watabou.utils.Reflection;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
|
|
||||||
|
@ -124,14 +125,7 @@ public class Blandfruit extends Food {
|
||||||
}
|
}
|
||||||
|
|
||||||
public Item cook(Seed seed){
|
public Item cook(Seed seed){
|
||||||
|
return imbuePotion(Reflection.newInstance(Potion.SeedToPotion.types.get(seed.getClass())));
|
||||||
try {
|
|
||||||
return imbuePotion(Potion.SeedToPotion.types.get(seed.getClass()).newInstance());
|
|
||||||
} catch (Exception e) {
|
|
||||||
ShatteredPixelDungeon.reportException(e);
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public Item imbuePotion(Potion potion){
|
public Item imbuePotion(Potion potion){
|
||||||
|
|
|
@ -29,6 +29,7 @@ import com.shatteredpixel.shatteredpixeldungeon.items.stones.Runestone;
|
||||||
import com.shatteredpixel.shatteredpixeldungeon.plants.Plant;
|
import com.shatteredpixel.shatteredpixeldungeon.plants.Plant;
|
||||||
import com.shatteredpixel.shatteredpixeldungeon.sprites.ItemSpriteSheet;
|
import com.shatteredpixel.shatteredpixeldungeon.sprites.ItemSpriteSheet;
|
||||||
import com.watabou.utils.Random;
|
import com.watabou.utils.Random;
|
||||||
|
import com.watabou.utils.Reflection;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
|
@ -57,25 +58,17 @@ public class AlchemicalCatalyst extends Potion {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void apply(Hero hero) {
|
public void apply(Hero hero) {
|
||||||
try {
|
Potion p = Reflection.newInstance(Random.chances(potionChances));
|
||||||
Potion p = Random.chances(potionChances).newInstance();
|
p.anonymize();
|
||||||
p.anonymize();
|
p.apply(hero);
|
||||||
p.apply(hero);
|
|
||||||
} catch (Exception e) {
|
|
||||||
ShatteredPixelDungeon.reportException(e);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void shatter(int cell) {
|
public void shatter(int cell) {
|
||||||
try {
|
Potion p = Reflection.newInstance(Random.chances(potionChances));
|
||||||
Potion p = Random.chances(potionChances).newInstance();
|
p.anonymize();
|
||||||
p.anonymize();
|
curItem = p;
|
||||||
curItem = p;
|
p.shatter(cell);
|
||||||
p.shatter(cell);
|
|
||||||
} catch (Exception e) {
|
|
||||||
ShatteredPixelDungeon.reportException(e);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|
|
@ -73,6 +73,7 @@ import com.shatteredpixel.shatteredpixeldungeon.windows.WndOptions;
|
||||||
import com.watabou.noosa.audio.Sample;
|
import com.watabou.noosa.audio.Sample;
|
||||||
import com.watabou.utils.Bundle;
|
import com.watabou.utils.Bundle;
|
||||||
import com.watabou.utils.Random;
|
import com.watabou.utils.Random;
|
||||||
|
import com.watabou.utils.Reflection;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
|
@ -516,14 +517,7 @@ public class Potion extends Item {
|
||||||
result = Generator.random( Generator.Category.POTION );
|
result = Generator.random( Generator.Category.POTION );
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
|
result = Reflection.newInstance(types.get(Random.element(ingredients).getClass()));
|
||||||
Class<? extends Potion> itemClass = types.get(Random.element(ingredients).getClass());
|
|
||||||
try {
|
|
||||||
result = itemClass.newInstance();
|
|
||||||
} catch (Exception e) {
|
|
||||||
ShatteredPixelDungeon.reportException(e);
|
|
||||||
result = Generator.random( Generator.Category.POTION );
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -39,6 +39,7 @@ import com.shatteredpixel.shatteredpixeldungeon.items.potions.PotionOfPurity;
|
||||||
import com.shatteredpixel.shatteredpixeldungeon.items.potions.PotionOfStrength;
|
import com.shatteredpixel.shatteredpixeldungeon.items.potions.PotionOfStrength;
|
||||||
import com.shatteredpixel.shatteredpixeldungeon.items.potions.PotionOfToxicGas;
|
import com.shatteredpixel.shatteredpixeldungeon.items.potions.PotionOfToxicGas;
|
||||||
import com.shatteredpixel.shatteredpixeldungeon.plants.Plant;
|
import com.shatteredpixel.shatteredpixeldungeon.plants.Plant;
|
||||||
|
import com.watabou.utils.Reflection;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
|
@ -118,12 +119,7 @@ public class ExoticPotion extends Potion {
|
||||||
@Override
|
@Override
|
||||||
//20 gold more than its none-exotic equivalent
|
//20 gold more than its none-exotic equivalent
|
||||||
public int price() {
|
public int price() {
|
||||||
try {
|
return (Reflection.newInstance(exoToReg.get(getClass())).price() + 20) * quantity;
|
||||||
return (exoToReg.get(getClass()).newInstance().price() + 20) * quantity;
|
|
||||||
} catch (Exception e){
|
|
||||||
ShatteredPixelDungeon.reportException(e);
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public static class PotionToExotic extends Recipe{
|
public static class PotionToExotic extends Recipe{
|
||||||
|
@ -156,11 +152,7 @@ public class ExoticPotion extends Potion {
|
||||||
for (Item i : ingredients){
|
for (Item i : ingredients){
|
||||||
i.quantity(i.quantity()-1);
|
i.quantity(i.quantity()-1);
|
||||||
if (regToExo.containsKey(i.getClass())) {
|
if (regToExo.containsKey(i.getClass())) {
|
||||||
try {
|
result = Reflection.newInstance(regToExo.get(i.getClass()));
|
||||||
result = regToExo.get(i.getClass()).newInstance();
|
|
||||||
} catch (Exception e) {
|
|
||||||
ShatteredPixelDungeon.reportException(e);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return result;
|
return result;
|
||||||
|
@ -170,11 +162,7 @@ public class ExoticPotion extends Potion {
|
||||||
public Item sampleOutput(ArrayList<Item> ingredients) {
|
public Item sampleOutput(ArrayList<Item> ingredients) {
|
||||||
for (Item i : ingredients){
|
for (Item i : ingredients){
|
||||||
if (regToExo.containsKey(i.getClass())) {
|
if (regToExo.containsKey(i.getClass())) {
|
||||||
try {
|
return Reflection.newInstance(regToExo.get(i.getClass()));
|
||||||
return regToExo.get(i.getClass()).newInstance();
|
|
||||||
} catch (Exception e) {
|
|
||||||
ShatteredPixelDungeon.reportException(e);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return null;
|
return null;
|
||||||
|
|
|
@ -51,6 +51,7 @@ import com.shatteredpixel.shatteredpixeldungeon.sprites.HeroSprite;
|
||||||
import com.shatteredpixel.shatteredpixeldungeon.sprites.ItemSpriteSheet;
|
import com.shatteredpixel.shatteredpixeldungeon.sprites.ItemSpriteSheet;
|
||||||
import com.shatteredpixel.shatteredpixeldungeon.utils.GLog;
|
import com.shatteredpixel.shatteredpixeldungeon.utils.GLog;
|
||||||
import com.watabou.utils.Bundle;
|
import com.watabou.utils.Bundle;
|
||||||
|
import com.watabou.utils.Reflection;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
|
@ -355,25 +356,15 @@ public abstract class Scroll extends Item {
|
||||||
|
|
||||||
s.quantity(s.quantity() - 1);
|
s.quantity(s.quantity() - 1);
|
||||||
|
|
||||||
try{
|
return Reflection.newInstance(stones.get(s.getClass())).quantity(amnts.get(s.getClass()));
|
||||||
return stones.get(s.getClass()).newInstance().quantity(amnts.get(s.getClass()));
|
|
||||||
} catch (Exception e) {
|
|
||||||
ShatteredPixelDungeon.reportException(e);
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Item sampleOutput(ArrayList<Item> ingredients) {
|
public Item sampleOutput(ArrayList<Item> ingredients) {
|
||||||
if (!testIngredients(ingredients)) return null;
|
if (!testIngredients(ingredients)) return null;
|
||||||
|
|
||||||
try{
|
Scroll s = (Scroll) ingredients.get(0);
|
||||||
Scroll s = (Scroll) ingredients.get(0);
|
return Reflection.newInstance(stones.get(s.getClass())).quantity(amnts.get(s.getClass()));
|
||||||
return stones.get(s.getClass()).newInstance().quantity(amnts.get(s.getClass()));
|
|
||||||
} catch (Exception e) {
|
|
||||||
ShatteredPixelDungeon.reportException(e);
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -48,6 +48,7 @@ import com.shatteredpixel.shatteredpixeldungeon.plants.Plant;
|
||||||
import com.shatteredpixel.shatteredpixeldungeon.utils.GLog;
|
import com.shatteredpixel.shatteredpixeldungeon.utils.GLog;
|
||||||
import com.shatteredpixel.shatteredpixeldungeon.windows.WndBag;
|
import com.shatteredpixel.shatteredpixeldungeon.windows.WndBag;
|
||||||
import com.watabou.utils.Random;
|
import com.watabou.utils.Random;
|
||||||
|
import com.watabou.utils.Reflection;
|
||||||
|
|
||||||
public class ScrollOfTransmutation extends InventoryScroll {
|
public class ScrollOfTransmutation extends InventoryScroll {
|
||||||
|
|
||||||
|
@ -150,12 +151,7 @@ public class ScrollOfTransmutation extends InventoryScroll {
|
||||||
}
|
}
|
||||||
|
|
||||||
do {
|
do {
|
||||||
try {
|
n = (Weapon) Reflection.newInstance(c.classes[Random.chances(c.probs)]);
|
||||||
n = (Weapon)c.classes[Random.chances(c.probs)].newInstance();
|
|
||||||
} catch (Exception e) {
|
|
||||||
ShatteredPixelDungeon.reportException(e);
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
} while (Challenges.isItemBlocked(n) || n.getClass() == w.getClass());
|
} while (Challenges.isItemBlocked(n) || n.getClass() == w.getClass());
|
||||||
|
|
||||||
int level = w.level();
|
int level = w.level();
|
||||||
|
@ -256,28 +252,18 @@ public class ScrollOfTransmutation extends InventoryScroll {
|
||||||
}
|
}
|
||||||
|
|
||||||
private Scroll changeScroll( Scroll s ) {
|
private Scroll changeScroll( Scroll s ) {
|
||||||
try {
|
if (s instanceof ExoticScroll) {
|
||||||
if (s instanceof ExoticScroll) {
|
return Reflection.newInstance(ExoticScroll.exoToReg.get(s.getClass()));
|
||||||
return ExoticScroll.exoToReg.get(s.getClass()).newInstance();
|
} else {
|
||||||
} else {
|
return Reflection.newInstance(ExoticScroll.regToExo.get(s.getClass()));
|
||||||
return ExoticScroll.regToExo.get(s.getClass()).newInstance();
|
|
||||||
}
|
|
||||||
} catch ( Exception e ){
|
|
||||||
ShatteredPixelDungeon.reportException(e);
|
|
||||||
return null;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private Potion changePotion( Potion p ) {
|
private Potion changePotion( Potion p ) {
|
||||||
try {
|
if (p instanceof ExoticPotion) {
|
||||||
if (p instanceof ExoticPotion) {
|
return Reflection.newInstance(ExoticPotion.exoToReg.get(p.getClass()));
|
||||||
return ExoticPotion.exoToReg.get(p.getClass()).newInstance();
|
} else {
|
||||||
} else {
|
return Reflection.newInstance(ExoticPotion.regToExo.get(p.getClass()));
|
||||||
return ExoticPotion.regToExo.get(p.getClass()).newInstance();
|
|
||||||
}
|
|
||||||
} catch ( Exception e ){
|
|
||||||
ShatteredPixelDungeon.reportException(e);
|
|
||||||
return null;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -38,6 +38,7 @@ import com.shatteredpixel.shatteredpixeldungeon.items.scrolls.ScrollOfTerror;
|
||||||
import com.shatteredpixel.shatteredpixeldungeon.items.scrolls.ScrollOfTransmutation;
|
import com.shatteredpixel.shatteredpixeldungeon.items.scrolls.ScrollOfTransmutation;
|
||||||
import com.shatteredpixel.shatteredpixeldungeon.items.scrolls.ScrollOfUpgrade;
|
import com.shatteredpixel.shatteredpixeldungeon.items.scrolls.ScrollOfUpgrade;
|
||||||
import com.shatteredpixel.shatteredpixeldungeon.items.stones.Runestone;
|
import com.shatteredpixel.shatteredpixeldungeon.items.stones.Runestone;
|
||||||
|
import com.watabou.utils.Reflection;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
|
@ -118,12 +119,7 @@ public abstract class ExoticScroll extends Scroll {
|
||||||
@Override
|
@Override
|
||||||
//20 gold more than its none-exotic equivalent
|
//20 gold more than its none-exotic equivalent
|
||||||
public int price() {
|
public int price() {
|
||||||
try {
|
return (Reflection.newInstance(exoToReg.get(getClass())).price() + 20) * quantity;
|
||||||
return (exoToReg.get(getClass()).newInstance().price() + 20) * quantity;
|
|
||||||
} catch (Exception e){
|
|
||||||
ShatteredPixelDungeon.reportException(e);
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public static class ScrollToExotic extends Recipe {
|
public static class ScrollToExotic extends Recipe {
|
||||||
|
@ -156,11 +152,7 @@ public abstract class ExoticScroll extends Scroll {
|
||||||
for (Item i : ingredients){
|
for (Item i : ingredients){
|
||||||
i.quantity(i.quantity()-1);
|
i.quantity(i.quantity()-1);
|
||||||
if (regToExo.containsKey(i.getClass())) {
|
if (regToExo.containsKey(i.getClass())) {
|
||||||
try {
|
result = Reflection.newInstance(regToExo.get(i.getClass()));
|
||||||
result = regToExo.get(i.getClass()).newInstance();
|
|
||||||
} catch (Exception e) {
|
|
||||||
ShatteredPixelDungeon.reportException(e);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return result;
|
return result;
|
||||||
|
@ -170,11 +162,7 @@ public abstract class ExoticScroll extends Scroll {
|
||||||
public Item sampleOutput(ArrayList<Item> ingredients) {
|
public Item sampleOutput(ArrayList<Item> ingredients) {
|
||||||
for (Item i : ingredients){
|
for (Item i : ingredients){
|
||||||
if (regToExo.containsKey(i.getClass())) {
|
if (regToExo.containsKey(i.getClass())) {
|
||||||
try {
|
return Reflection.newInstance(regToExo.get(i.getClass()));
|
||||||
return regToExo.get(i.getClass()).newInstance();
|
|
||||||
} catch (Exception e) {
|
|
||||||
ShatteredPixelDungeon.reportException(e);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return null;
|
return null;
|
||||||
|
|
|
@ -39,6 +39,7 @@ import com.shatteredpixel.shatteredpixeldungeon.utils.GLog;
|
||||||
import com.shatteredpixel.shatteredpixeldungeon.windows.IconTitle;
|
import com.shatteredpixel.shatteredpixeldungeon.windows.IconTitle;
|
||||||
import com.watabou.noosa.audio.Sample;
|
import com.watabou.noosa.audio.Sample;
|
||||||
import com.watabou.utils.Random;
|
import com.watabou.utils.Random;
|
||||||
|
import com.watabou.utils.Reflection;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.HashSet;
|
import java.util.HashSet;
|
||||||
|
@ -78,47 +79,43 @@ public class ScrollOfDivination extends ExoticScroll {
|
||||||
float[] probs = baseProbs.clone();
|
float[] probs = baseProbs.clone();
|
||||||
|
|
||||||
while (left > 0 && total > 0) {
|
while (left > 0 && total > 0) {
|
||||||
try {
|
switch (Random.chances(probs)) {
|
||||||
switch (Random.chances(probs)) {
|
default:
|
||||||
default:
|
probs = baseProbs.clone();
|
||||||
probs = baseProbs.clone();
|
continue;
|
||||||
|
case 0:
|
||||||
|
if (potions.isEmpty()) {
|
||||||
|
probs[0] = 0;
|
||||||
continue;
|
continue;
|
||||||
case 0:
|
}
|
||||||
if (potions.isEmpty()) {
|
probs[0]--;
|
||||||
probs[0] = 0;
|
Potion p = Reflection.newInstance(Random.element(potions));
|
||||||
continue;
|
p.setKnown();
|
||||||
}
|
IDed.add(p);
|
||||||
probs[0]--;
|
potions.remove(p.getClass());
|
||||||
Potion p = Random.element(potions).newInstance();
|
break;
|
||||||
p.setKnown();
|
case 1:
|
||||||
IDed.add(p);
|
if (scrolls.isEmpty()) {
|
||||||
potions.remove(p.getClass());
|
probs[1] = 0;
|
||||||
break;
|
continue;
|
||||||
case 1:
|
}
|
||||||
if (scrolls.isEmpty()) {
|
probs[1]--;
|
||||||
probs[1] = 0;
|
Scroll s = Reflection.newInstance(Random.element(scrolls));
|
||||||
continue;
|
s.setKnown();
|
||||||
}
|
IDed.add(s);
|
||||||
probs[1]--;
|
scrolls.remove(s.getClass());
|
||||||
Scroll s = Random.element(scrolls).newInstance();
|
break;
|
||||||
s.setKnown();
|
case 2:
|
||||||
IDed.add(s);
|
if (rings.isEmpty()) {
|
||||||
scrolls.remove(s.getClass());
|
probs[2] = 0;
|
||||||
break;
|
continue;
|
||||||
case 2:
|
}
|
||||||
if (rings.isEmpty()) {
|
probs[2]--;
|
||||||
probs[2] = 0;
|
Ring r = Reflection.newInstance(Random.element(rings));
|
||||||
continue;
|
r.setKnown();
|
||||||
}
|
IDed.add(r);
|
||||||
probs[2]--;
|
rings.remove(r.getClass());
|
||||||
Ring r = Random.element(rings).newInstance();
|
break;
|
||||||
r.setKnown();
|
|
||||||
IDed.add(r);
|
|
||||||
rings.remove(r.getClass());
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
} catch (Exception e) {
|
|
||||||
ShatteredPixelDungeon.reportException(e);
|
|
||||||
}
|
}
|
||||||
left --;
|
left --;
|
||||||
total --;
|
total --;
|
||||||
|
|
|
@ -41,6 +41,7 @@ import com.shatteredpixel.shatteredpixeldungeon.items.stones.Runestone;
|
||||||
import com.shatteredpixel.shatteredpixeldungeon.plants.Plant;
|
import com.shatteredpixel.shatteredpixeldungeon.plants.Plant;
|
||||||
import com.shatteredpixel.shatteredpixeldungeon.sprites.ItemSpriteSheet;
|
import com.shatteredpixel.shatteredpixeldungeon.sprites.ItemSpriteSheet;
|
||||||
import com.watabou.utils.Random;
|
import com.watabou.utils.Random;
|
||||||
|
import com.watabou.utils.Reflection;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
|
@ -72,14 +73,10 @@ public class ArcaneCatalyst extends Spell {
|
||||||
detach( curUser.belongings.backpack );
|
detach( curUser.belongings.backpack );
|
||||||
updateQuickslot();
|
updateQuickslot();
|
||||||
|
|
||||||
try {
|
Scroll s = Reflection.newInstance(Random.chances(scrollChances));
|
||||||
Scroll s = Random.chances(scrollChances).newInstance();
|
s.anonymize();
|
||||||
s.anonymize();
|
curItem = s;
|
||||||
curItem = s;
|
s.doRead();
|
||||||
s.doRead();
|
|
||||||
} catch (Exception e) {
|
|
||||||
ShatteredPixelDungeon.reportException(e);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|
|
@ -36,6 +36,7 @@ import com.shatteredpixel.shatteredpixeldungeon.sprites.ItemSpriteSheet;
|
||||||
import com.shatteredpixel.shatteredpixeldungeon.utils.GLog;
|
import com.shatteredpixel.shatteredpixeldungeon.utils.GLog;
|
||||||
import com.watabou.noosa.audio.Sample;
|
import com.watabou.noosa.audio.Sample;
|
||||||
import com.watabou.utils.Bundle;
|
import com.watabou.utils.Bundle;
|
||||||
|
import com.watabou.utils.Reflection;
|
||||||
|
|
||||||
public class ReclaimTrap extends TargetedSpell {
|
public class ReclaimTrap extends TargetedSpell {
|
||||||
|
|
||||||
|
@ -62,16 +63,12 @@ public class ReclaimTrap extends TargetedSpell {
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
|
|
||||||
try {
|
Trap t = Reflection.newInstance(storedTrap);
|
||||||
Trap t = storedTrap.newInstance();
|
storedTrap = null;
|
||||||
storedTrap = null;
|
|
||||||
|
t.pos = bolt.collisionPos;
|
||||||
t.pos = bolt.collisionPos;
|
t.activate();
|
||||||
t.activate();
|
|
||||||
|
|
||||||
} catch (Exception e) {
|
|
||||||
ShatteredPixelDungeon.reportException(e);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -111,11 +108,7 @@ public class ReclaimTrap extends TargetedSpell {
|
||||||
@Override
|
@Override
|
||||||
public ItemSprite.Glowing glowing() {
|
public ItemSprite.Glowing glowing() {
|
||||||
if (storedTrap != null){
|
if (storedTrap != null){
|
||||||
try {
|
return COLORS[Reflection.newInstance(storedTrap).color];
|
||||||
return COLORS[storedTrap.newInstance().color];
|
|
||||||
} catch (Exception e) {
|
|
||||||
ShatteredPixelDungeon.reportException(e);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
|
@ -39,6 +39,7 @@ import com.shatteredpixel.shatteredpixeldungeon.plants.Plant;
|
||||||
import com.shatteredpixel.shatteredpixeldungeon.sprites.ItemSpriteSheet;
|
import com.shatteredpixel.shatteredpixeldungeon.sprites.ItemSpriteSheet;
|
||||||
import com.shatteredpixel.shatteredpixeldungeon.utils.GLog;
|
import com.shatteredpixel.shatteredpixeldungeon.utils.GLog;
|
||||||
import com.shatteredpixel.shatteredpixeldungeon.windows.WndBag;
|
import com.shatteredpixel.shatteredpixeldungeon.windows.WndBag;
|
||||||
|
import com.watabou.utils.Reflection;
|
||||||
|
|
||||||
public class Recycle extends InventorySpell {
|
public class Recycle extends InventorySpell {
|
||||||
|
|
||||||
|
@ -54,22 +55,12 @@ public class Recycle extends InventorySpell {
|
||||||
if (item instanceof Potion) {
|
if (item instanceof Potion) {
|
||||||
result = Generator.random(Generator.Category.POTION);
|
result = Generator.random(Generator.Category.POTION);
|
||||||
if (item instanceof ExoticPotion){
|
if (item instanceof ExoticPotion){
|
||||||
try {
|
result = Reflection.newInstance(ExoticPotion.regToExo.get(result.getClass()));
|
||||||
result = ExoticPotion.regToExo.get(result.getClass()).newInstance();
|
|
||||||
} catch ( Exception e ){
|
|
||||||
ShatteredPixelDungeon.reportException(e);
|
|
||||||
result = item;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
} else if (item instanceof Scroll) {
|
} else if (item instanceof Scroll) {
|
||||||
result = Generator.random(Generator.Category.SCROLL);
|
result = Generator.random(Generator.Category.SCROLL);
|
||||||
if (item instanceof ExoticScroll){
|
if (item instanceof ExoticScroll){
|
||||||
try {
|
result = Reflection.newInstance(ExoticScroll.regToExo.get(result.getClass()));
|
||||||
result = ExoticScroll.regToExo.get(result.getClass()).newInstance();
|
|
||||||
} catch ( Exception e ){
|
|
||||||
ShatteredPixelDungeon.reportException(e);
|
|
||||||
result = item;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
} else if (item instanceof Plant.Seed) {
|
} else if (item instanceof Plant.Seed) {
|
||||||
result = Generator.random(Generator.Category.SEED);
|
result = Generator.random(Generator.Category.SEED);
|
||||||
|
|
|
@ -57,6 +57,7 @@ import com.shatteredpixel.shatteredpixeldungeon.utils.GLog;
|
||||||
import com.watabou.utils.Bundlable;
|
import com.watabou.utils.Bundlable;
|
||||||
import com.watabou.utils.Bundle;
|
import com.watabou.utils.Bundle;
|
||||||
import com.watabou.utils.Random;
|
import com.watabou.utils.Random;
|
||||||
|
import com.watabou.utils.Reflection;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
|
@ -371,65 +372,45 @@ abstract public class Weapon extends KindOfWeapon {
|
||||||
|
|
||||||
@SuppressWarnings("unchecked")
|
@SuppressWarnings("unchecked")
|
||||||
public static Enchantment randomCommon( Class<? extends Enchantment> ... toIgnore ) {
|
public static Enchantment randomCommon( Class<? extends Enchantment> ... toIgnore ) {
|
||||||
try {
|
ArrayList<Class<?>> enchants = new ArrayList<>(Arrays.asList(common));
|
||||||
ArrayList<Class<?>> enchants = new ArrayList<>(Arrays.asList(common));
|
enchants.removeAll(Arrays.asList(toIgnore));
|
||||||
enchants.removeAll(Arrays.asList(toIgnore));
|
if (enchants.isEmpty()) {
|
||||||
if (enchants.isEmpty()) {
|
return random();
|
||||||
return random();
|
} else {
|
||||||
} else {
|
return (Enchantment) Reflection.newInstance(Random.element(enchants));
|
||||||
return (Enchantment) Random.element(enchants).newInstance();
|
|
||||||
}
|
|
||||||
} catch (Exception e) {
|
|
||||||
ShatteredPixelDungeon.reportException(e);
|
|
||||||
return null;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@SuppressWarnings("unchecked")
|
@SuppressWarnings("unchecked")
|
||||||
public static Enchantment randomUncommon( Class<? extends Enchantment> ... toIgnore ) {
|
public static Enchantment randomUncommon( Class<? extends Enchantment> ... toIgnore ) {
|
||||||
try {
|
ArrayList<Class<?>> enchants = new ArrayList<>(Arrays.asList(uncommon));
|
||||||
ArrayList<Class<?>> enchants = new ArrayList<>(Arrays.asList(uncommon));
|
enchants.removeAll(Arrays.asList(toIgnore));
|
||||||
enchants.removeAll(Arrays.asList(toIgnore));
|
if (enchants.isEmpty()) {
|
||||||
if (enchants.isEmpty()) {
|
return random();
|
||||||
return random();
|
} else {
|
||||||
} else {
|
return (Enchantment) Reflection.newInstance(Random.element(enchants));
|
||||||
return (Enchantment) Random.element(enchants).newInstance();
|
|
||||||
}
|
|
||||||
} catch (Exception e) {
|
|
||||||
ShatteredPixelDungeon.reportException(e);
|
|
||||||
return null;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@SuppressWarnings("unchecked")
|
@SuppressWarnings("unchecked")
|
||||||
public static Enchantment randomRare( Class<? extends Enchantment> ... toIgnore ) {
|
public static Enchantment randomRare( Class<? extends Enchantment> ... toIgnore ) {
|
||||||
try {
|
ArrayList<Class<?>> enchants = new ArrayList<>(Arrays.asList(rare));
|
||||||
ArrayList<Class<?>> enchants = new ArrayList<>(Arrays.asList(rare));
|
enchants.removeAll(Arrays.asList(toIgnore));
|
||||||
enchants.removeAll(Arrays.asList(toIgnore));
|
if (enchants.isEmpty()) {
|
||||||
if (enchants.isEmpty()) {
|
return random();
|
||||||
return random();
|
} else {
|
||||||
} else {
|
return (Enchantment) Reflection.newInstance(Random.element(enchants));
|
||||||
return (Enchantment) Random.element(enchants).newInstance();
|
|
||||||
}
|
|
||||||
} catch (Exception e) {
|
|
||||||
ShatteredPixelDungeon.reportException(e);
|
|
||||||
return null;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@SuppressWarnings("unchecked")
|
@SuppressWarnings("unchecked")
|
||||||
public static Enchantment randomCurse( Class<? extends Enchantment> ... toIgnore ){
|
public static Enchantment randomCurse( Class<? extends Enchantment> ... toIgnore ){
|
||||||
try {
|
ArrayList<Class<?>> enchants = new ArrayList<>(Arrays.asList(curses));
|
||||||
ArrayList<Class<?>> enchants = new ArrayList<>(Arrays.asList(curses));
|
enchants.removeAll(Arrays.asList(toIgnore));
|
||||||
enchants.removeAll(Arrays.asList(toIgnore));
|
if (enchants.isEmpty()) {
|
||||||
if (enchants.isEmpty()) {
|
return random();
|
||||||
return random();
|
} else {
|
||||||
} else {
|
return (Enchantment) Reflection.newInstance(Random.element(enchants));
|
||||||
return (Enchantment) Random.element(enchants).newInstance();
|
|
||||||
}
|
|
||||||
} catch (Exception e) {
|
|
||||||
ShatteredPixelDungeon.reportException(e);
|
|
||||||
return null;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -26,6 +26,7 @@ import com.shatteredpixel.shatteredpixeldungeon.actors.Char;
|
||||||
import com.shatteredpixel.shatteredpixeldungeon.items.weapon.Weapon;
|
import com.shatteredpixel.shatteredpixeldungeon.items.weapon.Weapon;
|
||||||
import com.shatteredpixel.shatteredpixeldungeon.sprites.ItemSprite;
|
import com.shatteredpixel.shatteredpixeldungeon.sprites.ItemSprite;
|
||||||
import com.watabou.utils.Random;
|
import com.watabou.utils.Random;
|
||||||
|
import com.watabou.utils.Reflection;
|
||||||
|
|
||||||
public class Unstable extends Weapon.Enchantment {
|
public class Unstable extends Weapon.Enchantment {
|
||||||
|
|
||||||
|
@ -55,11 +56,7 @@ public class Unstable extends Weapon.Enchantment {
|
||||||
attacker.buff(Kinetic.ConservedDamage.class).detach();
|
attacker.buff(Kinetic.ConservedDamage.class).detach();
|
||||||
}
|
}
|
||||||
|
|
||||||
try {
|
damage = Reflection.newInstance(Random.oneOf(randomEnchants)).proc( weapon, attacker, defender, damage );
|
||||||
damage = Random.oneOf(randomEnchants).newInstance().proc( weapon, attacker, defender, damage );
|
|
||||||
} catch (Exception e) {
|
|
||||||
ShatteredPixelDungeon.reportException(e);
|
|
||||||
}
|
|
||||||
|
|
||||||
return damage + conservedDamage;
|
return damage + conservedDamage;
|
||||||
}
|
}
|
||||||
|
|
|
@ -45,6 +45,7 @@ import com.shatteredpixel.shatteredpixeldungeon.plants.Sungrass;
|
||||||
import com.shatteredpixel.shatteredpixeldungeon.plants.Swiftthistle;
|
import com.shatteredpixel.shatteredpixeldungeon.plants.Swiftthistle;
|
||||||
import com.shatteredpixel.shatteredpixeldungeon.scenes.GameScene;
|
import com.shatteredpixel.shatteredpixeldungeon.scenes.GameScene;
|
||||||
import com.shatteredpixel.shatteredpixeldungeon.windows.WndOptions;
|
import com.shatteredpixel.shatteredpixeldungeon.windows.WndOptions;
|
||||||
|
import com.watabou.utils.Reflection;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
|
@ -156,12 +157,7 @@ public abstract class TippedDart extends Dart {
|
||||||
}
|
}
|
||||||
|
|
||||||
public static TippedDart getTipped( Plant.Seed s, int quantity ){
|
public static TippedDart getTipped( Plant.Seed s, int quantity ){
|
||||||
try {
|
return (TippedDart) Reflection.newInstance(types.get(s.getClass())).quantity(quantity);
|
||||||
return (TippedDart) types.get(s.getClass()).newInstance().quantity(quantity);
|
|
||||||
} catch (Exception e){
|
|
||||||
ShatteredPixelDungeon.reportException(e);
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public static TippedDart randomTipped( int quantity ){
|
public static TippedDart randomTipped( int quantity ){
|
||||||
|
|
|
@ -81,6 +81,7 @@ import com.watabou.utils.Bundle;
|
||||||
import com.watabou.utils.PathFinder;
|
import com.watabou.utils.PathFinder;
|
||||||
import com.watabou.utils.Point;
|
import com.watabou.utils.Point;
|
||||||
import com.watabou.utils.Random;
|
import com.watabou.utils.Random;
|
||||||
|
import com.watabou.utils.Reflection;
|
||||||
import com.watabou.utils.SparseArray;
|
import com.watabou.utils.SparseArray;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
|
@ -439,15 +440,11 @@ public abstract class Level implements Bundlable {
|
||||||
private ArrayList<Class<?extends Mob>> mobsToSpawn = new ArrayList<>();
|
private ArrayList<Class<?extends Mob>> mobsToSpawn = new ArrayList<>();
|
||||||
|
|
||||||
public Mob createMob() {
|
public Mob createMob() {
|
||||||
if (mobsToSpawn == null || mobsToSpawn.isEmpty())
|
if (mobsToSpawn == null || mobsToSpawn.isEmpty()) {
|
||||||
mobsToSpawn = Bestiary.getMobRotation(Dungeon.depth);
|
mobsToSpawn = Bestiary.getMobRotation(Dungeon.depth);
|
||||||
|
|
||||||
try {
|
|
||||||
return mobsToSpawn.remove(0).newInstance();
|
|
||||||
} catch (Exception e) {
|
|
||||||
ShatteredPixelDungeon.reportException(e);
|
|
||||||
return null;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
return Reflection.newInstance(mobsToSpawn.remove(0));
|
||||||
}
|
}
|
||||||
|
|
||||||
abstract protected void createMobs();
|
abstract protected void createMobs();
|
||||||
|
|
|
@ -34,6 +34,7 @@ import com.watabou.utils.PathFinder;
|
||||||
import com.watabou.utils.Point;
|
import com.watabou.utils.Point;
|
||||||
import com.watabou.utils.Random;
|
import com.watabou.utils.Random;
|
||||||
import com.watabou.utils.Rect;
|
import com.watabou.utils.Rect;
|
||||||
|
import com.watabou.utils.Reflection;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
|
|
||||||
|
@ -356,14 +357,10 @@ public abstract class RegularPainter extends Painter {
|
||||||
Integer trapPos = Random.element(validCells);
|
Integer trapPos = Random.element(validCells);
|
||||||
validCells.remove(trapPos); //removes the integer object, not at the index
|
validCells.remove(trapPos); //removes the integer object, not at the index
|
||||||
|
|
||||||
try {
|
Trap trap = Reflection.newInstance(trapClasses[Random.chances( trapChances )]).hide();
|
||||||
Trap trap = trapClasses[Random.chances( trapChances )].newInstance().hide();
|
l.setTrap( trap, trapPos );
|
||||||
l.setTrap( trap, trapPos );
|
//some traps will not be hidden
|
||||||
//some traps will not be hidden
|
l.map[trapPos] = trap.visible ? Terrain.TRAP : Terrain.SECRET_TRAP;
|
||||||
l.map[trapPos] = trap.visible ? Terrain.TRAP : Terrain.SECRET_TRAP;
|
|
||||||
} catch (Exception e) {
|
|
||||||
throw new RuntimeException(e);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -26,6 +26,7 @@ import com.shatteredpixel.shatteredpixeldungeon.ShatteredPixelDungeon;
|
||||||
import com.shatteredpixel.shatteredpixeldungeon.levels.rooms.Room;
|
import com.shatteredpixel.shatteredpixeldungeon.levels.rooms.Room;
|
||||||
import com.watabou.utils.Point;
|
import com.watabou.utils.Point;
|
||||||
import com.watabou.utils.Random;
|
import com.watabou.utils.Random;
|
||||||
|
import com.watabou.utils.Reflection;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
|
|
||||||
|
@ -86,11 +87,6 @@ public abstract class ConnectionRoom extends Room {
|
||||||
}
|
}
|
||||||
|
|
||||||
public static ConnectionRoom createRoom(){
|
public static ConnectionRoom createRoom(){
|
||||||
try {
|
return Reflection.newInstance(rooms.get(Random.chances(chances[Dungeon.depth])));
|
||||||
return rooms.get(Random.chances(chances[Dungeon.depth])).newInstance();
|
|
||||||
} catch (Exception e) {
|
|
||||||
ShatteredPixelDungeon.reportException(e);
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -34,6 +34,7 @@ import com.shatteredpixel.shatteredpixeldungeon.levels.traps.RockfallTrap;
|
||||||
import com.shatteredpixel.shatteredpixeldungeon.levels.traps.Trap;
|
import com.shatteredpixel.shatteredpixeldungeon.levels.traps.Trap;
|
||||||
import com.watabou.utils.Point;
|
import com.watabou.utils.Point;
|
||||||
import com.watabou.utils.Random;
|
import com.watabou.utils.Random;
|
||||||
|
import com.watabou.utils.Reflection;
|
||||||
|
|
||||||
public class SecretHoardRoom extends SecretRoom {
|
public class SecretHoardRoom extends SecretRoom {
|
||||||
|
|
||||||
|
@ -68,12 +69,8 @@ public class SecretHoardRoom extends SecretRoom {
|
||||||
|
|
||||||
for (Point p : getPoints()){
|
for (Point p : getPoints()){
|
||||||
if (Random.Int(2) == 0 && level.map[level.pointToCell(p)] == Terrain.EMPTY){
|
if (Random.Int(2) == 0 && level.map[level.pointToCell(p)] == Terrain.EMPTY){
|
||||||
try {
|
level.setTrap(Reflection.newInstance(trapClass).reveal(), level.pointToCell(p));
|
||||||
level.setTrap(trapClass.newInstance().reveal(), level.pointToCell(p));
|
Painter.set(level, p, Terrain.TRAP);
|
||||||
Painter.set(level, p, Terrain.TRAP);
|
|
||||||
} catch (Exception e) {
|
|
||||||
ShatteredPixelDungeon.reportException(e);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -41,6 +41,7 @@ import com.shatteredpixel.shatteredpixeldungeon.levels.Terrain;
|
||||||
import com.shatteredpixel.shatteredpixeldungeon.levels.painters.Painter;
|
import com.shatteredpixel.shatteredpixeldungeon.levels.painters.Painter;
|
||||||
import com.watabou.utils.Point;
|
import com.watabou.utils.Point;
|
||||||
import com.watabou.utils.Random;
|
import com.watabou.utils.Random;
|
||||||
|
import com.watabou.utils.Reflection;
|
||||||
|
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
|
|
||||||
|
@ -81,14 +82,9 @@ public class SecretLaboratoryRoom extends SecretRoom {
|
||||||
pos = level.pointToCell(random());
|
pos = level.pointToCell(random());
|
||||||
} while (level.map[pos] != Terrain.EMPTY_SP || level.heaps.get( pos ) != null);
|
} while (level.map[pos] != Terrain.EMPTY_SP || level.heaps.get( pos ) != null);
|
||||||
|
|
||||||
try{
|
Class<?extends Potion> potionCls = Random.chances(chances);
|
||||||
Class<?extends Potion> potionCls = Random.chances(chances);
|
chances.put(potionCls, 0f);
|
||||||
chances.put(potionCls, 0f);
|
level.drop( Reflection.newInstance(potionCls), pos );
|
||||||
level.drop( potionCls.newInstance(), pos );
|
|
||||||
} catch (Exception e){
|
|
||||||
ShatteredPixelDungeon.reportException(e);
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -38,6 +38,7 @@ import com.shatteredpixel.shatteredpixeldungeon.levels.Level;
|
||||||
import com.shatteredpixel.shatteredpixeldungeon.levels.Terrain;
|
import com.shatteredpixel.shatteredpixeldungeon.levels.Terrain;
|
||||||
import com.shatteredpixel.shatteredpixeldungeon.levels.painters.Painter;
|
import com.shatteredpixel.shatteredpixeldungeon.levels.painters.Painter;
|
||||||
import com.watabou.utils.Random;
|
import com.watabou.utils.Random;
|
||||||
|
import com.watabou.utils.Reflection;
|
||||||
|
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
|
|
||||||
|
@ -91,14 +92,9 @@ public class SecretLibraryRoom extends SecretRoom {
|
||||||
pos = level.pointToCell(random());
|
pos = level.pointToCell(random());
|
||||||
} while (level.map[pos] != Terrain.EMPTY_SP || level.heaps.get( pos ) != null);
|
} while (level.map[pos] != Terrain.EMPTY_SP || level.heaps.get( pos ) != null);
|
||||||
|
|
||||||
try{
|
Class<?extends Scroll> scrollCls = Random.chances(chances);
|
||||||
Class<?extends Scroll> scrollCls = Random.chances(chances);
|
chances.put(scrollCls, 0f);
|
||||||
chances.put(scrollCls, 0f);
|
level.drop( Reflection.newInstance(scrollCls), pos );
|
||||||
level.drop( scrollCls.newInstance(), pos );
|
|
||||||
} catch (Exception e){
|
|
||||||
ShatteredPixelDungeon.reportException(e);
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -27,6 +27,7 @@ import com.shatteredpixel.shatteredpixeldungeon.actors.hero.HeroClass;
|
||||||
import com.shatteredpixel.shatteredpixeldungeon.levels.rooms.special.SpecialRoom;
|
import com.shatteredpixel.shatteredpixeldungeon.levels.rooms.special.SpecialRoom;
|
||||||
import com.watabou.utils.Bundle;
|
import com.watabou.utils.Bundle;
|
||||||
import com.watabou.utils.Random;
|
import com.watabou.utils.Random;
|
||||||
|
import com.watabou.utils.Reflection;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
|
@ -102,11 +103,8 @@ public abstract class SecretRoom extends SpecialRoom {
|
||||||
int newidx = Random.Int( runSecrets.size() );
|
int newidx = Random.Int( runSecrets.size() );
|
||||||
if (newidx < index) index = newidx;
|
if (newidx < index) index = newidx;
|
||||||
}
|
}
|
||||||
try {
|
|
||||||
r = runSecrets.get( index ).newInstance();
|
r = Reflection.newInstance(runSecrets.get( index ));
|
||||||
} catch (Exception e) {
|
|
||||||
ShatteredPixelDungeon.reportException(e);
|
|
||||||
}
|
|
||||||
|
|
||||||
runSecrets.add(runSecrets.remove(index));
|
runSecrets.add(runSecrets.remove(index));
|
||||||
|
|
||||||
|
|
|
@ -26,6 +26,7 @@ import com.shatteredpixel.shatteredpixeldungeon.ShatteredPixelDungeon;
|
||||||
import com.shatteredpixel.shatteredpixeldungeon.levels.rooms.Room;
|
import com.shatteredpixel.shatteredpixeldungeon.levels.rooms.Room;
|
||||||
import com.watabou.utils.Bundle;
|
import com.watabou.utils.Bundle;
|
||||||
import com.watabou.utils.Random;
|
import com.watabou.utils.Random;
|
||||||
|
import com.watabou.utils.Reflection;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
|
@ -147,11 +148,8 @@ public abstract class SpecialRoom extends Room {
|
||||||
int newidx = Random.Int( floorSpecials.size() );
|
int newidx = Random.Int( floorSpecials.size() );
|
||||||
if (newidx < index) index = newidx;
|
if (newidx < index) index = newidx;
|
||||||
}
|
}
|
||||||
try {
|
|
||||||
r = floorSpecials.get( index ).newInstance();
|
r = Reflection.newInstance(floorSpecials.get( index ));
|
||||||
} catch (Exception e) {
|
|
||||||
ShatteredPixelDungeon.reportException(e);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (r instanceof WeakFloorRoom){
|
if (r instanceof WeakFloorRoom){
|
||||||
pitNeededDepth = Dungeon.depth + 1;
|
pitNeededDepth = Dungeon.depth + 1;
|
||||||
|
|
|
@ -43,6 +43,7 @@ import com.shatteredpixel.shatteredpixeldungeon.levels.traps.Trap;
|
||||||
import com.shatteredpixel.shatteredpixeldungeon.levels.traps.WarpingTrap;
|
import com.shatteredpixel.shatteredpixeldungeon.levels.traps.WarpingTrap;
|
||||||
import com.watabou.utils.Point;
|
import com.watabou.utils.Point;
|
||||||
import com.watabou.utils.Random;
|
import com.watabou.utils.Random;
|
||||||
|
import com.watabou.utils.Reflection;
|
||||||
|
|
||||||
public class TrapsRoom extends SpecialRoom {
|
public class TrapsRoom extends SpecialRoom {
|
||||||
|
|
||||||
|
@ -94,11 +95,7 @@ public class TrapsRoom extends SpecialRoom {
|
||||||
for(Point p : getPoints()) {
|
for(Point p : getPoints()) {
|
||||||
int cell = level.pointToCell(p);
|
int cell = level.pointToCell(p);
|
||||||
if (level.map[cell] == Terrain.TRAP){
|
if (level.map[cell] == Terrain.TRAP){
|
||||||
try {
|
level.setTrap(Reflection.newInstance(trapClass).reveal(), cell);
|
||||||
level.setTrap(((Trap) trapClass.newInstance()).reveal(), cell);
|
|
||||||
} catch (Exception e) {
|
|
||||||
ShatteredPixelDungeon.reportException(e);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -25,6 +25,7 @@ import com.shatteredpixel.shatteredpixeldungeon.Dungeon;
|
||||||
import com.shatteredpixel.shatteredpixeldungeon.ShatteredPixelDungeon;
|
import com.shatteredpixel.shatteredpixeldungeon.ShatteredPixelDungeon;
|
||||||
import com.shatteredpixel.shatteredpixeldungeon.levels.rooms.Room;
|
import com.shatteredpixel.shatteredpixeldungeon.levels.rooms.Room;
|
||||||
import com.watabou.utils.Random;
|
import com.watabou.utils.Random;
|
||||||
|
import com.watabou.utils.Reflection;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
|
|
||||||
|
@ -156,12 +157,7 @@ public abstract class StandardRoom extends Room {
|
||||||
|
|
||||||
|
|
||||||
public static StandardRoom createRoom(){
|
public static StandardRoom createRoom(){
|
||||||
try{
|
return Reflection.newInstance(rooms.get(Random.chances(chances[Dungeon.depth])));
|
||||||
return rooms.get(Random.chances(chances[Dungeon.depth])).newInstance();
|
|
||||||
} catch (Exception e) {
|
|
||||||
ShatteredPixelDungeon.reportException(e);
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -41,6 +41,7 @@ import com.watabou.noosa.audio.Sample;
|
||||||
import com.watabou.utils.Bundlable;
|
import com.watabou.utils.Bundlable;
|
||||||
import com.watabou.utils.Bundle;
|
import com.watabou.utils.Bundle;
|
||||||
import com.watabou.utils.PathFinder;
|
import com.watabou.utils.PathFinder;
|
||||||
|
import com.watabou.utils.Reflection;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
|
|
||||||
|
@ -150,17 +151,12 @@ public abstract class Plant implements Bundlable {
|
||||||
}
|
}
|
||||||
|
|
||||||
public Plant couch( int pos, Level level ) {
|
public Plant couch( int pos, Level level ) {
|
||||||
try {
|
if (level != null && level.heroFOV != null && level.heroFOV[pos]) {
|
||||||
if (level != null && level.heroFOV != null && level.heroFOV[pos]) {
|
Sample.INSTANCE.play(Assets.SND_PLANT);
|
||||||
Sample.INSTANCE.play(Assets.SND_PLANT);
|
|
||||||
}
|
|
||||||
Plant plant = plantClass.newInstance();
|
|
||||||
plant.pos = pos;
|
|
||||||
return plant;
|
|
||||||
} catch (Exception e) {
|
|
||||||
ShatteredPixelDungeon.reportException(e);
|
|
||||||
return null;
|
|
||||||
}
|
}
|
||||||
|
Plant plant = Reflection.newInstance(plantClass);
|
||||||
|
plant.pos = pos;
|
||||||
|
return plant;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|
|
@ -41,6 +41,7 @@ import com.watabou.noosa.Scene;
|
||||||
import com.watabou.noosa.Visual;
|
import com.watabou.noosa.Visual;
|
||||||
import com.watabou.noosa.ui.Component;
|
import com.watabou.noosa.ui.Component;
|
||||||
import com.watabou.utils.BitmapCache;
|
import com.watabou.utils.BitmapCache;
|
||||||
|
import com.watabou.utils.Reflection;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
|
|
||||||
|
@ -152,7 +153,7 @@ public class PixelScene extends Scene {
|
||||||
if (getClass().equals(savedClass)){
|
if (getClass().equals(savedClass)){
|
||||||
for (Class<?extends Window> w : savedWindows){
|
for (Class<?extends Window> w : savedWindows){
|
||||||
try{
|
try{
|
||||||
add(w.newInstance());
|
add(Reflection.newInstanceUnhandled(w));
|
||||||
} catch (Exception e){
|
} catch (Exception e){
|
||||||
//window has no public zero-arg constructor, just eat the exception
|
//window has no public zero-arg constructor, just eat the exception
|
||||||
}
|
}
|
||||||
|
|
|
@ -29,6 +29,7 @@ import com.shatteredpixel.shatteredpixeldungeon.scenes.PixelScene;
|
||||||
import com.shatteredpixel.shatteredpixeldungeon.sprites.CharSprite;
|
import com.shatteredpixel.shatteredpixeldungeon.sprites.CharSprite;
|
||||||
import com.watabou.noosa.Game;
|
import com.watabou.noosa.Game;
|
||||||
import com.watabou.utils.Random;
|
import com.watabou.utils.Random;
|
||||||
|
import com.watabou.utils.Reflection;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
|
|
||||||
|
@ -134,21 +135,16 @@ public class AttackIndicator extends Tag {
|
||||||
sprite = null;
|
sprite = null;
|
||||||
}
|
}
|
||||||
|
|
||||||
try {
|
sprite = Reflection.newInstance(lastTarget.spriteClass);
|
||||||
sprite = lastTarget.spriteClass.newInstance();
|
active = true;
|
||||||
active = true;
|
sprite.linkVisuals(lastTarget);
|
||||||
sprite.linkVisuals(lastTarget);
|
sprite.idle();
|
||||||
sprite.idle();
|
sprite.paused = true;
|
||||||
sprite.paused = true;
|
add( sprite );
|
||||||
add( sprite );
|
|
||||||
|
|
||||||
sprite.x = x + (width - sprite.width()) / 2 + 1;
|
sprite.x = x + (width - sprite.width()) / 2 + 1;
|
||||||
sprite.y = y + (height - sprite.height()) / 2;
|
sprite.y = y + (height - sprite.height()) / 2;
|
||||||
PixelScene.align(sprite);
|
PixelScene.align(sprite);
|
||||||
|
|
||||||
} catch (Exception e) {
|
|
||||||
ShatteredPixelDungeon.reportException(e);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private boolean enabled = true;
|
private boolean enabled = true;
|
||||||
|
|
|
@ -73,6 +73,7 @@ import com.watabou.noosa.BitmapText;
|
||||||
import com.watabou.noosa.Group;
|
import com.watabou.noosa.Group;
|
||||||
import com.watabou.noosa.Image;
|
import com.watabou.noosa.Image;
|
||||||
import com.watabou.noosa.ui.Component;
|
import com.watabou.noosa.ui.Component;
|
||||||
|
import com.watabou.utils.Reflection;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
|
@ -254,14 +255,10 @@ public class QuickRecipe extends Component {
|
||||||
case 1:
|
case 1:
|
||||||
Recipe r = new Scroll.ScrollToStone();
|
Recipe r = new Scroll.ScrollToStone();
|
||||||
for (Class<?> cls : Generator.Category.SCROLL.classes){
|
for (Class<?> cls : Generator.Category.SCROLL.classes){
|
||||||
try{
|
Scroll scroll = (Scroll) Reflection.newInstance(cls);
|
||||||
Scroll scroll = (Scroll) cls.newInstance();
|
if (!scroll.isKnown()) scroll.anonymize();
|
||||||
if (!scroll.isKnown()) scroll.anonymize();
|
ArrayList<Item> in = new ArrayList<Item>(Arrays.asList(scroll));
|
||||||
ArrayList<Item> in = new ArrayList<Item>(Arrays.asList(scroll));
|
result.add(new QuickRecipe( r, in, r.sampleOutput(in)));
|
||||||
result.add(new QuickRecipe( r, in, r.sampleOutput(in)));
|
|
||||||
} catch (Exception e){
|
|
||||||
ShatteredPixelDungeon.reportException(e);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
return result;
|
return result;
|
||||||
case 2:
|
case 2:
|
||||||
|
@ -292,42 +289,30 @@ public class QuickRecipe extends Component {
|
||||||
r = new Bomb.EnhanceBomb();
|
r = new Bomb.EnhanceBomb();
|
||||||
int i = 0;
|
int i = 0;
|
||||||
for (Class<?> cls : Bomb.EnhanceBomb.validIngredients.keySet()){
|
for (Class<?> cls : Bomb.EnhanceBomb.validIngredients.keySet()){
|
||||||
try{
|
if (i == 2){
|
||||||
if (i == 2){
|
result.add(null);
|
||||||
result.add(null);
|
i = 0;
|
||||||
i = 0;
|
|
||||||
}
|
|
||||||
Item item = (Item) cls.newInstance();
|
|
||||||
ArrayList<Item> in = new ArrayList<Item>(Arrays.asList(new Bomb(), item));
|
|
||||||
result.add(new QuickRecipe( r, in, r.sampleOutput(in)));
|
|
||||||
i++;
|
|
||||||
} catch (Exception e){
|
|
||||||
ShatteredPixelDungeon.reportException(e);
|
|
||||||
}
|
}
|
||||||
|
Item item = (Item) Reflection.newInstance(cls);
|
||||||
|
ArrayList<Item> in = new ArrayList<Item>(Arrays.asList(new Bomb(), item));
|
||||||
|
result.add(new QuickRecipe( r, in, r.sampleOutput(in)));
|
||||||
|
i++;
|
||||||
}
|
}
|
||||||
return result;
|
return result;
|
||||||
case 4:
|
case 4:
|
||||||
r = new ExoticPotion.PotionToExotic();
|
r = new ExoticPotion.PotionToExotic();
|
||||||
for (Class<?> cls : Generator.Category.POTION.classes){
|
for (Class<?> cls : Generator.Category.POTION.classes){
|
||||||
try{
|
Potion pot = (Potion) Reflection.newInstance(cls);
|
||||||
Potion pot = (Potion) cls.newInstance();
|
ArrayList<Item> in = new ArrayList<>(Arrays.asList(pot, new Plant.Seed.PlaceHolder().quantity(2)));
|
||||||
ArrayList<Item> in = new ArrayList<>(Arrays.asList(pot, new Plant.Seed.PlaceHolder().quantity(2)));
|
result.add(new QuickRecipe( r, in, r.sampleOutput(in)));
|
||||||
result.add(new QuickRecipe( r, in, r.sampleOutput(in)));
|
|
||||||
} catch (Exception e){
|
|
||||||
ShatteredPixelDungeon.reportException(e);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
return result;
|
return result;
|
||||||
case 5:
|
case 5:
|
||||||
r = new ExoticScroll.ScrollToExotic();
|
r = new ExoticScroll.ScrollToExotic();
|
||||||
for (Class<?> cls : Generator.Category.SCROLL.classes){
|
for (Class<?> cls : Generator.Category.SCROLL.classes){
|
||||||
try{
|
Scroll scroll = (Scroll) Reflection.newInstance(cls);
|
||||||
Scroll scroll = (Scroll) cls.newInstance();
|
ArrayList<Item> in = new ArrayList<>(Arrays.asList(scroll, new Runestone.PlaceHolder().quantity(2)));
|
||||||
ArrayList<Item> in = new ArrayList<>(Arrays.asList(scroll, new Runestone.PlaceHolder().quantity(2)));
|
result.add(new QuickRecipe( r, in, r.sampleOutput(in)));
|
||||||
result.add(new QuickRecipe( r, in, r.sampleOutput(in)));
|
|
||||||
} catch (Exception e){
|
|
||||||
ShatteredPixelDungeon.reportException(e);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
return result;
|
return result;
|
||||||
case 6:
|
case 6:
|
||||||
|
|
|
@ -46,6 +46,7 @@ import com.watabou.noosa.BitmapText;
|
||||||
import com.watabou.noosa.ColorBlock;
|
import com.watabou.noosa.ColorBlock;
|
||||||
import com.watabou.noosa.Image;
|
import com.watabou.noosa.Image;
|
||||||
import com.watabou.noosa.ui.Component;
|
import com.watabou.noosa.ui.Component;
|
||||||
|
import com.watabou.utils.Reflection;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.Collections;
|
import java.util.Collections;
|
||||||
|
@ -669,16 +670,12 @@ public class WndJournal extends WndTabbed {
|
||||||
|
|
||||||
float pos = 0;
|
float pos = 0;
|
||||||
for (Class<? extends Item> itemClass : itemClasses) {
|
for (Class<? extends Item> itemClass : itemClasses) {
|
||||||
try{
|
CatalogItem item = new CatalogItem(Reflection.newInstance(itemClass), known.get(itemClass), Catalog.isSeen(itemClass));
|
||||||
CatalogItem item = new CatalogItem(itemClass.newInstance(), known.get(itemClass), Catalog.isSeen(itemClass));
|
item.setRect( 0, pos, width, ITEM_HEIGHT );
|
||||||
item.setRect( 0, pos, width, ITEM_HEIGHT );
|
content.add( item );
|
||||||
content.add( item );
|
items.add( item );
|
||||||
items.add( item );
|
|
||||||
|
pos += item.height();
|
||||||
pos += item.height();
|
|
||||||
} catch (Exception e) {
|
|
||||||
ShatteredPixelDungeon.reportException(e);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
content.setSize( width, pos );
|
content.setSize( width, pos );
|
||||||
|
|
Loading…
Reference in New Issue
Block a user