MV动态特征及影响
// ================================================ ==============================
//动态特征及影响
//通过Shaz
//最后更新:2015年11月26日
// ================================================ ==============================
/ *:
* @plugindesc让您在游戏过程中修改的特性和作用
* @author Shaz
*
* @帮帮我
*这个插件可以让你添加和删除性状演员,类武器,
*装甲,敌人和国家,以及添加和删除项目的效果和
*技能,动态,而无需状态设置仅用于这一目的。
*
*插件命令:
/*:
* @plugindesc Allows you to modify traits and effects during the game
* @author Shaz
*
* @help
* This plugin allows you to add and delete traits for Actors, Classes, Weapons,
* Armors, Enemies and States, and to add and delete effects for Items and
* Skills, dynamically, without needing states set up only for that purpose.
*
* Plugin Commands:
*
* AddTrait class id traitCode dataId [value]
* RemoveTrait class id traitCode [dataId] [value]
* GetTrait var class id traitCode dataId
*
* AddEffect class id effectCode dataId [value1] [value2]
* RemoveEffect class id effectCode [dataId] [value1] [value2]
* GetEffect var1 var2 class id effectCode dataId
*
* class = actor, class, skill, item, weapon, armor, enemy or state
* id = database id of the actor, class, skill, item, etc.
* traitCode = one of the codes listed below
* effectCode = one of the codes listed below
* dataId = refers to the drop-down list when adding traits or effects; when
* the list contains database items (like skills, equipment, states,
* elements), it is the database id of that item; when the list does
* not contain database items, it is the number of the item in the
* list, where the top item is 0
* var, var1, var2 = variable id that will contain the results of the
* GetTrait or GetEffect plugin calls
* value = a numeric value where traits need to have a value entered. Optional
* for the RemoveTrait command - if left out, ALL traits with the
* specified trait and data codes will be removed
* value1 = a numeric value where effects need to have one or two values
* entered. Optional for the RemoveEffect command - if left out, ALL
* effects with the specified effect and data codes will be removed.
* value2 = a numeric value where effects need to have one or two values
* entered. Optional for the RemoveEffect command - if left out, ALL
* effects with the specified effect and data codes will be removed.
*
* id, value, value1 and value2 can be formulae but must not contain spaces
*
* Values may be numbers or percentages. When percentages, sometimes they are
* whole numbers, and sometimes they are fractions
*
* To determine what numbers should be used, and what format, you could set the
* desired feature or effect up temporarily on a database item, then view the
* Data/*.json file after saving. The Online Javascript Beautifier can make
* it more readable: https://jsbeautifier.org/?without-codemirror
*
* Valid Trait Codes (value in JSON file - text to use in plugin):
* 11-TRAIT_ELEMENT_RATE 41-TRAIT_STYPE_ADD 61-TRAIT_ACTION_PLUS
* 12-TRAIT_DEBUFF_RATE 42-TRAIT_STYPE_SEAL 62-TRAIT_SPECIAL_FLAG
* 13-TRAIT_STATE_RATE 43-TRAIT_SKILL_ADD 63-TRAIT_COLLAPSE_TYPE
* 14-TRAIT_STATE_RESIST 44-TRAIT_SKILL_SEAL 64-TRAIT_PARTY_ABILITY
* 21-TRAIT_PARAM 51-TRAIT_EQUIP_WTYPE
* 22-TRAIT_XPARAM 52-TRAIT_EQUIP_ATYPE
* 23-TRAIT_SPARAM 53-TRAIT_EQUIP_LOCK
* 31-TRAIT_ATTACK_ELEMENT 54-TRAIT_EQUIP_SEAL
* 32-TRAIT_ATTACK_STATE 55-TRAIT_SLOT_TYPE
* 33-TRAIT_ATTACK_SPEED
* 34-TRAIT_ATTACK_TIMES
*
* Valid Effect Codes (value in JSON file - text to use in plugin):
* 11-EFFECT_RECOVER_HP 41-EFFECT_SPECIAL
* 12-EFFECT_RECOVER_MP 42-EFFECT_GROW
* 13-EFFECT_GAIN_TP 43-EFFECT_LEARN_SKILL
* 21-EFFECT_ADD_STATE 44-EFFECT_COMMON_EVENT
* 22-EFFECT_REMOVE_STATE
* 31-EFFECT_ADD_BUFF
* 32-EFFECT_ADD_DEBUFF
* 33-EFFECT_REMOVE_BUFF
* 34-EFFECT_REMOVE_DEBUFF
*/
(function() {
var _Game_Interpreter_pluginCommand = Game_Interpreter.prototype.pluginCommand;
Game_Interpreter.prototype.pluginCommand = function(command, args) {
switch(command.toUpperCase()) {
case 'ADDTRAIT':
this.addTrait(args);
break;
case 'REMOVETRAIT':
this.removeTrait(args);
break;
case 'GETTRAIT':
this.getTrait(args);
break;
case 'ADDEFFECT':
this.addEffect(args);
break;
case 'REMOVEEFFECT':
this.removeEffect(args);
break;
case 'GETEFFECT':
this.getEffect(args);
break;
default:
_Game_Interpreter_pluginCommand.call(this, command, args);
}
};
Game_Interpreter.prototype.addTrait = function(args) {
// * AddTrait class id traitCode dataId [value] - add a trait for an object
var obj = DataManager.getDatabaseObject(args[0], eval(args[1]));
var newTrait = {};
newTrait.code = Game_BattlerBase[args[2].toUpperCase()];
newTrait.dataId = eval(args[3]);
newTrait.value = args[4] ? eval(args[4]) : 0;
obj.traits.push(newTrait);
};
Game_Interpreter.prototype.removeTrait = function(args) {
// * RemoveTrait class id traitCode dataId [value] - remove a trait for an object
var obj = DataManager.getDatabaseObject(args[0], eval(args[1]));
var traitCode = Game_BattlerBase[args[2].toUpperCase()];
var dataId = eval(args[3]);
var value = eval(args[4]); // args[4] ? eval(args[4]) : null;
for (var i = obj.traits.length - 1; i >= 0; i--) {
var trait = obj.traits[i];
if (trait.code === traitCode &&
(trait.dataId === dataId || !dataId) &&
(trait.value === value || !value)) {
obj.traits.splice(i, 1);
}
}
};
Game_Interpreter.prototype.getTrait = function(args) {
// * GetTrait var class id traitCode dataId - return the value of an object's trait
var varId = parseInt(args[0]);
var obj = DataManager.getDatabaseObject(args[1], eval(args[2]));
var traitCode = Game_BattlerBase[args[3].toUpperCase()];
var dataId = eval(args[4]);
$gameVariables.setValue(varId, 0);
for (var i = 0; i < obj.traits.length; i++) {
var trait = obj.traits[i];
if (trait.code === traitCode && trait.dataId === dataId) {
$gameVariables.setFloat(varId, trait.value);
i = obj.traits.length;
}
}
};
Game_Interpreter.prototype.addEffect = function(args) {
// * AddEffect class id effectCode dataId [value1] [value2] - add an effect for an object
var obj = DataManager.getDatabaseObject(args[0], eval(args[1]));
var newEffect = {};
newEffect.code = Game_Action[args[2].toUpperCase()];
newEffect.dataId = eval(args[3]);
newEffect.value1 = args[4] ? eval(args[4]) : 0;
newEffect.value2 = args[5] ? eval(args[5]) : 0;
obj.effects.push(newEffect);
};
Game_Interpreter.prototype.removeEffect = function(args) {
// * RemoveEffect class id effectCode dataId [value1] [value2] - remove an effect from an object
var obj = DataManager.getDatabaseObject(args[0], eval(args[1]));
var effectCode = Game_Action[args[2].toUpperCase()];
var dataId = eval(args[3]);
var value1 = eval(args[4]); // args[4] ? eval(args[4]) : null;
var value2 = eval(args[5]); // args[5] ? eval(args[5]) : null;
for (var i = obj.effects.length - 1; i >= 0; i--) {
var effect = obj.effects[i];
if (effect.code === effectCode &&
(effect.dataId === dataId || !dataId) &&
(effect.value1 === value1 || !value1) &&
(effect.value2 === value2 || !value2)) {
obj.effects.splice(i, 1);
}
}
};
Game_Interpreter.prototype.getEffect = function(args) {
// * GetEffect var1 var2 class id effectCode dataId - return the value of an object's effect
var var1Id = parseInt(args[0]);
var var2Id = parseInt(args[1]);
var obj = DataManager.getDatabaseObject(args[2], eval(args[3]));
var effectCode = Game_Action[args[4].toUpperCase()];
var dataId = eval(args[5]);
$gameVariables.setValue(var1Id, 0);
$gameVariables.setValue(var2Id, 0);
for (var i = 0; i < obj.effects.length; i++) {
var effect = obj.effects[i];
if (effect.code === effectCode && effect.dataId === dataId) {
$gameVariables.setFloat(var1Id, effect.value1);
$gameVariables.setFloat(var2Id, effect.value2);
i = obj.effects.length;
}
}
};
// Allow non-integer values to be saved in Game_Variables
Game_Variables.prototype.setFloat = function(variableId, value) {
if (variableId > 0 && variableId < $dataSystem.variables.length) {
this._data[variableId] = value;
this.onChange();
}
};
// In the DataManager, we need to copy away the original list of
// traits and effects on launching the game, then restoring them
// whenever a new game is started or a game is loaded (to clear
// any changes that may have been made during gameplay).
// When saving a game we also need to save the current set of traits
// and effects, and when loading we need to repopulate the saved
// info back into the database
var _DataManager_isDatabaseLoaded = DataManager.isDatabaseLoaded;
DataManager.isDatabaseLoaded = function() {
var isLoaded = _DataManager_isDatabaseLoaded.call(this);
if (isLoaded && !this._TraitEffectsSet) {
this._TraitEffectsSet = true;
this.setTraitsAndEffects();
}
return isLoaded;
};
var _DataManager_createGameObjects = DataManager.createGameObjects;
DataManager.createGameObjects = function() {
_DataManager_createGameObjects.call(this);
this.resetTraitsAndEffects();
};
var _DataManager_makeSaveContents = DataManager.makeSaveContents;
DataManager.makeSaveContents = function() {
var contents = _DataManager_makeSaveContents.call(this);
contents.traits = this.gatherTraits();
contents.effects = this.gatherEffects();
return contents;
};
var _DataManager_extractSaveContents = DataManager.extractSaveContents;
DataManager.extractSaveContents = function(contents) {
_DataManager_extractSaveContents.call(this, contents);
this.loadTraits(contents.traits || {});
this.loadEffects(contents.effects || {});
};
DataManager.setTraitsAndEffects = function() {
$dataActors.forEach(function(obj) {this.setTraits(obj)}.bind(this));
$dataClasses.forEach(function(obj) {this.setTraits(obj)}.bind(this));
$dataSkills.forEach(function(obj) {this.setEffects(obj)}.bind(this));
$dataItems.forEach(function(obj) {this.setEffects(obj)}.bind(this));
$dataWeapons.forEach(function(obj) {this.setTraits(obj)}.bind(this));
$dataArmors.forEach(function(obj) {this.setTraits(obj)}.bind(this));
$dataEnemies.forEach(function(obj) {this.setTraits(obj)}.bind(this));
$dataStates.forEach(function(obj) {this.setTraits(obj)}.bind(this));
};
DataManager.setTraits = function(obj) {
if (obj) {
obj.savedTraits = JsonEx.makeDeepCopy(obj.traits);
}
};
DataManager.setEffects = function(obj) {
if (obj) {
obj.savedEffects = JsonEx.makeDeepCopy(obj.effects);
}
};
DataManager.resetTraitsAndEffects = function() {
$dataActors.forEach(function(obj) {this.resetTraits(obj)}.bind(this));
$dataClasses.forEach(function(obj) {this.resetTraits(obj)}.bind(this));
$dataSkills.forEach(function(obj) {this.resetEffects(obj)}.bind(this));
$dataItems.forEach(function(obj) {this.resetEffects(obj)}.bind(this));
$dataWeapons.forEach(function(obj) {this.resetTraits(obj)}.bind(this));
$dataArmors.forEach(function(obj) {this.resetTraits(obj)}.bind(this));
$dataEnemies.forEach(function(obj) {this.resetTraits(obj)}.bind(this));
$dataStates.forEach(function(obj) {this.resetTraits(obj)}.bind(this));
};
DataManager.resetTraits = function(obj) {
if (obj && obj.savedTraits) {
obj.traits = JsonEx.makeDeepCopy(obj.savedTraits);
}
};
DataManager.resetEffects = function(obj) {
if (obj && obj.savedEffects) {
obj.effects = JsonEx.makeDeepCopy(obj.savedEffects);
}
};
DataManager.gatherTraits = function() {
var allTraits = {};
allTraits['actors'] = this.pullTraits($dataActors);
allTraits['classes'] = this.pullTraits($dataClasses);
allTraits['weapons'] = this.pullTraits($dataWeapons);
allTraits['armors'] = this.pullTraits($dataArmors);
allTraits['enemies'] = this.pullTraits($dataEnemies);
allTraits['states'] = this.pullTraits($dataStates);
return allTraits;
};
DataManager.gatherEffects = function() {
var allEffects = {};
allEffects['skills'] = this.pullEffects($dataSkills);
allEffects['items'] = this.pullEffects($dataItems);
return allEffects;
};
DataManager.pullTraits = function(container) {
var traits = [];
container.forEach(function(obj) {
if (obj) {
traits.push(JsonEx.makeDeepCopy(obj.traits));
} else {
traits.push(null);
}
})
return traits;
};
DataManager.pullEffects = function(container) {
var effects = [];
container.forEach(function(obj) {
if (obj) {
effects.push(JsonEx.makeDeepCopy(obj.effects));
} else {
effects.push(null);
}
})
return effects;
};
DataManager.loadTraits = function(allTraits) {
this.pushTraits($dataActors, allTraits['actors'] || []);
this.pushTraits($dataClasses, allTraits['classes'] || []);
this.pushTraits($dataWeapons, allTraits['weapons'] || []);
this.pushTraits($dataArmors, allTraits['armors'] || []);
this.pushTraits($dataEnemies, allTraits['enemies'] || []);
this.pushTraits($dataStates, allTraits['states'] || []);
};
DataManager.loadEffects = function(allEffects) {
this.pushEffects($dataSkills, allEffects['skills'] || []);
this.pushEffects($dataItems, allEffects['items'] || []);
};
DataManager.pushTraits = function(container, traits) {
traits.forEach(function(obj, index) {
if (obj) {
container[index].traits = JsonEx.makeDeepCopy(obj);
}
})
};
DataManager.pushEffects = function(container, effects) {
effects.forEach(function(obj, index) {
if (obj) {
container[index].effects = JsonEx.makeDeepCopy(obj);
}
})
};
DataManager.getDatabaseObject = function(container, objId) {
switch (container.toUpperCase()) {
case 'ACTOR': return $dataActors[objId]; break;
case 'CLASS': return $dataClasses[objId]; break;
case 'SKILL': return $dataSkillls[objId]; break;
case 'ITEM': return $dataItems[objId]; break;
case 'WEAPON': return $dataWeapons[objId]; break;
case 'ARMOR': return $dataArmors[objId]; break;
case 'ENEMY': return $dataEnemies[objId]; break;
case 'STATE': return $dataStates[objId]; break;
}
};
})();