adding in better classes and methods
This commit is contained in:
95
main.py
95
main.py
@@ -13,59 +13,104 @@ class Adventurer:
|
|||||||
self.charisma = attributes.get('charisma', roll_dice(3,6))
|
self.charisma = attributes.get('charisma', roll_dice(3,6))
|
||||||
self.player_class = None
|
self.player_class = None
|
||||||
|
|
||||||
|
def __str__(self):
|
||||||
|
return f"{self.player_class}"
|
||||||
|
|
||||||
|
def get_attributes(self):
|
||||||
|
attribute_list = ['strength', 'intelligence', 'wisdom', 'dexterity', 'constitution', 'charisma']
|
||||||
|
return {k: self.__dict__[k] for k in attribute_list}
|
||||||
|
|
||||||
|
def get_best_prime_attribute(self):
|
||||||
|
attribute_list = [ 'strength', 'intelligence', 'wisdom', 'dexterity' ]
|
||||||
|
prime_attributes = {k: self.__dict__[k] for k in attribute_list}
|
||||||
|
# of those remaining, return highest, found this at https://stackoverflow.com/a/280156
|
||||||
|
return max(prime_attributes, key=prime_attributes.get)
|
||||||
|
|
||||||
|
def roll_equipment(self):
|
||||||
|
print("testing!")
|
||||||
|
|
||||||
|
|
||||||
class Fighter(Adventurer):
|
class Fighter(Adventurer):
|
||||||
prime_requisite = "strength"
|
prime_requisite = "strength"
|
||||||
def __init__(self, attributes: dict) -> None:
|
def __init__(self, attributes={}) -> None:
|
||||||
PlayerCharacter.__init__(self, attributes)
|
Adventurer.__init__(self, attributes)
|
||||||
self.player_class = "fighter"
|
self.player_class = "fighter"
|
||||||
self.hp = roll_dice(1, 8)
|
self.hp = roll_dice(1, 8)
|
||||||
|
|
||||||
class MagicUser(Adventurer):
|
class MagicUser(Adventurer):
|
||||||
prime_requisite = "intelligence"
|
prime_requisite = "intelligence"
|
||||||
def __init__(self, attributes: dict) -> None:
|
def __init__(self, attributes={}) -> None:
|
||||||
PlayerCharacter.__init__(self, name, attributes)
|
Adventurer.__init__(self, attributes)
|
||||||
self.player_class = "magic-user"
|
self.player_class = "magic-user"
|
||||||
self.hp = roll_dice(1, 4)
|
self.hp = roll_dice(1, 4)
|
||||||
|
|
||||||
class Cleric(Adventurer):
|
class Cleric(Adventurer):
|
||||||
prime_requisite = "wisdom"
|
prime_requisite = "wisdom"
|
||||||
def __init__(self, attributes: dict) -> None:
|
def __init__(self, attributes={}) -> None:
|
||||||
PlayerCharacter.__init__(self, name, attributes)
|
Adventurer.__init__(self, attributes)
|
||||||
self.player_class = "cleric"
|
self.player_class = "cleric"
|
||||||
self.hp = roll_dice(1, 6)
|
self.hp = roll_dice(1, 6)
|
||||||
|
|
||||||
class Thief(Adventurer):
|
class Thief(Adventurer):
|
||||||
prime_requisite = "dexterity"
|
prime_requisite = "dexterity"
|
||||||
def __init__(self, attributes: dict) -> None:
|
def __init__(self, attributes={}) -> None:
|
||||||
PlayerCharacter.__init__(self, name, attributes)
|
Adventurer.__init__(self, attributes)
|
||||||
self.player_class = "thief"
|
self.player_class = "thief"
|
||||||
|
self.hp = roll_dice(1, 4)
|
||||||
|
|
||||||
|
class Dwarf(Adventurer):
|
||||||
|
prime_requisite = "strength"
|
||||||
|
requirements = {'constitution' : 9 }
|
||||||
|
def __init__(self, attributes={}) -> None:
|
||||||
|
Adventurer.__init__(self, attributes)
|
||||||
|
self.player_class = "dwarf"
|
||||||
|
self.hp = roll_dice(1, 8)
|
||||||
|
|
||||||
|
class Elf(Adventurer):
|
||||||
|
prime_requisite = "intellgence"
|
||||||
|
requirements = {'intelligence' : 9 }
|
||||||
|
def __init__(self, attributes={}) -> None:
|
||||||
|
Adventurer.__init__(self, attributes)
|
||||||
|
self.player_class = "elf"
|
||||||
|
self.hp = roll_dice(1, 6)
|
||||||
|
|
||||||
|
class Halfling(Adventurer):
|
||||||
|
prime_requisite = "dexterity"
|
||||||
|
requirements = {'constitution' : 9, 'dexterity' : 9 }
|
||||||
|
def __init__(self, attributes={}) -> None:
|
||||||
|
Adventurer.__init__(self, attributes)
|
||||||
|
self.player_class = "halfling"
|
||||||
self.hp = roll_dice(1, 6)
|
self.hp = roll_dice(1, 6)
|
||||||
|
|
||||||
# Player Class Selector
|
# Player Class Selector
|
||||||
class ClassSelector():
|
class ClassSelector():
|
||||||
def __init__(self, player: Adventurer) -> None:
|
def __init__(self, player: Adventurer) -> None:
|
||||||
self.player = player
|
self.player = player
|
||||||
self.prime_requisites = { "strength" : "Fighter", "intelligence" : "Magic User", "wisdom" : "Cleric", "dexterity" : "Thief" }
|
self.available_classes = [ Fighter(), MagicUser(), Cleric(), Thief() ]
|
||||||
|
self.classes_with_reqs = [ Dwarf(), Elf(), Halfling() ]
|
||||||
self.selected_class = self.selection()
|
self.selected_class = self.selection()
|
||||||
|
|
||||||
def get_best_prime_attribute(self):
|
def return_class_by_best_attribute(self):
|
||||||
attributes = self.player.__dict__.copy()
|
# for adventurer classes in available classes, return the one where that classes' prime requisite is equal to the players best attribute
|
||||||
del attributes['player_class']
|
return [adv_class for adv_class in self.available_classes if adv_class.prime_requisite == self.player.get_best_prime_attribute()][0]
|
||||||
# we should not evaluate these two stats
|
|
||||||
del attributes['constitution']
|
def return_classes_with_requirements(self):
|
||||||
del attributes['charisma']
|
p_attrs = self.player.get_attributes()
|
||||||
# of those remaining, return highest, found this at https://stackoverflow.com/a/280156
|
possible_classes = []
|
||||||
return max(attributes, key=attributes.get)
|
for c in self.classes_with_reqs:
|
||||||
|
match_count = 0
|
||||||
|
for r in c.requirements:
|
||||||
|
if p_attrs[r] >= c.requirements[r]:
|
||||||
|
match_count += 1
|
||||||
|
if match_count >= len(c.requirements):
|
||||||
|
possible_classes.append(c)
|
||||||
|
return possible_classes
|
||||||
|
|
||||||
def selection(self):
|
def selection(self):
|
||||||
best_prime_attribute = self.get_best_prime_attribute()
|
best_prime_attribute = self.player.get_best_prime_attribute()
|
||||||
# create an array of possible player classes, add the best choice per player's best core attributes
|
# create an array of possible player classes, add the best choice per player's best core attributes
|
||||||
class_to_add = self.prime_requisites[best_prime_attribute]
|
possible_classes = [ self.return_class_by_best_attribute() ]
|
||||||
possible_classes = [class_to_add]
|
possible_classes += self.return_classes_with_requirements()
|
||||||
# check if player qualifies for other classes
|
|
||||||
if self.player.constitution >= 9 : possible_classes.append("Dwarf")
|
|
||||||
if self.player.intelligence >= 9 : possible_classes.append("Elf")
|
|
||||||
if self.player.constitution >= 9 and self.player.dexterity >= 9 : possible_classes.append("Halfling")
|
|
||||||
# randomly select class
|
# randomly select class
|
||||||
selected_class = random.choice(possible_classes)
|
selected_class = random.choice(possible_classes)
|
||||||
return f"{selected_class}"
|
return f"{selected_class}"
|
||||||
@@ -81,7 +126,7 @@ class PartyGenerator():
|
|||||||
attempts = 0
|
attempts = 0
|
||||||
while new_player.player_class not in self.adventurers:
|
while new_player.player_class not in self.adventurers:
|
||||||
attempts += 1
|
attempts += 1
|
||||||
my_adv = ClassSelector(new_player).selected_class
|
my_adv = ClassSelector(new_player).selection()
|
||||||
new_player.player_class = my_adv
|
new_player.player_class = my_adv
|
||||||
if new_player.player_class not in self.adventurers:
|
if new_player.player_class not in self.adventurers:
|
||||||
self.adventurers.append(new_player.player_class)
|
self.adventurers.append(new_player.player_class)
|
||||||
|
|||||||
Reference in New Issue
Block a user