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.
 
 
 

142 líneas
2.9 KiB

  1. let skins = require('../config/skins');
  2. module.exports = {
  3. type: 'wardrobe',
  4. proximalPlayers: [],
  5. init: function (blueprint) {
  6. this.obj.instance.objects.buildObjects([{
  7. properties: {
  8. x: this.obj.x - 1,
  9. y: this.obj.y - 1,
  10. width: 3,
  11. height: 3,
  12. cpnNotice: {
  13. actions: {
  14. enter: {
  15. cpn: 'wardrobe',
  16. method: 'enterArea',
  17. targetId: this.obj.id,
  18. args: []
  19. },
  20. exit: {
  21. cpn: 'wardrobe',
  22. method: 'exitArea',
  23. targetId: this.obj.id,
  24. args: []
  25. }
  26. }
  27. }
  28. }
  29. }]);
  30. },
  31. exitArea: function (obj) {
  32. if (!obj.player)
  33. return;
  34. else if (!this.proximalPlayers.some(p => p === obj))
  35. return;
  36. this.proximalPlayers.spliceWhere(p => p === obj);
  37. obj.syncer.setArray(true, 'serverActions', 'removeActions', {
  38. key: 'u',
  39. action: {
  40. targetId: this.obj.id,
  41. cpn: 'wardrobe',
  42. method: 'access'
  43. }
  44. });
  45. this.obj.instance.syncer.queue('onCloseWardrobe', null, [obj.serverId]);
  46. },
  47. enterArea: function (obj) {
  48. if (!obj.player)
  49. return;
  50. if (!this.proximalPlayers.some(p => p === obj))
  51. this.proximalPlayers.push(obj);
  52. let msg = 'Press U to access the wardrobe';
  53. obj.syncer.setArray(true, 'serverActions', 'addActions', {
  54. key: 'u',
  55. name: 'open wardrobe',
  56. action: {
  57. targetId: this.obj.id,
  58. cpn: 'wardrobe',
  59. method: 'open'
  60. }
  61. });
  62. this.obj.instance.syncer.queue('onGetAnnouncement', {
  63. src: this.obj.id,
  64. msg: msg
  65. }, [obj.serverId]);
  66. },
  67. open: function (msg) {
  68. if (!msg.has('sourceId'))
  69. return;
  70. let obj = this.obj.instance.objects.objects.find(o => o.serverId === msg.sourceId);
  71. if ((!obj) || (!obj.player))
  72. return;
  73. let thisObj = this.obj;
  74. if ((Math.abs(thisObj.x - obj.x) > 1) || (Math.abs(thisObj.y - obj.y) > 1))
  75. return;
  76. obj.auth.getSkinList({
  77. callback: this.onGetSkins.bind(this, obj)
  78. });
  79. },
  80. apply: function (msg) {
  81. let obj = this.obj.instance.objects.objects.find(o => o.serverId === msg.sourceId);
  82. if (
  83. !obj ||
  84. !this.proximalPlayers.some(p => p === obj) ||
  85. !obj.auth.doesOwnSkin(msg.skinId)
  86. )
  87. return;
  88. obj.skinId = msg.skinId;
  89. obj.cell = skins.getCell(obj.skinId);
  90. obj.sheetName = skins.getSpritesheet(obj.skinId);
  91. obj.fireEvent('onBeforeSkinChange', {
  92. newSkinId: obj.skinId,
  93. newCell: obj.cell,
  94. newSheetName: obj.sheetName
  95. });
  96. let syncer = obj.syncer;
  97. syncer.set(false, null, 'cell', obj.cell);
  98. syncer.set(false, null, 'sheetName', obj.sheetName);
  99. syncer.set(false, null, 'skinId', obj.skinId);
  100. let oSyncer = this.obj.instance.syncer;
  101. oSyncer.queue('onCloseWardrobe', null, [obj.serverId]);
  102. oSyncer.queue('onGetObject', {
  103. x: obj.x,
  104. y: obj.y,
  105. components: [{
  106. type: 'attackAnimation',
  107. row: 0,
  108. col: 4
  109. }]
  110. }, -1);
  111. },
  112. onGetSkins: function (obj, result) {
  113. this.obj.instance.syncer.queue('onGetWardrobeSkins', {
  114. id: this.obj.id,
  115. skins: result
  116. }, [obj.serverId]);
  117. }
  118. };