//============================================================================= // Mano_WeaponChange.js // ---------------------------------------------------------------------------- // Copyright (c) 2019-2019 Sigureya // This software is released under the MIT License. // http://opensource.org/licenses/mit-license.php // ---------------------------------------------------------------------------- // [Twitter]: https://twitter.com/Sigureya/ // [github]:https://github.com/Sigureya/RPGmakerMV //============================================================================= /*: * @plugindesc 戦闘中に武器を切り替えらえるシステムを実装します。 * * @author しぐれん * * @param subWeaponSlots * @text サブウェポンの個数 * @desc サブウェポンを装備できる数を指定します。 * @type number * @default 4 * @min 1 * * @param invalidWeaponDisplay * @text 不適正な装備の表示方法 * @desc 装備タイプが不適正なサブウェポンの表示形式を指定します。 * (戦闘中の設定) * @type select * @option 表示しない * @value 0 * @option 暗くして表示 * @value 1 * @default 0 * * @param normalAttackSkillList * @text 通常攻撃用スキル * @desc ここに登録しておくと、武器タイプを見ていい感じに割り当ててくれます。 * 一つの武器タイプに対して複数登録すると、最後の物のみが有効なります。 * @type skill[] * @default [] * * @help * ■メモ欄の記述 * (武器に設定) * 通常攻撃用スキルで登録したスキルの自動追加を無効化します。 * 特別な武器なので通常武器を違うのにしたい、という場合にどうぞ。 * * ■概要 * あらかじめ予備の武器を装備しておき、戦闘中に切り替えるシステムを実装します。 * 武器に対応するスキルは、スキルの必要武器タイプで判定します。 * この方法で発動したスキルは、武器振りモーションが適応されます。 * * 有効となるのは、実際に装備している武器のみです。 * * 装備が切り替わるのは、実際に攻撃を行う直前です。 * 行動時に混乱していると、武器の切り替えに失敗します。 * また、眠りなどの状態異常によって行動不能の場合も切り替えに失敗します。 * * スキルの表示順 * 通常攻撃→武器固有スキル→アクターが習得しているスキルの順です。 * * 二刀流との相性はとても悪いです。 * 動く気はしますが、保証はしません。 * * 更新履歴 * 2019/01/04 ver 1.0 公開 */ (function(){ 'use strict'; function getPluginParam(){ return PluginManager.parameters("Mano_WeaponChange");} const InValidWeaponDisplayMode ={ remove:0, disabled:1, }; const ENUM_ACTOR_COMMANDNAME =Object.freeze({ name:0, type:1 }); const setting =(function(){ const param =getPluginParam(); const result ={ actorCommandName:Number(param.actorCommandName) ||0, commandSymbol:"weaponMA", usingIcon:false, subWeaponSlots:Number(param.subWeaponSlots) ||1, openSymbol:"shift", // emptyWeaponOk: (param.emptyWeaponOk ==="true"), invalidWeaponDisplay:Number(param.invalidWeaponDisplay), /** * @type {Map} */ normalAttackSkillMap:new Map(), }; return result; })(); const Scene_Boot_Start = Scene_Boot.prototype.start; Scene_Boot.prototype.start = function(){ Scene_Boot_Start.call(this); const param =getPluginParam(); const skillIdList = JSON.parse(param.normalAttackSkillList ||"[]"); for (const iterator of skillIdList) { const skillId = Number(iterator); const skill = $dataSkills[skillId]; if(skill){ if(skill.requiredWtypeId1 !==0){ setting.normalAttackSkillMap.set(skill.requiredWtypeId1,skill); } if(skill.requiredWtypeId2 !==0){ setting.normalAttackSkillMap.set(skill.requiredWtypeId2,skill); } } } }; const DataManager_extractSaveContents =DataManager.extractSaveContents; DataManager.extractSaveContents =function(contents){ DataManager_extractSaveContents.call(this,contents); for (const actor of $gameActors._data) { if(actor){ actor.refreshSubWeaponSlot(); } } }; /** * @param {Game_Actor} actor */ function createSubWeaponSlot(actor){ const subWaponSlot = actor.numWeaponSlot(); const slots = actor.equipSlots(); const result = []; result.length = subWaponSlot; for(var i =0; i < subWaponSlot; ++i){ const equipType = slots[i]; if(equipType ===1){ result[i]=actor._equips[i]; }else{ result[i] =new Game_Item(); } } return result; } const Game_Actor_setup =Game_Actor.prototype.setup; Game_Actor.prototype.setup =function(actorId){ Game_Actor_setup.call(this,actorId); this.refreshSubWeaponSlot(); }; Game_Actor.prototype.refreshSubWeaponSlot =function(){ if(!this._subWeaponSlot){ this._subWeaponSlot = createSubWeaponSlot(this); } }; Game_Actor.prototype.isSubWeaponChangeOk =function(slotId){ return !this.isEquipTypeLocked(1); }; Game_Actor.prototype.clearSubWeapons =function(){ const length = this._subWeaponSlot.length; for(var i =0; i < length; ++i){ if(this.isSubWeaponChangeOk(i)){ this.changeSubWeapon(i,null); } } }; const Game_Actor_clearEquipments=Game_Actor.prototype.clearEquipments; Game_Actor.prototype.clearEquipments =function(){ Game_Actor_clearEquipments.call(this); this.clearSubWeapons(); }; /** * @param {Number} sorceIndex * @param {Number} targetIndex */ Game_Actor.prototype.bindSubWeapon =function(sorceIndex,targetIndex){ if(!this.canBindSubWeapon(sorceIndex,targetIndex)){ return false; } const finalTargetIndex = targetIndex ||0; const newWeapon = this._subWeaponSlot[sorceIndex]; if(newWeapon){ this._equips[finalTargetIndex] = newWeapon; this.refresh(); } return true; }; /** * @param {Number} SubWeaponIndex * @param {Number} targetIndex */ Game_Actor.prototype.canBindSubWeapon =function(SubWeaponIndex, targetIndex){ /** * @type {Game_Item} */ const subWeapon = this._subWeaponSlot[SubWeaponIndex]; if(!subWeapon){ return false; } if(!subWeapon.isWeapon()){ return false; } if(!this.canEquip(subWeapon.object())){ return false; } const finalTargetIndex = targetIndex ||0; const item = this._equips[finalTargetIndex]; if(item){ const slots = this.equipSlots(); if(slots[finalTargetIndex]===1){ return true; } } return false; }; /** * @returns {Game_Item} */ Game_Actor.prototype.getSubWeapon =function(index){ return this._subWeaponSlot[index]; }; Game_Actor.prototype.numWeaponSlot =function(){ return setting.subWeaponSlots; }; Game_Actor.prototype.subWeaponSlot =function(){ return this._subWeaponSlot; }; Game_Actor.prototype.isSubWeaponBinded =function(index){ /** * @type {Game_Item} */ const subWeapon = this._subWeaponSlot[index]; if(subWeapon){ for (const equip of this._equips) { if(equip ===subWeapon){ return true; } } } return false; }; /** * @param {Number} mainSlotId メインスロットの番号 * @returns {Number} 対応したスロットにバインドされているサブウェポン。見つからなかった場合、NaNを返す。ただ、NaNを返す時はエラー起こしていると思うよ。 */ Game_Actor.prototype.getBindedSubWeaponSlot =function(mainSlotId){ const item = this._equips[mainSlotId]; if(item){ const length =this._subWeaponSlot.length for(var i=0; i=0){ this.select(index); return; } } this.select(0); } /** * @param {Game_Actor} actor */ setActor(actor){ this._actor =actor; } show(){ this.refresh(); super.show(); } /** * @param {RPG.Skill} skill */ includes(skill){ if(this._weapon && skill){ const wType =this._weapon.wtypeId; return wType=== skill.requiredWtypeId1 || wType ===skill.requiredWtypeId2 ; } return false; } /** * @param {RPG.Weapon} weapon * @param {RPG.Skill} skill */ match(weapon,skill){ const wType = weapon.wtypeId; return wType=== skill.requiredWtypeId1 || wType ===skill.requiredWtypeId2 ; } /** * @param {RPG.Skill} skill */ isEnabled(skill){ const actor = this._actor; return skill &&(actor.meetsUsableItemConditions(skill) && actor.canPaySkillCost(skill) && !actor.isSkillSealed(skill.id) && !actor.isSkillTypeSealed(skill.stypeId) ); } /** * * @param {RPG.Weapon} weapon */ weaponSkills(weapon){ const result = []; const atk = this.normalAttackSkill(weapon); if(atk){ result.push(atk); } for(const t of weapon.traits){ if(t.code ===Game_BattlerBase.TRAIT_SKILL_ADD){ const skill = $dataSkills[t.dataId]; if(skill&& this.match(weapon,skill)){ result.push(skill); } } } return result; } /** * @param {RPG.Weapon} weapon * @returns {RPG.Skill[]} */ createSkillList(weapon){ if(this._actor && weapon){ const result = this.weaponSkills(weapon); const skills = this._actor.skills(); for (const iterator of skills) { if(this.match(weapon,iterator)){ if(!result.contains(iterator)){ result.push(iterator); } } } return result; } return []; } makeItemList(){ this._data = this.createSkillList(this.weapon()); } } Window_ActorCommand.prototype.isWeaponEnabled =function(weapon){ return true; }; Window_ActorCommand.prototype.getSubWeaponIndex =function(){ const data= this.currentData(); if(data && data.symbol ===setting.commandSymbol ){ return data.ext; } return -1; }; Window_ActorCommand.prototype.getSubWeapon =function(){ const data= this.currentData(); if(data && data.symbol ===setting.commandSymbol ){ const index = data.ext; return this._actor.getSubWeapon(index); } return null; }; /** * @param {Window_ActorCommand} commandWindow * @param {Game_Actor} actor */ function addSubWeaponCommandByRemove(commandWindow,actor){ const list = subWeaponList(actor); const len = list.length; for(var i=0; i