//============================================================================= // ステートの自動付与解除条件を設定するプラグイン // FTKR_AutoStateConditions.js // プラグインNo : 32 // 作成者 : フトコロ // 作成日 : 2017/05/02 // 最終更新日 : 2019/04/14 // バージョン : v1.0.1 //============================================================================= var Imported = Imported || {}; Imported.FTKR_ASC = true; var FTKR = FTKR || {}; FTKR.ASC = FTKR.ASC || {}; //============================================================================= /*: @plugindesc v1.0.1 Plugin that sets automatic state grant/revocation conditions @author Futokoro @url https://github.com/munokura/futokoro-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/futokoro-MV-plugins ). Original plugin by Futokoro. Please check the URL below for the latest version of the plugin. URL https://github.com/futokoro/RPGMaker ----- ----------------------------------------------------------------------------- Overview ----------------------------------------------------------------------------- By implementing this plugin, you can add automatic state assignment and removal conditions. Enter the following tags in the state's Note field. - Automatic assignment - Automatically assigns the state when the condition expression is met. Condition Expression - Automatic removal - Automatically removes the state when the condition expression is met. Condition Expression [About the Value of the Condition Expression (eval)] The condition expression (eval) allows you to use non-fixed values by entering a calculation expression, like the damage calculation formula. The following code can be used: a.param - References the parameter of the character being assigned a state. s[x] - References the state of switch ID x. v[x] - References the value of variable ID x. Input Example) The tag is enabled when switch ID 1 is ON. s[1] [Setting Multiple Conditions] The following two input examples have the same meaning. 1. Arrange multiple condition expressions vertically. Condition 1 Condition 2 1. Arrange multiple condition expressions horizontally using '&&'. Condition 1 && Condition 2 ----------------------------------------------------------------------------- Setup Instructions ----------------------------------------------------------------------------- 1. Add this plugin to the "Plugin Manager." ----------------------------------------------------------------------------- License for this plugin ----------------------------------------------------------------------------- This plugin is released under the MIT License. Copyright (c) 2017 Futokoro http://opensource.org/licenses/mit-license.php ----------------------------------------------------------------------------- Change History ----------------------------------------------------------------------------- v1.0.1 - 2019/04/13: Processing revisions 1. Part of the automatic state assignment and cancellation process is now executed at game startup. v1.0.0 - 2017/05/02: First version created ----------------------------------------------------------------------------- */ /*:ja @plugindesc v1.0.1 ステートの自動付与解除条件を設定するプラグイン @author Futokoro @url https://github.com/munokura/futokoro-MV-plugins @license MIT License @help ----------------------------------------------------------------------------- 概要 ----------------------------------------------------------------------------- 本プラグインを実装することで、ステートの自動付与および解除条件を追加できます。 以下のタグをステートのメモ欄に記入してください。 ・自動付与の場合 - 条件式を満たした時に自動で付与する 条件式 または 条件式 ・自動解除の場合 - 条件式を満たした時に自動で解除する 条件式 または 条件式 [条件式(eval) の値について] 条件式(eval)は、ダメージ計算式のように、計算式を入力することで、 固定値以外の値を使用することができます。以下のコードを使用できます。 a.param - ステート付与中のキャラのパラメータを参照します。 s[x] - スイッチID x の状態を参照します。 v[x] - 変数ID x の値を参照します。 入力例) スイッチID1 が ON の時にタグが有効になる。 s[1] [複数の条件を設定する場合] 以下の2種類の入力例は同じ意味です。 1. 縦に複数の条件式を並べる 条件式1 条件式2 1. '&&'を使用して横に複数の条件式を並べる 条件式1 && 条件式2 ----------------------------------------------------------------------------- 設定方法 ----------------------------------------------------------------------------- 1.「プラグインマネージャー(プラグイン管理)」に、本プラグインを追加して ください。 ----------------------------------------------------------------------------- 本プラグインのライセンスについて(License) ----------------------------------------------------------------------------- 本プラグインはMITライセンスのもとで公開しています。 Copyright (c) 2017 Futokoro http://opensource.org/licenses/mit-license.php ----------------------------------------------------------------------------- 変更来歴 ----------------------------------------------------------------------------- v1.0.1 - 2019/04/13 : 処理見直し 1. ステートの自動付与および自動解除判定の一部処理をゲーム起動時実行に変更。 v1.0.0 - 2017/05/02 : 初版作成 ----------------------------------------------------------------------------- */ //============================================================================= //============================================================================= // プラグイン パラメータ //============================================================================= FTKR.ASC.parameters = PluginManager.parameters('FTKR_AutoStateConditions'); //============================================================================= // 自作関数(グローバル) //============================================================================= FTKR.gameData = FTKR.gameData || { user: null, target: null, item: null, number: 0, }; if (!FTKR.setGameData) { FTKR.setGameData = function (user, target, item, number) { FTKR.gameData = { user: user || null, target: target || null, item: item || null, number: number || 0 }; }; } if (!FTKR.evalFormula) { FTKR.evalFormula = function (formula) { var datas = FTKR.gameData; try { var s = $gameSwitches._data; var v = $gameVariables._data; var a = datas.user; var b = datas.target; var item = datas.item; var number = datas.number; if (b) var result = b.result(); var value = eval(formula); if (isNaN(value)) value = 0; return value; } catch (e) { console.error(e); return 0; } }; } //============================================================================= // 自作関数(ローカル) //============================================================================= Array.prototype.convertEntrapmentRegArray = function () { return this.map(function (str) { return { a: new RegExp('<' + str + '>', 'i'), b: new RegExp('<\/' + str + '>', 'i') }; }); }; //正規表現オブジェクトの配列とdataをテストする Array.prototype.testRegs = function (data, prop) { return this.some(function (reg) { return prop ? reg[prop].test(data) : reg.test(data); }); }; // textの形式のメタデータを読み取ってtextを返す var readEntrapmentCodeToText = function (obj, codeTitles) { notes = codeTitles.convertEntrapmentRegArray(); var notedata = obj.note.split(/[\r\n]+/); var setMode = 'none'; for (var i = 0; i < notedata.length; i++) { var line = notedata[i]; if (notes.testRegs(line, 'a')) { var text = ''; setMode = 'read'; } else if (notes.testRegs(line, 'b')) { setMode = 'none'; } else if (setMode === 'read') { text += line + ';'; } } return text; }; // textを条件式に使える状態に変換する var convertTextToConditions = function (text) { var result = ''; if (text) { var datas = text.split(';'); datas.forEach(function (data, i) { result += data; if (datas[i + 1]) result += ')&&('; }); result = '(' + result + ')'; } return result; }; //============================================================================= // DataManager //============================================================================= var _DatabaseLoaded = false; var _DataManager_isDatabaseLoaded = DataManager.isDatabaseLoaded; DataManager.isDatabaseLoaded = function () { if (!_DataManager_isDatabaseLoaded.call(this)) return false; if (!_DatabaseLoaded) { this.ascStateNotetags($dataStates); _DatabaseLoaded = true; } return true; }; DataManager.ascStateNotetags = function (group) { for (var n = 1; n < group.length; n++) { var obj = group[n]; obj.asc = {}; obj.asc.add = convertTextToConditions(readEntrapmentCodeToText(obj, ['ASC_付与条件', 'ASC_ADD_CONDITIONS'])); obj.asc.remove = convertTextToConditions(readEntrapmentCodeToText(obj, ['ASC_解除条件', 'ASC_REMOMVE_CONDITIONS'])); } }; DataManager.evalRemoveStateConditions = function (obj) { var formula = obj.asc.remove; if (!formula) return false; return FTKR.evalFormula(formula); }; DataManager.evalAddStateConditions = function (obj) { var formula = obj.asc.add; if (!formula) return false; return FTKR.evalFormula(formula); }; //============================================================================= // ステートの自動付与&自動解除判定 //============================================================================= FTKR.ASC.Game_Battler_refresh = Game_Battler.prototype.refresh; Game_Battler.prototype.refresh = function () { FTKR.ASC.Game_Battler_refresh.call(this); if (this.isAlive()) { FTKR.setGameData(this); this.checkAutoAddState(); this.states().forEach(function (state) { if (DataManager.evalRemoveStateConditions(state)) { this.removeState(state.id); } }, this); } }; Game_Battler.prototype.checkAutoAddState = function () { $dataStates.forEach(function (state) { if (!state) return; if (DataManager.evalAddStateConditions(state)) { if (!this.isStateAffected(state.id)) { this.addState(state.id); } } }, this); };