//=============================================================================
// Enemy Death Exp
// MRP_EnemyDeathExp.js
// By Magnus0808 || Magnus Rubin Peterson
//=============================================================================
/*:
* @plugindesc Individually Experiance on Enemy Deaths
* @author Magnus0808
*
* @help This plugin changes the way exp is calculated.
* It also displays the exp gain above the actors head. The code for this is
* heavily inspired by HimeWorks' Battle Action Exp -> Battle Exp Popup
*
* This plugin is intended to be used with a enemy level plugin such as Yanfly's
* Enemy Levels. However, this is not necesarry. In case you use Yanfly's Enemy
* Levels, then this plugin will overwrite the exp formular!
*
* You can specify the exp formular using the meta tag: <expFormular:FORMULAR>
* E.g. <expFormular:
* value = 10 * actor.level - this.level;
* >
* value is the exp given.
*
* If you do not have an enemy level plugin then you can specify the enemy level
* using the meta tag: <level:ENEMY_LEVEL>
* E.g <level:10>
*
*
* @param Default Exp Formular
* @type note
* @default "var diffL = (actor.level + 6 - this.level).clamp(0, 11);\nvar multL = [5, 4.3, 3.7, 3.2, 2.8, 2.4, 2, 1.8, 1.6, 1.4, 1.2, 1][diffL];\nvalue = Math.round(80 * multL);"
*
* @param Distribute Exp
* @type boolean
* @desc If true then the exp will be distributed between the party instead of everyone getting it.
* @default true
*/
var Imported = Imported || {};
Imported.MRP_EnemyDeathExp = true;
var MRP = MRP || {};
MRP.EnemyDeathExp = MRP.EnemyDeathExp || {};
(function() {
MRP.EnemyDeathExp.parameters = PluginManager.parameters('MRP_EnemyDeathExp');;
MRP.EnemyDeathExp.defaultExpFormular = JSON.parse(String(MRP.EnemyDeathExp.parameters['Default Exp Formular']));
MRP.EnemyDeathExp.distributeExp = (String(MRP.EnemyDeathExp.parameters['Distribute Exp']) == "true");
//-----------------------------------------------------------------------------
// BattleManager
//
// Changes to the BattleManager
BattleManager.gainExp = function(enemy) {
console.log("BM GAIN EXP");
if(!enemy) return 0;
$gameParty.allMembers().forEach(function(actor) {
var exp = MRP.EnemyDeathExp.distributeExp ? Math.ceil(enemy.exp(actor) / $gameParty.aliveMembers().length) : enemy.exp(actor);
BattleManager._gainedTotalExp += exp;
actor.gainExp(exp);
});
};
BattleManager.displayExp = function() {
var exp = this._gainedTotalExp;
if (exp > 0) {
var text = TextManager.obtainExp.format(exp, TextManager.exp);
$gameMessage.add('\\.' + text);
}
};
MRP.EnemyDeathExp.BattleManager_initMembers = BattleManager.initMembers;
BattleManager.initMembers = function() {
MRP.EnemyDeathExp.BattleManager_initMembers.call(this);
this._gainedTotalExp = 0;
};
// Compatibility stuff
if(Imported.YEP_VictoryAftermath) {
MRP.EnemyDeathExp.BattleManager_startBattle = BattleManager.startBattle;
BattleManager.startBattle = function() {
MRP.EnemyDeathExp.BattleManager_startBattle.call(this);
if(Imported.YEP_X_AftermathLevelUp) this.prepareVictoryPreLevel();
$gameParty.allMembers().forEach(function(actor) {
actor._preVictoryExp = actor.currentExp();
actor._preVictoryLv = actor._level;
}, this);
};
BattleManager.prepareVictoryInfo = function() {
$gameParty.allMembers().forEach(function(actor) {
ImageManager.loadFace(actor.faceName());
actor._victoryPhase = true;
actor._victorySkills = [];
}, this);
this.gainRewards();
$gameParty.allMembers().forEach(function(actor) {
actor._expGained = actor.currentExp() - actor._preVictoryExp;
actor._postVictoryLv = actor._level;
}, this);
if(Imported.YEP_X_AftermathLevelUp) this.prepareVictoryPostLevel();
};
}
//-----------------------------------------------------------------------------
// Game_Enemy
//
// Changes to Game_Enemy
Object.defineProperty(Game_Enemy.prototype, 'level', {
get: function() {
return this._level;
},
configurable: true
});
MRP.EnemyDeathExp.Game_Enemy_die = Game_Enemy.prototype.die;
Game_Enemy.prototype.die = function() {
MRP.EnemyDeathExp.Game_Enemy_die.call(this);
BattleManager.gainExp(this);
};
MRP.EnemyDeathExp.Game_Enemy_setup = Game_Enemy.prototype.setup;
Game_Enemy.prototype.setup = function(enemyId, x, y) {
MRP.EnemyDeathExp.Game_Enemy_setup.call(this, enemyId, x, y);
this._level = this._level || eval(this.enemy().meta.level || 1);
};
Game_Enemy.prototype.exp = function(actor) {
if(!actor) return 0;
var value = 0;
var formular = this.enemy().meta.expFormular || MRP.EnemyDeathExp.defaultExpFormular;
value = eval(formular)
return value;
};
//-----------------------------------------------------------------------------
// Game_Actor
//
// Changes to Game_Actor
MRP.EnemyDeathExp.Game_Actor_changeExp = Game_Actor.prototype.changeExp;
Game_Actor.prototype.changeExp = function(exp, show) {
var gainedExp = exp - this.currentExp();
this._expGain = gainedExp;
MRP.EnemyDeathExp.Game_Actor_changeExp.call(this, exp, show);
};
Game_Actor.prototype.gainExp = function(exp) {
console.log("GAINED EXP")
var newExp = this.currentExp() + Math.round(exp * this.finalExpRate());
this.changeExp(newExp, this.shouldDisplayLevelUp());
};
//-----------------------------------------------------------------------------
// Sprite_Actor
//
// Changes to Sprite_Actor
MRP.EnemyDeathExp.Sprite_Actor_initMembers = Sprite_Actor.prototype.initMembers;
Sprite_Actor.prototype.initMembers = function() {
MRP.EnemyDeathExp.Sprite_Actor_initMembers.call(this);
this.createExpSprite();
};
Sprite_Actor.prototype.createExpSprite = function() {
this._expSprite = new Sprite_ExpGain();
this._expSprite.x = this.x + this.damageOffsetX() - 20;
this._expSprite.y = this.y + this.damageOffsetY() - 140;
this.addChild(this._expSprite);
};
MRP.EnemyDeathExp.Sprite_Actor_setBattler = Sprite_Actor.prototype.setBattler;
Sprite_Actor.prototype.setBattler = function(battler) {
var changed = (battler !== this._actor);
if (changed) {
this._expSprite.setup(battler, this._expSprite.x, this._expSprite.y);
}
MRP.EnemyDeathExp.Sprite_Actor_setBattler.call(this, battler);
};
MRP.EnemyDeathExp.Sprite_Actor_update = Sprite_Actor.prototype.update;
Sprite_Actor.prototype.update = function() {
MRP.EnemyDeathExp.Sprite_Actor_update.call(this);
if (this._actor && this._actor.isSpriteVisible()) {
this._expSprite.update();
}
}
//-----------------------------------------------------------------------------
// Sprite_ExpGain
//
// The sprite that shows the exp gained.
function Sprite_ExpGain() {
this.initialize.apply(this, arguments);
}
Sprite_ExpGain.prototype = Object.create(Sprite_Base.prototype);
Sprite_ExpGain.prototype.constructor = Sprite_ExpGain;
Sprite_ExpGain.prototype.initialize = function() {
Sprite_Base.prototype.initialize.call(this);
this._duration = 0;
};
Sprite_ExpGain.prototype.setup = function(battler, x, y) {
this.originalX = x;
this.originalY = y;
this._battler = battler;
this.bitmap = new Bitmap(100, 200);
this.bitmap.textColor = "rgb(0, 255, 0)";
this.bitmap.fontSize = 20;
};
Sprite_ExpGain.prototype.play = function(exp) {
this._battler._expGain = 0;
this.y = this.originalY;
this.bitmap.clear();
this.bitmap.drawText(exp + TextManager.expA, 0, 0, 100, 200, 'center');
this._duration = 90;
}
Sprite_ExpGain.prototype.update = function() {
if (this._duration > 30) {
this.y -= 0.5;
}
if (this._duration > 0) {
this.show();
this._duration -= 1
}else {
this.hide();
if(this._battler && this._battler._expGain > 0) this.play(this._battler._expGain);
}
};
Sprite_ExpGain.prototype.isPlaying = function() {
return this._duration > 0;
};
})();