-
Notifications
You must be signed in to change notification settings - Fork 9
/
Copy pathRTK_ActionLimit.js
210 lines (202 loc) · 6.76 KB
/
RTK_ActionLimit.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
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
//=============================================================================
// RTK_ActionLimit.js ver1.02 2016/08/20
// The MIT License (MIT)
//=============================================================================
/*:
* @plugindesc Set action's usable limit by note tag
* @author Toshio Yamashita (yamachan)
*
* @param meta tag
* @desc Meta tag name for Condition text in Note area
* @default condition
*
* @help This plugin does not provide plugin commands.
*
* NoteTags:
* <condition switch:n> # Can use this when #n switch is ON
* <condition actor:n,m,,> # Actors (ID: n,m,,) can use this
* <condition class:n,m,,> # Classes (ID: n,m,,) can use this
* <condition max:n> # Can use #n times in a battle
* <condition max +turn:n> # Increase max per n turn
* <condition max +level:n> # Increase max per n party members' max level
* <condition req item:n> # Require to use %n item before this
* <condition req item:n> # Require to use %n skill before this
*
* If you add the prefix "v" to the number n, it means a value in the game variables.
* e.g. <condition switch:v10> Can use this when the switch selected by the game variable #10 is ON.
* e.g. <condition actor:v10> An actor selected by the game variable #10 can use this.
*/
/*:ja
* @plugindesc メモ欄のタグでアクションの実行回数などを制限する
* @author Toshio Yamashita (yamachan)
*
* @param meta tag
* @desc ノート欄で使用条件を指定するタグ名
* @default condition
*
* @help このプラグインにはプラグインコマンドはありません。
*
* スキル・アイテムのメモ:
* <condition switch:n> # n番スイッチがONのときだけ戦闘で利用できる
* <condition actor:n,m,,> # n,m,,番のアクターだけが戦闘で利用できる
* <condition class:n,m,,> # n,m,,番のクラスだけが戦闘で利用できる
* <condition max:n> # 1度の戦闘でn回だけ利用できる
* <condition max +turn:n> # nターンごとに利用回数がプラスされる
* <condition max +level:n> # パーティの最大レベルが n に達すると利用回数がプラスされる
* <condition req item:n> # その戦闘中にn番のアイテムを使用後に利用可能になる
* <condition req skill:n> # その戦闘中にn番のスキルを使用後に利用可能になる
*
* 単独の数値 n の前に "v" を付与すると、その番号が示すゲーム変数の値が代わりに利用される
* 例) <condition switch:v10> は変数10番に入っている値に対応するスイッチがONのときだけ利用できる
* 例) <condition actor:v10> は変数10番に入っている値に対応するアクターだけが利用できる
*/
(function(_global) {
var N = 'RTK_ActionLimit';
var param = PluginManager.parameters(N);
var tag = String(param['meta tag'] || "condition");
var items = [];
var skills = [];
function conv(_s, _default) {
if (_s.match(/^\s*[\d.]+\s*$/)) {
return Number(_s);
}
var ret = _s.match(/^\s*v([\d.]+)\s*$/i);
if (ret) {
return $gameVariables.value(Number(ret[1]));
}
return _default;
}
function check(_s, _v) {
if ("string" != typeof _v || _v == "") {
return false;
}
_v = _v.toLowerCase();
return String(_s||"").split(",").some(function(v){
return v.toLowerCase() == _v;
});
}
function count(_i, _t) {
var ret = 0;
if (BattleManager._phase == "input") {
for (var l=0; l<BattleManager._actorIndex; l++) {
var actor = $gameParty.members()[l];
if (actor._actionState == "waiting") {
actor._actions.forEach(function(a){
if (a._item && a._item._dataClass == _t && a._item._itemId == _i) {
ret++;
}
});
}
}
}
return ret;
}
function plus(_m) {
var ret = 0;
if (_m[tag + " max +turn"]) {
var r = conv(_m[tag + " max +turn"], 0);
if (r > 0) {
ret += Math.floor($gameTroop.turnCount() / r);
}
}
if (_m[tag + " max +level"]) {
var r = conv(_m[tag + " max +level"], 0);
if (r > 0) {
ret += Math.floor($gameParty.highestLevel() / r);
}
}
return ret;
}
var _Scene_Battle_create = Scene_Battle.prototype.create;
Scene_Battle.prototype.create = function() {
_Scene_Battle_create.call(this);
items = [];
skills = [];
};
var _Game_BattlerBase_isOccasionOk = Game_BattlerBase.prototype.isOccasionOk;
Game_BattlerBase.prototype.isOccasionOk = function(item) {
var ret = _Game_BattlerBase_isOccasionOk.call(this, item);
if (ret && $gameParty.inBattle()) {
var meta = item && (item.meta || {});
if (meta[tag + " switch"]) {
var v = conv(meta[tag + " switch"], 0);
if (v > 0) {
if (!$gameSwitches.value(v)) {
return false;
}
}
}
if (meta[tag + " max"]) {
var v = conv(meta[tag + " max"], 0);
if (v > 0) {
if (DataManager.isItem(item)) {
items[item.id] = items[item.id] === undefined ? 0 : items[item.id];
if (items[item.id] + count(item.id, "item") >= v + plus(meta)) {
return false;
}
} else if (DataManager.isSkill(item)) {
skills[item.id] = skills[item.id] === undefined ? 0 : skills[item.id];
if (skills[item.id] + count(item.id, "skill") >= v + plus(meta)) {
return false;
}
}
}
}
if (meta[tag + " req item"]) {
var v = conv(meta[tag + " req item"], 0);
if (v > 0 && !items[v]) {
return false;
}
}
if (meta[tag + " req skill"]) {
var v = conv(meta[tag + " req skill"], 0);
if (v > 0 && !skills[v]) {
return false;
}
}
if (BattleManager.actor()) {
if (meta[tag + " actor"]) {
var v = conv(meta[tag + " actor"], 0);
if (v > 0) {
if (v != BattleManager.actor().actor().id) {
return false;
}
} else {
if(!check(meta[tag + " actor"], String(BattleManager.actor().actor().id))) {
return false;
}
}
}
if (meta[tag + " class"]) {
var v = conv(meta[tag + " class"], 0);
if (v > 0) {
if (v != BattleManager.actor()._classId) {
return false;
}
} else {
if (check(meta[tag + " class"], String(BattleManager.actor()._classId))) {
return false;
}
}
}
}
}
return ret;
};
var _Game_Party_consumeItem = Game_Party.prototype.consumeItem;
Game_Party.prototype.consumeItem = function(item) {
var ret = _Game_Party_consumeItem.call(this, item);
if ($gameParty.inBattle()) {
items[item.id] = items[item.id] === undefined ? 1 : items[item.id] + 1;
}
return ret;
};
var _Game_BattlerBase_paySkillCost = Game_BattlerBase.prototype.paySkillCost;
Game_BattlerBase.prototype.paySkillCost = function(skill) {
var ret = _Game_BattlerBase_paySkillCost.call(this, skill);
if ($gameParty.inBattle()) {
skills[skill.id] = skills[skill.id] === undefined ? 1 : skills[skill.id] + 1;
}
return ret;
};
})(this);