Você não pode selecionar mais de 25 tópicos Os tópicos devem começar com uma letra ou um número, podem incluir traços ('-') e podem ter até 35 caracteres.
 
 
 

337 linhas
8.1 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 name = item.name;
  125. if (item.quantity > 1)
  126. name += ' x' + item.quantity;
  127. var level = null;
  128. if (item.level)
  129. level = item.level.push ? item.level[0] + ' - ' + item.level[1] : item.level;
  130. var html = tplTooltip
  131. .replace('$NAME$', name)
  132. .replace('$QUALITY$', item.quality)
  133. .replace('$TYPE$', item.type)
  134. .replace('$SLOT$', item.slot)
  135. .replace('$STATS$', stats)
  136. .replace('$LEVEL$', level);
  137. if (item.requires) {
  138. html = html
  139. .replace('$ATTRIBUTE$', item.requires[0].stat)
  140. .replace('$ATTRIBUTEVALUE$', item.requires[0].value);
  141. }
  142. if (item.power)
  143. html = html.replace('$POWER$', ' ' + (new Array(item.power + 1)).join('+'));
  144. if ((item.spell) && (item.spell.values)) {
  145. var abilityValues = '';
  146. for (var p in item.spell.values) {
  147. if ((compare) && (shiftDown)) {
  148. var delta = item.spell.values[p] - compare.spell.values[p];
  149. // adjust by EPSILON to handle float point imprecision, otherwise 3.15 - 2 = 1.14 or 2 - 3.15 = -1.14
  150. // have to move away from zero by EPSILON, not a simple add
  151. if (delta >= 0) {
  152. delta += Number.EPSILON;
  153. } else {
  154. delta -= Number.EPSILON;
  155. }
  156. delta = ~~((delta) * 100) / 100;
  157. var rowClass = '';
  158. if (delta > 0) {
  159. rowClass = 'gainDamage';
  160. delta = '+' + delta;
  161. } else if (delta < 0) {
  162. rowClass = 'loseDamage';
  163. }
  164. abilityValues += '<div class="' + rowClass + '">' + p + ': ' + delta + '</div>';
  165. } else {
  166. abilityValues += p + ': ' + item.spell.values[p] + '<br/>';
  167. }
  168. }
  169. if (!item.ability)
  170. abilityValues = abilityValues;
  171. html = html.replace('$DAMAGE$', abilityValues);
  172. }
  173. this.tooltip.html(html);
  174. if (!item.level)
  175. this.tooltip.find('.level').hide();
  176. else
  177. this.tooltip.find('.level').show();
  178. if (!item.requires)
  179. this.tooltip.find('.stats').hide();
  180. else
  181. this.tooltip.find('.stats').show();
  182. if ((!item.type) || (item.type == item.name))
  183. this.tooltip.find('.type').hide();
  184. else {
  185. this.tooltip.find('.type')
  186. .html(item.type)
  187. .show();
  188. }
  189. if (item.power)
  190. this.tooltip.find('.power').show();
  191. var equipErrors = window.player.inventory.equipItemErrors(item);
  192. equipErrors.forEach(function (e) {
  193. this.tooltip.find('.requires').addClass('high-level');
  194. this.tooltip.find('.requires .' + e).addClass('high-level');
  195. }, this);
  196. if ((item.material) || (item.quest)) {
  197. this.tooltip.find('.level').hide();
  198. this.tooltip.find('.info').hide();
  199. if (item.material)
  200. this.tooltip.find('.material').show();
  201. else if (item.quest)
  202. this.tooltip.find('.quest').show();
  203. } else if (item.eq)
  204. this.tooltip.find('.info').hide();
  205. if (!item.ability) {
  206. this.tooltip.find('.damage').hide();
  207. } else
  208. this.tooltip.find('.info').hide();
  209. if (item.spell) {
  210. this.tooltip.find('.spellName')
  211. .html(item.spell.name)
  212. .addClass('q' + item.spell.quality)
  213. .show();
  214. this.tooltip.find('.damage')
  215. .show();
  216. if (item.ability)
  217. this.tooltip.find('.spellName').hide();
  218. } else
  219. this.tooltip.find('.spellName').hide();
  220. this.tooltip.find('.worth').html(item.worthText ? ('<br />value: ' + item.worthText) : '');
  221. if ((item.effects) && (item.type != 'mtx')) {
  222. var htmlEffects = '';
  223. item.effects.forEach(function (e, i) {
  224. htmlEffects += e.text;
  225. if (i < item.effects.length - 1)
  226. htmlEffects += '<br />';
  227. });
  228. this.find('.effects')
  229. .html(htmlEffects)
  230. .show();
  231. } else if (item.description) {
  232. this.find('.effects')
  233. .html(item.description)
  234. .show();
  235. } else
  236. this.find('.effects').hide();
  237. if (item.type == 'Reward Card') {
  238. this.find('.spellName')
  239. .html('Set Size: ' + item.setSize)
  240. .show();
  241. }
  242. if (item.factions) {
  243. var htmlFactions = '';
  244. item.factions.forEach(function (f, i) {
  245. var htmlF = f.name + ': ' + f.tierName;
  246. if (f.noEquip)
  247. htmlF = '<font class="color-red">' + htmlF + '</font>';
  248. htmlFactions += htmlF;
  249. if (i < item.factions.length - 1)
  250. htmlFactions += '<br />';
  251. });
  252. this.find('.faction')
  253. .html(htmlFactions)
  254. .show();
  255. } else
  256. this.find('.faction').hide();
  257. if ((shiftDown) || (!compare))
  258. this.tooltip.find('.info').hide();
  259. if (item.cd) {
  260. this.tooltip.find('.info')
  261. .html('cooldown: ' + item.cd)
  262. .show();
  263. } else if (item.uses) {
  264. this.tooltip.find('.info')
  265. .html('uses: ' + item.uses)
  266. .show();
  267. }
  268. this.tooltip
  269. .show();
  270. if (pos) {
  271. if (bottomAlign)
  272. pos.y -= this.tooltip.height();
  273. this.tooltip.css({
  274. left: pos.x,
  275. top: pos.y
  276. });
  277. }
  278. events.emit('onBuiltItemTooltip', this.tooltip);
  279. },
  280. showWorth: function (canAfford) {
  281. this.tooltip.find('.worth').show();
  282. if (!canAfford)
  283. this.tooltip.find('.worth').addClass('no-afford');
  284. }
  285. };
  286. });