Permalink
Browse files

Merge pull request #65 from egelmex/master

String externalising for Roles + some cleanups
  • Loading branch information...
2 parents 3beeeb6 + 2467745 commit 6a1e5e235320a9d8cc1665e5f77d95a899fdfe5c @tpcarlson tpcarlson committed Apr 13, 2012
@@ -1,11 +1,10 @@
package no.arcticdrakefox.wolfbot.management;
-import com.google.common.base.Joiner;
-import com.google.common.collect.Lists;
-
import no.arcticdrakefox.wolfbot.model.Role;
import no.arcticdrakefox.wolfbot.roles.SkipPlayer;
+import com.google.common.collect.Lists;
+
public class BotConstants {
public static final String NO_VOTES = "Noone ;_;";
public static final String SKIP_VOTE_NICKNAME = "Skipped!";
@@ -0,0 +1,38 @@
+package no.arcticdrakefox.wolfbot.management;
+
+import java.text.MessageFormat;
+import java.util.MissingResourceException;
+import java.util.Random;
+import java.util.ResourceBundle;
+
+public class Messages {
+ private static final String BUNDLE_NAME = "no.arcticdrakefox.wolfbot.roles.messages"; //$NON-NLS-1$
+
+ private static final Object[] empty = new Object[] {};
+
+ private static final ResourceBundle RESOURCE_BUNDLE = ResourceBundle
+ .getBundle(BUNDLE_NAME);
+
+ private static final Random rng = new Random();
+
+ private Messages() {
+ }
+
+ public static String getString(String key, Object[] args) {
+ try {
+ int count = Integer.parseInt(RESOURCE_BUNDLE.getString(key + ".count"));
+ int rnd = rng.nextInt(count);
+ return MessageFormat.format(RESOURCE_BUNDLE.getString(key+"."+rnd), args);
+ } catch (MissingResourceException e) {
+ try {
+ return MessageFormat.format(RESOURCE_BUNDLE.getString(key), args);
+ } catch (MissingResourceException ex) {
+ return "Missing String in properties file.";
+ }
+ }
+ }
+
+ public static String getString(String key) {
+ return getString(key, empty);
+ }
+}
@@ -1,5 +1,6 @@
package no.arcticdrakefox.wolfbot.management;
+@SuppressWarnings("serial")
public class WerewolfException extends Exception
{
String message;
@@ -1,5 +1,6 @@
package no.arcticdrakefox.wolfbot.roles;
+import no.arcticdrakefox.wolfbot.management.Messages;
import no.arcticdrakefox.wolfbot.management.PlayerList;
import no.arcticdrakefox.wolfbot.model.Role;
@@ -28,12 +29,12 @@ public Role getRole() {
@Override
public String roleInfo(PlayerList players) {
- return "You are the apprentice Scry. You will take over if your master dies.";
+ return Messages.getString("ApprenticeScry.intro"); //$NON-NLS-1$
}
@Override
public String nightStart() {
- if (active && !informed) return "Your master has been killed - you now have his powers." + super.nightStart();
+ if (active && !informed) return Messages.getString("ApprenticeScry.upgrade") + super.nightStart(); //$NON-NLS-1$
if (active) return super.nightStart();
return null;
}
@@ -51,6 +52,6 @@ public String nightEnd() {
}
@Override
public String helpText() {
- return "The apprentice scry has been learning from his master for years. If his master dies, he will gain his scrying power.";
+ return Messages.getString("ApprenticeScry.help"); //$NON-NLS-1$
}
}
@@ -1,5 +1,6 @@
package no.arcticdrakefox.wolfbot.roles;
+import no.arcticdrakefox.wolfbot.management.Messages;
import no.arcticdrakefox.wolfbot.management.Player;
import no.arcticdrakefox.wolfbot.management.PlayerList;
import no.arcticdrakefox.wolfbot.model.Role;
@@ -23,41 +24,40 @@ public Role getRole() {
@Override
public String roleInfo(PlayerList players) {
- return "You are the Aura Scry, each night you will be able to see whether " +
- "a player has a special ability.";
+ return Messages.getString("AuraScry.info"); //$NON-NLS-1$
}
@Override
public String nightStart() {
isReady = false;
- return "The stars smile on you tonight. You may !scry a person or just !rest";
+ return Messages.getString("AuraScry.nightInstructions"); //$NON-NLS-1$
}
@Override
public String nightAction(String message, PlayerList players) {
- String[] args = message.trim().split(" ", 2);
- if (args[0].equals("!scry")){
+ String[] args = message.trim().split(" ", 2); //$NON-NLS-1$
+ if (args[0].equals("!scry")){ //$NON-NLS-1$
if (args.length != 2)
- return "Correct usage: !scry <someone>";
+ return Messages.getString("AuraScry.correctUsage"); //$NON-NLS-1$
if (isReady)
- return "You may only scry one person each night.";
+ return Messages.getString("AuraScry.tooManyPeople"); //$NON-NLS-1$
Player target = players.getPlayer(args[1]);
if (target == null)
return targetNotFound(args[1]);
else {
if (target.equals(this)){
- return "You don't need your special powers to know that you are a scry.";
+ return Messages.getString("AuraScry.selfScry"); //$NON-NLS-1$
} else if (target.isAlive()){
isReady = true;
vote = target;
- return String.format("You set up your array of candles, orbs and artifacts, concentrating your efforts on %s", target);
+ return Messages.getString("AuraScry.Scried", new Object[] {target}); //$NON-NLS-1$
} else
- return String.format("%s is already dead.", target);
+ return Messages.getString("AuraScry.allreadyDead", new Object[] {target}); //$NON-NLS-1$
}
- } else if (args[0].equals("!rest")){
+ } else if (args[0].equals("!rest")){ //$NON-NLS-1$
isReady = true;
vote = null;
- return "You rest for tonight, confident that you already know all you need.";
+ return Messages.getString("AuraScry.rest"); //$NON-NLS-1$
} else
return null;
}
@@ -69,14 +69,14 @@ public String nightEnd() {
} else {
Role r = vote.getRole();
return (r != Role.villager) && (r!=Role.wolf) ?
- String.format("%s has an aura. They clearly have some power, though you know not what it may be.", vote)
- : String.format("%s does not appear to have any powers, whatever their crimes.", vote);
+ Messages.getString("AuraScry.hasAura", new Object[] {vote}) //$NON-NLS-1$
+ : Messages.getString("AuraScry.noAura", new Object[] {vote}); //$NON-NLS-1$
}
}
@Override
public String helpText() {
- return "The aura scry can look into the spirit world to sense the mental strength of others. He can focus on someone at night and will know if they have any special powers - but won't know what they are! ";
+ return Messages.getString("AuraScry.help"); //$NON-NLS-1$
}
}
@@ -1,12 +1,9 @@
package no.arcticdrakefox.wolfbot.roles;
+import no.arcticdrakefox.wolfbot.management.Messages;
import no.arcticdrakefox.wolfbot.management.Player;
import no.arcticdrakefox.wolfbot.management.PlayerList;
import no.arcticdrakefox.wolfbot.model.Role;
-import no.arcticdrakefox.wolfbot.model.WolfBotModel;
-import no.arcticdrakefox.wolfbot.predicates.TeamPredicate;
-
-import com.google.common.collect.Collections2;
public class Baner extends Player {
@@ -26,21 +23,21 @@ public Role getRole() {
@Override
public String roleInfo(PlayerList players) {
- return "You are the terror that flaps into the night! You are Wolfsbane! Baner of wolves! Each night you may choose one person to protect from wolf attacks.";
+ return Messages.getString("Baner.description"); //$NON-NLS-1$
}
@Override
public String nightStart() {
isReady = false;
- return "It's time. !bane the wolves from someone tonight or !rest";
+ return Messages.getString("Baner.nightInstructions"); //$NON-NLS-1$
}
@Override
public String nightAction(String message, PlayerList players) {
- String[] args = message.trim().split(" ", 2);
- if (args[0].equals("!bane")){
+ String[] args = message.trim().split(" ", 2); //$NON-NLS-1$
+ if (args[0].equals("!bane")){ //$NON-NLS-1$
if (args.length != 2)
- return "Correct usage: !bane <someone>";
+ return Messages.getString("Baner.correctUsage"); //$NON-NLS-1$
Player target = players.getPlayer(args[1]);
if (target == null)
return targetNotFound(args[1]);
@@ -49,16 +46,16 @@ public String nightAction(String message, PlayerList players) {
vote(target);
isReady = true;
if (target.equals(this))
- return "You fortify your defenses and set up traps. The wolves will never catch you!";
+ return Messages.getString("Baner.selfBane"); //$NON-NLS-1$
else
- return String.format("You don your purple cape and matching bell-shaped hat. %s will not die on your watch!", target);
+ return Messages.getString("Baner.bane", new Object[] {target}); //$NON-NLS-1$
} else
- return String.format("You are too late to save %s, they are dead already.", target);
+ return Messages.getString("Baner.tooLate", new Object[] {target}); //$NON-NLS-1$
}
- } else if (args[0].equals("!rest")){
+ } else if (args[0].equals("!rest")){ //$NON-NLS-1$
isReady = true;
vote = null;
- return "You give up. The village can die for all you care.";
+ return Messages.getString("Baner.rest"); //$NON-NLS-1$
} else
return null;
}
@@ -70,6 +67,6 @@ public String nightEnd() {
@Override
public String helpText() {
- return "The Baner can protect a member of the village each night, including themselves. If the wolves attack that person, they will be driven off and nobody will die.";
+ return Messages.getString("Baner.help"); //$NON-NLS-1$
}
}
@@ -1,5 +1,6 @@
package no.arcticdrakefox.wolfbot.roles;
+import no.arcticdrakefox.wolfbot.management.Messages;
import no.arcticdrakefox.wolfbot.management.Player;
import no.arcticdrakefox.wolfbot.management.PlayerList;
import no.arcticdrakefox.wolfbot.management.StringHandler;
@@ -24,49 +25,49 @@ public Role getRole() {
@Override
public String roleInfo(PlayerList players) {
- return String.format("You are a devil, an evil creature. You may check a person's role each night, or sacrifice someone. The wolves are %s, and you are on their side!",
- StringHandler.listToString(players.getWolves())
+ return Messages.getString("Devil.intro", //$NON-NLS-1$
+ new Object[] {StringHandler.listToString(players.getWolves())}
);
}
@Override
public String nightStart() {
isReady = false;
scryVote = null;
- return "The moon is in alignment. You may !scry a person, !kill them or just !rest";
+ return Messages.getString("Devil.nightInstructions"); //$NON-NLS-1$
}
@Override
public String nightAction(String message, PlayerList players) {
- String[] args = message.trim().split(" ", 2);
- if (args[0].matches("!scry|!kill")){
+ String[] args = message.trim().split(" ", 2); //$NON-NLS-1$
+ if (args[0].matches("!scry|!kill")){ //$NON-NLS-1$
if (args.length != 2)
- return "Correct usage: !scry <someone> or !kill <someone>";
+ return Messages.getString("Devil.nightHelp"); //$NON-NLS-1$
if (isReady)
- return "You may only scry one person each night.";
+ return Messages.getString("Devil.multipleScryError"); //$NON-NLS-1$
Player target = players.getPlayer(args[1]);
if (target == null)
return targetNotFound(args[1]);
else {
if (target.equals(this)){
- return "It makes no sense to target yourself.";
+ return Messages.getString("Devil.selfScry"); //$NON-NLS-1$
} else if (target.isAlive()){
isReady = true;
- if (args[0].equals("!scry")){
+ if (args[0].equals("!scry")){ //$NON-NLS-1$
scryVote = target;
- return String.format("You start a dark prayer to your evil gods, staring into the soul of %s", target);
+ return Messages.getString("Devil.successfulFeedback", new Object[]{target}); //$NON-NLS-1$
} else {
vote = target;
- return String.format("Though unbefitting of one of your stature, you abandon your artifacts and get out to hunt %s", target);
+ return Messages.getString("Devil.restFeedback", new Object[]{target}); //$NON-NLS-1$
}
} else
- return String.format("%s is already dead.", target);
+ return Messages.getString("Devil.targetDied", new Object[]{target}); //$NON-NLS-1$
}
- } else if (args[0].equals("!rest")){
+ } else if (args[0].equals("!rest")){ //$NON-NLS-1$
isReady = true;
vote = null;
scryVote = null;
- return "You rest for tonight, confident that you already know all you need.";
+ return Messages.getString("Devil.rested"); //$NON-NLS-1$
}
return null;
}
@@ -76,12 +77,12 @@ public String nightEnd() {
if (scryVote == null){
return null;
} else {
- return String.format("%s is a %s", vote, vote.getRole());
+ return Messages.getString("Devil.result", new Object[] {vote, vote.getRole()}); //$NON-NLS-1$
}
}
@Override
public String helpText() {
- return "The devil is an evil creature who can look deep into someone's soul and know what they are capable of. He can also sacrifice people at night, if he prefers.";
+ return Messages.getString("Devil.roleHelp"); //$NON-NLS-1$
}
}
@@ -2,6 +2,7 @@
import java.util.Collection;
+import no.arcticdrakefox.wolfbot.management.Messages;
import no.arcticdrakefox.wolfbot.management.Player;
import no.arcticdrakefox.wolfbot.management.PlayerList;
import no.arcticdrakefox.wolfbot.model.Role;
@@ -28,7 +29,7 @@ public Role getRole() {
@Override
public String roleInfo(PlayerList players) {
- return "You are diseased, your man-meat will poison any wolf that eats you.";
+ return Messages.getString("Diseased.intro"); //$NON-NLS-1$
}
@Override
@@ -67,7 +68,7 @@ public boolean apply(Player player) {
@Override
public String helpText() {
- return "I taste bad. Don't eat me!";
+ return Messages.getString("Diseased.helptext"); //$NON-NLS-1$
}
}
Oops, something went wrong.

0 comments on commit 6a1e5e2

Please sign in to comment.