able to get compress JSON characters stored as cookies

This commit is contained in:
Zachary Watts
2026-04-29 01:25:10 -04:00
parent dad1a4c588
commit e6d19b1f69
12 changed files with 185 additions and 57 deletions

View File

@@ -1,4 +1,5 @@
#!/usr/bin/python3
import json
import random
from equipment import *
from spells import *
@@ -9,8 +10,9 @@ def roll_dice(count, sides):
# Player Character Classes
class Adventurer:
def __init__(self, level=1, attributes={}) -> None:
def __init__(self, c_id: int, level=1, attributes={}) -> None:
# using a get() method to pull an attribute else use a default value, https://python-academy.org/en/handbook/get
self.id = c_id
self.player_class = None
self.level = level
self.strength = attributes.get('strength', roll_dice(3,6))
@@ -42,7 +44,12 @@ class Adventurer:
def __str__(self):
return f"{self.player_class}"
def character_sheet(self):
def get_json(self):
char_dict = self.__dict__
char_json = json.dumps(char_dict)
return char_dict
def vertical_sheet(self):
sheet = []
sheet.append('{0: <28}'.format(f"| {self.player_class.title()} - Level {self.level}"))
for key, val in self.get_attributes().items():
@@ -124,13 +131,12 @@ class Fighter(Adventurer):
{ "level" : 13, "xp" : 720000, "hit-dice" : 9, "thac0" : 10, "saves" : { "death / poison" : 4, "wands" : 5, "paralysis / petrify" : 6, "breath attack" : 5, "spells / rods / staves" : 8 }},
{ "level" : 14, "xp" : 840000, "hit-dice" : 9, "thac0" : 10, "saves" : { "death / poison" : 4, "wands" : 5, "paralysis / petrify" : 6, "breath attack" : 5, "spells / rods / staves" : 8 }}
]
def __init__(self, level, attributes={}) -> None:
Adventurer.__init__(self, level, attributes)
def __init__(self, c_id, level, attributes={}) -> None:
Adventurer.__init__(self, c_id, level, attributes)
self.player_class = "fighter"
self.progression = Fighter.progression
self.hp = roll_dice(self.level, 8)
self.ac = armor[self.armor]
self.vertical_sheet = self.character_sheet()
class MagicUser(Adventurer):
prime_requisite = "intelligence"
@@ -167,8 +173,8 @@ class MagicUser(Adventurer):
13: { 1: 4, 2: 4, 3: 4, 4: 3, 5: 3, 6: 3 },
14: { 1: 4, 2: 4, 3: 4, 4: 4, 5: 3, 6: 3 }
}
def __init__(self, level, attributes={}) -> None:
Adventurer.__init__(self, level, attributes)
def __init__(self,c_id, level, attributes={}) -> None:
Adventurer.__init__(self, c_id, level, attributes)
self.player_class = "magic user"
self.progression = MagicUser.progression
self.hp = roll_dice(self.level, 4)
@@ -177,8 +183,6 @@ class MagicUser(Adventurer):
self.weapons = [ list(filter(lambda d: 'silver dagger' in d['name'],weapons))[0], { "name" : "" } ]
self.spells = MagicUser.spells[self.level]
self.spell_book = self.select_spells()
self.vertical_sheet = self.character_sheet()
class Cleric(Adventurer):
prime_requisite = "wisdom"
@@ -215,8 +219,8 @@ class Cleric(Adventurer):
13: { 1: 5, 2: 5, 3: 4, 4: 4, 5: 4 },
14: { 1: 6, 2: 5, 3: 5, 4: 5, 5: 4 }
}
def __init__(self, level, attributes={}) -> None:
Adventurer.__init__(self, level, attributes)
def __init__(self,c_id, level, attributes={}) -> None:
Adventurer.__init__(self, c_id, level, attributes)
self.player_class = "cleric"
self.progression = Cleric.progression
self.hp = roll_dice(self.level, 6)
@@ -228,7 +232,6 @@ class Cleric(Adventurer):
self.weapons = [ random.choice(self.possible_melee_weapons), random.choice(self.possible_weapons) ]
self.spells = Cleric.spells[self.level]
self.spell_book = self.select_spells()
self.vertical_sheet = self.character_sheet()
class Thief(Adventurer):
prime_requisite = "dexterity"
@@ -249,14 +252,13 @@ class Thief(Adventurer):
{ "level" : 13, "xp" : 640000, "hit-dice" : 9, "thac0" : 12, "saves" : { "death / poison" : 8, "wands" : 9, "paralysis / petrify" : 7, "breath attack" : 10, "spells / rods / staves" : 8 }},
{ "level" : 14, "xp" : 760000, "hit-dice" : 9, "thac0" : 12, "saves" : { "death / poison" : 8, "wands" : 9, "paralysis / petrify" : 7, "breath attack" : 10, "spells / rods / staves" : 8 }}
]
def __init__(self, level, attributes={}) -> None:
Adventurer.__init__(self, level, attributes)
def __init__(self,c_id, level, attributes={}) -> None:
Adventurer.__init__(self, c_id, level, attributes)
self.player_class = "thief"
self.progression = Fighter.progression
self.hp = roll_dice(self.level, 4)
self.armor = random.choice(list(armor.keys()))
self.ac = armor[self.armor]
self.vertical_sheet = self.character_sheet()
class Dwarf(Adventurer):
prime_requisite = "strength"
@@ -275,14 +277,13 @@ class Dwarf(Adventurer):
{ "level" : 11, "xp" : 530000, "hit-dice" : 9, "thac0" : 12, "saves" : { "death / poison" : 2, "wands" : 3, "paralysis / petrify" : 4, "breath attack" : 4, "spells / rods / staves" : 6 }},
{ "level" : 12, "xp" : 660000, "hit-dice" : 9, "thac0" : 12, "saves" : { "death / poison" : 2, "wands" : 3, "paralysis / petrify" : 4, "breath attack" : 4, "spells / rods / staves" : 6 }}
]
def __init__(self, level, attributes={}) -> None:
Adventurer.__init__(self, level, attributes)
def __init__(self,c_id, level, attributes={}) -> None:
Adventurer.__init__(self, c_id, level, attributes)
self.player_class = "dwarf"
self.progression = Dwarf.progression
self.hp = roll_dice(self.level, 8)
self.armor = random.choice(list(armor.keys()))
self.ac = armor[self.armor]
self.vertical_sheet = self.character_sheet()
class Elf(Adventurer):
prime_requisite = "intellgence"
@@ -311,8 +312,8 @@ class Elf(Adventurer):
9: { 1: 3, 2: 3, 3: 3, 4: 2, 5: 1, 6: '-'},
10: { 1: 3, 2: 3, 3: 3, 4: 3, 5: 2, 6: '-'}
}
def __init__(self, level, attributes={}) -> None:
Adventurer.__init__(self, level, attributes)
def __init__(self,c_id, level, attributes={}) -> None:
Adventurer.__init__(self, c_id, level, attributes)
self.player_class = "elf"
self.progression = Elf.progression
self.hp = roll_dice(self.level, 6)
@@ -320,7 +321,6 @@ class Elf(Adventurer):
self.ac = armor[self.armor]
self.spells = Elf.spells[self.level]
self.spell_book = self.select_spells()
self.vertical_sheet = self.character_sheet()
class Halfling(Adventurer):
prime_requisite = "dexterity"
@@ -335,11 +335,10 @@ class Halfling(Adventurer):
{ "level" : 7, "xp" : 64000, "hit-dice" : 7, "thac0" : 14, "saves" : { "death / poison" : 4, "wands" : 5, "paralysis / petrify" : 6, "breath attack" : 7, "spells / rods / staves" : 8 }},
{ "level" : 8, "xp" : 120000, "hit-dice" : 8, "thac0" : 14, "saves" : { "death / poison" : 4, "wands" : 5, "paralysis / petrify" : 6, "breath attack" : 7, "spells / rods / staves" : 8 }},
]
def __init__(self, level, attributes={}) -> None:
Adventurer.__init__(self, level, attributes)
def __init__(self,c_id, level, attributes={}) -> None:
Adventurer.__init__(self, c_id, level, attributes)
self.player_class = "halfling"
self.progression = Halfling.progression
self.hp = roll_dice(self.level, 6)
self.armor = random.choice(list(armor.keys()))
self.ac = armor[self.armor]
self.vertical_sheet = self.character_sheet()