v0.3.4: reworked rankings to store their cause instead of a result string

This commit is contained in:
Evan Debenham 2016-01-23 02:12:18 -05:00 committed by Evan Debenham
parent 0e2fbc05fb
commit ac967fad27
36 changed files with 79 additions and 65 deletions

View File

@ -126,8 +126,6 @@ public class Dungeon {
public static int depth;
public static int gold;
// Reason of death
public static String resultDescription;
public static HashSet<Integer> chapters;
@ -672,14 +670,13 @@ public class Dungeon {
Hero.preview( info, bundle.getBundle( HERO ) );
}
public static void fail( String desc ) {
resultDescription = desc;
public static void fail( Class cause ) {
if (hero.belongings.getItem( Ankh.class ) == null) {
Rankings.INSTANCE.submit( false );
Rankings.INSTANCE.submit( false, cause );
}
}
public static void win( String desc ) {
public static void win( Class cause ) {
hero.belongings.identify();
@ -687,8 +684,7 @@ public class Dungeon {
Badges.validateChampion();
}
resultDescription = desc;
Rankings.INSTANCE.submit( true );
Rankings.INSTANCE.submit( true, cause );
}
public static void observe() {

View File

@ -28,6 +28,7 @@ import java.util.Collections;
import java.util.Comparator;
import com.shatteredpixel.shatteredpixeldungeon.actors.hero.Hero;
import com.shatteredpixel.shatteredpixeldungeon.messages.Messages;
import com.watabou.noosa.Game;
import com.shatteredpixel.shatteredpixeldungeon.actors.hero.HeroClass;
import com.shatteredpixel.shatteredpixeldungeon.utils.Utils;
@ -49,13 +50,13 @@ public enum Rankings {
public int totalNumber;
public int wonNumber;
public void submit( boolean win ) {
public void submit( boolean win, Class cause ) {
load();
Record rec = new Record();
rec.info = Dungeon.resultDescription;
rec.cause = cause;
rec.win = win;
rec.heroClass = Dungeon.hero.heroClass;
rec.armorTier = Dungeon.hero.tier();
@ -167,7 +168,11 @@ public enum Rankings {
public static class Record implements Bundlable {
//pre 0.3.4
public String info;
private static final String REASON = "reason";
private static final String CAUSE = "cause";
private static final String WIN = "win";
private static final String SCORE = "score";
private static final String TIER = "tier";
@ -175,7 +180,7 @@ public enum Rankings {
private static final String DEPTH = "depth";
private static final String GAME = "gameFile";
public String info;
public Class cause;
public boolean win;
public HeroClass heroClass;
@ -187,10 +192,28 @@ public enum Rankings {
public String gameFile;
public String deathDesc(){
if (cause == null && (info == null || info.equals("")))
return "Killed by Something";
else if (cause == null){
return info; //pre 0.3.4 saves
} else {
String result = Messages.get(cause, "rankings_desc", (Messages.get(cause, "name")));
if (result.contains("!!!NO TEXT FOUND!!!")){
return "Killed By Something";
} else {
return result;
}
}
}
@Override
public void restoreFromBundle( Bundle bundle ) {
//pre-0.3.4
info = bundle.getString( REASON );
cause = bundle.getClass( CAUSE );
win = bundle.getBoolean( WIN );
score = bundle.getInt( SCORE );
@ -239,7 +262,9 @@ public enum Rankings {
@Override
public void storeInBundle( Bundle bundle ) {
bundle.put( REASON, info );
if (info != null && !info.equals("")) bundle.put( REASON, info );
else bundle.put( CAUSE, cause );
bundle.put( WIN, win );
bundle.put( SCORE, score );

View File

@ -153,14 +153,7 @@ public abstract class Char extends Actor {
if (!enemy.isAlive() && visibleFight) {
if (enemy == Dungeon.hero) {
if ( this instanceof Yog ) {
Dungeon.fail( Utils.format( ResultDescriptions.NAMED, name) );
} else if (properties().contains(Property.MINIBOSS) || properties().contains(Property.BOSS)) {
Dungeon.fail( Utils.format( ResultDescriptions.UNIQUE, name) );
} else {
Dungeon.fail( Utils.format( ResultDescriptions.MOB, Utils.indefinite( name )) );
}
Dungeon.fail( getClass() );
GLog.n( Messages.get(Char.class, "kill", name) );
} else if (this == Dungeon.hero) {

View File

@ -72,7 +72,7 @@ public class ToxicGas extends Blob implements Hero.Doom {
Badges.validateDeathFromGas();
Dungeon.fail( ResultDescriptions.GAS );
Dungeon.fail( getClass() );
GLog.n( Messages.get(this, "ondeath") );
}
}

View File

@ -55,7 +55,7 @@ public class Bleeding extends Buff {
public void set( int level ) {
this.level = level;
};
}
@Override
public int icon() {
@ -80,7 +80,7 @@ public class Bleeding extends Buff {
}
if (target == Dungeon.hero && !target.isAlive()) {
Dungeon.fail( ResultDescriptions.BLEEDING );
Dungeon.fail( getClass() );
GLog.n( Messages.get(this, "ondeath") );
}

View File

@ -170,7 +170,7 @@ public class Burning extends Buff implements Hero.Doom {
Badges.validateDeathFromFire();
Dungeon.fail( ResultDescriptions.BURNING );
Dungeon.fail( getClass() );
GLog.n( Messages.get(this, "ondeath") );
}
}

View File

@ -188,7 +188,7 @@ public class Hunger extends Buff implements Hero.Doom {
Badges.validateDeathFromHunger();
Dungeon.fail( ResultDescriptions.HUNGER );
Dungeon.fail( getClass() );
GLog.n( Messages.get(this, "ondeath") );
}
}

View File

@ -62,7 +62,7 @@ public class Ooze extends Buff {
else if (Random.Int(2) == 0)
target.damage( 1, this );
if (!target.isAlive() && target == Dungeon.hero) {
Dungeon.fail( ResultDescriptions.OOZE );
Dungeon.fail( getClass() );
GLog.n( Messages.get(this, "ondeath") );
}
spend( TICK );

View File

@ -58,7 +58,7 @@ public class Poison extends Buff implements Hero.Doom {
public void set( float duration ) {
this.left = duration;
};
}
@Override
public int icon() {
@ -118,7 +118,7 @@ public class Poison extends Buff implements Hero.Doom {
public void onDeath() {
Badges.validateDeathFromPoison();
Dungeon.fail( ResultDescriptions.POISON );
Dungeon.fail( getClass() );
GLog.n( "You died from poison..." );
}
}

View File

@ -770,7 +770,7 @@ public class Hero extends Char {
GameScene.show( new WndMessage( Messages.get(this, "leave") ) );
ready();
} else {
Dungeon.win( ResultDescriptions.WIN );
Dungeon.win( Amulet.class );
Dungeon.deleteGame( Dungeon.hero.heroClass, true );
Game.switchScene( SurfaceScene.class );
}

View File

@ -128,7 +128,7 @@ public class Eye extends Mob {
}
if (!ch.isAlive() && ch == Dungeon.hero) {
Dungeon.fail( Utils.format( ResultDescriptions.MOB, Utils.indefinite( name ) ) );
Dungeon.fail( getClass() );
GLog.n( Messages.get(this, "deathgaze_kill") );
}
} else {

View File

@ -107,7 +107,7 @@ public class Shaman extends Mob implements Callback {
Camera.main.shake( 2, 0.3f );
if (!enemy.isAlive()) {
Dungeon.fail( Utils.format( ResultDescriptions.MOB, Utils.indefinite( name ) ) );
Dungeon.fail( getClass() );
GLog.n( Messages.get(this, "zap_kill") );
}
}

View File

@ -83,7 +83,7 @@ public class Skeleton extends Mob {
}
if (heroKilled) {
Dungeon.fail( Utils.format( ResultDescriptions.MOB, Utils.indefinite( name ) ) );
Dungeon.fail( getClass() );
GLog.n( Messages.get(this, "explo_kill") );
}
}

View File

@ -111,7 +111,7 @@ public class Warlock extends Mob implements Callback {
enemy.damage( dmg, this );
if (!enemy.isAlive() && enemy == Dungeon.hero) {
Dungeon.fail( Utils.format( ResultDescriptions.MOB, Utils.indefinite( name ) ) );
Dungeon.fail( getClass() );
GLog.n( Messages.get(this, "bolt_kill") );
}
} else {

View File

@ -346,7 +346,7 @@ public class Yog extends Mob {
enemy.sprite.flash();
if (!enemy.isAlive() && enemy == Dungeon.hero) {
Dungeon.fail( Utils.format( ResultDescriptions.UNIQUE, name ) );
Dungeon.fail( getClass() );
GLog.n( Messages.get(Char.class, "kill", name) );
}
return true;

View File

@ -149,7 +149,7 @@ public class Bomb extends Item {
}
if (ch == Dungeon.hero && !ch.isAlive())
Dungeon.fail( Messages.get(this, "ondeath") );
Dungeon.fail( getClass() );
}
}
}

View File

@ -152,7 +152,7 @@ public class Armor extends EquipableItem {
if (inscribe) {
inscribe( Glyph.random() );
}
};
}
STR--;
@ -339,7 +339,7 @@ public class Armor extends EquipableItem {
public boolean checkOwner( Char owner ) {
if (!owner.isAlive() && owner instanceof Hero) {
Dungeon.fail( Utils.format( ResultDescriptions.GLYPH, name() ) );
Dungeon.fail( getClass() );
GLog.n( Messages.get(this, "killed", name()) );
Badges.validateDeathFromGlyph();

View File

@ -104,7 +104,7 @@ public class Viscosity extends Glyph {
public void prolong( int damage ) {
this.damage += damage;
};
}
@Override
public int icon() {
@ -124,7 +124,7 @@ public class Viscosity extends Glyph {
if (target == Dungeon.hero && !target.isAlive()) {
Glyph glyph = new Viscosity();
Dungeon.fail( Utils.format( ResultDescriptions.GLYPH, glyph.name() ) );
Dungeon.fail( glyph.getClass() );
GLog.n( Messages.get(Glyph.class, "killed", glyph.name()) );
Badges.validateDeathFromGlyph();

View File

@ -74,7 +74,7 @@ public class ChaliceOfBlood extends Artifact {
protected void onSelect(int index) {
if (index == 0)
prick(Dungeon.hero);
};
}
}
);
@ -108,7 +108,7 @@ public class ChaliceOfBlood extends Artifact {
hero.damage(damage, this);
if (!hero.isAlive()) {
Dungeon.fail(Utils.format( ResultDescriptions.ITEM, name ));
Dungeon.fail( getClass() );
GLog.n( Messages.get(this, "ondeath") );
} else {
upgrade();

View File

@ -68,7 +68,7 @@ public class ScrollOfPsionicBlast extends Scroll {
curUser.spendAndNext( TIME_TO_READ ); //no animation here, the flash interrupts it anyway.
if (!curUser.isAlive()) {
Dungeon.fail( Utils.format(ResultDescriptions.ITEM, name ));
Dungeon.fail( getClass() );
GLog.n( Messages.get(this, "ondeath") );
}
}

View File

@ -250,7 +250,7 @@ public class CursedWand {
target.sprite.emitter().burst(Speck.factory(Speck.HEALING), 3);
Sample.INSTANCE.play(Assets.SND_CURSED);
if (!user.isAlive()) {
Dungeon.fail(Utils.format(ResultDescriptions.ITEM, wand.name()));
Dungeon.fail( wand.getClass() );
GLog.n(Messages.get(CursedWand.class, "ondeath", wand.name()));
}
break;

View File

@ -100,7 +100,7 @@ public class WandOfBlastWave extends Wand {
}
if (!curUser.isAlive()) {
Dungeon.fail( Utils.format(ResultDescriptions.ITEM, name) );
Dungeon.fail( getClass() );
GLog.n( Messages.get( this, "ondeath") );
}
}

View File

@ -73,7 +73,7 @@ public class WandOfLightning extends Wand {
}
if (!curUser.isAlive()) {
Dungeon.fail( Utils.format( ResultDescriptions.ITEM, name ) );
Dungeon.fail( getClass() );
GLog.n(Messages.get(this, "ondeath"));
}
}

View File

@ -173,7 +173,6 @@ public class WandOfTransfusion extends Wand {
}
}
//this wand costs health too
private void damageHero(){
// 15% of max hp
@ -181,7 +180,7 @@ public class WandOfTransfusion extends Wand {
curUser.damage(damage, this);
if (!curUser.isAlive()){
Dungeon.fail( Utils.format(ResultDescriptions.ITEM, name) );
Dungeon.fail( getClass() );
GLog.n( Messages.get(this, "ondeath") );
}
}

View File

@ -59,7 +59,7 @@ public class Chasm {
jumpConfirmed = true;
hero.resume();
}
};
}
}
);
}
@ -104,7 +104,7 @@ public class Chasm {
public void onDeath() {
Badges.validateDeathFromFalling();
Dungeon.fail( ResultDescriptions.FALL );
Dungeon.fail( getClass() );
GLog.n( Messages.get(Chasm.class, "ondeath") );
}
} );

View File

@ -57,7 +57,7 @@ public class ChillingTrap extends Trap{
Chill.prolong(ch, Chill.class, 5f + Random.Int(Dungeon.depth));
ch.damage(Random.NormalIntRange(1 , Dungeon.depth), this);
if (!ch.isAlive() && ch == Dungeon.hero){
Dungeon.fail( Utils.format(ResultDescriptions.TRAP, name) );
Dungeon.fail( getClass() );
GLog.n( Messages.get(this, "ondeath") );
}
}

View File

@ -66,7 +66,7 @@ public class DisintegrationTrap extends Trap {
if (ch == Dungeon.hero){
Hero hero = (Hero)ch;
if (!hero.isAlive()){
Dungeon.fail(Utils.format(ResultDescriptions.TRAP, name));
Dungeon.fail( getClass() );
GLog.n( Messages.get(this, "ondeath") );
} else {
Item item = hero.belongings.randomUnequipped();

View File

@ -59,7 +59,7 @@ public class FrostTrap extends Trap {
ch.damage(Random.NormalIntRange(1 , Dungeon.depth), this);
Chill.prolong(ch, Frost.class, 10f + Random.Int(Dungeon.depth));
if (!ch.isAlive() && ch == Dungeon.hero){
Dungeon.fail( Utils.format(ResultDescriptions.TRAP, name) );
Dungeon.fail( getClass() );
GLog.n( Messages.get(this, "ondeath") );
}
}

View File

@ -81,7 +81,7 @@ public class GrimTrap extends Trap {
}
Sample.INSTANCE.play(Assets.SND_CURSED);
if (!finalTarget.isAlive()) {
Dungeon.fail(Utils.format(ResultDescriptions.TRAP, name));
Dungeon.fail( getClass() );
GLog.n( Messages.get(this, "ondeath") );
}
} else {

View File

@ -61,7 +61,7 @@ public class LightningTrap extends Trap {
Camera.main.shake( 2, 0.3f );
if (!ch.isAlive()) {
Dungeon.fail( Utils.format( ResultDescriptions.TRAP, name ) );
Dungeon.fail( getClass() );
GLog.n( Messages.get(this, "ondeath") );
}
}

View File

@ -64,7 +64,7 @@ public class RockfallTrap extends Trap {
Buff.prolong( ch, Paralysis.class, Paralysis.duration(ch)*2);
if (!ch.isAlive() && ch == Dungeon.hero){
Dungeon.fail(Utils.format(ResultDescriptions.TRAP, name));
Dungeon.fail( getClass() );
GLog.n( Messages.get(this, "ondeath") );
}
}

View File

@ -66,7 +66,7 @@ public class SpearTrap extends Trap {
damage -= Random.IntRange( 0, ch.dr());
ch.damage( Math.max(damage, 0) , this);
if (!ch.isAlive() && ch == Dungeon.hero){
Dungeon.fail(Utils.format(ResultDescriptions.TRAP, name));
Dungeon.fail( getClass() );
GLog.n( Messages.get(this, "ondeath") );
}
}

View File

@ -20,6 +20,7 @@
*/
package com.shatteredpixel.shatteredpixeldungeon.scenes;
import com.shatteredpixel.shatteredpixeldungeon.items.Amulet;
import com.shatteredpixel.shatteredpixeldungeon.messages.Messages;
import com.watabou.noosa.Camera;
import com.watabou.noosa.Game;
@ -61,7 +62,7 @@ public class AmuletScene extends PixelScene {
RedButton btnExit = new RedButton( Messages.get(this, "exit") ) {
@Override
protected void onClick() {
Dungeon.win( ResultDescriptions.WIN );
Dungeon.win( Amulet.class );
Dungeon.deleteGame( Dungeon.hero.heroClass, true );
Game.switchScene( noText ? TitleScene.class : RankingsScene.class );
}

View File

@ -185,7 +185,7 @@ public class RankingsScene extends PixelScene {
position.text(" ");
position.measure();
desc.text( rec.info );
desc.text( rec.deathDesc() );
//desc.measure();
@ -277,8 +277,8 @@ public class RankingsScene extends PixelScene {
depth.x = steps.x + (steps.width - depth.width()) / 2;
depth.y = steps.y + (steps.height - depth.height()) / 2 + 1;
desc.setPos(shield.x + shield.width + GAP, shield.y + (shield.height - desc.height()) / 2 + 1);
desc.maxWidth((int)(steps.x - desc.left()));
desc.setPos(shield.x + shield.width + GAP, shield.y + (shield.height - desc.height()) / 2 + 1);
}
@Override

View File

@ -79,7 +79,7 @@ public class WndResurrect extends Window {
protected void onClick() {
hide();
Rankings.INSTANCE.submit( false );
Rankings.INSTANCE.submit( false, WndResurrect.causeOfDeath.getClass() );
Hero.reallyDie( WndResurrect.causeOfDeath );
}
};