I'm designing a simple role-playing game (similar to World of Warcraft, League of Legends, etc.) where you basically have a hero or a champion who fights with wild creatures and other heroes/champions. This hero can then level up by gaining experience points from fights, and each level grants him a skill point, which allows him to level up one of his skills. Each skill has its own purpose and does its own thing, an example of a skill would be:
class DamageAura(Skill):
"""
This skill increases damage dealt by your hero,
as well as deals damage back to the ones who attack your hero.
"""
name = 'Damage Aura'
description = '...'
# These methods are called when the actual event happens in game
def unit_attack(self, target, damage):
target._health -= (self.level / 100) * damage
def unit_defend(self, attacker, damage):
attacker.deal_damage((self.level / 100) * damage)
Now I would like the players of the game to be able to make their own heroes, and I need it to be simple. The problem is, I don't want to do "bad" code simply to make creating heroes easier. Here's what a hero class would ideally look like:
class Warrior(Hero):
name = 'Warrior'
description = 'Ancient Warrior is thirsty for blood.'
maximum_level = 30
agility = 20
intelligence = 10
strength = 30
class DamageAura(Skill):
name = 'Damage Aura'
description = '...'
def unit_attack(...):
...
class StrongerWeapons(Skill):
name = 'Stronger Weapons'
...
Now the problem is, I'd like the name
variable to be an attribute of the actual hero (f.e.Warrior
) instance, not a class variable.
Is there an easy, yet safe way to merge these two?
Basically the class variables would define the default values for a hero, but if I wanted to create a Warrior
instance with a custom name, I could do so by simply doing warrior1 = Warrior(name='Warrior God', maximum_level=40)
This is what the class would look like if I didn't have to worry about subclasses or ease-of-creation:
class Hero(object):
def __init__(self, name, description='', maximum_level=50, skill_set=None, ...):
self.name = name
self.description = description
self.maximum_level = maximum_level
self.skill_set = skill_set or []
...
EDIT: I forgot to mention; each player could be playing the exact same hero, Warrior in this case, so that's why Warrior is a class, not just an instance of Hero. They would all have the same skill set, but unique levels, etc.
EDIT 2: I'm having no problem with Python classes or anything, normally I would NOT make the skills nested classes, or anything similar, but in this case I must invest a lot on ease of creating classes, so even the "noobs" can do it without knowing rarely any python at all.