nyacronomicon/js/plugins/KN_EventItem.js
2026-03-12 22:39:10 -05:00

82 lines
2.7 KiB
JavaScript

//=============================================================================
// KN_EventItem.js
//=============================================================================
/*:ja
* @target MZ
* @author kurogoma knights
* @base PluginCommonBase
* @plugindesc イベントアイテム選択
* @help メタにEventItemタグがあり
* CategoryTypeが一致するものを表示する
* NUUN_ItemCategoryに依存
*
* @command SET_CATEGORY
* @desc イベントアイテム選択で表示するアイテムのCategoryTypeを設定する
* @arg categoryType
* @type select
* @option item
* @option skill
* @default type
*
*/
(() => {
'use strict';
const script = document.currentScript;
const param = PluginManagerEx.createParameter(script);
PluginManagerEx.registerCommand(script, "SET_CATEGORY", args => {
$gameSystem.setEventItemCategoryType(args.categoryType);
});
//
// Game_System
//
// イベントアイテムの表示で使うカテゴリ
Game_System.prototype.setEventItemCategoryType = function(value) {
return this._knCategoryType = value;
};
//
Game_System.prototype.getEventItemCategoryType = function() {
return this._knCategoryType;
};
//
// Window_EventItem
//
const _Window_EventItem_includes = Window_EventItem.prototype.includes;
Window_EventItem.prototype.includes = function(item) {
return _Window_EventItem_includes.apply(this, arguments) && this.isOkEventItem(item);
};
Window_EventItem.prototype.isOkEventItem = function(item) {
return item.meta.EventItem
&& item.meta.CategoryType == $gameSystem.getEventItemCategoryType();
};
// アイテム選択ウィンドウ
var _Window_EventItem_isEnabled = Window_EventItem.prototype.isEnabled;
Window_EventItem.prototype.isEnabled = function(item) {
// actor.canUseは使用可能かどうかの確認 なので、アイテム選択ウィンドウでは使えない
const actor = $gameParty.leader();
const gameItem = new Game_Item(item);
if (!item) return false;
if ($gameSystem.isBossBattle() && item.meta["ボス使用不可"]) return false; // ボス戦では使用不可
if (gameItem.hasMpCost()) {
if (actor.isSilenced()) return false; // 沈黙状態なら使用不可
if (!actor.hasEnoughMp(item)) return false; // MPが足りてなければ使用不可
}
if (gameItem.hasTpCost()) {
if (!actor.hasEnoughTp(item)) return false; // TPが足りてなければ使用不可
}
return _Window_EventItem_isEnabled.call(this, item);
};
})();