//============================================================================= // VariableControlItem.js // ---------------------------------------------------------------------------- // (C)2016 Triacontane // This software is released under the MIT License. // http://opensource.org/licenses/mit-license.php // ---------------------------------------------------------------------------- // Version // 1.2.0 2020/11/23 変数操作の実行条件に実行者を指定できる機能を追加 // 1.1.1 2017/04/19 範囲が「なし」の場合も操作できるよう修正 // 1.1.0 2016/10/21 加算と代入を別々のメモ欄で設定できるよう変更 // 1.0.0 2016/10/21 初版 // ---------------------------------------------------------------------------- // [Blog] : https://triacontane.blogspot.jp/ // [Twitter]: https://twitter.com/triacontane/ // [GitHub] : https://github.com/triacontane/ //============================================================================= /*: @url https://triacontane.blogspot.com/ @plugindesc Variable Operation Item Plugin @author Triacontane @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/triacontane-MV-plugins ). Original plugin by Triacontane. Please check the latest official version at: https://triacontane.blogspot.com ----- When an item or skill is used and the action is successful, you can manipulate variables. Specify the following in the item or skill's Note field. - Sets a value for variable number [3]. - Assigns the value [5] to the specified variable. - Adds the value [5] to the specified variable. - Variable manipulation only occurs if the performer is an actor. - Variable manipulation only occurs if the performer is an enemy character. * Specifying a negative value for the add value will result in subtraction. The setting value is evaluated as a JavaScript formula after applying control characters. For example, if you want to multiply variable [1] by [5] when using an item, use the following: - Multiply the value of variable [1] by [5] and set the result to variable [1]. This plugin does not have any plugin commands. Terms of Use: You may modify and redistribute this plugin without permission from the author, and there are no restrictions on its use (commercial, 18+, etc.). This plugin is now yours. */ /*:ja @plugindesc 変数操作アイテムプラグイン @author トリアコンタン @help アイテムもしくはスキルを使用し、かつ 行動が成功した場合に、変数を操作できます。 アイテムもしくはスキルのメモ欄に以下の通り指定してください。 # 変数番号[3]に値を設定します。 # 同上 # 指定した変数に値[5]を代入します。 # 同上 # 指定した変数に値[5]を加算します。 # 同上 # 実行者がアクターの場合のみ変数操作します。 # 同上 # 実行者が敵キャラの場合のみ変数操作します。 # 同上 ※加算値に負の値を指定すると減算になります。 設定値は、制御文字を適用した上でJavaScript計算式として評価されます。 たとえば、アイテムの使用で変数[1]に[5]を乗算したい場合は以下の通り設定します。 # 変数[1]の値に[5]を乗算した結果を変数[1]に設定 このプラグインにはプラグインコマンドはありません。 利用規約: 作者に無断で改変、再配布が可能で、利用形態(商用、18禁利用等) についても制限はありません。 このプラグインはもうあなたのものです。 */ (function () { 'use strict'; var metaTagPrefix = 'VCI'; var getArgNumber = function (arg, min, max) { if (arguments.length < 2) min = -Infinity; if (arguments.length < 3) max = Infinity; return (parseInt(convertEscapeCharacters(arg), 10) || 0).clamp(min, max); }; var getArgEval = function (arg, min, max) { if (arguments.length < 2) min = -Infinity; if (arguments.length < 3) max = Infinity; return (eval(convertEscapeCharacters(arg)) || 0).clamp(min, max); }; var getMetaValue = function (object, name) { var metaTagName = metaTagPrefix + (name ? name : ''); return object.meta.hasOwnProperty(metaTagName) ? object.meta[metaTagName] : undefined; }; var getMetaValues = function (object, names) { if (!Array.isArray(names)) return getMetaValue(object, names); for (var i = 0, n = names.length; i < n; i++) { var value = getMetaValue(object, names[i]); if (value !== undefined) return value; } return undefined; }; var convertEscapeCharacters = function (text) { if (text == null) text = ''; var windowLayer = SceneManager._scene._windowLayer; return windowLayer ? windowLayer.children[0].convertEscapeCharacters(text) : text; }; //============================================================================= // Game_Action // 行動が成功した場合、変数の操作を実行します。 //============================================================================= var _Game_Action_applyItemUserEffect = Game_Action.prototype.applyItemUserEffect; Game_Action.prototype.applyItemUserEffect = function (target) { _Game_Action_applyItemUserEffect.apply(this, arguments); if (!this.isForNone()) { this.applyVariableControl(); } }; var _Game_Action_applyGlobal = Game_Action.prototype.applyGlobal; Game_Action.prototype.applyGlobal = function (target) { _Game_Action_applyGlobal.apply(this, arguments); if (this.isForNone()) { this.applyVariableControl(); } }; Game_Action.prototype.isForNone = function () { return this.checkItemScope([0]); }; Game_Action.prototype.applyVariableControl = function () { if (!this.isVariableControlSubject()) { return; } var varNumberStr = getMetaValues(this.item(), ['VarNumber', '変数番号']); if (varNumberStr) { var varNumber = getArgNumber(varNumberStr, 0); var setValue = getMetaValues(this.item(), ['SetValue', '代入値']); if (setValue) { $gameVariables.setValue(varNumber, getArgEval(setValue)); return; } var addValue = getMetaValues(this.item(), ['AddValue', '加算値']); if (addValue) { var originalValue = $gameVariables.value(varNumber); $gameVariables.setValue(varNumber, originalValue + getArgEval(addValue)); } } }; Game_Action.prototype.isVariableControlSubject = function () { var subject = getMetaValues(this.item(), ['Subject', '実行者']); if (!subject || subject === true) { return true; } subject = subject.toLowerCase(); if (subject === 'actor' && this._subjectEnemyIndex >= 0) { return false; } if (subject === 'enemy' && this._subjectActorId > 0) { return false; } return true; }; })();