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.
 
 
 

141 lines
3.1 KiB

  1. let passiveTree = require('../config/passiveTree');
  2. module.exports = {
  3. type: 'passives',
  4. selected: [],
  5. points: 0,
  6. init: function (blueprint) {
  7. this.selected = ((blueprint || {}).selected || []);
  8. this.selected.spliceWhere(s => (passiveTree.nodes.some(n => ((n.id === s) && (n.spiritStart)))));
  9. this.selected.push(passiveTree.nodes.find(n => (n.spiritStart === this.obj.class)).id);
  10. let points = this.calcPoints();
  11. if (points + this.selected.length < this.selected.length) {
  12. this.selected = [];
  13. this.selected.push(passiveTree.nodes.find(n => (n.spiritStart === this.obj.class)).id);
  14. blueprint.selected = this.selected;
  15. points = this.calcPoints();
  16. }
  17. this.points = points;
  18. blueprint.points = points;
  19. let stats = this.obj.stats;
  20. this.selected.forEach(function (id) {
  21. let node = passiveTree.nodes.find(n => (n.id === id));
  22. if (node) {
  23. for (let p in node.stats)
  24. stats.addStat(p, node.stats[p]);
  25. }
  26. });
  27. },
  28. calcPoints: function () {
  29. let level = this.obj.stats.values.level;
  30. let points = level - this.selected.length + 1;
  31. if (level < 20)
  32. points--;
  33. return points;
  34. },
  35. applyPassives: function () {
  36. let stats = this.obj.stats;
  37. this.selected.forEach(function (id) {
  38. let node = passiveTree.nodes.find(n => (n.id === id));
  39. if (node) {
  40. for (let p in node.stats)
  41. stats.addStat(p, node.stats[p]);
  42. }
  43. });
  44. },
  45. tickNode: function (msg) {
  46. if (this.points <= 0)
  47. return;
  48. else if (this.selected.some(s => (s === msg.nodeId)))
  49. return;
  50. let nodeId = msg.nodeId;
  51. let node = passiveTree.nodes.find(n => (n.id === nodeId));
  52. if (node.spiritStart)
  53. return;
  54. let linked = passiveTree.links.some(function (l) {
  55. if ((l.from.id !== node.id) && (l.to.id !== node.id))
  56. return false;
  57. return (
  58. (this.selected.indexOf(l.from.id) > -1) ||
  59. (this.selected.indexOf(l.to.id) > -1)
  60. );
  61. }, this);
  62. if (!linked)
  63. return;
  64. this.points--;
  65. this.obj.syncer.set(true, 'passives', 'points', this.points);
  66. this.selected.push(nodeId);
  67. this.obj.syncer.setArray(true, 'passives', 'tickNodes', nodeId);
  68. let stats = this.obj.stats;
  69. if (node) {
  70. for (let p in node.stats)
  71. stats.addStat(p, node.stats[p]);
  72. }
  73. this.obj.spellbook.calcDps();
  74. },
  75. untickNode: function (msg) {
  76. let stats = this.obj.stats;
  77. this.selected.forEach(function (s) {
  78. let node = passiveTree.nodes.find(n => (n.id === s));
  79. if (node.spiritStart)
  80. return;
  81. this.points++;
  82. this.obj.syncer.set(true, 'passives', 'points', this.points);
  83. this.obj.syncer.setArray(true, 'passives', 'untickNodes', node.id);
  84. if (node) {
  85. for (let p in node.stats)
  86. stats.addStat(p, -node.stats[p]);
  87. }
  88. }, this);
  89. this.selected = [];
  90. this.selected.push(passiveTree.nodes.find(n => (n.spiritStart === this.obj.class)).id);
  91. this.obj.spellbook.calcDps();
  92. },
  93. simplify: function (self) {
  94. if (!self)
  95. return;
  96. return {
  97. type: 'passives',
  98. selected: this.selected,
  99. points: this.points
  100. };
  101. },
  102. events: {
  103. onLevelUp: function (level) {
  104. this.points = this.calcPoints();
  105. this.obj.syncer.set(true, 'passives', 'points', this.points);
  106. }
  107. }
  108. };