settings_migrator.js 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114
  1. /* eslint-disable no-param-reassign */
  2. "use strict";
  3. const DefaultSettings = {
  4. "npc": {
  5. // For bank NPC.
  6. // The "type" is a "type" from S_REQUEST_CONTRACT packet.
  7. // The "value" is a "container" from S_VIEW_WARE_EX packet.
  8. "bank": {
  9. "type": 26,
  10. "value": 1
  11. },
  12. "gbank": {
  13. "type": 26,
  14. "value": 3
  15. },
  16. "pbank": {
  17. "type": 26,
  18. "value": 9
  19. },
  20. "cbank": {
  21. "type": 26,
  22. "value": 12
  23. },
  24. // For other NPCs.
  25. // You can use "npcsummoner" command to enable debug for get values.
  26. "store": {
  27. "type": 9,
  28. "value": null,
  29. "gameId": null,
  30. "opts": [
  31. { "templateId": 2019, "huntingZoneId": 183, "_value": 70310 },
  32. { "templateId": 2022, "huntingZoneId": 58, "_value": 58001 }
  33. ]
  34. },
  35. "sstore": {
  36. "type": 9,
  37. "value": null,
  38. "gameId": null,
  39. "opts": [
  40. { "templateId": 2109, "huntingZoneId": 183, "_value": 250 },
  41. { "templateId": 2010, "huntingZoneId": 58, "_value": 58002 }
  42. ]
  43. },
  44. "bel": {
  45. "type": 50,
  46. "value": null,
  47. "gameId": null,
  48. "opts": [
  49. { "templateId": 2045, "huntingZoneId": 183, "_value": 141 },
  50. { "templateId": 2036, "huntingZoneId": 58, "_value": 141 }
  51. ]
  52. },
  53. "vg": {
  54. "type": 49,
  55. "value": null,
  56. "gameId": null,
  57. "opts": [
  58. { "templateId": 2058, "huntingZoneId": 183, "_value": 609 },
  59. { "templateId": 2009, "huntingZoneId": 58, "_value": 609 }
  60. ]
  61. }
  62. }
  63. };
  64. // Settings Migrator Extended v2.1
  65. module.exports = function MigrateSettings(from_ver, to_ver, settings) {
  66. if (from_ver === undefined) return { ...DefaultSettings, ...settings };
  67. else if (from_ver === null) return DefaultSettings;
  68. else {
  69. from_ver = Number(from_ver);
  70. to_ver = Number(to_ver);
  71. if (from_ver + 1 < to_ver) {
  72. settings = MigrateSettings(from_ver, from_ver + 1, settings);
  73. return MigrateSettings(from_ver + 1, to_ver, settings);
  74. }
  75. const oldsettings = settings;
  76. settings = Object.assign(DefaultSettings, {});
  77. for (const option in oldsettings) {
  78. if (settings[option] !== undefined) {
  79. settings[option] = MigrateOption(settings[option], oldsettings[option], ["value", "gameId"]);
  80. }
  81. }
  82. return settings;
  83. }
  84. };
  85. function MigrateOption(option, oldoption, excludes = []) {
  86. if (oldoption === undefined) {
  87. oldoption = option;
  88. }
  89. if (Array.isArray(option)) {
  90. for (const key of Object.keys(option)) {
  91. option[key] = MigrateOption(option[key], oldoption[key], excludes);
  92. }
  93. } else if (option !== null && Object.getPrototypeOf(option) === Object.prototype) {
  94. for (const key of Object.keys(option)) {
  95. if (excludes.includes(key)) {
  96. option[key] = oldoption[key] || null;
  97. } else {
  98. option[key] = MigrateOption(option[key], oldoption[key], excludes);
  99. }
  100. }
  101. } else {
  102. option = oldoption;
  103. }
  104. return option;
  105. }