-
Notifications
You must be signed in to change notification settings - Fork 170
/
Copy pathConvert_Damage.rb
582 lines (541 loc) · 21.9 KB
/
Convert_Damage.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
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
#==============================================================================
#
# ▼ Yanfly Engine Ace - Convert Damage v1.02
# -- Last Updated: 2012.01.23
# -- Level: Normal
# -- Requires: n/a
#
#==============================================================================
$imported = {} if $imported.nil?
$imported["YEA-ConvertDamage"] = true
#==============================================================================
# ▼ Updates
# =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
# 2013.02.17 - Bug fixes.
# 2012.01.23 - Compatibility Update: Doppelganger
# 2011.12.21 - Started Script and Finished.
#
#==============================================================================
# ▼ Introduction
# =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
# This script gives actors, classes, equipment, enemies, and states passive
# convert damage HP/MP traits. By dealing physical or magical damage (dependant
# on the type of attack), attackers may recover HP or MP depending on what
# kinds of convert damage types they have.
#
#==============================================================================
# ▼ 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.
#
# -----------------------------------------------------------------------------
# Actor Notetags - These notetags go in the actors notebox in the database.
# -----------------------------------------------------------------------------
# <convert hp physical: +x%>
# <convert hp physical: -x%>
# Converts any physical damage dealt to recover HP by x% of the damage dealt.
# Bonus converted damage rates are additive. There will be no effects if HP
# to be healed is 0 or below.
#
# <convert hp magical: +x%>
# <convert hp magical: -x%>
# Converts any magical damage dealt to recover HP by x% of the damage dealt.
# Bonus converted damage rates are additive. There will be no effects if HP
# to be healed is 0 or below.
#
# <convert mp physical: +x%>
# <convert mp physical: -x%>
# Converts any physical damage dealt to recover MP by x% of the damage dealt.
# Bonus converted damage rates are additive. There will be no effects if MP
# to be healed is 0 or below.
#
# <convert mp magical: +x%>
# <convert mp magical: -x%>
# Converts any magical damage dealt to recover MP by x% of the damage dealt.
# Bonus converted damage rates are additive. There will be no effects if MP
# to be healed is 0 or below.
#
# <anticonvert hp physical>
# <anticonvert hp magical>
# <anticonvert mp physical>
# <anticonvert mp magical>
# Prevents attackers from converting damage of those particular types. All
# converted recovery effects of that type will be reduced to 0.
#
# -----------------------------------------------------------------------------
# Class Notetags - These notetags go in the class notebox in the database.
# -----------------------------------------------------------------------------
# <convert hp physical: +x%>
# <convert hp physical: -x%>
# Converts any physical damage dealt to recover HP by x% of the damage dealt.
# Bonus converted damage rates are additive. There will be no effects if HP
# to be healed is 0 or below.
#
# <convert hp magical: +x%>
# <convert hp magical: -x%>
# Converts any magical damage dealt to recover HP by x% of the damage dealt.
# Bonus converted damage rates are additive. There will be no effects if HP
# to be healed is 0 or below.
#
# <convert mp physical: +x%>
# <convert mp physical: -x%>
# Converts any physical damage dealt to recover MP by x% of the damage dealt.
# Bonus converted damage rates are additive. There will be no effects if MP
# to be healed is 0 or below.
#
# <convert mp magical: +x%>
# <convert mp magical: -x%>
# Converts any magical damage dealt to recover MP by x% of the damage dealt.
# Bonus converted damage rates are additive. There will be no effects if MP
# to be healed is 0 or below.
#
# <anticonvert hp physical>
# <anticonvert hp magical>
# <anticonvert mp physical>
# <anticonvert mp magical>
# Prevents attackers from converting damage of those particular types. All
# converted recovery effects of that type will be reduced to 0.
#
# -----------------------------------------------------------------------------
# Skill Notetags - These notetags go in the skills notebox in the database.
# -----------------------------------------------------------------------------
# <no convert>
# Prevents any kind of converted damage effects from being applied when this
# skill is used.
#
# -----------------------------------------------------------------------------
# Item Notetags - These notetags go in the items notebox in the database.
# -----------------------------------------------------------------------------
# <no convert>
# Prevents any kind of converted damage effects from being applied when this
# item is used.
#
# -----------------------------------------------------------------------------
# Weapon Notetags - These notetags go in the weapons notebox in the database.
# -----------------------------------------------------------------------------
# <convert hp physical: +x%>
# <convert hp physical: -x%>
# Converts any physical damage dealt to recover HP by x% of the damage dealt.
# Bonus converted damage rates are additive. There will be no effects if HP
# to be healed is 0 or below.
#
# <convert hp magical: +x%>
# <convert hp magical: -x%>
# Converts any magical damage dealt to recover HP by x% of the damage dealt.
# Bonus converted damage rates are additive. There will be no effects if HP
# to be healed is 0 or below.
#
# <convert mp physical: +x%>
# <convert mp physical: -x%>
# Converts any physical damage dealt to recover MP by x% of the damage dealt.
# Bonus converted damage rates are additive. There will be no effects if MP
# to be healed is 0 or below.
#
# <convert mp magical: +x%>
# <convert mp magical: -x%>
# Converts any magical damage dealt to recover MP by x% of the damage dealt.
# Bonus converted damage rates are additive. There will be no effects if MP
# to be healed is 0 or below.
#
# <anticonvert hp physical>
# <anticonvert hp magical>
# <anticonvert mp physical>
# <anticonvert mp magical>
# Prevents attackers from converting damage of those particular types. All
# converted recovery effects of that type will be reduced to 0.
#
# -----------------------------------------------------------------------------
# Armour Notetags - These notetags go in the armours notebox in the database.
# -----------------------------------------------------------------------------
# <convert hp physical: +x%>
# <convert hp physical: -x%>
# Converts any physical damage dealt to recover HP by x% of the damage dealt.
# Bonus converted damage rates are additive. There will be no effects if HP
# to be healed is 0 or below.
#
# <convert hp magical: +x%>
# <convert hp magical: -x%>
# Converts any magical damage dealt to recover HP by x% of the damage dealt.
# Bonus converted damage rates are additive. There will be no effects if HP
# to be healed is 0 or below.
#
# <convert mp physical: +x%>
# <convert mp physical: -x%>
# Converts any physical damage dealt to recover MP by x% of the damage dealt.
# Bonus converted damage rates are additive. There will be no effects if MP
# to be healed is 0 or below.
#
# <convert mp magical: +x%>
# <convert mp magical: -x%>
# Converts any magical damage dealt to recover MP by x% of the damage dealt.
# Bonus converted damage rates are additive. There will be no effects if MP
# to be healed is 0 or below.
#
# <anticonvert hp physical>
# <anticonvert hp magical>
# <anticonvert mp physical>
# <anticonvert mp magical>
# Prevents attackers from converting damage of those particular types. All
# converted recovery effects of that type will be reduced to 0.
#
# -----------------------------------------------------------------------------
# Enemy Notetags - These notetags go in the enemies notebox in the database.
# -----------------------------------------------------------------------------
# <convert hp physical: +x%>
# <convert hp physical: -x%>
# Converts any physical damage dealt to recover HP by x% of the damage dealt.
# Bonus converted damage rates are additive. There will be no effects if HP
# to be healed is 0 or below.
#
# <convert hp magical: +x%>
# <convert hp magical: -x%>
# Converts any magical damage dealt to recover HP by x% of the damage dealt.
# Bonus converted damage rates are additive. There will be no effects if HP
# to be healed is 0 or below.
#
# <convert mp physical: +x%>
# <convert mp physical: -x%>
# Converts any physical damage dealt to recover MP by x% of the damage dealt.
# Bonus converted damage rates are additive. There will be no effects if MP
# to be healed is 0 or below.
#
# <convert mp magical: +x%>
# <convert mp magical: -x%>
# Converts any magical damage dealt to recover MP by x% of the damage dealt.
# Bonus converted damage rates are additive. There will be no effects if MP
# to be healed is 0 or below.
#
# <anticonvert hp physical>
# <anticonvert hp magical>
# <anticonvert mp physical>
# <anticonvert mp magical>
# Prevents attackers from converting damage of those particular types. All
# converted recovery effects of that type will be reduced to 0.
#
# -----------------------------------------------------------------------------
# State Notetags - These notetags go in the states notebox in the database.
# -----------------------------------------------------------------------------
# <convert hp physical: +x%>
# <convert hp physical: -x%>
# Converts any physical damage dealt to recover HP by x% of the damage dealt.
# Bonus converted damage rates are additive. There will be no effects if HP
# to be healed is 0 or below.
#
# <convert hp magical: +x%>
# <convert hp magical: -x%>
# Converts any magical damage dealt to recover HP by x% of the damage dealt.
# Bonus converted damage rates are additive. There will be no effects if HP
# to be healed is 0 or below.
#
# <convert mp physical: +x%>
# <convert mp physical: -x%>
# Converts any physical damage dealt to recover MP by x% of the damage dealt.
# Bonus converted damage rates are additive. There will be no effects if MP
# to be healed is 0 or below.
#
# <convert mp magical: +x%>
# <convert mp magical: -x%>
# Converts any magical damage dealt to recover MP by x% of the damage dealt.
# Bonus converted damage rates are additive. There will be no effects if MP
# to be healed is 0 or below.
#
# <anticonvert hp physical>
# <anticonvert hp magical>
# <anticonvert mp physical>
# <anticonvert mp magical>
# Prevents attackers from converting damage of those particular types. All
# converted recovery effects of that type will be reduced to 0.
#
#==============================================================================
# ▼ 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.
#
# For maximum compatibility with Yanfly Engine Ace - Ace Battle Engine, place
# this script under Ace Battle Engine.
#
#==============================================================================
module YEA
module CONVERT_DAMAGE
#=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
# - Limit Settings -
#=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
# Adjust the maximum converted damage rate for dealing damage (so that an
# attacker cannot gain huge amounts of recovery).
#=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
MAXIMUM_RATE = 1.0 # Maximum gain from dealing damage.
end # CONVERT_DAMAGE
end # YEA
#==============================================================================
# ▼ 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 BASEITEM
CONVERT_DMG = /<(?:CONVERT|convert)[ ](.*)[ ](.*):[ ]([\+\-]\d+)([%%])>/i
ANTICONVERT = /<(?:ANTI_CONVERT|anti convert|anticonvert)[ ](.*)[ ](.*)>/i
end # BASEITEM
module USABLEITEM
NO_CONVERT = /<(?:NO_CONVERT|no convert)>/i
end # USABLEITEM
end # REGEXP
end # YEA
#==============================================================================
# ■ DataManager
#==============================================================================
module DataManager
#--------------------------------------------------------------------------
# alias method: load_database
#--------------------------------------------------------------------------
class <<self; alias load_database_convertdmg load_database; end
def self.load_database
load_database_convertdmg
load_notetags_convertdmg
end
#--------------------------------------------------------------------------
# new method: load_notetags_convertdmg
#--------------------------------------------------------------------------
def self.load_notetags_convertdmg
groups = [$data_actors, $data_classes, $data_weapons, $data_armors,
$data_enemies, $data_states, $data_skills, $data_items]
for group in groups
for obj in group
next if obj.nil?
obj.load_notetags_convertdmg
end
end
end
end # DataManager
#==============================================================================
# ■ RPG::BaseItem
#==============================================================================
class RPG::BaseItem
#--------------------------------------------------------------------------
# public instance variables
#--------------------------------------------------------------------------
attr_accessor :convert_dmg
attr_accessor :anticonvert
#--------------------------------------------------------------------------
# common cache: load_notetags_convertdmg
#--------------------------------------------------------------------------
def load_notetags_convertdmg
@convert_dmg ={
:hp_physical => 0.0,
:hp_magical => 0.0,
:mp_physical => 0.0,
:mp_magical => 0.0,
} # Do not remove this.
@anticonvert = []
#---
self.note.split(/[\r\n]+/).each { |line|
case line
#---
when YEA::REGEXP::BASEITEM::CONVERT_DMG
case $1.upcase
when "HP"
case $2.upcase
when "PHYSICAL"; type = :hp_physical
when "MAGICAL"; type = :hp_magical
else; next
end
when "MP"
case $2.upcase
when "PHYSICAL"; type = :mp_physical
when "MAGICAL"; type = :mp_magical
else; next
end
else; next
end
@convert_dmg[type] = $3.to_i * 0.01
#---
when YEA::REGEXP::BASEITEM::ANTICONVERT
case $1.upcase
when "HP"
case $2.upcase
when "PHYSICAL"; type = :hp_physical
when "MAGICAL"; type = :hp_magical
else; next
end
when "MP"
case $2.upcase
when "PHYSICAL"; type = :mp_physical
when "MAGICAL"; type = :mp_magical
else; next
end
else; next
end
@anticonvert.push(type)
#---
end
} # self.note.split
#---
end
end # RPG::BaseItem
#==============================================================================
# ■ RPG::UsableItem
#==============================================================================
class RPG::UsableItem < RPG::BaseItem
#--------------------------------------------------------------------------
# public instance variables
#--------------------------------------------------------------------------
attr_accessor :no_convert
#--------------------------------------------------------------------------
# common cache: load_notetags_convertdmg
#--------------------------------------------------------------------------
def load_notetags_convertdmg
#---
self.note.split(/[\r\n]+/).each { |line|
case line
#---
when YEA::REGEXP::USABLEITEM::NO_CONVERT
@no_convert = true
#---
end
} # self.note.split
#---
end
end # RPG::UsableItem
#==============================================================================
# ■ Game_BattlerBase
#==============================================================================
class Game_BattlerBase
#--------------------------------------------------------------------------
# new method: convert_dmg_rate
#--------------------------------------------------------------------------
def convert_dmg_rate(type)
n = 0.0
if actor?
n += self.actor.convert_dmg[type]
n += self.class.convert_dmg[type]
for equip in equips
next if equip.nil?
n += equip.convert_dmg[type]
end
else
n += self.enemy.convert_dmg[type]
if $imported["YEA-Doppelganger"] && !self.class.nil?
n += self.class.convert_dmg[type]
end
end
for state in states
next if state.nil?
n += state.convert_dmg[type]
end
max_rate = YEA::CONVERT_DAMAGE::MAXIMUM_RATE
return [[n, max_rate].min, -max_rate].max
end
#--------------------------------------------------------------------------
# new method: anti_convert?
#--------------------------------------------------------------------------
def anti_convert?(type)
if actor?
return true if self.actor.anticonvert.include?(type)
return true if self.class.anticonvert.include?(type)
for equip in equips
next if equip.nil?
return true if equip.anticonvert.include?(type)
end
else
return true if self.enemy.anticonvert.include?(type)
end
for state in states
next if state.nil?
return true if state.anticonvert.include?(type)
end
return false
end
end # Game_BattlerBase
#==============================================================================
# ■ Game_Battler
#==============================================================================
class Game_Battler < Game_BattlerBase
#--------------------------------------------------------------------------
# alias method: execute_damage
#--------------------------------------------------------------------------
alias game_battler_execute_damage_convertdmg execute_damage
def execute_damage(user)
apply_vampire_effects(user)
game_battler_execute_damage_convertdmg(user)
end
#--------------------------------------------------------------------------
# new method: apply_vampire_effect
#--------------------------------------------------------------------------
def apply_vampire_effects(user)
return unless $game_party.in_battle
return unless @result.hp_damage > 0 || @result.mp_damage > 0
return if user.current_action.nil?
action = user.current_action.item
return if action.no_convert
apply_convert_physical_effect(user) if action.physical?
apply_convert_magical_effect(user) if action.magical?
end
#--------------------------------------------------------------------------
# new method: apply_convert_physical_effect
#--------------------------------------------------------------------------
def apply_convert_physical_effect(user)
hp_rate = user.convert_dmg_rate(:hp_physical)
hp_rate = 0 if anti_convert?(:hp_physical)
hp_healed = (@result.hp_damage * hp_rate).to_i
mp_rate = user.convert_dmg_rate(:mp_physical)
mp_rate = 0 if anti_convert?(:mp_physical)
mp_healed = (@result.mp_damage * mp_rate).to_i
if hp_healed != 0
user.hp += hp_healed
make_ace_battle_engine_convert_hp_popup(user, hp_healed)
end
if mp_healed != 0
user.mp += mp_healed
make_ace_battle_engine_convert_mp_popup(user, mp_healed)
end
end
#--------------------------------------------------------------------------
# new method: apply_convert_magical_effect
#--------------------------------------------------------------------------
def apply_convert_magical_effect(user)
hp_rate = user.convert_dmg_rate(:hp_magical)
hp_rate = 0 if anti_convert?(:hp_magical)
hp_healed = (@result.hp_damage * hp_rate).to_i
mp_rate = user.convert_dmg_rate(:mp_magical)
mp_rate = 0 if anti_convert?(:mp_magical)
mp_healed = (@result.mp_damage * mp_rate).to_i
if hp_healed != 0
user.hp += hp_healed
make_ace_battle_engine_convert_hp_popup(user, hp_healed)
end
if mp_healed != 0
user.mp += mp_healed
make_ace_battle_engine_convert_mp_popup(user, mp_healed)
end
end
#--------------------------------------------------------------------------
# new method: make_ace_battle_engine_convert_hp_popup
#--------------------------------------------------------------------------
def make_ace_battle_engine_convert_hp_popup(user, hp_healed)
return unless $imported["YEA-BattleEngine"]
setting = hp_healed > 0 ? :hp_heal : :hp_dmg
rules = hp_healed > 0 ? "HP_HEAL" : "HP_DMG"
value = hp_healed.abs
text = sprintf(YEA::BATTLE::POPUP_SETTINGS[setting], value.group)
user.create_popup(text, rules)
end
#--------------------------------------------------------------------------
# new method: make_ace_battle_engine_convert_mp_popup
#--------------------------------------------------------------------------
def make_ace_battle_engine_convert_mp_popup(user, mp_healed)
return unless $imported["YEA-BattleEngine"]
setting = mp_healed > 0 ? :mp_heal : :mp_dmg
rules = mp_healed > 0 ? "MP_HEAL" : "MP_DMG"
value = mp_healed.abs
text = sprintf(YEA::BATTLE::POPUP_SETTINGS[setting], value.group)
user.create_popup(text, rules)
end
end # Game_Battler
#==============================================================================
#
# ▼ End of File
#
#==============================================================================