Skip to content

Instantly share code, notes, and snippets.

@Tsumio
Created February 2, 2018 05:24
Show Gist options
  • Save Tsumio/e52634071e38ecc3bb2782c092131630 to your computer and use it in GitHub Desktop.
Save Tsumio/e52634071e38ecc3bb2782c092131630 to your computer and use it in GitHub Desktop.
For blog.
(function() {
'use strict';
////=============================================================================
//// Game_Actor
//// Override for Chain MP cost.
////=============================================================================
Game_Actor.prototype.canPaySkillCost = function(skill) {
return this._tp >= this.skillTpCost(skill) && ChainManager.getPartyMP() >= this.skillMpCost(skill);
};
Game_Actor.prototype.paySkillCost = function(skill) {
this._mp -= this.skillMpCost(skill);
this._tp -= this.skillTpCost(skill);
ChainManager.tryExecuteChainMpCost(this);
};
Game_Actor.prototype.chainSkillMpCost = function(cost) {
this._mp -= cost;
ChainManager.tryExecuteChainMpCost(this);
};
////=============================================================================
//// BattleManager
//// Override for Chain MP cost.
////=============================================================================
const _BattleManager_startBattle = BattleManager.startBattle;
BattleManager.startBattle = function() {
_BattleManager_startBattle.call(this);
ChainManager.initializeBattlers();
};
////=============================================================================
//// ChainManager
//// Manage Chain MP cost.
////=============================================================================
class ChainManager {
static initializeBattlers() {
this._battlers = $gameParty.battleMembers();
console.log("initializeBattlers");
}
/**
* @return {Array}
*/
static get battlers() {
return this._battlers;
}
static tryExecuteChainMpCost(currentBattler) {
const nextBattler = ChainManager.getNextBattler(currentBattler);
console.log(nextBattler);
if(nextBattler && currentBattler._mp <= 0) {
nextBattler.chainSkillMpCost(Math.abs(currentBattler._mp));
currentBattler._mp = 0;
}
}
static getPartyMP() {
let total = 0;
this.battlers.forEach(function(value, index) {
total += value.mp;
});
return total;
}
static getNextBattler(currentBattler) {
let nextIndex;
this.battlers.some(function(battler, index) {
if(battler === currentBattler) {
nextIndex = (index + 1)%this.battlers.length;
return true;
}
}, this);
return this.battlers[nextIndex];
}
}
})();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment