-
Notifications
You must be signed in to change notification settings - Fork 0
/
Weapon.py
93 lines (82 loc) · 2.95 KB
/
Weapon.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
import sqlite3
import os
def get_weapon_stats(weapon, level):
if os.path.exists("./Data/weapon_stats.db"):
connection = sqlite3.connect("./Data/weapon_stats.db")
else:
raise FileNotFoundError("/Data/weapon_stats.db was not found.")
sqlCommand = f"""SELECT * FROM {weapon} WHERE level = {level};"""
cursor = connection.cursor()
cursor.execute(sqlCommand)
return cursor.fetchall()[0]
def get_weapon_info(weapon):
if os.path.exists("./Data/weapon_info.db"):
connection = sqlite3.connect("./Data/weapon_info.db")
else:
raise FileNotFoundError("/Data/weapon_info.db was not found.")
sqlCommand = f"""SELECT * FROM WEAPONS WHERE internal_name = "{weapon}";"""
cursor = connection.cursor()
cursor.execute(sqlCommand)
return cursor.fetchall()[0]
def get_weapon_from_id(id):
if os.path.exists("./Data/weapon_info.db"):
connection = sqlite3.connect("./Data/weapon_info.db")
else:
return
sqlCommand = f"""SELECT * FROM WEAPONS WHERE id = "{id}";"""
cursor = connection.cursor()
cursor.execute(sqlCommand)
return cursor.fetchall()[0][1]
def get_max_level(weapon):
if os.path.exists("./Data/weapon_stats.db"):
connection = sqlite3.connect("./Data/weapon_stats.db")
else:
raise FileNotFoundError("/Data/weapon_stats.db was not found.")
sqlCommand = f"""SELECT level FROM {weapon};"""
cursor = connection.cursor()
cursor.execute(sqlCommand)
return cursor.fetchall()[-1][0]
class Weapon():
internal_name = ""
display_name = ""
type = ""
description = ""
def __init__(self, weapon, level):
details = get_weapon_info(weapon)
if type(details) != tuple:
raise TypeError
self.id = details[0]
self.level = level
self.internal_name = details[1]
self.display_name = details[2]
self.type = details[3]
self.stats = {}
affected_stats = details[4].split(",")
stats = get_weapon_stats(weapon, level)[2].split(":")
for i,stat in enumerate(affected_stats):
self.stats.update({stat: f"{stats[i]}"})
self.description = details[6]
percentages = list(self.stats.values())
if len(percentages) > 1:
percentages = f"{'%, '.join(percentages[:-1])}% and {percentages[-1]}%"
else:
percentages = f"{percentages[0]}%"
self.description = self.description.replace("{percent}", percentages)
def can_upgrade(self, player):
if self.max_level():
return 6
if player.th < self.level:
return 4
cost = get_weapon_stats(self.internal_name, self.level+1)[1].split(":")
if player.gold < int(cost[0]) or player.weapon_ore < int(cost[1]):
return 5
return 3
def level_up(self, player, levels=1):
for i in range(levels):
cost = get_weapon_stats(self.internal_name, self.level+i+1)[1].split(":")
player.gold -= int(cost[0])
player.weapon_ore -= int(cost[1])
self.level += levels
self = self.__init__(self.internal_name, self.level)
def max_level(self):
return self.level >= get_max_level(self.internal_name)