<?php
require_once 'engine/init.php';
include 'layout/overall/header.php';
// Función para obtener los tipos de combate de un archivo script
//function getCombatTypes($fullPath) {
// if (file_exists($fullPath)) {
// $content = file_get_contents($fullPath);
// $combatTypes = [];
// Buscar COMBAT_PARAM_TYPE
// if (preg_match('/combat:setParameter\(\s*COMBAT_PARAM_TYPE\s*,\s*(COMBAT_[A-Z]+)\s*\)/', $content, $matches)) {
// $combatTypes[] = $matches[1];
// }
// Buscar COMBAT_PARAM_EFFECT
// if (preg_match('/combat:setParameter\(\s*COMBAT_PARAM_EFFECT\s*,\s*(CONST_ME_[A-Z_]+)\s*\)/', $content, $matches)) {
// $combatTypes[] = $matches[1];
// }
// Buscar otros indicadores si no se encontró nada
// if (empty($combatTypes)) {
// if (strpos($content, 'COMBAT_HEALING') !== false) {
// $combatTypes[] = 'COMBAT_HEALING';
// }
// if (strpos($content, 'COMBAT_MANADRAIN') !== false) {
// $combatTypes[] = 'COMBAT_MANADRAIN';
// }
// if (strpos($content, 'COMBAT_LIFEDRAIN') !== false) {
// $combatTypes[] = 'COMBAT_LIFEDRAIN';
// }
// if (strpos($content, 'COMBAT_ENERGYDAMAGE') !== false) {
// $combatTypes[] = 'COMBAT_ENERGYDAMAGE';
// }
// if (strpos($content, 'COMBAT_EARTHDAMAGE') !== false) {
// $combatTypes[] = 'COMBAT_EARTHDAMAGE';
// }
// if (strpos($content, 'COMBAT_FIREDAMAGE') !== false) {
// $combatTypes[] = 'COMBAT_FIREDAMAGE';
// }
// if (strpos($content, 'COMBAT_ICEDAMAGE') !== false) {
// $combatTypes[] = 'COMBAT_ICEDAMAGE';
// }
// if (strpos($content, 'COMBAT_HOLYDAMAGE') !== false) {
// $combatTypes[] = 'COMBAT_HOLYDAMAGE';
// }
// if (strpos($content, 'COMBAT_DEATHDAMAGE') !== false) {
// $combatTypes[] = 'COMBAT_DEATHDAMAGE';
// }
// }
//
// return $combatTypes;
// }
// return ['Unknown'];
//}
function getCombatTypes($fullPath) {
if (file_exists($fullPath)) {
$content = file_get_contents($fullPath);
$combatTypes = [];
$combatParams = [
'COMBAT_PHYSICALDAMAGE', 'COMBAT_ENERGYDAMAGE', 'COMBAT_EARTHDAMAGE', 'COMBAT_FIREDAMAGE',
'COMBAT_UNDEFINEDDAMAGE', 'COMBAT_LIFEDRAIN', 'COMBAT_MANADRAIN', 'COMBAT_HEALING',
'COMBAT_DROWNDAMAGE', 'COMBAT_ICEDAMAGE', 'COMBAT_HOLYDAMAGE', 'COMBAT_DEATHDAMAGE'
];
$effectParams = [
'CONST_ME_NONE', 'CONST_ME_DRAWBLOOD', 'CONST_ME_LOSEENERGY', 'CONST_ME_POFF', 'CONST_ME_BLOCKHIT',
'CONST_ME_EXPLOSIONAREA', 'CONST_ME_EXPLOSIONHIT', 'CONST_ME_FIREAREA', 'CONST_ME_YELLOW_RINGS',
'CONST_ME_GREEN_RINGS', 'CONST_ME_HITAREA', 'CONST_ME_TELEPORT', 'CONST_ME_ENERGYHIT',
'CONST_ME_MAGIC_BLUE', 'CONST_ME_MAGIC_RED', 'CONST_ME_MAGIC_GREEN', 'CONST_ME_HITBYFIRE',
'CONST_ME_HITBYPOISON', 'CONST_ME_MORTAREA', 'CONST_ME_SOUND_GREEN', 'CONST_ME_SOUND_RED',
'CONST_ME_POISONAREA', 'CONST_ME_SOUND_YELLOW', 'CONST_ME_SOUND_PURPLE', 'CONST_ME_SOUND_BLUE',
'CONST_ME_SOUND_WHITE', 'CONST_ME_BUBBLES', 'CONST_ME_CRAPS', 'CONST_ME_GIFT_WRAPS',
'CONST_ME_FIREWORK_YELLOW', 'CONST_ME_FIREWORK_RED', 'CONST_ME_FIREWORK_BLUE', 'CONST_ME_STUN',
'CONST_ME_SLEEP', 'CONST_ME_WATERCREATURE', 'CONST_ME_GROUNDSHAKER', 'CONST_ME_HEARTS',
'CONST_ME_FIREATTACK', 'CONST_ME_ENERGYAREA', 'CONST_ME_SMALLCLOUDS', 'CONST_ME_HOLYDAMAGE',
'CONST_ME_BIGCLOUDS', 'CONST_ME_ICEAREA', 'CONST_ME_ICETORNADO', 'CONST_ME_ICEATTACK',
'CONST_ME_STONES', 'CONST_ME_SMALLPLANTS', 'CONST_ME_CARNIPHILA', 'CONST_ME_PURPLEENERGY',
'CONST_ME_YELLOWENERGY', 'CONST_ME_HOLYAREA', 'CONST_ME_BIGPLANTS', 'CONST_ME_CAKE',
'CONST_ME_GIANTICE', 'CONST_ME_WATERSPLASH', 'CONST_ME_PLANTATTACK', 'CONST_ME_TUTORIALARROW',
'CONST_ME_TUTORIALSQUARE', 'CONST_ME_MIRRORHORIZONTAL', 'CONST_ME_MIRRORVERTICAL',
'CONST_ME_SKULLHORIZONTAL', 'CONST_ME_SKULLVERTICAL', 'CONST_ME_ASSASSIN', 'CONST_ME_STEPSHORIZONTAL',
'CONST_ME_BLOODYSTEPS', 'CONST_ME_STEPSVERTICAL', 'CONST_ME_YALAHARIGHOST', 'CONST_ME_BATS',
'CONST_ME_SMOKE', 'CONST_ME_INSECTS', 'CONST_ME_DRAGONHEAD', 'CONST_ME_ORCSHAMAN',
'CONST_ME_ORCSHAMAN_FIRE', 'CONST_ME_THUNDER', 'CONST_ME_FERUMBRAS', 'CONST_ME_CONFETTI_HORIZONTAL',
'CONST_ME_CONFETTI_VERTICAL', 'CONST_ME_BLACKSMOKE', 'CONST_ME_REDSMOKE', 'CONST_ME_YELLOWSMOKE',
'CONST_ME_GREENSMOKE', 'CONST_ME_PURPLESMOKE', 'CONST_ME_EARLY_THUNDER', 'CONST_ME_RAGIAZ_BONECAPSULE',
'CONST_ME_CRITICAL_DAMAGE', 'CONST_ME_PLUNGING_FISH', 'CONST_ME_BLUECHAIN', 'CONST_ME_ORANGECHAIN',
'CONST_ME_GREENCHAIN', 'CONST_ME_PURPLECHAIN', 'CONST_ME_GREYCHAIN', 'CONST_ME_YELLOWCHAIN',
'CONST_ME_YELLOWSPARKLES', 'CONST_ME_FAEEXPLOSION', 'CONST_ME_FAECOMING', 'CONST_ME_FAEGOING',
'CONST_ME_BIGCLOUDSSINGLESPACE', 'CONST_ME_STONESSINGLESPACE', 'CONST_ME_BLUEGHOST',
'CONST_ME_POINTOFINTEREST', 'CONST_ME_MAPEFFECT', 'CONST_ME_PINKSPARK', 'CONST_ME_FIREWORK_GREEN',
'CONST_ME_FIREWORK_ORANGE', 'CONST_ME_FIREWORK_PURPLE', 'CONST_ME_FIREWORK_TURQUOISE',
'CONST_ME_THECUBE', 'CONST_ME_DRAWINK', 'CONST_ME_PRISMATICSPARKLES', 'CONST_ME_THAIAN',
'CONST_ME_THAIANGHOST', 'CONST_ME_GHOSTSMOKE', 'CONST_ME_FLOATINGBLOCK', 'CONST_ME_BLOCK',
'CONST_ME_ROOTING', 'CONST_ME_GHOSTLYSCRATCH', 'CONST_ME_GHOSTLYBITE', 'CONST_ME_BIGSCRATCHING',
'CONST_ME_SLASH', 'CONST_ME_BITE', 'CONST_ME_CHIVALRIOUSCHALLENGE', 'CONST_ME_DIVINEDAZZLE',
'CONST_ME_ELECTRICALSPARK', 'CONST_ME_PURPLETELEPORT', 'CONST_ME_REDTELEPORT',
'CONST_ME_ORANGETELEPORT', 'CONST_ME_GREYTELEPORT', 'CONST_ME_LIGHTBLUETELEPORT',
'CONST_ME_FATAL', 'CONST_ME_DODGE', 'CONST_ME_HOURGLASS', 'CONST_ME_FIREWORKSSTAR',
'CONST_ME_FIREWORKSCIRCLE', 'CONST_ME_FERUMBRAS_1', 'CONST_ME_GAZHARAGOTH', 'CONST_ME_MAD_MAGE',
'CONST_ME_HORESTIS', 'CONST_ME_DEVOVORGA', 'CONST_ME_FERUMBRAS_2', 'CONST_ME_FOAM'
];
foreach ($combatParams as $param) {
if (strpos($content, $param) !== false) {
$combatTypes[] = $param;
}
}
foreach ($effectParams as $param) {
if (strpos($content, $param) !== false) {
$combatTypes[] = $param;
}
}
return $combatTypes;
}
return ['Unknown'];
}
// Función para obtener todos los scripts de manera recursiva
function getAllScripts($dir) {
$scripts = [];
if (!is_dir($dir)) {
throw new Exception("El directorio no es válido: " . $dir);
}
$rii = new RecursiveIteratorIterator(new RecursiveDirectoryIterator($dir));
foreach ($rii as $file) {
if ($file->isDir()) {
continue;
}
if (pathinfo($file->getPathname(), PATHINFO_EXTENSION) == "lua") {
$scripts[] = $file->getPathname();
}
}
return $scripts;
}
// Cargar todos los tipos de combate
//$combatTypes = [];
//$scriptDir = 'C:/Users/felip/Documents/GitHub/pro-ot/data/spells/scripts/';
//try {
// $scripts = getAllScripts($scriptDir);
// foreach ($scripts as $script) {
// $scriptName = basename($script);
// $combatTypes[$scriptName] = getCombatTypes($script);
// }
//
// // Output the results
// foreach ($combatTypes as $scriptName => $params) {
// echo "File: $scriptName\n";
// echo "Combat Params: " . (empty($params) ? 'None' : implode(', ', array_map(function($k, $v) { return "$k => $v"; }, array_keys($////params), $params))) . "\n\n";
// }
//} catch (Exception $e) {
// echo "Error: " . $e->getMessage();
//}
// Cargar todos los tipos de combate
$combatTypes = [];
$scriptDir = 'C:/Users/felip/Documents/GitHub/pro-ot/data/spells/scripts/';
try {
$scripts = getAllScripts($scriptDir);
foreach ($scripts as $script) {
$scriptName = basename($script);
$combatTypes[$scriptName] = getCombatTypes($script);
}
} catch (Exception $e) {
echo "Error: " . $e->getMessage();
}
// Loading spell list
$spellsCache = new Cache('engine/cache/spells');
if (user_logged_in() && is_admin($user_data)) {
if (isset($_GET['update'])) {
echo "<p><strong>Logged in as admin, loading engine/XML/spells.xml file and updating cache.</strong></p>";
// SPELLS XML TO PHP ARRAY
$spellsXML = simplexml_load_file("engine/XML/spells.xml");
if ($spellsXML !== false) {
$types = array();
$type_attr = array();
$groups = array();
// This empty array will eventually contain all spells grouped by type and indexed by spell name
$spells = array();
// Loop through each XML spell object
foreach ($spellsXML as $type => $spell) {
// Get spell types
if (!in_array($type, $types)) {
$types[] = $type;
$type_attr[$type] = array();
}
// Get spell attributes
$attributes = array();
// Extract attribute values from the XML object and store it in a more manage friendly way $attributes
foreach ($spell->attributes() as $aName => $aValue)
$attributes["$aName"] = "$aValue";
// Alias attributes
if (isset($attributes['level'])) $attributes['lvl'] = $attributes['level'];
if (isset($attributes['magiclevel'])) $attributes['maglv'] = $attributes['magiclevel'];
// Populate type attributes
foreach (array_keys($attributes) as $attr) {
if (!in_array($attr, $type_attr[$type]))
$type_attr[$type][] = $attr;
}
// Get spell groups
if (isset($attributes['group'])) {
if (!in_array($attributes['group'], $groups))
$groups[] = $attributes['group'];
}
// Get spell vocations
$vocations = array();
foreach ($spell->vocation as $vocation) {
foreach ($vocation->attributes() as $attributeName => $attributeValue) {
if ("$attributeName" == "name") {
$vocId = vocation_name_to_id("$attributeValue");
$vocations[] = ($vocId !== false) ? $vocId : "$attributeValue";
} elseif ("$attributeName" == "id") {
$vocations[] = (int)"$attributeValue";
}
}
}
// Exclude monster spells and house spells
$words = (isset($attributes['words'])) ? $attributes['words'] : false;
$name = (isset($attributes['name'])) ? $attributes['name'] : false;
if (substr($words, 0, 3) !== '###' && substr($name, 0, 5) !== 'House') {
$spells[$type][$name] = array('vocations' => $vocations);
foreach ($type_attr[$type] as $att)
$spells[$type][$name][$att] = (isset($attributes[$att])) ? $attributes[$att] : false;
// Assign combat type
if (isset($attributes['script'])) {
$scriptName = basename($attributes['script']);
$spells[$type][$name]['combatType'] = isset($combatTypes[$scriptName]) ? $combatTypes[$scriptName] : 'Unknown';
} else {
$spells[$type][$name]['combatType'] = 'Unknown';
}
}
}
// Sort the spell list properly
foreach (array_keys($spells) as $type) {
usort($spells[$type], function ($a, $b) {
if (isset($a['lvl']))
return $a['lvl'] - $b['lvl'];
if (isset($a['maglv']))
return $a['maglv'] - $b['maglv'];
return -1;
});
}
$spellsCache->setContent($spells);
$spellsCache->save();
} else {
echo "<p><strong>Failed to load engine/XML/spells.xml file.</strong></p>";
}
} else {
$spells = $spellsCache->load();
?>
<form action="">
<input type="submit" name="update" value="Generate new cache">
</form>
<?php
}
} else {
$spells = $spellsCache->load();
}
if ($spells) {
// Preparing data
$configVoc = $config['vocations'];
$types = array_keys($spells);
$itemServer = 'https://forgottenot.online/'.$config['shop']['imageServer'].'/';
// Filter spells by vocation
$getVoc = (isset($_GET['vocation'])) ? getValue($_GET['vocation']) : 'all';
if ($getVoc !== 'all') {
$getVoc = (int)$getVoc;
foreach ($types as $type) {
foreach ($spells[$type] as $name => $spell) {
if (!empty($spell['vocations'])) {
if (!in_array($getVoc, $spell['vocations'])) {
unset($spells[$type][$name]);
}
}
}
}
}
// Render HTML
?>
<h1 id="spells">Spells<?php if ($getVoc !== 'all') echo ' ('.$configVoc[$getVoc]['name'].')';?></h1>
<form action="#spells" class="filter_spells">
<label for="vocation">Filter vocation:</label>
<select id="vocation" name="vocation">
<option value="all">All</option>
<?php foreach ($config['vocations'] as $id => $vocation): ?>
<option value="<?php echo $id; ?>" <?php if ($getVoc === $id) echo "selected"; ?>><?php echo $vocation['name']; ?></option>
<?php endforeach; ?>
</select>
<input type="submit" value="Search">
</form>
<h2>Spell types:</h2>
<ul>
<?php foreach ($types as $type): ?>
<li><a href="#spell_<?php echo $type; ?>"><?php echo ucfirst($type); ?></a></li>
<?php endforeach; ?>
</ul>
<h2 id="spell_instant">Instant Spells</h2>
<a href="#spells">Jump to top</a>
<table class="table tbl-hover">
<tbody>
<tr class="yellow">
<td>Name</td>
<td>Combat Type</td>
<td>Words</td>
<td>Level</td>
<td>Mana</td>
<td>Vocations</td>
</tr>
<?php foreach ($spells['instant'] as $spell): ?>
<tr>
<td><?php echo $spell['name']; ?></td>
<td><?php echo isset($spell['combatType']) ? (is_array($spell['combatType']) ? implode(', ', $spell['combatType']) : $spell['combatType']) : 'Unknown'; ?></td>
<td><?php echo $spell['words']; ?></td>
<td><?php echo $spell['lvl']; ?></td>
<td><?php echo $spell['mana']; ?></td>
<td><?php
if (!empty($spell['vocations'])) {
if ($getVoc !== 'all') {
echo $configVoc[$getVoc]['name'];
} else {
$names = array();
foreach ($spell['vocations'] as $id) {
if (isset($configVoc[$id]))
$names[] = $configVoc[$id]['name'];
}
echo implode(',<br>', $names);
}
}
?></td>
</tr>
<?php endforeach; ?>
</tbody>
</table>
<h2 id="spell_rune">Magical Runes</h2>
<a href="#spells">Jump to top</a>
<table class="table tbl-hover">
<tbody>
<tr class="yellow">
<td>Name</td>
<td>Combat Type</td>
<td>Level</td>
<td>Magic Level</td>
<td>Image</td>
<td>Vocations</td>
</tr>
<?php foreach ($spells['rune'] as $spell): ?>
<tr>
<td><?php echo $spell['name']; ?></td>
<td><?php echo isset($spell['combatType']) ? (is_array($spell['combatType']) ? implode(', ', $spell['combatType']) : $spell['combatType']) : 'Unknown'; ?></td>
<td><?php echo $spell['lvl']; ?></td>
<td><?php echo $spell['maglv']; ?></td>
<td><img src="<?php echo $itemServer.$spell['id'].'.gif'; ?>" alt="Rune image"></td>
<td><?php
if (!empty($spell['vocations'])) {
if ($getVoc !== 'all') {
echo $configVoc[$getVoc]['name'];
} else {
$names = array();
foreach ($spell['vocations'] as $id) {
if (isset($configVoc[$id]))
$names[] = $configVoc[$id]['name'];
}
echo implode(',<br>', $names);
}
}
?></td>
</tr>
<?php endforeach; ?>
</tbody>
</table>
<?php if (isset($spells['conjure'])): ?>
<h2 id="spell_conjure">Conjure Spells</h2>
<a href="#spells">Jump to top</a>
<table class="table tbl-hover">
<tbody>
<tr class="yellow">
<td>Name</td>
<td>Combat Type</td>
<td>Words</td>
<td>Level</td>
<td>Mana</td>
<td>Soul</td>
<td>Charges</td>
<td>Image</td>
<td>Vocations</td>
</tr>
<?php foreach ($spells['conjure'] as $spell): ?>
<tr>
<td><?php echo $spell['name']; ?></td>
<td><?php echo isset($spell['combatType']) ? (is_array($spell['combatType']) ? implode(', ', $spell['combatType']) : $spell['combatType']) : 'Unknown'; ?></td>
<td><?php echo $spell['words']; ?></td>
<td><?php echo $spell['lvl']; ?></td>
<td><?php echo $spell['mana']; ?></td>
<td><?php echo $spell['soul']; ?></td>
<td><?php echo $spell['conjureCount']; ?></td>
<td><img src="<?php echo $itemServer.$spell['conjureId'].'.gif'; ?>" alt="Rune image"></td>
<td><?php
if (!empty($spell['vocations'])) {
if ($getVoc !== 'all') {
echo $configVoc[$getVoc]['name'];
} else {
$names = array();
foreach ($spell['vocations'] as $id) {
if (isset($configVoc[$id]))
$names[] = $configVoc[$id]['name'];
}
echo implode(',<br>', $names);
}
}
?></td>
</tr>
<?php endforeach; ?>
</tbody>
</table>
<a href="#spells">Jump to top</a>
<?php endif; ?>
<?php
} else {
?>
<h1>Spells</h1>
<p>Spells have currently not been loaded into the website by the server admin.</p>
<?php
}
/* Debug tests
foreach ($spells as $type => $spells) {
data_dump($spells, false, "Type: $type");
}
// All spell attributes?
'group', 'words', 'lvl', 'level', 'maglv', 'magiclevel', 'charges', 'allowfaruse', 'blocktype', 'mana', 'soul', 'prem', 'aggressive', 'range', 'selftarget', 'needtarget', 'blockwalls', 'needweapon', 'exhaustion', 'groupcooldown', 'needlearn', 'casterTargetOrDirection', 'direction', 'params', 'playernameparam', 'conjureId', 'reagentId', 'conjureCount', 'vocations'
*/
include 'layout/overall/footer.php'; ?>