79 lines
3.1 KiB
JavaScript
79 lines
3.1 KiB
JavaScript
//=============================================================================
|
||
// KN_AutoUseOnGain.js
|
||
// Auto-use specific items when gained if a switch is ON
|
||
//=============================================================================
|
||
|
||
/*:ja
|
||
* @target MZ
|
||
* @plugindesc 取得時に指定アイテムを自動で使用します(スイッチでON/OFF)
|
||
* @author generated
|
||
*/
|
||
|
||
(function() {
|
||
'use strict';
|
||
|
||
// 設定: 自動使用対象のアイテムID配列
|
||
const AUTO_ITEM_IDS = [27, 28, 29, 30]; // 強化スクロール類
|
||
|
||
const _Game_Party_gainItem = Game_Party.prototype.gainItem;
|
||
Game_Party.prototype.gainItem = function(item, amount, includeEquip) {
|
||
// まず通常処理を呼ぶ
|
||
_Game_Party_gainItem.call(this, item, amount, includeEquip);
|
||
if (!item) return;
|
||
if (amount <= 0) return; // 取得のみ対象
|
||
if (!DataManager.isItem(item)) return; // 消耗アイテムのみ
|
||
if (!AUTO_ITEM_IDS.includes(item.id)) return; // 対象IDのみ
|
||
if (!$gameSwitches.value(Kurogoma.SwitchConst.AutoUseOnGain)) return; // スイッチがONでなければ何もしない
|
||
|
||
// 取得量分だけ自動使用(多量取得時は繰り返し)
|
||
const times = Math.max(1, amount);
|
||
let usedCount = 0;
|
||
|
||
// 一人旅のため使用者はリーダー固定
|
||
const user = $gameParty.leader();
|
||
if (!user) return;
|
||
|
||
for (let t = 0; t < times; t++) {
|
||
// 効果音
|
||
SoundManager.playUseItem();
|
||
|
||
// 消費
|
||
user.useItem(item);
|
||
|
||
// 効果の適用(Scene_ItemBase.applyItem を簡易的に模倣)
|
||
const action = new Game_Action(user);
|
||
action.setItemObject(item);
|
||
|
||
// ターゲット選定(フレンド対象かつ全体なら全員、単体なら使用者を対象にする)
|
||
let targets = [];
|
||
if (action.isForFriend()) {
|
||
if (action.isForAll()) {
|
||
targets = $gameParty.members();
|
||
} else {
|
||
targets = [user];
|
||
}
|
||
} else {
|
||
// 敵対象のアイテムは自動使用しない
|
||
targets = [];
|
||
}
|
||
|
||
for (const target of targets) {
|
||
for (let i = 0; i < action.numRepeats(); i++) {
|
||
action.apply(target);
|
||
}
|
||
}
|
||
action.applyGlobal();
|
||
usedCount++;
|
||
}
|
||
|
||
// 通知を表示(Torigoya は常時存在する想定)
|
||
if (usedCount > 0) {
|
||
const msg = usedCount === 1 ? `\\c[2]${item.name}\\c[0] を自動使用しました!` : `\\c[2]${item.name}\\c[0] x${usedCount} を自動使用しました!`;
|
||
const iconIndex = typeof item.iconIndex === 'number' ? item.iconIndex : 0;
|
||
Torigoya.NotifyMessage.Manager.notify(
|
||
new Torigoya.NotifyMessage.NotifyItem({ message: msg, icon: iconIndex })
|
||
);
|
||
}
|
||
};
|
||
|
||
})();
|