Ir para conteúdo

[Znote AAC] Advanced Spells


Sammy

Posts Recomendados


Este script carrega Spells.xml quando solicitado pelo usuário no painel admin, e cria um arquivo php salvando todas as magias em arrays. 
Ele tem opções de classificação exatamente como a página do Tibia. Ele funciona com ambas as distribuições 0.2 e 0.3.

 

Preview:

[âIMG]

[âIMG]

 

Vamos ao tutorial:

 

Configuração:

 

engine/function/general.php

 

Em

?>

Adicione

 
function build_spells($xml, $display_groups) {
    $t_count = 0;
    $rune = array();
    $string = '<?php'."\n".'#Generated spells file from admin panel'."\n".'#Edit at your own risk!';
   $string .= "\n".'$show_spells_groups = '.($display_groups ? 'true' : 'false').';'."\n".'$spells = array(';
    foreach($xml as $key => $value)
    {      
        if($value['lvl'])
        {
            if($key == 'rune')
            {
                if($display_groups)
                {
                    if($value['group'] == NULL)
                    {
                        echo '<span style="color:orange;font-weight:bold">WARNING: Group not found at spell "'.$value['name'].'", set to "Attack".</span><br>';
                    }
                    $rune[(string)$value['name']] = ($value['group'] == NULL) ? 'Attack' : $value['group'];
                }
                continue;
            }
 
            $t_count++;
            $string .= "\n\t".'array(';
           
            if($display_groups)
            {
                $string .= "\n\t\t".'"group" => ';
                {
                    if($value['function'] == 'conjureRune')
                    {
                        $string .= '\''.ucfirst($rune[(string)$value['name']]).'\'';
                    }
                    else
                    {
                        if($value['group'] == NULL)
                        {
                            echo '<span style="color:orange;font-weight:bold">WARNING: Group not found at spell "'.$value['name'].'", set to "Attack".</span><br>';
                        }
                        $string .= '\''.ucfirst(($value['group'] == NULL) ? 'Attack' : $value['group']).'\'';
                    }
                }
                $string .= ',';
            }
 
            $string .= "\n\t\t".'"type" => ';
            if(config('TFSVersion') == 'TFS_02')
            {
                $string .= (($value['function'] == 'conjureRune') ? '\'Rune\'' : '\'Instant\'');
            }
            if(config('TFSVersion') == 'TFS_03')
            {
                $string .= (($value['value'] == 'conjureRune') ? '\'Rune\'' : '\'Instant\'');
            }
            $string .= ',';
            $string .= "\n\t\t".'"name" => "'.$value['name'].'",';
            $string .= "\n\t\t".'"words" => \''.$value['words'].'\',';
            $string .= "\n\t\t".'"level" => '.$value['lvl'].',';
            $string .= "\n\t\t".'"mana" => ';
            $string .= (($value['mana'] == NULL) or ($value['mana'] == '')) ? '\'Var.\'' : $value['mana'];
            $string .= ',';
            $string .= "\n\t\t".'"premium" => ';
            if($value['prem'])
            {
                $string .= ($value['prem'] == 1) ? '\'yes\'' : '\'no\'';
            }
            else
            {
                $string .= '\'no\'';
            }
            $string .= ',';
            $vocs = array();
            $string .= "\n\t\t".'"vocation" => array(';
            foreach($value->vocation as $vocation)
            {
                if(config('TFSVersion') == 'TFS_02')
                {
                    $vocs[] = '\''.$vocation[0]['name'].'\'';
                }
                elseif(config('TFSVersion') == 'TFS_03')
                {
                    if(strpos($vocation[0]['id'], ';') !== FALSE)
                    {
                        $array = explode(';', $vocation[0]['id']);
                        foreach($array as $voc)
                        {
                            $vocs[] = '\''.vocation_id_to_name($voc).'\'';
                        }
                    }
                    else
                    {
                        $vocs[] = '\''.vocation_id_to_name((int)$vocation[0]['id']).'\'';
                    }
                }
            }
            if(count($vocs) < 1) foreach(config('vocations') as $id => $name) if($id > 0) $vocs[] = '\''.$name.'\'';
            $string .= implode(', ',$vocs).')'."\n\t".'),';
        }
    }  
    $string .= "\n".'); ?>';
    echo('Loaded '. $t_count .' spells!<br>');
    echo 'File "spell.php" '.(file_exists('spell.php') ? 'updated' : 'created').'!<br>';
    $file = fopen('spell.php', 'w');
    fwrite($file, $string);
    fclose($file);
}

admin.php

Antes

 
</ul>
 
<?php include 'layout/overall/footer.php'; ?>
 

Adicione

 
    <li>
        <b>Update spells from file:</b><br>
        <?php
            if (!isset($_POST['action']))
            {          
                $_POST['action'] = 'undefine';
            }
           
            if ($_POST['action'] == 'upload')
            {
                $xml = $_FILES['file'];
                $_POST['action'] = 'undefine';
                if($xml['tmp_name'])
                {
                    if($xml['name'] == 'spells.xml')
                    {
                        $groups = (isset($_POST['show_groups']) && $_POST['show_groups'] == 'yes') ? true : false;
                        echo 'Successfully fetched spells.xml!<br>';
                        echo 'Using temporal file: '. $_FILES['file']['tmp_name'] .'<br>';
                        build_spells(simplexml_load_file($xml['tmp_name']), $groups);
                    }
                    else
                    {
                        echo '<span style="color:red;font-weight:bold">ERROR: File "spells.xml" not found.</span>';
                    }
                }
                else
                {
                    echo '<span style="color:red;font-weight:bold">ERROR: Upload failed.</span>';
                }
            }
        ?>
        <form enctype='multipart/form-data' method='POST'>
            <input type='checkbox' name='show_groups' value='yes'> Show spells groups (Only for TFS 0.2.9+)<br>
            <input type='hidden' name='action' value='upload' />
            <input type='file' name='file' />
            <input type='submit' value='Submit' />
        </form>
    </li>
 

Crie o arquivo Spell.php e adicione dentro:

 

 
 <?php
require_once 'engine/init.php'; include 'layout/overall/header.php'; echo '<h1>Spells</h1>';
if(file_exists('spell.php')) { require_once 'spell.php'; ?>
<table>
    <tr class="yellow">
        <td><b>Name</b></td>
        <?php if($show_spells_groups) echo '<td><b>Group</b></td>'; ?>
        <td><b>Type</b></td>
        <td><b>Exp Lvl</b></td>
        <td><b>Mana</b></td>
        <td><b>Premium</b></td>
        </span>
    </tr>
 
<?php
    @$sort = $_REQUEST['sort'];
    if(!isset($sort)) $sort = 'name';
   
    @$vocation = $_REQUEST['vocation'];
    if(!isset($vocation)) $vocation = 'vall';
   
    if($show_spells_groups)
    {
        @$group = $_REQUEST['_group'];
        if(!isset($group)) $group = 'gall';
    }
   
    @$type = $_REQUEST['_type'];
    if(!isset($type)) $type = 'tall';
   
    @$premium = $_REQUEST['_premium'];
    if(!isset($premium)) $premium = 'pall';
   
    $order = array();
    foreach($spells as $key => $row)
    {
        $order[$key] = $row[$sort];
    }
    array_multisort($order, SORT_ASC, $spells);
   
    foreach($spells as $spell) {
        if($vocation != 'vall')
        {
            if(!in_array($vocation, $spell['vocation'])) continue;
        }
        if($show_spells_groups && $group != 'gall')
        {
            if($spell['group'] != $group) continue;
        }
        if($type != 'tall')
        {
            if($spell['type'] != $type) continue;
        }
        if($premium != 'pall')
        {
            if($spell['premium'] != $premium) continue;
        }
    ?>
    <tr>
        <td><?php echo '<b>'.$spell['name'].'</b> ('.$spell['words'].')'; ?></td>
        <?php if($show_spells_groups) echo '<td>'.$spell['group'].'</td>'; ?>
        <td><?php echo $spell['type']; ?></td>
        <td><?php echo $spell['level']; ?></td>
        <td><?php echo $spell['mana']; ?></td>
        <td><?php echo $spell['premium']; ?></td>
    </tr>
<?php } echo '</table>'; ?>
 
<form action='spells.php' method='post'>
    <table>
        <tr class="yellow">
            <td colspan=4><b>Spell Search</b></td></tr>
            <tr class="yellow">
                <?php if($show_spells_groups) {
                echo'<td width=25%><b>vocation</b></td>
                   <td width=25%><b>group</b></td>
                   <td width=25%><b>type</b></td>
                   <td width=25%><b>premium</b></td>';}
                else {
                echo'<td width=40%><b>vocation</b></td>
                   <td width=30%><b>type</b></td>
                   <td width=30%><b>premium</b></td>';}?>
            </tr>
            <tr>
                <td valign='top'>
                    <input type='radio' name='vocation' value='vall' checked> all<br>
                    <?php
                    foreach(config('vocations') as $id => $vocation)
                    {
                        if($id > 0)
                        {
                            echo "<input type='radio' name='vocation' value='".$vocation."'> ".$vocation."<br>";
                        }
                    }
                    ?>
                </td>
                <?php
                if($show_spells_groups) echo"
                   <td valign='top'>
                       <input type='radio' name='_group' value='gall' checked> all<br>
                       <input type='radio' name='_group' value='Attack'> attack<br>
                       <input type='radio' name='_group' value='Healing'> healing<br>
                       <input type='radio' name='_group' value='Support'> support</td>"; ?>
                <td valign='top'>
                    <input type='radio' name='_type' value='tall' checked> all<br>
                    <input type='radio' name='_type' value='Instant'> instant<br>
                    <input type='radio' name='_type' value='Rune'> rune
                </td>
                <td valign='top'>
                    <input type='radio' name='_premium' value='pall' checked> all<br>
                    <input type='radio' name='_premium' value='no'> no<br>
                    <input type='radio' name='_premium' value='yes'> yes
                </td>
            </tr>
            <tr>
                <td>sort by:
                    <select name='sort'>
                        <option value='name' selected>name
                        <option value='words'>words
                        <?php if($show_spells_groups) echo "<option value='group' >group"; ?>
                        <option value='type' >type
                        <option value='level' >exp lvl
                        <option value='mana' >mana
                        <option value='premium' >premium
                    </select>
                </td>
                <td colspan='3'>
                    <input type='submit' name='submit'>
                </td>
            </tr>
    </table>
</form>
<?php } else { echo 'This page has not been configured yet.'; };
include 'layout/overall/footer.php'; ?>
 

Depois Adicionar o link da página ao seu layout
layout padrão: /layout/menu.php

Adicione na lista de páginas: 

<li><a href="spells.php">Spells</a></li>

Fim do Tutorial ?

 

Eu não posso garantir que ele vai trabalhar com todas as distros TFS.
Lembre-se que você pode editar seu arquivo spell.php, principalmente necessário se você usar spells personalizadas.

 

 

Créditos: 

cbrm(otland)

Link para o comentário
Compartilhar em outros sites

×
×
  • Criar Novo...