= Converted formatting for the core rpg

This commit is contained in:
Matthew Cech
2019-06-19 21:58:26 -07:00
parent feca9e542a
commit 5e531a19b7
16 changed files with 85 additions and 85 deletions
+1 -1
View File
@@ -39,7 +39,7 @@ public class CommandRPG extends Command
String result = null; String result = null;
synchronized(framework) synchronized(framework)
{ {
result = framework.Run(user.uniqueID, input.args.trim()); result = framework.run(user.uniqueID, input.args.trim());
} }
if(result == null) if(result == null)
+2 -2
View File
@@ -7,7 +7,7 @@ import core.rpg.RPGState;
public class RPGCommandBattleFight extends RPGCommand public class RPGCommandBattleFight extends RPGCommand
{ {
@Override @Override
public String OnRun(RPGState state, RPGInput input) public String onRun(RPGState state, RPGInput input)
{ {
if(state.battleContext == null) if(state.battleContext == null)
return "```There's nothing to fight!```"; return "```There's nothing to fight!```";
@@ -19,7 +19,7 @@ public class RPGCommandBattleFight extends RPGCommand
reward = "+150xp"; reward = "+150xp";
state.battleContext = null; state.battleContext = null;
state.player.ApplyEXP(150); state.player.applyEXP(150);
if(out != null && reward != null) if(out != null && reward != null)
{ {
+3 -3
View File
@@ -7,15 +7,15 @@ import core.rpg.RPGState;
public class RPGCommandBattleRun extends RPGCommand public class RPGCommandBattleRun extends RPGCommand
{ {
@Override @Override
public String OnRun(RPGState state, RPGInput input) public String onRun(RPGState state, RPGInput input)
{ {
if(state.battleContext == null) if(state.battleContext == null)
return "```There's nothing to run from!```"; return "```There's nothing to run from!```";
long lostGold = (long)(state.player.GetGold() * .1); long lostGold = (long)(state.player.getGold() * .1);
String out = null; String out = null;
state.player.SpendGold(lostGold); state.player.spendGold(lostGold);
state.battleContext = null; state.battleContext = null;
out = "You duck behind a tree and manage to escape from encounter just barely!"; out = "You duck behind a tree and manage to escape from encounter just barely!";
+7 -7
View File
@@ -28,7 +28,7 @@ public class RPGCommandExplore extends RPGCommand
} }
@Override @Override
public String OnRun(RPGState state, RPGInput input) public String onRun(RPGState state, RPGInput input)
{ {
Chance chance = new Chance(100); Chance chance = new Chance(100);
@@ -50,7 +50,7 @@ public class RPGCommandExplore extends RPGCommand
out = "As you take a stroll, you spy a small shiny glint from a bush and decide to investigate! Looks like it's your lucky day!"; out = "As you take a stroll, you spy a small shiny glint from a bush and decide to investigate! Looks like it's your lucky day!";
reward = "+" + gp + "gp"; reward = "+" + gp + "gp";
state.player.GiveGold(gp); state.player.giveGold(gp);
} }
else if(chance.Next(20)) else if(chance.Next(20))
{ {
@@ -59,8 +59,8 @@ public class RPGCommandExplore extends RPGCommand
out = "You head out on a lovely stroll down a familiar path - the sun is out and the birds are chirping! Nothing much comes of it, but you feel refreshed."; out = "You head out on a lovely stroll down a familiar path - the sun is out and the birds are chirping! Nothing much comes of it, but you feel refreshed.";
reward = "+" + xp + "xp, +" + healing + "hp"; reward = "+" + xp + "xp, +" + healing + "hp";
state.player.ApplyHealing(healing); state.player.applyHealing(healing);
state.player.ApplyEXP(xp); state.player.applyEXP(xp);
} }
else if(chance.Next(20)) else if(chance.Next(20))
{ {
@@ -69,8 +69,8 @@ public class RPGCommandExplore extends RPGCommand
out = "Today's the day you head out on a new path. You find a lot of little nicknacks and trinkets on the trail, but leave them be. The trail gets really steep, the rocks jagged, but you keep going. Eventually, you make it out to the other side into a small but pleasant town, and collapse on a bench to catch your breath."; out = "Today's the day you head out on a new path. You find a lot of little nicknacks and trinkets on the trail, but leave them be. The trail gets really steep, the rocks jagged, but you keep going. Eventually, you make it out to the other side into a small but pleasant town, and collapse on a bench to catch your breath.";
reward = "+" + xp + "xp, -" + damage + "hp"; reward = "+" + xp + "xp, -" + damage + "hp";
state.player.ApplyEXP(xp); state.player.applyEXP(xp);
state.player.ApplyDamage(damage); state.player.applyDamage(damage);
} }
else else
{ {
@@ -78,7 +78,7 @@ public class RPGCommandExplore extends RPGCommand
out = "You step outside but it starts to rain. You decide not to do much today, and hang about the inn and the tavern."; out = "You step outside but it starts to rain. You decide not to do much today, and hang about the inn and the tavern.";
reward = "+" + hp + "hp"; reward = "+" + hp + "hp";
state.player.ApplyHealing(hp); state.player.applyHealing(hp);
} }
if(out != null && reward != null) if(out != null && reward != null)
+11 -11
View File
@@ -10,7 +10,7 @@ public class RPGCommandInfo extends RPGCommand
{ {
@Override @Override
public String OnRun(RPGState state, RPGInput input) public String onRun(RPGState state, RPGInput input)
{ {
String out = null; String out = null;
switch(input.value.trim().toLowerCase()) switch(input.value.trim().toLowerCase())
@@ -27,7 +27,7 @@ public class RPGCommandInfo extends RPGCommand
case "hand": case "hand":
case "att": case "att":
case "attack": case "attack":
out = WeaponStats(state.player.GetWeapon()); out = WeaponStats(state.player.getWeapon());
break; break;
case "armour": case "armour":
@@ -44,7 +44,7 @@ public class RPGCommandInfo extends RPGCommand
case "dress": case "dress":
case "wear": case "wear":
case "outfit": case "outfit":
out = ArmorStats(state.player.GetArmor()); out = ArmorStats(state.player.getArmor());
break; break;
} }
@@ -60,14 +60,14 @@ public class RPGCommandInfo extends RPGCommand
return null; return null;
String out = ""; String out = "";
out += "[" + weapon.GetName() + "]"; out += "[" + weapon.getName() + "]";
out += "\n"; out += "\n";
out += " att: " + weapon.GetAttack(); out += " att: " + weapon.getAttack();
out += "\n"; out += "\n";
out += "value: " + weapon.GetValue() + "gp"; out += "value: " + weapon.getValue() + "gp";
out += "\n"; out += "\n";
out += "\n"; out += "\n";
out += weapon.GetDescription(); out += weapon.getDescription();
return out; return out;
} }
@@ -78,14 +78,14 @@ public class RPGCommandInfo extends RPGCommand
return null; return null;
String out = ""; String out = "";
out += "[" + armor.GetName() + "]"; out += "[" + armor.getName() + "]";
out += "\n"; out += "\n";
out += " def: " + armor.GetDefense(); out += " def: " + armor.getDefense();
out += "\n"; out += "\n";
out += "value: " + armor.GetValue() + "gp"; out += "value: " + armor.getValue() + "gp";
out += "\n"; out += "\n";
out += "\n"; out += "\n";
out += armor.GetDescription(); out += armor.getDescription();
return out; return out;
} }
+13 -13
View File
@@ -11,18 +11,18 @@ import core.rpg.RPGWeapon;
public class RPGCommandStats extends RPGCommand public class RPGCommandStats extends RPGCommand
{ {
@Override @Override
public String OnRun(RPGState state, RPGInput input) public String onRun(RPGState state, RPGInput input)
{ {
RPGPlayer player = state.player; RPGPlayer player = state.player;
long exp = player.GetEXP(); long exp = player.getEXP();
long level = RPGExpTable.LevelFromEXP(player.GetEXP()); long level = RPGExpTable.levelFromEXP(player.getEXP());
long ceil = RPGExpTable.EXPCeil(level); long ceil = RPGExpTable.expCeil(level);
String indent = ""; String indent = "";
String linebreak = "\n"; String linebreak = "\n";
String out = ""; String out = "";
out += indent + "[" + player.GetName() + ", lv. " + level + "]"; out += indent + "[" + player.getName() + ", lv. " + level + "]";
out += indent + linebreak; out += indent + linebreak;
out += indent + "_______________"; out += indent + "_______________";
out += indent + linebreak; out += indent + linebreak;
@@ -31,26 +31,26 @@ public class RPGCommandStats extends RPGCommand
out += indent + " (until next: " + (ceil - exp) + ")"; out += indent + " (until next: " + (ceil - exp) + ")";
out += indent + linebreak; out += indent + linebreak;
out += indent + " Gold: " + player.GetGold(); out += indent + " Gold: " + player.getGold();
out += indent + linebreak; out += indent + linebreak;
out += indent + "Health: " + player.GetHealthCurrent() + "/" + player.GetHealthMax(); out += indent + "Health: " + player.getHealthCurrent() + "/" + player.getHealthMax();
out += indent + linebreak; out += indent + linebreak;
RPGWeapon weapon = player.GetWeapon(); RPGWeapon weapon = player.getWeapon();
out += indent + "_____"; out += indent + "_____";
out += indent + linebreak; out += indent + linebreak;
out += indent + "Weapon: " + weapon.GetName(); out += indent + "Weapon: " + weapon.getName();
out += indent + linebreak; out += indent + linebreak;
out += indent + " att: " + weapon.GetAttack(); out += indent + " att: " + weapon.getAttack();
out += indent + linebreak; out += indent + linebreak;
RPGArmor armor = player.GetArmor(); RPGArmor armor = player.getArmor();
out += indent + "_____"; out += indent + "_____";
out += indent + linebreak; out += indent + linebreak;
out += indent + "Armor: " + armor.GetName(); out += indent + "Armor: " + armor.getName();
out += indent + linebreak; out += indent + linebreak;
out += indent + " def: " + armor.GetDefense() ; out += indent + " def: " + armor.getDefense() ;
out += indent + linebreak; out += indent + linebreak;
out += indent + linebreak; out += indent + linebreak;
+1 -1
View File
@@ -10,5 +10,5 @@ public class RPGArmor extends RPGItem
defense = 1; defense = 1;
} }
public long GetDefense() { return defense; } public long getDefense() { return defense; }
} }
+1 -1
View File
@@ -5,5 +5,5 @@ public abstract class RPGCommand
public RPGCommand() { } public RPGCommand() { }
// OVERRIDE ME // OVERRIDE ME
public abstract String OnRun(RPGState state, RPGInput input); public abstract String onRun(RPGState state, RPGInput input);
} }
+3 -3
View File
@@ -2,7 +2,7 @@ package core.rpg;
public final class RPGExpTable public final class RPGExpTable
{ {
public static long EXPFloor(long level) public static long expFloor(long level)
{ {
if(level > Levels.length - 1) if(level > Levels.length - 1)
level = Levels.length - 1; level = Levels.length - 1;
@@ -13,7 +13,7 @@ public final class RPGExpTable
return Levels[(int) level]; return Levels[(int) level];
} }
public static long EXPCeil(long level) public static long expCeil(long level)
{ {
if(level > Levels.length - 1) if(level > Levels.length - 1)
level = Levels.length - 1; level = Levels.length - 1;
@@ -23,7 +23,7 @@ public final class RPGExpTable
return Levels[(int) (level + 1)]; return Levels[(int) (level + 1)];
} }
public static long LevelFromEXP(long exp) public static long levelFromEXP(long exp)
{ {
if(exp < 0) if(exp < 0)
exp = 0; exp = 0;
+15 -15
View File
@@ -22,24 +22,24 @@ public class RPGFramework
this.gameStates = new HashMap<String, RPGState>(); this.gameStates = new HashMap<String, RPGState>();
this.gameCommands = new HashMap<String, RPGCommand>(); this.gameCommands = new HashMap<String, RPGCommand>();
RegisterCommand("stats", new RPGCommandStats()); registerCommand("stats", new RPGCommandStats());
RegisterCommand("about", new RPGCommandInfo()); registerCommand("about", new RPGCommandInfo());
RegisterCommand("info", new RPGCommandInfo()); registerCommand("info", new RPGCommandInfo());
RegisterCommand("explore", new RPGCommandExplore()); registerCommand("explore", new RPGCommandExplore());
RegisterCommand("run", new RPGCommandBattleRun()); registerCommand("run", new RPGCommandBattleRun());
RegisterCommand("fight", new RPGCommandBattleFight()); registerCommand("fight", new RPGCommandBattleFight());
} }
// Primary external // Primary external
public String Run(String userID, String inputRaw) public String run(String userID, String inputRaw)
{ {
RPGState state = LookupState(userID); RPGState state = lookupState(userID);
RPGInput input = new RPGInput(inputRaw); RPGInput input = new RPGInput(inputRaw);
return ExecuteCommand(input.key, state, input); return executeCommand(input.key, state, input);
} }
// Get state for executing a command // Get state for executing a command
public RPGState LookupState(String userID) public RPGState lookupState(String userID)
{ {
RPGState state; RPGState state;
synchronized(gameStates) synchronized(gameStates)
@@ -58,23 +58,23 @@ public class RPGFramework
} }
// Registers a command // Registers a command
private void RegisterCommand(String commandName, RPGCommand command) private void registerCommand(String commandName, RPGCommand command)
{ {
commandName = commandName.toLowerCase(); commandName = commandName.toLowerCase();
if(gameCommands.put(commandName, command) != null) if(gameCommands.put(commandName, command) != null)
RPGLog.Log("Managed to register the same RPG command twice! Not ideal!"); RPGLog.log("Managed to register the same RPG command twice! Not ideal!");
RPGLog.Log("Registered " + commandName); RPGLog.log("Registered " + commandName);
} }
private String ExecuteCommand(String name, RPGState state, RPGInput input) private String executeCommand(String name, RPGState state, RPGInput input)
{ {
synchronized(gameCommands) synchronized(gameCommands)
{ {
RPGCommand command = gameCommands.get(name.toLowerCase()); RPGCommand command = gameCommands.get(name.toLowerCase());
if(command != null && state != null) if(command != null && state != null)
return command.OnRun(state, input); return command.onRun(state, input);
} }
return null; return null;
+3 -3
View File
@@ -19,7 +19,7 @@ public abstract class RPGItem
this.value = value; this.value = value;
} }
public String GetName() { return name; } public String getName() { return name; }
public String GetDescription() { return description; } public String getDescription() { return description; }
public long GetValue() { return value; } public long getValue() { return value; }
} }
+1 -1
View File
@@ -5,7 +5,7 @@ import utils.LogFilter;
public class RPGLog public class RPGLog
{ {
public static void Log(String toWrite) public static void log(String toWrite)
{ {
GlobalLog.Log(LogFilter.Command, "[RPG] " + toWrite); GlobalLog.Log(LogFilter.Command, "[RPG] " + toWrite);
} }
+8 -8
View File
@@ -10,29 +10,29 @@ public class RPGMain
public static void RPGmain(String[] args) public static void RPGmain(String[] args)
{ {
Init(); init();
while(Run()) { }; while(run()) { };
Shutdown(); shutdown();
} }
// Initializes stuff (small factory, ish) // Initializes stuff (small factory, ish)
private static void Init() private static void init()
{ {
framework = new RPGFramework(); framework = new RPGFramework();
scanner = new Scanner(System.in); scanner = new Scanner(System.in);
} }
// Main loop // Main loop
private static boolean Run() private static boolean run()
{ {
// move outside // move outside
String out = framework.Run("Test", scanner.nextLine()); String out = framework.run("Test", scanner.nextLine());
RPGLog.Log(out); RPGLog.log(out);
return true; return true;
} }
// Cleanup // Cleanup
private static void Shutdown() private static void shutdown()
{ {
scanner.close(); scanner.close();
} }
+9 -9
View File
@@ -22,17 +22,17 @@ public class RPGPlayer extends RPGUnit
} }
// Getters // Getters
public long GetEXP() { return exp; } public long getEXP() { return exp; }
public long GetGold() { return gold; } public long getGold() { return gold; }
public String GetName() { return name; } public String getName() { return name; }
public RPGArmor GetArmor() { return armor; }; public RPGArmor getArmor() { return armor; };
public RPGWeapon GetWeapon() { return weapon; }; public RPGWeapon getWeapon() { return weapon; };
// Setters // Setters
public void SetName(String name) { this.name = name; } public void setName(String name) { this.name = name; }
// Interactions // Interactions
public void ApplyEXP(int expToGive) public void applyEXP(int expToGive)
{ {
if(expToGive < 0) if(expToGive < 0)
expToGive = 0; expToGive = 0;
@@ -40,7 +40,7 @@ public class RPGPlayer extends RPGUnit
exp += expToGive; exp += expToGive;
} }
public void GiveGold(long amount) public void giveGold(long amount)
{ {
if(amount < 0) if(amount < 0)
amount = 0; amount = 0;
@@ -48,7 +48,7 @@ public class RPGPlayer extends RPGUnit
gold += amount; gold += amount;
} }
public void SpendGold(long amount) public void spendGold(long amount)
{ {
if(amount < 0) if(amount < 0)
amount = 0; amount = 0;
+5 -5
View File
@@ -5,13 +5,13 @@ public abstract class RPGUnit
protected int healthMax; protected int healthMax;
protected int healthCurrent; protected int healthCurrent;
public int GetHealthMax() { return healthMax; } public int getHealthMax() { return healthMax; }
public int GetHealthCurrent() { return healthCurrent; } public int getHealthCurrent() { return healthCurrent; }
public boolean IsAlive() { return healthCurrent > 0; } public boolean isAlive() { return healthCurrent > 0; }
// Generic implementation. Consider implementing armor in // Generic implementation. Consider implementing armor in
// derived classes, for example. // derived classes, for example.
public void ApplyDamage(int value) public void applyDamage(int value)
{ {
if(value < 0) if(value < 0)
value = 0; value = 0;
@@ -21,7 +21,7 @@ public abstract class RPGUnit
// Generic implementation. Consider applying boosts in // Generic implementation. Consider applying boosts in
// derived classes, for example. // derived classes, for example.
public void ApplyHealing(int value) public void applyHealing(int value)
{ {
if(value < 0) if(value < 0)
value = 0; value = 0;
+2 -2
View File
@@ -12,6 +12,6 @@ public class RPGWeapon extends RPGItem
accuracy = 0.8; accuracy = 0.8;
} }
public long GetAttack() { return attack; } public long getAttack() { return attack; }
public double GetAccuracy() { return accuracy; } public double getAccuracy() { return accuracy; }
} }