264 lines
11 KiB
Ruby
264 lines
11 KiB
Ruby
#==============================================================================
|
||
# ■ Game_Enemy
|
||
#------------------------------------------------------------------------------
|
||
# 敵キャラを扱うクラスです。このクラスは Game_Troop クラス($game_troop)の
|
||
# 内部で使用されます。
|
||
#==============================================================================
|
||
|
||
class Game_Enemy < Game_Battler
|
||
#--------------------------------------------------------------------------
|
||
# ● 公開インスタンス変数
|
||
#--------------------------------------------------------------------------
|
||
attr_reader :index # 敵グループ内インデックス
|
||
attr_reader :enemy_id # 敵キャラ ID
|
||
attr_reader :original_name # 元の名前
|
||
attr_accessor :letter # 名前につける ABC の文字
|
||
attr_accessor :plural # 複数出現フラグ
|
||
attr_accessor :screen_x # バトル画面 X 座標
|
||
attr_accessor :screen_y # バトル画面 Y 座標
|
||
#--------------------------------------------------------------------------
|
||
# ● オブジェクト初期化
|
||
#--------------------------------------------------------------------------
|
||
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
|
||
#--------------------------------------------------------------------------
|
||
# ● 敵キャラか否かの判定
|
||
#--------------------------------------------------------------------------
|
||
def enemy?
|
||
return true
|
||
end
|
||
#--------------------------------------------------------------------------
|
||
# ● 味方ユニットを取得
|
||
#--------------------------------------------------------------------------
|
||
def friends_unit
|
||
$game_troop
|
||
end
|
||
#--------------------------------------------------------------------------
|
||
# ● 敵ユニットを取得
|
||
#--------------------------------------------------------------------------
|
||
def opponents_unit
|
||
$game_party
|
||
end
|
||
#--------------------------------------------------------------------------
|
||
# ● 敵キャラオブジェクト取得
|
||
#--------------------------------------------------------------------------
|
||
def enemy
|
||
$data_enemies[@enemy_id]
|
||
end
|
||
#--------------------------------------------------------------------------
|
||
# ● 特徴を保持する全オブジェクトの配列取得
|
||
#--------------------------------------------------------------------------
|
||
def feature_objects
|
||
super + [enemy]
|
||
end
|
||
#--------------------------------------------------------------------------
|
||
# ● 表示名の取得
|
||
#--------------------------------------------------------------------------
|
||
def name
|
||
@original_name + (@plural ? letter : "")
|
||
end
|
||
#--------------------------------------------------------------------------
|
||
# ● 通常能力値の基本値取得
|
||
#--------------------------------------------------------------------------
|
||
def param_base(param_id)
|
||
enemy.params[param_id]
|
||
end
|
||
#--------------------------------------------------------------------------
|
||
# ● 経験値の取得
|
||
#--------------------------------------------------------------------------
|
||
def exp
|
||
enemy.exp
|
||
end
|
||
#--------------------------------------------------------------------------
|
||
# ● お金の取得
|
||
#--------------------------------------------------------------------------
|
||
def gold
|
||
enemy.gold
|
||
end
|
||
#--------------------------------------------------------------------------
|
||
# ● ドロップアイテムの配列作成
|
||
#--------------------------------------------------------------------------
|
||
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
|
||
#--------------------------------------------------------------------------
|
||
# ● ドロップアイテム取得率の倍率を取得
|
||
#--------------------------------------------------------------------------
|
||
def drop_item_rate
|
||
$game_party.drop_item_double? ? 2 : 1
|
||
end
|
||
#--------------------------------------------------------------------------
|
||
# ● アイテムオブジェクトの取得
|
||
#--------------------------------------------------------------------------
|
||
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
|
||
#--------------------------------------------------------------------------
|
||
# ● スプライトを使うか?
|
||
#--------------------------------------------------------------------------
|
||
def use_sprite?
|
||
return true
|
||
end
|
||
#--------------------------------------------------------------------------
|
||
# ● バトル画面 Z 座標の取得
|
||
#--------------------------------------------------------------------------
|
||
def screen_z
|
||
return 100
|
||
end
|
||
#--------------------------------------------------------------------------
|
||
# ● ダメージ効果の実行
|
||
#--------------------------------------------------------------------------
|
||
def perform_damage_effect
|
||
@sprite_effect_type = :blink
|
||
Sound.play_enemy_damage
|
||
end
|
||
#--------------------------------------------------------------------------
|
||
# ● コラプス効果の実行
|
||
#--------------------------------------------------------------------------
|
||
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
|
||
#--------------------------------------------------------------------------
|
||
# ● 変身
|
||
#--------------------------------------------------------------------------
|
||
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
|
||
#--------------------------------------------------------------------------
|
||
# ● 行動条件合致判定
|
||
# action : RPG::Enemy::Action
|
||
#--------------------------------------------------------------------------
|
||
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
|
||
#--------------------------------------------------------------------------
|
||
# ● 行動条件合致判定[ターン数]
|
||
#--------------------------------------------------------------------------
|
||
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
|
||
#--------------------------------------------------------------------------
|
||
# ● 行動条件合致判定[HP]
|
||
#--------------------------------------------------------------------------
|
||
def conditions_met_hp?(param1, param2)
|
||
hp_rate >= param1 && hp_rate <= param2
|
||
end
|
||
#--------------------------------------------------------------------------
|
||
# ● 行動条件合致判定[MP]
|
||
#--------------------------------------------------------------------------
|
||
def conditions_met_mp?(param1, param2)
|
||
mp_rate >= param1 && mp_rate <= param2
|
||
end
|
||
#--------------------------------------------------------------------------
|
||
# ● 行動条件合致判定[ステート]
|
||
#--------------------------------------------------------------------------
|
||
def conditions_met_state?(param1, param2)
|
||
state?(param1)
|
||
end
|
||
#--------------------------------------------------------------------------
|
||
# ● 行動条件合致判定[パーティレベル]
|
||
#--------------------------------------------------------------------------
|
||
def conditions_met_party_level?(param1, param2)
|
||
$game_party.highest_level >= param1
|
||
end
|
||
#--------------------------------------------------------------------------
|
||
# ● 行動条件合致判定[スイッチ]
|
||
#--------------------------------------------------------------------------
|
||
def conditions_met_switch?(param1, param2)
|
||
$game_switches[param1]
|
||
end
|
||
#--------------------------------------------------------------------------
|
||
# ● 現在の状況で戦闘行動が有効か否かを判定
|
||
# action : RPG::Enemy::Action
|
||
#--------------------------------------------------------------------------
|
||
def action_valid?(action)
|
||
conditions_met?(action) && usable?($data_skills[action.skill_id])
|
||
end
|
||
#--------------------------------------------------------------------------
|
||
# ● 戦闘行動をランダムに選択
|
||
# action_list : RPG::Enemy::Action の配列
|
||
# rating_zero : ゼロとみなすレーティング値
|
||
#--------------------------------------------------------------------------
|
||
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
|
||
#--------------------------------------------------------------------------
|
||
# ● 戦闘行動の作成
|
||
#--------------------------------------------------------------------------
|
||
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
|
||
end
|