Class: Game_Battler

Inherits:
Game_BattlerBase show all
Defined in:
Game_Battler.rb

Overview

** Game_Battler


A battler class with methods for sprites and actions added. This class

is used as a super class of the Game_Actor class and Game_Enemy class.

Direct Known Subclasses

Game_Actor, Game_Enemy

Constant Summary

EFFECT_RECOVER_HP =

  • Constants (Effects)


11
EFFECT_RECOVER_MP =

HP Recovery

12
EFFECT_GAIN_TP =

MP Recovery

13
EFFECT_ADD_STATE =

TP Gain

21
EFFECT_REMOVE_STATE =

Add State

22
EFFECT_ADD_BUFF =

Remove State

31
EFFECT_ADD_DEBUFF =

Add Buff

32
EFFECT_REMOVE_BUFF =

Add Debuff

33
EFFECT_REMOVE_DEBUFF =

Remove Buff

34
EFFECT_SPECIAL =

Remove Debuff

41
EFFECT_GROW =

Special Effect

42
EFFECT_LEARN_SKILL =

Raise Parameter

43
EFFECT_COMMON_EVENT =

Learn Skill

44
SPECIAL_EFFECT_ESCAPE =

  • Constants (Special Effects)


0

Constants inherited from Game_BattlerBase

Game_BattlerBase::FEATURE_ACTION_PLUS, Game_BattlerBase::FEATURE_ATK_ELEMENT, Game_BattlerBase::FEATURE_ATK_SPEED, Game_BattlerBase::FEATURE_ATK_STATE, Game_BattlerBase::FEATURE_ATK_TIMES, Game_BattlerBase::FEATURE_COLLAPSE_TYPE, Game_BattlerBase::FEATURE_DEBUFF_RATE, Game_BattlerBase::FEATURE_ELEMENT_RATE, Game_BattlerBase::FEATURE_EQUIP_ATYPE, Game_BattlerBase::FEATURE_EQUIP_FIX, Game_BattlerBase::FEATURE_EQUIP_SEAL, Game_BattlerBase::FEATURE_EQUIP_WTYPE, Game_BattlerBase::FEATURE_PARAM, Game_BattlerBase::FEATURE_PARTY_ABILITY, Game_BattlerBase::FEATURE_SKILL_ADD, Game_BattlerBase::FEATURE_SKILL_SEAL, Game_BattlerBase::FEATURE_SLOT_TYPE, Game_BattlerBase::FEATURE_SPARAM, Game_BattlerBase::FEATURE_SPECIAL_FLAG, Game_BattlerBase::FEATURE_STATE_RATE, Game_BattlerBase::FEATURE_STATE_RESIST, Game_BattlerBase::FEATURE_STYPE_ADD, Game_BattlerBase::FEATURE_STYPE_SEAL, Game_BattlerBase::FEATURE_XPARAM, Game_BattlerBase::FLAG_ID_AUTO_BATTLE, Game_BattlerBase::FLAG_ID_GUARD, Game_BattlerBase::FLAG_ID_PRESERVE_TP, Game_BattlerBase::FLAG_ID_SUBSTITUTE, Game_BattlerBase::ICON_BUFF_START, Game_BattlerBase::ICON_DEBUFF_START

Instance Attribute Summary (collapse)

Attributes inherited from Game_BattlerBase

#hp, #mp, #tp

Instance Method Summary (collapse)

Methods inherited from Game_BattlerBase

#action_plus_set, #actor?, #add_param, #added_skill_types, #added_skills, #agi, #alive?, #all_features, #appear, #atk, #atk_elements, #atk_speed, #atk_states, #atk_states_rate, #atk_times_add, #attack_skill_id, #attack_usable?, #auto_battle?, #buff_icon_index, #buff_icons, #cev, #change_hp, #clear_buffs, #clear_param_plus, #cnt, #collapse_type, #confusion?, #confusion_level, #cri, #dead?, #death_state?, #death_state_id, #debuff_rate, #def, #dual_wield?, #element_rate, #enemy?, #equip_atype_ok?, #equip_type_fixed?, #equip_type_sealed?, #equip_wtype_ok?, #equippable?, #erase_state, #eva, #exist?, #exr, #fdr, #feature_objects, #features, #features_pi, #features_set, #features_sum, #features_sum_all, #features_with_id, #grd, #guard?, #guard_skill_id, #guard_usable?, #hidden?, #hide, #hit, #hp_rate, #hrg, #inputable?, #item_conditions_met?, #luk, #mat, #max_tp, #mcr, #mdf, #mdr, #mev, #mhp, #mmp, #most_important_state_text, #movable?, #mp_rate, #mrf, #mrg, #normal?, #occasion_ok?, #param, #param_base, #param_buff_rate, #param_max, #param_min, #param_plus, #param_rate, #party_ability, #pay_skill_cost, #pdr, #pha, #preserve_tp?, #rec, #recover_all, #refresh, #restriction, #skill_conditions_met?, #skill_cost_payable?, #skill_mp_cost, #skill_sealed?, #skill_tp_cost, #skill_type_sealed?, #skill_wtype_ok?, #slot_type, #sort_states, #sparam, #special_flag, #state?, #state_icons, #state_rate, #state_resist?, #state_resist_set, #states, #substitute?, #tcr, #tgr, #tp_rate, #trg, #usable?, #usable_item_conditions_met?, #xparam

Constructor Details

- (Game_Battler) initialize


  • Object Initialization




46
47
48
49
50
51
52
53
54
55
56
# File 'Game_Battler.rb', line 46

def initialize
  @battler_name = ""
  @battler_hue = 0
  @actions = []
  @speed = 0
  @result = Game_ActionResult.new(self)
  @last_target_index = 0
  @guarding = false
  clear_sprite_effects
  super
end

Instance Attribute Details

- (Object) action_times (readonly)

action times



34
35
36
# File 'Game_Battler.rb', line 34

def action_times
  @action_times
end

- (Object) actions (readonly)

combat actions (action side)



35
36
37
# File 'Game_Battler.rb', line 35

def actions
  @actions
end

- (Object) animation_id

animation ID



39
40
41
# File 'Game_Battler.rb', line 39

def animation_id
  @animation_id
end

- (Object) animation_mirror

animation flip horizontal flag



40
41
42
# File 'Game_Battler.rb', line 40

def animation_mirror
  @animation_mirror
end

- (Object) battler_hue (readonly)

battle graphic hue



33
34
35
# File 'Game_Battler.rb', line 33

def battler_hue
  @battler_hue
end

- (Object) battler_name (readonly)


  • Public Instance Variables




32
33
34
# File 'Game_Battler.rb', line 32

def battler_name
  @battler_name
end

- (Object) last_target_index

last target



38
39
40
# File 'Game_Battler.rb', line 38

def last_target_index
  @last_target_index
end

- (Object) magic_reflection

reflection flag



42
43
44
# File 'Game_Battler.rb', line 42

def magic_reflection
  @magic_reflection
end

- (Object) result (readonly)

action result (target side)



37
38
39
# File 'Game_Battler.rb', line 37

def result
  @result
end

- (Object) speed (readonly)

action speed



36
37
38
# File 'Game_Battler.rb', line 36

def speed
  @speed
end

- (Object) sprite_effect_type

sprite effect



41
42
43
# File 'Game_Battler.rb', line 41

def sprite_effect_type
  @sprite_effect_type
end

Instance Method Details

- (Object) add_buff(param_id, turns)


  • Add Buff




172
173
174
175
176
177
178
179
# File 'Game_Battler.rb', line 172

def add_buff(param_id, turns)
  return unless alive?
  @buffs[param_id] += 1 unless buff_max?(param_id)
  erase_buff(param_id) if debuff?(param_id)
  overwrite_buff_turns(param_id, turns)
  @result.added_buffs.push(param_id).uniq!
  refresh
end

- (Object) add_debuff(param_id, turns)


  • Add Debuff




183
184
185
186
187
188
189
190
# File 'Game_Battler.rb', line 183

def add_debuff(param_id, turns)
  return unless alive?
  @buffs[param_id] -= 1 unless debuff_max?(param_id)
  erase_buff(param_id) if buff?(param_id)
  overwrite_buff_turns(param_id, turns)
  @result.added_debuffs.push(param_id).uniq!
  refresh
end

- (Object) add_new_state(state_id)


  • Add New State




110
111
112
113
114
115
116
# File 'Game_Battler.rb', line 110

def add_new_state(state_id)
  die if state_id == death_state_id
  @states.push(state_id)
  on_restrict if restriction > 0
  sort_states
  refresh
end

- (Object) add_state(state_id)


  • Add State




81
82
83
84
85
86
87
# File 'Game_Battler.rb', line 81

def add_state(state_id)
  if state_addable?(state_id)
    add_new_state(state_id) unless state?(state_id)
    reset_state_counts(state_id)
    @result.added_states.push(state_id).uniq!
  end
end

- (Object) apply_critical(damage)


  • Apply Critical




383
384
385
# File 'Game_Battler.rb', line 383

def apply_critical(damage)
  damage * 3
end

- (Object) apply_guard(damage)


  • Applying Guard Adjustment




397
398
399
# File 'Game_Battler.rb', line 397

def apply_guard(damage)
  damage / (damage > 0 && guard? ? 2 * grd : 1)
end

- (Object) apply_variance(damage, variance)


  • Applying Variance




389
390
391
392
393
# File 'Game_Battler.rb', line 389

def apply_variance(damage, variance)
  amp = [damage.abs * variance / 100, 0].max.to_i
  var = rand(amp + 1) + rand(amp + 1) - amp
  damage >= 0 ? damage + var : damage - var
end

- (Object) attack_apply(attacker)


  • Apply Normal Attack Effects




495
496
497
# File 'Game_Battler.rb', line 495

def attack_apply(attacker)
  item_apply(attacker, $data_skills[attacker.attack_skill_id])
end

- (Boolean) buff?(param_id)


  • Determine Buff Status


Returns:

  • (Boolean)


212
213
214
# File 'Game_Battler.rb', line 212

def buff?(param_id)
  @buffs[param_id] > 0
end

- (Boolean) buff_max?(param_id)


  • Determine if Buff Is at Maximum Level


Returns:

  • (Boolean)


224
225
226
# File 'Game_Battler.rb', line 224

def buff_max?(param_id)
  @buffs[param_id] == 2
end

- (Object) charge_tp_by_damage(damage_rate)


  • Charge TP by Damage Suffered




741
742
743
# File 'Game_Battler.rb', line 741

def charge_tp_by_damage(damage_rate)
  self.tp += 50 * damage_rate * tcr
end

- (Object) clear_actions


  • Clear Actions




68
69
70
# File 'Game_Battler.rb', line 68

def clear_actions
  @actions.clear
end

- (Object) clear_sprite_effects


  • Clear Sprite Effects




60
61
62
63
64
# File 'Game_Battler.rb', line 60

def clear_sprite_effects
  @animation_id = 0
  @animation_mirror = false
  @sprite_effect_type = nil
end

- (Object) clear_states


  • Clear State Information




74
75
76
77
# File 'Game_Battler.rb', line 74

def clear_states
  super
  @result.clear_status_effects
end

- (Object) clear_tp


  • Clear TP




735
736
737
# File 'Game_Battler.rb', line 735

def clear_tp
  self.tp = 0
end

- (Object) consume_item(item)


  • Consume Items




424
425
426
# File 'Game_Battler.rb', line 424

def consume_item(item)
  $game_party.consume_item(item)
end

- (Object) current_action


  • Get Current Action




323
324
325
# File 'Game_Battler.rb', line 323

def current_action
  @actions[0]
end

- (Boolean) debuff?(param_id)


  • Determine Debuff Status


Returns:

  • (Boolean)


218
219
220
# File 'Game_Battler.rb', line 218

def debuff?(param_id)
  @buffs[param_id] < 0
end

- (Boolean) debuff_max?(param_id)


  • Determine if Debuff Is at Maximum Level


Returns:

  • (Boolean)


230
231
232
# File 'Game_Battler.rb', line 230

def debuff_max?(param_id)
  @buffs[param_id] == -2
end

- (Object) die


  • Knock Out




149
150
151
152
153
# File 'Game_Battler.rb', line 149

def die
  @hp = 0
  clear_states
  clear_buffs
end

- (Object) elements_max_rate(elements)


  • Get Maximum Elemental Adjustment Amount

     elements : An array of attribute IDs
    Returns the most effective adjustment of all elemental alignments.



377
378
379
# File 'Game_Battler.rb', line 377

def elements_max_rate(elements)
  elements.inject([0.0]) {|r, i| r.push(element_rate(i)) }.max
end

- (Object) erase_buff(param_id)


  • Erase Buff/Debuff




205
206
207
208
# File 'Game_Battler.rb', line 205

def erase_buff(param_id)
  @buffs[param_id] = 0
  @buff_turns[param_id] = 0
end

- (Object) escape


  • Escape




163
164
165
166
167
168
# File 'Game_Battler.rb', line 163

def escape
  hide if $game_party.in_battle
  clear_actions
  clear_states
  Sound.play_escape
end

- (Object) execute_damage(user)


  • Damage Processing

    @result.hp_damage @result.mp_damage @result.hp_drain
    @result.mp_drain must be set before call.



405
406
407
408
409
410
411
# File 'Game_Battler.rb', line 405

def execute_damage(user)
  on_damage(@result.hp_damage) if @result.hp_damage > 0
  self.hp -= @result.hp_damage
  self.mp -= @result.mp_damage
  user.hp += @result.hp_drain
  user.mp += @result.mp_drain
end

- (Object) force_action(skill_id, target_index)


  • Force Action




335
336
337
338
339
340
341
342
343
344
345
346
347
# File 'Game_Battler.rb', line 335

def force_action(skill_id, target_index)
  clear_actions
  action = Game_Action.new(self, true)
  action.set_skill(skill_id)
  if target_index == -2
    action.target_index = last_target_index
  elsif target_index == -1
    action.decide_random_target
  else
    action.target_index = target_index
  end
  @actions.push(action)
end

- (Object) init_tp


  • Initialize TP




729
730
731
# File 'Game_Battler.rb', line 729

def init_tp
  self.tp = rand * 25
end

- (Object) item_apply(user, item)


  • Apply Effect of Skill/Item




501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
# File 'Game_Battler.rb', line 501

def item_apply(user, item)
  @result.clear
  @result.used = item_test(user, item)
  @result.missed = (@result.used && rand >= item_hit(user, item))
  @result.evaded = (!@result.missed && rand < item_eva(user, item))
  if @result.hit?
    unless item.damage.none?
      @result.critical = (rand < item_cri(user, item))
      make_damage_value(user, item)
      execute_damage(user)
    end
    item.effects.each {|effect| item_effect_apply(user, item, effect) }
    item_user_effect(user, item)
  end
end

- (Object) item_cnt(user, item)


  • Calculate Counterattack Rate for Skill/Item




458
459
460
461
462
# File 'Game_Battler.rb', line 458

def item_cnt(user, item)
  return 0 unless item.physical?          # Hit type is not physical
  return 0 unless opposite?(user)         # No counterattack on allies
  return cnt                              # Return counterattack rate
end

- (Object) item_cri(user, item)


  • Calculate Critical Rate of Skill/Item




489
490
491
# File 'Game_Battler.rb', line 489

def item_cri(user, item)
  item.damage.critical ? user.cri * (1 - cev) : 0
end

- (Object) item_effect_add_buff(user, item, effect)


  • Buff

    Effect




646
647
648
649
# File 'Game_Battler.rb', line 646

def item_effect_add_buff(user, item, effect)
  add_buff(effect.data_id, effect.value1)
  @result.success = true
end

- (Object) item_effect_add_debuff(user, item, effect)


  • Debuff

    Effect




653
654
655
656
657
658
659
# File 'Game_Battler.rb', line 653

def item_effect_add_debuff(user, item, effect)
  chance = debuff_rate(effect.data_id) * luk_effect_rate(user)
  if rand < chance
    add_debuff(effect.data_id, effect.value1)
    @result.success = true
  end
end

- (Object) item_effect_add_state(user, item, effect)


  • Add State

    Effect




599
600
601
602
603
604
605
# File 'Game_Battler.rb', line 599

def item_effect_add_state(user, item, effect)
  if effect.data_id == 0
    item_effect_add_state_attack(user, item, effect)
  else
    item_effect_add_state_normal(user, item, effect)
  end
end

- (Object) item_effect_add_state_attack(user, item, effect)


  • Add State

    Effect: Normal Attack




609
610
611
612
613
614
615
616
617
618
619
620
# File 'Game_Battler.rb', line 609

def item_effect_add_state_attack(user, item, effect)
  user.atk_states.each do |state_id|
    chance = effect.value1
    chance *= state_rate(state_id)
    chance *= user.atk_states_rate(state_id)
    chance *= luk_effect_rate(user)
    if rand < chance
      add_state(state_id)
      @result.success = true
    end
  end
end

- (Object) item_effect_add_state_normal(user, item, effect)


  • Add State

    Effect: Normal




624
625
626
627
628
629
630
631
632
# File 'Game_Battler.rb', line 624

def item_effect_add_state_normal(user, item, effect)
  chance = effect.value1
  chance *= state_rate(effect.data_id) if opposite?(user)
  chance *= luk_effect_rate(user)      if opposite?(user)
  if rand < chance
    add_state(effect.data_id)
    @result.success = true
  end
end

- (Object) item_effect_apply(user, item, effect)


  • Apply Effect




546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
# File 'Game_Battler.rb', line 546

def item_effect_apply(user, item, effect)
  method_table = {
    EFFECT_RECOVER_HP    => :item_effect_recover_hp,
    EFFECT_RECOVER_MP    => :item_effect_recover_mp,
    EFFECT_GAIN_TP       => :item_effect_gain_tp,
    EFFECT_ADD_STATE     => :item_effect_add_state,
    EFFECT_REMOVE_STATE  => :item_effect_remove_state,
    EFFECT_ADD_BUFF      => :item_effect_add_buff,
    EFFECT_ADD_DEBUFF    => :item_effect_add_debuff,
    EFFECT_REMOVE_BUFF   => :item_effect_remove_buff,
    EFFECT_REMOVE_DEBUFF => :item_effect_remove_debuff,
    EFFECT_SPECIAL       => :item_effect_special,
    EFFECT_GROW          => :item_effect_grow,
    EFFECT_LEARN_SKILL   => :item_effect_learn_skill,
    EFFECT_COMMON_EVENT  => :item_effect_common_event,
  }
  method_name = method_table[effect.code]
  send(method_name, user, item, effect) if method_name
end

- (Object) item_effect_common_event(user, item, effect)


  • Common Event

    Effect




701
702
# File 'Game_Battler.rb', line 701

def item_effect_common_event(user, item, effect)
end

- (Object) item_effect_gain_tp(user, item, effect)


  • TP Gain

    Effect




590
591
592
593
594
595
# File 'Game_Battler.rb', line 590

def item_effect_gain_tp(user, item, effect)
  value = effect.value1.to_i
  @result.tp_damage -= value
  @result.success = true if value != 0
  self.tp += value
end

- (Object) item_effect_grow(user, item, effect)


  • Raise Parameter

    Effect




687
688
689
690
# File 'Game_Battler.rb', line 687

def item_effect_grow(user, item, effect)
  add_param(effect.data_id, effect.value1.to_i)
  @result.success = true
end

- (Object) item_effect_learn_skill(user, item, effect)


  • Learn Skill

    Effect




694
695
696
697
# File 'Game_Battler.rb', line 694

def item_effect_learn_skill(user, item, effect)
  learn_skill(effect.data_id) if actor?
  @result.success = true
end

- (Object) item_effect_recover_hp(user, item, effect)


  • HP Recovery

    Effect




568
569
570
571
572
573
574
575
# File 'Game_Battler.rb', line 568

def item_effect_recover_hp(user, item, effect)
  value = (mhp * effect.value1 + effect.value2) * rec
  value *= user.pha if item.is_a?(RPG::Item)
  value = value.to_i
  @result.hp_damage -= value
  @result.success = true
  self.hp += value
end

- (Object) item_effect_recover_mp(user, item, effect)


  • MP Recovery

    Effect




579
580
581
582
583
584
585
586
# File 'Game_Battler.rb', line 579

def item_effect_recover_mp(user, item, effect)
  value = (mmp * effect.value1 + effect.value2) * rec
  value *= user.pha if item.is_a?(RPG::Item)
  value = value.to_i
  @result.mp_damage -= value
  @result.success = true if value != 0
  self.mp += value
end

- (Object) item_effect_remove_buff(user, item, effect)


  • Remove Buff

    Effect




663
664
665
666
# File 'Game_Battler.rb', line 663

def item_effect_remove_buff(user, item, effect)
  remove_buff(effect.data_id) if @buffs[effect.data_id] > 0
  @result.success = true
end

- (Object) item_effect_remove_debuff(user, item, effect)


  • Remove Debuff

    Effect




670
671
672
673
# File 'Game_Battler.rb', line 670

def item_effect_remove_debuff(user, item, effect)
  remove_buff(effect.data_id) if @buffs[effect.data_id] < 0
  @result.success = true
end

- (Object) item_effect_remove_state(user, item, effect)


  • Remove State

    Effect




636
637
638
639
640
641
642
# File 'Game_Battler.rb', line 636

def item_effect_remove_state(user, item, effect)
  chance = effect.value1
  if rand < chance
    remove_state(effect.data_id)
    @result.success = true
  end
end

- (Object) item_effect_special(user, item, effect)


  • Special Effect

    Effect




677
678
679
680
681
682
683
# File 'Game_Battler.rb', line 677

def item_effect_special(user, item, effect)
  case effect.data_id
  when SPECIAL_EFFECT_ESCAPE
    escape
  end
  @result.success = true
end

- (Object) item_effect_test(user, item, effect)


  • Test Effect




519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
# File 'Game_Battler.rb', line 519

def item_effect_test(user, item, effect)
  case effect.code
  when EFFECT_RECOVER_HP
    hp < mhp || effect.value1 < 0 || effect.value2 < 0
  when EFFECT_RECOVER_MP
    mp < mmp || effect.value1 < 0 || effect.value2 < 0
  when EFFECT_ADD_STATE
    !state?(effect.data_id)
  when EFFECT_REMOVE_STATE
    state?(effect.data_id)
  when EFFECT_ADD_BUFF
    !buff_max?(effect.data_id)
  when EFFECT_ADD_DEBUFF
    !debuff_max?(effect.data_id)
  when EFFECT_REMOVE_BUFF
    buff?(effect.data_id)
  when EFFECT_REMOVE_DEBUFF
    debuff?(effect.data_id)
  when EFFECT_LEARN_SKILL
    actor? && !skills.include?($data_skills[effect.data_id])
  else
    true
  end
end

- (Object) item_element_rate(user, item)


  • Get Element Modifier for Skill/Item




365
366
367
368
369
370
371
# File 'Game_Battler.rb', line 365

def item_element_rate(user, item)
  if item.damage.element_id < 0
    user.atk_elements.empty? ? 1.0 : elements_max_rate(user.atk_elements)
  else
    element_rate(item.damage.element_id)
  end
end

- (Object) item_eva(user, item)


  • Calculate Evasion Rate for Skill/Item




481
482
483
484
485
# File 'Game_Battler.rb', line 481

def item_eva(user, item)
  return eva if item.physical?    # Return evasion if physical attack
  return mev if item.magical?     # Return magic evasion if magic attack
  return 0
end

- (Object) item_global_effect_apply(effect)


  • Apply Effect of Use to Other Than User




430
431
432
433
434
# File 'Game_Battler.rb', line 430

def item_global_effect_apply(effect)
  if effect.code == EFFECT_COMMON_EVENT
    $game_temp.reserve_common_event(effect.data_id)
  end
end

- (Boolean) item_has_any_valid_effects?(user, item)


  • Determine if Skill/Item Has Any Valid Effects


Returns:

  • (Boolean)


452
453
454
# File 'Game_Battler.rb', line 452

def item_has_any_valid_effects?(user, item)
  item.effects.any? {|effect| item_effect_test(user, item, effect) }
end

- (Object) item_hit(user, item)


  • Calculate Hit Rate of Skill/Item




473
474
475
476
477
# File 'Game_Battler.rb', line 473

def item_hit(user, item)
  rate = item.success_rate * 0.01     # Get success rate
  rate *= user.hit if item.physical?  # Physical attack: Multiply hit rate
  return rate                         # Return calculated hit rate
end

- (Object) item_mrf(user, item)


  • Calculate Reflection Rate of Skill/Item




466
467
468
469
# File 'Game_Battler.rb', line 466

def item_mrf(user, item)
  return mrf if item.magical?     # Return magic reflection if magic attack
  return 0
end

- (Object) item_test(user, item)


  • Test Skill/Item Application

    Used to determine, for example, if a character is already fully healed

    and so cannot recover anymore.




440
441
442
443
444
445
446
447
448
# File 'Game_Battler.rb', line 440

def item_test(user, item)
  return false if item.for_dead_friend? != dead?
  return true if $game_party.in_battle
  return true if item.for_opponent?
  return true if item.damage.recover? && item.damage.to_hp? && hp < mhp
  return true if item.damage.recover? && item.damage.to_mp? && mp < mmp
  return true if item_has_any_valid_effects?(user, item)
  return false
end

- (Object) item_user_effect(user, item)


  • Effect of Skill/Item on Using Side




706
707
708
# File 'Game_Battler.rb', line 706

def item_user_effect(user, item)
  user.tp += item.tp_gain * user.tcr
end

- (Object) luk_effect_rate(user)


  • Get Effect Change Rate by Luck




712
713
714
# File 'Game_Battler.rb', line 712

def luk_effect_rate(user)
  [1.0 + (user.luk - luk) * 0.001, 0.0].max
end

- (Object) make_action_times


  • Determine Action Times




303
304
305
# File 'Game_Battler.rb', line 303

def make_action_times
  action_plus_set.inject(1) {|r, p| rand < p ? r + 1 : r }
end

- (Object) make_actions


  • Create Battle Action




309
310
311
312
313
# File 'Game_Battler.rb', line 309

def make_actions
  clear_actions
  return unless movable?
  @actions = Array.new(make_action_times) { Game_Action.new(self) }
end

- (Object) make_damage_value(user, item)


  • Calculate Damage




351
352
353
354
355
356
357
358
359
360
361
# File 'Game_Battler.rb', line 351

def make_damage_value(user, item)
  value = item.damage.eval(user, self, $game_variables)
  value *= item_element_rate(user, item)
  value *= pdr if item.physical?
  value *= mdr if item.magical?
  value *= rec if item.damage.recover?
  value = apply_critical(value) if @result.critical
  value = apply_variance(value, item.damage.variance)
  value = apply_guard(value)
  @result.make_damage(value.to_i, item)
end

- (Object) make_speed


  • Determine Action Speed




317
318
319
# File 'Game_Battler.rb', line 317

def make_speed
  @speed = @actions.collect {|action| action.speed }.min || 0
end

- (Object) max_slip_damage


  • Get Maximum Value of Slip Damage




756
757
758
# File 'Game_Battler.rb', line 756

def max_slip_damage
  $data_system.opt_slip_death ? hp : [hp - 1, 0].max
end

- (Object) on_action_end


  • Processing at End of Action




791
792
793
794
795
# File 'Game_Battler.rb', line 791

def on_action_end
  @result.clear
  remove_states_auto(1)
  remove_buffs_auto
end

- (Object) on_battle_end


  • Processing at End of Battle




809
810
811
812
813
814
815
816
# File 'Game_Battler.rb', line 809

def on_battle_end
  @result.clear
  remove_battle_states
  remove_all_buffs
  clear_actions
  clear_tp unless preserve_tp?
  appear
end

- (Object) on_battle_start


  • Processing at Start of Battle




785
786
787
# File 'Game_Battler.rb', line 785

def on_battle_start
  init_tp unless preserve_tp?
end

- (Object) on_damage(value)


  • Processing When Suffering Damage




820
821
822
823
# File 'Game_Battler.rb', line 820

def on_damage(value)
  remove_states_by_damage
  charge_tp_by_damage(value.to_f / mhp)
end

- (Object) on_restrict


  • Processing Performed When Action Restriction Occurs




120
121
122
123
124
125
# File 'Game_Battler.rb', line 120

def on_restrict
  clear_actions
  states.each do |state|
    remove_state(state.id) if state.remove_by_restriction
  end
end

- (Object) on_turn_end


  • Processing at End of Turn




799
800
801
802
803
804
805
# File 'Game_Battler.rb', line 799

def on_turn_end
  @result.clear
  regenerate_all
  update_state_turns
  update_buff_turns
  remove_states_auto(2)
end

- (Boolean) opposite?(battler)


  • Determine if Hostile Relation


Returns:

  • (Boolean)


718
719
720
# File 'Game_Battler.rb', line 718

def opposite?(battler)
  actor? != battler.actor? || battler.magic_reflection
end

- (Object) overwrite_buff_turns(param_id, turns)


  • Overwrite Buff/Debuff Turns

    Doesn't overwrite if number of turns would become shorter.



237
238
239
# File 'Game_Battler.rb', line 237

def overwrite_buff_turns(param_id, turns)
  @buff_turns[param_id] = turns if @buff_turns[param_id].to_i < turns
end

- (Object) perform_map_damage_effect


  • Effect When Taking Damage on Map




724
725
# File 'Game_Battler.rb', line 724

def perform_map_damage_effect
end

- (Object) regenerate_all


  • Regenerate All




775
776
777
778
779
780
781
# File 'Game_Battler.rb', line 775

def regenerate_all
  if alive?
    regenerate_hp
    regenerate_mp
    regenerate_tp
  end
end

- (Object) regenerate_hp


  • Regenerate HP




747
748
749
750
751
752
# File 'Game_Battler.rb', line 747

def regenerate_hp
  damage = -(mhp * hrg).to_i
  perform_map_damage_effect if $game_party.in_battle && damage > 0
  @result.hp_damage = [damage, max_slip_damage].min
  self.hp -= @result.hp_damage
end

- (Object) regenerate_mp


  • Regenerate MP




762
763
764
765
# File 'Game_Battler.rb', line 762

def regenerate_mp
  @result.mp_damage = -(mmp * mrg).to_i
  self.mp -= @result.mp_damage
end

- (Object) regenerate_tp


  • Regenerate TP




769
770
771
# File 'Game_Battler.rb', line 769

def regenerate_tp
  self.tp += 100 * trg
end

- (Object) remove_all_buffs


  • Remove All Buffs/Debuffs




267
268
269
# File 'Game_Battler.rb', line 267

def remove_all_buffs
  @buffs.size.times {|param_id| remove_buff(param_id) }
end

- (Object) remove_battle_states


  • Remove Battle States




259
260
261
262
263
# File 'Game_Battler.rb', line 259

def remove_battle_states
  states.each do |state|
    remove_state(state.id) if state.remove_at_battle_end
  end
end

- (Object) remove_buff(param_id)


  • Remove Buff/Debuff




194
195
196
197
198
199
200
201
# File 'Game_Battler.rb', line 194

def remove_buff(param_id)
  return unless alive?
  return if @buffs[param_id] == 0
  erase_buff(param_id)
  @buff_turns.delete(param_id)
  @result.removed_buffs.push(param_id).uniq!
  refresh
end

- (Object) remove_buffs_auto


  • Automatically Remove Buffs/Debuffs




284
285
286
287
288
289
# File 'Game_Battler.rb', line 284

def remove_buffs_auto
  @buffs.size.times do |param_id|
    next if @buffs[param_id] == 0 || @buff_turns[param_id] > 0
    remove_buff(param_id)
  end
end

- (Object) remove_current_action


  • Remove Current Action




329
330
331
# File 'Game_Battler.rb', line 329

def remove_current_action
  @actions.shift
end

- (Object) remove_state(state_id)


  • Remove State




138
139
140
141
142
143
144
145
# File 'Game_Battler.rb', line 138

def remove_state(state_id)
  if state?(state_id)
    revive if state_id == death_state_id
    erase_state(state_id)
    refresh
    @result.removed_states.push(state_id).uniq!
  end
end

- (Object) remove_states_auto(timing)


  • Automatically Remove States

    timing:  Timing (1: End of action 2: End of turn)



274
275
276
277
278
279
280
# File 'Game_Battler.rb', line 274

def remove_states_auto(timing)
  states.each do |state|
    if @state_turns[state.id] == 0 && state.auto_removal_timing == timing
      remove_state(state.id)
    end
  end
end

- (Object) remove_states_by_damage


  • Remove State by Damage




293
294
295
296
297
298
299
# File 'Game_Battler.rb', line 293

def remove_states_by_damage
  states.each do |state|
    if state.remove_by_damage && rand(100) < state.chance_by_damage
      remove_state(state.id)
    end
  end
end

- (Object) reset_state_counts(state_id)


  • Reset State Counts (Turns and Steps)




129
130
131
132
133
134
# File 'Game_Battler.rb', line 129

def reset_state_counts(state_id)
  state = $data_states[state_id]
  variance = 1 + [state.max_turns - state.min_turns, 0].max
  @state_turns[state_id] = state.min_turns + rand(variance)
  @state_steps[state_id] = state.steps_to_remove
end

- (Object) revive


  • Revive from Knock Out




157
158
159
# File 'Game_Battler.rb', line 157

def revive
  @hp = 1 if @hp == 0
end

- (Boolean) state_addable?(state_id)


  • Determine if States Are Addable


Returns:

  • (Boolean)


91
92
93
94
# File 'Game_Battler.rb', line 91

def state_addable?(state_id)
  alive? && $data_states[state_id] && !state_resist?(state_id) &&
    !state_removed?(state_id) && !state_restrict?(state_id)
end

- (Boolean) state_removed?(state_id)


  • Determine States Removed During Same Action


Returns:

  • (Boolean)


98
99
100
# File 'Game_Battler.rb', line 98

def state_removed?(state_id)
  @result.removed_states.include?(state_id)
end

- (Boolean) state_restrict?(state_id)


  • Determine States Removed by Action Restriction


Returns:

  • (Boolean)


104
105
106
# File 'Game_Battler.rb', line 104

def state_restrict?(state_id)
  $data_states[state_id].remove_by_restriction && restriction > 0
end

- (Object) update_buff_turns


  • Update Buff/Debuff Turn Count




251
252
253
254
255
# File 'Game_Battler.rb', line 251

def update_buff_turns
  @buff_turns.keys.each do |param_id|
    @buff_turns[param_id] -= 1 if @buff_turns[param_id] > 0
  end
end

- (Object) update_state_turns


  • Update State Turn Count




243
244
245
246
247
# File 'Game_Battler.rb', line 243

def update_state_turns
  states.each do |state|
    @state_turns[state.id] -= 1 if @state_turns[state.id] > 0
  end
end

- (Object) use_item(item)


  • Use Skill/Item

    Called for the acting side and applies the effect to other than the user.



416
417
418
419
420
# File 'Game_Battler.rb', line 416

def use_item(item)
  pay_skill_cost(item) if item.is_a?(RPG::Skill)
  consume_item(item)   if item.is_a?(RPG::Item)
  item.effects.each {|effect| item_global_effect_apply(effect) }
end