forked from suppayami/rmvxa-collection
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Dash Stamina.rb
401 lines (351 loc) · 14.7 KB
/
Dash Stamina.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
#==============================================================================
#
# ▼ Yami Engine Symphony - Dash Stamina
# -- Last Updated: 2013.02.27
# -- Level: Easy
# -- Requires: n/a
#
#==============================================================================
$imported = {} if $imported.nil?
$imported["YES-DashStamina"] = true
#==============================================================================
# ▼ Updates
# =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
# 2013.02.27 - Added recover method.
# - Added rest area feature.
# 2012.11.18 - Fixed Enable Window option.
# 2012.11.17 - Added recovery frames.
# - Added stamina variable.
# - Fixed recovery problem when holding Shift.
# 2012.11.15 - Started and Finished Script.
#
#==============================================================================
# ▼ Introduction
# =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
# This script provides stamina feature for dashing on map. Dashing will comsume
# stamina and be disable if run our of stamina.
#
#==============================================================================
# ▼ Instructions
# =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
# To install this script, open up your script editor and copy/paste this script
# to an open slot below ▼ Materials/素材 but above ▼ Main. Remember to save.
#
# -----------------------------------------------------------------------------
# Script Calls - These commands are used with script calls.
# -----------------------------------------------------------------------------
# YES.recover_stamina
# Fully recover stamina for player.
#
# YES.recover_stamina(X)
# Recover X stamina for player.
#
#==============================================================================
# ▼ 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.
#
#==============================================================================
#==============================================================================
# ■ Configuration
#==============================================================================
module YES
module DASH
#=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
# - General Settings -
#=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
STAMINA_DEFAULT = 200 # Default Stamina for player.
STAMINA_PER_FRAME = 1 # Default Stamina cost per frame while dashing.
MOVE_RESTORE = false # Set this to false to disable restoring
# stamina while moving.
RECOVER_FRAMES = 120 # Start recovering after X frames.
STAMINA_RESTORE = 5 # Restoring Stamina per X frames.
RESTORE_AFTER = 10 # Restore Stamina after X frames.
REST_AREA_RATE = 1 # Restore rate when standing on rest area.
# Set this to 1 to disable rest area function.
REST_AREA_REGION = 19 # Region ID of rest area.
#=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
# - Switches and Variables Settings -
#=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
STAMINA_VARIABLE = 10 # Variable to control stamina.
DISABLE_SWITCH = 98 # Switch to toggle Stamina Feature.
# Set to true to disable Stamina Feature.
#=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
# - Windows Settings -
#=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
ENABLE_WINDOW = true # Toggle stamina window.
AUTO_HIDE_WINDOW = true # Toggle auto-hide function for Stamina Window.
HIDE_AFTER_FRAMES = 300 # Hide after X frames if not dashing.
STAMINA_TEXT = "Stamina"
WINDOW_WIDTH = 180
BAR_COLORS = { # Settings for stamina bar colors.
:color1 => 28,
:color2 => 29,
} # Do not remove this.
end # DASH
end # YES
#==============================================================================
# ▼ 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.
#==============================================================================
#==============================================================================
# ■ Module Yami Engine Symphony
#==============================================================================
module YES
#--------------------------------------------------------------------------
# self.recover_stamina
#--------------------------------------------------------------------------
def self.recover_stamina(amount = :full)
$game_player.recover_stamina(amount)
end
end # YES
#==============================================================================
# ■ Game_Player
#==============================================================================
class Game_Player < Game_Character
#--------------------------------------------------------------------------
# * Public Instance Variables
#--------------------------------------------------------------------------
attr_accessor :stamina_backup
#--------------------------------------------------------------------------
# alias method: initialize
#--------------------------------------------------------------------------
alias dash_initialize initialize
def initialize
dash_initialize
#---
@stamina = YES::DASH::STAMINA_DEFAULT
$game_variables[YES::DASH::STAMINA_VARIABLE] = YES::DASH::STAMINA_DEFAULT
#---
@recover_frames = 0
@stamina_backup = {}
end
#--------------------------------------------------------------------------
# new method: stamina
#--------------------------------------------------------------------------
def stamina
return @stamina
end
#--------------------------------------------------------------------------
# new method: stamina_max
#--------------------------------------------------------------------------
def stamina_max
$game_variables[YES::DASH::STAMINA_VARIABLE]
end
#--------------------------------------------------------------------------
# new method: stamina_rate
#--------------------------------------------------------------------------
def stamina_rate
stamina.to_f / stamina_max.to_f
end
#--------------------------------------------------------------------------
# new method: stamina_cost
#--------------------------------------------------------------------------
def stamina_cost
[YES::DASH::STAMINA_PER_FRAME, @stamina].min
end
#--------------------------------------------------------------------------
# new method: recover_stamina
#--------------------------------------------------------------------------
def recover_stamina(amount = :full)
if amount.is_a?(Integer)
@stamina += amount
correct_stamina
else
@stamina = stamina_max
end
end
#--------------------------------------------------------------------------
# alias method: update
#--------------------------------------------------------------------------
alias dash_update update
def update
dash_update
update_dash_stamina
#---
correct_stamina
#---
update_stamina_recover
end
#--------------------------------------------------------------------------
# new method: correct_stamina
#--------------------------------------------------------------------------
def correct_stamina
@stamina = stamina_max if @stamina > stamina_max
@stamina = 0 if @stamina < 0
end
#--------------------------------------------------------------------------
# new method: update_dash_stamina
#--------------------------------------------------------------------------
def update_dash_stamina
return unless moving?
return unless dash?
@stamina = @stamina - stamina_cost
@stamina = 0 if @stamina < 0
@recover_frames = YES::DASH::RECOVER_FRAMES
end
#--------------------------------------------------------------------------
# new method: update_stamina_recover
#--------------------------------------------------------------------------
def update_stamina_recover
@recover_frames -= 1
return if @recover_frames > 0
return if moving? && YES::DASH::MOVE_RESTORE
return unless Graphics.frame_count % YES::DASH::RESTORE_AFTER == 0
return correct_stamina if @stamina >= stamina_max
@stamina += stamina_recover
@stamina = stamina_max if @stamina > stamina_max
end
#--------------------------------------------------------------------------
# alias method: dash?
#--------------------------------------------------------------------------
alias stamina_dash? dash?
def dash?
return false if @stamina <= 0 && !$game_switches[YES::DASH::DISABLE_SWITCH]
return stamina_dash?
end
#--------------------------------------------------------------------------
# new method: stamina_recover
#--------------------------------------------------------------------------
def stamina_recover
YES::DASH::STAMINA_RESTORE * rest_area_rate
end
#--------------------------------------------------------------------------
# new method: on_rest_area?
#--------------------------------------------------------------------------
def on_rest_area?
region_id == YES::DASH::REST_AREA_REGION
end
#--------------------------------------------------------------------------
# new method: rest_area_rate
#--------------------------------------------------------------------------
def rest_area_rate
on_rest_area? ? YES::DASH::REST_AREA_RATE : 1
end
end # Game_Player
#==============================================================================
# ■ Window_Stamina
#==============================================================================
class Window_Stamina < Window_Base
#--------------------------------------------------------------------------
# initialize
#--------------------------------------------------------------------------
def initialize
super(24, Graphics.height - 74, YES::DASH::WINDOW_WIDTH, 50)
@time = YES::DASH::HIDE_AFTER_FRAMES
refresh
#---
$game_player.stamina_backup[:x] ||= self.x
$game_player.stamina_backup[:time] ||= @time
self.x = $game_player.stamina_backup[:x]
@time = $game_player.stamina_backup[:time]
end
#--------------------------------------------------------------------------
# refresh
#--------------------------------------------------------------------------
def refresh
return if @stamina && @stamina == $game_player.stamina
contents.clear
#---
draw_stamina_bar(0, 0, YES::DASH::WINDOW_WIDTH - 24)
#---
@stamina = $game_player.stamina
end
#--------------------------------------------------------------------------
# stamina_bar_color1
#--------------------------------------------------------------------------
def stamina_bar_color1
text_color(YES::DASH::BAR_COLORS[:color1])
end
#--------------------------------------------------------------------------
# stamina_bar_color2
#--------------------------------------------------------------------------
def stamina_bar_color2
text_color(YES::DASH::BAR_COLORS[:color2])
end
#--------------------------------------------------------------------------
# draw_stamina_bar
#--------------------------------------------------------------------------
def draw_stamina_bar(x, y, width = 156)
draw_gauge(x, y, width,$game_player.stamina_rate, stamina_bar_color1, stamina_bar_color2)
change_color(system_color)
draw_text(x, y, contents.width, line_height, YES::DASH::STAMINA_TEXT)
draw_current_and_max_values(x, y, width, $game_player.stamina,
$game_player.stamina_max, normal_color, normal_color)
end
#--------------------------------------------------------------------------
# update
#--------------------------------------------------------------------------
def update
super
update_hide
update_show
update_input
refresh
$game_switches[YES::DASH::DISABLE_SWITCH] ? self.hide : self.show
self.hide unless YES::DASH::ENABLE_WINDOW
end
#--------------------------------------------------------------------------
# update_hide
#--------------------------------------------------------------------------
def update_hide
return unless YES::DASH::AUTO_HIDE_WINDOW
return if $game_player.dash?
@time -= 1
return unless @time <= 0
#---
self.x -= 9 if self.x > -self.width
end
#--------------------------------------------------------------------------
# update_show
#--------------------------------------------------------------------------
def update_show
return unless YES::DASH::AUTO_HIDE_WINDOW
return unless @show
@time = 180
self.x += 8 if self.x < 24
@show = false if self.x >= 24
end
#--------------------------------------------------------------------------
# update_input
#--------------------------------------------------------------------------
def update_input
return unless $game_player.dash?
return unless $game_player.moving?
@show = true
end
#--------------------------------------------------------------------------
# dispose
#--------------------------------------------------------------------------
def dispose
$game_player.stamina_backup[:x] = self.x
$game_player.stamina_backup[:time] = @time
super
end
end # Window_Stamina
#==============================================================================
# ■ Scene_Map
#==============================================================================
class Scene_Map < Scene_Base
#--------------------------------------------------------------------------
# alias method: create_all_windows
#--------------------------------------------------------------------------
alias dash_create_all_windows create_all_windows
def create_all_windows
dash_create_all_windows
create_dash_window
end
#--------------------------------------------------------------------------
# new method: create_dash_window
#--------------------------------------------------------------------------
def create_dash_window
@stamina_window = Window_Stamina.new
end
end # Scene_Map
#==============================================================================
#
# ▼ End of File
#
#==============================================================================