v0.8.0: refactored how character names are stored and accessed

This commit is contained in:
Evan Debenham 2019-12-07 17:30:34 -05:00
parent c36844cbcf
commit 8bcb1e4630
22 changed files with 47 additions and 45 deletions

View File

@ -140,7 +140,7 @@ public class GamesInProgress {
info.goldCollected = Statistics.goldCollected; info.goldCollected = Statistics.goldCollected;
info.maxDepth = Statistics.deepestFloor; info.maxDepth = Statistics.deepestFloor;
slotStates.put( slot, info ); slotStates.put( slot, info );
} }

View File

@ -101,8 +101,6 @@ public abstract class Char extends Actor {
public CharSprite sprite; public CharSprite sprite;
public String name = "mob";
public int HT; public int HT;
public int HP; public int HP;
@ -137,6 +135,10 @@ public abstract class Char extends Actor {
return false; return false;
} }
public String name(){
return Messages.get(this, "name");
}
public boolean canInteract( Hero h ){ public boolean canInteract( Hero h ){
return Dungeon.level.adjacent( pos, h.pos ); return Dungeon.level.adjacent( pos, h.pos );
} }
@ -293,10 +295,10 @@ public abstract class Char extends Actor {
} }
Dungeon.fail( getClass() ); Dungeon.fail( getClass() );
GLog.n( Messages.capitalize(Messages.get(Char.class, "kill", name)) ); GLog.n( Messages.capitalize(Messages.get(Char.class, "kill", name())) );
} else if (this == Dungeon.hero) { } else if (this == Dungeon.hero) {
GLog.i( Messages.capitalize(Messages.get(Char.class, "defeat", enemy.name)) ); GLog.i( Messages.capitalize(Messages.get(Char.class, "defeat", enemy.name())) );
} }
} }

View File

@ -301,7 +301,7 @@ public class Combo extends Buff implements ActionIndicator.Action {
enemy.sprite.flash(); enemy.sprite.flash();
if (!enemy.isAlive()){ if (!enemy.isAlive()){
GLog.i( Messages.capitalize(Messages.get(Char.class, "defeat", enemy.name)) ); GLog.i( Messages.capitalize(Messages.get(Char.class, "defeat", enemy.name())) );
} }
Hero hero = (Hero)target; Hero hero = (Hero)target;

View File

@ -181,11 +181,10 @@ public class Hero extends Char {
//This list is maintained so that some logic checks can be skipped //This list is maintained so that some logic checks can be skipped
// for enemies we know we aren't seeing normally, resultign in better performance // for enemies we know we aren't seeing normally, resultign in better performance
public ArrayList<Mob> mindVisionEnemies = new ArrayList<>(); public ArrayList<Mob> mindVisionEnemies = new ArrayList<>();
public Hero() { public Hero() {
super(); super();
name = Messages.get(this, "name");
HP = HT = 20; HP = HT = 20;
STR = STARTING_STR; STR = STARTING_STR;
@ -288,8 +287,9 @@ public class Hero extends Char {
return subClass == null || subClass == HeroSubClass.NONE ? heroClass.title() : subClass.title(); return subClass == null || subClass == HeroSubClass.NONE ? heroClass.title() : subClass.title();
} }
public String givenName(){ @Override
return name.equals(Messages.get(this, "name")) ? className() : name; public String name(){
return className();
} }
public void live() { public void live() {

View File

@ -163,7 +163,7 @@ public class King extends Mob {
beacon.upgrade(); beacon.upgrade();
} }
yell( Messages.get(this, "defeated", Dungeon.hero.givenName()) ); yell( Messages.get(this, "defeated", Dungeon.hero.name()) );
} }
@Override @Override

View File

@ -71,7 +71,6 @@ import java.util.HashSet;
public abstract class Mob extends Char { public abstract class Mob extends Char {
{ {
name = Messages.get(this, "name");
actPriority = MOB_PRIO; actPriority = MOB_PRIO;
alignment = Alignment.ENEMY; alignment = Alignment.ENEMY;
@ -700,7 +699,7 @@ public abstract class Mob extends Char {
} }
public void yell( String str ) { public void yell( String str ) {
GLog.n( "%s: \"%s\" ", Messages.titleCase(name), str ); GLog.n( "%s: \"%s\" ", Messages.titleCase(name()), str );
} }
//returns true when a mob sees the hero, and is currently targeting them. //returns true when a mob sees the hero, and is currently targeting them.

View File

@ -290,7 +290,7 @@ public class NewTengu extends Mob {
BossHealthBar.assignBoss(this); BossHealthBar.assignBoss(this);
if (HP <= HT/2) BossHealthBar.bleed(true); if (HP <= HT/2) BossHealthBar.bleed(true);
if (HP == HT) { if (HP == HT) {
yell(Messages.get(this, "notice_gotcha", Dungeon.hero.givenName())); yell(Messages.get(this, "notice_gotcha", Dungeon.hero.name()));
for (Char ch : Actor.chars()){ for (Char ch : Actor.chars()){
if (ch instanceof DriedRose.GhostHero){ if (ch instanceof DriedRose.GhostHero){
GLog.n("\n"); GLog.n("\n");
@ -298,7 +298,7 @@ public class NewTengu extends Mob {
} }
} }
} else { } else {
yell(Messages.get(this, "notice_have", Dungeon.hero.givenName())); yell(Messages.get(this, "notice_have", Dungeon.hero.name()));
} }
} }
} }

View File

@ -248,7 +248,7 @@ public class OldTengu extends Mob {
BossHealthBar.assignBoss(this); BossHealthBar.assignBoss(this);
if (HP <= HT/2) BossHealthBar.bleed(true); if (HP <= HT/2) BossHealthBar.bleed(true);
if (HP == HT) { if (HP == HT) {
yell(Messages.get(this, "notice_mine", Dungeon.hero.givenName())); yell(Messages.get(this, "notice_mine", Dungeon.hero.name()));
for (Char ch : Actor.chars()){ for (Char ch : Actor.chars()){
if (ch instanceof DriedRose.GhostHero){ if (ch instanceof DriedRose.GhostHero){
GLog.n("\n"); GLog.n("\n");
@ -256,7 +256,7 @@ public class OldTengu extends Mob {
} }
} }
} else { } else {
yell(Messages.get(this, "notice_face", Dungeon.hero.givenName())); yell(Messages.get(this, "notice_face", Dungeon.hero.name()));
} }
} }
} }

View File

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

View File

@ -164,13 +164,13 @@ public class Ghost extends NPC {
switch (Quest.type){ switch (Quest.type){
case 1: default: case 1: default:
questBoss = new FetidRat(); questBoss = new FetidRat();
txt_quest = Messages.get(this, "rat_1", Dungeon.hero.givenName()); break; txt_quest = Messages.get(this, "rat_1", Dungeon.hero.name()); break;
case 2: case 2:
questBoss = new GnollTrickster(); questBoss = new GnollTrickster();
txt_quest = Messages.get(this, "gnoll_1", Dungeon.hero.givenName()); break; txt_quest = Messages.get(this, "gnoll_1", Dungeon.hero.name()); break;
case 3: case 3:
questBoss = new GreatCrab(); questBoss = new GreatCrab();
txt_quest = Messages.get(this, "crab_1", Dungeon.hero.givenName()); break; txt_quest = Messages.get(this, "crab_1", Dungeon.hero.name()); break;
} }
questBoss.pos = Dungeon.level.randomRespawnCell(); questBoss.pos = Dungeon.level.randomRespawnCell();

View File

@ -58,7 +58,7 @@ public class Imp extends NPC {
if (!Quest.given && Dungeon.level.heroFOV[pos]) { if (!Quest.given && Dungeon.level.heroFOV[pos]) {
if (!seenBefore) { if (!seenBefore) {
yell( Messages.get(this, "hey", Dungeon.hero.givenName() ) ); yell( Messages.get(this, "hey", Dungeon.hero.name() ) );
} }
seenBefore = true; seenBefore = true;
} else { } else {
@ -104,8 +104,8 @@ public class Imp extends NPC {
}); });
} else { } else {
tell( Quest.alternative ? tell( Quest.alternative ?
Messages.get(this, "monks_2", Dungeon.hero.givenName()) Messages.get(this, "monks_2", Dungeon.hero.name())
: Messages.get(this, "golems_2", Dungeon.hero.givenName()) ); : Messages.get(this, "golems_2", Dungeon.hero.name()) );
} }
} else { } else {
@ -130,7 +130,7 @@ public class Imp extends NPC {
public void flee() { public void flee() {
yell( Messages.get(this, "cya", Dungeon.hero.givenName()) ); yell( Messages.get(this, "cya", Dungeon.hero.name()) );
destroy(); destroy();
sprite.die(); sprite.die();

View File

@ -41,7 +41,7 @@ public class ImpShopkeeper extends Shopkeeper {
protected boolean act() { protected boolean act() {
if (!seenBefore && Dungeon.level.heroFOV[pos]) { if (!seenBefore && Dungeon.level.heroFOV[pos]) {
yell( Messages.get(this, "greetings", Dungeon.hero.givenName() ) ); yell( Messages.get(this, "greetings", Dungeon.hero.name() ) );
seenBefore = true; seenBefore = true;
} }

View File

@ -113,13 +113,13 @@ public class Wandmaker extends NPC {
String msg; String msg;
switch(Quest.type){ switch(Quest.type){
case 1: default: case 1: default:
msg = Messages.get(this, "reminder_dust", Dungeon.hero.givenName()); msg = Messages.get(this, "reminder_dust", Dungeon.hero.name());
break; break;
case 2: case 2:
msg = Messages.get(this, "reminder_ember", Dungeon.hero.givenName()); msg = Messages.get(this, "reminder_ember", Dungeon.hero.name());
break; break;
case 3: case 3:
msg = Messages.get(this, "reminder_berry", Dungeon.hero.givenName()); msg = Messages.get(this, "reminder_berry", Dungeon.hero.name());
break; break;
} }
Game.runOnRenderThread(new Callback() { Game.runOnRenderThread(new Callback() {
@ -142,7 +142,7 @@ public class Wandmaker extends NPC {
msg1 += Messages.get(this, "intro_rogue"); msg1 += Messages.get(this, "intro_rogue");
break; break;
case MAGE: case MAGE:
msg1 += Messages.get(this, "intro_mage", Dungeon.hero.givenName()); msg1 += Messages.get(this, "intro_mage", Dungeon.hero.name());
break; break;
case HUNTRESS: case HUNTRESS:
msg1 += Messages.get(this, "intro_huntress"); msg1 += Messages.get(this, "intro_huntress");

View File

@ -157,7 +157,7 @@ public class DriedRose extends Artifact {
hero.sprite.operate(hero.pos); hero.sprite.operate(hero.pos);
if (!firstSummon) { if (!firstSummon) {
ghost.yell( Messages.get(GhostHero.class, "hello", Dungeon.hero.givenName()) ); ghost.yell( Messages.get(GhostHero.class, "hello", Dungeon.hero.name()) );
Sample.INSTANCE.play( Assets.SND_GHOST ); Sample.INSTANCE.play( Assets.SND_GHOST );
firstSummon = true; firstSummon = true;

View File

@ -65,7 +65,7 @@ public class ScrollOfTerror extends Scroll {
GLog.i( Messages.get(this, "none") ); GLog.i( Messages.get(this, "none") );
break; break;
case 1: case 1:
GLog.i( Messages.get(this, "one", affected.name) ); GLog.i( Messages.get(this, "one", affected.name()) );
break; break;
default: default:
GLog.i( Messages.get(this, "many") ); GLog.i( Messages.get(this, "many") );

View File

@ -186,11 +186,14 @@ public class WandOfWarding extends Wand {
viewDistance = 3; viewDistance = 3;
state = WANDERING; state = WANDERING;
name = Messages.get(this, "name_" + tier );
} }
public void upgrade( int wandLevel ){ @Override
public String name() {
return Messages.get(this, "name_" + tier );
}
public void upgrade(int wandLevel ){
if (this.wandLevel < wandLevel){ if (this.wandLevel < wandLevel){
this.wandLevel = wandLevel; this.wandLevel = wandLevel;
} }
@ -216,7 +219,6 @@ public class WandOfWarding extends Wand {
if (tier < 6){ if (tier < 6){
tier++; tier++;
viewDistance++; viewDistance++;
name = Messages.get(this, "name_" + tier );
updateSpriteState(); updateSpriteState();
GameScene.updateFog(pos, viewDistance+1); GameScene.updateFog(pos, viewDistance+1);
} }
@ -414,7 +416,6 @@ public class WandOfWarding extends Wand {
super.restoreFromBundle(bundle); super.restoreFromBundle(bundle);
tier = bundle.getInt(TIER); tier = bundle.getInt(TIER);
viewDistance = 2 + tier; viewDistance = 2 + tier;
name = Messages.get(this, "name_" + tier );
wandLevel = bundle.getInt(WAND_LEVEL); wandLevel = bundle.getInt(WAND_LEVEL);
totalZaps = bundle.getInt(TOTAL_ZAPS); totalZaps = bundle.getInt(TOTAL_ZAPS);
} }

View File

@ -1027,7 +1027,7 @@ public class GameScene extends PixelScene {
Mob mob = (Mob) Actor.findChar(cell); Mob mob = (Mob) Actor.findChar(cell);
if (mob != null) { if (mob != null) {
objects.add(mob); objects.add(mob);
names.add(Messages.titleCase( mob.name )); names.add(Messages.titleCase( mob.name() ));
} }
} }
} }

View File

@ -56,7 +56,7 @@ public class WndBlacksmith extends Window {
IconTitle titlebar = new IconTitle(); IconTitle titlebar = new IconTitle();
titlebar.icon( troll.sprite() ); titlebar.icon( troll.sprite() );
titlebar.label( Messages.titleCase( troll.name ) ); titlebar.label( Messages.titleCase( troll.name() ) );
titlebar.setRect( 0, 0, WIDTH, 0 ); titlebar.setRect( 0, 0, WIDTH, 0 );
add( titlebar ); add( titlebar );

View File

@ -102,10 +102,10 @@ public class WndHero extends WndTabbed {
IconTitle title = new IconTitle(); IconTitle title = new IconTitle();
title.icon( HeroSprite.avatar(hero.heroClass, hero.tier()) ); title.icon( HeroSprite.avatar(hero.heroClass, hero.tier()) );
if (hero.givenName().equals(hero.className())) if (hero.name().equals(hero.className()))
title.label( Messages.get(this, "title", hero.lvl, hero.className() ).toUpperCase( Locale.ENGLISH ) ); title.label( Messages.get(this, "title", hero.lvl, hero.className() ).toUpperCase( Locale.ENGLISH ) );
else else
title.label((hero.givenName() + "\n" + Messages.get(this, "title", hero.lvl, hero.className())).toUpperCase(Locale.ENGLISH)); title.label((hero.name() + "\n" + Messages.get(this, "title", hero.lvl, hero.className())).toUpperCase(Locale.ENGLISH));
title.color(Window.SHPX_COLOR); title.color(Window.SHPX_COLOR);
title.setRect( 0, 0, WIDTH, 0 ); title.setRect( 0, 0, WIDTH, 0 );
add(title); add(title);

View File

@ -49,7 +49,7 @@ public class WndInfoMob extends WndTitledMessage {
public MobTitle( Mob mob ) { public MobTitle( Mob mob ) {
name = PixelScene.renderTextBlock( Messages.titleCase( mob.name ), 9 ); name = PixelScene.renderTextBlock( Messages.titleCase( mob.name() ), 9 );
name.hardlight( TITLE_COLOR ); name.hardlight( TITLE_COLOR );
add( name ); add( name );

View File

@ -27,6 +27,6 @@ import com.shatteredpixel.shatteredpixeldungeon.messages.Messages;
public class WndQuest extends WndTitledMessage { public class WndQuest extends WndTitledMessage {
public WndQuest( NPC questgiver, String text ) { public WndQuest( NPC questgiver, String text ) {
super( questgiver.sprite(), Messages.titleCase( questgiver.name ), text ); super( questgiver.sprite(), Messages.titleCase( questgiver.name() ), text );
} }
} }

View File

@ -100,7 +100,7 @@ public class WndWandmaker extends Window {
Dungeon.level.drop( reward, wandmaker.pos ).sprite.drop(); Dungeon.level.drop( reward, wandmaker.pos ).sprite.drop();
} }
wandmaker.yell( Messages.get(this, "farewell", Dungeon.hero.givenName()) ); wandmaker.yell( Messages.get(this, "farewell", Dungeon.hero.name()) );
wandmaker.destroy(); wandmaker.destroy();
wandmaker.sprite.die(); wandmaker.sprite.die();