Vous ne pouvez pas sélectionner plus de 25 sujets Les noms de sujets doivent commencer par une lettre ou un nombre, peuvent contenir des tirets ('-') et peuvent comporter jusqu'à 35 caractères.
 
 
 

115 lignes
2.1 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.msgFunction = blueprint.msgFunction;
  11. this.actions = blueprint.actions || {};
  12. this.announce = blueprint.announce;
  13. this.maxLevel = blueprint.maxLevel || 0;
  14. this.syncer = this.obj.instance.syncer;
  15. },
  16. destroy: function () {
  17. this.contents.forEach(c => this.collisionExit(c));
  18. },
  19. callAction: function (obj, actionName) {
  20. let action = this.actions[actionName];
  21. if (!action)
  22. return;
  23. let args = action.args || [];
  24. let cpn = null;
  25. if (typeof(action) === 'function') {
  26. action(obj);
  27. return;
  28. }
  29. if (action.targetId) {
  30. let target = this.obj.instance.objects.find(o => o.id === action.targetId);
  31. if (target) {
  32. cpn = target[action.cpn];
  33. if ((cpn) && (cpn[action.method]))
  34. cpn[action.method](obj, ...args);
  35. }
  36. return;
  37. }
  38. cpn = obj[action.cpn];
  39. if ((cpn) && (cpn[action.method]))
  40. cpn[action.method](...args);
  41. },
  42. collisionEnter: function (obj) {
  43. if (!obj.player)
  44. return;
  45. else if ((this.maxLevel) && (obj.stats.values.level > this.maxLevel))
  46. return;
  47. this.contents.push(obj);
  48. this.callAction(obj, 'enter');
  49. if (!this.msg && !this.msgFunction)
  50. return;
  51. const msg = this.msg || this.msgFunction(obj);
  52. if (this.announce) {
  53. this.syncer.queue('onGetAnnouncement', {
  54. src: this.obj.id,
  55. msg
  56. }, [obj.serverId]);
  57. return;
  58. }
  59. this.syncer.queue('onGetDialogue', {
  60. src: this.obj.id,
  61. msg
  62. }, [obj.serverId]);
  63. },
  64. collisionExit: function (obj, force) {
  65. if (!force) {
  66. if (!obj.player)
  67. return;
  68. else if ((this.maxLevel) && (obj.stats.values.level > this.maxLevel))
  69. return;
  70. }
  71. this.contents.spliceWhere(c => (c === obj));
  72. this.callAction(obj, 'exit');
  73. if (!this.msg)
  74. return;
  75. this.syncer.queue('onRemoveDialogue', {
  76. src: this.obj.id
  77. }, [obj.serverId]);
  78. },
  79. events: {
  80. onCellPlayerLevelUp: function (obj) {
  81. if ((this.maxLevel) && (obj.stats.values.level > this.maxLevel))
  82. this.collisionExit(obj, true);
  83. }
  84. }
  85. };