This repository has been archived by the owner on Oct 5, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 13
/
Copy pathgenerateDynamicLootBaseFromSPT.js
123 lines (106 loc) · 3.77 KB
/
generateDynamicLootBaseFromSPT.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
/*
Made by TheMaoci for MTGA
Generates our loot structs from SPT type of files
requires database of SPT in SPT_assets folder
will generate output into generated-from-spt
*/
"use strict";
const fs = require('fs');
const path = require('path');
const log = console.log;
const stringify = (data) => JSON.stringify(data, null, "\t");
const parse = (string) => JSON.parse(string);
const read = (file) => fs.readFileSync(file, 'utf8');
var WORKING_DIR = "SPT_assets/locations";
var MapNames = fs.readdirSync(`${WORKING_DIR}`);
var TotalDynamicLootSpawns = {};
//var TotalForcedLootSpawns = {};
for(let mapName of MapNames)
{
if(mapName.includes(".")) continue;
const lootFile = `${WORKING_DIR}/${mapName}/looseLoot.json`;
if(!fs.existsSync(lootFile)) continue;
let MapDynamicLootSpawns = [];
let MapForcedLootSpawns = [];
let MapSpawnerItemsTable = {};
const data = parse(read(lootFile));
const forcedSpawns = data.spawnpointsForced;
for(let spawn of forcedSpawns)
{
const template = spawn.template;
MapForcedLootSpawns.push({
"worldId": template.Id,
"questItmTpl": template.Items[0]._tpl,
"Position": [
template.Position.x,
template.Position.y,
template.Position.z
],
"Rotation": [
template.Rotation.x,
template.Rotation.y,
template.Rotation.z
]
})
}
const spawns = data.spawnpoints;
for(let spawn of spawns)
{
const template = spawn.template;
let lootToPush = {
"worldId": template.Id,
"Position": [
template.Position.x,
template.Position.y,
template.Position.z
]
}
if(template.useGravity == true)
{
lootToPush["useGravity"] = true;
}
if(template.randomRotation == true)
{
lootToPush["randomRotation"] = true;
} else {
lootToPush["Rotation"] = [template.Rotation.x,template.Rotation.y,template.Rotation.z];
}
MapDynamicLootSpawns.push(lootToPush);
let name = template.Id
name = name.replace(/[\(\)\[\]0-9- ]{1,99}/g ,"");
name = name.replace("__", "");
// map data
if(typeof MapSpawnerItemsTable[name] != "undefined"){
for(let dist of spawn.itemDistribution)
{
if(!MapSpawnerItemsTable[name].includes(dist.tpl))
MapSpawnerItemsTable[name].push(dist.tpl);
}
} else {
MapSpawnerItemsTable[name] = [];
for(let dist of spawn.itemDistribution)
{
MapSpawnerItemsTable[name].push(dist.tpl);
}
}
// global data
if(typeof TotalDynamicLootSpawns[name] != "undefined"){
for(let dist of spawn.itemDistribution)
{
if(!TotalDynamicLootSpawns[name].includes(dist.tpl))
TotalDynamicLootSpawns[name].push(dist.tpl);
}
} else {
TotalDynamicLootSpawns[name] = [];
for(let dist of spawn.itemDistribution)
{
TotalDynamicLootSpawns[name].push(dist.tpl);
}
}
}
fs.mkdirSync(path.join(__dirname, 'generated-from-spt', mapName));
fs.writeFileSync(`./generated-from-spt/${mapName}/dynamics.json`, stringify(MapDynamicLootSpawns));
fs.writeFileSync(`./generated-from-spt/${mapName}/quests.json`, stringify(MapForcedLootSpawns));
fs.writeFileSync(`./generated-from-spt/${mapName}/availableSpawns.json`, stringify(MapSpawnerItemsTable));
}
fs.writeFileSync(`./generated/TotalAvailableSpawns.json`, stringify(TotalDynamicLootSpawns));