95 lines
3.7 KiB
JavaScript
95 lines
3.7 KiB
JavaScript
//=============================================================================
|
||
// IM_MPP_StateLevelUtils.js
|
||
// ----------------------------------------------------------------------------
|
||
// author : Umu
|
||
//=============================================================================
|
||
/*:
|
||
* @target MZ
|
||
* @plugindesc MPP_StateLevel 用ユーティリティ関数集(ver.1.0.0)
|
||
* @author Umu
|
||
*
|
||
* @help
|
||
* ▼グローバル関数(イベントのスクリプトから使用)
|
||
* SL_getStateLevel(actorId, stateId) // スタック数取得(無いとき 0)
|
||
* SL_setStateLevel(actorId, stateId, n) // スタック数上書き (n<=0 で解除)
|
||
*
|
||
* 例)変数10番にアクター1の毒(ID:4)スタック数を取得
|
||
* $gameVariables.setValue(10, SL_getStateLevel(1, 4));
|
||
*
|
||
* 例)アクター3の毒を 5 スタックに強制
|
||
* SL_setStateLevel(3, 4, 5);
|
||
*
|
||
* ●プラグインコマンドはありません。
|
||
* ●前提プラグイン: MPP_StateLevel.js (v1.0.0 以上)
|
||
*/
|
||
|
||
(() => {
|
||
"use strict";
|
||
|
||
//-------------------------------------------------------------------------
|
||
// Math.clamp ― ポリフィル
|
||
//-------------------------------------------------------------------------
|
||
if (!Math.clamp) {
|
||
/**
|
||
* v を a〜b の範囲に収めて返す
|
||
* @param {number} v
|
||
* @param {number} a
|
||
* @param {number} b
|
||
* @returns {number}
|
||
*/
|
||
Math.clamp = (v, a, b) => Math.max(a, Math.min(b, v));
|
||
}
|
||
|
||
//-------------------------------------------------------------------------
|
||
// 内部ヘルパー
|
||
const actorById = id => $gameActors.actor(Number(id)) || null;
|
||
|
||
//-------------------------------------------------------------------------
|
||
// Game_BattlerBase 拡張(既にあれば上書きしない)
|
||
if (!Game_BattlerBase.prototype.getStateLevel) {
|
||
Game_BattlerBase.prototype.getStateLevel = function(stateId) {
|
||
stateId = Number(stateId);
|
||
return (this._stateLevels && this._stateLevels[stateId]) || 0;
|
||
};
|
||
}
|
||
|
||
if (!Game_BattlerBase.prototype.setStateLevel) {
|
||
Game_BattlerBase.prototype.setStateLevel = function(stateId, level) {
|
||
stateId = Number(stateId);
|
||
level = Number(level);
|
||
const max = this.maxStateLevel ? this.maxStateLevel(stateId) : 99;
|
||
level = Math.clamp(level, 0, max);
|
||
|
||
if (level <= 0) { // 解除
|
||
this.eraseState(stateId);
|
||
return;
|
||
}
|
||
if (!this._stateLevels) {
|
||
this._stateLevels = {};
|
||
}
|
||
// ここでステートレベルをlevelで打つとMPP_StateLevelの処理で
|
||
// 後のaddStateで指定レベル+1になってしまうので補正
|
||
// (リセットの中で暗黙にインクリメントされてる)
|
||
this._stateLevels[stateId] = level - 1;
|
||
if (!this.isStateAffected(stateId)) {
|
||
this.resetStateCounts(stateId);
|
||
} else if (this.resetMaxStateTurn) {
|
||
this.resetMaxStateTurn(stateId);
|
||
}
|
||
};
|
||
}
|
||
|
||
//-------------------------------------------------------------------------
|
||
// グローバル関数
|
||
|
||
window.SL_getStateLevel = function(actorId, stateId) {
|
||
const actor = actorById(actorId);
|
||
return actor ? actor.getStateLevel(stateId) : 0;
|
||
};
|
||
|
||
window.SL_setStateLevel = function(actorId, stateId, level) {
|
||
const actor = actorById(actorId);
|
||
if (actor) actor.setStateLevel(stateId, level);
|
||
};
|
||
|
||
})();
|