150 lines
5.7 KiB
Python
Executable File
150 lines
5.7 KiB
Python
Executable File
#!/usr/bin/python3
|
|
import random
|
|
|
|
# Player Character Classes
|
|
class Adventurer:
|
|
def __init__(self, attributes={}) -> None:
|
|
# using a get() method to pull an attribute else use a default value, https://python-academy.org/en/handbook/get
|
|
self.strength = attributes.get('strength', roll_dice(3,6))
|
|
self.intelligence = attributes.get('intelligence', roll_dice(3,6))
|
|
self.wisdom = attributes.get('wisdom', roll_dice(3,6))
|
|
self.dexterity = attributes.get('dexterity', roll_dice(3,6))
|
|
self.constitution = attributes.get('constitution', roll_dice(3,6))
|
|
self.charisma = attributes.get('charisma', roll_dice(3,6))
|
|
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):
|
|
prime_requisite = "strength"
|
|
def __init__(self, attributes={}) -> None:
|
|
Adventurer.__init__(self, attributes)
|
|
self.player_class = "fighter"
|
|
self.hp = roll_dice(1, 8)
|
|
|
|
class MagicUser(Adventurer):
|
|
prime_requisite = "intelligence"
|
|
def __init__(self, attributes={}) -> None:
|
|
Adventurer.__init__(self, attributes)
|
|
self.player_class = "magic-user"
|
|
self.hp = roll_dice(1, 4)
|
|
|
|
class Cleric(Adventurer):
|
|
prime_requisite = "wisdom"
|
|
def __init__(self, attributes={}) -> None:
|
|
Adventurer.__init__(self, attributes)
|
|
self.player_class = "cleric"
|
|
self.hp = roll_dice(1, 6)
|
|
|
|
class Thief(Adventurer):
|
|
prime_requisite = "dexterity"
|
|
def __init__(self, attributes={}) -> None:
|
|
Adventurer.__init__(self, attributes)
|
|
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)
|
|
|
|
# Player Class Selector
|
|
class ClassSelector():
|
|
def __init__(self, player: Adventurer) -> None:
|
|
self.player = player
|
|
self.available_classes = [ Fighter(), MagicUser(), Cleric(), Thief() ]
|
|
self.classes_with_reqs = [ Dwarf(), Elf(), Halfling() ]
|
|
self.selected_class = self.selection()
|
|
|
|
def return_class_by_best_attribute(self):
|
|
# for adventurer classes in available classes, return the one where that classes' prime requisite is equal to the players best attribute
|
|
return [adv_class for adv_class in self.available_classes if adv_class.prime_requisite == self.player.get_best_prime_attribute()][0]
|
|
|
|
def return_classes_with_requirements(self):
|
|
p_attrs = self.player.get_attributes()
|
|
possible_classes = []
|
|
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):
|
|
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
|
|
possible_classes = [ self.return_class_by_best_attribute() ]
|
|
possible_classes += self.return_classes_with_requirements()
|
|
# randomly select class
|
|
selected_class = random.choice(possible_classes)
|
|
return f"{selected_class}"
|
|
|
|
class PartyGenerator():
|
|
def __init__(self, party_size=4) -> None:
|
|
self.size = party_size
|
|
self.adventurers = []
|
|
|
|
def gen_party(self):
|
|
while len(self.adventurers) < self.size:
|
|
new_player = Adventurer()
|
|
attempts = 0
|
|
while new_player.player_class not in self.adventurers:
|
|
attempts += 1
|
|
my_adv = ClassSelector(new_player).selection()
|
|
new_player.player_class = my_adv
|
|
if new_player.player_class not in self.adventurers:
|
|
self.adventurers.append(new_player.player_class)
|
|
# i couldnt randomly generate a scenario where a character couldn't be added, but it seems possible, so this is the hard cut off
|
|
elif attempts > 10:
|
|
self.adventurers.append(new_player.player_class)
|
|
|
|
def __str__(self):
|
|
return f"{self.adventurers}"
|
|
|
|
# functions
|
|
def roll_dice(count, sides):
|
|
return sum(random.randint(1,sides) for _ in range(count))
|
|
|
|
def main():
|
|
new_party = PartyGenerator()
|
|
new_party.gen_party()
|
|
print(new_party)
|
|
|
|
main()
|