Different Attack Systems in RPG [duplicate]

I'm making a 2d rpg game with libgdx and java, and I'm wondering how I would organize different attack systems - magic, melee, etc. (it's not a turn-based rpg). I have a PlayerClass enum, a Player2D class(2d representation), and a Player class (for storing player data). Would I make an Attack class, with MagicAttack and MeleeAttack? Then have a method in Player2D like attack(Attack attack)? I've considered a few options, but I want to be sure. Thanks!

• I like the idea of actually having separate methods for MagicAttack (...) and MeleeAttack (...). You might pass in a specialized class or enum value depending on whether it's elemental/non-elemental, blunt/slashing/piercing/etc. to make resistance checks straight-forward. – Andon M. Coleman Sep 3 '13 at 5:00
• I actually meant having MagicAttack and MeleeAttack be subclasses of Attack... – Jimmt Sep 3 '13 at 5:07
• Oh... I'm not so sure about that then, my thinking is that a lot of weapons have magical damage components in addition to physical and some spells do physical damage in addition to magical. It's difficult to handle this simply by subclassing in languages that don't support multiple inheritance. – Andon M. Coleman Sep 3 '13 at 5:18
• ah, good point there. So an Attack class with methods for each type of attack? Where would I put this class? – Jimmt Sep 3 '13 at 5:28
• IMHO, MagicAttack and MeleeAttack are both attacks. A sword (for example) may have both, or may have a lot of attacks type: (melee, magical melee, magical distance, ranged (if throwing), etc..). What is not clear for me, it if they should be a parameter of the weapon: sword(melee=34, magic-dist:5, ..) or classes. – Adrian Maire Sep 3 '13 at 7:45

I would recommend you to create an abstract base class or interface Attack which defines a method perform(Combatant user, Combatant victim).
AttackMagic and AttackMelee would extend this class with their own implementations of this method.
In the project I am currently working on (an MMORPG server in Java) I did however use a different, very non-object-oriented, approach. I have a single class GameSystem which includes methods for calculating all combat mechanic rules. It has a static method performAttack(Combatant attacker, Combatant victim, Attack attack) with lots of if-else and switch statements for the different kinds of attackers, victims and attacks.