v0.9.1b: added various safety checks to prevent crashes
This commit is contained in:
parent
90721786a2
commit
4f4174c7b9
|
@ -39,20 +39,20 @@ public class Random {
|
|||
resetGenerators();
|
||||
}
|
||||
|
||||
public static void resetGenerators(){
|
||||
public static synchronized void resetGenerators(){
|
||||
generators = new ArrayDeque<>();
|
||||
generators.push(new java.util.Random());
|
||||
}
|
||||
|
||||
public static void pushGenerator(){
|
||||
public static synchronized void pushGenerator(){
|
||||
generators.push( new java.util.Random() );
|
||||
}
|
||||
|
||||
public static void pushGenerator( long seed ){
|
||||
public static synchronized void pushGenerator( long seed ){
|
||||
generators.push( new java.util.Random( seed ) );
|
||||
}
|
||||
|
||||
public static void popGenerator(){
|
||||
public static synchronized void popGenerator(){
|
||||
if (generators.size() == 1){
|
||||
Game.reportException( new RuntimeException("tried to pop the last random number generator!"));
|
||||
} else {
|
||||
|
@ -61,7 +61,7 @@ public class Random {
|
|||
}
|
||||
|
||||
//returns a uniformly distributed float in the range [0, 1)
|
||||
public static float Float() {
|
||||
public static synchronized float Float() {
|
||||
return generators.peek().nextFloat();
|
||||
}
|
||||
|
||||
|
@ -81,7 +81,7 @@ public class Random {
|
|||
}
|
||||
|
||||
//returns a uniformly distributed int in the range [0, max)
|
||||
public static int Int( int max ) {
|
||||
public static synchronized int Int( int max ) {
|
||||
return max > 0 ? generators.peek().nextInt(max) : 0;
|
||||
}
|
||||
|
||||
|
@ -101,7 +101,7 @@ public class Random {
|
|||
}
|
||||
|
||||
//returns a uniformly distributed long in the range [-2^63, 2^63)
|
||||
public static long Long() {
|
||||
public static synchronized long Long() {
|
||||
return generators.peek().nextLong();
|
||||
}
|
||||
|
||||
|
@ -190,7 +190,7 @@ public class Random {
|
|||
null;
|
||||
}
|
||||
|
||||
public static<T> void shuffle( List<?extends T> list){
|
||||
public synchronized static<T> void shuffle( List<?extends T> list){
|
||||
Collections.shuffle(list, generators.peek());
|
||||
}
|
||||
|
||||
|
|
|
@ -570,7 +570,8 @@ public class Item implements Bundlable {
|
|||
@Override
|
||||
public void call() {
|
||||
curUser = user;
|
||||
Item.this.detach(user.belongings.backpack).onThrow(cell);
|
||||
Item i = Item.this.detach(user.belongings.backpack);
|
||||
if (i != null) i.onThrow(cell);
|
||||
if (curUser.hasTalent(Talent.IMPROVISED_PROJECTILES)
|
||||
&& !(Item.this instanceof MissileWeapon)
|
||||
&& curUser.buff(Talent.ImprovisedProjectileCooldown.class) == null){
|
||||
|
|
|
@ -22,6 +22,7 @@
|
|||
package com.shatteredpixel.shatteredpixeldungeon.sprites;
|
||||
|
||||
import com.shatteredpixel.shatteredpixeldungeon.Assets;
|
||||
import com.watabou.noosa.Game;
|
||||
import com.watabou.noosa.TextureFilm;
|
||||
|
||||
public class GhoulSprite extends MobSprite {
|
||||
|
@ -44,10 +45,10 @@ public class GhoulSprite extends MobSprite {
|
|||
attack = new Animation( 12, false );
|
||||
attack.frames( frames, 0, 8, 9 );
|
||||
|
||||
crumple = new Animation( 15, false);
|
||||
crumple = new Animation( 1, false);
|
||||
crumple.frames( frames, 0, 10, 11, 12 );
|
||||
|
||||
die = new Animation( 15, false );
|
||||
die = new Animation( 1, false );
|
||||
die.frames( frames, 0, 10, 11, 12, 13 );
|
||||
|
||||
play( idle );
|
||||
|
@ -58,6 +59,16 @@ public class GhoulSprite extends MobSprite {
|
|||
play(crumple);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void move(int from, int to) {
|
||||
if (parent == null){
|
||||
//fixme this happens rarely, likely due to ghoul like link?
|
||||
Game.reportException(new RuntimeException("ghoul sprite tried to move with null parent! ghoul HP: " + ch.HP));
|
||||
return;
|
||||
}
|
||||
super.move(from, to);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void die() {
|
||||
if (curAnim == crumple){
|
||||
|
|
Loading…
Reference in New Issue
Block a user