Vous ne pouvez pas sélectionner plus de 25 sujets Les noms de sujets doivent commencer par une lettre ou un nombre, peuvent contenir des tirets ('-') et peuvent comporter jusqu'à 35 caractères.
 
 
 

241 lignes
5.3 KiB

  1. define([
  2. 'js/system/events',
  3. 'js/system/client',
  4. 'js/system/globals',
  5. 'js/objects/objects',
  6. 'html!ui/templates/party/template',
  7. 'css!ui/templates/party/styles',
  8. 'html!ui/templates/party/templateInvite',
  9. 'html!ui/templates/party/templatePartyMember',
  10. 'js/config'
  11. ], function (
  12. events,
  13. client,
  14. globals,
  15. objects,
  16. template,
  17. styles,
  18. templateInvite,
  19. templatePartyMember,
  20. config
  21. ) {
  22. return {
  23. tpl: template,
  24. invite: null,
  25. party: null,
  26. postRender: function () {
  27. this.onEvent('onGetInvite', this.onGetInvite.bind(this));
  28. this.onEvent('onGetParty', this.onGetParty.bind(this));
  29. this.onEvent('onPartyDisband', this.onPartyDisband.bind(this));
  30. this.onEvent('onGetConnectedPlayer', this.onGetConnectedPlayer.bind(this));
  31. this.onEvent('onGetPartyStats', this.onGetPartyStats.bind(this));
  32. this.onEvent('onTogglePartyView', this.onTogglePartyView.bind(this));
  33. this.onTogglePartyView(config.partyView);
  34. },
  35. onGetConnectedPlayer: function (msg) {
  36. const { party } = this;
  37. const { player: { serverId: playerId, zoneId: playerZone } } = window;
  38. if (!party)
  39. return;
  40. if (!(msg instanceof Array))
  41. msg = [msg];
  42. msg.forEach(m => {
  43. const { id: mId, zoneId: mZone } = m;
  44. if (party.indexOf(m.id) === -1)
  45. return;
  46. if (mId === playerId) {
  47. party.forEach(p => {
  48. const mObj = globals.onlineList.find(o => o.id === p);
  49. let el = this.find('.member[memberId="' + p + '"]');
  50. el.removeClass('differentZone');
  51. if (mObj.mZone !== mZone)
  52. el.addClass('differentZone');
  53. });
  54. } else {
  55. let el = this.find('.member[memberId="' + m.id + '"]');
  56. el.removeClass('differentZone');
  57. if (m.mZone !== playerZone)
  58. el.addClass('differentZone');
  59. el.find('.txtLevel').html('level: ' + m.level);
  60. }
  61. });
  62. },
  63. onGetPartyStats: function (id, stats) {
  64. let party = this.party;
  65. if (!party)
  66. return;
  67. let el = this.find('.member[memberId="' + id + '"]');
  68. if (el.length === 0)
  69. return;
  70. if ((stats.hp !== null) && (stats.hpMax !== null)) {
  71. let hpPercentage = Math.min(100, (stats.hp / stats.hpMax) * 100);
  72. el.find('.statHp').css('width', hpPercentage + '%');
  73. }
  74. if ((stats.mana !== null) && (stats.manaMax !== null)) {
  75. let manaPercentage = Math.min((stats.mana / stats.manaMax) * 100, 100);
  76. el.find('.statMana').css('width', manaPercentage + '%');
  77. }
  78. if (stats.level !== null)
  79. el.find('.txtLevel').html('level: ' + stats.level);
  80. },
  81. onPartyDisband: function () {
  82. this.find('.party .list')
  83. .empty();
  84. },
  85. onGetParty: function (party) {
  86. // Destroy invite frame if you join a party
  87. if (this.invite)
  88. this.destroyInvite();
  89. let container = this.find('.party .list')
  90. .empty();
  91. this.party = party;
  92. if (!party)
  93. return;
  94. party.forEach(p => {
  95. if (p === window.player.serverId)
  96. return;
  97. let player = globals.onlineList.find(o => o.id === p);
  98. let playerName = player ? player.name : 'unknown';
  99. let level = 'level: ' + (player ? player.level : '?');
  100. let html = templatePartyMember
  101. .replace('$NAME$', playerName)
  102. .replace('$LEVEL$', level);
  103. let el = $(html)
  104. .appendTo(container)
  105. .attr('memberId', p)
  106. .on('contextmenu', this.showContext.bind(this, playerName, p));
  107. if (player.zoneId !== window.player.zoneId)
  108. el.addClass('differentZone');
  109. //Find stats
  110. let memberObj = objects.objects.find(o => o.serverId === p);
  111. if ((memberObj) && (memberObj.stats))
  112. this.onGetPartyStats(p, memberObj.stats.values);
  113. });
  114. },
  115. showContext: function (charName, id, e) {
  116. events.emit('onContextMenu', [{
  117. text: 'whisper',
  118. callback: events.emit.bind(events, 'onDoWhisper', charName)
  119. }, {
  120. text: 'remove from party',
  121. callback: this.removeFromParty.bind(this, id)
  122. }, {
  123. text: 'leave party',
  124. callback: this.leaveParty.bind(this)
  125. }], e);
  126. e.preventDefault();
  127. return false;
  128. },
  129. onGetInvite: function (sourceId) {
  130. if (this.invite)
  131. this.destroyInvite();
  132. let sourcePlayer = globals.onlineList.find(o => o.id === sourceId);
  133. let html = templateInvite
  134. .replace('$NAME$', sourcePlayer.name);
  135. let el = $(html)
  136. .appendTo(this.el);
  137. el
  138. .find('.btn')
  139. .on('click', this.destroyInvite.bind(this));
  140. this.invite = {
  141. fromId: sourcePlayer.id,
  142. fromName: sourcePlayer.name,
  143. el: el
  144. };
  145. },
  146. destroyInvite: function (e) {
  147. if (e) {
  148. if ($(e.target).hasClass('btnAccept'))
  149. this.acceptInvite();
  150. else
  151. this.declineInvite();
  152. }
  153. this.invite.el.remove();
  154. this.invite = null;
  155. events.emit('onUiHover', false);
  156. },
  157. acceptInvite: function () {
  158. client.request({
  159. cpn: 'social',
  160. method: 'acceptInvite',
  161. data: {
  162. targetId: this.invite.fromId
  163. }
  164. });
  165. },
  166. declineInvite: function () {
  167. client.request({
  168. cpn: 'social',
  169. method: 'declineInvite',
  170. data: {
  171. targetId: this.invite.fromId
  172. }
  173. });
  174. },
  175. removeFromParty: function (id) {
  176. client.request({
  177. cpn: 'social',
  178. method: 'removeFromParty',
  179. data: {
  180. id
  181. }
  182. });
  183. },
  184. leaveParty: function () {
  185. client.request({
  186. cpn: 'social',
  187. method: 'leaveParty'
  188. });
  189. },
  190. onTogglePartyView: function (state) {
  191. this.el.removeClass('full compact minimal');
  192. this.el.addClass(state);
  193. }
  194. };
  195. });