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.
 
 
 

102 lines
1.9 KiB

  1. module.exports = {
  2. type: 'notice',
  3. msg: null,
  4. actions: null,
  5. syncer: null,
  6. maxLevel: 0,
  7. contents: [],
  8. init: function (blueprint) {
  9. this.msg = blueprint.msg;
  10. this.actions = blueprint.actions || {};
  11. this.announce = blueprint.announce;
  12. this.maxLevel = blueprint.maxLevel || 0;
  13. this.syncer = this.obj.instance.syncer;
  14. },
  15. destroy: function () {
  16. this.contents.forEach(c => this.collisionExit(c));
  17. },
  18. callAction: function (obj, actionName) {
  19. let action = this.actions[actionName];
  20. if (!action)
  21. return;
  22. if (action.targetId) {
  23. let target = this.obj.instance.objects.find(o => o.id === action.targetId);
  24. if (target) {
  25. let cpn = target[action.cpn];
  26. if ((cpn) && (cpn[action.method]))
  27. cpn[action.method].call(cpn, obj, action.args);
  28. }
  29. return;
  30. }
  31. let cpn = obj[action.cpn];
  32. if ((cpn) && (cpn[action.method]))
  33. cpn[action.method].apply(cpn, action.args);
  34. },
  35. collisionEnter: function (obj) {
  36. if (!obj.player)
  37. return;
  38. else if ((this.maxLevel) && (obj.stats.values.level > this.maxLevel))
  39. return;
  40. this.contents.push(obj);
  41. this.callAction(obj, 'enter');
  42. if (!this.msg)
  43. return;
  44. if (this.announce) {
  45. this.syncer.queue('onGetAnnouncement', {
  46. src: this.obj.id,
  47. msg: this.msg
  48. }, [obj.serverId]);
  49. return;
  50. }
  51. this.syncer.queue('onGetDialogue', {
  52. src: this.obj.id,
  53. msg: this.msg
  54. }, [obj.serverId]);
  55. },
  56. collisionExit: function (obj, force) {
  57. if (!force) {
  58. if (!obj.player)
  59. return;
  60. else if ((this.maxLevel) && (obj.stats.values.level > this.maxLevel))
  61. return;
  62. }
  63. this.contents.spliceWhere(c => (c === obj));
  64. this.callAction(obj, 'exit');
  65. if (!this.msg)
  66. return;
  67. this.syncer.queue('onRemoveDialogue', {
  68. src: this.obj.id
  69. }, [obj.serverId]);
  70. },
  71. events: {
  72. onCellPlayerLevelUp: function (obj) {
  73. if ((this.maxLevel) && (obj.stats.values.level > this.maxLevel))
  74. this.collisionExit(obj, true);
  75. }
  76. }
  77. };