找回密码
 注册用户
查看: 247|回复: 0

[RMMZ] 【汉化】敌人血条

[复制链接]

88

主题

7

回帖

1277

积分

资深会员

积分
1277
发表于 2024-6-3 17:44:47 | 显示全部楼层 |阅读模式

简易的敌人血条

原地址:Torigoya_EnemyHpBar / 敵にHPバーを表示プラグイン | 鳥小屋プラグイン置き場 (rutan.dev)

预览:
ogp.jpg

脚本:

  1. /*---------------------------------------------------------------------------*
  2. * TorigoyaMZ_EnemyHpBar.js v.1.3.2
  3. *---------------------------------------------------------------------------*
  4. * 2021/10/10 20:48 (JST)
  5. *---------------------------------------------------------------------------*
  6. * Ruたん ( @ru_shalm )
  7. * https://torigoya-plugin.rutan.dev
  8. *---------------------------------------------------------------------------*/

  9. /*:
  10. * @target MZ
  11. * @plugindesc 敌人血条显示插件 (v.1.3.2)
  12. * 汉化 by 烁灵 更多插件请访问 www.hknmtt.com
  13. * @author Ruたん(ru_shalm)
  14. * @license public domain
  15. * @version 1.3.2
  16. * @url https://raw.githubusercontent.com/rutan/torigoya-rpg-maker-plugin/gh-pages/TorigoyaMZ_EnemyHpBar.js
  17. * @help
  18. * 敵にHPバーを表示プラグイン (v.1.3.2)
  19. * https://torigoya-plugin.rutan.dev
  20. *
  21. * 显示敌人HP条
  22. *
  23. * ------------------------------------------------------------
  24. * ■ 使用方法
  25. * ------------------------------------------------------------
  26. * 开启插件即可
  27. * 详细设定请修改插件参数
  28. *
  29. * ------------------------------------------------------------
  30. * ■ 可以单独设定敌人显示血条的效果
  31. * ------------------------------------------------------------
  32. * 以下设定在敌人备注栏生效
  33. *
  34. * ▼ 指定敌人不显示血条
  35. * <HP条不显示>
  36. *
  37. * ▼ x 坐标偏移
  38. * <HP条X: 100>
  39. *
  40. * ※表示向右移动 100 像素,负数则向左
  41. *
  42. * ▼ y 坐标偏移
  43. * <HP条Y: 100>
  44. *
  45. * ※表示向下移动 100 像素,负数则向上
  46. *
  47. * ▼ 修改为指定宽度
  48. * <HP条宽度: 320>
  49. *
  50. * ▼ 修改为指定高度
  51. * <HP条高度: 30>
  52. *
  53. * ▼ 敌人 hp 满足条件的时候出现hp数值
  54. *
  55. * <HP显示条件: false>
  56. *
  57. * ▼ 比如,hp 变为一半才出现:
  58. *
  59. * <HP显示条件: a.hp < a.mhp * 0.5>
  60. *
  61. * 使用伤害计算公式格式的表达式
  62. * (a 是敌人。不过 b 不能使用)
  63. * 不能使用 大于号 >,如果需要请写成 「 &gt; 」
  64. * 条件为真时 hp 会显示
  65. * 为假时会显示 ?????
  66. *
  67. * ▼ 以下设定使显示条件达到后不再隐藏 hp
  68. *
  69. * <HP表示条件: a.hp < a.mhp * 0.5>
  70. * <HP显示持续>
  71. *
  72. * 此处的 <HP显示持续> 追加注释表示
  73. * 该战斗中一旦显示过 hp,则不会再显示为 ?????
  74. *
  75. * @param base
  76. * @text ■ 基本设定
  77. *
  78. * @param basePosition
  79. * @text 显示位置
  80. * @desc HP 调的显示位置
  81. * @type select
  82. * @parent base
  83. * @option 敌人图像上方
  84. * @value top
  85. * @option 敌人图像下方
  86. * @value bottom
  87. * @default top
  88. *
  89. * @param basePosX
  90. * @text 坐标偏移:X
  91. * @desc 横坐标偏移
  92. * 负数为左,正数为右
  93. * @type number
  94. * @parent base
  95. * @min -10000
  96. * @max 10000
  97. * @default 0
  98. *
  99. * @param basePosY
  100. * @text 坐标偏移:Y
  101. * @desc 纵坐标偏移
  102. * 负数为上,正数为下
  103. * @type number
  104. * @parent base
  105. * @min -10000
  106. * @max 10000
  107. * @default 0
  108. *
  109. * @param customize
  110. * @text ■ 自定义参数
  111. *
  112. * @param customizeCondition
  113. * @text 显示条件
  114. * @desc 血条显示条件
  115. * @type select
  116. * @parent customize
  117. * @option 一直显示
  118. * @value always
  119. * @option 选中、受伤时
  120. * @value selectOrDamage
  121. * @default always
  122. *
  123. * @param customizeGaugeWidth
  124. * @text 宽度
  125. * @desc HP条宽度
  126. * @type number
  127. * @parent customize
  128. * @min 1
  129. * @default 100
  130. *
  131. * @param customizeGaugeHeight
  132. * @text 高度
  133. * @desc HP条高度
  134. * @type number
  135. * @parent customize
  136. * @min 1
  137. * @default 10
  138. *
  139. * @param customizeDrawLabel
  140. * @text HP数值
  141. * @desc 是否显示HP数值
  142. * @type boolean
  143. * @parent customize
  144. * @on 显示
  145. * @off 不显示
  146. * @default true
  147. *
  148. * @param customizeLabelWidth
  149. * @text HP宽度调整
  150. * @desc HP宽度调整值
  151. * @type number
  152. * @parent customize
  153. * @min 0
  154. * @default 20
  155. *
  156. * @param customizeLabelFontSize
  157. * @text HP 字符字号
  158. * @desc HP 字符字号
  159. * @type number
  160. * @parent customize
  161. * @min 1
  162. * @default 16
  163. *
  164. * @param customizeValueFontSize
  165. * @text HP 数值字号
  166. * @desc HP 数值字号
  167. * @type number
  168. * @parent customize
  169. * @min 1
  170. * @default 20
  171. *
  172. * @param customizeMaskHpValue
  173. * @text HP暗号文字
  174. * @desc HP数值未知时的文字
  175. * @type string
  176. * @parent customize
  177. * @default ?????
  178. */

  179. (function () {
  180.     'use strict';

  181.     const Torigoya = (window.Torigoya = window.Torigoya || {});

  182.     function getPluginName() {
  183.         const cs = document.currentScript;
  184.         return cs ? cs.src.split('/').pop().replace(/\.js$/, '') : 'TorigoyaMZ_EnemyHpBar';
  185.     }

  186.     function pickStringValueFromParameter(parameter, key, defaultValue = '') {
  187.         if (!parameter.hasOwnProperty(key)) return defaultValue;
  188.         return ''.concat(parameter[key] || '');
  189.     }

  190.     function pickIntegerValueFromParameter(parameter, key, defaultValue = 0) {
  191.         if (!parameter.hasOwnProperty(key) || parameter[key] === '') return defaultValue;
  192.         return parseInt(parameter[key], 10);
  193.     }

  194.     function pickBooleanValueFromParameter(parameter, key, defaultValue = 'false') {
  195.         return ''.concat(parameter[key] || defaultValue) === 'true';
  196.     }

  197.     function readParameter() {
  198.         const parameter = PluginManager.parameters(getPluginName());
  199.         return {
  200.             version: '1.3.2',
  201.             basePosition: pickStringValueFromParameter(parameter, 'basePosition', 'top'),
  202.             basePosX: pickIntegerValueFromParameter(parameter, 'basePosX', 0),
  203.             basePosY: pickIntegerValueFromParameter(parameter, 'basePosY', 0),
  204.             customizeCondition: pickStringValueFromParameter(parameter, 'customizeCondition', 'always'),
  205.             customizeGaugeWidth: pickIntegerValueFromParameter(parameter, 'customizeGaugeWidth', 100),
  206.             customizeGaugeHeight: pickIntegerValueFromParameter(parameter, 'customizeGaugeHeight', 10),
  207.             customizeDrawLabel: pickBooleanValueFromParameter(parameter, 'customizeDrawLabel', 'true'),
  208.             customizeLabelWidth: pickIntegerValueFromParameter(parameter, 'customizeLabelWidth', 20),
  209.             customizeLabelFontSize: pickIntegerValueFromParameter(parameter, 'customizeLabelFontSize', 16),
  210.             customizeValueFontSize: pickIntegerValueFromParameter(parameter, 'customizeValueFontSize', 20),
  211.             customizeMaskHpValue: pickStringValueFromParameter(parameter, 'customizeMaskHpValue', '?????'),
  212.         };
  213.     }

  214.     function unescapeMetaString(string) {
  215.         return ''
  216.             .concat(string || '')
  217.             .trim()
  218.             .replace(/&lt;/g, '<')
  219.             .replace(/&gt;/g, '>');
  220.     }

  221.     Torigoya.EnemyHpBar = {
  222.         name: getPluginName(),
  223.         parameter: readParameter(),
  224.     };

  225.     function isHiddenHpBar(enemy) {
  226.         return !enemy || enemy.meta['hiddenHpBar'] || enemy.meta['HP条不显示'];
  227.     }

  228.     function hpBarX(enemy) {
  229.         return parseInt((enemy && (enemy.meta['hpBarPosX'] || enemy.meta['HP条X'])) || 0, 10);
  230.     }

  231.     function hpBarY(enemy) {
  232.         return parseInt((enemy && (enemy.meta['hpBarPosY'] || enemy.meta['HP条Y'])) || 0, 10);
  233.     }

  234.     function hpBarWidth(enemy) {
  235.         return parseInt((enemy && (enemy.meta['hpBarWidth'] || enemy.meta['HP条宽度'])) || 0, 10);
  236.     }

  237.     function hpBarHeight(enemy) {
  238.         return parseInt((enemy && (enemy.meta['hpBarHeight'] || enemy.meta['HP条高度'])) || 0, 10);
  239.     }

  240.     const forceShowHpValueCache = new WeakSet();

  241.     function isShowHpValueOfBattler(a) {
  242.         if (!a) return true;
  243.         if (forceShowHpValueCache.has(a)) return true;

  244.         const enemy = a.enemy();
  245.         const code = enemy.meta['hpShowCondition'] || enemy.meta['HP显示条件'] || '';
  246.         if (!code) return true;
  247.         try {
  248.             if (eval(unescapeMetaString(code))) {
  249.                 if (enemy.meta['hpShowPermanently'] || enemy.meta['HP显示持续']) {
  250.                     forceShowHpValueCache.add(a);
  251.                 }
  252.                 return true;
  253.             }
  254.         } catch (e) {
  255.             if ($gameTemp.isPlaytest()) console.error(e);
  256.         }

  257.         return false;
  258.     }

  259.     class Sprite_EnemyHpGauge extends Sprite_Gauge {
  260.         constructor() {
  261.             super();
  262.             this._durationWait = 0;
  263.         }

  264.         setup(battler, statusType) {
  265.             if (this._battler === battler) return;
  266.             this._battler = battler;
  267.             this.reCreateBitmap();
  268.             super.setup(battler, statusType);
  269.         }

  270.         reCreateBitmap() {
  271.             if (this.bitmap) this.bitmap.destroy();
  272.             this.bitmap = null;
  273.             this.createBitmap();
  274.         }

  275.         bitmapWidth() {
  276.             return this.gaugeWidth() + this.gaugeX();
  277.         }

  278.         bitmapHeight() {
  279.             // コアスクリプトv.1.3.3 の以下の修正内容を適用
  280.             // > HP(略)MP(略)TP(略)に一部の英文字を利用すると見切れる問題を修正
  281.             if (Sprite_Gauge.prototype.textHeight) {
  282.                 return Math.round(this.textHeight() * 1.5);
  283.             } else {
  284.                 return this.textHeight();
  285.             }
  286.         }

  287.         textHeight() {
  288.             if (Torigoya.EnemyHpBar.parameter.customizeDrawLabel) {
  289.                 return Math.max(
  290.                     this.labelFontSize() + this.labelOutlineWidth(),
  291.                     this.valueFontSize() + this.valueOutlineWidth(),
  292.                     this.gaugeHeight()
  293.                 );
  294.             } else {
  295.                 return this.gaugeHeight();
  296.             }
  297.         }

  298.         gaugeWidth() {
  299.             return (
  300.                 hpBarWidth(this._battler && this._battler.enemy()) || Torigoya.EnemyHpBar.parameter.customizeGaugeWidth
  301.             );
  302.         }

  303.         gaugeHeight() {
  304.             return (
  305.                 hpBarHeight(this._battler && this._battler.enemy()) ||
  306.                 Torigoya.EnemyHpBar.parameter.customizeGaugeHeight
  307.             );
  308.         }

  309.         gaugeX() {
  310.             if (!Torigoya.EnemyHpBar.parameter.customizeDrawLabel) return 0;
  311.             return Torigoya.EnemyHpBar.parameter.customizeLabelWidth;
  312.         }

  313.         labelFontSize() {
  314.             return Torigoya.EnemyHpBar.parameter.customizeLabelFontSize;
  315.         }

  316.         valueFontSize() {
  317.             return Torigoya.EnemyHpBar.parameter.customizeValueFontSize;
  318.         }

  319.         updateTargetValue(value, maxValue) {
  320.             const oldDuration = this._duration;

  321.             super.updateTargetValue(value, maxValue);

  322.             if (oldDuration !== this._duration && BattleManager._phase !== '') {
  323.                 this._durationWait = this.durationWait();
  324.             }
  325.         }

  326.         updateGaugeAnimation() {
  327.             super.updateGaugeAnimation();
  328.             if (this._durationWait > 0 && this._duration <= 0) {
  329.                 --this._durationWait;
  330.             }
  331.         }

  332.         drawLabel() {
  333.             if (!Torigoya.EnemyHpBar.parameter.customizeDrawLabel) return;
  334.             super.drawLabel();
  335.         }

  336.         drawValue() {
  337.             if (!Torigoya.EnemyHpBar.parameter.customizeDrawLabel) return;
  338.             if (isShowHpValueOfBattler(this._battler)) {
  339.                 super.drawValue();
  340.             } else {
  341.                 this.drawMaskValue();
  342.             }
  343.         }

  344.         drawMaskValue() {
  345.             const width = this.bitmapWidth();
  346.             const height = this.bitmapHeight();
  347.             this.setupValueFont();
  348.             this.bitmap.drawText(Torigoya.EnemyHpBar.parameter.customizeMaskHpValue, 0, 0, width, height, 'right');
  349.         }

  350.         durationWait() {
  351.             return this._statusType === 'time' ? 0 : 60;
  352.         }

  353.         shouldShow() {
  354.             if (!this._battler) return false;
  355.             if (this._battler.isDead()) return false;
  356.             if (isHiddenHpBar(this._battler.enemy())) return false;

  357.             switch (Torigoya.EnemyHpBar.parameter.customizeCondition) {
  358.                 case 'always': {
  359.                     return true;
  360.                 }
  361.                 case 'selectOrDamage': {
  362.                     if (BattleManager._phase === 'start') return false;

  363.                     if (this._battler && this._battler.isSelected()) return true;
  364.                     if (BattleManager._phase === 'input') return false;

  365.                     if (this._duration > 0) return true;
  366.                     if (this._durationWait > 0) return true;

  367.                     break;
  368.                 }
  369.             }

  370.             return false;
  371.         }
  372.     }

  373.     Torigoya.EnemyHpBar.Sprite_EnemyHpGauge = Sprite_EnemyHpGauge;

  374.     (() => {
  375.         const upstream_Sprite_Enemy_initMembers = Sprite_Enemy.prototype.initMembers;
  376.         Sprite_Enemy.prototype.initMembers = function () {
  377.             upstream_Sprite_Enemy_initMembers.apply(this);
  378.             this.torigoyaEnemyHpBar_createGaugeSprite();
  379.         };

  380.         Sprite_Enemy.prototype.torigoyaEnemyHpBar_createGaugeSprite = function () {
  381.             this._torigoyaEnemyHpBar_gaugeSprite = new Torigoya.EnemyHpBar.Sprite_EnemyHpGauge();
  382.             this._torigoyaEnemyHpBar_gaugeSprite.anchor.x = 0.5;
  383.             this._torigoyaEnemyHpBar_gaugeSprite.opacity = 0;
  384.             this.addChild(this._torigoyaEnemyHpBar_gaugeSprite);
  385.         };

  386.         const upstream_Sprite_Enemy_setBattler = Sprite_Enemy.prototype.setBattler;
  387.         Sprite_Enemy.prototype.setBattler = function (battler) {
  388.             upstream_Sprite_Enemy_setBattler.apply(this, arguments);
  389.             this._torigoyaEnemyHpBar_gaugeSprite.setup(battler, 'hp');
  390.         };

  391.         const upstream_Sprite_Enemy_update = Sprite_Enemy.prototype.update;
  392.         Sprite_Enemy.prototype.update = function () {
  393.             upstream_Sprite_Enemy_update.apply(this);
  394.             if (this._enemy) {
  395.                 this.torigoyaEnemyHpBar_updateGaugeSprite();
  396.             }
  397.         };

  398.         Sprite_Enemy.prototype.torigoyaEnemyHpBar_updateGaugeSprite = function () {
  399.             this._torigoyaEnemyHpBar_gaugeSprite.x = this.torigoyaEnemyHpBar_posX();
  400.             this._torigoyaEnemyHpBar_gaugeSprite.y = this.torigoyaEnemyHpBar_posY();

  401.             this._torigoyaEnemyHpBar_gaugeSprite.opacity += this._torigoyaEnemyHpBar_gaugeSprite.shouldShow()
  402.                 ? 48
  403.                 : -48;
  404.         };

  405.         Sprite_Enemy.prototype.torigoyaEnemyHpBar_posX = function () {
  406.             let x = Torigoya.EnemyHpBar.parameter.basePosX;
  407.             x += hpBarX(this._battler && this._battler.enemy());
  408.             return x;
  409.         };

  410.         Sprite_Enemy.prototype.torigoyaEnemyHpBar_posY = function () {
  411.             let y = Torigoya.EnemyHpBar.parameter.basePosY;
  412.             if (this.bitmap && this.bitmap.isReady()) {
  413.                 switch (Torigoya.EnemyHpBar.parameter.basePosition) {
  414.                     case 'top':
  415.                         y -= this.bitmap.height + this._torigoyaEnemyHpBar_gaugeSprite.textHeight();
  416.                         break;
  417.                 }
  418.             }
  419.             y += hpBarY(this._battler && this._battler.enemy());

  420.             return y;
  421.         };
  422.     })();
  423. })();
复制代码


回复

使用道具 举报

您需要登录后才可以回帖 登录 | 注册用户

本版积分规则

Archiver|QQ群: 48625831|爱上RPG|哈库纳玛塔塔 |网站地图 Clicky

GMT+8, 2024-10-23 13:22 , Processed in 0.073266 second(s), 22 queries .

Powered by Discuz! X3.5

Copyright © 2001-2020, Tencent Cloud.

快速回复 返回顶部 返回列表