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.
 
 
 

51 lines
888 B

  1. module.exports = {
  2. type: 'chest',
  3. ownerId: -1,
  4. ttl: -1,
  5. init: function (blueprint) {
  6. if (blueprint.ownerId !== null)
  7. this.ownerId = blueprint.ownerId;
  8. if (blueprint.ttl)
  9. this.ttl = blueprint.ttl;
  10. },
  11. simplify: function (self) {
  12. return {
  13. type: 'chest',
  14. ownerId: this.ownerId
  15. };
  16. },
  17. update: function () {
  18. if (this.ttl > 0) {
  19. this.ttl--;
  20. if (this.ttl === 0)
  21. this.obj.destroyed = true;
  22. }
  23. },
  24. collisionEnter: function (obj) {
  25. if (!obj.player)
  26. return;
  27. let ownerId = this.ownerId;
  28. if (ownerId !== -1) {
  29. if (ownerId instanceof Array) {
  30. if (ownerId.indexOf(obj.serverId) === -1)
  31. return;
  32. } else if (ownerId !== obj.serverId)
  33. return;
  34. }
  35. //Make sure the player took all the items
  36. // since maybe he doesn't have enough space for everything
  37. if (this.obj.inventory.giveItems(obj))
  38. this.obj.destroyed = true;
  39. }
  40. };