-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathskills_panel.py
159 lines (123 loc) · 6.89 KB
/
skills_panel.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
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
import tkinter as tk
from functools import partial
import file_helper
import settings as st
import view_helper as vh
import stat_helper
import skills_module
class SkillsPanel:
def __init__(self, parent, cont):
self.frame = tk.Frame(parent, bg=st.base_bg)
self.cont = cont
norm_font = st.norm_font
melee_header = tk.Label(self.frame, text="Melee", font=norm_font, fg=st.label_text, bg=st.base_bg)
magic_header = tk.Label(self.frame, text="Magic", font=norm_font, fg=st.label_text, bg=st.base_bg)
defensive_header = tk.Label(self.frame, text="Defense", font=norm_font, fg=st.label_text, bg=st.base_bg)
other_header = tk.Label(self.frame, text="Other", font=norm_font, fg=st.label_text, bg=st.base_bg)
# warning, do not change the labels
offensive_labels = ['heavy weapons', 'light weapons', 'finesse weapons', 'two handed combat', 'missile weapons']
magic_labels = ['war magic', 'life magic', 'creature enchantment', 'item enchantment', 'void magic']
defensive_labels = ['melee defense', 'missile defense', 'magic defense']
other_labels = ['sneak attack', 'dirty fighting', 'dual wield', 'deception', 'shield', 'run']
self.offensive_entries = vh.make_int_entry(self.frame, offensive_labels)
self.magic_entries = vh.make_int_entry(self.frame, magic_labels)
self.defensive_entries = vh.make_int_entry(self.frame, defensive_labels)
self.other_entries = vh.make_int_entry(self.frame, other_labels)
# ** is dictionary unpacking, helps merge multiple dictionaries into a single dictionary
self.all_entries = {
**self.offensive_entries, **self.magic_entries, **self.defensive_entries, **self.other_entries
}
set_button = tk.Button(self.frame, text="Set", bg=st.button_bg, command=self.set_skills)
batch_button = tk.Button(self.frame, text="Run Batch",
command=partial(self.cont.run_sql_batch, self.set_skills))
tooltip = ("All fields optional. Set attributes first and enter desired skill levels. "
"Entire skill table is replaced so anything left blank will be deleted. "
)
tooltip_label = tk.Label(self.frame, text=tooltip, font=norm_font, fg="dark green", wraplength=420,
justify=tk.LEFT, bg=st.base_bg)
# layout
r = 0
c = 0
headers = [melee_header, magic_header, defensive_header, other_header]
content = [self.offensive_entries, self.magic_entries, self.defensive_entries, self.other_entries]
buttons = [set_button, batch_button]
for i in range(len(headers)):
headers[i].grid(row=r, column=c, sticky='w')
r += 1
for name, entry in content[i].items():
label = tk.Label(self.frame, text=name, font=norm_font, bg=st.base_bg)
label.grid(row=r, column=c)
entry.grid(row=r, column=c + 1)
r += 1
for button in buttons:
button.grid(row=r, column=c, padx=5, pady=5, sticky="ew")
r += 1
tooltip_label.grid(row=r, column=c, columnspan=2)
r += 1
def check_parameters(self):
"""Check attributes, base, effective, and pcap skills."""
if self.cont.sql_commands is not None:
# clear existing
for name, entry in self.all_entries.items():
entry.delete(0, tk.END) # delete existing
attributes = stat_helper.get_all_attributes(self.cont.sql_commands)
skills = skills_module.get_skill_table(self.cont.sql_commands)
if skills: # false if the skill list is empty
self.cont.view.console.print("\nCurrent Effective Skills\n", "purple")
for skill in skills:
attribute_bonus = skills_module.get_attribute_bonus(attributes, skill.name)
effective_value = skill.value + attribute_bonus
self.cont.view.console.print(skill.name + "\t" + str(effective_value) + "\n")
for name, entry in self.all_entries.items():
name = name.title().replace(" ", "")
if name == skill.name:
entry.insert(0, str(effective_value)) # insert new
self.cont.view.console.print("\nPCAP Effective Skills (mean [min, max])\n", "purple")
pcap_skills = self.get_skill_pcap()
for name, v in pcap_skills.items():
if "defense" in name:
self.cont.view.console.print(
str(name) + "\t" + str(v[0]) + " [" + str(v[1]) + ", " + str(v[2]) + "]\n", "brown"
)
else:
self.cont.view.console.print(
str(name) + "\t" + str(v[0]) + " [" + str(v[1]) + ", " + str(v[2]) + "]\n"
)
else:
self.cont.file_warning()
def get_skill_pcap(self):
if self.cont.sql_commands is not None:
name = file_helper.get_name(self.cont.sql_commands)
pcap_skills = skills_module.skill_look_up(name)
return pcap_skills
def set_skills(self):
if self.cont.sql_commands is not None:
wcid = file_helper.get_wcid(self.cont.sql_commands)
attributes = stat_helper.get_all_attributes(self.cont.sql_commands)
skills = {}
# k = skill name , v = skill value
for k, v in self.all_entries.items():
val = v.get() # skill value entered in the skill panel
if val != "":
effective_int = int(val)
label = k.title().replace(" ", "") # for example, "life magic" becomes "LifeMagic"
attribute_bonus = skills_module.get_attribute_bonus(attributes, label)
base_int = effective_int - attribute_bonus # adjust down by attribute bonus to get base skill value
if base_int <= 0:
base_int = 1
skill_name = k.title().replace(" ", "")
skills[skill_name] = base_int
# make the skill table
new_command = skills_module.make_skill_table(wcid, skills)
my_list = []
# delete if already there
for command in self.cont.sql_commands:
if str("`weenie_properties_skill`") in command:
pass
else:
if command.strip() != "":
my_list.append(command)
my_list.append(new_command)
self.cont.sql_commands = my_list
else:
self.cont.file_warning()