//=============================================================================
// Local Functions
//=============================================================================
TAA.skm.functions = TAA.skm.functions || {};
TAA.skm.functions.prepareUnleveledList = function(params){
var list = params ? JSON.parse(params) : [];
var result = [];
if(!list || list.length <= 0) return result;
for(var i=0; i<list.length; i++){
if(!isNaN(list)){
result.push(parseInt(list));
}
}
return result;
};
for(var i=0; i < TAA.skm.Parameters.PMSkills.length; i++){
var skmData = this.parsePMSkillItem(JSON.parse(TAA.skm.Parameters.PMSkills));
var id = skmData[this._idObject];
if($dataSkillLevels[id] !== undefined)
console.error("Duplicated ID: " + id + ". Keeping the first entry.");
else
$dataSkillLevels[id] = skmData;
}
};
/**
* Auxiliary function used to get special params from skill by level
*
* @static
* @method getCodeData
*/
SkillManager.getCodeData = function(skill, subject, level, type){
var code = undefined;
var a = subject;
var id = this.getSkillId(skill);
if(level === undefined)
level = TAA.skm.Parameters.MinLevel;
if(id === undefined) return code;
if(a._skillMastery[id] === undefined && type !== 'requirements') return code;
/**
* Checks if skill requirements are met for a specified skill and level
*
* @static
* @method requirementsMet
*/
SkillManager.requirementsMet = function(skill, level, subject){
var code = undefined;
var a = subject;
var id = this.getSkillId(skill);
/**
* Returns how much XP is required to reach the next level
*
* @static
* @method getXpForLevel
*/
SkillManager.getXpForLevel = function(skillId, level){
var skillData = $dataSkillLevels[skillId];
var xpFormula = this.getXpFormula(skillData).replace(/level/g, level);
return eval(xpFormula);
};
Game_BattlerBase.prototype.setSkillXp = function(skillId, xp){
if(TAA.skm.Parameters.Unleveled.contains(skillId)) return;
var level = this.getSkillLevel(skillId);
if(level < 0) return;
var formula = SkillManager.getXpFormula($dataSkillLevels[skillId]);
if(!SkillManager.requirementsMet($dataSkills[skillId], level, this)){
this._skillMastery[skillId].xp = 0;
}
else{
// Ensures xp is always set below the threshold for the next level
if(formula && xp >= eval(formula)){
xp = eval(formula + "-1");
}
this._skillMastery[skillId].xp = xp;
}
};
let currentLevel = this._skillMastery[skill.id].level;
for(var i = TAA.skm.Parameters.MinLevel; i<=currentLevel; i++){
let tpCost = skill.leveledTpCost(i);
let mpCost = skill.leveledMpCost(i);
Game_Battler.prototype.processSkillUses = function(){
for(var i=0; i < this._skillUses.length; i++){
var id = this._skillUses;
var previousLevel = this._skillMastery[id].level;
if(this.increaseSkillUseCount(id, this._skillMastery[id].uses)){
var newLevel = this._skillMastery[id].level;
if(newLevel > previousLevel){
var playAnim = false;
var mirror = false;
switch(TAA.skm.Parameters.LvlUpAnimConfig){
case "Actors Only":
if(this.isActor())
playAnim = true;
break;
case "Enemies Only":
if(this.isEnemy()){
playAnim = true;
mirror = true;
}
break;
case "Always":
playAnim = true;
break;
default:
playAnim = false;
}
// show text on level up?
if(TAA.skm.Parameters.LvlUpMsg !== "" && (this.isActor() || (this.isEnemy() && TAA.skm.Parameters.EnemyLvlUpMsg))){
var text = this.prepareSkillLvlUpText(id);
BattleManager.skillLevelUpMsg(text);
}
if(playAnim && TAA.skm.Parameters.LvlUpAnimation > 0){
let anim = TAA.skm.Parameters.LvlUpAnimation;
if(this.isMaxLevelSkill(id) && TAA.skm.Parameters.MaxLvMsgEnabled && TAA.skm.Parameters.MaxLvAnimation > 0)
anim = TAA.skm.Parameters.MaxLvAnimation;
if(Utils.RPGMAKER_NAME === 'MZ')
$gameTemp.requestAnimation([this], anim, mirror);
else
this.startAnimation(anim, mirror);
}
}
}
if(this._skillMastery[id].uses > 0) this._skillMastery[id].uses = 0;
}
this.resetSkillUseCounter();
};
TAA.skm.alias.GameAction.itemCri = Game_Action.prototype.itemCri;
Game_Action.prototype.itemCri = function(target){
var result = TAA.skm.alias.GameAction.itemCri.call(this, target);
switch(this._skmCriticalModifier){
case 'force':
case 'always':
case 'enable':
case '2':
result = 1;
break;
case 'never':
case 'disable':
case '1':
result = 0;
break;
default:
// no action
}
return result;
};
TAA.skm.alias.GameAction.makeDamageValue = Game_Action.prototype.makeDamageValue;
Game_Action.prototype.makeDamageValue = function(target, critical){
this._skmIsCritical = critical;
var value = TAA.skm.alias.GameAction.makeDamageValue.call(this, target, critical);
value = this.applySkillModifiers(value, undefined, target);
return value;
};
TAA.skm.alias.GameAction.evalDamageFormula = Game_Action.prototype.evalDamageFormula;
Game_Action.prototype.evalDamageFormula = function(target){
if(this.item().leveledDamage === undefined)
return TAA.skm.alias.GameAction.evalDamageFormula.call(this, target);
try{
var item = this.item();
var a = this.subject();
var b = target;
var v = $gameVariables._data;
var sign = ([3, 4].contains(item.damage.type) ? -1 : 1);
var value = Math.max(eval(item.leveledDamage(a.skillLevel(item.id))), 0) * sign;
if(isNaN(value)) value = 0;
return value;
} catch(e) {
return 0;
}
};
TAA.skm.alias.GameAction.applyItemUserEffect = Game_Action.prototype.applyItemUserEffect;
Game_Action.prototype.applyItemUserEffect = function(target){
var skill = this.item();
if(skill.leveledTpGain === undefined || skill.id === undefined)
TAA.skm.alias.GameAction.applyItemUserEffect.call(this, target);
else{
var level = this.subject().skillLevel(skill.id);
var value = Math.floor(skill.leveledTpGain(level) * this.subject().tcr);
this.subject().gainSilentTp(value);
}
};
TAA.skm.alias.GameSwitches = TAA.skm.alias.GameSwitches || {};
Game_Switches.prototype.setValueOnRange = function(lowerRange, upperRange, operation){
var op = this.convertOperationToEval('sw', operation);
var sw = lowerRange;
while(sw <= upperRange){
try{
$gameSwitches.setValue(sw, eval(op));
} catch(e){
console.error("Failed to eval sentence: " + op);
}
sw++;
}
};
Game_Switches.prototype.convertOperationToEval = function(swVarName, operation){
var op = 'false';
switch(String(operation)){
case 'on':
case 'true':
op = 'true';
break;
case 'off':
case 'false':
op = 'false';
break;
case 'toggle':
op = "!$gameSwitches.value(" + swVarName + ")";
break;
default:
if(String(operation).match(/switch ([0-9]+)/i))
op = "$gameSwitches.value(" + RegExp.$1 + ")";
else
op = "$gameSwitches.value(" + swVarName + ")";
}
if (item) {
if(Utils.RPGMAKER_NAME === 'MZ')
var iconBoxWidth = ImageManager.iconWidth + 4;
else
var iconBoxWidth = Window_Base._iconWidth + 4;
this.resetTextColor();
this.drawIcon(item.iconIndex, x + 2, y + 2);
var name = this.setupSkillMasteryName(item, this._actor.skillLevel(item.id));
this.drawText(name, x + iconBoxWidth, y, width - iconBoxWidth);
}
}
else
TAA.skm.alias.WindowBase.drawItemName.call(this, item, x, y, width);
};
Window_Base.prototype.drawSKMGauge = function(item, x, y, width, isVertical){
var gX = x;
var gY = y;
if(this._actor === undefined) return;
var colors = this.getSKMGaugeColors(item);
if(Utils.RPGMAKER_NAME === 'MZ'){
var color1 = ColorManager.textColor(colors[0]);
var color2 = ColorManager.textColor(colors[1]);
var backColor = ColorManager.textColor(TAA.skm.Parameters.GaugeBgColor);
var outlineColor = ColorManager.textColor(TAA.skm.Parameters.GaugeOutlineColor);
var iconWidth = ImageManager.iconWidth;
}
else{
var color1 = this.textColor(colors[0]);
var color2 = this.textColor(colors[1]);
var backColor = this.textColor(TAA.skm.Parameters.GaugeBgColor);
var outlineColor = this.textColor(TAA.skm.Parameters.GaugeOutlineColor);
var iconWidth = Window_Base._iconWidth;
}
var gHeight = !isNaN(TAA.skm.Parameters.GaugeHeight) ? TAA.skm.Parameters.GaugeHeight : 32;
var gWidth = !isNaN(TAA.skm.Parameters.GaugeWidth) ? TAA.skm.Parameters.GaugeWidth : 6;
for(var i=1; i<=level; i++){
let name = TAA.skm.Parameters.SkillLevelWindow.SkillName.replace(/%1/g,SkillManager.getName(skill, i));
let mpCost = SkillManager.getMpCost(skill, i);
let tpCost = SkillManager.getTpCost(skill, i);
let cost = {mp:mpCost, tp:tpCost};