forked from Archeia/YEARepo
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Instant_Cast.rb
324 lines (288 loc) · 12.1 KB
/
Instant_Cast.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
#==============================================================================
#
# ▼ Yanfly Engine Ace - Instant Cast v1.03
# -- Last Updated: 2012.07.17
# -- Level: Normal
# -- Requires: n/a
#
#==============================================================================
$imported = {} if $imported.nil?
$imported["YEA-InstantCast"] = true
#==============================================================================
# ▼ Updates
# =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
# 2012.07.17 - Instant doesn't take up a turn if a characterh as additional
# actions/can attack twice.
# 2012.01.12 - Anti-crash methods implemented.
# 2011.12.26 - Bug Fixed: If actor gets stunned while doing an instant cast,
# the actor will not be reselected.
# 2011.12.21 - Started Script and Finished.
#
#==============================================================================
# ▼ Introduction
# =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
# From the VX Yanfly Engines, instant cast properties have been a staple skill
# and item property. Instant cast makes a return in RPG Maker VX Ace. There's
# a few changes made with instant casts.
#
# 1) For actors with multiple actions, instants will only occur if the first
# action is an instant. If the first action is not an instant the follow-up
# actions contain an instant, the instant will be treated as normal.
#
# 2) Any actions added on by instants will automatically trigger immediately
# after the instant finishes and will be treated as instants. This includes
# Active Chain Skills triggering from an instant.
#
# 3) If an enemy uses an instant, the enemy will gain an additional skill to
# use after using the said instant. This will apply whenever an enemy uses
# an instant skill, even if it was after the enemy's first action.
#
#==============================================================================
# ▼ 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.
#
# -----------------------------------------------------------------------------
# Skill Notetags - These notetags go in the skills notebox in the database.
# -----------------------------------------------------------------------------
# <instant>
# Causes the action to be an instant action. If an instant action is selected
# first, then the action will be performed before the battle phase starts. If
# placed behind a non-instant action, the would-be instant action will be
# considered a normal action. If an enemy uses an instant action, no matter if
# it was used first or after, the enemy gains an additional action.
#
# -----------------------------------------------------------------------------
# Item Notetags - These notetags go in the items notebox in the database.
# -----------------------------------------------------------------------------
# <instant>
# Causes the action to be an instant action. If an instant action is selected
# first, then the action will be performed before the battle phase starts. If
# placed behind a non-instant action, the would-be instant action will be
# considered a normal action. If an enemy uses an instant action, no matter if
# it was used first or after, the enemy gains an additional action.
#
#==============================================================================
# ▼ Compatibility
# =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
# This script is made strictly for RPG Maker VX Ace. It is highly unlikely that
# it will run with RPG Maker VX without adjusting.
#
# This script is compatible with Yanfly Engine Ace - Ace Battle Engine v1.00+.
# Place this script under Ace Battle Engine in the script listing
#
#==============================================================================
# ▼ 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 YEA
module REGEXP
module USABLEITEM
INSTANT = /<(?:INSTANT|instant)>/i
end # USABLEITEM
end # REGEXP
end # YEA
#==============================================================================
# ¡ DataManager
#==============================================================================
module DataManager
#--------------------------------------------------------------------------
# alias method: load_database
#--------------------------------------------------------------------------
class <<self; alias load_database_instant load_database; end
def self.load_database
load_database_instant
load_notetags_instant
end
#--------------------------------------------------------------------------
# new method: load_notetags_instant
#--------------------------------------------------------------------------
def self.load_notetags_instant
groups = [$data_skills, $data_items]
for group in groups
for obj in group
next if obj.nil?
obj.load_notetags_instant
end
end
end
end # DataManager
#==============================================================================
# ¡ RPG::UsableItem
#==============================================================================
class RPG::UsableItem < RPG::BaseItem
#--------------------------------------------------------------------------
# public instance variables
#--------------------------------------------------------------------------
attr_accessor :instant
#--------------------------------------------------------------------------
# common cache: load_notetags_instant
#--------------------------------------------------------------------------
def load_notetags_instant
@instant = false
#---
self.note.split(/[\r\n]+/).each { |line|
case line
#---
when YEA::REGEXP::USABLEITEM::INSTANT
@instant = true
#---
end
} # self.note.split
#---
end
end # RPG::UsableItem
#==============================================================================
# ¡ Game_Actor
#==============================================================================
class Game_Actor < Game_Battler
#--------------------------------------------------------------------------
# new method: check_instant_action
#--------------------------------------------------------------------------
def check_instant_action
@backup_actions_instant = []
@actions.each { |action|
next unless action
if action.item.nil?
@backup_actions_instant.push(action.dup)
next
end
unless action.item.instant
@backup_actions_instant.push(action.dup)
action.clear
end
}
end
#--------------------------------------------------------------------------
# new method: restore_instant_action
#--------------------------------------------------------------------------
def restore_instant_action
@backup_actions_instant.each_index { |i|
@actions[i] = @backup_actions_instant[i]
}
@backup_actions_instant.clear
i = 0
@actions.each { |action| if action.item.nil?; break; end; i += 1 }
@action_input_index = i
end
end # Game_Actor
#==============================================================================
# ¡ Game_Enemy
#==============================================================================
class Game_Enemy < Game_Battler
#--------------------------------------------------------------------------
# new method: add_extra_action
#--------------------------------------------------------------------------
def add_extra_action
action_list = enemy.actions.select {|a| action_valid?(a) }
return if action_list.empty?
rating_max = action_list.collect {|a| a.rating }.max
rating_zero = rating_max - 3
action_list.reject! {|a| a.rating <= rating_zero }
action = Game_Action.new(self)
action.set_enemy_action(select_enemy_action(action_list, rating_zero))
@actions.push(action)
end
end # Game_Enemy
#==============================================================================
# ¡ Scene_Battle
#==============================================================================
class Scene_Battle < Scene_Base
#--------------------------------------------------------------------------
# alias method: next_command
#--------------------------------------------------------------------------
alias scene_battle_next_command_instant next_command
def next_command
if instant_action?
perform_instant_action
else
scene_battle_next_command_instant
end
end
#--------------------------------------------------------------------------
# new method: instant_action?
#--------------------------------------------------------------------------
def instant_action?
return false if BattleManager.actor.nil?
return false if BattleManager.actor.input.nil?
action = BattleManager.actor.input.item
return false if action.nil?
return action.instant
end
#--------------------------------------------------------------------------
# new method: perform_instant_action
#--------------------------------------------------------------------------
def perform_instant_action
hide_instant_action_windows
@subject = BattleManager.actor
@subject.check_instant_action
execute_action if @subject.current_action.valid?
process_event
loop do
@subject.remove_current_action
break if $game_troop.all_dead?
break unless @subject.current_action
@subject.current_action.prepare
execute_action if @subject.current_action.valid?
end
process_action_end
@subject.make_actions
@subject.restore_instant_action
@subject = nil
show_instant_action_windows
end
#--------------------------------------------------------------------------
# new method: hide_instant_action_windows
#--------------------------------------------------------------------------
def hide_instant_action_windows
if $imported["YEA-BattleEngine"]
@info_viewport.visible = true
@status_aid_window.hide
@status_window.show
@actor_command_window.show
end
end
#--------------------------------------------------------------------------
# new method: show_instant_action_windows
#--------------------------------------------------------------------------
def show_instant_action_windows
if $imported["YEA-BattleEngine"]
@info_viewport.visible = true
end
start_actor_command_selection
status_redraw_target(BattleManager.actor)
next_command unless BattleManager.actor.inputable?
end
#--------------------------------------------------------------------------
# new method: status_redraw_target
#--------------------------------------------------------------------------
def status_redraw_target(target)
return unless target.actor?
@status_window.draw_item($game_party.battle_members.index(target))
end
#--------------------------------------------------------------------------
# alias method: execute_action
#--------------------------------------------------------------------------
alias scene_battle_execute_action_instant execute_action
def execute_action
scene_battle_execute_action_instant
enemy_add_actions
end
#--------------------------------------------------------------------------
# new method: enemy_add_actions
#--------------------------------------------------------------------------
def enemy_add_actions
return if @subject.actor?
return if @subject.current_action.nil?
return if @subject.current_action.item.nil?
return unless @subject.current_action.item.instant
@subject.add_extra_action
end
end # Scene_Battle
#==============================================================================
#
# ▼ End of File
#
#==============================================================================