84 lines
3.4 KiB
Python
Executable File
84 lines
3.4 KiB
Python
Executable File
#!/usr/bin/python3
|
|
import random
|
|
|
|
class PlayerCharacter:
|
|
def __init__(self, attributes={}) -> None:
|
|
self.strength = roll_dice(3,6) if not attributes else attributes['strength']
|
|
self.intelligence = roll_dice(3,6) if not attributes else attributes['intelligence']
|
|
self.wisdom = roll_dice(3,6) if not attributes else attributes['wisdom']
|
|
self.dexterity = roll_dice(3,6) if not attributes else attributes['dexterity']
|
|
self.constitution = roll_dice(3,6) if not attributes else attributes['constitution']
|
|
self.charisma = roll_dice(3,6) if not attributes else attributes['charisma']
|
|
|
|
def class_selector(self):
|
|
# take the 4 primary attribtues
|
|
base_attr = self.__dict__.copy()
|
|
del base_attr['constitution']
|
|
del base_attr['charisma']
|
|
# of those grab the highest, found this at https://stackoverflow.com/a/280156
|
|
max_base_attr = max(base_attr, key=base_attr.get)
|
|
# use that to pick the best possible base class
|
|
best_class = { "strength" : "Fighter", "intelligence" : "Magic User", "wisdom" : "Cleric", "dexterity" : "Thief" }
|
|
best_base_class = best_class[max_base_attr]
|
|
# create a list of possible classes
|
|
possible_classes = [ best_base_class ]
|
|
# check if player qualifies for other classes
|
|
if self.constitution >= 9 : possible_classes.append("Dwarf")
|
|
if self.intelligence >= 9 : possible_classes.append("Elf")
|
|
if self.constitution >= 9 and self.dexterity >= 9 : possible_classes.append("Halfling")
|
|
# randomly select class
|
|
selected_class = random.choice(possible_classes)
|
|
return f"{selected_class}"
|
|
|
|
class Fighter(PlayerCharacter):
|
|
prime_requisite = "strength"
|
|
def __init__(self, attributes: dict) -> None:
|
|
PlayerCharacter.__init__(self, attributes)
|
|
self.player_class = "fighter"
|
|
self.hp = roll_dice(1, 8)
|
|
|
|
class MagicUser(PlayerCharacter):
|
|
prime_requisite = "intelligence"
|
|
def __init__(self, attributes: dict) -> None:
|
|
PlayerCharacter.__init__(self, name, attributes)
|
|
self.player_class = "magic-user"
|
|
self.hp = roll_dice(1, 4)
|
|
|
|
class Cleric(PlayerCharacter):
|
|
prime_requisite = "wisdom"
|
|
def __init__(self, attributes: dict) -> None:
|
|
PlayerCharacter.__init__(self, name, attributes)
|
|
self.player_class = "cleric"
|
|
self.hp = roll_dice(1, 6)
|
|
|
|
class Thief(PlayerCharacter):
|
|
prime_requisite = "dexterity"
|
|
def __init__(self, attributes: dict) -> None:
|
|
PlayerCharacter.__init__(self, name, attributes)
|
|
self.player_class = "thief"
|
|
self.hp = roll_dice(1, 6)
|
|
|
|
# functions
|
|
def roll_dice(count, sides):
|
|
return sum(random.randint(1,sides) for _ in range(count))
|
|
|
|
def main():
|
|
adventurer_party = []
|
|
expected_party_size = 4
|
|
while len(adventurer_party) < expected_party_size:
|
|
new_player = PlayerCharacter()
|
|
selected_class = None
|
|
attempts = 0
|
|
while selected_class not in adventurer_party:
|
|
attempts += 1
|
|
selected_class = new_player.class_selector()
|
|
if selected_class not in adventurer_party:
|
|
adventurer_party.append(selected_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:
|
|
adventurer_party.append(selected_class)
|
|
|
|
print(f"{adventurer_party}")
|
|
|
|
main()
|