PDA

View Full Version : D&D 3.x Class Java Class Writer



1pwny
2015-06-07, 07:32 PM
Hello everyone! So, I've participated in a few of the Homebrew class design competitions, and I got bored of making that table really quickly. You know, the one with the BAB and stuff/level? So, I wrote a java program to do it for me. Here's the code.

I know it looks ugly, but I had to use the noparse tag. Sorry!


import java.util.Scanner;

public class ClassWriter {
private static Scanner s = new Scanner(System.in);

private static String extraTitle="",extra="";

private static int l=1;
private static int[] stats = new int[4]; //BAB, fort, ref, will tracker
private static int[] improve = new int[4]; //rate at which the saves improve
private static int[] lt = {0,0,0,0}; //level tracker, DON'T CHANGE!

public static void main(String[] args) {
//extraTitle = "\n
{extra column's header} ";


String temp;
boolean isMed = false;

int maxlevel;
System.out.print("Welcome to somebody27else's class writer!"
+ "\nMake sure to type carefully, and good luck!"
+ "\n========================================"
+ "\nHow many levels does your class have? ");
maxlevel = s.nextInt();

System.out.print("Slow, medium, or fast BAB progression? ");
temp = s.next();
s.nextLine();
if(temp.equalsIgnoreCase("slow") || temp.equalsIgnoreCase("s")) {
stats[0] = 0;
improve[0] = 2;
} else if(temp.equalsIgnoreCase("medium") || temp.equalsIgnoreCase("m")) {
stats[0] = 0;
improve[0] = 1;
isMed = true;
} else if(temp.equalsIgnoreCase("fast") || temp.equalsIgnoreCase("f")) {
stats[0] = 0;
improve[0] = 1;
}

setSave(1,"Fort");
setSave(2,"Ref");
setSave(3,"Will");

char q = 0x22;

System.out.println("\n\n"
+ "\n"
+ "\n"
+ "\n"
+ "\n
Level"
+ "\n
BAB"
+ "\n
Fort"
+ "\n
Ref"
+ "\n
Will"
+ "\n
Special"
+ extraTitle
+ "\n\n");

String babstr;
for(l=1; l <= maxlevel; l++) {
for(int n=0; n<4; n++) {
lt[n]++;
if(lt[n]==improve[n]) {
lt[n] = 0;
stats[n]++;
}
}

if(((l-1)%4==0) && isMed) {
stats[0]--;
}

babstr="+"+stats[0];

if(stats[0]>5)
babstr += "/+"+(stats[0]-5);
if(stats[0]>10)
babstr += "/+"+(stats[0]-10);
if(stats[0]>15)
babstr += "/+"+(stats[0]-15);

setExtra();

System.out.println(""
+ "\n
"+l+" "
+ "\n
"+babstr+" "
+ "\n
+"+stats[1]+" "
+ "\n
+"+stats[2]+" "
+ "\n
+"+stats[3]+" "
+ "\n
"
+ extra
+ "\n\n");
}

System.out.println("");
}

public static void setSave(int stat,String sName) {
String temp;
System.out.print("Slow or fast " + sName + " save progression? ");
temp = s.nextLine();
if(temp.equalsIgnoreCase("slow") || temp.equalsIgnoreCase("s")) {
stats[stat] = 0;
improve[stat] = 3;
} else if(temp.equalsIgnoreCase("fast") || temp.equalsIgnoreCase("f")) {
stats[stat] = 2;
improve[stat] = 2;
}
}

public static void setExtra() {
/** place to write extra conditions/columns **/

//extra = "\n
"+ {insert whatever you want here} +"";
}
}

Most of this is self-explanatory. You can copy the code into an online compiler, or whatever java compiler you have on your computer. It runs from the terminal.
This will create the basic table with class level, BAB, fort, ref, and will. Yes, the program will ask you for those.

If you want to add extra columns, like for spells known or maneuvers or such, it gets a little more complicated. Either follow these instruction if you know some java, or just ask me if you don't.

Go to the first line in the main. The extraTitle line should be commented out. De-comment it.
You should get an error because, in fact, {extra column's header} is not valid java code. Replace that with what you want your new column to be named.
OPTIONAL: To add more columns, copy everything inside the quotes and paste it into the end of the quotes. Each paste will add a new line you can change the title of.
Go to the setExtra() method. The line which gives extra a value should be commented. De-comment it.
Do whatever shenanigans you want to put in the by-level extra data. Ex: If I want to give my class 1 maneuver every 4 levels, I could write this: extra = "\n
"+ (l/4 + 1) +"
";



This is the basic guide. Any questions on usage, problems, feedback, or anything in general, please reply!

Amechra
2015-06-07, 09:28 PM
Why are you storing the save progressions and BAB as Integers? Switch statements and for-loops are your friends.

I remember next to nothing of Java at the moment, but you can just take the input and use a Switch statement to pick the right formula for both BAB and your Saves. I know that would be easier in both C++ and Javascript, but again, I no remember Java good.

EDIT: Also, for future reference, you can hit the blue button on the upper-left corner to switch to WYSIWYG mode; it really speeds up tables, but you should switch back if you need to do any other formatting.

EDIT TO THE EDIT: Also for future reference, <CODE></CODE> tags should conserve indenting (replace the <> with [], as normal).

Jormengand
2015-06-08, 04:01 PM
Or, of course, you could use PifRO (http://pifro.com/dnd/NEW/) (Set it to PIFBB, not GITP).

1pwny
2015-06-08, 04:15 PM
Why are you storing the save progressions and BAB as Integers? Switch statements and for-loops are your friends.

I remember next to nothing of Java at the moment, but you can just take the input and use a Switch statement to pick the right formula for both BAB and your Saves. I know that would be easier in both C++ and Javascript, but again, I no remember Java good.

Well, maybe. But that's not really how I structured the program. I don't know, it just seems easier to edit and understand for the general populace as it is right now. But this is my first time getting feedback on it, so :smallyuk:


]EDIT: Also, for future reference, you can hit the blue button on the upper-left corner to switch to WYSIWYG mode; it really speeds up tables, but you should switch back if you need to do any other formatting.

If only I knew what WYSIWYG was.


EDIT TO THE EDIT: Also for future reference, <CODE></CODE> tags should conserve indenting (replace the <> with [], as normal).

Thanks for the advice


Or, of course, you could use PifRO (http://pifro.com/dnd/NEW/) (Set it to PIFBB, not GITP).

...I totally knew about that. Welp, now we have 2 options.

Jormengand
2015-06-08, 06:27 PM
If only I knew what WYSIWYG was.

What you see is what you get. Try it.