//============================================================================= // TMPlugin - エネミー行動予測 // バージョン: 1.1.0 // 最終更新日: 2018/08/21 // 配布元 : http://hikimoki.sakura.ne.jp/ //----------------------------------------------------------------------------- // Copyright (c) 2016 tomoaky // Released under the MIT license. // http://opensource.org/licenses/mit-license.php //============================================================================= /*: @plugindesc Displays text hints about the Enemies's next action. @author tomoaky @url https://github.com/munokura/tomoaky-MV-plugins @license MIT License @help English Help Translator: munokura This is an unofficial English translation of the plugin help, created to support global RPG Maker users. Feedback is welcome to improve translation quality (see: https://github.com/munokura/tomoaky-MV-plugins ). Original plugin by tomoaky. ----- TMPlugin - Enemy Action Prediction ver. 1.1.0 How to Use: Set action prediction using tags like in the skill's Note field. Predictive text will be displayed over the enemy graphics while you're entering party commands during battle scenes. This plugin has been tested with RPG Maker MV Version 1.6.1. This plugin is distributed under the MIT License and is free for commercial use, modification, and redistribution. Note field Tag (Skill): Predictive text will be displayed over the enemy graphics while you're entering commands on the turn the enemy will use this skill. If this tag is not present, the skill name will be displayed instead. You can add line breaks to the predictive text to display multiple lines of action predictions. However, the number of lines cannot exceed the number set by the plugin parameter maxLines. Displays icon number 5 at the beginning of the predictive text. If this tag is not present, a skill icon will be displayed instead. If the plugin parameter showIcon is set to OFF (false), the icon will not be displayed. Memo Tag (Enemies): Shifts the display position of this enemy's predicted behavior 50 dots to the right. To shift it to the left, set a negative value. Shifts the display position of this enemy's predicted behavior 80 dots down. To shift it up, set a negative value. Plugin Command: fsStop Disables the behavior prediction function. The behavior prediction function is enabled at the start of the game. The behavior prediction function status is saved in save data. fsStart Enables the behavior prediction function if it was previously disabled. Plugin Parameter Notes: maxLines Sets the maximum number of lines for the behavior prediction display. The more lines you add, the larger the bitmap generated will be, so do not set a value larger than necessary. If multiple actions occur per turn, you will need as many lines as there are actions. If line breaks are used in the action prediction display, the required number of lines will increase. color / backColor / headerColor This parameter accepts color names such as black or blue, and color codes such as #000000 or #0000ff. headerText This is the header text to display in the upper left of the action prediction. If nothing is entered, the header text will be hidden. cornerRadius By installing TMBitmapEx.js above this plugin and setting this parameter to a value of 1 or greater, you can make the background of the action prediction a rounded rectangle. @param width @desc Width of action prediction display Default: 240 @default 240 @type number @param maxLines @desc Maximum number of lines for action prediction display Default: 3 @default 3 @type number @param lineHeight @desc Height of one line of the action prediction display Initial value: 36 @default 36 @type number @param fontSize @desc Font size for predictive behavior display Default: 28 @default 28 @type number @param color @desc Prediction Show Text color Default: white @default white @param backColor @desc Background color of the action prediction display Default: black @default black @param backOpacity @desc Background opacity of the action prediction display. Default: 128 (0 to 255) @default 128 @type number @max 255 @param textAlign @desc Alignment of action prediction display @default center @type select @option left @option center @option right @param showIcon @desc Display an icon at the beginning of the skill name. Default: ON (ON = Display / OFF = Hide) @default true @type boolean @param headerText @desc Header text for action prediction display Default: Next @default Next @param headerHeight @desc Header height for action prediction display Default: 20 @default 20 @type number @param headerFontSize @desc Font size of header for action prediction display Default: 16 @default 16 @type number @param headerColor @desc Prediction header text color Default: red @default red @param cornerRadius @desc Radius of the rounded part of the rounded rectangle when TMBitmapEx.js is installed. Default value: 6 @default 6 @type number */ /*:ja @plugindesc 敵キャラの次の行動のヒントなどをテキストで表示します。 @author tomoaky @url https://github.com/munokura/tomoaky-MV-plugins @license MIT License @help TMPlugin - エネミー行動予測 ver1.1.0 使い方: スキルのメモ欄に のようなタグで行動予測の設定を してください。 戦闘シーンでパーティのコマンドを入力している間、敵グラフィックに 重なるように予測テキストが表示されるようになります。 このプラグインは RPGツクールMV Version 1.6.1 で動作確認をしています。 このプラグインはMITライセンスのもとに配布しています、商用利用、 改造、再配布など、自由にお使いいただけます。 メモ欄タグ(スキル): 敵がこのスキルを使用するターンのコマンド入力中に、予測テキストが 敵グラフィックに重なるように表示されます。 このタグがない場合はスキル名を代わりに表示します。 予測テキストを途中で改行することで、行動予測の表示も複数行になります。 ただしプラグインパラメータ maxLines で設定した行数を超えることは できません。 予測テキストの頭に 5 番のアイコンを表示します。 このタグがない場合はスキルアイコンを代わりに表示します。 プラグインパラメータ showIcon がOFF(false)の場合は表示しません。 メモ欄タグ(敵キャラ): この敵の行動予測の表示位置を右に 50 ドットずらします。左にずらす場合は 負の値を設定してください。 この敵の行動予測の表示位置を下に 80 ドットずらします。上にずらす場合は 負の値を設定してください。 プラグインコマンド: fsStop 行動予測機能を無効にします。ゲーム開始時は行動予測機能が有効に なっています。行動予測機能の状態はセーブデータに保存されます。 fsStart 無効にした行動予測機能を有効にします。 プラグインパラメータ補足: maxLines 行動予測表示の最大行数を設定します。行数が多いほど大きなビットマップが 生成されるため、必要以上に大きな値は設定しないでください。 1ターンに複数回の行動がある場合、行動回数分の行数が必要になります。 行動予測表示に改行を利用する場合はさらに必要な行数が増えます。 color / backColor / headerColor このパラメータには、black や blue といったカラーネームと、 #000000 や #0000ff のようなカラーコードを設定することができます。 headerText 行動予測の左上に表示するヘッダーテキストです。何も入力しなければ ヘッダーテキストは非表示になります。 cornerRadius TMBitmapEx.js をこのプラグインよりも上の位置に導入しつつ、 このパラメータの値を 1 以上にすることで、行動予測の背景を 角丸の矩形にすることができます。 @param width @desc 行動予測表示の横幅 初期値: 240 @default 240 @type number @param maxLines @desc 行動予測表示の最大行数 初期値: 3 @default 3 @type number @param lineHeight @desc 行動予測表示の 1 行の高さ 初期値: 36 @default 36 @type number @param fontSize @desc 行動予測表示のフォントサイズ 初期値: 28 @default 28 @type number @param color @desc 行動予測表示の文字色 初期値: white @default white @param backColor @desc 行動予測表示の背景の色 初期値: black @default black @param backOpacity @desc 行動予測表示の背景の不透明度 初期値: 128 ( 0 ~ 255 ) @default 128 @type number @max 255 @param textAlign @desc 行動予測表示の行揃え @default center @type select @option left @option center @option right @param showIcon @desc スキル名の頭にアイコンも表示する 初期値: ON( ON = 表示 / OFF = 非表示 ) @default true @type boolean @param headerText @desc 行動予測表示のヘッダーテキスト 初期値: Next @default Next @param headerHeight @desc 行動予測表示のヘッダーの高さ 初期値: 20 @default 20 @type number @param headerFontSize @desc 行動予測表示のヘッダーのフォントサイズ 初期値: 16 @default 16 @type number @param headerColor @desc 行動予測表示のヘッダーの文字色 初期値: red @default red @param cornerRadius @desc TMBitmapEx.js導入時の、角丸矩形の丸部分の半径 初期値: 6 @default 6 @type number */ var Imported = Imported || {}; Imported.TMFutureSight = true; (function() { var parameters = PluginManager.parameters('TMFutureSight'); var SightWidth = +(parameters['width'] || 240); var SightMaxLines = +(parameters['maxLines'] || 3); var SightLineHeight = +(parameters['lineHeight'] || 36); var SightFontSize = +(parameters['fontSize'] || 28); var SightColor = parameters['color'] || 'white'; var SightBackColor = parameters['backColor'] || 'black'; var SightBackOpacity = +(parameters['backOpacity'] || 128); var SightCornerRadius = +(parameters['cornerRadius'] || 6); var SightTextAlign = parameters['textAlign'] || 'center'; var SightShowIcon = JSON.parse(parameters['showIcon'] || 'true'); var SightHeaderText = parameters['headerText']; var SightHeaderHeight = +(parameters['headerHeight'] || 20); var SightHeaderFontSize = +(parameters['headerFontSize'] || 16); var SightHeaderColor = parameters['headerColor'] || 'red'; //----------------------------------------------------------------------------- // Game_System // Game_System.prototype.isFutureSightEnabled = function() { if (this._futureSightEnabled == null) { this._futureSightEnabled = true; } return this._futureSightEnabled; }; Game_System.prototype.disableFutureSight = function() { this._futureSightEnabled = false; }; Game_System.prototype.enableFutureSight = function() { this._futureSightEnabled = true; }; //----------------------------------------------------------------------------- // Game_Enemy // Game_Enemy.prototype.setFutureSightTexts = function() { this._futureSightTexts = []; this._futureSightIcons = []; for (var i = 0; i < this._actions.length; i++) { if (this._actions[i]) { var skill = this._actions[i].item(); if (skill) { if (skill.meta.fsText) { this._futureSightTexts.push(skill.meta.fsText); } else { this._futureSightTexts.push(skill.name); } this._futureSightIcons.push(this.fsIconIndex(skill)); } } } }; Game_Enemy.prototype.fsIconIndex = function(skill) { if (!SightShowIcon) { return 0; } if (skill.meta.fsIcon) { return +skill.meta.fsIcon; } return skill.iconIndex; }; Game_Enemy.prototype.resetFutureSightTexts = function() { this._futureSightTexts = []; }; Game_Enemy.prototype.futureSightTexts = function() { return this._futureSightTexts || []; }; Game_Enemy.prototype.futureSightIcons = function() { return this._futureSightIcons || []; }; //----------------------------------------------------------------------------- // Game_Troop // var _Game_Troop_makeActions = Game_Troop.prototype.makeActions; Game_Troop.prototype.makeActions = function() { _Game_Troop_makeActions.call(this); if ($gameSystem.isFutureSightEnabled() && !BattleManager._preemptive) { this.members().forEach(function(member) { member.setFutureSightTexts(); }); } }; var _Game_Troop_increaseTurn = Game_Troop.prototype.increaseTurn; Game_Troop.prototype.increaseTurn = function() { _Game_Troop_increaseTurn.call(this); this.members().forEach(function(member) { member.resetFutureSightTexts(); }); }; //----------------------------------------------------------------------------- // Game_Interpreter // var _Game_Interpreter_pluginCommand = Game_Interpreter.prototype.pluginCommand; Game_Interpreter.prototype.pluginCommand = function(command, args) { _Game_Interpreter_pluginCommand.call(this, command, args); if (command === 'fsStart') { $gameSystem.enableFutureSight(); } else if (command === 'fsStop') { $gameSystem.disableFutureSight(); } }; //----------------------------------------------------------------------------- // Sprite_Enemy // var _Sprite_Enemy_update = Sprite_Enemy.prototype.update; Sprite_Enemy.prototype.update = function() { _Sprite_Enemy_update.call(this); if (this._enemy) { this.updateFutureSight(); } }; Sprite_Enemy.prototype.updateFutureSight = function() { if (!this._futureSightSprite && this.parent) { this._futureSightSprite = new Sprite_FutureSight(this); this.parent.addChild(this._futureSightSprite); } }; //----------------------------------------------------------------------------- // Sprite_FutureSight // function Sprite_FutureSight() { this.initialize.apply(this, arguments); } Sprite_FutureSight.prototype = Object.create(Sprite.prototype); Sprite_FutureSight.prototype.constructor = Sprite_FutureSight; Sprite_FutureSight.prototype.initialize = function(enemySprite) { Sprite.prototype.initialize.call(this); this._enemySprite = enemySprite; var width = SightWidth; var height = SightLineHeight * SightMaxLines + SightHeaderHeight; this.bitmap = new Bitmap(width, height); this.anchor.x = 0.5; this.anchor.y = 1; this.z = 10; this._texts = []; this._icons = []; }; Sprite_FutureSight.prototype.refresh = function() { this.bitmap.clear(); if (this._texts.length > 0) { var lines = this._texts.reduce(function(r, text) { return r + text.split('\n').length; }, 0); var y = SightHeaderHeight; var width = this.bitmap.width; var height = SightLineHeight * lines; this.drawSightBack(0, y, width, height); this.drawSightHeader(0, 0, width, SightHeaderHeight); this.drawSightText(4, y, width - 8, SightLineHeight); } }; Sprite_FutureSight.prototype.drawSightBack = function(x, y, width, height) { this.bitmap.paintOpacity = SightBackOpacity; if (Imported.TMBitmapEx && SightCornerRadius) { this.bitmap.fillRoundRect(x, y, width, height, SightCornerRadius, SightBackColor); } else { this.bitmap.fillRect(x, y, width, height, SightBackColor); } this.bitmap.paintOpacity = 255; }; Sprite_FutureSight.prototype.drawSightHeader = function(x, y, width, height) { if (SightHeaderText) { this.bitmap.fontSize = SightHeaderFontSize; this.bitmap.textColor = SightHeaderColor; this.bitmap.drawText(SightHeaderText, x, y, width, height); } }; Sprite_FutureSight.prototype.drawSightText = function(x, y, width, height) { this.bitmap.fontSize = SightFontSize; this.bitmap.textColor = SightColor; for (var i = 0; i < this._texts.length; i++) { var text = this._texts[i]; var iconIndex = this._icons[i]; var dx = x; var dw = width; if (iconIndex > 0) { var iconX = this.sightIconX(text, width); if (iconX <= 0) { iconX = 0; dx += SightLineHeight; dw -= SightLineHeight; } this.drawSightIcon(iconIndex, x + iconX, y); } var arr = text.split('\n'); for (var j = 0; j < arr.length; j++) { this.bitmap.drawText(arr[j], dx, y, dw, height, SightTextAlign); y += SightLineHeight; } } }; Sprite_FutureSight.prototype.sightIconX = function(text, width) { var textWidth = this.bitmap.measureTextWidth(text); if (SightTextAlign === 'left') { return 0; } else if (SightTextAlign === 'center') { return (width - textWidth) / 2 - SightLineHeight; } else { return width - textWidth - SightLineHeight; } }; Sprite_FutureSight.prototype.drawSightIcon = function(iconIndex, x, y) { var bitmap = ImageManager.loadSystem('IconSet'); var pw = Window_Base._iconWidth; var ph = Window_Base._iconHeight; var sx = iconIndex % 16 * pw; var sy = Math.floor(iconIndex / 16) * ph; var dw = SightLineHeight - 4; var dh = SightLineHeight - 4; this.bitmap.blt(bitmap, sx, sy, pw, ph, x + 2, y + 2, dw, dh); }; Sprite_FutureSight.prototype.update = function() { Sprite.prototype.update.call(this); var futureSightTexts = this._enemySprite._enemy.futureSightTexts().concat(); var futureSightIcons = this._enemySprite._enemy.futureSightIcons().concat(); if (this._texts.toString() !== futureSightTexts.toString() || this._icons.toString() !== futureSightIcons.toString()) { this._texts = futureSightTexts; this._icons = futureSightIcons; this.refresh(); } var enemy = this._enemySprite._enemy.enemy(); this.x = this._enemySprite.x + (+enemy.meta.fsOffsetX || 0); this.y = this._enemySprite.y + (+enemy.meta.fsOffsetY || 0); }; })();