forked from Kage9951/Destiny2ItemManager
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathDestiny2Armor.py
203 lines (175 loc) · 6.44 KB
/
Destiny2Armor.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
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
import csv
class Armor:
def __init__(self):
self.perks = [] # Array to store perks
self.name = '' # init with blank name
self.total_rec_perks = 0 # Total amount of Rec perks
def Check_Perks(self, perk):
for x in self.perks: # Loop through perks on armor
if perk.lower() == x.lower(): # If matches input
return 1 # return true
return 0 # Otherwise return false
def Get_Total_Rec_Perks(self, perks):
for perk in perks: # Loop through array of perks from input
if self.Check_Perks(perk.perk): # Check for a match
self.total_rec_perks += perk.weight # increase total by weight
# Adding a weight system to Rec Perks
# Ex. Remote Connection, Pump Action has a weight of 2
# Precision Weapon Targeting, Ashes to Assets has a weight of 1
# Add the weight to self.total_rec_perks to prioritize what perks are wanted
# So a helm with Remote Connection, Pump Action is better than a helm with Remote Connection, Ashes to Assets
def Print_RecPerks(self, perks): # Just a function to print out armor and its rec perks
print(f" -{self.equippable}: {self.name}")
for perk in perks:
if self.Check_Perks(perk.perk):
print(f" {perk.perk}")
class PerkSets: # Allows for Custom Perks sets. May be replaced by weight system.
def __init__(self, x):
self._perks = x
self._count = 0
def Check(self, perks):
_perk_found = []
for perk in self._perks:
if perk in perks:
_perk_found.append(True)
else:
_perk_found.append(False)
if False in _perk_found:
return False
else:
self._count += 1
return True
class Perk:
def __init__(self, p, m, w):
self.perk = p
self.total = 0
self._min = 1
self.weight = w
self._item = {}
for x in ['Hunter', 'Warlock', 'Titan']:
for y in ['Helmet', 'Gauntlets', 'Chest Armor', 'Leg Armor']:
self._item.update({f'{x}-{y}': 0})
self._item.update({'Hunter-Hunter Cloak': 0,
'Warlock-Warlock Bond': 0,
'Titan-Titan Mark': 0
})
def Update(self, armor):
temp = armor.Check_Perks(self.perk)
self._item[f"{armor.equippable}-{armor.type}"] += temp
self.total += temp
def Get_Item_Status(self, key):
return self._item[key] < self._min
# For Max Power Changes
maxPower = 700
# This marks untagged gear at max power as infuse
# Get data from CSVs
# Get Perk Sets from CSV
perk_sets = []
with open('Perk_Sets.csv') as csvfile:
data = csv.reader(csvfile)
for row in data:
if row[0][0] != '#':
perk_sets.append(PerkSets(row))
perks = []
# Get Perks from CSV
with open('RecommendedPerks.csv') as csvfile:
data = csv.reader(csvfile)
for row in data:
if row[0][0] != '#':
perks.append(Perk(row[0], int(row[1]), int(row[2])))
# Get Armor from CSV
armor = []
with open('destinyArmor.csv', encoding='utf-8') as csvfile:
data = csv.reader(csvfile)
for row in data:
if (row[4] != 'Exotic'):
arm = Armor()
arm.name = row[0]
arm.hash = row[1]
arm.id = row[2]
arm.tag = row[3]
arm.tier = row[4]
arm.type = row[5]
arm.equippable = row[7]
arm.power = row[8]
arm.masterworkType = row[9]
arm.masterworkTier = row[10]
arm.mobility = row[19]
arm.recovery = row[20]
arm.resilience = row[21]
arm.notes = row[22]
for x in range(23, len(row)):
arm.perks.append(row[x].replace('*', ''))
if arm.tag not in ['Tag', 'favorite']:
arm.tag = None
arm.Get_Total_Rec_Perks(perks)
armor.append(arm)
# Update Existing Favorites
for arm in armor:
if arm.tag == 'favorite':
for perk in perks:
perk.Update(arm)
# Find Perks
maxLength = 0
# Find Keeps
for perk in perks:
print(f"\n{perk.perk}")
topArmor = {}
for x in ['Hunter', 'Warlock', 'Titan']:
for y in ['Helmet', 'Gauntlets', 'Chest Armor', 'Leg Armor']:
topArmor.update({f'{x}-{y}': [Armor()]})
topArmor.update({'Hunter-Hunter Cloak': [Armor()],
'Warlock-Warlock Bond': [Armor()],
'Titan-Titan Mark': [Armor()]
})
# Get armor with most rec perks for the current perk and add to the dict
for arm in armor:
if arm.tag != 'Tag': # Exclue header row
if arm.Check_Perks(perk.perk): # Check if current perk is on armor
key = f'{arm.equippable}-{arm.type}' # Create dict key
# if more rec perks then
if arm.total_rec_perks > topArmor[key][0].total_rec_perks:
topArmor[key] = []
topArmor[key].append(arm) # replace current piece
elif arm.total_rec_perks == topArmor[key][0].total_rec_perks:
topArmor[key].append(arm)
for key in topArmor:
for arm in topArmor[key]:
if arm.name != '':
arm.tag = 'keep'
for p in perks:
p.Update(arm)
arm.Print_RecPerks(perks)
# Find Perk Sets
maxLen = 0
for perk_set in perk_sets:
if len(str(perk_set._perks)) > maxLen: # Getting max length for formatting purposes
maxLen = len(str(perk_set._perks))
for arm in armor:
if perk_set.Check(arm.perks):
arm.tag = 'favorite'
for perk in perks:
perk.Update(arm)
# Mark infuse
for arm in armor:
if arm.power == maxPower and arm.tag == None:
arm.tag = 'infuse'
# Print Perk Sets
for perk_set in perk_sets:
x = maxLen - len(str(perk_set._perks))
print(f"{perk_set._perks}{' '*x} || {perk_set._count}")
# Export CSV
with open('DestinyArmorExport.csv', 'w', newline='') as csvfile:
data = csv.writer(csvfile)
for arm in armor:
data.writerow([
arm.hash,
arm.id,
arm.tag,
arm.notes
])
count = 0
for arm in armor:
if arm.tag in ['favorite', 'keep']:
count += 1
print(f"\nTotal Tagged Armor: {count}")