-
Notifications
You must be signed in to change notification settings - Fork 3
/
settings_migrator.js
114 lines (105 loc) · 2.69 KB
/
settings_migrator.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
/* 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;
}