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.
 
 
 

125 lines
2.5 KiB

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