Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //=============================================================================
- // Bobstah Plugins
- // BOB_CustomStats.js
- // Version: 1.2.1
- //=============================================================================
- var Imported = Imported || {};
- Imported.BOB_CustomStats = true;
- var Bobstah = Bobstah || {};
- Bobstah.CustomStats = Bobstah.CustomStats || {};
- //=============================================================================
- /*:
- * @plugindesc Allows you to create custom stats for damage formulas or any other use.
- * @author Bobstah
- *
- * ============================================================================
- * Introduction
- * ============================================================================
- * A simple custom stat plugin. Does not display the stats in
- * the actor Status window.
- *
- * ============================================================================
- * Notetags
- * ============================================================================
- * Actor/Enemy/Class
- * <CustomStat: statName=statValue>
- * statName - The name you want to reference this stat with.
- * statValue - The default value of your stat. Must be a number.
- *
- * Weapon/Armor/State
- * <CustomStat: statName+statValue>
- * <CustomStat: statName-statValue>
- * ============================================================================
- * Examples
- * ============================================================================
- * After setting a custom stat to an actor/enemy, you reference
- * it in damage formulas or other code just like any other
- * stat. Below is a sample damage formula for the a stat
- * named 'sanity':
- * 100 + a.sanity
- *
- * Let's say you gave the enemy a stat named 'insanity':
- * (100+ a.sanity) - b.insanity
- *
- */
- Bobstah.CustomStats.statList = [];
- Bobstah.CustomStats.createStat = function(param, value) {
- var newStat = {};
- newStat[param] = {};
- newStat[param].get = function() {
- if (this.customStats[param] && this.customStats[param] !== null) {
- return this.customStats[param];
- } else if (typeof(this._classId) !== "undefined") {
- if ($dataClasses[this._classId][param] && $dataClasses[this._classId][param] !== null) {
- return $dataClasses[this._classId][param];
- } else {
- return 0;
- }
- } else {
- return 0;
- }
- };
- newStat[param].set = function(val) {
- if (this.customStats[param] && this.customStats[param] !== null) {
- this.customStats[param] = val;
- } else if (typeof(this._classId) !== "undefined") {
- if ($dataClasses[this._classId][param] && $dataClasses[this._classId][param] !== null) {
- $dataClasses[this.classId][param] = val;
- }
- } else {
- this.customStats[param] = val;
- }
- };
- newStat[param].configurable = true;
- return newStat;
- };
- Bobstah.CustomStats.applyCustomStats = function(obj) {
- obj.customStats = obj.customStats || {};
- for (i = 0; i < Bobstah.CustomStats.statList.length; i++) {
- var param = Bobstah.CustomStats.statList[i];
- var value = null;
- if (typeof(obj.customStats[param]) !== "undefined") {
- value = obj.customStats[param];
- }
- if (typeof(obj[param]) !== "undefined") { continue; }
- var newStat = Bobstah.CustomStats.createStat(param, value);
- Object.defineProperties(obj,newStat);
- obj.customStats[param] = value;
- }
- };
- //=============================================================================
- // DataManager
- //=============================================================================
- Bobstah.CustomStats.DataManager_isDatabaseLoaded = DataManager.isDatabaseLoaded;
- DataManager.isDatabaseLoaded = function() {
- if (!Bobstah.CustomStats.DataManager_isDatabaseLoaded.call(this)) return false;
- DataManager.processBobstahCustomStatsNotes($dataActors);
- DataManager.processBobstahCustomStatsNotes($dataClasses);
- DataManager.processBobstahCustomStatsNotes($dataEnemies);
- DataManager.processBobstahCustomStatsModNotes($dataWeapons);
- DataManager.processBobstahCustomStatsModNotes($dataArmors);
- DataManager.processBobstahCustomStatsModNotes($dataStates);
- DataManager.processBobstahCustomStats($dataActors);
- DataManager.processBobstahCustomStats($dataClasses);
- DataManager.processBobstahCustomStats($dataEnemies);
- return true;
- };
- DataManager.processBobstahCustomStatsNotes = function(group) {
- var statregex = /<CustomStat:\s*([A-z]+)=(\d+)\s*>/ig
- for (var n = 1; n < group.length; n++) {
- var obj = group[n];
- var notedata = obj.note;
- obj.customStats = obj.customStats || {};
- while(stat = statregex.exec(notedata)) {
- var param = stat[1];
- var value = Number(stat[2]);
- var newStat = Bobstah.CustomStats.createStat(param, value);
- Object.defineProperties(obj,newStat);
- if (Bobstah.CustomStats.statList.indexOf(param) === -1) {
- Bobstah.CustomStats.statList.push(param);
- }
- obj.customStats[param] = value;
- }
- }
- };
- DataManager.processBobstahCustomStatsModNotes = function(group) {
- var statregex = /<CustomStat:\s*([A-z]+)([+\-])(\d+)\s*>/ig;
- for (var n = 1; n < group.length; n++) {
- var obj = group[n];
- var notedata = obj.note;
- obj.customStats = obj.customStats || {};
- while(stat = statregex.exec(notedata)) {
- var param = stat[1];
- var op = stat[2];
- var value = Number(stat[3]);
- obj.customStats[param] = {'operation': op, 'value':value};
- }
- }
- };
- Bobstah.CustomStats.DataManager_makeSaveContents = DataManager.makeSaveContents;
- DataManager.makeSaveContents = function() {
- $gameSystem.storeCustomStats(Bobstah.CustomStats.statList);
- return Bobstah.CustomStats.DataManager_makeSaveContents.call(this);
- };
- Bobstah.CustomStats.DataManager_extractSaveContents = DataManager.extractSaveContents;
- DataManager.extractSaveContents = function(contents) {
- Bobstah.CustomStats.DataManager_extractSaveContents.call(this, contents);
- Bobstah.CustomStats.statList = $gameSystem.getCustomStats();
- DataManager.processBobstahCustomStats($gameActors._data);
- };
- DataManager.processBobstahCustomStats = function(group) {
- for (var n = 1; n < group.length; n++) {
- var obj = group[n];
- Bobstah.CustomStats.applyCustomStats(obj);
- }
- };
- //=============================================================================
- // Game_System
- //=============================================================================
- Game_System.prototype.storeCustomStats = function(arrayin) {
- this.customStatList = arrayin;
- };
- Game_System.prototype.getCustomStats = function() {
- return this.customStatList;
- };
- //=============================================================================
- // Game_BattlerBase
- //=============================================================================
- Game_BattlerBase.prototype.loadCustomStats = function(myId, datalist) {
- //Load Custom Stats
- Bobstah.CustomStats.applyCustomStats(this);
- for (var statId in this.customStats) {
- if (typeof(datalist[myId].customStats[statId]) !== "undefined") {
- this.customStats[statId] = datalist[myId].customStats[statId];
- }
- }
- };
- Game_BattlerBase.prototype.handleCustomStats = function(obj, opposite) {
- opposite = opposite || false;
- for (var statId in obj.customStats) {
- var stat = obj.customStats[statId];
- if (this.customStats[statId] === null) {
- this.customStats[statId] = 0;
- }
- switch (stat.operation) {
- case "-":
- this.customStats[statId] = (opposite === false ? this.customStats[statId] - stat.value : this.customStats[statId] + stat.value);
- break;
- default:
- this.customStats[statId] = (opposite === false ? this.customStats[statId] + stat.value : this.customStats[statId] - stat.value);
- break;
- }
- }
- };
- Bobstah.CustomStats.GameBattlerBase_addNewState = Game_BattlerBase.prototype.addNewState;
- Game_BattlerBase.prototype.addNewState = function(stateId) {
- var res = Bobstah.CustomStats.GameBattlerBase_addNewState.call(this, stateId);
- if (stateId !== null) {
- var state = $dataStates[stateId];
- this.handleCustomStats(state);
- }
- return res;
- };
- //=============================================================================
- // Game_Battler
- //=============================================================================
- Bobstah.CustomStats.GameBattler_removeState = Game_Battler.prototype.removeState;
- Game_Battler.prototype.removeState = function(stateId) {
- var res = Bobstah.CustomStats.GameBattler_removeState.call(this, stateId);
- if (stateId !== null) {
- var state = $dataStates[stateId];
- this.handleCustomStats(state, true);
- }
- return res;
- };
- //=============================================================================
- // Game_Actor
- //=============================================================================
- Bobstah.CustomStats.GameActor_setup = Game_Actor.prototype.setup;
- Game_Actor.prototype.setup = function(actorId) {
- Bobstah.CustomStats.GameActor_setup.call(this, actorId);
- this.loadCustomStats(actorId, $dataActors);
- };
- Bobstah.CustomStats.GameActor_changeEquip = Game_Actor.prototype.changeEquip;
- Game_Actor.prototype.changeEquip = function(slotId, item) {
- if (this.equips()[slotId]) {
- var oldItem = this.equips()[slotId];
- this.handleCustomStats(oldItem, true);
- }
- var res = Bobstah.CustomStats.GameActor_changeEquip.call(this, slotId, item);
- if (item !== null) {
- this.handleCustomStats(item);
- }
- return res;
- };
- //=============================================================================
- // Game_Enemy
- //=============================================================================
- Bobstah.CustomStats.GameEnemy_setup = Game_Enemy.prototype.setup;
- Game_Enemy.prototype.setup = function(enemyId, x, y) {
- Bobstah.CustomStats.GameEnemy_setup.call(this, enemyId, x, y);
- this.loadCustomStats(enemyId, $dataEnemies);
- };
Advertisement
Add Comment
Please, Sign In to add comment