Nevar pievienot vairāk kā 25 tēmas Tēmai ir jāsākas ar burtu vai ciparu, tā var saturēt domu zīmes ('-') un var būt līdz 35 simboliem gara.
 
 
 

146 rindas
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. cpn: 'wardrobe',
  41. method: 'access',
  42. data: {
  43. targetId: this.obj.id
  44. }
  45. }
  46. });
  47. this.obj.instance.syncer.queue('onCloseWardrobe', null, [obj.serverId]);
  48. },
  49. enterArea: function (obj) {
  50. if (!obj.player)
  51. return;
  52. if (!this.proximalPlayers.some(p => p === obj))
  53. this.proximalPlayers.push(obj);
  54. let msg = 'Press U to access the wardrobe';
  55. obj.syncer.setArray(true, 'serverActions', 'addActions', {
  56. key: 'u',
  57. name: 'open wardrobe',
  58. action: {
  59. cpn: 'wardrobe',
  60. method: 'open',
  61. data: {
  62. targetId: this.obj.id
  63. }
  64. }
  65. });
  66. this.obj.instance.syncer.queue('onGetAnnouncement', {
  67. src: this.obj.id,
  68. msg: msg
  69. }, [obj.serverId]);
  70. },
  71. open: function (msg) {
  72. if (!msg.has('sourceId'))
  73. return;
  74. let obj = this.obj.instance.objects.objects.find(o => o.serverId === msg.sourceId);
  75. if ((!obj) || (!obj.player))
  76. return;
  77. let thisObj = this.obj;
  78. if ((Math.abs(thisObj.x - obj.x) > 1) || (Math.abs(thisObj.y - obj.y) > 1))
  79. return;
  80. obj.auth.getSkinList({
  81. callback: this.onGetSkins.bind(this, obj)
  82. });
  83. },
  84. apply: function (msg) {
  85. let obj = this.obj.instance.objects.objects.find(o => o.serverId === msg.sourceId);
  86. if (
  87. !obj ||
  88. !this.proximalPlayers.some(p => p === obj) ||
  89. !obj.auth.doesOwnSkin(msg.skinId)
  90. )
  91. return;
  92. obj.skinId = msg.skinId;
  93. obj.cell = skins.getCell(obj.skinId);
  94. obj.sheetName = skins.getSpritesheet(obj.skinId);
  95. obj.fireEvent('onBeforeSkinChange', {
  96. newSkinId: obj.skinId,
  97. newCell: obj.cell,
  98. newSheetName: obj.sheetName
  99. });
  100. let syncer = obj.syncer;
  101. syncer.set(false, null, 'cell', obj.cell);
  102. syncer.set(false, null, 'sheetName', obj.sheetName);
  103. syncer.set(false, null, 'skinId', obj.skinId);
  104. let oSyncer = this.obj.instance.syncer;
  105. oSyncer.queue('onCloseWardrobe', null, [obj.serverId]);
  106. oSyncer.queue('onGetObject', {
  107. x: obj.x,
  108. y: obj.y,
  109. components: [{
  110. type: 'attackAnimation',
  111. row: 0,
  112. col: 4
  113. }]
  114. }, -1);
  115. },
  116. onGetSkins: function (obj, result) {
  117. this.obj.instance.syncer.queue('onGetWardrobeSkins', {
  118. id: this.obj.id,
  119. skins: result
  120. }, [obj.serverId]);
  121. }
  122. };