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