Raizen

Untitled

Sep 26th, 2020
558
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 12.58 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 && this._needLoadGauge) {
  209. this._needLoadGauge = false;
  210. this.createAkeaGauge();
  211. }
  212. this.updateAkeaGauge();
  213. };
  214. const _Sprite_Battler_initialize = Sprite_Battler.prototype.initialize;
  215. Sprite_Battler.prototype.initialize = function (battler) {
  216. _Sprite_Battler_initialize.call(this, ...arguments);
  217. this._needLoadGauge = true;
  218. }
  219. Sprite_Battler.prototype.createAkeaGauge = function () {
  220. this._mainAkeaGauge = new Sprite();
  221. this.addChild(this._mainAkeaGauge);
  222. this._gaugeBase = new Array();
  223. this._gaugeBars = new Array();
  224. this._gaugeInfos = new Array();
  225. this.createAkeaGaugeImages();
  226. };
  227. Sprite_Battler.prototype.createAkeaGaugeImages = function () {
  228. const battlerConfig = this.unloadBattlerGaugeConfig();
  229. const gauges = Akea.AnimatedGauges.GaugeConfig;
  230. let gauge;
  231. if (!battlerConfig) { return };
  232. for (let n = 0; n < battlerConfig.gauges.length; n++) {
  233. gauge = gauges[battlerConfig.gauges[n]];
  234. this._gaugeBase[n] = new Sprite();
  235. this._gaugeBase[n].bitmap = ImageManager.loadAkea(gauge.gaugeBase);
  236. this._gaugeBars[n] = new Sprite();
  237. this._gaugeBars[n].bitmap = ImageManager.loadAkea(gauge.gaugeBar);
  238. this.setAkeaGaugePositions(n, gauge);
  239. this._gaugeInfos[n] = {
  240. maximum: gauge.maximum,
  241. variable: gauge.variable,
  242. gaugeType: gauge.gaugeType,
  243. baseX: gauge.baseX,
  244. baseY: gauge.baseY
  245. };
  246. }
  247. };
  248. Sprite_Battler.prototype.setAkeaGaugePositions = function (n, gauge) {
  249. switch (gauge.gaugeType) {
  250. case "global":
  251. this._gaugeBase[n].x = gauge.baseX;
  252. this._gaugeBase[n].y = gauge.baseY;
  253. this._gaugeBars[n].x = gauge.barX;
  254. this._gaugeBars[n].y = gauge.barY;
  255. BattleManager._spriteset._battleField.addChild(this._gaugeBase[n]);
  256. BattleManager._spriteset._battleField.addChild(this._gaugeBars[n]);
  257. break;
  258. case "hud":
  259. this._gaugeBase[n].x = gauge.baseX;
  260. this._gaugeBase[n].y = gauge.baseY;
  261. this._gaugeBars[n].x = gauge.barX;
  262. this._gaugeBars[n].y = gauge.barY;
  263. SceneManager._scene._statusWindow.addAkeaGauge(this._battler, this._gaugeBase[n]);
  264. SceneManager._scene._statusWindow.addAkeaGauge(this._battler, this._gaugeBars[n]);
  265. break;
  266. case "battlerHead":
  267. this._gaugeBase[n].x = gauge.baseX;
  268. this._gaugeBase[n].y = gauge.baseY;
  269. this._gaugeBars[n].x = gauge.barX;
  270. this._gaugeBars[n].y = gauge.barY;
  271. this._mainAkeaGauge.addChild(this._gaugeBase[n]);
  272. this._mainAkeaGauge.addChild(this._gaugeBars[n]);
  273. this._needToUpdateHeight = true;
  274. break;
  275. case "battlerBase":
  276. this._gaugeBase[n].x = gauge.baseX;
  277. this._gaugeBase[n].y = gauge.baseY;
  278. this._gaugeBars[n].x = gauge.barX;
  279. this._gaugeBars[n].y = gauge.barY;
  280. this._mainAkeaGauge.addChild(this._gaugeBase[n]);
  281. this._mainAkeaGauge.addChild(this._gaugeBars[n]);
  282. break;
  283. }
  284. };
  285.  
  286. Sprite_Battler.prototype.unloadBattlerGaugeConfig = function () {
  287. let config;
  288. if (this._battler.isActor()) {
  289. config = Akea.AnimatedGauges.ActorConfig.filter(battler => battler.id == this._battler.actorId());
  290. } else {
  291. config = Akea.AnimatedGauges.EnemyConfig.filter(battler => battler.id == this._battler.enemyId());
  292. }
  293. return config[0];
  294. };
  295.  
  296. const _Sprite_Battler_updateFrame = Sprite_Battler.prototype.updateFrame;
  297. Sprite_Battler.prototype.updateFrame = function () {
  298. _Sprite_Battler_updateFrame.call(this, ...arguments);
  299. if (this._needToUpdateHeight && this.mainSprite().height != 0) {
  300. for (let n = 0; n < this._gaugeBars.length; n++) {
  301. if (this._gaugeInfos[n].gaugeType === "battlerHead") {
  302. this._gaugeBase[n].y -= this.mainSprite().height;
  303. this._gaugeBars[n].y -= this.mainSprite().height;
  304. }
  305. };
  306. this._needToUpdateHeight = false;
  307. }
  308. };
  309.  
  310. Sprite_Battler.prototype.updateAkeaGauge = function () {
  311. for (let n = 0; n < this._gaugeBars.length; n++) {
  312. let variable = eval(this._gaugeInfos[n].variable);
  313. let max = eval(this._gaugeInfos[n].maximum);
  314. this._gaugeBars[n].scale.x = variable / max;
  315. if (Akea.AnimatedGauges.DeactivateGauge && this._battler.isActing() || (Akea.BattleSystem && this._battler.getAkeaAnimatedBSActions().hasActions())) {
  316. this._gaugeBars[n].opacity -= 25;
  317. this._gaugeBase[n].opacity -= 25;
  318. } else {
  319. this._gaugeBars[n].opacity += 25;
  320. this._gaugeBase[n].opacity += 25;
  321. }
  322. };
  323. };
  324.  
  325. Window_BattleStatus.prototype.addAkeaGauge = function (actor, sprite) {
  326. const index = $gameParty.battleMembers().indexOf(actor);
  327. const rect = this.itemRect(index);
  328. const x = rect.x;
  329. const y = rect.y + rect.height / 2 - this.lineHeight() * 1.5;
  330. sprite.x += x;
  331. sprite.y += y;
  332. this.addInnerChild(sprite);
  333. };
  334.  
  335. const _Window_StatusBase_placeGauge = Window_StatusBase.prototype.placeGauge;
  336. Window_StatusBase.prototype.placeGauge = function (actor, type, x, y) {
  337. if (Akea.AnimatedGauges.HudConfig.includes(type)) { return };
  338. _Window_StatusBase_placeGauge.call(this, ...arguments);
  339. };
  340.  
  341. })();
Add Comment
Please, Sign In to add comment