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.
 
 
 

50 lines
1022 B

  1. module.exports = {
  2. type: 'chatter',
  3. chats: null,
  4. cdMax: 50,
  5. cd: 0,
  6. chance: 0.035,
  7. global: false,
  8. init: function (blueprint) {
  9. this.chats = extend(true, [], blueprint.chats);
  10. this.cd = ~~(Math.random() * this.cdMax);
  11. for (let p in blueprint) {
  12. if (p === 'chats')
  13. continue;
  14. this[p] = blueprint[p];
  15. }
  16. },
  17. update: function () {
  18. if ((this.obj.aggro) && (this.obj.aggro.list.length > 0))
  19. return;
  20. else if (this.chats.length === 0)
  21. return;
  22. if ((this.cd === 0) && (Math.random() < this.chance)) {
  23. this.cd = this.cdMax;
  24. let pick = this.chats[~~(Math.random() * this.chats.length)];
  25. if (!this.global)
  26. this.obj.syncer.set(false, 'chatter', 'msg', pick.msg);
  27. else {
  28. //HACK
  29. //This shouldn't always be pink, but only events use this atm so it's fine
  30. this.obj.instance.syncer.queue('onGetMessages', {
  31. messages: {
  32. class: 'color-pinkB',
  33. message: this.obj.name + ': ' + pick.msg
  34. }
  35. }, -1);
  36. }
  37. } else if (this.cd > 0)
  38. this.cd--;
  39. }
  40. };