You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 

142 lines
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.fireEvent('onBeforeSkinChange', {
  89. oldSkinId: obj.skinId,
  90. newSkinId: msg.skinId
  91. });
  92. obj.skinId = msg.skinId;
  93. obj.cell = skins.getCell(obj.skinId);
  94. obj.sheetName = skins.getSpritesheet(obj.skinId);
  95. let syncer = obj.syncer;
  96. syncer.set(false, null, 'cell', obj.cell);
  97. syncer.set(false, null, 'sheetName', obj.sheetName);
  98. syncer.set(false, null, 'skinId', obj.skinId);
  99. let oSyncer = this.obj.instance.syncer;
  100. oSyncer.queue('onCloseWardrobe', null, [obj.serverId]);
  101. oSyncer.queue('onGetObject', {
  102. x: obj.x,
  103. y: obj.y,
  104. components: [{
  105. type: 'attackAnimation',
  106. row: 0,
  107. col: 4
  108. }]
  109. }, -1);
  110. },
  111. onGetSkins: function (obj, result) {
  112. this.obj.instance.syncer.queue('onGetWardrobeSkins', {
  113. id: this.obj.id,
  114. skins: result
  115. }, [obj.serverId]);
  116. }
  117. };