25개 이상의 토픽을 선택하실 수 없습니다. Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 

104 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. let cpn = null;
  23. if (action.targetId) {
  24. let target = this.obj.instance.objects.find(o => o.id === action.targetId);
  25. if (target) {
  26. cpn = target[action.cpn];
  27. if ((cpn) && (cpn[action.method]))
  28. cpn[action.method](cpn, obj, action.args);
  29. }
  30. return;
  31. }
  32. cpn = obj[action.cpn];
  33. if ((cpn) && (cpn[action.method]))
  34. cpn[action.method].apply(cpn, action.args);
  35. },
  36. collisionEnter: function (obj) {
  37. if (!obj.player)
  38. return;
  39. else if ((this.maxLevel) && (obj.stats.values.level > this.maxLevel))
  40. return;
  41. this.contents.push(obj);
  42. this.callAction(obj, 'enter');
  43. if (!this.msg)
  44. return;
  45. if (this.announce) {
  46. this.syncer.queue('onGetAnnouncement', {
  47. src: this.obj.id,
  48. msg: this.msg
  49. }, [obj.serverId]);
  50. return;
  51. }
  52. this.syncer.queue('onGetDialogue', {
  53. src: this.obj.id,
  54. msg: this.msg
  55. }, [obj.serverId]);
  56. },
  57. collisionExit: function (obj, force) {
  58. if (!force) {
  59. if (!obj.player)
  60. return;
  61. else if ((this.maxLevel) && (obj.stats.values.level > this.maxLevel))
  62. return;
  63. }
  64. this.contents.spliceWhere(c => (c === obj));
  65. this.callAction(obj, 'exit');
  66. if (!this.msg)
  67. return;
  68. this.syncer.queue('onRemoveDialogue', {
  69. src: this.obj.id
  70. }, [obj.serverId]);
  71. },
  72. events: {
  73. onCellPlayerLevelUp: function (obj) {
  74. if ((this.maxLevel) && (obj.stats.values.level > this.maxLevel))
  75. this.collisionExit(obj, true);
  76. }
  77. }
  78. };