Skip to content

Commit

Permalink
START: Repeatable Quests
Browse files Browse the repository at this point in the history
  • Loading branch information
paulov-t committed Jul 28, 2022
1 parent da92f4e commit ff7af22
Show file tree
Hide file tree
Showing 7 changed files with 775 additions and 40 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ user/configs/mods.json
user/mods
server.json*
gameplay.json*
quest.json*
# user/profiles - profiles is already being done above

AE-Server-*
Expand Down
66 changes: 48 additions & 18 deletions src/Controllers/AccountController.js
Original file line number Diff line number Diff line change
Expand Up @@ -282,35 +282,26 @@ class AccountController
return false;
}

// --------------------------------------------------------
//Load the PMC profile from disk.
let loadedProfile = fileIO.readParsed(AccountController.getPmcPath(sessionID));
// --------------------------------------------------------

// --------------------------------------------------------
// Fix the GUID system used by JET and replace with MongoId
const changedIds = {};
for(const item of loadedProfile.Inventory.items) {
if(item._id.length > 24) {
const oldId = item._id;
const newId = utility.generateNewId(undefined, 3);
console.log(`${oldId} is becoming ${newId}`);
changedIds[oldId] = newId;
item._id = newId;
}
}
for(const item of loadedProfile.Inventory.items) {
if(changedIds[item.parentId] !== undefined) {
item.parentId = changedIds[item.parentId];
}
}
loadedProfile = AccountController.ChangeGuidToMongo(loadedProfile);
// --------------------------------------------------------

// In patch 0.12.12.30 . BSG introduced "Special Slots" for PMCs.
// To cater for old/broken accounts, we remove the old "Pockets" (557ffd194bdc2d28148b457f) and replace with the new (627a4e6b255f7527fb05a0f6)
loadedProfile = AccountController.AddSpecialSlotPockets(loadedProfile);

// --------------------------------------------------------
// Add Repeatable Quests
loadedProfile = AccountController.AddRepeatableQuestsProperty(loadedProfile);
// --------------------------------------------------------

if(Object.keys(changedIds).length > 0) {
logger.logSuccess(`Login cleaned ${Object.keys(changedIds).length} items`);
}

AccountController.profiles[sessionID]["pmc"] = loadedProfile;

// ----------------------------------
Expand Down Expand Up @@ -444,6 +435,45 @@ class AccountController
return profile;
}

/** Fix the GUID system used by JET and replace with MongoId
* @param {*} profile
* @returns {object} profile
*/
static ChangeGuidToMongo(loadedProfile) {
const changedIds = {};
for(const item of loadedProfile.Inventory.items) {
if(item._id.length > 24) {
const oldId = item._id;
const newId = utility.generateNewId(undefined, 3);
console.log(`${oldId} is becoming ${newId}`);
changedIds[oldId] = newId;
item._id = newId;
}
}
for(const item of loadedProfile.Inventory.items) {
if(changedIds[item.parentId] !== undefined) {
item.parentId = changedIds[item.parentId];
}
}
if(Object.keys(changedIds).length > 0) {
logger.logSuccess(`Login cleaned ${Object.keys(changedIds).length} items`);
}
return loadedProfile;
}

/** Adds the "RepeatableQuests" property to the profile
* @param {*} pmcProfile
* @returns {object} profile
*/
static AddRepeatableQuestsProperty(profile)
{
if (!profile.RepeatableQuests)
{
profile.RepeatableQuests = [];
}
return profile;
}

/** Create character profile
*
* @param {*} info
Expand Down
32 changes: 12 additions & 20 deletions src/Controllers/ConfigController.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,14 @@ class ConfigController {
if(ConfigController.Configs === undefined)
ConfigController.Configs = {};

this.refreshGameplayConfigFromBase();
this.refreshServerConfigFromBase();
global.gameplayConfig = {};
this.rebuildFromBaseConfig("gameplay", global.gameplayConfig)
// this.refreshGameplayConfigFromBase();
global.serverConfig = {};
this.rebuildFromBaseConfig("server", global.serverConfig)
// this.refreshServerConfigFromBase();
global.questConfig = {};
this.rebuildFromBaseConfig("quest", global.questConfig)

const files = fs.readdirSync(`user/configs/`);

Expand Down Expand Up @@ -64,21 +70,15 @@ class ConfigController {
const configFileLocation = process.cwd() + `/user/configs/${configFileName}.json`;

if(!fs.existsSync(configFileLocation))
fs.writeFileSync(configFileLocation, JSON.stringify(configBase));
fs.writeFileSync(configFileLocation, JSON.stringify(configBase, null, 1));

globalVariable = JSON.parse(fs.readFileSync(configFileLocation));

let changesMade = false;
for(let item in configBase) {
if(globalVariable[item] === undefined) {
globalVariable[item] = configBase[item];
logger.logInfo("Adding Config Setting " + item + " to " + configFileLocation);
changesMade = true;
}
}
changesMade = ConfigController.mergeRecursiveIgnoringExisting(globalVariable, configBase);

if(changesMade)
fs.writeFileSync(configFileLocation, JSON.stringify(globalVariable));
fs.writeFileSync(configFileLocation, JSON.stringify(globalVariable, null, 1));
}

static refreshServerConfigFromBase() {
Expand All @@ -95,22 +95,14 @@ class ConfigController {
if(fs.existsSync(process.cwd() + "/user/configs/server.json"))
global.serverConfig = JSON.parse(fs.readFileSync(process.cwd() + "/user/configs/server.json"));

// let changesMade = false;
// for(let item in serverConfigBase) {
// if(global.serverConfig[item] === undefined) {
// global.serverConfig[item] = serverConfigBase[item];
// logger.logInfo("Adding Config Setting " + item + " to server.json");
// changesMade = true;
// }
// }
let changesMade = false;
changesMade = ConfigController.mergeRecursiveIgnoringExisting(global.serverConfig, serverConfigBase);

if(changesMade)
fs.writeFileSync(process.cwd() + "/user/configs/server.json", JSON.stringify(global.serverConfig));
}

static refreshGameplayConfigFromBase() {
static refreshGameplayConfigFromBase() {
const configBase = JSON.parse(fs.readFileSync("user/configs/gameplay_base.json"));
if(!fs.existsSync("user/configs/gameplay.json"))
fs.writeFileSync("user/configs/gameplay.json", JSON.stringify(configBase));
Expand Down
Loading

0 comments on commit ff7af22

Please sign in to comment.