Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
48 changes: 47 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
.idea
PyRPG_Mini.iml
markdown-navigator.xml
misc.xml
Expand All @@ -7,3 +6,50 @@ vcs.xml
workspace.xml
markdown-navigator
inspectionProfiles

# Byte-compiled / optimized / DLL files
__pycache__/
*.py[cod]
*$py.class

# csv-files
*.csv

# certificates
*.crt

# PyCharm
.idea/

# Distribution / packaging
.Python
build/
develop-eggs/
dist/
downloads/
eggs/
.eggs/
lib/
lib64/
parts/
sdist/
var/
wheels/
share/python-wheels/
*.egg-info/
.installed.cfg
*.egg
MANIFEST

# Translations
*.mo
*.pot

# Environments
.env
.venv
env/
venv/
ENV/
env.bak/
venv.bak/
138 changes: 78 additions & 60 deletions Armor.py
Original file line number Diff line number Diff line change
@@ -1,112 +1,130 @@
import Game
import random
from texttools import *


class ArmorType:
OUTFIT = 'outfit'
PLATE = 'plate'
ROBE = 'robe'


class ArmorQuality:
RUSTY = 'rusty'
COMMON = 'common'
GREAT = 'great'
MAGICAL = 'magical'
LEGENDARY = 'legendary'


class Armor:
# level,classtype,name,type,basedef,durability
def __init__(self, armorlevel, armorclasstype, armorname, armortype, armorbasedef, armordur):
def __init__(self,
armor_level: int,
armor_class_type: str,
armor_name: str,
armor_type: ArmorType,
armor_base_def: int,
armor_dur: int):
# level
self.level = armorlevel
self.level: int = armor_level

# hero Class
self.classtype = armorclasstype
self.class_type: str = armor_class_type

# hero Class
self.type = armortype
self.name = armorname
self.type: ArmorType = armor_type
self.name: str = armor_name

# Armor Quality (rusty, common, great, magical, legendary)
chance = random.randint(1, 100)
chance: int = random.randint(1, 100)

if chance < 20:
self.quality = 'Rusty'
self.quality = ArmorQuality.RUSTY
elif chance >= 21 or chance < 65:
self.quality = 'Common'
self.quality = ArmorQuality.COMMON
elif chance >= 66 or chance < 86:
self.quality = 'Great'
self.quality = ArmorQuality.GREAT
elif chance >= 85 or chance < 96:
self.quality = 'Magical'
self.quality = ArmorQuality.MAGICAL
elif chance >= 96 or chance < 100:
self.quality = 'Legendary'
self.quality = ArmorQuality.LEGENDARY

# Defense Values
self.basedefn = armorbasedef
self.base_defn = armor_base_def
if self.quality == 'Rusty':
self.basedefn = int(self.basedefn * 0.9)
self.base_defn = int(self.base_defn * 0.9)
elif self.quality == 'Common':
self.basedefn = int(self.basedefn * 1)
self.base_defn = int(self.base_defn * 1)
elif self.quality == 'Great':
self.basedefn = int(self.basedefn * 1.25)
self.base_defn = int(self.base_defn * 1.25)
elif self.quality == 'Magical':
self.basedefn = int(self.basedefn * 1.6)
self.base_defn = int(self.base_defn * 1.6)
elif self.quality == 'Legendary':
self.basedefn = int(self.basedefn * 2)
self.base_defn = int(self.base_defn * 2)

self.defn = self.basedefn
self.defn = self.base_defn

# armor durability value
self.maxdur = armordur
self.max_dur = armor_dur
if self.quality == 'Rusty':
self.maxdur = int(self.maxdur * 0.9)
self.max_dur = int(self.max_dur * 0.9)
elif self.quality == 'Common':
self.maxdur = int(self.maxdur * 1)
self.max_dur = int(self.max_dur * 1)
elif self.quality == 'Great':
self.maxdur = int(self.maxdur * 1.25)
self.max_dur = int(self.max_dur * 1.25)
elif self.quality == 'Magical':
self.maxdur = int(self.maxdur * 1.6)
self.max_dur = int(self.max_dur * 1.6)
elif self.quality == 'Legendary':
self.maxdur = int(self.maxdur * 2)
self.dur = self.maxdur
self.max_dur = int(self.max_dur * 2)
self.dur = self.max_dur

# damage durability, and check to see if broken
def damagedur(self, aug, curve):
def damage_dur(self, aug, curve) -> None:
self.dur -= int(aug * curve * .1)
self.isbroken()
pass
self.is_broken()

# restore dur and check to see if fixed
def restoredur(self, aug):
def restore_dur(self, aug) -> None:
self.dur += aug
if self.dur > self.maxdur:
self.dur = self.maxdur
if not self.isbroken():
self.defn = self.basedefn
if self.dur > self.max_dur:
self.dur = self.max_dur
if not self.is_broken():
self.defn = self.base_defn

# repair entirely
def repair(self):
self.defn = self.basedefn
self.dur = self.maxdur
def repair(self) -> None:
self.defn = self.base_defn
self.dur = self.max_dur

# 15% durability = stat reduction
def isbroken(self):
def is_broken(self) -> bool:
if self.dur <= 0:
self.gearbreak()
self.gear_break()
return True
elif self.dur > 0:
return False
return False

# this breaks the gear
def gearbreak(self):
self.atk = int(self.basedefn * .3)
def gear_break(self) -> None:
# Possible FixMe: self.atk seems to serve no purpose
self.atk = int(self.base_defn * .3)

# prints all armor info
def printarmorinfo(self):
Game.marqueeprint('ARMOR')
print(Game.lr_justify('Level:', str(self.level), 60))
print(Game.lr_justify('Name:', str(self.name), 60))
print(Game.lr_justify('Type:', str(self.type), 60))
print(Game.lr_justify('Defense:', str(self.defn) + '/' + str(self.basedefn), 60))
print(Game.lr_justify('Dur:', str(self.dur) + '/' + str(self.maxdur), 60))
print(Game.lr_justify('Broken?:', str(self.isbroken()), 60))
print(Game.lr_justify('Quality:', str(self.quality()), 60))

# ['Level', 'Name', 'Type', 'Defense', 'Dur', 'Broken?', 'Power']
def datadict(self):
def print_armor_info(self) -> None:
marqueeprint('ARMOR')
print(lr_justify('Level:', str(self.level), 60))
print(lr_justify('Name:', str(self.name), 60))
print(lr_justify('Type:', str(self.type), 60))
print(lr_justify('Defense:', str(self.defn) + '/' + str(self.base_defn), 60))
print(lr_justify('Dur:', str(self.dur) + '/' + str(self.max_dur), 60))
print(lr_justify('Broken?:', 'Yes' if self.is_broken() else 'No', 60))
print(lr_justify('Quality:', str(self.quality), 60))

# {'Level', 'Name', 'Type', 'Defense', 'Dur', 'Broken?', 'Power'}
def datadict(self) -> dict:
return {'Level': str(self.level),
'Name': str(self.name) + ' ' + str(self.type),
'Name': f'{self.name} {self.type}',
'Def': str(self.defn),
'Dur': str(self.dur) + '/' + str(self.maxdur),
'Broken?': str(self.isbroken()),
'Repair Cost': str(self.maxdur - self.dur) + ' gold',
'Dur': f'{self.dur} / {self.max_dur}',
'Broken?': str(self.is_broken()),
'Repair Cost': f'{str(self.max_dur - self.dur)} gold',
'Quality': str(self.quality)
}
53 changes: 29 additions & 24 deletions dbsetup.py → Database.py
Original file line number Diff line number Diff line change
@@ -1,24 +1,25 @@
import csv
import os
from sqlite3 import connect
from texttools import centerprint

import Game


class dbsetup():
class Database:
def __init__(self):
self.dbpath = './db/game.db'
self.db_path: str = './db/game.db'
# import and create our player database
self.gamedb = connect(self.dbpath)
self.conn = self.gamedb.cursor()
self.game_db = connect(self.db_path)
self.conn = self.game_db.cursor()

# used to delete the current database
def deletedbifexists(self):
@staticmethod
def delete_db_if_exists() -> None:
if os.path.exists('./db/game.db'):
os.remove('./db/game.db')

def setupdb(self):
# If you set this to 1, it will print out all data as it populates the datbase.
@staticmethod
def setup_db():
# If you set this to 1, it will print out all data as it populates the database.
debugging = 0

# make a database connection to the game database
Expand All @@ -35,7 +36,8 @@ def setupdb(self):
if debugging:
print('creating table for armor')
cur.execute(
'''CREATE TABLE IF NOT EXISTS armor (level INTEGER, class TEXT, name TEXT, type TEXT, basedef INTEGER, durability INTEGER)''')
'CREATE TABLE IF NOT EXISTS armor '
'(level INTEGER, class TEXT, name TEXT, type TEXT, base_def INTEGER, durability INTEGER)')

# insert our armor table in the database
if debugging:
Expand All @@ -56,7 +58,9 @@ def setupdb(self):
if debugging:
print('creating table for enemies')
cur.execute(
'''CREATE TABLE IF NOT EXISTS enemies(level INT, firstname TEXT, middlename TEXT, lastname TEXT, attack INTEGER, xp INTEGER, gold INTEGER, hp INTEGER, def INTEGER, status TEXT)''')
'CREATE TABLE IF NOT EXISTS enemies '
'(level INT, firstname TEXT, middlename TEXT, lastname TEXT, attack INTEGER, '
'xp INTEGER, gold INTEGER, hp INTEGER, def INTEGER, status TEXT)')

# insert our enemy table in the database
if debugging:
Expand All @@ -73,13 +77,13 @@ def setupdb(self):
for row in rows:
print('QUERY ALL: ' + str(row))

# create our items table in the database
# create our item's table in the database
if debugging:
print('creating table for items')
cur.execute(
'''CREATE TABLE IF NOT EXISTS items(level INT, grade INT,name TEXT,effect INT,value INT)''')
'CREATE TABLE IF NOT EXISTS items(level INT, grade INT,name TEXT,effect INT,value INT)')

# insert our items table in the database
# insert our item's table in the database
if debugging:
print('inserting items into database')
with open('./csv/items.csv', 'r') as fin:
Expand All @@ -94,15 +98,15 @@ def setupdb(self):
for row in rows:
print('QUERY ALL: ' + str(row))

# create our levelnotes table in the database
# create our level notes table in the database
if debugging:
print('creating table for levelnotes')
print('creating table for level notes')
cur.execute(
'''CREATE TABLE IF NOT EXISTS levelnotes(Level INT,HP INT,ATK INT,DEF INT,xptonextlevel INT, dodge INT )''')
'CREATE TABLE IF NOT EXISTS levelnotes(Level INT,HP INT,ATK INT,DEF INT,xptonextlevel INT, dodge INT )')

# insert our levelnotes table in the database
# insert our level notes table in the database
if debugging:
print('inserting levelnotes into database')
print('inserting level notes into database')
with open('./csv/levelnotes.csv', 'r') as fin:
dr = csv.reader(fin)
for i in dr:
Expand All @@ -115,13 +119,13 @@ def setupdb(self):
for row in rows:
print('QUERY ALL: ' + str(row))

# create our shields table in the database
# create our shield's table in the database
if debugging:
print('creating table for shields')
cur.execute(
'''CREATE TABLE IF NOT EXISTS shields (level INT,class TEXT,name TEXT,type TEXT,basedef INT,durability INT)''')
'CREATE TABLE IF NOT EXISTS shields (level INT,class TEXT,name TEXT,type TEXT,base_def INT,durability INT)')

# insert our shields table in the database
# insert our shield's table in the database
if debugging:
print('inserting shields into database')
with open('./csv/shields.csv', 'r') as fin:
Expand All @@ -140,7 +144,8 @@ def setupdb(self):
if debugging:
print('creating table for weapons')
cur.execute(
'''CREATE TABLE IF NOT EXISTS weapons ( level INTEGER ,class TEXT ,name TEXT ,type TEXT,baseattack INTEGER ,durability INTEGER ,power TEXT)''')
'CREATE TABLE IF NOT EXISTS weapons '
'(level INTEGER ,class TEXT ,name TEXT ,type TEXT,baseattack INTEGER ,durability INTEGER ,power TEXT)')

# insert our weapons table in the database
if debugging:
Expand Down Expand Up @@ -181,4 +186,4 @@ def setupdb(self):
conn.commit()
# close the database connection to let other operations use it
conn.close()
Game.centerprint('...Have fun')
centerprint('...Have fun')
Loading