Last active
April 26, 2019 02:52
-
-
Save joaoescribano/214a7b335347f68e2e504903b9bd83e4 to your computer and use it in GitHub Desktop.
Sphere Server Script Pack item crawler [Ultima Online]
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
$scriptFolder = "../script-original/"; | |
$scriptFiles = glob("{$scriptFolder}*.scp"); | |
$scriptFiles = array_merge($scriptFiles, glob("{$scriptFolder}/*/*.scp")); | |
$scriptFiles = array_merge($scriptFiles, glob("{$scriptFolder}/*/*/*.scp")); | |
$scriptFiles = array_merge($scriptFiles, glob("{$scriptFolder}/*/*/*/*.scp")); | |
$scriptFiles = array_merge($scriptFiles, glob("{$scriptFolder}/*/*/*/*/*.scp")); | |
$scriptFiles = array_merge($scriptFiles, glob("{$scriptFolder}/*/*/*/*/*/*.scp")); | |
$scriptFiles = array_merge($scriptFiles, glob("{$scriptFolder}/*/*/*/*/*/*/*.scp")); | |
$scriptFiles = array_merge($scriptFiles, glob("{$scriptFolder}/*/*/*/*/*/*/*/*.scp")); | |
$items = []; | |
$sectionList = ['[ITE', 'ON=@', '[FUN', '[TYP','[MUL','[PLE','[DIA','[EOF','[DEF','[COM','[EVE','[MEN','[SKI','[ARE','[ROO','[STA','[MOO','[TEL','[CHA','[TEM','[SPE','[NAM','[NEW','[REG','[ADV','[SPA','[RES','[OBS','[FAM','[KAR','[NOT','[RUN']; | |
foreach ($scriptFiles as $fileKey => $fileSrc) { | |
$file = fopen($fileSrc, "r"); | |
/* Crawler memory */ | |
$foundItemHeader = false; | |
$lastItemData = null; | |
while(!feof($file)) { | |
$line = fgets($file); | |
$lineTest = mb_strtoupper(trim($line)); | |
if (empty(trim($line)) || substr($lineTest, 0, 2) == "//") { | |
continue; | |
} | |
if ($foundItemHeader && in_array(substr($lineTest, 0, 4), $sectionList)) { | |
$items[] = $lastItemData; | |
$lastItemData = null; | |
$foundItemHeader = false; | |
} | |
if (substr($lineTest, 0, 9) == "[ITEMDEF ") { | |
$foundItemHeader = true; | |
} | |
if ($foundItemHeader) { | |
$lastItemData .= $line; | |
} | |
} | |
fclose($file); | |
} | |
echo "Total item found: " . count($items) . "\nNow filtering and processing items into objects\n"; | |
/* Now start to read item properties */ | |
$filteredItems = []; | |
foreach ($items as $itemKey => $item) { | |
$lines = explode("\n", $item); | |
$itemTmp = new stdClass(); | |
$itemTmp->real_id = null; | |
foreach ($lines as $lineKey => $line) { | |
if (strstr($line, "//")) { | |
$line = trim(explode("//", $line)[0]); | |
} | |
if ($lineKey == 0) { | |
$tmp = str_replace(["[ITEMDEF ", "]"], ["",""], $line); | |
if (substr($tmp, 0, 1) == "m"){ | |
continue 2; | |
} | |
$itemTmp->real_id = str_replace(["\n", "\r", "\t", "[itemdef "], ["","","",""], $tmp); | |
} else { | |
$tmp = explode("=", $line); | |
if (count($tmp) == 2) { | |
$prop = mb_strtolower(trim($tmp[0])); | |
$val = mb_strtolower(trim($tmp[1])); | |
$itemTmp->$prop = $val; | |
} | |
} | |
} | |
if (isset($filteredItems[$itemTmp->real_id])) { | |
echo "Item '" . trim($itemTmp->real_id) . "' already exists\n"; | |
unset($filteredItems[$itemTmp->real_id]); | |
continue; | |
} | |
$filteredItems[$itemTmp->real_id] = $itemTmp; | |
} | |
echo "Remaining items: " . count($filteredItems) . "\n"; | |
file_put_contents("item_filtered.php", "<?php\n\$items = " . var_export($filteredItems, true) . ";"); | |
echo "Sorting item types\n"; | |
$types = ['no_type' => []]; | |
foreach ($filteredItems as $itemRealId => $item) { | |
if (!empty($item->type)) { | |
if (!isset($types[$item->type])) { | |
$types[$item->type] = []; | |
} | |
$types[$item->type][] = $itemRealId; | |
} else { | |
$types["no_type"][] = $itemRealId; | |
} | |
} | |
echo "Sorting craftable items\n"; | |
$craftables = []; | |
foreach ($filteredItems as $itemRealId => $item) { | |
if (!empty($item->type) && !empty($item->resources) && !empty($item->skillmake)) { | |
if (!isset($craftables[$item->type])) { | |
$craftables[$item->type] = []; | |
} | |
$craftables[$item->type][] = $itemRealId; | |
} | |
} | |
file_put_contents("item_craftable_by_type.php", "<?php\n\$craftables = " . var_export($craftables, true) . ";"); | |
echo "All done, files created.\n\n"; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment