Part of rapidly putting together a prototype is knowing that, at some point, I’ve got to go back and clean up the code. Make it work, first, then make it work right (and finally, make it work fast if you need to). Before I can go any further it’s a good idea to clean up the code and solidify one of the most fragile systems, which is the equipment/weapons/attack generation code.
Some of the issues I addressed:
- Too many classes. I overused subclassing for quick new behaviors–for example, special effects like poison arrows were a subclass of regular arrows. This is the road to ruin in object oriented programming, so a way better solution is to have an optional slot for special effects. I think I removed about ten classes this week.
- Arbitrary relationship between weapons and the attacks they generate. The way it was handled before, there was a Weapon class (subclass of Gear, subclass of Item–another thing I flattened into just the Item class), which had all the properties for attack creation. Stuff like damage, attack interval, range. The problem is that heroes have multiple equipment slots, and any of them can alter weapon properties: for example, a charm could add lifesteal to an attack, but reduce its attack power to compensate. Both a bow and arrow should be able to influence attack properties (though in general, the bow controls range and rate of fire, while the arrow controls damage and special effects).
- Complicated system for special effects related to equipped gear. There’s an easy hook for items to apply status effects to the heroes when they are spawned. Before, it was a mishmash of conditionals spread out over several classes.
The new systems are freshly finished, so only Shaedu’s attacks are operational now. But it’s going to be straightforward to port the other heroes over to the new system. Authoring items is going to be much easier moving forward, since they’re all unified into a single type with optional components. Any type of gear is capable of altering any attribute of the creature it’s equipped on.