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

@ -101,8 +101,6 @@ public abstract class Char extends Actor {
public CharSprite sprite;
public String name = "mob";
public int HT;
public int HP;
@ -137,6 +135,10 @@ public abstract class Char extends Actor {
return false;
}
public String name(){
return Messages.get(this, "name");
}
public boolean canInteract( Hero h ){
return Dungeon.level.adjacent( pos, h.pos );
}
@ -293,10 +295,10 @@ public abstract class Char extends Actor {
}
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) {
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();
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;

View File

@ -184,7 +184,6 @@ public class Hero extends Char {
public Hero() {
super();
name = Messages.get(this, "name");
HP = HT = 20;
STR = STARTING_STR;
@ -288,8 +287,9 @@ public class Hero extends Char {
return subClass == null || subClass == HeroSubClass.NONE ? heroClass.title() : subClass.title();
}
public String givenName(){
return name.equals(Messages.get(this, "name")) ? className() : name;
@Override
public String name(){
return className();
}
public void live() {

View File

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

View File

@ -71,7 +71,6 @@ import java.util.HashSet;
public abstract class Mob extends Char {
{
name = Messages.get(this, "name");
actPriority = MOB_PRIO;
alignment = Alignment.ENEMY;
@ -700,7 +699,7 @@ public abstract class Mob extends Char {
}
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.

View File

@ -290,7 +290,7 @@ public class NewTengu extends Mob {
BossHealthBar.assignBoss(this);
if (HP <= HT/2) BossHealthBar.bleed(true);
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()){
if (ch instanceof DriedRose.GhostHero){
GLog.n("\n");
@ -298,7 +298,7 @@ public class NewTengu extends Mob {
}
}
} 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);
if (HP <= HT/2) BossHealthBar.bleed(true);
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()){
if (ch instanceof DriedRose.GhostHero){
GLog.n("\n");
@ -256,7 +256,7 @@ public class OldTengu extends Mob {
}
}
} 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) {
Dungeon.fail( getClass() );
GLog.n( Messages.get(Char.class, "kill", name) );
GLog.n( Messages.get(Char.class, "kill", name()) );
}
return true;

View File

@ -164,13 +164,13 @@ public class Ghost extends NPC {
switch (Quest.type){
case 1: default:
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:
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:
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();

View File

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

View File

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

View File

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

View File

@ -157,7 +157,7 @@ public class DriedRose extends Artifact {
hero.sprite.operate(hero.pos);
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 );
firstSummon = true;

View File

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

View File

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

View File

@ -1027,7 +1027,7 @@ public class GameScene extends PixelScene {
Mob mob = (Mob) Actor.findChar(cell);
if (mob != null) {
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();
titlebar.icon( troll.sprite() );
titlebar.label( Messages.titleCase( troll.name ) );
titlebar.label( Messages.titleCase( troll.name() ) );
titlebar.setRect( 0, 0, WIDTH, 0 );
add( titlebar );

View File

@ -102,10 +102,10 @@ public class WndHero extends WndTabbed {
IconTitle title = new IconTitle();
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 ) );
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.setRect( 0, 0, WIDTH, 0 );
add(title);

View File

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

View File

@ -27,6 +27,6 @@ import com.shatteredpixel.shatteredpixeldungeon.messages.Messages;
public class WndQuest extends WndTitledMessage {
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();
}
wandmaker.yell( Messages.get(this, "farewell", Dungeon.hero.givenName()) );
wandmaker.yell( Messages.get(this, "farewell", Dungeon.hero.name()) );
wandmaker.destroy();
wandmaker.sprite.die();