Требование: PHP => 5.3, часть 2
[cswow.git] / include / talent_calc.php
blob633f5f4f4ed482b61f42de543b199f00110d03ff
1 <?php
2 include_once("include/simple_cacher.php");
4 function generateCharacterBild($guid, $class, $spec)
6 global $talentTabId, $cDB, $wDB;
7 $tab_set = $wDB->selectCol('SELECT `id` FROM `wowd_talent_tab` WHERE `class_mask` & ?d ORDER BY `tab` ', 1<<($class-1));
8 if (!$tab_set)
9 return;
10 $bild = '';
11 $tinfo = $wDB->select(
12 'SELECT
13 `TalentID`,
14 `TalentTab` AS ARRAY_KEY_1,
15 `Row` AS ARRAY_KEY_2,
16 `Col` AS ARRAY_KEY_3,
17 `Rank_1`,
18 `Rank_2`,
19 `Rank_3`,
20 `Rank_4`,
21 `Rank_5`
22 FROM `wowd_talents` WHERE `TalentTab` IN (?a) ORDER BY `TalentTab`, `Row`, `Col`', $tab_set);
23 $points = array(0, 0, 0);
24 $total = 0;
25 $max = 0;
26 $name = "Undefined";
27 foreach($tab_set as $i=>$tab)
29 foreach($tinfo[$tab] as $row=>$rows)
30 foreach($rows as $col=>$data)
32 $rank = $cDB->selectCell('SELECT `current_rank` FROM `character_talent` WHERE `guid` = ?d and `spec` = ?d AND `talent_id`=?d', $guid, $spec, $data['TalentID']);
33 if (isset($rank)) ++$rank;
34 else $rank = 0;
35 $bild.= $rank;
36 $points[$i]+=$rank;
37 $total+=$rank;
39 if ($points[$i] > $max) {$max = $points[$i]; $name = getTalentName($tab);}
41 return array('calc_bild'=>$bild, 'points'=>$points, 'total'=>$total, 'name'=>$name);
44 function includeTalentScript($class, $petId, $maxLevel, $header, $ver = "322")
46 global $wDB, $game_text, $config;
47 $tab_set = 0;
48 // Create tabs list
49 if ($class)
51 // For players
52 $tab_set = $wDB->selectCol('SELECT `id` FROM `wowd_talent_tab` WHERE `class_mask` & ?d ORDER BY `tab` ', 1<<($class-1));
54 else if ($petId>=0)
56 // For pets (need get pet_talent_type from creature_family)
57 $talent_type = $wDB->selectCell('SELECT `pet_talent_type` FROM `wowd_creature_family` WHERE `category` = ?d', $petId);
58 if (isset($talent_type) && $talent_type>=0)
59 $tab_set = $wDB->selectCol('SELECT `id` FROM `wowd_talent_tab` WHERE `pet_mask` & ?d ORDER BY `tab`', 1<<$talent_type);
61 if (!$tab_set)
62 return;
63 // Создаём кэш для калькулятора (если его нет или устарел)
64 $data_file = "tc_".$class.$petId."_".$config['lang']."_".$ver.".js";
65 if (checkUseCacheJs($data_file, 60*60*24))
67 // Подготаливаем данные для скрипта
68 $tab_name = array(); // Имена веток талантов
69 $tid_to_tab = array(); // Преборазователь TalentId => TabId
70 $tabs = array(); // Тут уже будут данные для JS скрипта
71 $spell_desc = array(); // Тут хранятся описания спеллов
72 $t_row = 0; // Максимум строк
73 $t_col = 0; // Максимум колонок
75 // Стрелки зависимосей описаны тут
76 $arrows = array(
77 '0_1' =>array('img'=>'right', 'x'=>-14,'y'=>12),
78 '0_-1'=>array('img'=>'left', 'x'=> 40,'y'=>12),
79 '1_-1'=>array('img'=>'down-left', 'x'=> 14,'y'=>-40),
80 '1_0' =>array('img'=>'down-1', 'x'=> 13,'y'=>-12),
81 '2_0' =>array('img'=>'down-2', 'x'=> 13,'y'=>-70),
82 '2_1' =>array('img'=>'down2-right','x'=>-13,'y'=>-94),
83 '2_-1'=>array('img'=>'down2-left','x'=>14,'y'=>-94),
84 '3_0' =>array('img'=>'down-3', 'x'=> 13,'y'=>-128),
85 '4_0' =>array('img'=>'down-4', 'x'=> 13,'y'=>-188),
86 '1_1' =>array('img'=>'down-right','x'=>-13,'y'=>-40)
88 // Получаем данные о ветках из базы и переводим их в нужный формат
89 if ($class)
91 $ppr = 5;
92 $talents = $wDB->select(
93 'SELECT
94 `TalentID` AS ARRAY_KEY,
95 `TalentTab`,
96 `Row`,
97 `Col`,
98 `Rank_1`,
99 `Rank_2`,
100 `Rank_3`,
101 `Rank_4`,
102 `Rank_5`,
103 `DependsOn`,
104 `DependsOnRank`
105 FROM
106 `wowd_talents`
107 WHERE `TalentTab` IN (?a)', $tab_set);
109 else if ($petId >= 0)
111 $ppr = 3;
112 $petMask1=0;
113 $petMask2=0;
114 if ($petId < 32) $petMask1=1<<($petId );
115 else $petMask2=1<<($petId-32);
116 $talents = $wDB->select(
117 'SELECT
118 `TalentID` AS ARRAY_KEY,
119 `TalentTab`,
120 `Row`,
121 `Col`,
122 `Rank_1`,
123 `Rank_2`,
124 `Rank_3`,
125 `Rank_4`,
126 `Rank_5`,
127 `DependsOn`,
128 `DependsOnRank`
129 FROM
130 `wowd_talents`
131 WHERE
132 `TalentTab` IN (?a) AND ((`petflag1`=0 AND `petflag2`=0) OR (`petflag1`& ?d) OR (`petflag2`& ?d))', $tab_set, $petMask1, $petMask2);
135 // Заполняем преборазователь TalentId => TabId и Имена веток талантов
136 foreach ($tab_set as $id=>$tid)
138 $tid_to_tab[$tid]=$id;
139 $tab_name[$id] = getTalentName($tid);
142 foreach($talents as $id=>$t)
144 $tabId = $tid_to_tab[$t['TalentTab']];
145 $row = $t['Row'];
146 $col = $t['Col'];
147 $spells = array();
148 $icon = 0;
149 $max = 0;
151 if ($t_row <= $row) $t_row = $row+1;
152 if ($t_col <= $col) $t_col = $col+1;
154 for ($i=1;$i<6;$i++)
156 $spellid = $t['Rank_'.$i];
157 if ($spellid == 0)
158 continue;
159 $max = $i;
160 $spells[$i-1] = $spellid;
161 $spell = getSpell($spellid);
162 if ($icon==0) $icon = getSpellIconName($spell['SpellIconID']);
163 $name = $spell['SpellName'];
164 $spell_desc[$spellid]=array('name'=>$name, 'desc'=>getSpellDesc($spell));
166 $tabs[$tabId.'_'.$row.'_'.$col]=array('id'=>$id, 'spells'=>$spells, 'icon'=>$icon, 'max'=>$max);
168 if ($t['DependsOn'] && isset($talents[$t['DependsOn']]))
170 $d = $talents[$t['DependsOn']];
171 $dx = $t['Row']-$d['Row'];
172 $dy = $t['Col']-$d['Col'];
173 $a = $arrows[$dx."_".$dy];
174 $tabs[$tabId.'_'.$row.'_'.$col]['depend'] = array(
175 'id'=>$tid_to_tab[$d['TalentTab']]."_".$d['Row']."_".$d['Col'],
176 'rank'=>$t['DependsOnRank'],
177 'img'=>$a['img'],
178 'x'=>intval($a['x']),
179 'y'=>intval($a['y']));
181 else
182 $depend = 0;
184 echo'
185 var tc_showclass ="'.($class?$class:$tab_set[0]).'";
186 var tc_name = '.php2js($tab_name).';
187 var tc_tabs = '.count($tab_set).';
188 var tc_row = '.$t_row.';
189 var tc_col = '.$t_col.';
190 var tc_tab = '.php2js($tabs).';
191 var tc_point_per_row = '.$ppr.';
192 var tc_spell_desc = '.php2js($spell_desc).';
193 var lang_rank = "'.$game_text['talent_rank'].'";
194 var lang_next_rank = "'.$game_text['talent_next_rank'].'";
195 var lang_req_points = "'.$game_text['talent_req_points'].'";';
196 flushJsCache($data_file);
198 echo'
199 <script type="text/javascript" id = "talent_calc">
200 var tc_maxlevel = '.$maxLevel.';
201 var lang_header = \''.$header.'\';
202 </script>
203 <script type="text/javascript" src="js/talent_calc_base.js"></script>';