Du kan inte välja fler än 25 ämnen Ämnen måste starta med en bokstav eller siffra, kan innehålla bindestreck ('-') och vara max 35 tecken långa.
 
 
 

128 rader
2.5 KiB

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