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.
 
 
 

56 lines
1.0 KiB

  1. define([
  2. 'js/system/events'
  3. ], function (
  4. events
  5. ) {
  6. return {
  7. type: 'trade',
  8. itemList: null,
  9. action: 'buy',
  10. init: function (blueprint) {
  11. },
  12. extend: function (blueprint) {
  13. let redraw = false;
  14. if (blueprint.buyList) {
  15. this.itemList = blueprint.buyList;
  16. redraw = true;
  17. this.action = 'buy';
  18. if (blueprint.buyList.buyback)
  19. this.action = 'buyback';
  20. delete blueprint.buyList;
  21. } else if (blueprint.sellList) {
  22. this.itemList = blueprint.sellList;
  23. redraw = true;
  24. this.action = 'sell';
  25. delete blueprint.sellList;
  26. }
  27. if (blueprint.removeItems) {
  28. this.itemList.items.spliceWhere(function (b) {
  29. return (blueprint.removeItems.indexOf(b.id) > -1);
  30. });
  31. redraw = true;
  32. delete blueprint.removeItems;
  33. }
  34. if (blueprint.redraw)
  35. redraw = true;
  36. for (let p in blueprint)
  37. this[p] = blueprint[p];
  38. if (redraw)
  39. events.emit('onGetTradeList', this.itemList, this.action);
  40. if (blueprint.closeTrade)
  41. events.emit('onCloseTrade');
  42. }
  43. };
  44. });