//============================================================================= // Extension for Yanfly Engine Plugins - Party Replace On Death // YEP_X_PartyReplaceOnDeath.js //============================================================================= var Imported = Imported || {}; Imported.YEP_PartySystem = true; var Yanfly = Yanfly || {}; Yanfly.Party = Yanfly.Party || {}; //============================================================================= /*: * @plugindesc v0.90 Initial Release. * Allows backup party members to replace a dead party, like in DQ4. * @author Wilminator * * @param ---General--- * @default * * @param Replace On All Dead * @desc Replace active party with backup actors if party is all dead? * NO - false YES - true * @default false * * @param Replace With Formation Screen * @desc Use the Formation screen to replace an all dead party? * NO - false YES - true * @default true * * @param Replace On All Dead Notification * @desc Text displayed when swapping out for live actors. * @default Comrades jump out to avenge the fallen! * * * @help * ============================================================================ * Introduction * ============================================================================ * * This plugin enhances Yanfly's Party System plugin. It adds the option to * use any live members of your party not involved in combat to replace a * completely wiped out team. The author has the choice of using the party * menu or randomly filling combatatnt slots with anyone with a pulse ;) * * This plugin requires YEP_PartySystem.js and must be below it. * * This plugin is plug and play. All you have to do is just turn it on and * change the parameters to your liking. * * * ============================================================================ * Changelog * ============================================================================ * * Version 0.91: * - Fixed Formation window - it now requires a survivor to go to battle * * Version 0.90: * - Initial release! May want to pretty up the replacement of dead teammates * though. */ //============================================================================= //============================================================================= // Parameter Variables //============================================================================= Yanfly.Parameters = PluginManager.parameters('YEP_X_PartyReplaceOnDeath'); Yanfly.Param = Yanfly.Param || {}; Yanfly.Icon = Yanfly.Icon || {}; Yanfly.Param.ReplaceOnAllDead = String(Yanfly.Parameters['Replace On All Dead']); Yanfly.Param.ReplaceOnAllDead = eval(Yanfly.Param.ReplaceOnAllDead); Yanfly.Param.ReplaceWithFormationScreen = String(Yanfly.Parameters['Replace With Formation Screen']); Yanfly.Param.ReplaceWithFormationScreen = eval(Yanfly.Param.ReplaceWithFormationScreen); Yanfly.Param.ReplaceOnAllDeadNotification = String(Yanfly.Parameters['Replace On All Dead Notification']); //============================================================================= // BattleManager //============================================================================= if (Yanfly.Param.ReplaceOnAllDead) { Yanfly.Party.BattleManager_checkBattleEnd = BattleManager.checkBattleEnd; BattleManager.checkBattleEnd = function() { if ($gameParty.isAllDead()) { var lockedActors = $gameParty.battleMembers().filter(function(member) { return member._locked || member._required; }); //console.log(lockedActors.length.toString() + ' ' + $gameParty.maxBattleMembers().toString() + ' ' + (!$gameParty.isTotallyDead() ? 'alive' : 'dead')); // See if we can swap out any battlers and if there is anyone alive to swap them out with. if (lockedActors.length < $gameParty.maxBattleMembers() && !$gameParty.isTotallyDead()) { // Reset the cooldown, otherwise no one may be available for exchange. $gameSystem.resetBattleFormationCooldown(); // Battlers can be swapped out. If allowed to use the Formation window, use it. if (Yanfly.Param.ReplaceWithFormationScreen) { BattleManager._bypassMoveToStartLocation = true; $gameParty.loadActorImages(); BattleManager._savedActor = BattleManager.actor(); $gameSystem.setBattleFormationCooldown(); Yanfly.Party.SavedBattleBgm = AudioManager.saveBgm(); Yanfly.Party.SavedBattleBgs = AudioManager.saveBgs(); SceneManager.push(Scene_Party); $gameTemp._partyBattle = true; // How do we display a message box saying that we are swapping out actors? $gameMessage.add(Yanfly.Param.ReplaceOnAllDeadNotification); return false; } // Otherwise swap out battlers randomly. else { // How do we display a message box saying that we are swapping out actors? $gameMessage.add(Yanfly.Param.ReplaceOnAllDeadNotification); var aliveMembers = $gameParty.allAliveMembers(); for (var index =0; index < $gameParty.maxBattleMembers(); ++index) { if (aliveMembers.length > 0) { var battler = $gameParty.battleMembers()[index]; //console.log(index.toString() + ' ' + aliveMembers.join(',') + ' ' + $gameParty._actors.join(',')); if (!battler || (!battler._locked && !battler._required)) { var volunteerOffset =Math.floor(Math.random()*aliveMembers.length); var volunteer = aliveMembers.splice(volunteerOffset,1)[0]; //console.log('Swapping '+index+' and '+volunteer._actorId); $gameParty._battleMembers[index] = volunteer._actorId; //console.log($gameParty._actors.join(',')); } } else{ $gameParty._battleMembers[index] = 0; } } $gameParty.rearrangeActors(); $gamePlayer.refresh(); $gameParty.battleMembers().map(function (o){if(o && o.refresh) {o.refresh();}}); } } } return Yanfly.Party.BattleManager_checkBattleEnd.call(this); }; }; // Yanfly.Param.ReplaceOnAllDead //============================================================================= // Game_Party //============================================================================= Game_Unit.prototype.allAliveMembers = function() { return this.allMembers().filter(function(member) { return member.isAlive(); }); }; Game_Unit.prototype.isTotallyDead = function() { return this.allAliveMembers().length === 0; }; //============================================================================= // End of File //=============================================================================