-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathcreateMinedItemSummary.php
341 lines (291 loc) · 9.92 KB
/
createMinedItemSummary.php
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
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
<?php
if (php_sapi_name() != "cli") die("Can only be run from command line!");
require("/home/uesp/secrets/esolog.secrets");
require("esoCommon.php");
$TABLE_SUFFIX = "";
$MAKE_NAME_TITLECASE = true;
$FIELDS = array(
"name",
/*
"itemId",
"description",
"materialLevelDesc",
"style",
"trait",
"type",
"specialType", //Update13
"equipType",
"weaponType",
"armorType",
"craftType",
"bindType",
"isUnique",
"isUniqueEquipped",
"isVendorTrash",
"isArmorDecay",
"isConsumable",
"setName",
"abilityName",
"tags",
"dyeData",*/
"icon",
"enchantName",
);
$RANGE_FIELDS = array(
"level",
"quality",
"value",
"weaponPower",
"armorRating",
"abilityDesc",
"enchantDesc",
"maxCharges",
"glyphMinLevel",
"traitDesc",
"setBonusDesc1",
"setBonusDesc2",
"setBonusDesc3",
"setBonusDesc4",
"setBonusDesc5",
"setBonusDesc6",
"setBonusDesc7",
"setBonusDesc8",
"setBonusDesc9",
"setBonusDesc10",
"setBonusDesc11",
"setBonusDesc12",
);
// if (intval($TABLE_SUFFIX) <= 8) unset($FIELDS['tags']);
$dbRead = new mysqli($uespEsoLogReadDBHost, $uespEsoLogReadUser, $uespEsoLogReadPW, $uespEsoLogDatabase);
if ($dbRead->connect_error) exit("Could not connect to mysql database!");
$db = new mysqli($uespEsoLogWriteDBHost, $uespEsoLogWriteUser, $uespEsoLogWritePW, $uespEsoLogDatabase);
if ($db->connect_error) exit("Could not connect to mysql database!");
/* Old method
*
$query = "DROP TABLE minedItemSummaryTmp IF EXISTS;";
$result = $db->query($query);
$query = "CREATE TABLE IF NOT EXISTS minedItemSummaryTmp(
id BIGINT NOT NULL AUTO_INCREMENT,
itemId INTEGER NOT NULL,
name TINYTEXT NOT NULL,
allNames TEXT NOT NULL,
description TEXT NOT NULL,
materialLevelDesc TEXT NOT NULL,
style TINYINT NOT NULL DEFAULT -1,
trait TINYINT NOT NULL DEFAULT -1,
type TINYINT NOT NULL DEFAULT -1,
specialType SMALLINT NOT NULL DEFAULT -1,
equipType TINYINT NOT NULL DEFAULT -1,
weaponType TINYINT NOT NULL DEFAULT -1,
armorType TINYINT NOT NULL DEFAULT -1,
craftType TINYINT NOT NULL DEFAULT -1,
bindType TINYINT NOT NULL DEFAULT -1,
isUnique BIT NOT NULL DEFAULT 0,
isUniqueEquipped BIT NOT NULL DEFAULT 0,
isVendorTrash BIT NOT NULL DEFAULT 0,
isArmorDecay BIT NOT NULL DEFAULT 0,
isConsumable BIT NOT NULL DEFAULT 0,
icon TINYTEXT NOT NULL,
setName TINYTEXT NOT NULL,
enchantName TINYTEXT NOT NULL,
abilityName TINYTEXT NOT NULL,
level TINYTEXT NOT NULL,
value TINYTEXT NOT NULL,
quality TINYTEXT NOT NULL,
weaponPower TINYTEXT NOT NULL,
armorRating TINYTEXT NOT NULL,
abilityDesc TEXT NOT NULL,
enchantDesc TEXT NOT NULL,
traitDesc TINYTEXT NOT NULL,
traitAbilityDesc TINYTEXT NOT NULL,
setBonusDesc1 TEXT NOT NULL,
setBonusDesc2 TEXT NOT NULL,
setBonusDesc3 TEXT NOT NULL,
setBonusDesc4 TEXT NOT NULL,
setBonusDesc5 TEXT NOT NULL,
tags TINYTEXT NOT NULL,
dyeData TEXT NOT NULL,
actorCategory TINYINT NOT NULL,
PRIMARY KEY (id),
INDEX index_itemid (itemId),
INDEX index_style (style),
INDEX index_trait (trait),
INDEX index_type (type),
INDEX index_weapontype (weaponType),
INDEX index_armortype (armorType),
INDEX index_equiptype (equipType),
INDEX index_crafttype (craftType),
FULLTEXT(name, description, abilityName, abilityDesc, enchantName, enchantDesc, traitDesc, setName, setBonusDesc1, setBonusDesc2, setBonusDesc3, setBonusDesc4, setBonusDesc5, tags, allNames)
) ENGINE=MYISAM;";
$result = $db->query($query);
if (!$result) exit("ERROR: Database query error creating table!\n" . $db->error); */
/*
$result = $db->query("SELECT * FROM minedItemSummary$TABLE_SUFFIX;");
if (!$result) exit("ERROR: Database query error loading existing mined item summary table!\n" . $db->error);
$minedItemSummaries = array();
while ($row = $result->fetch_assoc())
{
$itemId = intval($row['itemId']);
$minedItemSummaries[$itemId] = $row;
} */
$FIRSTID = 3; // 1/2 are potion/poison data
$LASTID = 220000;
$MINSUBTYPE = 0; // Has problems with item enchantments missing
$MINSUBTYPE = 2;
$MAXSUBTYPE = 370;
for ($id = $FIRSTID; $id <= $LASTID; $id++)
{
if ($id % 100 == 0) print("Parsing Item $id...\n");
/*$minedItemSummary = $minedItemSummaries[$id];
if ($minedItemSummary == null)
{
$minedItemSummary = [];
$minedItemSummary['itemId'] = $id;
print("\tWarning: Found null mined\ItemSummary!\n");
} */
$query = "SELECT * FROM minedItem$TABLE_SUFFIX WHERE itemId=$id AND internalLevel=1 AND internalSubtype=$MINSUBTYPE LIMIT 1;";
$result = $dbRead->query($query);
if (!$result) exit("ERROR: Database query error (finding min item)!\n" . $db->error);
$minItemData = $result->fetch_assoc();
if (!$minItemData)
{
$query = "SELECT * FROM minedItem$TABLE_SUFFIX WHERE itemId=$id AND internalLevel=1 AND internalSubtype=1 LIMIT 1;";
$result = $dbRead->query($query);
if (!$result) exit("ERROR: Database query error (finding min item)!\n" . $db->error);
$minItemData = $result->fetch_assoc();
if (!$minItemData)
{
$query = "SELECT * FROM minedItem$TABLE_SUFFIX WHERE itemId=$id LIMIT 1;";
$result = $dbRead->query($query);
if (!$result) exit("ERROR: Database query error (finding min item v2)!\n" . $db->error);
$minItemData = $result->fetch_assoc();
}
if (!$minItemData) continue;
}
$query = "SELECT * FROM minedItem$TABLE_SUFFIX WHERE itemId=$id AND internalLevel=50 AND internalSubtype=$MAXSUBTYPE LIMIT 1;";
$result = $dbRead->query($query);
if (!$result) exit("ERROR: Database query error (finding max item)!\n" . $db->error);
$maxItemData = $result->fetch_assoc();
if (!$maxItemData)
{
$query = "SELECT * FROM minedItem$TABLE_SUFFIX where itemId=$id ORDER BY value DESC LIMIT 1;";
$result = $dbRead->query($query);
if (!$result) exit("ERROR: Database query error (finding max item v2)!\n" . $db->error);
$maxItemData = $result->fetch_assoc();
}
$allNames = array();
$query = "SELECT name from minedItem$TABLE_SUFFIX where itemId=$id;";
$result = $dbRead->query($query);
if (!$result) exit("ERROR: Database query error (finding all item names)!\n" . $db->error);
while (($row = $result->fetch_assoc()))
{
$name = $row['name'];
$allNames[$name] = 1;
}
$allNameValue = "";
foreach ($allNames as $name => $value)
{
$allNameValue .= $name . "\n";
}
$columns = array();
$values = array();
foreach ($FIELDS as $field)
{
$value = "";
if (array_key_exists($field, $minItemData))
{
//$value = $db->real_escape_string($minItemData[$field]);
$value = $minItemData[$field];
}
if ($field == "icon" && array_key_exists($field, $maxItemData))
{
//$value = $db->real_escape_string($maxItemData[$field]);
$value = $maxItemData[$field];
}
if ($value != "" && ($field == 'name' || $field == 'setName'))
{
$value = preg_replace("#Trifling #i", "", $value);
if ($MAKE_NAME_TITLECASE) $value = MakeEsoTitleCaseName($value);
}
$value = $db->real_escape_string($value);
$columns[] = $field;
$values[] = "'$value'";
}
foreach ($RANGE_FIELDS as $field)
{
$minValue = $minItemData[$field];
$maxValue = $maxItemData[$field];
if ($field == "level")
{
$minLevel = GetEsoItemLevelText($minValue);
$maxLevel = GetEsoItemLevelText($maxValue);
if ($maxLevel == null || $minLevel == $maxLevel)
$values[] = "'$maxLevel'";
else
$values[] = "'$minLevel-$maxLevel'";
}
elseif (is_numeric($minValue))
{
if ($minValue == null || $minValue == $maxValue)
$values[] = "'$minValue'";
else
$values[] = "'$minValue-$maxValue'";
}
else
{
//Grants a 3.0 point Damage Shield for 5.0 seconds
//Life Drain Deals 4.0 Magic Damage and heals you for 2.0.
//Increase weapon enchantment effect by 8.0%
$minNumbers = preg_split("/([0-9]+(?:\.[0-9])?)/s", $minValue, -1, PREG_SPLIT_DELIM_CAPTURE);
$maxNumbers = preg_split("/([0-9]+(?:\.[0-9])?)/s", $maxValue, -1, PREG_SPLIT_DELIM_CAPTURE);
$value = "";
for ($i = 0; $i < count($minNumbers); $i++)
{
$minBlock = $minNumbers[$i];
$maxBlock = $maxNumbers[$i];
if ($maxBlock == null) $maxBlock = $minBlock;
if (is_numeric($minBlock[0]))
{
if ($minBlock == $maxBlock)
$range = strval($minBlock);
else
$range = "$minBlock-$maxBlock";
$value .= $range;
}
else
{
$value .= $minBlock;
}
}
//print("\tMin: $minValue\n");
//print("\tMax: $maxValue\n");
//print("\tRange: $value\n");
$values[] = "'" . $db->real_escape_string($value) . "'";
}
$columns[] = $field;
}
$columns[] = "allNames";
$values[] = "'" . $db->real_escape_string($allNameValue) . "'";;
/*
$query = "INSERT INTO minedItemSummaryTmp(" . implode(",", $columns) . ") VALUES(" . implode(",", $values) . ");";
$result = $db->query($query);
if (!$result) print("ERROR: Database query error (writing item summary)!\n" . $db->error . "\nQuery=".$query . "\n");
*/
$querySets = [];
foreach ($columns as $i => $col)
{
$value = $values[$i];
$querySets[] = "$col=$value";
}
$query = "UPDATE minedItemSummary$TABLE_SUFFIX SET " . implode(",", $querySets) . " WHERE itemId='$id';";
$result = $db->query($query);
if (!$result) print("ERROR: Database query error (updating item summary)!\n" . $db->error . "\nQuery=".$query . "\n");
}
/*
$query = "DROP TABLE IF EXISTS minedItemSummary$TABLE_SUFFIX;";
$result = $db->query($query);
if (!$result) print("Error: Failed to delete table to minedItemSummary$TABLE_SUFFIX!\n{$db->error}");
$query = "RENAME TABLE minedItemSummaryTmp to minedItemSummary$TABLE_SUFFIX;";
$result = $db->query($query);
if (!$result) print("Error: Failed to rename temp table to minedItemSummary$TABLE_SUFFIX!\n{$db->error}");
*/