Tuesday, December 9, 2008

Java: CharSi Update #12

Before I could get the Equip and Remove JButtons working in the Armor panel I had to first correct some oversights and problems in the Stats class. Specifically not all of the mods were being summed correctly, or at all, so a few methods needed to be generated. I made a different method for each array or subset of variables so that each could be called separately. Currently I don't have a need to call them separately, but one could arise in the future so I'm planning ahead. Along with this a super method was needed that would call all of the summing methods at once, SetAll.

Now that the Stats panel was all set it was time to finish the Equip JButton listener. First a check is done to ensure that there isn't already a piece of Armor equipped on the virtual character. This is done with an array stored in the Equipment class, and therefore available to all classes that govern the tabbedpanes. After that check is complete, and passes, then the stats from the selected item are stored using the massive If-Else statement created earlier. Once completed the SetAll method is called to save this information into the Stat class variables and the Armor slot is considered "filled".

StoreItemStats();
Equipment.equipListModel.addElement(itemName);
Stats.SetAll();
Equipment.equipYes[1] = 1; //1 = filled, 0 = empty

This places the item name as an element in the equipped JList component. I decided that any elements in this list, while clickable, won't display the items properties in the JTextArea. That would have required saving the data into a text file to be displayed on command, and at this point that isn't a critical element for the application to function.

Now that an item can be equipped, it needs to be removed as well. Doing so needed another method, ZeroStatArrays, that would empty the contents of all the stat arrays before calling the SetAll method to sum the stats from all equipment pieces. Along with this the element in question would need to be removed from the equipped JList. However, before this could be done a check needs to be made to ensure that the user is in the correct JPanel for the equipment being removed. I decided that needed to be a requirement to remove the item piece.

Now that those pieces were in place, I had to run through the entire list of available armor pieces and both equip and remove each one. This was a check to ensure that the right values are being stored by the StoreItemStats method. As it turned out there were several bugs in that part of the code. A few times the wrong slot of the array was updated, while others there was a conflict between mods I didn't know existed, such as between "to mana" and "Damage taken goes to mana". Both contain the phrase "to mana" and therefore the method was attempting to apply both statements to the value given.

As a last piece I removed the Perfect and Reroll components. These were now redundant as the user is choosing the desired values whenever the item is equipped. The next step will be to transfer this code to the Belt class file and then test all those items to ensure the StoreItemStats code is still valid. I'm sure there are some mods not handled by the armor files that may still have small difficulties. Each piece of defensive equipment will be handled in turn until they are all completed.

No comments: