lib.js 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  1. /*
  2. * @licstart The following is the entire license notice for the JavaScript
  3. * code in this page.
  4. *
  5. * This file is part of gish-ap-calc.
  6. *
  7. * gish-ap-calc is free software: you can redistribute it and/or modify it
  8. * under the terms of the GNU Affero General Public License as published by the
  9. * Free Software Foundation, either version 3 of the License, or (at your
  10. * option) any later version.
  11. *
  12. * gish-ap-calc is distributed in the hope that it will be useful, but WITHOUT
  13. * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  14. * FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero General Public License
  15. * for more details.
  16. *
  17. * You should have received a copy of the GNU Affero General Public License
  18. * along with gish-ap-calc. If not, see <https://www.gnu.org/licenses/>.
  19. *
  20. * @licend The above is the entire license notice for the JavaScript code in
  21. * this page.
  22. */
  23. import { mDps, wacc, wDps, wHitRate } from "./mechanics.js";
  24. export function allocateAp(ap, initialBaseStats, initialStats, level, weapon, spell, totalWatk, rawMatk, rawWacc, monster, wDominanceFactor) {
  25. const baseStats = initialBaseStats.clone();
  26. const stats = initialStats.clone();
  27. const d = Math.max(monster.level - level, 0);
  28. while (ap > 0) {
  29. const physHitRate = wHitRate(wacc(stats.dex, stats.luk, rawWacc), monster.avoid, d);
  30. if (physHitRate < 0.95) {
  31. ++baseStats.luk;
  32. ++stats.luk;
  33. --ap;
  34. continue;
  35. }
  36. if (baseStats.str + baseStats.dex < baseStats.int) {
  37. ++baseStats.str;
  38. ++stats.str;
  39. --ap;
  40. continue;
  41. }
  42. const spellDps = mDps(stats, rawMatk, spell, monster, d);
  43. const meleeDps = wDps(stats, rawWacc, totalWatk, weapon, monster, d);
  44. if (meleeDps < spellDps * wDominanceFactor) {
  45. ++stats.str;
  46. const meleeDpsStrAdd = wDps(stats, rawWacc, totalWatk, weapon, monster, d);
  47. --stats.str;
  48. ++stats.luk;
  49. const meleeDpsLukAdd = wDps(stats, rawWacc, totalWatk, weapon, monster, d);
  50. --stats.luk;
  51. if (meleeDpsStrAdd > meleeDpsLukAdd) {
  52. ++baseStats.str;
  53. ++stats.str;
  54. }
  55. else {
  56. ++baseStats.luk;
  57. ++stats.luk;
  58. }
  59. --ap;
  60. continue;
  61. }
  62. const lukToNextTen = 10 - (stats.luk % 10);
  63. stats.int += lukToNextTen;
  64. const spellDpsIntAdd = mDps(stats, rawMatk, spell, monster, d);
  65. stats.int -= lukToNextTen;
  66. stats.luk += lukToNextTen;
  67. const spellDpsLukAdd = mDps(stats, rawMatk, spell, monster, d);
  68. stats.luk -= lukToNextTen;
  69. if (spellDpsIntAdd >= spellDpsLukAdd) {
  70. ++baseStats.int;
  71. ++stats.int;
  72. }
  73. else {
  74. ++baseStats.luk;
  75. ++stats.luk;
  76. }
  77. --ap;
  78. }
  79. return [baseStats, stats];
  80. }