| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114 |
- /* eslint-disable no-param-reassign */
- "use strict";
- const DefaultSettings = {
- "npc": {
- // For bank NPC.
- // The "type" is a "type" from S_REQUEST_CONTRACT packet.
- // The "value" is a "container" from S_VIEW_WARE_EX packet.
- "bank": {
- "type": 26,
- "value": 1
- },
- "gbank": {
- "type": 26,
- "value": 3
- },
- "pbank": {
- "type": 26,
- "value": 9
- },
- "cbank": {
- "type": 26,
- "value": 12
- },
- // For other NPCs.
- // You can use "npcsummoner" command to enable debug for get values.
- "store": {
- "type": 9,
- "value": null,
- "gameId": null,
- "opts": [
- { "templateId": 2019, "huntingZoneId": 183, "_value": 70310 },
- { "templateId": 2022, "huntingZoneId": 58, "_value": 58001 }
- ]
- },
- "sstore": {
- "type": 9,
- "value": null,
- "gameId": null,
- "opts": [
- { "templateId": 2109, "huntingZoneId": 183, "_value": 250 },
- { "templateId": 2010, "huntingZoneId": 58, "_value": 58002 }
- ]
- },
- "bel": {
- "type": 50,
- "value": null,
- "gameId": null,
- "opts": [
- { "templateId": 2045, "huntingZoneId": 183, "_value": 141 },
- { "templateId": 2036, "huntingZoneId": 58, "_value": 141 }
- ]
- },
- "vg": {
- "type": 49,
- "value": null,
- "gameId": null,
- "opts": [
- { "templateId": 2058, "huntingZoneId": 183, "_value": 609 },
- { "templateId": 2009, "huntingZoneId": 58, "_value": 609 }
- ]
- }
- }
- };
- // Settings Migrator Extended v2.1
- module.exports = function MigrateSettings(from_ver, to_ver, settings) {
- if (from_ver === undefined) return { ...DefaultSettings, ...settings };
- else if (from_ver === null) return DefaultSettings;
- else {
- from_ver = Number(from_ver);
- to_ver = Number(to_ver);
- if (from_ver + 1 < to_ver) {
- settings = MigrateSettings(from_ver, from_ver + 1, settings);
- return MigrateSettings(from_ver + 1, to_ver, settings);
- }
- const oldsettings = settings;
- settings = Object.assign(DefaultSettings, {});
- for (const option in oldsettings) {
- if (settings[option] !== undefined) {
- settings[option] = MigrateOption(settings[option], oldsettings[option], ["value", "gameId"]);
- }
- }
- return settings;
- }
- };
- function MigrateOption(option, oldoption, excludes = []) {
- if (oldoption === undefined) {
- oldoption = option;
- }
- if (Array.isArray(option)) {
- for (const key of Object.keys(option)) {
- option[key] = MigrateOption(option[key], oldoption[key], excludes);
- }
- } else if (option !== null && Object.getPrototypeOf(option) === Object.prototype) {
- for (const key of Object.keys(option)) {
- if (excludes.includes(key)) {
- option[key] = oldoption[key] || null;
- } else {
- option[key] = MigrateOption(option[key], oldoption[key], excludes);
- }
- }
- } else {
- option = oldoption;
- }
- return option;
- }
|