Guest User

Untitled

a guest
Nov 2nd, 2015
365
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 10.34 KB | None | 0 0
  1. //=============================================================================
  2. // Bobstah Plugins
  3. // BOB_CustomStats.js
  4. // Version: 1.2.1
  5. //=============================================================================
  6.  
  7. var Imported = Imported || {};
  8. Imported.BOB_CustomStats = true;
  9.  
  10. var Bobstah = Bobstah || {};
  11. Bobstah.CustomStats = Bobstah.CustomStats || {};
  12.  
  13. //=============================================================================
  14. /*:
  15. * @plugindesc Allows you to create custom stats for damage formulas or any other use.
  16. * @author Bobstah
  17. *
  18. * ============================================================================
  19. * Introduction
  20. * ============================================================================
  21. * A simple custom stat plugin. Does not display the stats in
  22. * the actor Status window.
  23. *
  24. * ============================================================================
  25. * Notetags
  26. * ============================================================================
  27. * Actor/Enemy/Class
  28. * <CustomStat: statName=statValue>
  29. * statName - The name you want to reference this stat with.
  30. * statValue - The default value of your stat. Must be a number.
  31. *
  32. * Weapon/Armor/State
  33. * <CustomStat: statName+statValue>
  34. * <CustomStat: statName-statValue>
  35. * ============================================================================
  36. * Examples
  37. * ============================================================================
  38. * After setting a custom stat to an actor/enemy, you reference
  39. * it in damage formulas or other code just like any other
  40. * stat. Below is a sample damage formula for the a stat
  41. * named 'sanity':
  42. * 100 + a.sanity
  43. *
  44. * Let's say you gave the enemy a stat named 'insanity':
  45. * (100+ a.sanity) - b.insanity
  46. *
  47. */
  48.  
  49. Bobstah.CustomStats.statList = [];
  50. Bobstah.CustomStats.createStat = function(param, value) {
  51.  
  52. var newStat = {};
  53. newStat[param] = {};
  54. newStat[param].get = function() {
  55. if (this.customStats[param] && this.customStats[param] !== null) {
  56. return this.customStats[param];
  57. } else if (typeof(this._classId) !== "undefined") {
  58. if ($dataClasses[this._classId][param] && $dataClasses[this._classId][param] !== null) {
  59. return $dataClasses[this._classId][param];
  60. } else {
  61. return 0;
  62. }
  63. } else {
  64. return 0;
  65. }
  66. };
  67. newStat[param].set = function(val) {
  68. if (this.customStats[param] && this.customStats[param] !== null) {
  69. this.customStats[param] = val;
  70. } else if (typeof(this._classId) !== "undefined") {
  71. if ($dataClasses[this._classId][param] && $dataClasses[this._classId][param] !== null) {
  72. $dataClasses[this.classId][param] = val;
  73. }
  74. } else {
  75. this.customStats[param] = val;
  76. }
  77. };
  78. newStat[param].configurable = true;
  79. return newStat;
  80. };
  81.  
  82. Bobstah.CustomStats.applyCustomStats = function(obj) {
  83. obj.customStats = obj.customStats || {};
  84. for (i = 0; i < Bobstah.CustomStats.statList.length; i++) {
  85. var param = Bobstah.CustomStats.statList[i];
  86. var value = null;
  87. if (typeof(obj.customStats[param]) !== "undefined") {
  88. value = obj.customStats[param];
  89. }
  90. if (typeof(obj[param]) !== "undefined") { continue; }
  91. var newStat = Bobstah.CustomStats.createStat(param, value);
  92. Object.defineProperties(obj,newStat);
  93. obj.customStats[param] = value;
  94. }
  95. };
  96.  
  97. //=============================================================================
  98. // DataManager
  99. //=============================================================================
  100. Bobstah.CustomStats.DataManager_isDatabaseLoaded = DataManager.isDatabaseLoaded;
  101. DataManager.isDatabaseLoaded = function() {
  102. if (!Bobstah.CustomStats.DataManager_isDatabaseLoaded.call(this)) return false;
  103. DataManager.processBobstahCustomStatsNotes($dataActors);
  104. DataManager.processBobstahCustomStatsNotes($dataClasses);
  105. DataManager.processBobstahCustomStatsNotes($dataEnemies);
  106.  
  107. DataManager.processBobstahCustomStatsModNotes($dataWeapons);
  108. DataManager.processBobstahCustomStatsModNotes($dataArmors);
  109. DataManager.processBobstahCustomStatsModNotes($dataStates);
  110.  
  111. DataManager.processBobstahCustomStats($dataActors);
  112. DataManager.processBobstahCustomStats($dataClasses);
  113. DataManager.processBobstahCustomStats($dataEnemies);
  114. return true;
  115. };
  116.  
  117. DataManager.processBobstahCustomStatsNotes = function(group) {
  118. var statregex = /<CustomStat:\s*([A-z]+)=(\d+)\s*>/ig
  119. for (var n = 1; n < group.length; n++) {
  120. var obj = group[n];
  121. var notedata = obj.note;
  122. obj.customStats = obj.customStats || {};
  123. while(stat = statregex.exec(notedata)) {
  124. var param = stat[1];
  125. var value = Number(stat[2]);
  126. var newStat = Bobstah.CustomStats.createStat(param, value);
  127. Object.defineProperties(obj,newStat);
  128. if (Bobstah.CustomStats.statList.indexOf(param) === -1) {
  129. Bobstah.CustomStats.statList.push(param);
  130. }
  131. obj.customStats[param] = value;
  132. }
  133. }
  134. };
  135.  
  136. DataManager.processBobstahCustomStatsModNotes = function(group) {
  137. var statregex = /<CustomStat:\s*([A-z]+)([+\-])(\d+)\s*>/ig;
  138. for (var n = 1; n < group.length; n++) {
  139. var obj = group[n];
  140. var notedata = obj.note;
  141. obj.customStats = obj.customStats || {};
  142. while(stat = statregex.exec(notedata)) {
  143. var param = stat[1];
  144. var op = stat[2];
  145. var value = Number(stat[3]);
  146. obj.customStats[param] = {'operation': op, 'value':value};
  147. }
  148. }
  149. };
  150.  
  151. Bobstah.CustomStats.DataManager_makeSaveContents = DataManager.makeSaveContents;
  152. DataManager.makeSaveContents = function() {
  153. $gameSystem.storeCustomStats(Bobstah.CustomStats.statList);
  154. return Bobstah.CustomStats.DataManager_makeSaveContents.call(this);
  155. };
  156.  
  157. Bobstah.CustomStats.DataManager_extractSaveContents = DataManager.extractSaveContents;
  158. DataManager.extractSaveContents = function(contents) {
  159. Bobstah.CustomStats.DataManager_extractSaveContents.call(this, contents);
  160. Bobstah.CustomStats.statList = $gameSystem.getCustomStats();
  161. DataManager.processBobstahCustomStats($gameActors._data);
  162. };
  163.  
  164. DataManager.processBobstahCustomStats = function(group) {
  165. for (var n = 1; n < group.length; n++) {
  166. var obj = group[n];
  167. Bobstah.CustomStats.applyCustomStats(obj);
  168. }
  169. };
  170.  
  171. //=============================================================================
  172. // Game_System
  173. //=============================================================================
  174. Game_System.prototype.storeCustomStats = function(arrayin) {
  175. this.customStatList = arrayin;
  176. };
  177.  
  178. Game_System.prototype.getCustomStats = function() {
  179. return this.customStatList;
  180. };
  181.  
  182. //=============================================================================
  183. // Game_BattlerBase
  184. //=============================================================================
  185. Game_BattlerBase.prototype.loadCustomStats = function(myId, datalist) {
  186. //Load Custom Stats
  187. Bobstah.CustomStats.applyCustomStats(this);
  188. for (var statId in this.customStats) {
  189. if (typeof(datalist[myId].customStats[statId]) !== "undefined") {
  190. this.customStats[statId] = datalist[myId].customStats[statId];
  191. }
  192. }
  193. };
  194.  
  195. Game_BattlerBase.prototype.handleCustomStats = function(obj, opposite) {
  196. opposite = opposite || false;
  197. for (var statId in obj.customStats) {
  198. var stat = obj.customStats[statId];
  199. if (this.customStats[statId] === null) {
  200. this.customStats[statId] = 0;
  201. }
  202. switch (stat.operation) {
  203. case "-":
  204. this.customStats[statId] = (opposite === false ? this.customStats[statId] - stat.value : this.customStats[statId] + stat.value);
  205. break;
  206.  
  207. default:
  208. this.customStats[statId] = (opposite === false ? this.customStats[statId] + stat.value : this.customStats[statId] - stat.value);
  209. break;
  210. }
  211. }
  212. };
  213.  
  214. Bobstah.CustomStats.GameBattlerBase_addNewState = Game_BattlerBase.prototype.addNewState;
  215. Game_BattlerBase.prototype.addNewState = function(stateId) {
  216. var res = Bobstah.CustomStats.GameBattlerBase_addNewState.call(this, stateId);
  217. if (stateId !== null) {
  218. var state = $dataStates[stateId];
  219. this.handleCustomStats(state);
  220. }
  221. return res;
  222. };
  223.  
  224. //=============================================================================
  225. // Game_Battler
  226. //=============================================================================
  227. Bobstah.CustomStats.GameBattler_removeState = Game_Battler.prototype.removeState;
  228. Game_Battler.prototype.removeState = function(stateId) {
  229. var res = Bobstah.CustomStats.GameBattler_removeState.call(this, stateId);
  230. if (stateId !== null) {
  231. var state = $dataStates[stateId];
  232. this.handleCustomStats(state, true);
  233. }
  234. return res;
  235. };
  236.  
  237. //=============================================================================
  238. // Game_Actor
  239. //=============================================================================
  240. Bobstah.CustomStats.GameActor_setup = Game_Actor.prototype.setup;
  241. Game_Actor.prototype.setup = function(actorId) {
  242. Bobstah.CustomStats.GameActor_setup.call(this, actorId);
  243. this.loadCustomStats(actorId, $dataActors);
  244. };
  245.  
  246. Bobstah.CustomStats.GameActor_changeEquip = Game_Actor.prototype.changeEquip;
  247. Game_Actor.prototype.changeEquip = function(slotId, item) {
  248. if (this.equips()[slotId]) {
  249. var oldItem = this.equips()[slotId];
  250. this.handleCustomStats(oldItem, true);
  251. }
  252. var res = Bobstah.CustomStats.GameActor_changeEquip.call(this, slotId, item);
  253. if (item !== null) {
  254. this.handleCustomStats(item);
  255. }
  256. return res;
  257. };
  258.  
  259. //=============================================================================
  260. // Game_Enemy
  261. //=============================================================================
  262. Bobstah.CustomStats.GameEnemy_setup = Game_Enemy.prototype.setup;
  263. Game_Enemy.prototype.setup = function(enemyId, x, y) {
  264. Bobstah.CustomStats.GameEnemy_setup.call(this, enemyId, x, y);
  265. this.loadCustomStats(enemyId, $dataEnemies);
  266. };
Advertisement
Add Comment
Please, Sign In to add comment