<?php

namespace Aowow;

if (!defined('AOWOW_REVISION'))
    die('illegal access');

if (!CLI)
    die('not in cli mode');


CLISetup::registerSetup("sql", new class extends SetupScript
{
    protected $info = array(
        'talents' => [[], CLISetup::ARGV_PARAM, 'Compiles supplemental data for type: Profile from dbc.']
    );

    protected $dbcSourceFiles = ['talent', 'talenttab'];

    public function generate() : bool
    {
        DB::Aowow()->qry('TRUNCATE ::talents');

        // class: 0 => hunter pets
        for ($i = 1; $i < 6; $i++)
            DB::Aowow()->qry(
               'INSERT INTO ::talents
                    SELECT  t.id,
                            IF(tt.classMask <> 0, LOG(2, tt.classMask) + 1, 0),
                            tt.creatureFamilyMask,
                            IF(tt.creaturefamilyMask <> 0, LOG(2, tt.creaturefamilyMask), tt.tabNumber),
                            t.row,
                            t.column,
                            t.rank%i,
                            %i
                    FROM    dbc_talenttab tt
                    JOIN    dbc_talent t ON tt.id = t.tabId
                    WHERE   t.rank%i <> 0',
                $i, $i, $i
            );

        return true;
    }
});

?>
