Поиск квестов по типам классов...
[cswowd.git] / js / talent_calc_base.js
blobef47ff1cdf09184ef542cc6d412ce54b9d6a2468
1 /*
2 * Talent calculator script
3 * For work need additional data generated by talent_calc.php script
4 */
5 var tc_maxpoints = tc_tabs!=1 ? tc_maxlevel - 9 : (tc_maxlevel - 20)>>2;
6 var tc_use_bonus = 0;
7 var tc_bild = new Array();
8 var tc_mode = new Array();
9 var tc_points = new Array(0, 0, 0);
10 var tc_totalpoints = 0;
11 var tc_base_bild_link = 0;
13 tc_cleanupBild();
15 function tc_cleanupBild()
17 for (var i=0; i<tc_tabs; i++)
19 for (var row = 0; row < tc_row; row++)
20 for (var col = 0; col < tc_col; col++)
21 if (tc_tab[i+'_'+row+'_'+col])
23 tc_bild[i+'_'+row+'_'+col] = 0;
24 tc_mode[i+'_'+row+'_'+col] = -1;
26 tc_points[i]=0;
28 tc_totalpoints = 0;
30 function tc_resetTree(i)
32 for (var row = 0; row < tc_row; row++)
33 for (var col = 0; col < tc_col; col++)
34 if (tc_tab[i+'_'+row+'_'+col])
35 tc_bild[i+'_'+row+'_'+col] = 0;
36 tc_totalpoints-= tc_points[i];
37 tc_points[i] = 0;
38 tc_updateAllTabs();
39 return false;
41 function tc_resetBild()
43 for (var i=0; i<tc_tabs; i++)
44 tc_resetTree(i);
45 return false;
47 function tc_bildFromStr(str)
49 for (var i=0,j=0; i<tc_tabs; i++)
50 for (var row = 0; row < tc_row; row++)
51 for (var col = 0; col < tc_col; col++)
52 if (tc_tab[i+'_'+row+'_'+col])
54 var p = str ? parseInt(str.charAt(j)) : 0;
55 tc_bild[i+'_'+row+'_'+col] = p;
56 tc_points[i]+=p;
57 tc_totalpoints+=p;
58 j++;
61 function tc_bildToStr()
63 var str = '';
64 for (var i=0; i<tc_tabs; i++)
65 for (var row = 0; row < tc_row; row++)
66 for (var col = 0; col < tc_col; col++)
67 if (tc_tab[i+'_'+row+'_'+col])
68 str+=tc_bild[i+'_'+row+'_'+col];
69 return str;
71 function tc_addTalent(el)
73 var l = el.id.split('_');
74 var i = parseInt(l[1]);
75 var row = parseInt(l[2]);
76 var col = parseInt(l[3]);
77 if (tc_canAddPoint(i, row, col))
79 tc_bild[i+'_'+row+'_'+col]++;
80 tc_mode[i+'_'+row+'_'+col]=-1;
81 tc_points[i]++;
82 tc_totalpoints++;
83 tc_updateAllTabs();
84 tc_showTip(el,true);
86 return false;
88 function tc_removeTalent(el)
90 var l = el.id.split('_');
91 var i = parseInt(l[1]);
92 var row = parseInt(l[2]);
93 var col = parseInt(l[3]);
94 if (tc_canRemovePoint(i, row, col))
96 tc_bild[i+'_'+row+'_'+col]--;
97 tc_mode[i+'_'+row+'_'+col]=-1;
98 tc_points[i]--;
99 tc_totalpoints--;
100 tc_updateAllTabs();
101 tc_showTip(el,true);
103 return false;
105 function tc_showTip(el, update)
107 if (el.tagName!='TD')
108 return;
109 var l = el.id.split('_');
110 var i = parseInt(l[1]);
111 var row = parseInt(l[2]);
112 var col = parseInt(l[3]);
113 var data = tc_tab[i+'_'+row+'_'+col];
114 var rank = tc_bild[i+'_'+row+'_'+col];
115 var id = rank == 0 ? data.spells[0] : data.spells[rank-1];
116 var req = '';
117 if (data.depend)
121 if (row!=0)
123 req = '<tr><td' + (tc_points[i] < row*tc_point_per_row ? ' class=SpellErr' : '') +'>' + lang_req_points + '</td></tr>';
124 req = req.replace(/<num>/, (row*tc_point_per_row));
125 req = req.replace(/<name>/, tc_name[i]);
127 var text ='<table class=spell><tbody>'
128 + '<tr><td class=Name>' + tc_spell_desc[id].name + '</td></tr>'
129 + req
130 + '<tr><td>' + lang_rank +' '+ rank + ' / ' + data.max + '</td></tr>'
131 + '<tr><td class=Talent>'+tc_spell_desc[id].desc+'</td></tr>';
132 if (rank!=0 && rank < data.max)
133 text +='<tr><td><br>' + lang_next_rank + '</td></tr>'
134 + '<tr><td class=Talent>'+tc_spell_desc[data.spells[rank]].desc+'</td></tr>';
135 text+='</tbody></table>';
136 if (update)
137 tt_UpdateTip(text);
138 else
139 Tip(text, TIMEDOWN, 0, OFFSETX, 60);
141 function tc_canAddPoint(i, row, col)
143 var data = tc_tab[i+'_'+row+'_'+col];
144 if (!data)
145 return false;
146 if (tc_totalpoints >=tc_maxpoints)
147 return false;
148 if (row*tc_point_per_row > tc_points[i])
149 return false;
150 if (data.max <= tc_bild[i+'_'+row+'_'+col])
151 return false;
152 var d = data.depend;
153 if (d && tc_bild[d.id]<=d.rank)
154 return false;
155 return true;
157 function tc_canRemovePoint(i, row, col)
159 var id = i+'_'+row+'_'+col;
160 var data = tc_tab[id];
161 var count = tc_bild[id];
162 if (count == 0)
163 return false;
164 var amount = 0;
165 for (var r = 0; r < tc_row, amount < tc_points[i]; r++)
167 var add = 0;
168 for (var c = 0; c < tc_col; c++)
170 var t = tc_tab[i+'_'+r+'_'+c];
171 if (t)
173 var a = tc_bild[i+'_'+r+'_'+c];
174 add+=a;
175 var d = t.depend;
176 if (d && d.id==id && a && count-1<=d.rank)
177 return false;
180 if (r > row && add && amount<=r*tc_point_per_row)
181 return false;
182 amount+=add;
184 return true;
187 var tc_element=
189 {frame:'icon-over-grey.gif', dir:'images/bwicons/', color:'#1AFF1A', arrow:'green'},
190 {frame:'icon-over-grey.gif', dir:'images/bwicons/', color:'#FFFFFF', arrow:'grey'},
191 {frame:'icon-over-yellow.gif', dir:'images/icons/', color:'#FFD100', arrow:'yellow'},
192 {frame:'icon-over-green.gif', dir:'images/icons/', color:'#1AFF1A', arrow:'green'}
194 function tc_getElementMode(i, row, col)
196 var count = tc_bild[i+'_'+row+'_'+col];
197 if (count == 0)
199 if (tc_canAddPoint(i, row, col)) return 0;
200 return 1;
202 else if (count == tc_tab[i+'_'+row+'_'+col].max) return 2;
203 return 3;
205 function tc_updateAllTabs()
207 for (var i=0; i<tc_tabs; i++)
208 tc_updateTab(i);
209 tc_updateBildLink();
211 function tc_updateBildLink()
213 var bildhref = document.getElementById('talent_bild_link');
214 if (bildhref)
216 if (tc_base_bild_link == 0)
217 tc_base_bild_link = bildhref.href;
218 bildhref.href = tc_base_bild_link + (tc_totalpoints ? '&bild=' + tc_bildToStr() : '');
221 function tc_updateTab(i)
223 document.getElementById('talent_point_'+i).innerHTML = tc_points[i];
224 var max = tc_points[i] == 0 ? tc_row : tc_points[i]/tc_point_per_row+2;
225 for (var r = 0; r < tc_row, r < max; r++)
226 for (var c = 0; c < tc_col; c++)
228 var id = i+'_'+r+'_'+c;
229 if (!tc_tab[id])
230 continue;
231 tc_updateElment(id, tc_getElementMode(i, r, c));
234 function tc_updateElment(id, mode)
236 if (mode==tc_mode[id])
237 return;
238 tc_mode[id] = mode;
239 var d = tc_tab[id];
240 var div = document.getElementById('talent_'+id).firstChild;
241 var m = tc_element[mode];
242 for(var img = div.firstChild; img!=null; img = img.nextSibling)
244 if (img.id=='ico') img.src = m.dir+d.icon;
245 else if (img.id=='brd') img.src = 'images/talentcalc/'+m.frame;
246 else if (img.id=='rnk'){img.style.color = m.color;img.innerHTML = tc_bild[id] + '/' + d.max;}
247 else if (img.id=='arw') img.src = 'images/talentcalc/'+d.depend.img+'-'+m.arrow+'.gif';
250 function tc_renderTree(element)
252 var text = ''
253 + '<table class=talenttab><tbody>'
254 + '<tr><td colspan=' + tc_tabs + ' class=head>' + lang_header + '</td></tr>'
255 + '<tr>';
256 for (var i=0; i<tc_tabs; i++)
258 text+= '<td style="position: relative;">';
259 text+= '<img src="images/talentcalc/t_'+tc_showclass+'_'+i+'.jpg" style="position: absolute; width: '+(58*tc_col+10)+'px; height:'+(58*tc_row+10)+'px;"></div>';
260 text+= '<table class=talent cellSpacing=0><tbody>';
261 for (var row = 0; row < tc_row; row++)
263 text+= '<tr valign=top>';
264 for (var col = 0; col < tc_col; col++)
266 var id = i+'_'+row+'_'+col;
267 var d = tc_tab[id];
268 text+= '<td id="talent_'+id+'" onclick="return tc_addTalent(this);" oncontextmenu="return tc_removeTalent(this);" onmouseover="tc_showTip(this, false);">';
269 if (d)
271 var mode = tc_getElementMode(i, row, col);
272 tc_mode[id] = mode;
273 var m = tc_element[mode];
274 text+= '<div style="position: relative;">'
275 text+= '<img id="ico" src="'+m.dir+d.icon+'" width=44 height=44 style="position: absolute; left: 2px; top: 2px;">';
276 text+= '<img id="brd" src="images/talentcalc/'+m.frame+'" style="position: absolute; left: 0px; top: 0px;">';
277 text+= '<div id="rnk" style="position: absolute; left: 34px; top: 38px; color:'+m.color+';">'+ tc_bild[id] + '/' + d.max + '</div>';
278 if (d.depend)
279 text+= '<img id="arw" src="images/talentcalc/'+d.depend.img+'-'+m.arrow+'.gif" style="position: absolute; border: 0px; left: '+d.depend.x+'px; top: '+d.depend.y+'px;">';
280 text+= '</div>';
282 text+= '</td>';
284 text+= '</tr>';
286 text+= '</tbody></table></td>';
288 text+= '<tr class=bottom>';
289 for (i = 0;i<tc_tabs;i++)
291 text+= '<td><div style="position: relative;">'
292 + '<img align="left" src="images/talentcalc/'+tc_showclass+'_'+i+'.png">'
293 + tc_name[i] + ': '
294 + '<span id="talent_point_'+i+'">'+tc_points[i]+'</span>'
295 + '<a href=# onclick="return tc_resetTree('+i+');" style="position: absolute; top: 2px; right: 2px;"><img src="images/talentcalc/reset.gif" border=0></a>'
296 + '</div></td>';
298 text+= '</tr>';
299 text+= '</tbody></table>';
300 document.getElementById(element).innerHTML = text;
301 tc_updateBildLink();