settings_migrator.js 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126
  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. { "templateId": 5001, "huntingZoneId": 13, "_value": 16091 },
  34. { "templateId": 5101, "huntingZoneId": 13, "_value": 16092 },
  35. { "templateId": 5201, "huntingZoneId": 13, "_value": 16092 },
  36. { "templateId": 5301, "huntingZoneId": 13, "_value": 16092 },
  37. { "templateId": 1015, "huntingZoneId": 3051, "_value": 2851665 },
  38. { "templateId": 1037, "huntingZoneId": 3051, "_value": 2851665 },
  39. { "templateId": 1222, "huntingZoneId": 3051, "_value": 2851665 },
  40. { "templateId": 1303, "huntingZoneId": 3051, "_value": 2851665 },
  41. { "templateId": 1408, "huntingZoneId": 3051, "_value": 16094 }
  42. ]
  43. },
  44. "sstore": {
  45. "type": 9,
  46. "value": null,
  47. "gameId": null,
  48. "opts": [
  49. { "templateId": 2109, "huntingZoneId": 183, "_value": 250 },
  50. { "templateId": 2010, "huntingZoneId": 58, "_value": 58002 },
  51. { "templateId": 1385, "huntingZoneId": 3051, "_value": 58002 }
  52. ]
  53. },
  54. "bel": {
  55. "type": 50,
  56. "value": null,
  57. "gameId": null,
  58. "opts": [
  59. { "templateId": 2045, "huntingZoneId": 183, "_value": 141 },
  60. { "templateId": 2036, "huntingZoneId": 58, "_value": 141 },
  61. { "templateId": 1414, "huntingZoneId": 3051, "_value": 141 }
  62. ]
  63. },
  64. "vg": {
  65. "type": 49,
  66. "value": null,
  67. "gameId": null,
  68. "opts": [
  69. { "templateId": 2058, "huntingZoneId": 183, "_value": 609 },
  70. { "templateId": 2009, "huntingZoneId": 58, "_value": 609 },
  71. { "templateId": 1382, "huntingZoneId": 3051, "_value": 609 }
  72. ]
  73. }
  74. }
  75. };
  76. // Settings Migrator Extended v2.1
  77. module.exports = function MigrateSettings(from_ver, to_ver, settings) {
  78. if (from_ver === undefined) return { ...DefaultSettings, ...settings };
  79. else if (from_ver === null) return DefaultSettings;
  80. else {
  81. from_ver = Number(from_ver);
  82. to_ver = Number(to_ver);
  83. if (from_ver + 1 < to_ver) {
  84. settings = MigrateSettings(from_ver, from_ver + 1, settings);
  85. return MigrateSettings(from_ver + 1, to_ver, settings);
  86. }
  87. const oldsettings = settings;
  88. settings = Object.assign(DefaultSettings, {});
  89. for (const option in oldsettings) {
  90. if (settings[option] !== undefined) {
  91. settings[option] = MigrateOption(settings[option], oldsettings[option], ["value", "gameId"]);
  92. }
  93. }
  94. return settings;
  95. }
  96. };
  97. function MigrateOption(option, oldoption, excludes = []) {
  98. if (oldoption === undefined) {
  99. oldoption = option;
  100. }
  101. if (Array.isArray(option)) {
  102. for (const key of Object.keys(option)) {
  103. option[key] = MigrateOption(option[key], oldoption[key], excludes);
  104. }
  105. } else if (option !== null && Object.getPrototypeOf(option) === Object.prototype) {
  106. for (const key of Object.keys(option)) {
  107. if (excludes.includes(key)) {
  108. option[key] = oldoption[key] || null;
  109. } else {
  110. option[key] = MigrateOption(option[key], oldoption[key], excludes);
  111. }
  112. }
  113. } else {
  114. option = oldoption;
  115. }
  116. return option;
  117. }