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
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
| #========================================
# ** Game_Battler
#------------------------------------------------------------------------------
# This class deals with battlers. It's used as a superclass of the Game_Actor
# and Game_Enemy classes.
#Recalcule des Formules de combat par Monos.
#Coups simple: Les points de dégats sont: Attaque - Defense.
#Objet/Compétence: Base domage de l'objet/compétence pour les points dégats.
#Ensuite suivant les paramètres des pourcentages: Force-Defense pour les sort physique
#Intelligence - Intelligence pour les sorts "magique"
#=============================================
class Game_Battler
#--------------------------------------------------------------------------
# * Public Instance Variables
#--------------------------------------------------------------------------
attr_reader :battler_name # battle graphic filename
attr_reader :battler_hue # battle graphic hue
attr_reader :hp # HP
attr_reader :mp # MP
attr_reader :action # battle action
attr_accessor :hidden # hidden flag
attr_accessor :immortal # immortal flag
attr_accessor :animation_id # animation ID
attr_accessor :animation_mirror # animation flip horizontal flag
attr_accessor :white_flash # white flash flag
attr_accessor :blink # blink flag
attr_accessor :collapse # collapse flag
attr_reader :skipped # action results: skipped flag
attr_reader :missed # action results: missed flag
attr_reader :evaded # action results: evaded flag
attr_reader :critical # action results: critical flag
attr_reader :absorbed # action results: absorbed flag
attr_reader :hp_damage # action results: HP damage
attr_reader :mp_damage # action results: MP damage
#--------------------------------------------------------------------------
# * Object Initialization
#--------------------------------------------------------------------------
def initialize
@battler_name = ""
@battler_hue = 0
@hp = 0
@mp = 0
@action = Game_BattleAction.new(self)
@states = [] # States (ID array)
@state_turns = {} # Remaining turns for states (Hash)
@hidden = false
@immortal = false
clear_extra_values
clear_sprite_effects
clear_action_results
end
#--------------------------------------------------------------------------
# * Clear Values Added to Parameter
#--------------------------------------------------------------------------
def clear_extra_values
@maxhp_plus = 0
@maxmp_plus = 0
@atk_plus = 0
@def_plus = 0
@spi_plus = 0
@agi_plus = 0
end
#--------------------------------------------------------------------------
# * Clear Variable Used for Sprite Communication
#--------------------------------------------------------------------------
def clear_sprite_effects
@animation_id = 0
@animation_mirror = false
@white_flash = false
@blink = false
@collapse = false
end
#--------------------------------------------------------------------------
# * Clear Variable for Storing Action Results
#--------------------------------------------------------------------------
def clear_action_results
@skipped = false
@missed = false
@evaded = false
@critical = false
@absorbed = false
@hp_damage = 0
@mp_damage = 0
@added_states = [] # Added states (ID array)
@removed_states = [] # Removed states (ID array)
@remained_states = [] # Unchanged states (ID array)
end
#--------------------------------------------------------------------------
# * Get Current States as an Object Array
#--------------------------------------------------------------------------
def states
result = []
for i in @states
result.push($data_states[i])
end
return result
end
#--------------------------------------------------------------------------
# * Get the states that were added due to the previous action
#--------------------------------------------------------------------------
def added_states
result = []
for i in @added_states
result.push($data_states[i])
end
return result
end
#--------------------------------------------------------------------------
# * Get the states that were removed due to the previous action
#--------------------------------------------------------------------------
def removed_states
result = []
for i in @removed_states
result.push($data_states[i])
end
return result
end
#--------------------------------------------------------------------------
# * Get the states that remained the same after the previous action
# Used, for example, when someone tries to put to sleep a character
# who is already sleeping.
#--------------------------------------------------------------------------
def remained_states
result = []
for i in @remained_states
result.push($data_states[i])
end
return result
end
#--------------------------------------------------------------------------
# * Determine whether or not there was some effect on states by the
# previous action
#--------------------------------------------------------------------------
def states_active?
return true unless @added_states.empty?
return true unless @removed_states.empty?
return true unless @remained_states.empty?
return false
end
#--------------------------------------------------------------------------
# * Get Maximum HP Limit
#--------------------------------------------------------------------------
def maxhp_limit
return 999999
end
#--------------------------------------------------------------------------
# * Get Maximum HP
#--------------------------------------------------------------------------
def maxhp
return [[base_maxhp + @maxhp_plus, 1].max, maxhp_limit].min
end
#--------------------------------------------------------------------------
# * Get Maximum MP
#--------------------------------------------------------------------------
def maxmp
return [[base_maxmp + @maxmp_plus, 0].max, 9999].min
end
#--------------------------------------------------------------------------
# * Get Attack
#--------------------------------------------------------------------------
def atk
n = [[base_atk + @atk_plus, 1].max, 999].min
for state in states do n *= state.atk_rate / 100.0 end
n = [[Integer(n), 1].max, 999].min
return n
end
#--------------------------------------------------------------------------
# * Get Defense
#--------------------------------------------------------------------------
def def
n = [[base_def + @def_plus, 1].max, 999].min
for state in states do n *= state.def_rate / 100.0 end
n = [[Integer(n), 1].max, 999].min
return n
end
#--------------------------------------------------------------------------
# * Get Spirit
#--------------------------------------------------------------------------
def spi
n = [[base_spi + @spi_plus, 1].max, 999].min
for state in states do n *= state.spi_rate / 100.0 end
n = [[Integer(n), 1].max, 999].min
return n
end
#--------------------------------------------------------------------------
# * Get Agility
#--------------------------------------------------------------------------
def agi
n = [[base_agi + @agi_plus, 1].max, 999].min
for state in states do n *= state.agi_rate / 100.0 end
n = [[Integer(n), 1].max, 999].min
return n
end
#--------------------------------------------------------------------------
# * Get [Super Guard] Option
#--------------------------------------------------------------------------
def super_guard
return false
end
#--------------------------------------------------------------------------
# * Get [Fast Attack] weapon option
#--------------------------------------------------------------------------
def fast_attack
return false
end
#--------------------------------------------------------------------------
# * Get [Dual Attack] weapon option
#--------------------------------------------------------------------------
def dual_attack
return false
end
#--------------------------------------------------------------------------
# * Get [Prevent Critical] armor option
#--------------------------------------------------------------------------
def prevent_critical
return false
end
#--------------------------------------------------------------------------
# * Get [Half MP Cost] armor option
#--------------------------------------------------------------------------
def half_mp_cost
return false
end
#--------------------------------------------------------------------------
# * Set Maximum HP
# new_maxhp : new maximum HP
#--------------------------------------------------------------------------
def maxhp=(new_maxhp)
@maxhp_plus += new_maxhp - self.maxhp
@maxhp_plus = [[@maxhp_plus, -9999].max, 9999].min
@hp = [@hp, self.maxhp].min
end
#--------------------------------------------------------------------------
# * Set Maximum MP
# new_maxmp : new maximum MP
#--------------------------------------------------------------------------
def maxmp=(new_maxmp)
@maxmp_plus += new_maxmp - self.maxmp
@maxmp_plus = [[@maxmp_plus, -9999].max, 9999].min
@mp = [@mp, self.maxmp].min
end
#--------------------------------------------------------------------------
# * Set Attack
# new_atk : new attack
#--------------------------------------------------------------------------
def atk=(new_atk)
@atk_plus += new_atk - self.atk
@atk_plus = [[@atk_plus, -999].max, 999].min
end
#--------------------------------------------------------------------------
# * Set Defense
# new_def : new defense
#--------------------------------------------------------------------------
def def=(new_def)
@def_plus += new_def - self.def
@def_plus = [[@def_plus, -999].max, 999].min
end
#--------------------------------------------------------------------------
# * Set Spirit
# new_spi : new spirit
#--------------------------------------------------------------------------
def spi=(new_spi)
@spi_plus += new_spi - self.spi
@spi_plus = [[@spi_plus, -999].max, 999].min
end
#--------------------------------------------------------------------------
# * Set Agility
# new_agi : new agility
#--------------------------------------------------------------------------
def agi=(new_agi)
@agi_plus += new_agi - self.agi
@agi_plus = [[@agi_plus, -999].max, 999].min
end
#--------------------------------------------------------------------------
# * Change HP
# hp : new HP
#--------------------------------------------------------------------------
def hp=(hp)
@hp = [[hp, maxhp].min, 0].max
if @hp == 0 and not state?(1) and not @immortal
add_state(1) # Add incapacitated (state #1)
@added_states.push(1)
elsif @hp > 0 and state?(1)
remove_state(1) # Remove incapacitated (state #1)
@removed_states.push(1)
end
end
#--------------------------------------------------------------------------
# * Change MP
# mp : new MP
#--------------------------------------------------------------------------
def mp=(mp)
@mp = [[mp, maxmp].min, 0].max
end
#--------------------------------------------------------------------------
# * Recover All
#--------------------------------------------------------------------------
def recover_all
@hp = maxhp
@mp = maxmp
for i in @states.clone do remove_state(i) end
end
#--------------------------------------------------------------------------
# * Determine Incapacitation
#--------------------------------------------------------------------------
def dead?
return (not @hidden and @hp == 0 and not @immortal)
end
#--------------------------------------------------------------------------
# * Determine Existence
#--------------------------------------------------------------------------
def exist?
return (not @hidden and not dead?)
end
#--------------------------------------------------------------------------
# * Determine if Command is Inputable
#--------------------------------------------------------------------------
def inputable?
return (not @hidden and restriction <= 1)
end
#--------------------------------------------------------------------------
# * Determine if Action is Possible
#--------------------------------------------------------------------------
def movable?
return (not @hidden and restriction < 4)
end
#--------------------------------------------------------------------------
# * Determine if Attack is Parriable
#--------------------------------------------------------------------------
def parriable?
return (not @hidden and restriction < 5)
end
#--------------------------------------------------------------------------
# * Determine if Character is Silenced
#--------------------------------------------------------------------------
def silent?
return (not @hidden and restriction == 1)
end
#--------------------------------------------------------------------------
# * Determine if Character is in Berserker State
#--------------------------------------------------------------------------
def berserker?
return (not @hidden and restriction == 2)
end
#--------------------------------------------------------------------------
# * Determine if Character is Confused
#--------------------------------------------------------------------------
def confusion?
return (not @hidden and restriction == 3)
end
#--------------------------------------------------------------------------
# * Determine if Guarding
#--------------------------------------------------------------------------
def guarding?
return @action.guard?
end
#--------------------------------------------------------------------------
# * Get Element Change Value
# element_id : element ID
#--------------------------------------------------------------------------
def element_rate(element_id)
return 100
end
#--------------------------------------------------------------------------
# * Get Added State Success Rate
#--------------------------------------------------------------------------
def state_probability(state_id)
return 0
end
#--------------------------------------------------------------------------
# * Determine if State is Resisted
# state_id : state ID
#--------------------------------------------------------------------------
def state_resist?(state_id)
return false
end
#--------------------------------------------------------------------------
# * Get Normal Attack Element
#--------------------------------------------------------------------------
def element_set
return []
end
#--------------------------------------------------------------------------
# * Get Normal Attack State Change (+)
#--------------------------------------------------------------------------
def plus_state_set
return []
end
#--------------------------------------------------------------------------
# * Get Normal Attack State Change (-)
#--------------------------------------------------------------------------
def minus_state_set
return []
end
#--------------------------------------------------------------------------
# * Check State
# state_id : state ID
# Return true if the applicable state is added.
#--------------------------------------------------------------------------
def state?(state_id)
return @states.include?(state_id)
end
#--------------------------------------------------------------------------
# * Determine if a State is Full or Not
# state_id : state ID
# Return true if the number of turns the state is to be sustained
# equals the minimum number of turns after which the state will
# naturally be removed.
#--------------------------------------------------------------------------
def state_full?(state_id)
return false unless state?(state_id)
return @state_turns[state_id] == $data_states[state_id].hold_turn
end
#--------------------------------------------------------------------------
# * Determine if a State Should be Ignored
# state_id : state ID
# Returns true when the following conditions are fulfilled.
# * If State A which is to be added, is included in State B's
# [States to Cancel] list.
# * If State B is not included in the [States to Cancel] list for
# the new State A.
# These conditions would apply when, for example, trying to poison a
# character that is already incapacitated. It does not apply in cases
# such as applying ATK up while ATK down is already in effect.
#--------------------------------------------------------------------------
def state_ignore?(state_id)
for state in states
if state.state_set.include?(state_id) and
not $data_states[state_id].state_set.include?(state.id)
return true
end
end
return false
end
#--------------------------------------------------------------------------
# * Determine if it is a state that should be offset
# state_id : state ID
# Returns true when the following conditions are fulfilled.
# * The [Offset by Opp.] option is enabled for the new state.
# * The [States to Cancel] list of the new state to be added
# contains at least one of the current states.
# This would apply when, for example, ATK up is applied while ATK down
# is already in effect.
#--------------------------------------------------------------------------
def state_offset?(state_id)
return false unless $data_states[state_id].offset_by_opposite
for i in @states
return true if $data_states[state_id].state_set.include?(i)
end
return false
end
#--------------------------------------------------------------------------
# * Sorting States
# Sort the content of the @states array, with higher priority states
# coming first.
#--------------------------------------------------------------------------
def sort_states
@states.sort! do |a, b|
state_a = $data_states[a]
state_b = $data_states[b]
if state_a.priority != state_b.priority
state_b.priority <=> state_a.priority
else
a <=> b
end
end
end
#--------------------------------------------------------------------------
# * Add State
# state_id : state ID
#--------------------------------------------------------------------------
def add_state(state_id)
state = $data_states[state_id] # Get state data
return if state == nil # Is data invalid?
return if state_ignore?(state_id) # Is it a state should be ignored?
unless state?(state_id) # Is this state not added?
unless state_offset?(state_id) # Is it a state should be offset?
@states.push(state_id) # Add the ID to the @states array
end
if state_id == 1 # If it is incapacitated (state 1)
@hp = 0 # Change HP to 0
end
unless inputable? # If the character cannot act
@action.clear # Clear battle actions
end
for i in state.state_set # Take the [States to Cancel]
remove_state(i) # And actually remove them
@removed_states.delete(i) # It will not be displayed
end
sort_states # Sort states with priority
end
@state_turns[state_id] = state.hold_turn # Set the number of turns
end
#--------------------------------------------------------------------------
# * Remove State
# state_id : state ID
#--------------------------------------------------------------------------
def remove_state(state_id)
return unless state?(state_id) # Is this state not added?
if state_id == 1 and @hp == 0 # If it is incapacitated (state 1)
@hp = 1 # Change HP to 1
end
@states.delete(state_id) # Remove the ID from the @states
@state_turns.delete(state_id) # Remove from the @state_turns
end
#--------------------------------------------------------------------------
# * Get Restriction
# Get the largest restriction from the currently added states.
#--------------------------------------------------------------------------
def restriction
restriction_max = 0
for state in states
if state.restriction >= restriction_max
restriction_max = state.restriction
end
end
return restriction_max
end
#--------------------------------------------------------------------------
# * Determine [Slip Damage] States
#--------------------------------------------------------------------------
def slip_damage?
for state in states
return true if state.slip_damage
end
return false
end
#--------------------------------------------------------------------------
# * Determine if the state is [Reduced hit ratio]
#--------------------------------------------------------------------------
def reduce_hit_ratio?
for state in states
return true if state.reduce_hit_ratio
end
return false
end
#--------------------------------------------------------------------------
# * Get Most Important State Continuation Message
#--------------------------------------------------------------------------
def most_important_state_text
for state in states
return state.message3 unless state.message3.empty?
end
return ""
end
#--------------------------------------------------------------------------
# * Remove Battle States (called when battle ends)
#--------------------------------------------------------------------------
def remove_states_battle
for state in states
remove_state(state.id) if state.battle_only
end
end
#--------------------------------------------------------------------------
# * Natural Removal of States (called up each turn)
#--------------------------------------------------------------------------
def remove_states_auto
clear_action_results
for i in @state_turns.keys.clone
if @state_turns[i] > 0
@state_turns[i] -= 1
elsif rand(100) < $data_states[i].auto_release_prob
remove_state(i)
@removed_states.push(i)
end
end
end
#--------------------------------------------------------------------------
# * State Removal due to Damage (called each time damage is caused)
#--------------------------------------------------------------------------
def remove_states_shock
for state in states
if state.release_by_damage
remove_state(state.id)
@removed_states.push(state.id)
end
end
end
#--------------------------------------------------------------------------
# * Calculation of MP Consumed for Skills
# skill : skill
#--------------------------------------------------------------------------
def calc_mp_cost(skill)
if half_mp_cost
return skill.mp_cost / 2
else
return skill.mp_cost
end
end
#--------------------------------------------------------------------------
# * Determine Usable Skills
# skill : skill
#--------------------------------------------------------------------------
def skill_can_use?(skill)
return false unless skill.is_a?(RPG::Skill)
return false unless movable?
return false if silent? and skill.spi_f > 0
return false if calc_mp_cost(skill) > mp
if $game_temp.in_battle
return skill.battle_ok?
else
return skill.menu_ok?
end
end
#--------------------------------------------------------------------------
# * Calculation of Final Hit Ratio
# user : Attacker, or user of skill or item
# obj : Skill or item (for normal attacks, this is nil)
#--------------------------------------------------------------------------
def calc_hit(user, obj = nil)
if obj == nil # for a normal attack
hit = user.hit # get hit ratio
physical = true
elsif obj.is_a?(RPG::Skill) # for a skill
hit = obj.hit # get success rate
physical = obj.physical_attack
else # for an item
hit = 100 # the hit ratio is made 100%
physical = obj.physical_attack
end
if physical # for a physical attack
hit /= 4 if user.reduce_hit_ratio? # when the user is blinded
end
return hit
end
#--------------------------------------------------------------------------
# * Calculate Final Evasion Rate
# user : Attacker, or user of skill or item
# obj : Skill or item (for normal attacks, this is nil)
#--------------------------------------------------------------------------
def calc_eva(user, obj = nil)
eva = self.eva
unless obj == nil # if it is a skill or an item
eva = 0 unless obj.physical_attack # 0% if not a physical attack
end
unless parriable? # If not parriable
eva = 0 # 0%
end
return eva
end
#--------------------------------------------------------------------------
# * Calculation of Damage From Normal Attack
# attacker : Attacker
# The results are substituted for @hp_damage
#--------------------------------------------------------------------------
def make_attack_damage_value(attacker)
damage = attacker.atk - self.def # base calculation
damage = 0 if damage < 0 # if negative, make 0
damage *= elements_max_rate(attacker.element_set) # elemental adjustment
damage /= 100
if damage == 0 # if damage is 0,
damage = rand(2) # half of the time, 1 dmg
elsif damage > 0 # a positive number?
@critical = (rand(100) < attacker.cri) # critical hit?
@critical = false if prevent_critical # criticals prevented?
damage *= 2 if @critical # critical adjustment
end
damage = apply_variance(damage, 20) # variance
damage = apply_guard(damage) # guard adjustment
@hp_damage = damage # damage HP
end
#--------------------------------------------------------------------------
# * Calculation of Damage Caused by Skills or Items
# user : User of skill or item
# obj : Skill or item (for normal attacks, this is nil)
# The results are substituted for @hp_damage or @mp_damage.
#--------------------------------------------------------------------------
def make_obj_damage_value(user, obj)
damage = obj.base_damage # get base damage
if damage > 0 # a positive number?
damage += user.atk * obj.atk_f / 100 # Attack F of the user
damage += user.spi * obj.spi_f / 100 # Spirit F of the user
unless obj.ignore_defense # Except for ignore defense
damage -= self.def * obj.atk_f / 100 # Attack F of the target
damage -= self.spi * obj.spi_f / 100 # Spirit F of the target
end
damage = 0 if damage < 0 # If negative, make 0
elsif damage < 0 # a negative number?
damage -= user.atk * obj.atk_f / 100 # Attack F of the user
damage -= user.spi * obj.spi_f / 100 # Spirit F of the user
end
damage *= elements_max_rate(obj.element_set) # elemental adjustment
damage /= 100
damage = apply_variance(damage, obj.variance) # variance
damage = apply_guard(damage) # guard adjustment
if obj.damage_to_mp
@mp_damage = damage # damage MP
else
@hp_damage = damage # damage HP
end
end
#--------------------------------------------------------------------------
# * Calculation of Absorb Effect
# user : User of skill or item
# obj : Skill or item (for normal attacks, this is nil)
# @hp_damage and @mp_damage must be calculated before this is called.
#--------------------------------------------------------------------------
def make_obj_absorb_effect(user, obj)
if obj.absorb_damage # if absorbing damage
@hp_damage = [self.hp, @hp_damage].min # HP damage range adjustment
@mp_damage = [self.mp, @mp_damage].min # MP damage range adjustment
if @hp_damage > 0 or @mp_damage > 0 # a positive number?
@absorbed = true # turn the absorb flag ON
end
end
end
#--------------------------------------------------------------------------
# * Calculating HP Recovery Amount From an Item
#--------------------------------------------------------------------------
def calc_hp_recovery(user, item)
result = maxhp * item.hp_recovery_rate / 100 + item.hp_recovery
result *= 2 if user.pharmacology # Pharmacology doubles the effect
return result
end
#--------------------------------------------------------------------------
# * Calculating MP Recovery Amount From an Item
#--------------------------------------------------------------------------
def calc_mp_recovery(user, item)
result = maxmp * item.mp_recovery_rate / 100 + item.mp_recovery
result *= 2 if user.pharmacology # Pharmacology doubles the effect
return result
end
#--------------------------------------------------------------------------
# * Get Maximum Elemental Adjustment Amount
# element_set : Elemental alignment
# Returns the most effective adjustment of all elemental alignments.
#--------------------------------------------------------------------------
def elements_max_rate(element_set)
return 100 if element_set.empty? # If there is no element
rate_list = []
for i in element_set
rate_list.push(element_rate(i))
end
return rate_list.max
end
#--------------------------------------------------------------------------
# * Applying Variance
# damage : Damage
# variance : Degree of variance
#--------------------------------------------------------------------------
def apply_variance(damage, variance)
if damage != 0 # If damage is not 0
amp = [damage.abs * variance / 100, 0].max # Calculate range
damage += rand(amp+1) + rand(amp+1) - amp # Execute variance
end
return damage
end
#--------------------------------------------------------------------------
# * Applying Guard Adjustment
# damage : Damage
#--------------------------------------------------------------------------
def apply_guard(damage)
if damage > 0 and guarding? # Determine if guarding
damage /= super_guard ? 4 : 2 # Reduce damage
end
return damage
end
#--------------------------------------------------------------------------
# * Damage Reflection
# user : User of skill or item
# @hp_damage, @mp_damage, or @absorbed must be calculated before this
# method is called.
#--------------------------------------------------------------------------
def execute_damage(user)
if @hp_damage > 0 # Damage is a positive number
remove_states_shock # Remove state due to attack
end
self.hp -= @hp_damage
self.mp -= @mp_damage
if @absorbed # If absorbing
user.hp += @hp_damage
user.mp += @mp_damage
end
end
#--------------------------------------------------------------------------
# * Apply State Changes
# obj : Skill, item, or attacker
#--------------------------------------------------------------------------
def apply_state_changes(obj)
plus = obj.plus_state_set # get state change (+)
minus = obj.minus_state_set # get state change (-)
for i in plus # state change (+)
next if state_resist?(i) # is it resisted?
next if dead? # are they incapacitated?
next if i == 1 and @immortal # are they immortal?
if state?(i) # is it already applied?
@remained_states.push(i) # record unchanged states
next
end
if rand(100) < state_probability(i) # determine probability
add_state(i) # add state
@added_states.push(i) # record added states
end
end
for i in minus # state change (-)
next unless state?(i) # is the state not applied?
remove_state(i) # remove state
@removed_states.push(i) # record removed states
end
for i in @added_states & @removed_states # if there are any states in
@added_states.delete(i) # both added and removed
@removed_states.delete(i) # sections, delete them both
end
end
#--------------------------------------------------------------------------
# * Determine Whether to Apply a Normal Attack
# attacker : Attacker
#--------------------------------------------------------------------------
def attack_effective?(attacker)
if dead?
return false
end
return true
end
#--------------------------------------------------------------------------
# * Apply Normal Attack Effects
# attacker : Attacker
#--------------------------------------------------------------------------
def attack_effect(attacker)
clear_action_results
unless attack_effective?(attacker)
@skipped = true
return
end
if rand(100) >= calc_hit(attacker) # determine hit ratio
@missed = true
return
end
if rand(100) < calc_eva(attacker) # determine evasion rate
@evaded = true
return
end
make_attack_damage_value(attacker) # damage calculation
execute_damage(attacker) # damage reflection
if @hp_damage == 0 # physical no damage?
return
end
apply_state_changes(attacker) # state change
end
#--------------------------------------------------------------------------
# * Determine if a Skill can be Applied
# user : Skill user
# skill : Skill
#--------------------------------------------------------------------------
def skill_effective?(user, skill)
if skill.for_dead_friend? != dead?
return false
end
if not $game_temp.in_battle and skill.for_friend?
return skill_test(user, skill)
end
return true
end
#--------------------------------------------------------------------------
# * Skill Application Test
# user : Skill user
# skill : Skill
# Used to determine, for example, if a character is already fully healed
# and so cannot recover anymore.
#--------------------------------------------------------------------------
def skill_test(user, skill)
tester = self.clone
tester.make_obj_damage_value(user, skill)
tester.apply_state_changes(skill)
if tester.hp_damage < 0
return true if tester.hp < tester.maxhp
end
if tester.mp_damage < 0
return true if tester.mp < tester.maxmp
end
return true unless tester.added_states.empty?
return true unless tester.removed_states.empty?
return false
end
#--------------------------------------------------------------------------
# * Apply Skill Effects
# user : Skill user
# skill : skill
#--------------------------------------------------------------------------
def skill_effect(user, skill)
clear_action_results
unless skill_effective?(user, skill)
@skipped = true
return
end
if rand(100) >= calc_hit(user, skill) # determine hit ratio
@missed = true
return
end
if rand(100) < calc_eva(user, skill) # determine evasion rate
@evaded = true
return
end
make_obj_damage_value(user, skill) # calculate damage
make_obj_absorb_effect(user, skill) # calculate absorption effect
execute_damage(user) # damage reflection
if skill.physical_attack and @hp_damage == 0 # physical no damage?
return
end
apply_state_changes(skill) # state change
end
#--------------------------------------------------------------------------
# * Determine if an Item can be Used
# user : Item user
# item : item
#--------------------------------------------------------------------------
def item_effective?(user, item)
if item.for_dead_friend? != dead?
return false
end
if not $game_temp.in_battle and item.for_friend?
return item_test(user, item)
end
return true
end
#--------------------------------------------------------------------------
# * Item Application Test
# user : Item user
# item : item
# Used to determine, for example, if a character is already fully healed
# and so cannot recover anymore.
#--------------------------------------------------------------------------
def item_test(user, item)
tester = self.clone
tester.make_obj_damage_value(user, item)
tester.apply_state_changes(item)
if tester.hp_damage < 0 or tester.calc_hp_recovery(user, item) > 0
return true if tester.hp < tester.maxhp
end
if tester.mp_damage < 0 or tester.calc_mp_recovery(user, item) > 0
return true if tester.mp < tester.maxmp
end
return true unless tester.added_states.empty?
return true unless tester.removed_states.empty?
return true if item.parameter_type > 0
return false
end
#--------------------------------------------------------------------------
# * Apply Item Effects
# user : Item user
# item : item
#--------------------------------------------------------------------------
def item_effect(user, item)
clear_action_results
unless item_effective?(user, item)
@skipped = true
return
end
if rand(100) >= calc_hit(user, item) # determine hit ratio
@missed = true
return
end
if rand(100) < calc_eva(user, item) # determine evasion rate
@evaded = true
return
end
hp_recovery = calc_hp_recovery(user, item) # calc HP recovery amount
mp_recovery = calc_mp_recovery(user, item) # calc MP recovery amount
make_obj_damage_value(user, item) # damage calculation
@hp_damage -= hp_recovery # subtract HP recovery amount
@mp_damage -= mp_recovery # subtract MP recovery amount
make_obj_absorb_effect(user, item) # calculate absorption effect
execute_damage(user) # damage reflection
item_growth_effect(user, item) # apply growth effect
if item.physical_attack and @hp_damage == 0 # physical no damage?
return
end
apply_state_changes(item) # state change
end
#--------------------------------------------------------------------------
# * Item Growth Effect Application
# user : Item user
# item : item
#--------------------------------------------------------------------------
def item_growth_effect(user, item)
if item.parameter_type > 0 and item.parameter_points != 0
case item.parameter_type
when 1 # Maximum HP
@maxhp_plus += item.parameter_points
when 2 # Maximum MP
@maxmp_plus += item.parameter_points
when 3 # Attack
@atk_plus += item.parameter_points
when 4 # Defense
@def_plus += item.parameter_points
when 5 # Spirit
@spi_plus += item.parameter_points
when 6 # Agility
@agi_plus += item.parameter_points
end
end
end
#--------------------------------------------------------------------------
# * Application of Slip Damage Effects
#--------------------------------------------------------------------------
def slip_damage_effect
if slip_damage? and @hp > 0
@hp_damage = apply_variance(maxhp / 10, 10)
@hp_damage = @hp - 1 if @hp_damage >= @hp
self.hp -= @hp_damage
end
end
end |