Class: Game_Enemy

Inherits:
Game_Battler show all
Defined in:
Game_Enemy.rb

Overview

** Game_Enemy


This class handles enemies. It used within the Game_Troop class

($game_troop).

Constant Summary

Constant Summary

Constants inherited from Game_Battler

Game_Battler::EFFECT_ADD_BUFF, Game_Battler::EFFECT_ADD_DEBUFF, Game_Battler::EFFECT_ADD_STATE, Game_Battler::EFFECT_COMMON_EVENT, Game_Battler::EFFECT_GAIN_TP, Game_Battler::EFFECT_GROW, Game_Battler::EFFECT_LEARN_SKILL, Game_Battler::EFFECT_RECOVER_HP, Game_Battler::EFFECT_RECOVER_MP, Game_Battler::EFFECT_REMOVE_BUFF, Game_Battler::EFFECT_REMOVE_DEBUFF, Game_Battler::EFFECT_REMOVE_STATE, Game_Battler::EFFECT_SPECIAL, Game_Battler::SPECIAL_EFFECT_ESCAPE

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_Battler

#action_times, #actions, #animation_id, #animation_mirror, #battler_hue, #battler_name, #last_target_index, #magic_reflection, #result, #speed, #sprite_effect_type

Attributes inherited from Game_BattlerBase

#hp, #mp, #tp

Instance Method Summary (collapse)

Methods inherited from Game_Battler

#add_buff, #add_debuff, #add_new_state, #add_state, #apply_critical, #apply_guard, #apply_variance, #attack_apply, #buff?, #buff_max?, #charge_tp_by_damage, #clear_actions, #clear_sprite_effects, #clear_states, #clear_tp, #consume_item, #current_action, #debuff?, #debuff_max?, #die, #elements_max_rate, #erase_buff, #escape, #execute_damage, #force_action, #init_tp, #item_apply, #item_cnt, #item_cri, #item_effect_add_buff, #item_effect_add_debuff, #item_effect_add_state, #item_effect_add_state_attack, #item_effect_add_state_normal, #item_effect_apply, #item_effect_common_event, #item_effect_gain_tp, #item_effect_grow, #item_effect_learn_skill, #item_effect_recover_hp, #item_effect_recover_mp, #item_effect_remove_buff, #item_effect_remove_debuff, #item_effect_remove_state, #item_effect_special, #item_effect_test, #item_element_rate, #item_eva, #item_global_effect_apply, #item_has_any_valid_effects?, #item_hit, #item_mrf, #item_test, #item_user_effect, #luk_effect_rate, #make_action_times, #make_damage_value, #make_speed, #max_slip_damage, #on_action_end, #on_battle_end, #on_battle_start, #on_damage, #on_restrict, #on_turn_end, #opposite?, #overwrite_buff_turns, #perform_map_damage_effect, #regenerate_all, #regenerate_hp, #regenerate_mp, #regenerate_tp, #remove_all_buffs, #remove_battle_states, #remove_buff, #remove_buffs_auto, #remove_current_action, #remove_state, #remove_states_auto, #remove_states_by_damage, #reset_state_counts, #revive, #state_addable?, #state_removed?, #state_restrict?, #update_buff_turns, #update_state_turns, #use_item

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, #clear_states, #cnt, #collapse_type, #confusion?, #confusion_level, #cri, #dead?, #death_state?, #death_state_id, #debuff_rate, #def, #dual_wield?, #element_rate, #equip_atype_ok?, #equip_type_fixed?, #equip_type_sealed?, #equip_wtype_ok?, #equippable?, #erase_state, #eva, #exist?, #exr, #fdr, #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_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_Enemy) initialize(index, enemy_id)


  • Object Initialization




22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
# File 'Game_Enemy.rb', line 22

def initialize(index, enemy_id)
  super()
  @index = index
  @enemy_id = enemy_id
  enemy = $data_enemies[@enemy_id]
  @original_name = enemy.name
  @letter = ""
  @plural = false
  @screen_x = 0
  @screen_y = 0
  @battler_name = enemy.battler_name
  @battler_hue = enemy.battler_hue
  @hp = mhp
  @mp = mmp
end

Instance Attribute Details

- (Object) enemy_id (readonly)

enemy ID



13
14
15
# File 'Game_Enemy.rb', line 13

def enemy_id
  @enemy_id
end

- (Object) index (readonly)


  • Public Instance Variables




12
13
14
# File 'Game_Enemy.rb', line 12

def index
  @index
end

- (Object) letter

letters to be attached to the name



15
16
17
# File 'Game_Enemy.rb', line 15

def letter
  @letter
end

- (Object) original_name (readonly)

original name



14
15
16
# File 'Game_Enemy.rb', line 14

def original_name
  @original_name
end

- (Object) plural

multiple appearance flag



16
17
18
# File 'Game_Enemy.rb', line 16

def plural
  @plural
end

- (Object) screen_x

battle screen X coordinate



17
18
19
# File 'Game_Enemy.rb', line 17

def screen_x
  @screen_x
end

- (Object) screen_y

battle screen Y coordinate



18
19
20
# File 'Game_Enemy.rb', line 18

def screen_y
  @screen_y
end

Instance Method Details

- (Boolean) action_valid?(action)


  • Determine if Action Is Valid in Current State

    action : RPG::Enemy::Action

Returns:

  • (Boolean)


232
233
234
# File 'Game_Enemy.rb', line 232

def action_valid?(action)
  conditions_met?(action) && usable?($data_skills[action.skill_id])
end

- (Boolean) conditions_met?(action)


  • Determine if Action Conditions Are Met

    action : RPG::Enemy::Action

Returns:

  • (Boolean)


171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
# File 'Game_Enemy.rb', line 171

def conditions_met?(action)
  method_table = {
    1 => :conditions_met_turns?,
    2 => :conditions_met_hp?,
    3 => :conditions_met_mp?,
    4 => :conditions_met_state?,
    5 => :conditions_met_party_level?,
    6 => :conditions_met_switch?,
  }
  method_name = method_table[action.condition_type]
  if method_name
    send(method_name, action.condition_param1, action.condition_param2)
  else
    true
  end
end

- (Boolean) conditions_met_hp?(param1, param2)


  • Determine if Action Conditions Are Met [HP]


Returns:

  • (Boolean)


201
202
203
# File 'Game_Enemy.rb', line 201

def conditions_met_hp?(param1, param2)
  hp_rate >= param1 && hp_rate <= param2
end

- (Boolean) conditions_met_mp?(param1, param2)


  • Determine if Action Conditions Are Met [MP]


Returns:

  • (Boolean)


207
208
209
# File 'Game_Enemy.rb', line 207

def conditions_met_mp?(param1, param2)
  mp_rate >= param1 && mp_rate <= param2
end

- (Boolean) conditions_met_party_level?(param1, param2)


  • Determine if Action Conditions Are Met [Party Level]


Returns:

  • (Boolean)


219
220
221
# File 'Game_Enemy.rb', line 219

def conditions_met_party_level?(param1, param2)
  $game_party.highest_level >= param1
end

- (Boolean) conditions_met_state?(param1, param2)


  • Determine if Action Conditions Are Met [State]


Returns:

  • (Boolean)


213
214
215
# File 'Game_Enemy.rb', line 213

def conditions_met_state?(param1, param2)
  state?(param1)
end

- (Boolean) conditions_met_switch?(param1, param2)


  • Determine if Action Conditions Are Met [Switch]


Returns:

  • (Boolean)


225
226
227
# File 'Game_Enemy.rb', line 225

def conditions_met_switch?(param1, param2)
  $game_switches[param1]
end

- (Boolean) conditions_met_turns?(param1, param2)


  • Determine if Action Conditions Are Met [Turns]


Returns:

  • (Boolean)


190
191
192
193
194
195
196
197
# File 'Game_Enemy.rb', line 190

def conditions_met_turns?(param1, param2)
  n = $game_troop.turn_count
  if param2 == 0
    n == param1
  else
    n > 0 && n >= param1 && n % param2 == param1 % param2
  end
end

- (Object) drop_item_rate


  • Get Multiplier for Dropped Item Acquisition Probability




106
107
108
# File 'Game_Enemy.rb', line 106

def drop_item_rate
  $game_party.drop_item_double? ? 2 : 1
end

- (Object) enemy


  • Get Enemy Object




58
59
60
# File 'Game_Enemy.rb', line 58

def enemy
  $data_enemies[@enemy_id]
end

- (Boolean) enemy?


  • Determine if Enemy


Returns:

  • (Boolean)


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

def enemy?
  return true
end

- (Object) exp


  • Get Experience




82
83
84
# File 'Game_Enemy.rb', line 82

def exp
  enemy.exp
end

- (Object) feature_objects


  • Get Array of All Objects Retaining Features




64
65
66
# File 'Game_Enemy.rb', line 64

def feature_objects
  super + [enemy]
end

- (Object) friends_unit


  • Get Allied Units




46
47
48
# File 'Game_Enemy.rb', line 46

def friends_unit
  $game_troop
end

- (Object) gold


  • Get Gold




88
89
90
# File 'Game_Enemy.rb', line 88

def gold
  enemy.gold
end

- (Object) item_object(kind, data_id)


  • Get Item Object




112
113
114
115
116
117
# File 'Game_Enemy.rb', line 112

def item_object(kind, data_id)
  return $data_items  [data_id] if kind == 1
  return $data_weapons[data_id] if kind == 2
  return $data_armors [data_id] if kind == 3
  return nil
end

- (Object) make_actions


  • Create Battle Action




252
253
254
255
256
257
258
259
260
261
262
263
# File 'Game_Enemy.rb', line 252

def make_actions
  super
  return if @actions.empty?
  action_list = enemy.actions.select {|a| action_valid?(a) }
  return if action_list.empty?
  rating_max = action_list.collect {|a| a.rating }.max
  rating_zero = rating_max - 3
  action_list.reject! {|a| a.rating <= rating_zero }
  @actions.each do |action|
    action.set_enemy_action(select_enemy_action(action_list, rating_zero))
  end
end

- (Object) make_drop_items


  • Create Array of Dropped Items




94
95
96
97
98
99
100
101
102
# File 'Game_Enemy.rb', line 94

def make_drop_items
  enemy.drop_items.inject([]) do |r, di|
    if di.kind > 0 && rand * di.denominator < drop_item_rate
      r.push(item_object(di.kind, di.data_id))
    else
      r
    end
  end
end

- (Object) name


  • Get Display Name




70
71
72
# File 'Game_Enemy.rb', line 70

def name
  @original_name + (@plural ? letter : "")
end

- (Object) opponents_unit


  • Get Enemy Units




52
53
54
# File 'Game_Enemy.rb', line 52

def opponents_unit
  $game_party
end

- (Object) param_base(param_id)


  • Get Base Value of Parameter




76
77
78
# File 'Game_Enemy.rb', line 76

def param_base(param_id)
  enemy.params[param_id]
end

- (Object) perform_collapse_effect


  • Execute Collapse Effect




140
141
142
143
144
145
146
147
148
149
150
151
# File 'Game_Enemy.rb', line 140

def perform_collapse_effect
  case collapse_type
  when 0
    @sprite_effect_type = :collapse
    Sound.play_enemy_collapse
  when 1
    @sprite_effect_type = :boss_collapse
    Sound.play_boss_collapse1
  when 2
    @sprite_effect_type = :instant_collapse
  end
end

- (Object) perform_damage_effect


  • Execute Damage Effect




133
134
135
136
# File 'Game_Enemy.rb', line 133

def perform_damage_effect
  @sprite_effect_type = :blink
  Sound.play_enemy_damage
end

- (Object) screen_z


  • Get Battle Screen Z-Coordinate




127
128
129
# File 'Game_Enemy.rb', line 127

def screen_z
  return 100
end

- (Object) select_enemy_action(action_list, rating_zero)


  • Randomly Select Action

    action_list:  RPG::Enemy::Action array
    rating_zero:  Rating value to consider as zero



240
241
242
243
244
245
246
247
248
# File 'Game_Enemy.rb', line 240

def select_enemy_action(action_list, rating_zero)
  sum = action_list.inject(0) {|r, a| r += a.rating - rating_zero }
  return nil if sum <= 0
  value = rand(sum)
  action_list.each do |action|
    return action if value < action.rating - rating_zero
    value -= action.rating - rating_zero
  end
end

- (Object) transform(enemy_id)


  • Transform




155
156
157
158
159
160
161
162
163
164
165
166
# File 'Game_Enemy.rb', line 155

def transform(enemy_id)
  @enemy_id = enemy_id
  if enemy.name != @original_name
    @original_name = enemy.name
    @letter = ""
    @plural = false
  end
  @battler_name = enemy.battler_name
  @battler_hue = enemy.battler_hue
  refresh
  make_actions unless @actions.empty?
end

- (Boolean) use_sprite?


  • Use Sprites?


Returns:

  • (Boolean)


121
122
123
# File 'Game_Enemy.rb', line 121

def use_sprite?
  return true
end