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 rivejä
892 B

  1. module.exports = {
  2. type: 'chest',
  3. ownerName: null,
  4. ttl: -1,
  5. init: function (blueprint) {
  6. if (blueprint.has('ownerName'))
  7. this.ownerName = blueprint.ownerName;
  8. if (blueprint.ttl)
  9. this.ttl = blueprint.ttl;
  10. },
  11. simplify: function (self) {
  12. return {
  13. type: 'chest',
  14. ownerName: this.ownerName
  15. };
  16. },
  17. update: function () {
  18. if (this.ttl > 0) {
  19. this.ttl--;
  20. if (!this.ttl)
  21. this.obj.destroyed = true;
  22. }
  23. },
  24. collisionEnter: function (obj) {
  25. if (!obj.player)
  26. return;
  27. let ownerName = this.ownerName;
  28. if (ownerName) {
  29. if (ownerName instanceof Array) {
  30. if (ownerName.indexOf(obj.name) === -1)
  31. return;
  32. } else if (ownerName !== obj.name)
  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. };