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.
 
 
 

124 lines
2.4 KiB

  1. let skins = require('../config/skins');
  2. module.exports = {
  3. type: 'wardrobe',
  4. init: function (blueprint) {
  5. let o = 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. action: {
  50. targetId: this.obj.id,
  51. cpn: 'wardrobe',
  52. method: 'open'
  53. }
  54. });
  55. this.obj.instance.syncer.queue('onGetAnnouncement', {
  56. src: this.obj.id,
  57. msg: msg
  58. }, [obj.serverId]);
  59. },
  60. open: function (msg) {
  61. if (msg.sourceId === null)
  62. return;
  63. let obj = this.obj.instance.objects.objects.find(o => o.serverId === msg.sourceId);
  64. if ((!obj) || (!obj.player))
  65. return;
  66. let thisObj = this.obj;
  67. if ((Math.abs(thisObj.x - obj.x) > 1) || (Math.abs(thisObj.y - obj.y) > 1))
  68. return;
  69. obj.auth.getSkins({
  70. callback: this.onGetSkins.bind(this, obj)
  71. });
  72. },
  73. apply: function (msg) {
  74. let obj = this.obj.instance.objects.objects.find(o => o.serverId === msg.sourceId);
  75. if (!obj)
  76. return;
  77. obj.skinId = msg.skinId;
  78. obj.cell = skins.getCell(obj.skinId);
  79. obj.sheetName = skins.getSpritesheet(obj.skinId);
  80. let syncer = obj.syncer;
  81. syncer.set(false, null, 'cell', obj.cell);
  82. syncer.set(false, null, 'sheetName', obj.sheetName);
  83. syncer.set(false, null, 'skinId', obj.skinId);
  84. let oSyncer = this.obj.instance.syncer;
  85. oSyncer.queue('onCloseWardrobe', null, [obj.serverId]);
  86. oSyncer.queue('onGetObject', {
  87. x: obj.x,
  88. y: obj.y,
  89. components: [{
  90. type: 'attackAnimation',
  91. row: 0,
  92. col: 4
  93. }]
  94. });
  95. },
  96. onGetSkins: function (obj, skins) {
  97. this.obj.instance.syncer.queue('onGetWardrobeSkins', {
  98. id: this.obj.id,
  99. skins: skins
  100. }, [obj.serverId]);
  101. }
  102. };