No puede seleccionar más de 25 temas Los temas deben comenzar con una letra o número, pueden incluir guiones ('-') y pueden tener hasta 35 caracteres de largo.
 
 
 

360 líneas
8.8 KiB

  1. define([
  2. 'js/system/events',
  3. 'css!ui/templates/tooltipItem/styles',
  4. 'html!ui/templates/tooltipItem/template',
  5. 'html!ui/templates/tooltipItem/templateTooltip',
  6. 'js/misc/statTranslations'
  7. ], function (
  8. events,
  9. styles,
  10. template,
  11. tplTooltip,
  12. statTranslations
  13. ) {
  14. var percentageStats = [
  15. 'addCritChance',
  16. 'addCritMultiplier',
  17. 'addAttackCritChance',
  18. 'addAttackCritMultiplier',
  19. 'addSpellCritChance',
  20. 'addSpellCritMultiplier',
  21. 'sprintChance',
  22. 'dmgPercent',
  23. 'xpIncrease',
  24. 'blockAttackChance',
  25. 'blockSpellChance',
  26. 'dodgeAttackChance',
  27. 'dodgeSpellChance',
  28. 'attackSpeed',
  29. 'castSpeed',
  30. 'itemQuantity',
  31. 'magicFind',
  32. 'catchChance',
  33. 'catchSpeed',
  34. 'fishRarity',
  35. 'fishWeight',
  36. 'fishItems'
  37. ];
  38. return {
  39. tpl: template,
  40. type: 'tooltipItem',
  41. tooltip: null,
  42. item: null,
  43. postRender: function () {
  44. this.tooltip = this.el.find('.tooltip');
  45. this.onEvent('onShowItemTooltip', this.onShowItemTooltip.bind(this));
  46. this.onEvent('onHideItemTooltip', this.onHideItemTooltip.bind(this));
  47. },
  48. onHideItemTooltip: function (item) {
  49. if ((this.item != item) && (this.item.refItem) && (this.item.refItem != item))
  50. return;
  51. this.item = null;
  52. this.tooltip.hide();
  53. },
  54. onShowItemTooltip: function (item, pos, compare, bottomAlign, shiftDown) {
  55. this.item = item;
  56. var tempStats = $.extend(true, {}, item.stats);
  57. var enchantedStats = item.enchantedStats || {};
  58. if ((compare) && (shiftDown)) {
  59. if (!item.eq) {
  60. var compareStats = compare.stats;
  61. for (var s in tempStats) {
  62. if (compareStats[s]) {
  63. var delta = tempStats[s] - compareStats[s];
  64. if (delta > 0)
  65. tempStats[s] = '+' + delta;
  66. else if (delta < 0)
  67. tempStats[s] = delta;
  68. } else
  69. tempStats[s] = '+' + tempStats[s];
  70. }
  71. for (var s in compareStats) {
  72. if (!tempStats[s]) {
  73. tempStats[s] = -compareStats[s];
  74. }
  75. }
  76. }
  77. } else {
  78. Object.keys(tempStats).forEach(function (s) {
  79. if (enchantedStats[s]) {
  80. tempStats[s] -= enchantedStats[s];
  81. if (tempStats[s] <= 0)
  82. delete tempStats[s];
  83. tempStats['_' + s] = enchantedStats[s];
  84. }
  85. });
  86. }
  87. stats = Object.keys(tempStats)
  88. .map(function (s) {
  89. var isEnchanted = (s[0] == '_');
  90. var statName = s;
  91. if (isEnchanted)
  92. statName = statName.substr(1);
  93. statName = statTranslations.translate(statName);
  94. var value = tempStats[s];
  95. if (percentageStats.indexOf(s) > -1)
  96. value += '%';
  97. else if ((s.indexOf('element') == 0) && (s.indexOf('Resist') == -1))
  98. value += '%';
  99. var row = value + ' ' + statName;
  100. var rowClass = '';
  101. if (compare) {
  102. if (row.indexOf('-') > -1)
  103. rowClass = 'loseStat';
  104. else if (row.indexOf('+') > -1)
  105. rowClass = 'gainStat';
  106. }
  107. if (isEnchanted)
  108. rowClass += ' enchanted';
  109. row = '<div class="' + rowClass + '">' + row + '</div>';
  110. return row;
  111. }, this)
  112. .sort(function (a, b) {
  113. return (a.replace(' enchanted', '').length - b.replace(' enchanted', '').length);
  114. })
  115. .sort(function (a, b) {
  116. if ((a.indexOf('enchanted') > -1) && (b.indexOf('enchanted') == -1))
  117. return 1;
  118. else if ((a.indexOf('enchanted') == -1) && (b.indexOf('enchanted') > -1))
  119. return -1;
  120. else
  121. return 0;
  122. })
  123. .join('');
  124. var implicitStats = (item.implicitStats || []).map(function (s) {
  125. var stat = s.stat;
  126. var statName = statTranslations.translate(stat);
  127. var value = s.value;
  128. if (percentageStats.indexOf(stat) > -1)
  129. value += '%';
  130. else if ((stat.indexOf('element') == 0) && (stat.indexOf('Resist') == -1))
  131. value += '%';
  132. var row = value + ' ' + statName;
  133. var rowClass = '';
  134. row = '<div class="' + rowClass + '">' + row + '</div>';
  135. return row;
  136. }).join('');
  137. var name = item.name;
  138. if (item.quantity > 1)
  139. name += ' x' + item.quantity;
  140. var level = null;
  141. if (item.level)
  142. level = item.level.push ? item.level[0] + ' - ' + item.level[1] : item.level;
  143. var html = tplTooltip
  144. .replace('$NAME$', name)
  145. .replace('$QUALITY$', item.quality)
  146. .replace('$TYPE$', item.type)
  147. .replace('$SLOT$', item.slot)
  148. .replace('$IMPLICITSTATS$', implicitStats)
  149. .replace('$STATS$', stats)
  150. .replace('$LEVEL$', level);
  151. if (item.requires) {
  152. html = html
  153. .replace('$ATTRIBUTE$', item.requires[0].stat)
  154. .replace('$ATTRIBUTEVALUE$', item.requires[0].value);
  155. }
  156. if (item.power)
  157. html = html.replace('$POWER$', ' ' + (new Array(item.power + 1)).join('+'));
  158. if ((item.spell) && (item.spell.values)) {
  159. var abilityValues = '';
  160. for (var p in item.spell.values) {
  161. if ((compare) && (shiftDown)) {
  162. var delta = item.spell.values[p] - compare.spell.values[p];
  163. // adjust by EPSILON to handle float point imprecision, otherwise 3.15 - 2 = 1.14 or 2 - 3.15 = -1.14
  164. // have to move away from zero by EPSILON, not a simple add
  165. if (delta >= 0) {
  166. delta += Number.EPSILON;
  167. } else {
  168. delta -= Number.EPSILON;
  169. }
  170. delta = ~~((delta) * 100) / 100;
  171. var rowClass = '';
  172. if (delta > 0) {
  173. rowClass = 'gainDamage';
  174. delta = '+' + delta;
  175. } else if (delta < 0) {
  176. rowClass = 'loseDamage';
  177. }
  178. abilityValues += '<div class="' + rowClass + '">' + p + ': ' + delta + '</div>';
  179. } else {
  180. abilityValues += p + ': ' + item.spell.values[p] + '<br/>';
  181. }
  182. }
  183. if (!item.ability)
  184. abilityValues = abilityValues;
  185. html = html.replace('$DAMAGE$', abilityValues);
  186. }
  187. this.tooltip.html(html);
  188. if (!item.level)
  189. this.tooltip.find('.level').hide();
  190. else
  191. this.tooltip.find('.level').show();
  192. if (!item.implicitStats)
  193. this.tooltip.find('.implicitStats').hide();
  194. else
  195. this.tooltip.find('.implicitStats').show();
  196. if (!item.requires)
  197. this.tooltip.find('.requires .stats').hide();
  198. else
  199. this.tooltip.find('.requires .stats').show();
  200. if ((!item.type) || (item.type == item.name))
  201. this.tooltip.find('.type').hide();
  202. else {
  203. this.tooltip.find('.type')
  204. .html(item.type)
  205. .show();
  206. }
  207. if (item.power)
  208. this.tooltip.find('.power').show();
  209. var equipErrors = window.player.inventory.equipItemErrors(item);
  210. equipErrors.forEach(function (e) {
  211. this.tooltip.find('.requires').addClass('high-level');
  212. this.tooltip.find('.requires .' + e).addClass('high-level');
  213. }, this);
  214. if ((item.material) || (item.quest)) {
  215. this.tooltip.find('.level').hide();
  216. this.tooltip.find('.info').hide();
  217. if (item.material)
  218. this.tooltip.find('.material').show();
  219. else if (item.quest)
  220. this.tooltip.find('.quest').show();
  221. } else if (item.eq)
  222. this.tooltip.find('.info').hide();
  223. if (!item.ability) {
  224. this.tooltip.find('.damage').hide();
  225. } else
  226. this.tooltip.find('.info').hide();
  227. if (item.spell) {
  228. this.tooltip.find('.spellName')
  229. .html(item.spell.name)
  230. .addClass('q' + item.spell.quality)
  231. .show();
  232. this.tooltip.find('.damage')
  233. .show();
  234. if (item.ability)
  235. this.tooltip.find('.spellName').hide();
  236. } else
  237. this.tooltip.find('.spellName').hide();
  238. this.tooltip.find('.worth').html(item.worthText ? ('<br />value: ' + item.worthText) : '');
  239. if ((item.effects) && (item.type != 'mtx')) {
  240. var htmlEffects = '';
  241. item.effects.forEach(function (e, i) {
  242. htmlEffects += e.text;
  243. if (i < item.effects.length - 1)
  244. htmlEffects += '<br />';
  245. });
  246. this.find('.effects')
  247. .html(htmlEffects)
  248. .show();
  249. } else if (item.description) {
  250. this.find('.effects')
  251. .html(item.description)
  252. .show();
  253. } else
  254. this.find('.effects').hide();
  255. if (item.type == 'Reward Card') {
  256. this.find('.spellName')
  257. .html('Set Size: ' + item.setSize)
  258. .show();
  259. }
  260. if (item.factions) {
  261. var htmlFactions = '';
  262. item.factions.forEach(function (f, i) {
  263. var htmlF = f.name + ': ' + f.tierName;
  264. if (f.noEquip)
  265. htmlF = '<font class="color-red">' + htmlF + '</font>';
  266. htmlFactions += htmlF;
  267. if (i < item.factions.length - 1)
  268. htmlFactions += '<br />';
  269. });
  270. this.find('.faction')
  271. .html(htmlFactions)
  272. .show();
  273. } else
  274. this.find('.faction').hide();
  275. if ((shiftDown) || (!compare))
  276. this.tooltip.find('.info').hide();
  277. if (item.cd) {
  278. this.tooltip.find('.info')
  279. .html('cooldown: ' + item.cd)
  280. .show();
  281. } else if (item.uses) {
  282. this.tooltip.find('.info')
  283. .html('uses: ' + item.uses)
  284. .show();
  285. }
  286. this.tooltip
  287. .show();
  288. if (pos) {
  289. if (bottomAlign)
  290. pos.y -= this.tooltip.height();
  291. this.tooltip.css({
  292. left: pos.x,
  293. top: pos.y
  294. });
  295. }
  296. events.emit('onBuiltItemTooltip', this.tooltip);
  297. },
  298. showWorth: function (canAfford) {
  299. this.tooltip.find('.worth').show();
  300. if (!canAfford)
  301. this.tooltip.find('.worth').addClass('no-afford');
  302. }
  303. };
  304. });