-
-
Notifications
You must be signed in to change notification settings - Fork 52
/
Copy pathRS_PutInSubPartyMembers.js
154 lines (139 loc) · 5.14 KB
/
RS_PutInSubPartyMembers.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
//================================================================
// RS_PutInSubPartyMembers.js
// ---------------------------------------------------------------
// The MIT License
// Copyright (c) 2019 biud436
// ---------------------------------------------------------------
// Free for commercial and non commercial use.
//================================================================
/*:
* @plugindesc This plugin allows you to add extra party members when all active party members are defeated in battle <RS_PutInSubPartyMembers>
* @author biud436
*
* @param Extra Members Ids
* @type actor[]
* @desc Specify the actor IDs of extra party members who will automatically join when the main party is defeated.
* @default ["5","6","7","8"]
*
* @help
* =======================================================================
* Introduction
* =======================================================================
* This plugin provides a "second chance" feature by automatically adding
* reserve party members to your active party when all current members
* are defeated in battle. Instead of facing an immediate Game Over,
* the battle continues with your backup members.
*
* =======================================================================
* How to Use
* =======================================================================
* 1. Set up your extra party members in the plugin parameters
* 2. Make sure these actors are properly set up in the database
* 3. When all active party members are defeated in battle, the extra
* members will automatically be added to the party
* 4. The battle only ends in defeat when both the main party AND
* all extra members are defeated
*
* =======================================================================
* Notes
* =======================================================================
* - The extra members are not initially in the active party
* - They will only join during battle when needed
* - The plugin maintains separate tracking for main and extra members
* - Compatible with RPG Maker MV v1.5.1 or higher
*
* =======================================================================
* Version Log
* =======================================================================
* 2019.01.26 (v1.0.0) - First Release.
*/
var Imported = Imported || {};
Imported.RS_PutInSubPartyMembers = true;
var RS = RS || {};
RS.PutInSubPartyMembers = RS.PutInSubPartyMembers || {};
(function ($) {
var parameters = $plugins.filter(function (i) {
return i.description.contains('<RS_PutInSubPartyMembers>');
});
parameters = parameters.length > 0 && parameters[0].parameters;
$.jsonParse = function (str) {
var retData = JSON.parse(str, function (k, v) {
try {
return $.jsonParse(v);
} catch (e) {
return v;
}
});
return retData;
};
var extraMembers = $.jsonParse(parameters['Extra Members Ids']);
//================================================================
// Game_Party
//================================================================
Game_Party.prototype.getMemberIds = function () {
var ids = $gameParty.members().map(function (i) {
return i.actorId();
});
return ids;
};
Game_Party.prototype.extraMembers = function () {
var members = this.getMemberIds()
.concat(extraMembers)
.map(function (id) {
return $gameActors.actor(id);
});
return members.filter(function (member) {
return member.isAlive();
});
};
Game_Party.prototype.isExtraMembersAllDead = function () {
return this.extraMembers().length === 0;
};
//================================================================
// BattleManager
//================================================================
var alias_BattleManager_initMembers = BattleManager.initMembers;
BattleManager.initMembers = function () {
alias_BattleManager_initMembers.call(this);
this.initExtraMembers();
};
BattleManager.initExtraMembers = function () {
// 추가 멤버 셋업
extraMembers.forEach(function (i) {
var actorId = i;
$gameActors.actor(actorId).setup(actorId);
});
this._isExtraMembers = false;
};
/**
* ! 턴 진행 중에 여분의 파티원을 투입합니다.
*/
var alias_BattleManager_updateTurn = BattleManager.updateTurn;
BattleManager.updateTurn = function () {
alias_BattleManager_updateTurn.call(this);
if ($gameParty.isAllDead() && !this._isExtraMembers) {
$gameParty.getMemberIds().forEach(function (e, i, a) {
$gameParty.removeActor(e);
$gameParty.addActor(extraMembers[i]);
});
this._isExtraMembers = true;
}
};
/**
* ! 여분의 파티원까지 모두 Dead 상태일 때 전투가 종료 됩니다.
*/
BattleManager.checkBattleEnd = function () {
if (this._phase) {
if (this.checkAbort()) {
return true;
} else if ($gameParty.isAllDead() && $gameParty.isExtraMembersAllDead()) {
this.processDefeat();
return true;
} else if ($gameTroop.isAllDead()) {
this.processVictory();
return true;
}
}
return false;
};
})(RS.PutInSubPartyMembers);