//============================================================================== // dsCommandAssign.js // Copyright (c) 2015 - 2018 DOURAKU // Released under the MIT License. // http://opensource.org/licenses/mit-license.php //============================================================================== /*: * @plugindesc コマンド割り当てシステム ver1.1.0 * @author 道楽 * * @param Command Enable * @desc メニューコマンドを使用するか * @default true * * @param Command Name * @desc コマンド割り当てコマンドの名称 * @default コマンド割り当て * * @param Empty Slot * @desc コマンド未割り当て時の表示名 * @default −−−−−−−−− * * @param Remove Command * @desc コマンド割り当て解除の名称 * @default はずす * * @param Visible Switch Id * @desc コマンド表示スイッチ番号 * 0の場合は無効となる * @default 0 * * @help * このプラグインは以下のメモタグの設定ができます。 * * ----------------------------------------------------------------------------- * 職業に設定するメモタグ * * * 割り当てられるスロット数を設定します。 * [スロット数] - 割り当てられるスロットの数。(数字) */ var Imported = Imported || {}; Imported.dsCommandAssign = true; (function (exports) { 'use strict'; exports.Param = (function() { var ret = {}; var parameters = PluginManager.parameters('dsCommandAssign'); ret.CommandEnable = Boolean(parameters['Command Enable'] === 'true' || false); ret.CommandName = String(parameters['Command Name']); ret.EmptySlot = String(parameters['Empty Slot']); ret.RemoveCommand = String(parameters['Remove Command']); ret.VisibleSwitchId = Number(parameters['Visible Switch Id']); return ret; })(); //-------------------------------------------------------------------------- /** Game_Actor */ var _Game_Actor_initMembers = Game_Actor.prototype.initMembers; Game_Actor.prototype.initMembers = function() { _Game_Actor_initMembers.call(this); this._stypeSlot = []; this._assignEnable = []; }; Game_Actor.prototype.addedSkillTypes = function() { return this._stypeSlot.filter(function(stypeId) { return ( stypeId != 0 ); }, this); }; Game_Actor.prototype.addedSkillTypesDirect = function() { return this._stypeSlot; }; Game_Actor.prototype.isSkillTypeAssignEnable = function(slot) { return this._assignEnable[slot]; }; var _Game_Actor_refresh = Game_Actor.prototype.refresh; Game_Actor.prototype.refresh = function() { this.refreshAssignSlot(); _Game_Actor_refresh.call(this); }; Game_Actor.prototype.refreshAssignSlot = function() { var oldStypeSlot = this._stypeSlot.filter(function(stypeId, slot) { return this._assignEnable[slot]; }, this); this._stypeSlot = []; this._assignEnable = []; var skillTypes = this.traitsSet(Game_BattlerBase.TRAIT_STYPE_ADD); skillTypes.sort(function(a, b) { return a - b; }); skillTypes.forEach(function(stypeId) { this._stypeSlot.push(stypeId); this._assignEnable.push(false); }, this); var classData = this.currentClass(); if ( classData.meta.assignSlot ) { oldStypeSlot = oldStypeSlot.filter(function(stypeId) { return !skillTypes.some(function(someId) { return (someId == stypeId); }); }); var slotNum = Number(classData.meta.assignSlot); for ( var ii = 0; ii < slotNum; ii++ ) { if ( ii < oldStypeSlot.length ) { this._stypeSlot.push(oldStypeSlot[ii]); } else { this._stypeSlot.push(0); } this._assignEnable.push(true); } } }; Game_Actor.prototype.assignSkillType = function(slot, stypeId) { if ( this.isSkillTypeAssignEnable(slot) ) { this._stypeSlot[slot] = stypeId; } }; //-------------------------------------------------------------------------- /** Window_AssignSlot */ exports.Window_AssignSlot = (function() { function Window_AssignSlot() { this.initialize.apply(this, arguments); } Window_AssignSlot.prototype = Object.create(Window_Command.prototype); Window_AssignSlot.prototype.constructor = Window_AssignSlot; Window_AssignSlot.prototype.initialize = function(x, y) { Window_Command.prototype.initialize.call(this, x, y); this._actor = null; }; Window_AssignSlot.prototype.setActor = function(actor) { if ( this._actor !== actor ) { this._actor = actor; this.refresh(); this.selectLast(); } }; Window_AssignSlot.prototype.numVisibleRows = function() { return 4; }; Window_AssignSlot.prototype.update = function() { Window_Command.prototype.update.call(this); if ( this._skillWindow ) { if ( this.active ) { var stypeId = this._list[this.index()].ext; this._skillWindow.setStypeId(stypeId); } } }; Window_AssignSlot.prototype.makeCommandList = function() { if ( this._actor ) { var skillTypes = this._actor.addedSkillTypesDirect(); skillTypes.forEach(function(stypeId, slot) { var cmdName = (stypeId == 0) ? dsCommandAssign.Param.EmptySlot : $dataSystem.skillTypes[stypeId]; var enabled = this._actor.isSkillTypeAssignEnable(slot); this.addCommand(cmdName, 'skill', enabled, stypeId); }, this); } }; Window_AssignSlot.prototype.setSkillWindow = function(skillWindow) { this._skillWindow = skillWindow; }; Window_AssignSlot.prototype.selectLast = function() { var skill = this._actor.lastMenuSkill(); if ( skill ) { this.selectExt(skill.stypeId); } else { this.select(0); } }; return Window_AssignSlot; })(); //-------------------------------------------------------------------------- /** Window_AssignStatus */ exports.Window_AssignStatus = (function() { function Window_AssignStatus() { this.initialize.apply(this, arguments); } Window_AssignStatus.prototype = Object.create(Window_Base.prototype); Window_AssignStatus.prototype.constructor = Window_AssignStatus; Window_AssignStatus.prototype.initialize = function(x, y, width, height) { Window_Base.prototype.initialize.call(this, x, y, width, height); this._actor = null; }; Window_AssignStatus.prototype.setActor = function(actor) { if ( this._actor !== actor ) { this._actor = actor; this.refresh(); } }; Window_AssignStatus.prototype.refresh = function() { this.contents.clear(); if ( this._actor ) { var w = this.width - this.padding * 2; var h = this.height - this.padding * 2; var y = h / 2 - this.lineHeight() * 1.5; var width = w - 162 - this.textPadding(); this.drawActorFace(this._actor, 0, 0, 144, h); this.drawActorSimpleStatus(this._actor, 162, y, width); } }; return Window_AssignStatus; })(); //-------------------------------------------------------------------------- /** Window_AssignType */ exports.Window_AssignType = (function() { function Window_AssignType() { this.initialize.apply(this, arguments); } Window_AssignType.prototype = Object.create(Window_Selectable.prototype); Window_AssignType.prototype.constructor = Window_AssignType; Window_AssignType.prototype.initialize = function(x, y, width, height) { Window_Selectable.prototype.initialize.call(this, x, y, width, height); this._actor = null; }; Window_AssignType.prototype.setActor = function(actor) { if ( this._actor !== actor ) { this._actor = actor; this.refresh(); } }; Window_AssignType.prototype.maxCols = function() { return 1; }; Window_AssignType.prototype.selectedStypeId = function() { return this._data[this.index()]; }; Window_AssignType.prototype.maxItems = function() { return this._data ? this._data.length : 1; }; Window_AssignType.prototype.update = function() { Window_Selectable.prototype.update.call(this); if ( this._skillWindow ) { if ( this.active ) { var stypeId = this._data[this.index()]; this._skillWindow.setStypeId(stypeId); } } }; Window_AssignType.prototype.makeItemList = function() { this._data = []; this._data.push(0); if ( this._actor ) { var skillTypeEnable = []; $dataSystem.skillTypes.forEach(function(stype, idx) { skillTypeEnable[idx] = false; }); this._actor.skills().forEach(function(skill) { skillTypeEnable[skill.stypeId] = true; }); var skillTypes = this._actor.addedSkillTypes(); skillTypes.forEach(function(stypeId) { skillTypeEnable[stypeId] = false; }); skillTypeEnable.forEach(function(enable, idx) { if ( enable ) { this._data.push(idx); } }, this); } }; Window_AssignType.prototype.drawItem = function(index) { var stypeId = this._data[index]; var stypeName = (stypeId == 0) ? dsCommandAssign.Param.RemoveCommand : $dataSystem.skillTypes[stypeId]; var rect = this.itemRect(index); rect.width -= this.textPadding(); this.drawText(stypeName, rect.x, rect.y, rect.width); }; Window_AssignType.prototype.refresh = function() { this.makeItemList(); this.createContents(); this.drawAllItems(); }; Window_AssignType.prototype.setSkillWindow = function(skillWindow) { this._skillWindow = skillWindow; }; Window_AssignType.prototype.selectLast = function() { this.select(0); }; return Window_AssignType; })(); //-------------------------------------------------------------------------- /** Window_LearnedList */ exports.Window_LearnedList = (function() { function Window_LearnedList() { this.initialize.apply(this, arguments); } Window_LearnedList.prototype = Object.create(Window_SkillList.prototype); Window_LearnedList.prototype.constructor = Window_LearnedList; Window_LearnedList.prototype.initialize = function(x, y, width, height) { Window_SkillList.prototype.initialize.call(this, x, y, width, height); }; Window_LearnedList.prototype.maxCols = function() { return 1; }; return Window_LearnedList; })(); //-------------------------------------------------------------------------- /** Window_SkillType */ Window_SkillType.prototype.makeCommandList = function() { if ( this._actor ) { var skillTypes = this._actor.addedSkillTypes(); skillTypes.forEach(function(stypeId) { var name = $dataSystem.skillTypes[stypeId]; this.addCommand(name, 'skill', true, stypeId); }, this); } }; //-------------------------------------------------------------------------- /** Window_ActorCommand */ Window_ActorCommand.prototype.addSkillCommands = function() { var skillTypes = this._actor.addedSkillTypes(); skillTypes.forEach(function(stypeId) { var name = $dataSystem.skillTypes[stypeId]; this.addCommand(name, 'skill', true, stypeId); }, this); }; //-------------------------------------------------------------------------- /** Window_MenuCommand */ var _Window_MenuCommand_addOriginalCommands = Window_MenuCommand.prototype.addOriginalCommands; Window_MenuCommand.prototype.addOriginalCommands = function() { _Window_MenuCommand_addOriginalCommands.call(this); if ( dsCommandAssign.Param.CommandEnable ) { if ( dsCommandAssign.Param.VisibleSwitchId !== 0 ) { if ( $gameSwitches.value(dsCommandAssign.Param.VisibleSwitchId) ) { this.addCommand(dsCommandAssign.Param.CommandName, 'commandAssign', true); } } else { this.addCommand(dsCommandAssign.Param.CommandName, 'commandAssign', true); } } }; //-------------------------------------------------------------------------- /** Scene_CommandAssign */ exports.Scene_CommandAssign = (function() { function Scene_CommandAssign() { this.initialize.apply(this, arguments); } Scene_CommandAssign.prototype = Object.create(Scene_MenuBase.prototype); Scene_CommandAssign.prototype.constructor = Scene_CommandAssign; Scene_CommandAssign.prototype.initialize = function() { Scene_MenuBase.prototype.initialize.call(this); }; Scene_CommandAssign.prototype.create = function() { Scene_MenuBase.prototype.create.call(this); this.createHelpWindow(); this.createCommandWindow(); this.createStatusWindow(); this.createTypeWindow(); this.createSkillListWindow(); this.refreshActor(); }; Scene_CommandAssign.prototype.createCommandWindow = function() { var wx = 0; var wy = this._helpWindow.height; this._slotWindow = new exports.Window_AssignSlot(wx, wy); this._slotWindow.setHandler('ok', this.onSlotOk.bind(this)); this._slotWindow.setHandler('cancel', this.popScene.bind(this)); this._slotWindow.setHandler('pagedown', this.nextActor.bind(this)); this._slotWindow.setHandler('pageup', this.previousActor.bind(this)); this.addWindow(this._slotWindow); }; Scene_CommandAssign.prototype.createStatusWindow = function() { var wx = this._slotWindow.width; var wy = this._helpWindow.height; var ww = Graphics.boxWidth - wx; var wh = this._slotWindow.height; this._statusWindow = new exports.Window_AssignStatus(wx, wy, ww, wh); this.addWindow(this._statusWindow); }; Scene_CommandAssign.prototype.createTypeWindow = function() { var wx = 0; var wy = this._slotWindow.y + this._slotWindow.height; var ww = 424; var wh = Graphics.boxHeight - wy; this._typeListWindow = new exports.Window_AssignType(wx, wy, ww, wh); this._typeListWindow.setHandler('ok', this.onTypeOk.bind(this)); this._typeListWindow.setHandler('cancel', this.onTypeCancel.bind(this)); this._typeListWindow.setHandler('pagedown', this.onTypeExtend.bind(this)); this._typeListWindow.setHandler('pageup', this.onTypeExtend.bind(this)); this.addWindow(this._typeListWindow); }; Scene_CommandAssign.prototype.createSkillListWindow = function() { var wx = this._typeListWindow.width; var wy = this._slotWindow.y + this._slotWindow.height; var ww = Graphics.boxWidth - wx; var wh = Graphics.boxHeight - wy; this._skillListWindow = new exports.Window_LearnedList(wx, wy, ww, wh); this._skillListWindow.setHandler('cancel', this.onSkillCancel.bind(this)); this._skillListWindow.setHandler('pagedown', this.onSkillCancel.bind(this)); this._skillListWindow.setHandler('pageup', this.onSkillCancel.bind(this)); this._skillListWindow.setHelpWindow(this._helpWindow); this._slotWindow.setSkillWindow(this._skillListWindow); this._typeListWindow.setSkillWindow(this._skillListWindow); this.addWindow(this._skillListWindow); }; Scene_CommandAssign.prototype.onSlotOk = function() { this._typeListWindow.activate(); this._typeListWindow.selectLast(); }; Scene_CommandAssign.prototype.onTypeOk = function() { var actor = this.actor(); var slot = this._slotWindow.index(); var stypeId = this._typeListWindow.selectedStypeId(); actor.assignSkillType(slot, stypeId); this._slotWindow.activate(); this._typeListWindow.deselect(); this._typeListWindow.refresh(); this._slotWindow.refresh(); }; Scene_CommandAssign.prototype.onTypeCancel = function() { this._slotWindow.activate(); this._typeListWindow.deselect(); }; Scene_CommandAssign.prototype.onTypeExtend = function() { this._skillListWindow.activate(); this._skillListWindow.select(0); }; Scene_CommandAssign.prototype.onSkillCancel = function() { this._skillListWindow.deselect(); this._helpWindow.clear(); this._typeListWindow.activate(); }; Scene_CommandAssign.prototype.onActorChange = function() { this.refreshActor(); this._slotWindow.activate(); }; Scene_CommandAssign.prototype.refreshActor = function() { var actor = this.actor(); this._slotWindow.setActor(actor); this._statusWindow.setActor(actor); this._typeListWindow.setActor(actor); this._skillListWindow.setActor(actor); }; return Scene_CommandAssign; })(); //-------------------------------------------------------------------------- /** Scene_Menu */ var _Scene_Menu_createCommandWindow = Scene_Menu.prototype.createCommandWindow; Scene_Menu.prototype.createCommandWindow = function() { _Scene_Menu_createCommandWindow.call(this); this._commandWindow.setHandler('commandAssign', this.commandPersonal.bind(this)); }; var _Scene_Menu_onPersonalOk = Scene_Menu.prototype.onPersonalOk; Scene_Menu.prototype.onPersonalOk = function() { switch ( this._commandWindow.currentSymbol() ) { case 'commandAssign': SceneManager.push(exports.Scene_CommandAssign); break; default: _Scene_Menu_onPersonalOk.call(this); break; } }; }((this.dsCommandAssign = this.dsCommandAssign || {})));