Raizen

Untitled

Sep 26th, 2020
91
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 12.92 KB | None | 0 0
  1.  
  2. //==========================================================================
  3. // Akea Custom Gauges
  4. //----------------------------------------------------------------------------
  5. // 09/11/20 | Version: 1.0.0
  6. // This software is released under the zlib License.
  7. //============================================================================
  8.  
  9. /*:
  10. * @target MZ
  11. * @plugindesc Akea Custom Gauges version: 1.0.0
  12. * @author Reisen (Mauricio Pastana)
  13. * @url https://www.patreon.com/raizen884
  14. * @orderAfter AkeaAnimatedBattleSystem
  15. *
  16. * @help Akea Custom Gauges - this plugins is under zlib license
  17. * For support and new plugins join our discord server! https://discord.gg/Kh9XXZ2
  18. * Want to support new creations? be a patreon!
  19.  
  20. * This plugin works as the following:
  21. *
  22. * You will create in the parameters the gauges as asked, each gauge has a back image
  23. * and its bar image, you need to then set the x and y for them.
  24. * The type of gauge is where will that gauge scope be, if you choose battlerBase for example,
  25. * The gauge will act as when x and y are 0, on the base of the battler.
  26. * global is absolute values and hud is on the hud below, or on the custom hud if you are using any.
  27. * The maximum and variable gauge values are the only tricky part, that is needed
  28. * a script call for each value, the max value would be when the bar is full,
  29. * and the variable value is from 0 until max, the actual value for that gauge.
  30. *
  31. * Examples:
  32. * For hp you would use:
  33. * | Maximum Gauge Value > this._battler.mhp
  34. * | Variable Gauge Value > this._battler.hp
  35. *
  36. * For mp you would use:
  37. * | Maximum Gauge Value > this._battler.mmp
  38. * | Variable Gauge Value > this._battler.mp
  39. *
  40. * For tp you would use:
  41. * | Maximum Gauge Value > 100
  42. * | Variable Gauge Value > this._battler.tp
  43. *
  44. * For tpb (or atb) you would use:
  45. * | Maximum Gauge Value > 1
  46. * | Variable Gauge Value > this._battler.tpbChargeTime()
  47. *
  48. * This gives you freedom for new and different ways to use your gauge! This means its very
  49. * easy to adjust a custom attribute also!
  50. *
  51. * After you create your first gauge, you will need to append them to actors/enemies, this
  52. * can look like a bit of work, but this gives you much more freedom to customize your
  53. * gauges as you like for any actor/enemy!
  54. *
  55. *
  56. *
  57. *
  58. * @param actingGauge
  59. * @type boolean
  60. * @default true
  61. * @text Gauge Deactivation
  62. * @desc Deactivate Gauge when the battler is acting?
  63. *
  64. * @param removeMenu
  65. * @type select[]
  66. * @option time
  67. * @option hp
  68. * @option mp
  69. * @option tp
  70. * @text Remove From Hud
  71. * @desc Deactivate what bars from the hud, if any?
  72. *
  73. * @param actorConfig
  74. * @type struct<Actor>[]
  75. * @text Actor Configuration
  76. * @desc Configure here each actor with its extra gauges
  77. *
  78. * @param enemyConfig
  79. * @type struct<Enemy>[]
  80. * @text Enemy Configuration
  81. * @desc Configure here each enemy with its extra gauges
  82. *
  83. * @param gaugeConfig
  84. * @type struct<Gauge>[]
  85. * @text Gauge Configuration
  86. * @desc Configure here each gauge
  87. *
  88.  
  89. */
  90. /*~struct~Actor:
  91. * @param id
  92. * @type actor
  93. * @text Actor
  94. * @param gauges
  95. * @type number[]
  96. * @text Gauges
  97. * @desc Gauges to append to this actor, just put the id of each gauge you want to add to that actor here
  98. */
  99.  
  100. /*~struct~Enemy:
  101. * @param id
  102. * @type enemy
  103. * @text Enemy
  104. * @param gauges
  105. * @type number[]
  106. * @text Gauges
  107. * @desc Gauges to append to this actor, just put the id of each gauge you want to add to that actor here
  108. */
  109.  
  110. /*~struct~Gauge:
  111. * @param gaugeBase
  112. * @type file
  113. * @dir img/akea/
  114. * @text Gauge Base Image
  115. * @desc Static image of the Gauge
  116. * @param baseX
  117. * @type number
  118. * @min -1000
  119. * @text Base X Position
  120. * @desc X Position for Gauge Base
  121. * @param baseY
  122. * @type number
  123. * @min -1000
  124. * @text Base Y Position
  125. * @desc Y Position for Gauge Base
  126. * @param gaugeBar
  127. * @type file
  128. * @dir img/akea/
  129. * @text Gauge Bar Image
  130. * @desc Image of the Gauge Bar
  131. * @param barX
  132. * @type number
  133. * @min -1000
  134. * @text Bar X Position
  135. * @desc X Position for Gauge Bar
  136. * @param barY
  137. * @type number
  138. * @min -1000
  139. * @text Bar Y Position
  140. * @desc Y Position for Gauge Bar
  141. * @param gaugeType
  142. * @type select
  143. * @option global
  144. * @option hud
  145. * @option battlerBase
  146. * @option battlerHead
  147. * @text Type of The Gauge
  148. * @desc if it should follow the battler(base or head), be absolute (global) or on the hud (actors only)
  149. * @param maximum
  150. * @type text
  151. * @default this._battler.mhp
  152. * @text Maximum Gauge Value
  153. * @desc The code that represents the maximum value, checkout the help for the most used ones.
  154. * @param variable
  155. * @type text
  156. * @default this._battler.hp
  157. * @text Variable Gauge Value
  158. * @desc The code that represents the variable value, checkout the help for the most used ones.
  159. */
  160.  
  161. // DON'T MODIFY THIS PART!!!
  162. var Akea = Akea || {};
  163. Akea.AnimatedGauges = Akea.AnimatedGauges || {};
  164. Akea.AnimatedGauges.VERSION = [1, 0, 0];
  165.  
  166. ImageManager.loadAkea = function (filename) {
  167. return this.loadBitmap("img/akea/", filename);
  168. };
  169.  
  170. (() => {
  171. const pluginName = "AkeaCustomGauges";
  172. const parameters = PluginManager.parameters(pluginName);
  173. let temp = JSON.parse(parameters.gaugeConfig);
  174. Akea.AnimatedGauges.GaugeConfig = [];
  175. Akea.AnimatedGauges.ActorConfig = [];
  176. Akea.AnimatedGauges.EnemyConfig = [];
  177. Akea.AnimatedGauges.DeactivateGauge = parameters.actingGauge == "true" ? true : false;
  178. Akea.AnimatedGauges.HudConfig = JSON.parse(parameters.removeMenu);
  179. let temp2;
  180. for (const gauge of temp) {
  181. temp2 = JSON.parse(gauge);
  182. temp2.baseX = parseInt(temp2.baseX);
  183. temp2.baseY = parseInt(temp2.baseY);
  184. temp2.barX = parseInt(temp2.barX);
  185. temp2.barY = parseInt(temp2.barY);
  186. Akea.AnimatedGauges.GaugeConfig.push(temp2);
  187. }
  188. temp = JSON.parse(parameters.actorConfig);
  189. for (const actor of temp) {
  190. temp2 = JSON.parse(actor);
  191. temp2.id = parseInt(temp2.id);
  192. temp2.gauges = JSON.parse(temp2.gauges).map(gauge => parseInt(gauge) - 1);
  193. Akea.AnimatedGauges.ActorConfig.push(temp2);
  194. }
  195. temp = JSON.parse(parameters.enemyConfig);
  196. for (const enemy of temp) {
  197. temp2 = JSON.parse(enemy);
  198. temp2.id = parseInt(temp2.id);
  199. temp2.gauges = JSON.parse(temp2.gauges).map(gauge => parseInt(gauge) - 1);
  200. Akea.AnimatedGauges.EnemyConfig.push(temp2);
  201. }
  202. temp = null;
  203. temp2 = null;
  204. const _Sprite_Battler_updateBitmap = Sprite_Battler.prototype.updateBitmap;
  205. Sprite_Battler.prototype.updateBitmap = function () {
  206. _Sprite_Battler_updateBitmap.call(this, ...arguments);
  207. const name = this._battler.battlerName();
  208. if (this._battlerName !== name) {
  209. this.createAkeaGauge();
  210. }
  211. this.updateAkeaGauge();
  212. };
  213.  
  214. const _Sprite_Enemy_updateBitmap = Sprite_Enemy.prototype.updateBitmap;
  215. Sprite_Enemy.prototype.updateBitmap = function() {
  216. _Sprite_Enemy_updateBitmap.call(this, ...arguments);
  217. var name = this._enemy.battlerName();
  218. if (this._battlerName !== name) {
  219. this._battlerName = name;
  220. };
  221. };
  222. const _Sprite_Actor_updateBitmap = Sprite_Actor.prototype.updateBitmap;
  223. Sprite_Actor.prototype.updateBitmap = function() {
  224. _Sprite_Actor_updateBitmap.call(this, ...arguments);
  225. var name = this._actor.battlerName();
  226. if (this._battlerName !== name) {
  227. this._battlerName = name;
  228. };
  229. };
  230. Sprite_Battler.prototype.createAkeaGauge = function () {
  231. this._mainAkeaGauge = new Sprite();
  232. this.addChild(this._mainAkeaGauge);
  233. this._gaugeBase = new Array();
  234. this._gaugeBars = new Array();
  235. this._gaugeInfos = new Array();
  236. this.createAkeaGaugeImages();
  237. };
  238. Sprite_Battler.prototype.createAkeaGaugeImages = function () {
  239. const battlerConfig = this.unloadBattlerGaugeConfig();
  240. const gauges = Akea.AnimatedGauges.GaugeConfig;
  241. let gauge;
  242. if (!battlerConfig) { return };
  243. for (let n = 0; n < battlerConfig.gauges.length; n++) {
  244. gauge = gauges[battlerConfig.gauges[n]];
  245. this._gaugeBase[n] = new Sprite();
  246. this._gaugeBase[n].bitmap = ImageManager.loadAkea(gauge.gaugeBase);
  247. this._gaugeBars[n] = new Sprite();
  248. this._gaugeBars[n].bitmap = ImageManager.loadAkea(gauge.gaugeBar);
  249. this.setAkeaGaugePositions(n, gauge);
  250. this._gaugeInfos[n] = {
  251. maximum: gauge.maximum,
  252. variable: gauge.variable,
  253. gaugeType: gauge.gaugeType,
  254. baseX: gauge.baseX,
  255. baseY: gauge.baseY
  256. };
  257. }
  258. };
  259. Sprite_Battler.prototype.setAkeaGaugePositions = function (n, gauge) {
  260. switch (gauge.gaugeType) {
  261. case "global":
  262. this._gaugeBase[n].x = gauge.baseX;
  263. this._gaugeBase[n].y = gauge.baseY;
  264. this._gaugeBars[n].x = gauge.barX;
  265. this._gaugeBars[n].y = gauge.barY;
  266. BattleManager._spriteset._battleField.addChild(this._gaugeBase[n]);
  267. BattleManager._spriteset._battleField.addChild(this._gaugeBars[n]);
  268. break;
  269. case "hud":
  270. this._gaugeBase[n].x = gauge.baseX;
  271. this._gaugeBase[n].y = gauge.baseY;
  272. this._gaugeBars[n].x = gauge.barX;
  273. this._gaugeBars[n].y = gauge.barY;
  274. SceneManager._scene._statusWindow.addAkeaGauge(this._battler, this._gaugeBase[n]);
  275. SceneManager._scene._statusWindow.addAkeaGauge(this._battler, this._gaugeBars[n]);
  276. break;
  277. case "battlerHead":
  278. this._gaugeBase[n].x = gauge.baseX;
  279. this._gaugeBase[n].y = gauge.baseY;
  280. this._gaugeBars[n].x = gauge.barX;
  281. this._gaugeBars[n].y = gauge.barY;
  282. this._mainAkeaGauge.addChild(this._gaugeBase[n]);
  283. this._mainAkeaGauge.addChild(this._gaugeBars[n]);
  284. this._needToUpdateHeight = true;
  285. break;
  286. case "battlerBase":
  287. this._gaugeBase[n].x = gauge.baseX;
  288. this._gaugeBase[n].y = gauge.baseY;
  289. this._gaugeBars[n].x = gauge.barX;
  290. this._gaugeBars[n].y = gauge.barY;
  291. this._mainAkeaGauge.addChild(this._gaugeBase[n]);
  292. this._mainAkeaGauge.addChild(this._gaugeBars[n]);
  293. break;
  294. }
  295. };
  296.  
  297. Sprite_Battler.prototype.unloadBattlerGaugeConfig = function () {
  298. let config;
  299. if (this._battler.isActor()) {
  300. config = Akea.AnimatedGauges.ActorConfig.filter(battler => battler.id == this._battler.actorId());
  301. } else {
  302. config = Akea.AnimatedGauges.EnemyConfig.filter(battler => battler.id == this._battler.enemyId());
  303. }
  304. return config[0];
  305. };
  306.  
  307. const _Sprite_Battler_updateFrame = Sprite_Battler.prototype.updateFrame;
  308. Sprite_Battler.prototype.updateFrame = function () {
  309. _Sprite_Battler_updateFrame.call(this, ...arguments);
  310. if (this._needToUpdateHeight && this.mainSprite().height != 0) {
  311. for (let n = 0; n < this._gaugeBars.length; n++) {
  312. if (this._gaugeInfos[n].gaugeType === "battlerHead") {
  313. this._gaugeBase[n].y -= this.mainSprite().height;
  314. this._gaugeBars[n].y -= this.mainSprite().height;
  315. }
  316. };
  317. this._needToUpdateHeight = false;
  318. }
  319. };
  320.  
  321. Sprite_Battler.prototype.updateAkeaGauge = function () {
  322. for (let n = 0; n < this._gaugeBars.length; n++) {
  323. let variable = eval(this._gaugeInfos[n].variable);
  324. let max = eval(this._gaugeInfos[n].maximum);
  325. this._gaugeBars[n].scale.x = variable / max;
  326. if (Akea.AnimatedGauges.DeactivateGauge && this._battler.isActing() || (Akea.BattleSystem && this._battler.getAkeaAnimatedBSActions().hasActions())) {
  327. this._gaugeBars[n].opacity -= 25;
  328. this._gaugeBase[n].opacity -= 25;
  329. } else {
  330. this._gaugeBars[n].opacity += 25;
  331. this._gaugeBase[n].opacity += 25;
  332. }
  333. };
  334. };
  335.  
  336. Window_BattleStatus.prototype.addAkeaGauge = function (actor, sprite) {
  337. const index = $gameParty.battleMembers().indexOf(actor);
  338. const rect = this.itemRect(index);
  339. const x = rect.x;
  340. const y = rect.y + rect.height / 2 - this.lineHeight() * 1.5;
  341. sprite.x += x;
  342. sprite.y += y;
  343. this.addInnerChild(sprite);
  344. };
  345.  
  346. const _Window_StatusBase_placeGauge = Window_StatusBase.prototype.placeGauge;
  347. Window_StatusBase.prototype.placeGauge = function (actor, type, x, y) {
  348. if (Akea.AnimatedGauges.HudConfig.includes(type)) { return };
  349. _Window_StatusBase_placeGauge.call(this, ...arguments);
  350. };
  351.  
  352. })();
Add Comment
Please, Sign In to add comment