2 * Talent calculator script
\r
3 * For work need additional data generated by talent_calc.php script
\r
5 var tc_maxpoints = tc_tabs!=1 ? tc_maxlevel - 9 : (tc_maxlevel - 20)>>2;
\r
6 var tc_use_bonus = 0;
\r
7 var tc_bild = new Array();
\r
8 var tc_mode = new Array();
\r
9 var tc_points = new Array(0, 0, 0);
\r
10 var tc_totalpoints = 0;
\r
11 var tc_base_bild_link = 0;
\r
15 function tc_cleanupBild()
\r
17 for (var i=0; i<tc_tabs; i++)
\r
19 for (var row = 0; row < tc_row; row++)
\r
20 for (var col = 0; col < tc_col; col++)
\r
21 if (tc_tab[i+'_'+row+'_'+col])
\r
23 tc_bild[i+'_'+row+'_'+col] = 0;
\r
24 tc_mode[i+'_'+row+'_'+col] = -1;
\r
30 function tc_resetTree(i)
\r
32 for (var row = 0; row < tc_row; row++)
\r
33 for (var col = 0; col < tc_col; col++)
\r
34 if (tc_tab[i+'_'+row+'_'+col])
\r
35 tc_bild[i+'_'+row+'_'+col] = 0;
\r
36 tc_totalpoints-= tc_points[i];
\r
41 function tc_resetBild()
\r
43 for (var i=0; i<tc_tabs; i++)
\r
47 function tc_bildFromStr(str)
\r
49 for (var i=0,j=0; i<tc_tabs; i++)
\r
50 for (var row = 0; row < tc_row; row++)
\r
51 for (var col = 0; col < tc_col; col++)
\r
52 if (tc_tab[i+'_'+row+'_'+col])
\r
54 var p = str ? parseInt(str.charAt(j)) : 0;
\r
55 tc_bild[i+'_'+row+'_'+col] = p;
\r
61 function tc_bildToStr()
\r
64 for (var i=0; i<tc_tabs; i++)
\r
65 for (var row = 0; row < tc_row; row++)
\r
66 for (var col = 0; col < tc_col; col++)
\r
67 if (tc_tab[i+'_'+row+'_'+col])
\r
68 str+=tc_bild[i+'_'+row+'_'+col];
\r
71 function tc_addTalent(el)
\r
73 var l = el.id.split('_');
\r
74 var i = parseInt(l[1]);
\r
75 var row = parseInt(l[2]);
\r
76 var col = parseInt(l[3]);
\r
77 if (tc_canAddPoint(i, row, col))
\r
79 tc_bild[i+'_'+row+'_'+col]++;
\r
80 tc_mode[i+'_'+row+'_'+col]=-1;
\r
84 tc_showTip(el,true);
\r
88 function tc_removeTalent(el)
\r
90 var l = el.id.split('_');
\r
91 var i = parseInt(l[1]);
\r
92 var row = parseInt(l[2]);
\r
93 var col = parseInt(l[3]);
\r
94 if (tc_canRemovePoint(i, row, col))
\r
96 tc_bild[i+'_'+row+'_'+col]--;
\r
97 tc_mode[i+'_'+row+'_'+col]=-1;
\r
100 tc_updateAllTabs();
\r
101 tc_showTip(el,true);
\r
105 function tc_showTip(el, update)
\r
107 if (el.tagName!='TD')
\r
109 var l = el.id.split('_');
\r
110 var i = parseInt(l[1]);
\r
111 var row = parseInt(l[2]);
\r
112 var col = parseInt(l[3]);
\r
113 var data = tc_tab[i+'_'+row+'_'+col];
\r
114 var rank = tc_bild[i+'_'+row+'_'+col];
\r
115 var id = rank == 0 ? data.spells[0] : data.spells[rank-1];
\r
123 req = '<tr><td' + (tc_points[i] < row*tc_point_per_row ? ' class=SpellErr' : '') +'>' + lang_req_points + '</td></tr>';
\r
124 req = req.replace(/<num>/, (row*tc_point_per_row));
\r
125 req = req.replace(/<name>/, tc_name[i]);
\r
127 var text ='<table class=spell><tbody>'
\r
128 + '<tr><td class=Name>' + tc_spell_desc[id].name + '</td></tr>'
\r
130 + '<tr><td>' + lang_rank +' '+ rank + ' / ' + data.max + '</td></tr>'
\r
131 + '<tr><td class=Talent>'+tc_spell_desc[id].desc+'</td></tr>';
\r
132 if (rank!=0 && rank < data.max)
\r
133 text +='<tr><td><br>' + lang_next_rank + '</td></tr>'
\r
134 + '<tr><td class=Talent>'+tc_spell_desc[data.spells[rank]].desc+'</td></tr>';
\r
135 text+='</tbody></table>';
\r
137 tt_UpdateTip(text);
\r
139 Tip(text, TIMEDOWN, 0, OFFSETX, 60);
\r
141 function tc_canAddPoint(i, row, col)
\r
143 var data = tc_tab[i+'_'+row+'_'+col];
\r
146 if (tc_totalpoints >=tc_maxpoints)
\r
148 if (row*tc_point_per_row > tc_points[i])
\r
150 if (data.max <= tc_bild[i+'_'+row+'_'+col])
\r
152 var d = data.depend;
\r
153 if (d && tc_bild[d.id]<=d.rank)
\r
157 function tc_canRemovePoint(i, row, col)
\r
159 var id = i+'_'+row+'_'+col;
\r
160 var data = tc_tab[id];
\r
161 var count = tc_bild[id];
\r
165 for (var r = 0; r < tc_row, amount < tc_points[i]; r++)
\r
168 for (var c = 0; c < tc_col; c++)
\r
170 var t = tc_tab[i+'_'+r+'_'+c];
\r
173 var a = tc_bild[i+'_'+r+'_'+c];
\r
176 if (d && d.id==id && a && count-1<=d.rank)
\r
180 if (r > row && add && amount<=r*tc_point_per_row)
\r
189 {frame:'icon-over-grey.gif', dir:'images/bwicons/', color:'#1AFF1A', arrow:'green'},
\r
190 {frame:'icon-over-grey.gif', dir:'images/bwicons/', color:'#FFFFFF', arrow:'grey'},
\r
191 {frame:'icon-over-yellow.gif', dir:'images/icons/', color:'#FFD100', arrow:'yellow'},
\r
192 {frame:'icon-over-green.gif', dir:'images/icons/', color:'#1AFF1A', arrow:'green'}
\r
194 function tc_getElementMode(i, row, col)
\r
196 var count = tc_bild[i+'_'+row+'_'+col];
\r
199 if (tc_canAddPoint(i, row, col)) return 0;
\r
202 else if (count == tc_tab[i+'_'+row+'_'+col].max) return 2;
\r
205 function tc_updateAllTabs()
\r
207 for (var i=0; i<tc_tabs; i++)
\r
209 tc_updateBildLink();
\r
211 function tc_updateBildLink()
\r
213 var bildhref = document.getElementById('talent_bild_link');
\r
216 if (tc_base_bild_link == 0)
\r
217 tc_base_bild_link = bildhref.href;
\r
218 bildhref.href = tc_base_bild_link + (tc_totalpoints ? '&bild=' + tc_bildToStr() : '');
\r
221 function tc_updateTab(i)
\r
223 document.getElementById('talent_point_'+i).innerHTML = tc_points[i];
\r
224 var max = tc_points[i] == 0 ? tc_row : tc_points[i]/tc_point_per_row+2;
\r
225 for (var r = 0; r < tc_row, r < max; r++)
\r
226 for (var c = 0; c < tc_col; c++)
\r
228 var id = i+'_'+r+'_'+c;
\r
231 tc_updateElment(id, tc_getElementMode(i, r, c));
\r
234 function tc_updateElment(id, mode)
\r
236 if (mode==tc_mode[id])
\r
238 tc_mode[id] = mode;
\r
239 var d = tc_tab[id];
\r
240 var div = document.getElementById('talent_'+id).firstChild;
\r
241 var m = tc_element[mode];
\r
242 for(var img = div.firstChild; img!=null; img = img.nextSibling)
\r
244 if (img.id=='ico') img.src = m.dir+d.icon;
\r
245 else if (img.id=='brd') img.src = 'images/talentcalc/'+m.frame;
\r
246 else if (img.id=='rnk'){img.style.color = m.color;img.innerHTML = tc_bild[id] + '/' + d.max;}
\r
247 else if (img.id=='arw') img.src = 'images/talentcalc/'+d.depend.img+'-'+m.arrow+'.gif';
\r
250 function tc_renderTree(element)
\r
253 + '<table class=talenttab><tbody>'
\r
254 + '<tr><td colspan=' + tc_tabs + ' class=head>' + lang_header + '</td></tr>'
\r
256 for (var i=0; i<tc_tabs; i++)
\r
258 text+= '<td style="position: relative;">';
\r
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>';
\r
260 text+= '<table class=talent cellSpacing=0><tbody>';
\r
261 for (var row = 0; row < tc_row; row++)
\r
263 text+= '<tr valign=top>';
\r
264 for (var col = 0; col < tc_col; col++)
\r
266 var id = i+'_'+row+'_'+col;
\r
267 var d = tc_tab[id];
\r
268 text+= '<td id="talent_'+id+'" onclick="return tc_addTalent(this);" oncontextmenu="return tc_removeTalent(this);" onmouseover="tc_showTip(this, false);">';
\r
271 var mode = tc_getElementMode(i, row, col);
\r
272 tc_mode[id] = mode;
\r
273 var m = tc_element[mode];
\r
274 text+= '<div style="position: relative;">'
\r
275 text+= '<img id="ico" src="'+m.dir+d.icon+'" width=44 height=44 style="position: absolute; left: 2px; top: 2px;">';
\r
276 text+= '<img id="brd" src="images/talentcalc/'+m.frame+'" style="position: absolute; left: 0px; top: 0px;">';
\r
277 text+= '<div id="rnk" style="position: absolute; left: 34px; top: 38px; color:'+m.color+';">'+ tc_bild[id] + '/' + d.max + '</div>';
\r
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;">';
\r
286 text+= '</tbody></table></td>';
\r
288 text+= '<tr class=bottom>';
\r
289 for (i = 0;i<tc_tabs;i++)
\r
291 text+= '<td><div style="position: relative;">'
\r
292 + '<img align="left" src="images/talentcalc/'+tc_showclass+'_'+i+'.png">'
\r
293 + tc_name[i] + ': '
\r
294 + '<span id="talent_point_'+i+'">'+tc_points[i]+'</span>'
\r
295 + '<a href=# onclick="return tc_resetTree('+i+');" style="position: absolute; top: 2px; right: 2px;"><img src="images/talentcalc/reset.gif" border=0></a>'
\r
299 text+= '</tbody></table>';
\r
300 document.getElementById(element).innerHTML = text;
\r
301 tc_updateBildLink();
\r