Hello!
Not quite sure where to put this but I created a plugin for my game, where in the new game everything loads fine, however when I load a save where the data should already be there, the data gets reset and I'm thoroughly confused why.
I'm using Scene_Boot:
Any help would be great! I am using the VisuMZ sample project as a base, including this plugin, to test things out, but not sure why it is not loading the trees. If it's working on a new game, shouldn't it work on a continued save?
Look forward to the help!
Not quite sure where to put this but I created a plugin for my game, where in the new game everything loads fine, however when I load a save where the data should already be there, the data gets reset and I'm thoroughly confused why.
I'm using Scene_Boot:
Code:
PurpsMZ.TreeSystem.Scene_Boot_onDatabaseLoaded = Scene_Boot.prototype.onDatabaseLoaded;
// prototype.onDatabaseLoaded
Scene_Boot.prototype.onDatabaseLoaded = function(){
PurpsMZ.TreeSystem.Scene_Boot_onDatabaseLoaded.call(this);
this.process_PurpsMZ_TreeSystem_Notetags();
console.log("In Scene_Boot");
},
// process_PurpsMZ_TreeSystem_Notetags
Scene_Boot.prototype.process_PurpsMZ_TreeSystem_Notetags = function(){
this.process_PurpsMZ_TreeSystem_Data();
this.process_PurpsMZ_TreeSystem_SkillRankRegExp();
this.process_PurpsMZ_TreeSystem_Actor_TreeRegExp();
this.process_PurpsMZ_TreeSystem_Class_TreeRegExp();
},
Code:
PurpsMZ.TreeSystem.Game_Actor_setup = Game_Actor.prototype.setup;
Game_Actor.prototype.setup = function(actorId) {
console.log("Setting up Actor: " + actorId);
PurpsMZ.TreeSystem.Game_Actor_setup.call(this, actorId);
this.initSp();
this.initSkillTrees();
};
Game_Actor.prototype.initSp = function() {
const actor = this.actor();
for (let i = 0; i < $dataClasses.length; i++) {
this.setSp(0,i);
this.setSpGained(0,i);
}
};
Game_Actor.prototype.initSkillTrees = function() {
this._activeTrees = [];
this._resetTimes = [];
this._dormantTrees = [];
this._spentSp = [];
this._dormantSpentSp = [];
let skillTrees,
classId;
if (Imported.VisuMZ_2_ClassChangeSystem && this.multiclasses().length > 1){
const classes = this.multiclasses();
for (let idx = 1; idx <= classes.length; ++idx){
classId = this.multiclassId(idx);
skillTrees = $dataClasses[classId].skillTrees;
if (!skillTrees) continue;
for(const tree of skillTrees){
//console.log(classId);
this.addSkillTree(tree);
}
}
} else{
classId = this.currentClass().id;
skillTrees = $dataClasses[classId].skillTrees;
for(const tree of skillTrees){
//console.log(classId);
this.addSkillTree(tree);
}
}
skillTrees = $dataActors[this.actorId()].skillTrees;
for(const tree of skillTrees){
//console.log(this.actorId());
this.addSkillTree(tree);
}
if (Object.keys(this._activeTrees).length > 0 && this._level > 1){
//Debug - Actor is higher than 1 and has a skill tree.
console.log("Gaining SP from Starting Level...");
let diff = this._level;
while (diff--){
this.gainSkillPoints();
}
}
};
Game_Actor.prototype.addSkillTree = function(treeId) {
const tree = treeId;
const Key = this.checkTree(tree);
if (!Key){
console.log("This tree doesn't exist.");
return;
}
console.log(this._activeTrees);
if (this._dormantTrees[Key] != undefined){
console.log("Has used this Tree before");
// console.log(this._dormantTrees[treeId]);
this._activeTrees[Key] = this._dormantTrees[Key];
this._spentSp[Key] = this._dormantSpentSp[Key];
}else{
//console.log(this.name() + "'s adding Skill Tree: " + tree['Key']);
this._activeTrees[Key] = clone(tree);
this._spentSp[Key] = [];
this._spentSp[Key]['spTotal'] = 0;
for(const node of this._activeTrees[Key].Nodes){
node['Key'] = node['Key'].toLowerCase().trim();
const skillId = node['Id'];
if(!skillId){
continue;
}
if (this.isLearnedSkill(skillId)){
node['rank'] = 1;
}else{
node['rank'] = 0;
}
this._spentSp[Key][node['Key']] = 0;
}
this._resetTimes[Key] = 0;
//console.log(this.name() + "'s Trees: ");
//console.log(this._activeTrees[Key]);
}
//console.log(this._activeTrees[Key]);
};
Code:
const clone = function(obj) {
if (null == obj || "object" != typeof obj) return obj;
var copy = obj.constructor();
for (var attr in obj) {
if (obj.hasOwnProperty(attr)) copy[attr] = clone(obj[attr]);
}
return copy;
}
New Game:
Continue:
Continue:
Any help would be great! I am using the VisuMZ sample project as a base, including this plugin, to test things out, but not sure why it is not loading the trees. If it's working on a new game, shouldn't it work on a continued save?
Look forward to the help!
