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.
 
 
 

48 lines
1015 B

  1. module.exports = {
  2. init: function () {
  3. let mob = this.instance.objects.objects.find(m => (m.id === this.mobId));
  4. let states = mob.dialogue.states;
  5. this.addStates(states, this.dialogue.add || {});
  6. this.removeStates(states, this.dialogue.remove || {});
  7. },
  8. addStates: function (dialogue, states) {
  9. for (let s in states) {
  10. let source = extend(true, {}, states[s]);
  11. let target = dialogue[s];
  12. if (!target) {
  13. dialogue[s] = source;
  14. continue;
  15. }
  16. for (let o in source) {
  17. target.msg[0].options.push(o);
  18. target.options[o] = source[o];
  19. }
  20. }
  21. },
  22. removeStates: function (dialogue, states) {
  23. for (let s in states) {
  24. let source = states[s];
  25. let target = dialogue[s];
  26. if (!target)
  27. continue;
  28. else if (source === null) {
  29. delete dialogue[s];
  30. continue;
  31. }
  32. for (let o in source) {
  33. let targetOptions = target.msg[0].options;
  34. if (targetOptions.options)
  35. targetOptions.spliceWhere(t => (t === o));
  36. delete target.options[o];
  37. }
  38. }
  39. }
  40. };