I'm writing my first game and would love some advice on how to get away from all this hardcoding I'm using... Each Character has "abilities" (all individual functions) but I can't seem to figure out how to streamline this. Example:
def lightning_bolt(self): if self.is_stunned: print("Stunned...ability unsuccessful.") elif self.is_confused: confused_test = roll_d_x(2) if confused_test == 1: print("Confused...ability unsuccessful.") else: defender.mobility = (defender.mobility / 2) success = self.success_check() defender.mobility = (defender.mobility * 2) if success: volatile_roll = roll_d_x(10) if volatile_roll == 1: self.volatile_magic() else: defender.lose_health(((self.energy * 0.5) + 10)) self.lose_energy(25) stun_test = roll_d_x(4) if stun_test == 1: defender.is_stunned = True else: print("Ability failed.")
Note: all abilities must pass this "stunned and confused test" and a "volatile test". I will be defining a function for those. *I wanted to make "class Ability:", but I want each character to have their own individual abilities. Is there a way to nest classes or something? Any ideas to streamline aspects like "cost" and "damage dealt", etc.?