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.
 
 
 

97 lines
1.8 KiB

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