forked from suppayami/rmvxa-collection
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Hospital - Prizes.rb
494 lines (438 loc) · 16.5 KB
/
Hospital - Prizes.rb
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
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
#==============================================================================
#
# ¥ Yami Engine Symphony - Hospital: Hospital Prizes
# -- Last Updated: 2012.11.13
# -- Level: Easy
# -- Requires: YES - Hospital
#
#==============================================================================
$imported = {} if $imported.nil?
$imported["YES-HospitalPrizes"] = true
#==============================================================================
# ¥ Updates
# =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
# 2012.11.13 - Started and Finished Script.
#
#==============================================================================
# ¥ Introduction
# =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
# This script provides some hospital prizes for party. Prizes are depended
# on how often party use hospital's service.
#
#==============================================================================
# ¥ Instructions
# =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
# To install this script, open up your script editor and copy/paste this script
# to an open slot below ¥ Materials/‘fÞ but above ¥ Main. Remember to save.
#
#==============================================================================
# ¥ Compatibility
# =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
# This script is made strictly for RPG Maker VX Ace. It is highly unlikely that
# it will run with RPG Maker VX without adjustments.
#
#==============================================================================
#==============================================================================
# ¥ Editting anything past this point may potentially result in causing
# computer damage, incontinence, explosion of user's head, coma, death, and/or
# halitosis so edit at your own risk.
#==============================================================================
#==============================================================================
# ¡ Regular Expression
#==============================================================================
module REGEXP
module HOSPITAL
PRIZE_MAX = /<(?:PRIZE_MAX|prize max):[ ]*(\d+)>/i
PRIZE_HP = /<(?:PRIZE_HP|prize hp):[ ]*(\d+)>/i
PRIZE_MP = /<(?:PRIZE_MP|prize mp):[ ]*(\d+)>/i
PRIZE_STATE = /<(?:PRIZE_STATE|prize state)[ ]*(\d+):[ ]*(\d+)>/i
PRIZE_STATES = /<(?:PRIZE_STATES|prize states):[ ]*(\d+)>/i
end # HOSPITAL
end # REGEXP
#==============================================================================
# ¡ DataManager
#==============================================================================
module DataManager
#--------------------------------------------------------------------------
# alias method: load_database
#--------------------------------------------------------------------------
class <<self; alias create_game_objects_hospital_prize create_game_objects; end
def self.create_game_objects
create_game_objects_hospital_prize
initialize_hospital_prize
end
#--------------------------------------------------------------------------
# new method: initialize_hospital_prize
#--------------------------------------------------------------------------
def self.initialize_hospital_prize
$data_prizes = []
#---
groups = [$data_items, $data_weapons, $data_armors]
groups.each { |group|
group.each { |obj|
next if obj.nil?
obj.initialize_hospital_prize
}
}
end
end # DataManager
#==============================================================================
# ¡ RPG::BaseItem
#==============================================================================
class RPG::BaseItem
#--------------------------------------------------------------------------
# new method: initialize_hospital_prize
#--------------------------------------------------------------------------
def initialize_hospital_prize
prize = false
@prize_req = [0,0,0,{},0] # Limit, HP, MP, State, States
#---
self.note.split(/[\r\n]+/).each { |line|
case line
when REGEXP::HOSPITAL::PRIZE_MAX
@prize_req[0] = $1.to_i
when REGEXP::HOSPITAL::PRIZE_HP
prize = true
@prize_req[1] = $1.to_i
when REGEXP::HOSPITAL::PRIZE_MP
prize = true
@prize_req[2] = $1.to_i
when REGEXP::HOSPITAL::PRIZE_STATE
prize = true
@prize_req[3][$1.to_i] = $2.to_i
when REGEXP::HOSPITAL::PRIZE_STATE
prize = true
@prize_req[4] = $1.to_i
end
}
#---
$data_prizes.push(self) if prize
end
#--------------------------------------------------------------------------
# new method: prize_total
#--------------------------------------------------------------------------
def prize_total
n = nil
if @prize_req[1] > 0
m = $game_party.prize_hp / @prize_req[1]
n = n.nil? ? m : [m, n].min
end
if @prize_req[2] > 0
m = $game_party.prize_mp / @prize_req[2]
n = n.nil? ? m : [m, n].min
end
if @prize_req[3].size > 0
@prize_req[3].each { |s, i|
x = $game_party.prize_state[s]
x = x.nil? ? 0 : x
m = x / i
n = n.nil? ? m : [m, n].min
}
end
if @prize_req[4] > 0
m = $game_party.prize_states / @prize_req[4]
n = n.nil? ? m : [m, n].min
end
return n.nil? ? 0 : n
end
#--------------------------------------------------------------------------
# new method: prize_available
#--------------------------------------------------------------------------
def prize_available
[[prize_total - prize_received, prize_limit - prize_received].min, 0].max
end
#--------------------------------------------------------------------------
# new method: prize_received
#--------------------------------------------------------------------------
def prize_received
$game_party.prize_received(self)
end
#--------------------------------------------------------------------------
# new method: prize_limit
#--------------------------------------------------------------------------
def prize_limit
@prize_req[0] > 0 ? @prize_req[0] : $game_party.max_item_number(self)
end
end # RPG::BaseItem
#==============================================================================
# ¡ Game_Actor
#==============================================================================
class Game_Actor < Game_Battler
#--------------------------------------------------------------------------
# alias method: hospital_recover
#--------------------------------------------------------------------------
alias prize_hospital_recover hospital_recover
def hospital_recover
if $game_party.gold >= self.hospital_fee
storage_hospital
end
#---
prize_hospital_recover
end
#--------------------------------------------------------------------------
# new method: storage_hospital
#--------------------------------------------------------------------------
def storage_hospital
shp = [mhp - @hp, 0].max
smp = [mmp - @mp, 0].max
#---
$game_party.storage_hospital(shp, smp, self.hospitalize_states)
end
end # Game_Actor
#==============================================================================
# ¡ Game_Party
#==============================================================================
class Game_Party < Game_Unit
#--------------------------------------------------------------------------
# Public Instance Variables
#--------------------------------------------------------------------------
attr_reader :prize_hp
attr_reader :prize_mp
attr_reader :prize_state
attr_reader :prize_states
#--------------------------------------------------------------------------
# alias method: initialize
#--------------------------------------------------------------------------
alias hospital_prize_initialize initialize
def initialize
hospital_prize_initialize
#---
@prize_hp = 0
@prize_mp = 0
@prize_state = {}
@prize_states = 0
#---
@prize_receieved = {}
@prize_receieved[:item] = {}
@prize_receieved[:weapon] = {}
@prize_receieved[:armor] = {}
end
#--------------------------------------------------------------------------
# new method: storage_hospital
#--------------------------------------------------------------------------
def storage_hospital(hp, mp, states)
@prize_hp += hp
@prize_mp += mp
#---
states.each { |state|
@prize_state[state.id] ||= 0
@prize_state[state.id] += 1
}
#---
@prize_states += states.size
end
#--------------------------------------------------------------------------
# new method: prize_received
#--------------------------------------------------------------------------
def prize_received(item)
return 0 unless item
if item.is_a?(RPG::Item)
r = @prize_receieved[:item][item.id]
elsif item.is_a?(RPG::Weapon)
r = @prize_receieved[:weapon][item.id]
elsif item.is_a?(RPG::Armor)
r = @prize_receieved[:armor][item.id]
else; return 0; end
return r.nil? ? 0 : r
end
#--------------------------------------------------------------------------
# new method: claim_prize
#--------------------------------------------------------------------------
def claim_prize(item)
if item.nil?
Sound.play_buzzer
return
end
if item_number(item) < max_item_number(item)
amount = [max_item_number(item) - item_number(item), item.prize_available].min
gain_item(item, amount)
if item.is_a?(RPG::Item)
@prize_receieved[:item][item.id] ||= 0
@prize_receieved[:item][item.id] += amount
elsif item.is_a?(RPG::Weapon)
@prize_receieved[:weapon][item.id] ||= 0
@prize_receieved[:weapon][item.id] += amount
elsif item.is_a?(RPG::Armor)
@prize_receieved[:armor][item.id] ||= 0
@prize_receieved[:armor][item.id] += amount
else; return; end
else
Sound.play_buzzer
end
end
end # Game_Party
#==============================================================================
# ¡ Window_HospitalPrizes
#==============================================================================
class Window_HospitalPrizes < Window_Selectable
#--------------------------------------------------------------------------
# initialize
#--------------------------------------------------------------------------
def initialize(x, y, height)
super(x, y, Graphics.width, height)
refresh
self.hide
end
#--------------------------------------------------------------------------
# init_data
#--------------------------------------------------------------------------
def init_data
@data = $data_prizes.select { |p| p.prize_available > 0 }
end
#--------------------------------------------------------------------------
# refresh
#--------------------------------------------------------------------------
def refresh
init_data
super
end
#--------------------------------------------------------------------------
# col_max
#--------------------------------------------------------------------------
def col_max
return 2
end
#--------------------------------------------------------------------------
# item_max
#--------------------------------------------------------------------------
def item_max
@data ? @data.size : 0
end
#--------------------------------------------------------------------------
# draw_item
#--------------------------------------------------------------------------
def draw_item(index)
item = @data[index]
if item
rect = item_rect(index)
rect.width -= 4
draw_item_name(item, rect.x, rect.y)
draw_item_number(rect, item)
end
end
#--------------------------------------------------------------------------
# draw_item_number
#--------------------------------------------------------------------------
def draw_item_number(rect, item)
draw_text(rect, sprintf("x%2d", item.prize_available), 2)
end
#--------------------------------------------------------------------------
# activate
#--------------------------------------------------------------------------
def activate
self.index = 0 if self.index < 0
return super
end
#--------------------------------------------------------------------------
# item
#--------------------------------------------------------------------------
def item
@data[index]
end
end # Window_HospitalPrizes
#==============================================================================
# ¡ Scene_Hospital
#==============================================================================
class Scene_Hospital < Scene_MenuBase
#--------------------------------------------------------------------------
# alias method: start
#--------------------------------------------------------------------------
alias prize_start start
def start
prize_start
create_prize_windows
end
#--------------------------------------------------------------------------
# alias method: create_command_window
#--------------------------------------------------------------------------
alias prize_create_command_window create_command_window
def create_command_window
prize_create_command_window
@command_window.set_handler(:prize, method(:command_prize))
end
#--------------------------------------------------------------------------
# new method: create_prize_windows
#--------------------------------------------------------------------------
def create_prize_windows
@prize_help_window = Window_Help.new
@prize_help_window.hide
@prize_help_window.y = Graphics.height - @prize_help_window.height
#---
wy = @command_window.height
wh = Graphics.height - @gold_window.height - @command_window.height
@prize_window = Window_HospitalPrizes.new(0, wy, wh)
@prize_window.set_handler(:ok, method(:prize_ok))
@prize_window.set_handler(:cancel, method(:prize_cancel))
end
#--------------------------------------------------------------------------
# alias method: update
#--------------------------------------------------------------------------
alias prize_udpate update
def update
prize_udpate
#---
if @command_window.active
if @command_window.current_symbol == :prize
@actors_window.hide
@prize_window.show
else
@prize_window.hide
@actors_window.show
end
end
#---
if @prize_window.active
@prize_help_window.set_item(@prize_window.item)
end
end
#--------------------------------------------------------------------------
# alias method: command_heal_all
#--------------------------------------------------------------------------
alias prize_command_heal_all command_heal_all
def command_heal_all
prize_command_heal_all
@prize_window.refresh
end
#--------------------------------------------------------------------------
# alias method: actor_ok
#--------------------------------------------------------------------------
alias prize_actor_ok actor_ok
def actor_ok
prize_actor_ok
@prize_window.refresh
end
#--------------------------------------------------------------------------
# new method: command_prize
#--------------------------------------------------------------------------
def command_prize
@prize_window.height = Graphics.height - @prize_help_window.height - @command_window.height
@prize_window.refresh
@prize_window.show.activate
@prize_help_window.show
@help_window.hide
@gold_window.hide
end
#--------------------------------------------------------------------------
# new method: prize_ok
#--------------------------------------------------------------------------
def prize_ok
$game_party.claim_prize(@prize_window.item)
@prize_window.activate.refresh
end
#--------------------------------------------------------------------------
# new method: prize_cancel
#--------------------------------------------------------------------------
def prize_cancel
@prize_window.height = Graphics.height - @gold_window.height - @command_window.height
@prize_window.deactivate
@command_window.activate
@prize_help_window.hide
@help_window.show
@gold_window.show
end
end # Scene_Hospital
#==============================================================================
#
# ¥ End of File
#
#==============================================================================