Skip to content
This repository has been archived by the owner on Oct 5, 2023. It is now read-only.

Commit

Permalink
custom scripts to generate data for MTGA from various sources JET/Pre…
Browse files Browse the repository at this point in the history
…sets/SPT
  • Loading branch information
themaoci committed Jan 22, 2023
1 parent c187291 commit 3ece32f
Show file tree
Hide file tree
Showing 6 changed files with 294 additions and 20 deletions.
1 change: 1 addition & 0 deletions #scripts/SPT_assets/readme.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Copy assets database into this location for scripts to work properly
48 changes: 28 additions & 20 deletions #scripts/convertMapsData.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,13 @@

/*
Made by TheMaoci for MTGA
this scripts cakes old type of containers/dynamic/quest/weapons data structure
and changes it to newer more compressed one
files are not overriden and are named as originalname2
*/


"use strict";
const fs = require('fs');
const path = require('path');
Expand All @@ -12,14 +22,15 @@ var WORKING_DIR = "../assets/database/locations";

var MapNames = fs.readdirSync(`${WORKING_DIR}`);

/*
var FolderStructure = {
MapName: {
bossWaves: "filesContainingBossWaves",
lootSpawns: "filesContainingLootSpawns",
waves: "filesContainingWaves"
}
}

*/

for(let mapName of MapNames)
{
Expand All @@ -33,6 +44,10 @@ for(let mapName of MapNames)

// we are skipping IsStatic cause it will be always static for containers and false for dynamics

// --- STATIC - CONTAINERS ---
// --- STATIC - CONTAINERS ---
// --- STATIC - CONTAINERS ---
// --- STATIC - CONTAINERS ---
let newContainers = [];
for(let container of containers)
{
Expand All @@ -44,6 +59,10 @@ for(let mapName of MapNames)
}
fs.writeFileSync(`${WORKING_DIR}/${mapName}/lootspawns/containers2.json`, stringify(newContainers));

// --- DYNAMIC - LOOSELOOT ---
// --- DYNAMIC - LOOSELOOT---
// --- DYNAMIC - LOOSELOOT ---
// --- DYNAMIC - LOOSELOOT ---
let newDynamic = [];
for(let dynamic of dynamics)
{
Expand Down Expand Up @@ -81,6 +100,10 @@ for(let mapName of MapNames)
}
fs.writeFileSync(`${WORKING_DIR}/${mapName}/lootspawns/dynamic2.json`, stringify(newDynamic));

// --- STATIONARY - WEAPONS ---
// --- STATIONARY - WEAPONS ---
// --- STATIONARY - WEAPONS ---
// --- STATIONARY - WEAPONS ---
let newWeapon = [];
for(let weapon of weapons)
{
Expand All @@ -92,6 +115,10 @@ for(let mapName of MapNames)
}
fs.writeFileSync(`${WORKING_DIR}/${mapName}/lootspawns/weapons2.json`, stringify(newWeapon));

// --- QUESTS ---
// --- QUESTS ---
// --- QUESTS ---
// --- QUESTS ---
let newQuest = [];
for(let quest of newQuest)
{
Expand All @@ -117,23 +144,4 @@ for(let mapName of MapNames)
newQuest.push(newData);
}
fs.writeFileSync(`${WORKING_DIR}/${mapName}/lootspawns/quests2.json`, stringify(newQuest));

//let getFiles = fs.readdirSync(`${WORKING_DIR}/${mapName}/lootspawns`);
//let MapFiles = [];
//let FilesToDeleteAfterWorkIsDone = [];


//for(let file of getFiles)
//{
// if(file.includes(".json"))
// {
// MapFiles.push(parse(read(`${WORKING_DIR}/${mapName}/${file}`)).Location)
// FilesToDeleteAfterWorkIsDone.push(`${WORKING_DIR}/${mapName}/${file}`);
// }
// }

//log(MapFiles);

//break;

}
71 changes: 71 additions & 0 deletions #scripts/generateDynamicLootBaseFromPresets.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
/*
Made by TheMaoci for MTGA
This scripts generates 1 file with all the loot spawns with simplified names
and what items will be spawning on that locations based on presets in #presets folder in MTGA database
*/


"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 = "../assets/database/locations";

var MapNames = fs.readdirSync(`${WORKING_DIR}`);

for(let mapName of MapNames)
{
if(mapName.includes(".")) continue;
let presetFileNames = fs.readdirSync(`${WORKING_DIR}/${mapName}/#presets`);
let presetLocationDynamicSpawnNames = {};
//let presetsData = [];
for(let presetName of presetFileNames)
{
let data = parse(read(`${WORKING_DIR}/${mapName}/#presets/${presetName}`));

if(typeof data.Location == "undefined"){

data = data.data;
} else {
data = data.Location;
}
if(typeof data.Loot == "undefined")
{
log(presetName + " undefined data.[Location or data].Loot")
continue;
}

let LootSpawns = data.Loot;
for(let loot in LootSpawns)
{
if(typeof LootSpawns[loot].IsStatic != undefined)
{
if(LootSpawns[loot].IsStatic == false)
{
let name = LootSpawns[loot].Id;
name = name.replace(/[\(\)\[\]0-9- ]{1,99}/g ,"");
name = name.replace("__", "");
if(name.includes("quest")){

continue;
}
if(typeof presetLocationDynamicSpawnNames[name] != "undefined"){
presetLocationDynamicSpawnNames[name].OrgId.push(LootSpawns[loot].Id)
} else {
log(name);
presetLocationDynamicSpawnNames[name] = { OrgId: [LootSpawns[loot].Id] }
}
}
}
}
//presetsData.push(data);

}
fs.writeFileSync("./dynamicLootAll.json", stringify(presetLocationDynamicSpawnNames));
}
123 changes: 123 additions & 0 deletions #scripts/generateDynamicLootBaseFromSPT.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,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));
1 change: 1 addition & 0 deletions #scripts/generated-from-spt/readme.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Folder where generated staff will be present
70 changes: 70 additions & 0 deletions #scripts/updateLocationsBasedOnGeneratedFromSPT.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@

/*
Made by TheMaoci for MTGA
This scripts loops through generated locations dynamic/quests files in folder generated-flom-spt
checks if that entry is existing in our MTGA locations data and if not adds it in there.
this files not overrides anything you will need to manually go inside each location folder
and review and change names from dynamic_new and quests_new to dynamic and quests and deleting original files
*/

"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 = "./generated-from-spt";
var WORKING_DIR_OUT = "../assets/database/locations";

var MapNames_GEN = fs.readdirSync(`${WORKING_DIR}`);
var MapNames_ORG = fs.readdirSync(`${WORKING_DIR_OUT}`);


for(let mapName of MapNames_ORG)
{
if(mapName.includes(".")) continue;
if(!fs.existsSync(`${WORKING_DIR_OUT}/${mapName}/lootSpawns/dynamic.json`))
{
let dynCopy = parse(read(`${WORKING_DIR}/${mapName}/dynamics.json`));
fs.writeFileSync(`${WORKING_DIR_OUT}/${mapName}/lootSpawns/dynamic.json`, stringify(dynamicLoot));
}
if(!fs.existsSync(`${WORKING_DIR_OUT}/${mapName}/lootSpawns/quests.json`))
{
let queCopy = parse(read(`${WORKING_DIR}/${mapName}/quests.json`));
fs.writeFileSync(`${WORKING_DIR_OUT}/${mapName}/lootSpawns/quests.json`, stringify(questLoot));
}
let dynamicLoot = parse(read(`${WORKING_DIR_OUT}/${mapName}/lootSpawns/dynamic.json`));
let questLoot = parse(read(`${WORKING_DIR_OUT}/${mapName}/lootSpawns/quests.json`));
let ListOfDynamicsInList = []
let ListOfQuestsInList = []
for(let dyn of dynamicLoot)
{
ListOfDynamicsInList.push(dyn.worldId)
}
for(let quest of questLoot)
{
ListOfQuestsInList.push(quest.worldId)
}

let newDynamic = parse(read(`${WORKING_DIR}/${mapName}/dynamics.json`));
let newQuest = parse(read(`${WORKING_DIR}/${mapName}/quests.json`));

for(let dyn of newDynamic)
{
if(!ListOfDynamicsInList.includes(dyn.worldId))
dynamicLoot.push(dyn);
}
for(let quest of newQuest)
{
if(!ListOfQuestsInList.includes(quest.worldId))
questLoot.push(quest);
}

fs.writeFileSync(`${WORKING_DIR_OUT}/${mapName}/lootSpawns/dynamic_new.json`, stringify(dynamicLoot));
fs.writeFileSync(`${WORKING_DIR_OUT}/${mapName}/lootSpawns/quests_new.json`, stringify(questLoot));
}

0 comments on commit 3ece32f

Please sign in to comment.