2 * Talent calculator script
3 * For work need additional data generated by talent_calc.php script
5 var tc_maxpoints
= tc_tabs
!=1 ? tc_maxlevel
- 9 : (tc_maxlevel
- 20)>>2;
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;
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;
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
];
41 function tc_resetBild()
43 for (var i
=0; i
<tc_tabs
; i
++)
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
;
61 function tc_bildToStr()
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
];
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;
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;
105 function tc_showTip(el
, update
)
107 if (el
.tagName
!='TD')
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];
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>'
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>';
139 Tip(text
, TIMEDOWN
, 0, OFFSETX
, 60);
141 function tc_canAddPoint(i
, row
, col
)
143 var data
= tc_tab
[i
+'_'+row
+'_'+col
];
146 if (tc_totalpoints
>=tc_maxpoints
)
148 if (row
*tc_point_per_row
> tc_points
[i
])
150 if (data
.max
<= tc_bild
[i
+'_'+row
+'_'+col
])
153 if (d
&& tc_bild
[d
.id
]<=d
.rank
)
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
];
165 for (var r
= 0; r
< tc_row
, amount
< tc_points
[i
]; r
++)
168 for (var c
= 0; c
< tc_col
; c
++)
170 var t
= tc_tab
[i
+'_'+r
+'_'+c
];
173 var a
= tc_bild
[i
+'_'+r
+'_'+c
];
176 if (d
&& d
.id
==id
&& a
&& count
-1<=d
.rank
)
180 if (r
> row
&& add
&& amount
<=r
*tc_point_per_row
)
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
];
199 if (tc_canAddPoint(i
, row
, col
)) return 0;
202 else if (count
== tc_tab
[i
+'_'+row
+'_'+col
].max
) return 2;
205 function tc_updateAllTabs()
207 for (var i
=0; i
<tc_tabs
; i
++)
211 function tc_updateBildLink()
213 var bildhref
= document
.getElementById('talent_bild_link');
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
;
231 tc_updateElment(id
, tc_getElementMode(i
, r
, c
));
234 function tc_updateElment(id
, mode
)
236 if (mode
==tc_mode
[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
)
253 + '<table class=talenttab><tbody>'
254 + '<tr><td colspan=' + tc_tabs
+ ' class=head>' + lang_header
+ '</td></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
;
268 text
+= '<td id="talent_'+id
+'" onclick="return tc_addTalent(this);" oncontextmenu="return tc_removeTalent(this);" onmouseover="tc_showTip(this, false);">';
271 var mode
= tc_getElementMode(i
, row
, col
);
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>';
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;">';
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">'
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>'
299 text
+= '</tbody></table>';
300 document
.getElementById(element
).innerHTML
= text
;