Wednesday, October 1, 2008

Java: CharSi Update #9

It turns out an array of arrays was the best way to contain all of the information needed for the Runeword Wizard. This allowed me to use For and While loops for any comparison purposes as I had an array for all of the selected options and then compared each slot to its corresponding slots in the array of arrays. Somewhat of a brute force method but I'm satisfied with the results.

To start off I needed to create the main variable of this program, the array of Strings that would hold all of my selection choices.

String[] selectionArray = {"", "", "1", "0", "2", "1", "0", "1", "1", "1", "1", "1", "1", "1", "1", "1", "1", "1", "1", "1", "1", "1", "1", "1", "1", "1", "1", "1", "1", "1", "1", "1", "1", "1", "1", "1", "1", "1", "1", "1", "0", "0", "0", "0", "0", "0", "0", "0", "0", "0", "0", "0", "0", "0", "0", "0", "0", "0"};

There are 58 slots to this array, one for each rune, base item and search modifier. A value of "1" equals true while a "0" equals false. All runes are initially selected while the base items are not. As components are selected their corresponding Listeners will alter the necessary value in this array. Along with the selectionArray, a separate array was created for each possible runeword, of which there are eighty-three. To that end there were quite a few arrays that looked similiar to this:

String[] heartOfTheOak = {"heartoftheoak.txt", "Heart of the Oak", "1", "0", "4", "0", "0", "0", "0", "0", "0", "0", "0", "0", "0", "0", "1", "0", "0", "0", "0", "0", "0", "0", "1", "0", "0", "1", "0", "0", "0", "0", "1", "0", "0", "0", "0", "0", "0", "0", "0", "0", "0", "0", "0", "0", "0", "0", "0", "1", "0", "0", "0", "0", "0", "0", "0", "1"};

After creation each array is then added to a slot in main runeword array to create the needed array of arrays. This becomes key when doing the actual comparison between what is needed and the runewords available. The workhorse of this program is a method named CompareRunewordCriteria(). This method is called when the Display Jbutton is pressed. To start it sets a boolean variable to false, assuming the runeword won't fit the criteria given. Then it compares the base items needed with those selected, if there is a match then the variable is set to true, if there isn't a match then we move on to the next runeword. Then runes available are compared to those needed, as well as if the runeword has the right number of slots, contains an aura and all the other selection criteria are compared. If after all that the boolean variable is set to true, then the runeword name is added to the DefaultListModel so that it is displayed as an option in the JList component.

That was the hard part. After that it was simply hooking up the JList component Listener to display the right text file when an option in the JList is selected. The code for displaying the text was borrowed from the AMAS Rune panel, as was the text files containing the runeword information.


After everything was in place I did run some comparisons between my program and the online runeword calculator to ensure my results were accurate. A few changes had to be made, I apparently didn't consider all weapon types when melee weapons are concerned. Also Mauls were removed as a selection since those are incoporated into the Hammer option and Daggers were put in place instead. When originally thinking about daggers I assumed one socket was all they could have, which turned out to be incorrect. But a few quick variable name changes and daggers are now an available option.

This Runeword Wizard now replaces the runeword list from the AMAS program as this one is much more robust. I can search on specific runes and it provides a much larger pool of available base items beyond the four originally available (shield, helm, armor, weapon). Gradually I'll be phasing AMAS out of use, but I don't see doing so for quite a while as I want to finish the character simulator portion of CharSi before adding any other reference tools to the program.

No comments: