|
简易的敌人血条
原地址:Torigoya_EnemyHpBar / 敵にHPバーを表示プラグイン | 鳥小屋プラグイン置き場 (rutan.dev)
预览:
脚本:
- /*---------------------------------------------------------------------------*
- * TorigoyaMZ_EnemyHpBar.js v.1.3.2
- *---------------------------------------------------------------------------*
- * 2021/10/10 20:48 (JST)
- *---------------------------------------------------------------------------*
- * Ruたん ( @ru_shalm )
- * https://torigoya-plugin.rutan.dev
- *---------------------------------------------------------------------------*/
- /*:
- * @target MZ
- * @plugindesc 敌人血条显示插件 (v.1.3.2)
- * 汉化 by 烁灵 更多插件请访问 www.hknmtt.com
- * @author Ruたん(ru_shalm)
- * @license public domain
- * @version 1.3.2
- * @url https://raw.githubusercontent.com/rutan/torigoya-rpg-maker-plugin/gh-pages/TorigoyaMZ_EnemyHpBar.js
- * @help
- * 敵にHPバーを表示プラグイン (v.1.3.2)
- * https://torigoya-plugin.rutan.dev
- *
- * 显示敌人HP条
- *
- * ------------------------------------------------------------
- * ■ 使用方法
- * ------------------------------------------------------------
- * 开启插件即可
- * 详细设定请修改插件参数
- *
- * ------------------------------------------------------------
- * ■ 可以单独设定敌人显示血条的效果
- * ------------------------------------------------------------
- * 以下设定在敌人备注栏生效
- *
- * ▼ 指定敌人不显示血条
- * <HP条不显示>
- *
- * ▼ x 坐标偏移
- * <HP条X: 100>
- *
- * ※表示向右移动 100 像素,负数则向左
- *
- * ▼ y 坐标偏移
- * <HP条Y: 100>
- *
- * ※表示向下移动 100 像素,负数则向上
- *
- * ▼ 修改为指定宽度
- * <HP条宽度: 320>
- *
- * ▼ 修改为指定高度
- * <HP条高度: 30>
- *
- * ▼ 敌人 hp 满足条件的时候出现hp数值
- *
- * <HP显示条件: false>
- *
- * ▼ 比如,hp 变为一半才出现:
- *
- * <HP显示条件: a.hp < a.mhp * 0.5>
- *
- * 使用伤害计算公式格式的表达式
- * (a 是敌人。不过 b 不能使用)
- * 不能使用 大于号 >,如果需要请写成 「 > 」
- * 条件为真时 hp 会显示
- * 为假时会显示 ?????
- *
- * ▼ 以下设定使显示条件达到后不再隐藏 hp
- *
- * <HP表示条件: a.hp < a.mhp * 0.5>
- * <HP显示持续>
- *
- * 此处的 <HP显示持续> 追加注释表示
- * 该战斗中一旦显示过 hp,则不会再显示为 ?????
- *
- * @param base
- * @text ■ 基本设定
- *
- * @param basePosition
- * @text 显示位置
- * @desc HP 调的显示位置
- * @type select
- * @parent base
- * @option 敌人图像上方
- * @value top
- * @option 敌人图像下方
- * @value bottom
- * @default top
- *
- * @param basePosX
- * @text 坐标偏移:X
- * @desc 横坐标偏移
- * 负数为左,正数为右
- * @type number
- * @parent base
- * @min -10000
- * @max 10000
- * @default 0
- *
- * @param basePosY
- * @text 坐标偏移:Y
- * @desc 纵坐标偏移
- * 负数为上,正数为下
- * @type number
- * @parent base
- * @min -10000
- * @max 10000
- * @default 0
- *
- * @param customize
- * @text ■ 自定义参数
- *
- * @param customizeCondition
- * @text 显示条件
- * @desc 血条显示条件
- * @type select
- * @parent customize
- * @option 一直显示
- * @value always
- * @option 选中、受伤时
- * @value selectOrDamage
- * @default always
- *
- * @param customizeGaugeWidth
- * @text 宽度
- * @desc HP条宽度
- * @type number
- * @parent customize
- * @min 1
- * @default 100
- *
- * @param customizeGaugeHeight
- * @text 高度
- * @desc HP条高度
- * @type number
- * @parent customize
- * @min 1
- * @default 10
- *
- * @param customizeDrawLabel
- * @text HP数值
- * @desc 是否显示HP数值
- * @type boolean
- * @parent customize
- * @on 显示
- * @off 不显示
- * @default true
- *
- * @param customizeLabelWidth
- * @text HP宽度调整
- * @desc HP宽度调整值
- * @type number
- * @parent customize
- * @min 0
- * @default 20
- *
- * @param customizeLabelFontSize
- * @text HP 字符字号
- * @desc HP 字符字号
- * @type number
- * @parent customize
- * @min 1
- * @default 16
- *
- * @param customizeValueFontSize
- * @text HP 数值字号
- * @desc HP 数值字号
- * @type number
- * @parent customize
- * @min 1
- * @default 20
- *
- * @param customizeMaskHpValue
- * @text HP暗号文字
- * @desc HP数值未知时的文字
- * @type string
- * @parent customize
- * @default ?????
- */
- (function () {
- 'use strict';
- const Torigoya = (window.Torigoya = window.Torigoya || {});
- function getPluginName() {
- const cs = document.currentScript;
- return cs ? cs.src.split('/').pop().replace(/\.js$/, '') : 'TorigoyaMZ_EnemyHpBar';
- }
- function pickStringValueFromParameter(parameter, key, defaultValue = '') {
- if (!parameter.hasOwnProperty(key)) return defaultValue;
- return ''.concat(parameter[key] || '');
- }
- function pickIntegerValueFromParameter(parameter, key, defaultValue = 0) {
- if (!parameter.hasOwnProperty(key) || parameter[key] === '') return defaultValue;
- return parseInt(parameter[key], 10);
- }
- function pickBooleanValueFromParameter(parameter, key, defaultValue = 'false') {
- return ''.concat(parameter[key] || defaultValue) === 'true';
- }
- function readParameter() {
- const parameter = PluginManager.parameters(getPluginName());
- return {
- version: '1.3.2',
- basePosition: pickStringValueFromParameter(parameter, 'basePosition', 'top'),
- basePosX: pickIntegerValueFromParameter(parameter, 'basePosX', 0),
- basePosY: pickIntegerValueFromParameter(parameter, 'basePosY', 0),
- customizeCondition: pickStringValueFromParameter(parameter, 'customizeCondition', 'always'),
- customizeGaugeWidth: pickIntegerValueFromParameter(parameter, 'customizeGaugeWidth', 100),
- customizeGaugeHeight: pickIntegerValueFromParameter(parameter, 'customizeGaugeHeight', 10),
- customizeDrawLabel: pickBooleanValueFromParameter(parameter, 'customizeDrawLabel', 'true'),
- customizeLabelWidth: pickIntegerValueFromParameter(parameter, 'customizeLabelWidth', 20),
- customizeLabelFontSize: pickIntegerValueFromParameter(parameter, 'customizeLabelFontSize', 16),
- customizeValueFontSize: pickIntegerValueFromParameter(parameter, 'customizeValueFontSize', 20),
- customizeMaskHpValue: pickStringValueFromParameter(parameter, 'customizeMaskHpValue', '?????'),
- };
- }
- function unescapeMetaString(string) {
- return ''
- .concat(string || '')
- .trim()
- .replace(/</g, '<')
- .replace(/>/g, '>');
- }
- Torigoya.EnemyHpBar = {
- name: getPluginName(),
- parameter: readParameter(),
- };
- function isHiddenHpBar(enemy) {
- return !enemy || enemy.meta['hiddenHpBar'] || enemy.meta['HP条不显示'];
- }
- function hpBarX(enemy) {
- return parseInt((enemy && (enemy.meta['hpBarPosX'] || enemy.meta['HP条X'])) || 0, 10);
- }
- function hpBarY(enemy) {
- return parseInt((enemy && (enemy.meta['hpBarPosY'] || enemy.meta['HP条Y'])) || 0, 10);
- }
- function hpBarWidth(enemy) {
- return parseInt((enemy && (enemy.meta['hpBarWidth'] || enemy.meta['HP条宽度'])) || 0, 10);
- }
- function hpBarHeight(enemy) {
- return parseInt((enemy && (enemy.meta['hpBarHeight'] || enemy.meta['HP条高度'])) || 0, 10);
- }
- const forceShowHpValueCache = new WeakSet();
- function isShowHpValueOfBattler(a) {
- if (!a) return true;
- if (forceShowHpValueCache.has(a)) return true;
- const enemy = a.enemy();
- const code = enemy.meta['hpShowCondition'] || enemy.meta['HP显示条件'] || '';
- if (!code) return true;
- try {
- if (eval(unescapeMetaString(code))) {
- if (enemy.meta['hpShowPermanently'] || enemy.meta['HP显示持续']) {
- forceShowHpValueCache.add(a);
- }
- return true;
- }
- } catch (e) {
- if ($gameTemp.isPlaytest()) console.error(e);
- }
- return false;
- }
- class Sprite_EnemyHpGauge extends Sprite_Gauge {
- constructor() {
- super();
- this._durationWait = 0;
- }
- setup(battler, statusType) {
- if (this._battler === battler) return;
- this._battler = battler;
- this.reCreateBitmap();
- super.setup(battler, statusType);
- }
- reCreateBitmap() {
- if (this.bitmap) this.bitmap.destroy();
- this.bitmap = null;
- this.createBitmap();
- }
- bitmapWidth() {
- return this.gaugeWidth() + this.gaugeX();
- }
- bitmapHeight() {
- // コアスクリプトv.1.3.3 の以下の修正内容を適用
- // > HP(略)MP(略)TP(略)に一部の英文字を利用すると見切れる問題を修正
- if (Sprite_Gauge.prototype.textHeight) {
- return Math.round(this.textHeight() * 1.5);
- } else {
- return this.textHeight();
- }
- }
- textHeight() {
- if (Torigoya.EnemyHpBar.parameter.customizeDrawLabel) {
- return Math.max(
- this.labelFontSize() + this.labelOutlineWidth(),
- this.valueFontSize() + this.valueOutlineWidth(),
- this.gaugeHeight()
- );
- } else {
- return this.gaugeHeight();
- }
- }
- gaugeWidth() {
- return (
- hpBarWidth(this._battler && this._battler.enemy()) || Torigoya.EnemyHpBar.parameter.customizeGaugeWidth
- );
- }
- gaugeHeight() {
- return (
- hpBarHeight(this._battler && this._battler.enemy()) ||
- Torigoya.EnemyHpBar.parameter.customizeGaugeHeight
- );
- }
- gaugeX() {
- if (!Torigoya.EnemyHpBar.parameter.customizeDrawLabel) return 0;
- return Torigoya.EnemyHpBar.parameter.customizeLabelWidth;
- }
- labelFontSize() {
- return Torigoya.EnemyHpBar.parameter.customizeLabelFontSize;
- }
- valueFontSize() {
- return Torigoya.EnemyHpBar.parameter.customizeValueFontSize;
- }
- updateTargetValue(value, maxValue) {
- const oldDuration = this._duration;
- super.updateTargetValue(value, maxValue);
- if (oldDuration !== this._duration && BattleManager._phase !== '') {
- this._durationWait = this.durationWait();
- }
- }
- updateGaugeAnimation() {
- super.updateGaugeAnimation();
- if (this._durationWait > 0 && this._duration <= 0) {
- --this._durationWait;
- }
- }
- drawLabel() {
- if (!Torigoya.EnemyHpBar.parameter.customizeDrawLabel) return;
- super.drawLabel();
- }
- drawValue() {
- if (!Torigoya.EnemyHpBar.parameter.customizeDrawLabel) return;
- if (isShowHpValueOfBattler(this._battler)) {
- super.drawValue();
- } else {
- this.drawMaskValue();
- }
- }
- drawMaskValue() {
- const width = this.bitmapWidth();
- const height = this.bitmapHeight();
- this.setupValueFont();
- this.bitmap.drawText(Torigoya.EnemyHpBar.parameter.customizeMaskHpValue, 0, 0, width, height, 'right');
- }
- durationWait() {
- return this._statusType === 'time' ? 0 : 60;
- }
- shouldShow() {
- if (!this._battler) return false;
- if (this._battler.isDead()) return false;
- if (isHiddenHpBar(this._battler.enemy())) return false;
- switch (Torigoya.EnemyHpBar.parameter.customizeCondition) {
- case 'always': {
- return true;
- }
- case 'selectOrDamage': {
- if (BattleManager._phase === 'start') return false;
- if (this._battler && this._battler.isSelected()) return true;
- if (BattleManager._phase === 'input') return false;
- if (this._duration > 0) return true;
- if (this._durationWait > 0) return true;
- break;
- }
- }
- return false;
- }
- }
- Torigoya.EnemyHpBar.Sprite_EnemyHpGauge = Sprite_EnemyHpGauge;
- (() => {
- const upstream_Sprite_Enemy_initMembers = Sprite_Enemy.prototype.initMembers;
- Sprite_Enemy.prototype.initMembers = function () {
- upstream_Sprite_Enemy_initMembers.apply(this);
- this.torigoyaEnemyHpBar_createGaugeSprite();
- };
- Sprite_Enemy.prototype.torigoyaEnemyHpBar_createGaugeSprite = function () {
- this._torigoyaEnemyHpBar_gaugeSprite = new Torigoya.EnemyHpBar.Sprite_EnemyHpGauge();
- this._torigoyaEnemyHpBar_gaugeSprite.anchor.x = 0.5;
- this._torigoyaEnemyHpBar_gaugeSprite.opacity = 0;
- this.addChild(this._torigoyaEnemyHpBar_gaugeSprite);
- };
- const upstream_Sprite_Enemy_setBattler = Sprite_Enemy.prototype.setBattler;
- Sprite_Enemy.prototype.setBattler = function (battler) {
- upstream_Sprite_Enemy_setBattler.apply(this, arguments);
- this._torigoyaEnemyHpBar_gaugeSprite.setup(battler, 'hp');
- };
- const upstream_Sprite_Enemy_update = Sprite_Enemy.prototype.update;
- Sprite_Enemy.prototype.update = function () {
- upstream_Sprite_Enemy_update.apply(this);
- if (this._enemy) {
- this.torigoyaEnemyHpBar_updateGaugeSprite();
- }
- };
- Sprite_Enemy.prototype.torigoyaEnemyHpBar_updateGaugeSprite = function () {
- this._torigoyaEnemyHpBar_gaugeSprite.x = this.torigoyaEnemyHpBar_posX();
- this._torigoyaEnemyHpBar_gaugeSprite.y = this.torigoyaEnemyHpBar_posY();
- this._torigoyaEnemyHpBar_gaugeSprite.opacity += this._torigoyaEnemyHpBar_gaugeSprite.shouldShow()
- ? 48
- : -48;
- };
- Sprite_Enemy.prototype.torigoyaEnemyHpBar_posX = function () {
- let x = Torigoya.EnemyHpBar.parameter.basePosX;
- x += hpBarX(this._battler && this._battler.enemy());
- return x;
- };
- Sprite_Enemy.prototype.torigoyaEnemyHpBar_posY = function () {
- let y = Torigoya.EnemyHpBar.parameter.basePosY;
- if (this.bitmap && this.bitmap.isReady()) {
- switch (Torigoya.EnemyHpBar.parameter.basePosition) {
- case 'top':
- y -= this.bitmap.height + this._torigoyaEnemyHpBar_gaugeSprite.textHeight();
- break;
- }
- }
- y += hpBarY(this._battler && this._battler.enemy());
- return y;
- };
- })();
- })();
复制代码
|
|