Moved inventory details to its own class

This commit is contained in:
kansaigaijin
2025-06-26 21:42:55 +12:00
parent b2f5e4eaf1
commit f896cc9184
2 changed files with 498 additions and 539 deletions

View File

@@ -1,470 +1,432 @@
import time import time
from player import * from player import *
def wait(): def wait():
input("Press enter to continue...") input("Press enter to continue...")
def startGame(): def startGame():
print("Welcome, stranger.") print("Welcome, stranger.")
start = input("Would you like to create your own character or use pre-generated stats?" start = input("Would you like to create your own character or use pre-generated stats?"
"\n 1) Create a new character\n 2) Pre-generated\n >> ") "\n 1) Create a new character\n 2) Pre-generated\n >> ")
while True: while True:
if start in ("2", "Pregen"): if start in ("2", "Pregen"):
print("Please be prepared to enter a name, gender, age, race, and class, from those available in the game." print("Please be prepared to enter a name, gender, age, race, and class, from those available in the game."
"\nIf you are unsure what the options are, please go back and create a new character.") "\nIf you are unsure what the options are, please go back and create a new character.")
create = input("Do you wish to continue? Y/N\n >> ") create = input("Do you wish to continue? Y/N\n >> ")
if create in ("y", "yes"): if create in ("y", "yes"):
name = input("Name: ") name = input("Name: ")
gender = input("Gender: ") gender = input("Gender: ")
age = int(input("Age: ") age = int(input("Age: ")
race = input("Race: ") race = input("Race: ")
job = input("Job: ") job = input("Job: ")
return name, gender, age, race, job return name, gender, age, race, job
elif create in ("n", "no"): elif create in ("n", "no"):
start = "1" start = "1"
elif start in ("1", "Create"): elif start in ("1", "Create"):
while True: # Global check to see if Name, Age, and Gender are correct while True: # Global check to see if Name, Age, and Gender are correct
# Name # Name
name = input('What is your name?\n >> ') name = input('What is your name?\n >> ')
while len(name) < 2: while len(name) < 2:
name = input('Input name was too short. Try again.\nWhat is your name?\n >> ') name = input('Input name was too short. Try again.\nWhat is your name?\n >> ')
# Gender # Gender
while True: while True:
gender_select = input("What is your gender?\n" gender_select = input("What is your gender?\n"
"1) Male\n2) Female\n3) Other\n >> ") "1) Male\n2) Female\n3) Other\n >> ")
if gender_select not in ("male", "female", "other", "1", "2", "3"): if gender_select not in ("male", "female", "other", "1", "2", "3"):
print("Sorry I didn't recognise that gender. Please try again.") print("Sorry I didn't recognise that gender. Please try again.")
continue continue
else: else:
break break
if gender_select in ("1", "male"): if gender_select in ("1", "male"):
gender = "Male" gender = "Male"
elif gender_select in ("2", "female"): elif gender_select in ("2", "female"):
gender = "Female" gender = "Female"
elif gender_select in ("3", "other"): elif gender_select in ("3", "other"):
gender = "Other" gender = "Other"
while True: while True:
# Age # Age
try: try:
age = int(input('How old are you?\n >> ') age = int(input('How old are you?\n >> ')
break break
except ValueError: except ValueError:
print("Sorry I didn't recognise that age. Please type in a whole number.") print("Sorry I didn't recognise that age. Please type in a whole number.")
continue continue
# Double check responses # Double check responses
correct = input(f"Hello, {name}. You are a {age} year old {gender}.\nIs this correct? Y/N\n >> ") correct = input(f"Hello, {name}. You are a {age} year old {gender}.\nIs this correct? Y/N\n >> ")
if correct in ['y', 'yes']: if correct in ['y', 'yes']:
break break
elif correct in ['n', 'no']: elif correct in ['n', 'no']:
continue continue
else: else:
print("Sorry, I didn't catch that.\n") print("Sorry, I didn't catch that.\n")
correct = input(f"You are a {age} year old {gender}. \nIs this correct? Y/N\n >> ") correct = input(f"You are a {age} year old {gender}. \nIs this correct? Y/N\n >> ")
if correct in ['y', 'yes']: if correct in ['y', 'yes']:
break break
elif correct in ['n', 'no']: elif correct in ['n', 'no']:
continue continue
break break
while True: # Global check to see if Race and Job are correct while True: # Global check to see if Race and Job are correct
# Race # Race
while True: while True:
race = input("Please select a race to learn more about it: Elf, Dwarf, or Human.\n >> ") race = input("Please select a race to learn more about it: Elf, Dwarf, or Human.\n >> ")
if race not in ("Elf", "Dwarf", "Human", None): if race not in ("Elf", "Dwarf", "Human", None):
race = input("Sorry I didn't recognise that race. Please select 'Elf', 'Dwarf', or 'Human'.\n >> ") race = input("Sorry I didn't recognise that race. Please select 'Elf', 'Dwarf', or 'Human'.\n >> ")
elif race is None: elif race is None:
race = input("Please select a race to learn more about it: Elf, Dwarf, or Human.\n >> ") race = input("Please select a race to learn more about it: Elf, Dwarf, or Human.\n >> ")
continue continue
else: else:
# Replace these prints with appropriate explanations for the web interface # Replace these prints with appropriate explanations for the web interface
if race == "Elf": if race == "Elf":
print("Information about Elves...") print("Information about Elves...")
elif race == "Dwarf": elif race == "Dwarf":
print("Information about Dwarves...") print("Information about Dwarves...")
elif race == "Human": elif race == "Human":
print("Information about Humans...") print("Information about Humans...")
print('Would you like to proceed with this race or view another?') print('Would you like to proceed with this race or view another?')
proceed = input('1) Proceed\n2) View another race\n >> ') proceed = input('1) Proceed\n2) View another race\n >> ')
if proceed in ('1', 'proceed'): if proceed in ('1', 'proceed'):
break break
elif proceed in ('2', 'view', 'view another', 'view another race'): elif proceed in ('2', 'view', 'view another', 'view another race'):
race = None race = None
continue continue
# Job # Job
while True: while True:
job = input("Please select a job to learn more about it: Barbarian, Cleric, or Wizard.\n >> ") job = input("Please select a job to learn more about it: Barbarian, Cleric, or Wizard.\n >> ")
if job not in ("Barbarian", "Cleric", "Wizard", None): if job not in ("Barbarian", "Cleric", "Wizard", None):
job = input("Sorry I didn't recognise that job. Please select 'Barbarian', 'Cleric', or 'Wizard'.\n >> ") job = input("Sorry I didn't recognise that job. Please select 'Barbarian', 'Cleric', or 'Wizard'.\n >> ")
elif job is None: elif job is None:
job = input("Please select a job to learn more about it: Barbarian, Cleric, or Wizard.\n >> ") job = input("Please select a job to learn more about it: Barbarian, Cleric, or Wizard.\n >> ")
continue continue
else: else:
# Replace these prints with appropriate explanations for the web interface # Replace these prints with appropriate explanations for the web interface
if job == "Barbarian": if job == "Barbarian":
print("Information about Barbarians...") print("Information about Barbarians...")
elif job == "Cleric": elif job == "Cleric":
print("Information about Clerics...") print("Information about Clerics...")
elif job == "Wizard": elif job == "Wizard":
print("Information about Wizards...") print("Information about Wizards...")
print('Would you like to proceed with this job or view another?') print('Would you like to proceed with this job or view another?')
proceed = input('1) Proceed\n2) View another job\n >> ') proceed = input('1) Proceed\n2) View another job\n >> ')
if proceed in ('1', 'proceed'): if proceed in ('1', 'proceed'):
break break
elif proceed in ('2', 'view', 'view another', 'view another job'): elif proceed in ('2', 'view', 'view another', 'view another job'):
job = None job = None
continue continue
while True: while True:
# Final check # Final check
correct = input(f"{name}, you are a {race} {job}.\nIs this correct? Y/N\n >> ") correct = input(f"{name}, you are a {race} {job}.\nIs this correct? Y/N\n >> ")
if correct in ['y', 'yes']: if correct in ['y', 'yes']:
break break
elif correct in ['n', 'no']: elif correct in ['n', 'no']:
continue continue
else: else:
print("Sorry, I didn't catch that. Please try again.\n") print("Sorry, I didn't catch that. Please try again.\n")
continue continue
return name, gender, age, race, job return name, gender, age, race, job
def query_equip(): def query_equip():
while True: while True:
print("Do you want to:\n" print("Do you want to:\n"
"1) View your equipped items\n" "1) View your equipped items\n"
"2) Change your equipped items\n" "2) Change your equipped items\n"
"3) Return") "3) Return")
response = input(">> ") response = input(">> ")
if response == "1": if response == "1":
current_equipment() current_equipment()
elif response == "2": elif response == "2":
change_equip() change_equip()
elif response == "3": elif response == "3":
break break
def change_equip(): def change_equip():
canAddAttunement() canAddAttunement()
while True: while True:
response = input("Which equipment slot would you like to change?\n" response = input("Which equipment slot would you like to change?\n"
"1) Weapon\n" "1) Weapon\n"
"2) Armor\n" "2) Armor\n"
"3) Other\n" "3) Other\n"
"4) Return\n" "4) Return\n"
">> ").title() ">> ").title()
if response not in ("1", "2", "3", "4", "Weapon", "Armor", "Other", "Return"): if response not in ("1", "2", "3", "4", "Weapon", "Armor", "Other", "Return"):
print("Sorry I didn't recognise that. Please try again.\n") print("Sorry I didn't recognise that. Please try again.\n")
change_equip() change_equip()
elif response in ("1", "Weapon"): # Weapon elif response in ("1", "Weapon"): # Weapon
itemlist = ["Return"] # create blank list for items itemlist = ["Return"] # create blank list for items
for item_key, item_value in Inventory.items(): # item, attribute for item_key, item_value in Inventory.items(): # item, attribute
for key, value in item_value.items(): # attribute, stat for key, value in item_value.items(): # attribute, stat
if key == "object" and value == Weapon: # if item = class `Weapon` if key == "object" and value == Weapon: # if item = class `Weapon`
itemlist.append(item_key) itemlist.append(item_key)
if item_key in Equipment.values(): if item_key in Equipment.values():
itemlist.remove(item_key) itemlist.remove(item_key)
if len(itemlist) == 1: if len(itemlist) == 1:
print("You have nothing available to equip.\n") print("You have nothing available to equip.\n")
else: else:
print("What would you like to equip?\n") print("What would you like to equip?\n")
for i, name in enumerate(itemlist, start=1): for i, name in enumerate(itemlist, start=1):
option = f'{i}) {name}\n' option = f'{i}) {name}\n'
print(option) print(option)
selection = int(input(">> ")) selection = int(input(">> "))
for i, name in enumerate(itemlist, start=1): for i, name in enumerate(itemlist, start=1):
if selection == i: if selection == i:
if name == "Return": if name == "Return":
break break
elif name.itemType == ItemType.Weapon: elif name.itemType == ItemType.Weapon:
if name.attunement: # if item has attunement if name.attunement: # if item has attunement
if not canAddAttunement(): # check if can add another attuned item if not canAddAttunement(): # check if can add another attuned item
if Equipment["Main Hand"].attunement: # if attune is max, check if swapped weapon is attuned if Equipment["Main Hand"].attunement: # if attune is max, check if swapped weapon is attuned
if name.versatile: if name.versatile:
Equipment["Main Hand"] = name Equipment["Main Hand"] = name
Equipment["Off Hand"] = name Equipment["Off Hand"] = name
elif name.slot == "Main Hand": elif name.slot == "Main Hand":
Equipment["Main Hand"] = name Equipment["Main Hand"] = name
Equipment["Off Hand"] = None Equipment["Off Hand"] = None
elif name.slot == "Two Handed": elif name.slot == "Two Handed":
Equipment["Main Hand"] = None Equipment["Main Hand"] = None
Equipment["Off Hand"] = None Equipment["Off Hand"] = None
Equipment["Two Handed"] = name Equipment["Two Handed"] = name
else: else:
print("\n Cannot equip items: Too many attuned items equipped") # if not attuned, it refuses the equip. print("\n Cannot equip items: Too many attuned items equipped") # if not attuned, it refuses the equip.
break break
else: # If canAddAttunement = True else: # If canAddAttunement = True
if name.versatile: if name.versatile:
Equipment["Main Hand"] = name Equipment["Main Hand"] = name
Equipment["Off Hand"] = name Equipment["Off Hand"] = name
elif name.slot == "Main Hand": elif name.slot == "Main Hand":
Equipment["Main Hand"] = name Equipment["Main Hand"] = name
Equipment["Off Hand"] = None Equipment["Off Hand"] = None
elif name.slot == "Two Handed": elif name.slot == "Two Handed":
Equipment["Main Hand"] = None Equipment["Main Hand"] = None
Equipment["Off Hand"] = None Equipment["Off Hand"] = None
Equipment["Two Handed"] = name Equipment["Two Handed"] = name
print(f"{current_equipment()}") print(f"{current_equipment()}")
elif response in ("2", "Armor"): # Armor elif response in ("2", "Armor"): # Armor
itemlist = ["Return"] # create blank list for items itemlist = ["Return"] # create blank list for items
for item_key, item_value in Inventory.items(): # item, attribute for item_key, item_value in Inventory.items(): # item, attribute
for key, value in item_value.items(): # attribute, stat for key, value in item_value.items(): # attribute, stat
if key == "object" and value == Armor: # if item = class `Weapon` if key == "object" and value == Armor: # if item = class `Weapon`
itemlist.append(item_key) # Add item type to list itemlist.append(item_key) # Add item type to list
if item_key in Equipment.values(): if item_key in Equipment.values():
itemlist.remove(item_key) # remove from list if currently equipped - itemlist.remove(item_key) # remove from list if currently equipped -
# consider if holding multiple objects # consider if holding multiple objects
if len(itemlist) == 1: if len(itemlist) == 1:
print("You have nothing available to equip.\n") print("You have nothing available to equip.\n")
else: else:
print("What would you like to equip?\n") print("What would you like to equip?\n")
for i, name in enumerate(itemlist, start=1): for i, name in enumerate(itemlist, start=1):
option = f'{i}) {name}' option = f'{i}) {name}'
print(option) print(option)
selection = int(input(">> ")) selection = int(input(">> "))
for i, name in enumerate(itemlist, start=1): for i, name in enumerate(itemlist, start=1):
if selection == i: if selection == i:
if name == "Return": if name == "Return":
break break
elif name.itemType == Armor: elif name.itemType == Armor:
try: try:
if name.attunment: if name.attunment:
print("Not coded attunement yet") # if item has attunement - check availability print("Not coded attunement yet") # if item has attunement - check availability
except AttributeError: # if no attunement except AttributeError: # if no attunement
if name.slot == Slots.Helm: if name.slot == Slots.Helm:
equip = {"Helm": name} equip = {"Helm": name}
Equipment.update(equip) Equipment.update(equip)
elif name.slot == Slots.Chest: elif name.slot == Slots.Chest:
equip = {"Chest": name} equip = {"Chest": name}
Equipment.update(equip) Equipment.update(equip)
elif name.slot == Slots.Wrists: elif name.slot == Slots.Wrists:
equip = {"Wrists": name} equip = {"Wrists": name}
Equipment.update(equip) Equipment.update(equip)
elif name.slot == Slots.Feet: elif name.slot == Slots.Feet:
equip = {"Feet": name} equip = {"Feet": name}
Equipment.update(equip) Equipment.update(equip)
print(f"You now have equipped: \n" print(f"You now have equipped: \n"
f"{current_equipment()}") f"{current_equipment()}")
elif response in ("3", "Other"): # Other elif response in ("3", "Other"): # Other
itemlist = ["Return"] # create blank list for items itemlist = ["Return"] # create blank list for items
for item_key, item_value in Inventory.items(): # item, attribute for item_key, item_value in Inventory.items(): # item, attribute
for key, value in item_value.items(): # attribute, stat for key, value in item_value.items(): # attribute, stat
if key == "object" and value == Armor: # if item = class `Weapon` if key == "object" and value == Armor: # if item = class `Weapon`
itemlist.append(item_key) # Add item type to list itemlist.append(item_key) # Add item type to list
if item_key in Equipment.values(): if item_key in Equipment.values():
itemlist.remove(item_key) # remove from list if currently equipped - itemlist.remove(item_key) # remove from list if currently equipped -
# consider if holding multiple objects # consider if holding multiple objects
if len(itemlist) == 1: if len(itemlist) == 1:
print("You have nothing available to equip.\n") print("You have nothing available to equip.\n")
else: else:
print("What would you like to equip?\n") print("What would you like to equip?\n")
for i, name in enumerate(itemlist, start=1): for i, name in enumerate(itemlist, start=1):
option = f'{i}) {name}' option = f'{i}) {name}'
print(option) print(option)
selection = int(input(">> ")) selection = int(input(">> "))
for i, name in enumerate(itemlist, start=1): for i, name in enumerate(itemlist, start=1):
if selection == i: if selection == i:
if name == "Return": if name == "Return":
break break
elif name.itemType == Armor: elif name.itemType == Armor:
try: try:
if name.attunment: if name.attunment:
print("Not coded attunement yet") # if item has attunement - check availability print("Not coded attunement yet") # if item has attunement - check availability
except AttributeError: # if no attunement except AttributeError: # if no attunement
if name.slot == Slots.Neck: if name.slot == Slots.Neck:
equip = {"Neck": name} equip = {"Neck": name}
Equipment.update(equip) Equipment.update(equip)
elif name.slot == Slots.Cloak: elif name.slot == Slots.Cloak:
equip = {"Cloak": name} equip = {"Cloak": name}
Equipment.update(equip) Equipment.update(equip)
elif name.slot == Slots.LeftRing: elif name.slot == Slots.LeftRing:
equip = {"Left Ring": name} equip = {"Left Ring": name}
Equipment.update(equip) Equipment.update(equip)
elif name.slot == Slots.RightRing: elif name.slot == Slots.RightRing:
equip = {"Right Ring": name} equip = {"Right Ring": name}
Equipment.update(equip) Equipment.update(equip)
print(f"You now have equipped: \n" print(f"You now have equipped: \n"
f"{current_equipment()}") f"{current_equipment()}")
elif response in ("4", "Return"): elif response in ("4", "Return"):
break break
else: else:
print("That wasn't an option.") print("That wasn't an option.")
def get_instructions(): def get_instructions():
descrip1 = ("There are certain commands that will be available almost anytime you are able to type,\n" descrip1 = ("There are certain commands that will be available almost anytime you are able to type,\n"
"such as viewing your inventory, checking your equipped items, and also changing them.\n" "such as viewing your inventory, checking your equipped items, and also changing them.\n"
"You can also view your stats including your current and max hp.\n") "You can also view your stats including your current and max hp.\n")
descrip2 = ("Some examples are: 'Check inventory', 'Check equipment', and 'View stats'.\n" descrip2 = ("Some examples are: 'Check inventory', 'Check equipment', and 'View stats'.\n"
"To travel to a new area, just type 'Go north' or 'enter cave' etc.\n" "To travel to a new area, just type 'Go north' or 'enter cave' etc.\n"
"To replay the description of the current area, type 'location'.") "To replay the description of the current area, type 'location'.")
print(descrip1) print(descrip1)
time.sleep(5) time.sleep(5)
print(descrip2) print(descrip2)
def canAddAttunement(): def canAddAttunement():
attune = 0 attune = 0
for slot, equipment in Equipment.items(): for slot, equipment in Equipment.items():
if isinstance(equipment, Weapon): if isinstance(equipment, Weapon):
if equipment.attunement: if equipment.attunement:
attune += 1 attune += 1
Equipment["Attunement"] = attune Equipment["Attunement"] = attune
if attune > 3: if attune > 3:
return False return False
else: else:
return True return True
def error_message(): def error_message():
print("That command was not recognised. Please try again.") print("That command was not recognised. Please try again.")
def parse(input_text): def parse(input_text):
command = input_text.lower() command = input_text.lower()
object1 = None object1 = None
remaining_words_index = None remaining_words_index = None
words = input_text.split() words = input_text.split()
if len(words) > 0: if len(words) > 0:
if words[0] == "help": if words[0] == "help":
command = "help" command = "help"
if words[0] == "scene": if words[0] == "scene":
command = "scene" command = "scene"
if words[0] in ("view", "check", "show"): if words[0] in ("view", "check", "show"):
if words[1] in ("inventory", "bag", "backpack"): if words[1] in ("inventory", "bag", "backpack"):
command = "inventory" command = "inventory"
elif words[1] in ("equipment", "equip", "items"): elif words[1] in ("equipment", "equip", "items"):
command = "equipment" command = "equipment"
elif words[1] == "stats": elif words[1] == "stats":
command = "stats" command = "stats"
elif words[1] in ("hp", "hitpoints", "health"): elif words[1] in ("hp", "hitpoints", "health"):
command = "hp" command = "hp"
elif words[1] == "hit" and words[2] == "points": elif words[1] == "hit" and words[2] == "points":
command = "hp" command = "hp"
if words[0] in ("equip", "equipment"): if words[0] in ("equip", "equipment"):
command = "equipment" command = "equipment"
if words[0] in ("inventory", "bag", "backpack"): if words[0] in ("inventory", "bag", "backpack"):
command = "inventory" command = "inventory"
found_examine_words = False found_examine_words = False
if (words[0] == "examine") and len(words) > 1: if (words[0] == "examine") and len(words) > 1:
found_examine_words = True found_examine_words = True
remaining_words_index = 1 remaining_words_index = 1
if found_examine_words: if found_examine_words:
remaining_words = "" remaining_words = ""
for i in range(remaining_words_index, len(words)): for i in range(remaining_words_index, len(words)):
remaining_words += words[i] remaining_words += words[i]
if i < len(words) - 1: if i < len(words) - 1:
remaining_words += " " remaining_words += " "
command = "examine" command = "examine"
object1 = remaining_words object1 = remaining_words
found_take_words = False found_take_words = False
if ((words[0] == "take") and len(words) > 1) or \ if ((words[0] == "take") and len(words) > 1) or \
((words[0] == "pick") and (words[1] == "up") and len(words) > 2): ((words[0] == "pick") and (words[1] == "up") and len(words) > 2):
found_take_words = True found_take_words = True
remaining_words_index = 1 remaining_words_index = 1
if found_take_words: if found_take_words:
remaining_words = "" remaining_words = ""
for i in range(remaining_words_index, len(words)): for i in range(remaining_words_index, len(words)):
remaining_words += words[i] remaining_words += words[i]
if i < len(words) - 1: if i < len(words) - 1:
remaining_words += " " remaining_words += " "
command = "take" command = "take"
object1 = remaining_words object1 = remaining_words
found_loot_words = False found_loot_words = False
if (words[0] == "loot") and len(words) > 1: if (words[0] == "loot") and len(words) > 1:
found_loot_words = True found_loot_words = True
remaining_words_index = 1 remaining_words_index = 1
if found_loot_words: if found_loot_words:
remaining_words = "" remaining_words = ""
for i in range(remaining_words_index, len(words)): for i in range(remaining_words_index, len(words)):
remaining_words += words[i] remaining_words += words[i]
if i < len(words) - 1: if i < len(words) - 1:
remaining_words += " " remaining_words += " "
command = "loot" command = "loot"
object1 = remaining_words object1 = remaining_words
found_drop_words = False found_drop_words = False
if (words[0] == "drop") and len(words) > 1: if (words[0] == "drop") and len(words) > 1:
found_drop_words = True found_drop_words = True
remaining_words_index = 1 remaining_words_index = 1
if found_drop_words: if found_drop_words:
remaining_words = "" remaining_words = ""
for i in range(remaining_words_index, len(words)): for i in range(remaining_words_index, len(words)):
remaining_words += words[i] remaining_words += words[i]
if i < len(words) - 1: if i < len(words) - 1:
remaining_words += " " remaining_words += " "
command = "drop" command = "drop"
object1 = remaining_words object1 = remaining_words
if words[0] not in ("view", "check", "show", "loot", "examine", "take", "equip", "equipment", "inventory", if words[0] not in ("view", "check", "show", "loot", "examine", "take", "equip", "equipment", "inventory",
"bag", "backpack", "drop"): "bag", "backpack", "drop"):
command = "error" command = "error"
return command, object1 return command, object1
# def skill_check(skill): # def skill_check(skill):
# """Roll a d20 and add modifier # """Roll a d20 and add modifier
# Return value to compare vs a hardcoded DC""" # Return value to compare vs a hardcoded DC"""
# #
# #
# def roll_dice(num_dice): # def roll_dice(num_dice):
# roll_results = [] # roll_results = []
# for _ in range(num_dice): # for _ in range(num_dice):
# roll = randint(*user.hitDie) # roll = randint(*user.hitDie)
# roll_results.append(roll) # roll_results.append(roll)
# return roll_results # return roll_results
def current_inventory(): def calc_weight():
"""Prints a list of items in your backpack that aren't equipped to your person.""" pass
print(f'In your rucksack you have:')
for item_key, item_value in Inventory.items(): # string, dictionary
if item_key not in Equipment.values():
values = item_value.values() # make a variable of all values
values_list = list(values) # turn variable into a list
count_value = values_list[0] # take the first value from list - why?
print(f'{item_key.name} x {count_value}\n'
f' {item_key.description}\n')
def current_equipment():
"""Prints a list of items that you have equipped in your slots."""
print(f'You are currently wearing:')
for slot, equipment in Equipment.items(): # string, dictionary
if equipment is not None:
if slot == "Attunement":
continue
elif equipment.itemType == ItemType.Weapon:
if equipment.versatile:
print(f'{slot}: {equipment.name} - {equipment.versatiledmg}\n'
f' {equipment.description}\n')
continue
elif equipment.damage1H is not None:
print(f'{slot}: {equipment.name} - {equipment.damage1H}\n'
f' {equipment.description}\n')
elif equipment.damage2H is not None:
print(f'{slot}: {equipment.name} - {equipment.damage2H}\n'
f' {equipment.description}\n')
elif equipment.itemType == ItemType.Armor:
print(f'{slot}: {equipment.name} - AC {equipment.ac}\n'
f' {equipment.description}\n')
elif equipment.itemType == ItemType.Item:
print(f'{slot}: {equipment.name}\n'
f' {equipment.description}\n')
def calc_weight():
pass

135
player.py
View File

@@ -1,8 +1,60 @@
from enum import Enum, auto import function_list
from random import randint from random import randint
from enum_list import *
import functions class Inventory:
def __init__(self):
self.items = []
def add_item(self, item):
self.items.append(item)
print(f"Added {item.name} to inventory.")
def remove_item(self, item):
if item in self.items:
self.items.remove(item)
print(f"Removed {item.name} from inventory.")
else:
print("Item not found in inventory.")
@staticmethod
def current_inventory():
"""Prints a list of items in your backpack that aren't equipped to your person."""
print(f'In your rucksack you have:')
for item_key, item_value in Inventory.items(): # string, dictionary
if item_key not in Equipment.values():
values = item_value.values() # make a variable of all values
values_list = list(values) # turn variable into a list
count_value = values_list[0] # take the first value from list - why?
print(f'{item_key.name} x {count_value}\n'
f' {item_key.description}\n')
@staticmethod
def current_equipment():
"""Prints a list of items that you have equipped in your slots."""
print(f'You are currently wearing:')
for slot, equipment in Equipment.items(): # string, dictionary
if equipment is not None:
if slot == "Attunement":
continue
elif equipment.itemType == ItemType.Weapon:
if equipment.versatile:
print(f'{slot}: {equipment.name} - {equipment.versatiledmg}\n'
f' {equipment.description}\n')
continue
elif equipment.damage1H is not None:
print(f'{slot}: {equipment.name} - {equipment.damage1H}\n'
f' {equipment.description}\n')
elif equipment.damage2H is not None:
print(f'{slot}: {equipment.name} - {equipment.damage2H}\n'
f' {equipment.description}\n')
elif equipment.itemType == ItemType.Armor:
print(f'{slot}: {equipment.name} - AC {equipment.ac}\n'
f' {equipment.description}\n')
elif equipment.itemType == ItemType.Item:
print(f'{slot}: {equipment.name}\n'
f' {equipment.description}\n')
class Player: class Player:
"""Character Creation""" """Character Creation"""
@@ -15,6 +67,11 @@ class Player:
self.age = age self.age = age
self.race = race self.race = race
self.job = job self.job = job
# Defence
self.ac = 0
self.elemental_resistance = {DamageType.Fire: False, DamageType.Water: False, DamageType.Lightning: False}
self.physical_resistance = {DamageType.Slashing: False, DamageType.Crushing: False, DamageType.Piercing: False}
# Health (move off Player, keep on Job) # Health (move off Player, keep on Job)
# self.hitDie = self.job.hd # self.hitDie = self.job.hd
# self.currentHP = 100 # self.currentHP = 100
@@ -23,16 +80,14 @@ class Player:
self.level = 1 self.level = 1
self.exp = 0 self.exp = 0
self.maxEXP = 100 self.maxEXP = 100
# Magic (Not ready yet) # Magic (Not ready yet)
# self.spells_known = [] # self.spells_known = []
# self.spells_ready = [] # self.spells_ready = []
# Equipment # Equipment
self.weapon = rock self.weapon = rock
self.armor = tornRags self.armor = tornRags
# Defence
self.ac = 0
self.elemental_resistance = {DamageType.Fire: False, DamageType.Water: False, DamageType.Lightning: False}
self.physical_resistance = {DamageType.Slashing: False, DamageType.Crushing: False, DamageType.Piercing: False}
# Ability Scores # Ability Scores
self.stats = {"Strength": 0, self.stats = {"Strength": 0,
"Dexterity": 0, "Dexterity": 0,
@@ -48,23 +103,7 @@ class Player:
"Wisdom": 0, "Wisdom": 0,
"Charisma": 0} "Charisma": 0}
# Held items # Held items
self.inventory = {rock: {"Count": 1, self.inventory = Inventory
"object": Weapon,
"equipped": True
},
paper: {"Count": 1,
"object": Weapon,
"equipped": False
},
tornRags: {"Count": 1,
"object": Armor,
"equipped": True
},
GP1: {"Count": 10,
"object": Money,
"equipped": False
},
}
def getModifier(self): def getModifier(self):
"""Floor calculation to work out skill check modifiers""" """Floor calculation to work out skill check modifiers"""
@@ -282,9 +321,9 @@ class Player:
self.getModifier() self.getModifier()
self.current_stats() self.current_stats()
print(' ') print(' ')
functions.current_equipment() function_list.current_equipment()
print(' ') print(' ')
functions.current_inventory() function_list.current_inventory()
print(' ') print(' ')
def health_check(self): def health_check(self):
@@ -371,57 +410,15 @@ class Player:
else: else:
continue continue
class DamageType(Enum):
Slashing = auto()
Crushing = auto()
Piercing = auto()
Fire = auto()
Water = auto()
Lightning = auto()
class DamageMod(Enum):
Strength = auto()
Dexterity = auto()
Constitution = auto()
Intelligence = auto()
Wisdom = auto()
Charisma = auto()
class ItemType(Enum):
Armor = auto()
Weapon = auto()
Money = auto()
Item = auto()
class Slots(Enum):
MainHand = auto()
OffHand = auto()
TwoHanded = auto()
Helm = auto()
Chest = auto()
Wrists = auto()
Feet = auto()
Neck = auto()
Cloak = auto()
LeftRing = auto()
RightRing = auto()
Other = auto()
Attunement = auto()
class Item: class Item:
"""The base class for all items""" """The base class for all items"""
def __init__(self, name, description, value, magical, ItemType, attunement): def __init__(self, name, description, value, magical, itemType, attunement):
self.name = name self.name = name
self.description = description self.description = description
self.value = value self.value = value
self.magical = magical self.magical = magical
self.itemType = ItemType self.itemType = itemType
self.attunement = attunement self.attunement = attunement
def __repr__(self): def __repr__(self):