Update player.py

Updated Enum names for better usage.
Beginning to consider attunement ramifications.
Allocation for character creation is better formatted.
This commit is contained in:
KansaiGaijin
2022-10-30 14:43:47 +13:00
committed by GitHub
parent b9a7705f42
commit 0eba3e823e

View File

@@ -29,8 +29,8 @@ class Player:
self.armor = tornRags self.armor = tornRags
# Defence # Defence
self.ac = 0 self.ac = 0
self.elemental_resistance = {DamageType.FIRE: False, DamageType.WATER: False, DamageType.LIGHTNING: False} self.elemental_resistance = {DamageType.Fire: False, DamageType.Water: False, DamageType.Lightning: False}
self.physical_resistance = {DamageType.SLASHING: False, DamageType.CRUSHING: False, DamageType.PIERCING: 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,
@@ -280,9 +280,9 @@ class Player:
self.getModifier() self.getModifier()
self.current_stats() self.current_stats()
print(' ') print(' ')
self.current_equip() functions.current_equipment()
print(' ') print(' ')
self.current_inventory() functions.current_inventory()
print(' ') print(' ')
def health_check(self): def health_check(self):
@@ -299,12 +299,6 @@ class Player:
def allocation(self): def allocation(self):
while True: while True:
self.stats["Strength"] = 0
self.stats["Dexterity"] = 0
self.stats["Constitution"] = 0
self.stats["Intelligence"] = 0
self.stats["Wisdom"] = 0
self.stats["Charisma"] = 0
rolls = [] rolls = []
stats = [] stats = []
attributes = ["Strength", "Dexterity", "Constitution", "Intelligence", "Wisdom", "Charisma"] attributes = ["Strength", "Dexterity", "Constitution", "Intelligence", "Wisdom", "Charisma"]
@@ -331,16 +325,20 @@ class Player:
while len(stats) != 0: while len(stats) != 0:
input_text = input(">> ").title() input_text = input(">> ").title()
words = input_text.split() words = input_text.split()
if len(words) < 2:
if words[0] in stats and words[1] in attributes: if words[0] in stats and words[1] in attributes:
self.stats[words[1]] += int(words[0]) self.stats[words[1]] += int(words[0])
stats.remove(words[0]) stats.remove(words[0])
attributes.remove(words[1]) attributes.remove(words[1])
if len(stats) == 0: if len(stats) == 1:
self.stats[attributes[0]] += int(stats[0])
print("") print("")
break break
print("The remaining options are:\n") print(f"The remaining stats are:\n {', '.join(stats)}\n\n"
print(', '.join(stats)) f"The remaining attributes are:\n {', '.join(attributes)}")
print(', '.join(attributes)) else:
print("Error. Input was not recognised. Please try again with 'Number' + 'Attribute'.")
continue
else: else:
print("Error. Input was not recognised. Please try again with 'Number' + 'Attribute'.") print("Error. Input was not recognised. Please try again with 'Number' + 'Attribute'.")
continue continue
@@ -373,28 +371,28 @@ class Player:
class DamageType(Enum): class DamageType(Enum):
SLASHING = auto() Slashing = auto()
CRUSHING = auto() Crushing = auto()
PIERCING = auto() Piercing = auto()
FIRE = auto() Fire = auto()
WATER = auto() Water = auto()
LIGHTNING = auto() Lightning = auto()
class DamageMod(Enum): class DamageMod(Enum):
STRENGTH = auto() Strength = auto()
DEXTERITY = auto() Dexterity = auto()
CONSTITUTION = auto() Constitution = auto()
INTELLIGENCE = auto() Intelligence = auto()
WISDOM = auto() Wisdom = auto()
CHARISMA = auto() Charisma = auto()
class ItemType(Enum): class ItemType(Enum):
ARMOR = auto() Armor = auto()
WEAPON = auto() Weapon = auto()
MONEY = auto() Money = auto()
ITEM = auto() Item = auto()
class Slots(Enum): class Slots(Enum):
@@ -420,8 +418,7 @@ class Item:
self.description = description self.description = description
self.value = value self.value = value
self.magical = magical self.magical = magical
self.type = Item self.type = ItemType.Item
self.count = 1
def __repr__(self): def __repr__(self):
return f"{self.name}\n=====\n{self.description}\nValue: {self.value}\n" return f"{self.name}\n=====\n{self.description}\nValue: {self.value}\n"
@@ -434,7 +431,7 @@ class Money(Item):
self.name = name self.name = name
self.amt = amt self.amt = amt
self.magical = magical self.magical = magical
self.type = ItemType.MONEY self.type = ItemType.Money
super().__init__(name=self.name, super().__init__(name=self.name,
description=f"A small round coin made of {self.name.lower()} " description=f"A small round coin made of {self.name.lower()} "
f"with the imperial city logo stamped on the face.", f"with the imperial city logo stamped on the face.",
@@ -446,7 +443,7 @@ class Weapon(Item):
"""The base class for all weapons""" """The base class for all weapons"""
def __init__(self, name, description, value, slot, damage1H, damage2H, def __init__(self, name, description, value, slot, damage1H, damage2H,
dmgType, dmgMod, versatile, thrown, itemType, magical): dmgType, dmgMod, versatile, thrown, magical):
self.slot = slot self.slot = slot
self.damage1H = damage1H self.damage1H = damage1H
self.damage2H = damage2H self.damage2H = damage2H
@@ -454,7 +451,8 @@ class Weapon(Item):
self.dmgMod = dmgMod self.dmgMod = dmgMod
self.versatile = versatile self.versatile = versatile
self.thrown = thrown self.thrown = thrown
self.itemType = itemType self.itemType = ItemType.Weapon
self.attunement = False
super().__init__(name, description, value, magical) super().__init__(name, description, value, magical)
def __repr__(self): def __repr__(self):
@@ -463,20 +461,19 @@ class Weapon(Item):
f"\nValue: {self.value}" \ f"\nValue: {self.value}" \
f"\nDamage: One Handed - {self.damage1H}" \ f"\nDamage: One Handed - {self.damage1H}" \
f"\nDamage: Two Handed - {self.damage2H}" \ f"\nDamage: Two Handed - {self.damage2H}" \
f"\nDamage Type: {self.dmgType}" \ f"\nDamage Type: {self.dmgType.name.title()}" \
f"\nMagical: {self.magical}" f"\nMagical: {self.magical}"
class Armor(Item): class Armor(Item):
"""The base class for all armor""" """The base class for all armor"""
def __init__(self, name, description, value, grade, ac, disadvantage, dmgRes, def __init__(self, name, description, value, grade, ac, disadvantage, dmgRes, magical):
itemType, magical):
self.grade = grade self.grade = grade
self.ac = ac self.ac = ac
self.stealthDis = disadvantage self.stealthDis = disadvantage
self.dmgRes = dmgRes self.dmgRes = dmgRes
self.itemType = itemType self.itemType = ItemType.Armor
super().__init__(name, description, value, magical) super().__init__(name, description, value, magical)
def __repr__(self): def __repr__(self):
@@ -509,11 +506,10 @@ rock = Weapon(
slot=Slots.MainHand, slot=Slots.MainHand,
damage1H='1d6', damage1H='1d6',
damage2H=None, damage2H=None,
dmgType=DamageType.CRUSHING, dmgType=DamageType.Crushing,
dmgMod=DamageMod.STRENGTH, dmgMod=DamageMod.Strength,
versatile=False, versatile=False,
thrown=True, thrown=True,
itemType="Weapon",
magical=False magical=False
) )
@@ -524,11 +520,10 @@ dagger = Weapon(
slot=Slots.MainHand, slot=Slots.MainHand,
damage1H='1d6', damage1H='1d6',
damage2H=None, damage2H=None,
dmgType=DamageType.SLASHING, dmgType=DamageType.Slashing,
dmgMod=DamageMod.DEXTERITY, dmgMod=DamageMod.Dexterity,
versatile=False, versatile=False,
thrown=True, thrown=True,
itemType="Weapon",
magical=False magical=False
) )
@@ -540,7 +535,6 @@ tornRags = Armor(
ac=0, ac=0,
disadvantage=True, disadvantage=True,
dmgRes="None", dmgRes="None",
itemType="Armor",
magical=False magical=False
) )
paper = Item( paper = Item(
@@ -582,3 +576,4 @@ Equipment = {
"Right Ring": None, "Right Ring": None,
"Attunement": None "Attunement": None
} }