Hello good people,
I'm currently making a simple turn based RPG game.
I have a player class, and this player can hold a weapon.
What I want to be able to do, is for the player to equip a wide variety of weapons that can do slightly different things.
People who play the incredibly popular MMORPG game World Of Warcraft, or similar games will be quite familiar with this.
So for example, we can have basic weapons, like a sword that does say 5 damage. But then we can have another one with special effects that can do things like alter stats to the character, eg +5 to strength. Or a weapon that has a %chance to attack twice or blast fire damage or something.
The way I have implemented a weapon class so far is kind of like this:
We have a WeaponType enum type.
This WeaponType acts like a table that holds all statistics for a weapon. So it kinda looks like:
public enum WeaponType(int damage, boolean isTwoHand)
......
SWORD(4, false)
AXE(5, true)
MACE(5, false)
So in our Weapon class, we're able to access the weapon stats depending on the type.
WeaponType type;
int dmg;
boolean isTwoHand;
public Weapon(WeaponType type) {
this.type = type;
dmg = type.damage;
isTwoHand = type.isTwoHand;
}
The reason why I'm using enum type to store values is because 2D arrays can get kind of messy with null values and the sizing of the array isnt dynamic. If anyone has a better way of implementing it, then please do share.
So basically what I would like to know, is a flexible way of making customised weapons outside of the statistics in the enum table (like in the examples I showed earlier).
The only thing I can think of right now, is subtyping the Weapon class, and coding in extra methods to implement them. But I think this can get rather messy with too many subtyped weapons. It will be hard to manage if I have lots of weapon types.
If anyone has any ideas, then I'd love to know.
Thank you!