forked from suppayami/rmvxa-collection
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Infective State.rb
299 lines (272 loc) · 10.5 KB
/
Infective State.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
#==============================================================================
#
# ¥ Yami Engine Symphony - Infective State
# -- Last Updated: 2012.12.14
# -- Level: Easy
# -- Requires: n/a
#
#==============================================================================
$imported = {} if $imported.nil?
$imported["YES-InfectiveState"] = true
#==============================================================================
# ¥ Updates
# =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
# 2012.12.14 - Finished Script.
# 2012.12.12 - Started Script.
#
#==============================================================================
# ¥ Introduction
# =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
# This script provides infect feature for specific states.
#
#==============================================================================
# ¥ 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.
#
# -----------------------------------------------------------------------------
# State Notetags - These notetags go in the state notebox in the database.
# -----------------------------------------------------------------------------
# <infect allies x: y, z%>
# Infects all allies with state x after y turns with a chance of z%.
#
# <infect enemies x: y, z%>
# Infects all enemies with state x after y turns with a chance of z%.
#
# <infect n allias x: y, z%>
# Infects n allies with state x after y turns with a chance of z%.
#
# <infect n enemies x: y, z%>
# Infects n enemies with state x after y turns with a chance of z%.
#
#==============================================================================
# ¥ 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 INFECTIVE_STATE
INFECT_ALLY = /<(?:INFECT ALLIES)[ ](\d+):[ ]*(\d+)(?:,[ ]*(\d+)[%“]?)?>/i
INFECT_ENEMY = /<(?:INFECT ENEMIES)[ ](\d+):[ ]*(\d+)(?:,[ ]*(\d+)[%“]?)?>/i
INFECT_X_ALLY = /<(?:INFECT (\d+) ALLIES)[ ](\d+):[ ]*(\d+)(?:,[ ]*(\d+)[%“]?)?>/i
INFECT_X_ENEMY = /<(?:INFECT (\d+) ENEMIES)[ ](\d+):[ ]*(\d+)(?:,[ ]*(\d+)[%“]?)?>/i
end # INFECTIVE_STATE
end # REGEXP
#==============================================================================
# ¡ DataManager
#==============================================================================
module DataManager
#--------------------------------------------------------------------------
# alias method: load_database
#--------------------------------------------------------------------------
class <<self; alias load_database_infective_state load_database; end
def self.load_database
load_database_infective_state
initialize_infective_state
end
#--------------------------------------------------------------------------
# new method: initialize_infective_state
#--------------------------------------------------------------------------
def self.initialize_infective_state
groups = [$data_states]
groups.each { |group|
group.each { |obj|
next if obj.nil?
obj.initialize_infective_state
}
}
end
end # DataManager
#==============================================================================
# ¡ RPG::BaseItem
#==============================================================================
class RPG::BaseItem
#--------------------------------------------------------------------------
# * Public Instance Variables
#--------------------------------------------------------------------------
attr_accessor :infect_allies
attr_accessor :infect_enemies
#--------------------------------------------------------------------------
# new method: initialize_infective_state
#--------------------------------------------------------------------------
def initialize_infective_state
@infect_allies = {}
@infect_enemies = {}
self.note.split(/[\r\n]+/).each { |line|
case line
when REGEXP::INFECTIVE_STATE::INFECT_ALLY
array = [0, $2.to_i, $3.to_i]
array[2] = 100 if array[2] <= 0
@infect_allies[$1.to_i] = array if array[1] > 0
when REGEXP::INFECTIVE_STATE::INFECT_ENEMY
array = [0, $2.to_i, $3.to_i]
array[2] = 100 if array[2] <= 0
@infect_enemies[$1.to_i] = array if array[1] > 0
when REGEXP::INFECTIVE_STATE::INFECT_X_ALLY
array = [$1.to_i, $3.to_i, $4.to_i]
array[2] = 100 if array[2] <= 0
@infect_allies[$2.to_i] = array if array[1] > 0
when REGEXP::INFECTIVE_STATE::INFECT_X_ENEMY
array = [$1.to_i, $3.to_i, $4.to_i]
array[2] = 100 if array[2] <= 0
@infect_enemies[$2.to_i] = array if array[1] > 0
end
}
end
end # RPG::BaseItem
#==============================================================================
# ¡ Game_Battler
#==============================================================================
class Game_Battler < Game_BattlerBase
#--------------------------------------------------------------------------
# new method: infective_states
#--------------------------------------------------------------------------
def infective_states
states.select { |state|
state.infect_allies.size + state.infect_enemies.size > 0
}
end
#--------------------------------------------------------------------------
# new method: infective_allies
#--------------------------------------------------------------------------
def infective_allies
states.select { |state|
state.infect_allies.size > 0
}
end
#--------------------------------------------------------------------------
# new method: infective_enemies
#--------------------------------------------------------------------------
def infective_enemies
states.select { |state|
state.infect_enemies.size > 0
}
end
#--------------------------------------------------------------------------
# new method: infect_allies_include?
#--------------------------------------------------------------------------
def infect_allies_include?(id)
infective_allies.any? { |state| state.infect_allies.keys.include?(id) }
end
#--------------------------------------------------------------------------
# new method: infect_enemies_include?
#--------------------------------------------------------------------------
def infect_enemies_include?(id)
infective_enemies.any? { |state| state.infect_enemies.keys.include?(id) }
end
#--------------------------------------------------------------------------
# new method: infective_calc
#--------------------------------------------------------------------------
def update_infective
@infect_allies ||= {}
@infect_enemies ||= {}
#---
infective_allies.each { |state|
state.infect_allies.each { |id, hash|
@infect_allies[id] = hash[1] if @infect_allies[id].nil? || @infect_allies[id] <= 0
@infect_allies[id] -= 1
}
}
#---
infective_enemies.each { |state|
state.infect_enemies.each { |id, hash|
@infect_enemies[id] = hash[1] if @infect_enemies[id].nil? || @infect_enemies[id] <= 0
@infect_enemies[id] -= 1
}
}
#---
infective_allies.each { |state|
state.infect_allies.each { |id, hash|
next if @infect_allies[id] > 0
if self.actor?
battlers = $game_party.battle_members
else
battlers = $game_troop.members
end
if hash[0] <= 0
if rand(100) < hash[2]
battlers.each { |battler| battler.add_state(id) }
end
else
count = hash[0]
battlers = battlers.shuffle
battlers.each { |battler|
if battler && battler.alive? && !battler.state?(id)
if rand(100) > hash[2]
battler.add_state(id)
count -= 1
end
end
break if count <= 0
}
end
}
}
#---
infective_enemies.each { |state|
state.infect_enemies.each { |id, hash|
next if @infect_enemies[id] > 0
next if rand(100) > hash[2]
if self.actor?
battlers = $game_troop.members
else
battlers = $game_party.battle_members
end
if hash[0] <= 0
if rand(100) < hash[2]
battlers.each { |battler| battler.add_state(id) }
end
else
count = hash[0]
battlers = battlers.shuffle
battlers.each { |battler|
if battler && battler.alive? && !battler.state?(id)
if rand(100) > hash[2]
battler.add_state(id)
count -= 1
end
end
break if count <= 0
}
end
}
}
end
#--------------------------------------------------------------------------
# new method: infective_clear
#--------------------------------------------------------------------------
def infective_clear
@infect_allies.each_key { |id|
@infect_allies[id] = nil unless infect_allies_include?(id)
}
#---
@infect_enemies.each_key { |id|
@infect_enemies[id] = nil unless infect_enemies_include?(id)
}
end
#--------------------------------------------------------------------------
# alias method: on_turn_end
#--------------------------------------------------------------------------
alias yes_infect_state_on_turn_end on_turn_end
def on_turn_end
yes_infect_state_on_turn_end
update_infective
infective_clear
end
end # Game_Battler
#==============================================================================
#
# ¥ End of File
#
#==============================================================================