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
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
| =begin
Equipment Requirements
by Fomar0153
modified by Zouzaka
Version 1.3
----------------------
Notes
----------------------
Adds a level requirement to equipment.
----------------------
Instructions
----------------------
Notetag the weapons/armors like so:
<levelreq x>
<mhpreq x>
<mmpreq x>
<atkreq x>
<defreq x>
<matreq x>
<mdfreq x>
<agireq x>
<lukreq x>
<switchreq x>
<variablereq x,y>
<wepreq x>
<armreq x>
----------------------
Change Log
----------------------
1.0 -> 1.1 Added stat requirements
Changed script name from Equipment Level Requirements
to just Equipment Requirements
1.1 -> 1.2 Added switch and other equipment requirements
1.2 -> 1.3 Ajout D'une Window qui affiche les Conditions requises
Réduit le script de base de plus de 50 lignes
1.3 -> 1.4 Optimisation et resolution de bug
----------------------
Known bugs
----------------------
None
=end
#--------------------------------------------------------------------------
# ● If set to true then it compares the requirement with the actor's base
# stat rather than their current.
#--------------------------------------------------------------------------
EQUIPREQ_USE_BASE_STAT = true
#--------------------------------------------------------------------------
# ● Vocab for switch's
# every switch_id in a different line
#--------------------------------------------------------------------------
Switch_Vocab = {
# Switch_ID => "Vocab",
2 => "Visiter la Campagne",
}
#--------------------------------------------------------------------------
# ● Vocab for variables
# every variable_id in a different line
#--------------------------------------------------------------------------
Variable_Vocab = {
# Variable_ID => "Vocab",
2 => "Nombre de pierres à casser",
}
class Game_Actor
def optimize_equipments
clear_equipments
equip_slots.size.times do |i|
next if !equip_change_ok?(i)
items = $game_party.equip_items.select do |item|
item.etype_id == equip_slots[i] &&
equippable?(item) && item.performance >= 0 && reqstate?(item)
end
change_equip(i, items.max_by {|item| item.performance })
end
end
def reqstate?(item)
unless item == nil
return false if level < item.levelreq
return false if reqstat(0) < item.mhpreq
return false if reqstat(1) < item.mmpreq
return false if reqstat(2) < item.atkreq
return false if reqstat(3) < item.defreq
return false if reqstat(4) < item.matreq
return false if reqstat(5) < item.mdfreq
return false if reqstat(6) < item.agireq
return false if reqstat(7) < item.lukreq
if item.switchreq > 0
return false unless $game_switches[item.switchreq]
end
if item.variablereq != 0
return false unless $game_variables[item.variablereq[0]] < item.variablereq[1]
end
if item.wepreq > 0
e = []
for equip in equips
e.push(equip.id) if equip.class == RPG::Weapon
end
return false unless e.include?(item.wepreq)
end
if item.armreq > 0
e = []
for equip in equips
e.push(equip.id) if equip.class == RPG::Armor
end
return false unless e.include?(item.armreq)
end
end
return true
end
#--------------------------------------------------------------------------
# ● New Method
#--------------------------------------------------------------------------
def reqstat(id)
EQUIPREQ_USE_BASE_STAT ? param_base(id) : param(id)
end
end
class Window_EquipItem
#--------------------------------------------------------------------------
# ● Check the requirements
#--------------------------------------------------------------------------
def enable?(item)
return @actor.reqstate?(item)
end
end
module RPG
#--------------------------------------------------------------------------
# ● Equip Item is inherited by both Weapon and Armor
#--------------------------------------------------------------------------
class EquipItem
def variablereq
self.note =~ /<variablereq (.*),(.*)>/i ? [$1.to_i,$2.to_i] : 0
end
def levelreq
self.note =~ /<levelreq (.*)>/i ? $1.to_i : 0
end
def mhpreq
self.note =~ /<mhpreq (.*)>/i ? $1.to_i : 0
end
def mmpreq
self.note =~ /<mmpreq (.*)>/i ? $1.to_i : 0
end
def atkreq
self.note =~ /<atkreq (.*)>/i ? $1.to_i : 0
end
def defreq
self.note =~ /<defreq (.*)>/i ? $1.to_i : 0
end
def matreq
self.note =~ /<matreq (.*)>/i ? $1.to_i : 0
end
def mdfreq
self.note =~ /<mdfreq (.*)>/i ? $1.to_i : 0
end
def agireq
self.note =~ /<agireq (.*)>/i ? $1.to_i : 0
end
def lukreq
self.note =~ /<lukreq (.*)>/i ? $1.to_i : 0
end
def switchreq
self.note =~ /<switchreq (.*)>/i ? $1.to_i : 0
end
def wepreq
self.note =~ /<wepreq (.*)>/i ? $1.to_i : 0
end
def armreq
self.note =~ /<armreq (.*)>/i ? $1.to_i : 0
end
end
end
class Window_Requirement < Window_Base
def initialize(x, y)
super(x, y, Graphics.width/2, Graphics.height)
self.openness = 0
self.z = 250
@item = nil
@actor = nil
refresh
end
def reqstat(id)
EQUIPREQ_USE_BASE_STAT ? @actor.param_base(id) : @actor.param(id)
end
def item ; return @item ; end
def item=(item)
@item = item
refresh
end
def actor ; return @actor ; end
def actor=(actor)
@actor = actor
refresh
end
def update
super
if Input.trigger?(:R)
@actor = $game_party.menu_actor_next
refresh
elsif Input.trigger?(:L)
@actor = $game_party.menu_actor_prev
refresh
end
end
def refresh
contents.clear
@req = ["item.levelreq","item.mhpreq","item.mmpreq","item.atkreq","item.defreq","item.matreq","item.mdfreq","item.agireq","item.lukreq"]#,"item.wepreq","item.armreq"]
@vocab_req = [Vocab.level,Vocab.param(0),Vocab.param(1),Vocab.param(2),Vocab.param(3),Vocab.param(4),Vocab.param(5),Vocab.param(6),Vocab.param(7)]#,Vocab.weapon,Vocab.armor]
@req_condition = ["@actor.level","reqstat(0)","reqstat(1)","reqstat(2)","reqstat(3)","reqstat(4)","reqstat(5)","reqstat(6)","reqstat(7)"]
@t = 2
change_color(normal_color)
draw_text(contents.width/8, 0, contents.width, line_height, "Conditions requises")
@req.each do |req|
if item != nil && eval(req) != 0 && actor != nil
eval(@req_condition[@req.index(req)]) < eval(req) ? change_color(text_color(2)) : change_color(normal_color)
draw_text(0, line_height*@t, contents.width, line_height, @vocab_req[@req.index(req)]+" requis : "+eval(req).to_s)
@t += 1
end
end
change_color(normal_color)
if item != nil && item.wepreq != 0 && actor != nil
e = []
for equip in @actor.equips
if equip.class == RPG::Weapon
e.push(equip.id)
end
end
change_color(text_color(2)) unless e.include?(item.wepreq)
draw_text(0, line_height*@t, contents.width, line_height, "Arme requise : "+$data_weapons[item.wepreq].name)
@t += 1
end
change_color(normal_color)
if item != nil && item.armreq != 0 && actor != nil
e = []
for equip in @actor.equips
e.push(equip.id) if equip.class == RPG::Armor
end
change_color(text_color(2)) unless e.include?(item.armreq)
draw_text(0, line_height*(@t), contents.width, line_height, "Armure requise : "+$data_armors[item.armreq].name)
@t += 1
end
if item && item.switchreq != 0
$game_switches[item.switchreq] ? change_color(normal_color) : change_color(text_color(2))
draw_text(0, line_height*(@t), contents.width, line_height, Switch_Vocab[item.switchreq])
@t += 1
end
if item && item.variablereq != 0
$game_variables[item.variablereq[0]] >= item.variablereq[1] ? change_color(normal_color) : change_color(text_color(2))
draw_text(0, line_height*(@t), contents.width, line_height, Variable_Vocab[item.variablereq[0]]+" "+$game_variables[item.variablereq[0]].to_s+"/"+item.variablereq[1].to_s)
end
change_color(normal_color)
draw_text(0, contents.height-line_height*3, contents.width, line_height, "Prec.(Q) | Suiv.(W)",1)
draw_text(0, contents.height-line_height*2, contents.width, line_height, "Personnage Actuel",1)
draw_text(0, contents.height-line_height, contents.width, line_height, @actor.name,1) if @actor
end
end
#~ #==============================================================================
#~ # ** Scene_Equip
#~ #------------------------------------------------------------------------------
#~ # This class performs the equipment screen processing.
#~ #==============================================================================
class Scene_Equip
alias :old_start :start
def start
old_start
@window_req = Window_Requirement.new(Graphics.width/4,0)
end
alias :old_update :update
def update
old_update
if Input.trigger?(:CTRL)
if @window_req.openness == 0 && @item_window.active && @item_window.item != nil
@window_req.item=@item_window.item
@window_req.actor= @actor
@background = Sprite.new
@background.z = 200
@background.bitmap = Bitmap.new(Graphics.width, Graphics.height)
@background.bitmap.fill_rect(0,0,Graphics.width,Graphics.height,Color.new(0, 0, 0,128))
@window_req.open
@item_window.deactivate
elsif @window_req.openness == 255
@background.dispose if @background
@window_req.close
@item_window.activate
end
end
end
end
class Scene_Item < Scene_ItemBase
alias :old_start :start
def start
old_start
@window_req = Window_Requirement.new(Graphics.width/4,0)
end
alias :old_update :update
def update
old_update
if Input.trigger?(:CTRL)
if @window_req.openness == 0 && (@item_window.item.class == RPG::Weapon || @item_window.item.class == RPG::Armor)
@window_req.item=@item_window.item
@window_req.actor= @actor
@background = Sprite.new
@background.z = 200
@background.bitmap = Bitmap.new(Graphics.width, Graphics.height)
@background.bitmap.fill_rect(0,0,Graphics.width,Graphics.height,Color.new(0, 0, 0,128))
@window_req.open
@item_window.deactivate
elsif @window_req.openness == 255
@background.dispose if @background
@window_req.close
@item_window.activate
end
end
end
end |