forked from Inconcessus/html5-tibia-engine
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrewrite-items-xml.js
164 lines (114 loc) · 4.26 KB
/
rewrite-items-xml.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
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
const fs = require("fs");
const otb2json = require("../lib/otb2json");
var parseString = require('xml2js').parseString;
// Libraries
var xml = fs.readFileSync("items-xml/740-items.xml").toString();
let collection = new Array();
function loadOTB(filename) {
/*
* Function Database.__loadOTB
* Loads the items.otb file to map server id to client id
*/
let map = new Object();
// Call otb2json library to read the file
let otb = otb2json.read(filename);
// Create a lookup table referencing server to client id (or itself)
otb.children.forEach(function(node) {
// Reference by the server identifier
map[node.sid] = new Object({
"id": node.cid,
"flags": node.flags,
"group": node.group,
"node": node,
"properties": null
});
}, this);
return map;
}
parseString(xml, function(error, result) {
otb = loadOTB("items-otb/740-items.otb");
if(error !== null) {
throw(error);
}
result.items.item.forEach(function(item) {
itemSelf = item["$"];
// Single ID
if(itemSelf.id) {
itemSelf.fromid = itemSelf.id;
itemSelf.toid = itemSelf.id;
}
if(itemSelf.fromid && itemSelf.toid) {
for(var i = Number(itemSelf.fromid); i <= Number(itemSelf.toid); i++) {
let thing = {
"article": itemSelf.article,
"name": itemSelf.name
}
if(item.attribute) {
item.attribute.forEach(function(attribute) {
attributeSelf = attribute["$"];
if(["absorbPercentFire", "absorbPercentPhysical", "absorbPercentEnergy", "absorbPercentPoison", "absorbPercentLifeDrain", "transformDeEquipTo", "transformEquipTo", "writeOnceItemId", "maxTextLen", "decayTo", "healthGain", "healthTicks", "manaGain", "manaTicks", "duration", "weight", "defense", "charges", "containerSize", "armor", "attack", "speed"].includes(attributeSelf.key)) {
thing[attributeSelf.key] = Number(attributeSelf.value);
} else if(["showduration", "allowpickupable", "blockprojectile", "writeable", "readable", "stopduration", "manashield", "showcharges", "suppressDrunk", "preventitemloss", "magicpoints", "invisible"].includes(attributeSelf.key)) {
thing[attributeSelf.key] = Boolean(attributeSelf.value);
} else {
thing[attributeSelf.key] = attributeSelf.value;
}
});
}
let grp = otb[String(i)].group;
let flags = otb[String(i)].flags;
if(grp === 0x02) {
if(thing.type === undefined) {
thing.type = 'container';
}
}
if(grp === 0x0B) {
thing.type = 'splash';
}
if(grp === 0x0C) {
thing.type = 'fluidContainer';
}
if(grp === 0x06) {
thing.type = 'rune';
}
if(thing.hasOwnProperty('corpseType') && thing.hasOwnProperty("containerSize")) {
thing.type = 'corpse';
}
if([1227, 1228, 1229, 1230, 1245, 1246, 1247, 1248, 1259, 1260, 1261, 1262].includes(Number(itemSelf.id))) {
thing.expertise = true;
}
if([1223, 1224, 1225, 1226].includes(Number(itemSelf.id))) {
thing.unwanted = true;
}
// Vertical
if([2037, 2038, 1818, 2060, 2061, 2066, 2067].includes(Number(itemSelf.id))) {
otb[String(i)].flags += 131072;
}
// Horizontal
if([2039, 2040, 1811, 2058, 2059, 2068, 2069].includes(Number(itemSelf.id))) {
otb[String(i)].flags += 262144;
}
// Add mailbox
if(Number(itemSelf.id) === 2593) {
thing.type = 'mailbox';
}
// Fix stamped letter
if(Number(itemSelf.id) === 2598) {
delete thing.readable;
thing.type = 'readable';
}
if([1811, 1818].includes(Number(itemSelf.id))) {
otb[String(i)].flags += 1048576;
}
// These are readables..
if((flags & (1 << 14)) || (flags & (1 << 20))) {
thing.type = 'readable';
}
otb[String(i)].properties = thing;
if(otb[String(i)].node.speed) otb[String(i)].properties.friction = otb[String(i)].node.speed;
delete otb[String(i)].node;
}
}
});
fs.writeFileSync("definitions.json", JSON.stringify(otb, null, 4));
});