Creating a subclass of class weapon for each weapon type is a very bad idea in my opinion. Sure it is easy to create 1 class at a time as you go along, but when your game is more complex it will be much more difficult to make additions & modify existing classes. If I were going to subclass weapons there would only be classes for different types of weapons (ex. ranged, thrown, one hand edged, one hand blunt...) My suggestion to eliminate subclassing of weapons would be to use weapon tables for creation. something similar to what follows (please forgive that this example isn't run ready & debugged, its just here so that you will be able to understand from reading what I mean.)
require 'lib/gameobject'
#weapon tables in a hash
#stats 0=attack 1=defense
weapons_stats = {
"dagger" => [5, 5],
"sword" => [10, 5]
"mace" => [15, 1],
"quarter staff" => [2, 18],
"blackjack" => [5, 3],
"quiot" => [7, 1],
"battle axe" => [20, 4]}
#weapon types
weapon_names = {
"dagger" => ['dagger', 'dirk', 'knife', 'butcher knife', 'stiletto'],
"sword" => ['sword', 'kris', 'wakizashi', 'gladius'],
"mace" => ['mace', 'pernat', 'massuelle'],
"quarter staff" => ['quarter staff', 'staff', 'bo stick'],
"blackjack" => ['blackjack', 'sap'],
"quoit" => ['quoit', 'chakram'],
"battle axe" => ['battle axe', 'executioner\'s axe', 'tabar', 'greataxe']}
class Weapon < GameObject
include Wearable
def initialize(type, *args)
super
info.position = :wield
info.weapon_type = type
info.attack = weapons_stats[type][0]
info.defense = weapons_stats[type][1]
info.layer = 0
@movable = true
@generic = "weapon"
end
end
Now that being said, I would go even further with this recommendation, I would say that weapons shouldn't have generic combat attributes attached to them. Just the "type" of weapon, and any bonuses specific to that individual weapon. Combat resolution is a much better place to determine what base stats apply to weapons & armor involved in that event of combat.
The reason for this recommendation is ease of future changes. Lets say for example that you start your game w/ all dirks having attack 5 and defense 5.. and then after a few months you rework how you want to do combat, and change dirks to attack .05 defesne .003 (yeah thats a big rework to how combat is done eh? But unbeknownst to the combat guru who is doing this rework some other admin renamed a 'dirk' to 'long-knife' and it didn't get caught in the script that the combat guru had to apply to all dirks (because they were already created.. ugh) and la-de-da you have a dirk "long-knife" in the game that is way overpowered. If the base weapon stats are all left in tables that are a part of combat calculation the need to modify all existing items when a change to the system is made is eliminated.. and there is no chance of items not working as 'intended'.
VR,
Joseph