822 lines
36 KiB
Ruby
822 lines
36 KiB
Ruby
#==============================================================================
|
||
# ■ Game_Battler
|
||
#------------------------------------------------------------------------------
|
||
# スプライトや行動に関するメソッドを追加したバトラーのクラスです。このクラス
|
||
# は Game_Actor クラスと Game_Enemy クラスのスーパークラスとして使用されます。
|
||
#==============================================================================
|
||
|
||
class Game_Battler < Game_BattlerBase
|
||
#--------------------------------------------------------------------------
|
||
# ● 定数(使用効果)
|
||
#--------------------------------------------------------------------------
|
||
EFFECT_RECOVER_HP = 11 # HP 回復
|
||
EFFECT_RECOVER_MP = 12 # MP 回復
|
||
EFFECT_GAIN_TP = 13 # TP 増加
|
||
EFFECT_ADD_STATE = 21 # ステート付加
|
||
EFFECT_REMOVE_STATE = 22 # ステート解除
|
||
EFFECT_ADD_BUFF = 31 # 能力強化
|
||
EFFECT_ADD_DEBUFF = 32 # 能力弱体
|
||
EFFECT_REMOVE_BUFF = 33 # 能力強化の解除
|
||
EFFECT_REMOVE_DEBUFF = 34 # 能力弱体の解除
|
||
EFFECT_SPECIAL = 41 # 特殊効果
|
||
EFFECT_GROW = 42 # 成長
|
||
EFFECT_LEARN_SKILL = 43 # スキル習得
|
||
EFFECT_COMMON_EVENT = 44 # コモンイベント
|
||
#--------------------------------------------------------------------------
|
||
# ● 定数(特殊効果)
|
||
#--------------------------------------------------------------------------
|
||
SPECIAL_EFFECT_ESCAPE = 0 # 逃げる
|
||
#--------------------------------------------------------------------------
|
||
# ● 公開インスタンス変数
|
||
#--------------------------------------------------------------------------
|
||
attr_reader :battler_name # 戦闘グラフィック ファイル名
|
||
attr_reader :battler_hue # 戦闘グラフィック 色相
|
||
attr_reader :action_times # 行動回数
|
||
attr_reader :actions # 戦闘行動(行動側)
|
||
attr_reader :speed # 行動速度
|
||
attr_reader :result # 行動結果(対象側)
|
||
attr_accessor :last_target_index # ラストターゲット
|
||
attr_accessor :animation_id # アニメーション ID
|
||
attr_accessor :animation_mirror # アニメーション 左右反転フラグ
|
||
attr_accessor :sprite_effect_type # スプライトのエフェクト
|
||
#--------------------------------------------------------------------------
|
||
# ● オブジェクト初期化
|
||
#--------------------------------------------------------------------------
|
||
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
|
||
#--------------------------------------------------------------------------
|
||
# ● スプライトのエフェクトをクリア
|
||
#--------------------------------------------------------------------------
|
||
def clear_sprite_effects
|
||
@animation_id = 0
|
||
@animation_mirror = false
|
||
@sprite_effect_type = nil
|
||
end
|
||
#--------------------------------------------------------------------------
|
||
# ● 戦闘行動のクリア
|
||
#--------------------------------------------------------------------------
|
||
def clear_actions
|
||
@actions.clear
|
||
end
|
||
#--------------------------------------------------------------------------
|
||
# ● ステート情報をクリア
|
||
#--------------------------------------------------------------------------
|
||
def clear_states
|
||
super
|
||
@result.clear_status_effects
|
||
end
|
||
#--------------------------------------------------------------------------
|
||
# ● ステートの付加
|
||
#--------------------------------------------------------------------------
|
||
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
|
||
#--------------------------------------------------------------------------
|
||
# ● ステートの付加可能判定
|
||
#--------------------------------------------------------------------------
|
||
def state_addable?(state_id)
|
||
alive? && $data_states[state_id] && !state_resist?(state_id) &&
|
||
!state_removed?(state_id) && !state_restrict?(state_id)
|
||
end
|
||
#--------------------------------------------------------------------------
|
||
# ● 同一行動内で解除済みのステートを判定
|
||
#--------------------------------------------------------------------------
|
||
def state_removed?(state_id)
|
||
@result.removed_states.include?(state_id)
|
||
end
|
||
#--------------------------------------------------------------------------
|
||
# ● 行動制約によって無効化されるステートを判定
|
||
#--------------------------------------------------------------------------
|
||
def state_restrict?(state_id)
|
||
$data_states[state_id].remove_by_restriction && restriction > 0
|
||
end
|
||
#--------------------------------------------------------------------------
|
||
# ● 新しいステートの付加
|
||
#--------------------------------------------------------------------------
|
||
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
|
||
#--------------------------------------------------------------------------
|
||
# ● 行動制約が生じたときの処理
|
||
#--------------------------------------------------------------------------
|
||
def on_restrict
|
||
clear_actions
|
||
states.each do |state|
|
||
remove_state(state.id) if state.remove_by_restriction
|
||
end
|
||
end
|
||
#--------------------------------------------------------------------------
|
||
# ● ステートのカウント(ターン数および歩数)をリセット
|
||
#--------------------------------------------------------------------------
|
||
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
|
||
#--------------------------------------------------------------------------
|
||
# ● ステートの解除
|
||
#--------------------------------------------------------------------------
|
||
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
|
||
#--------------------------------------------------------------------------
|
||
# ● 戦闘不能になる
|
||
#--------------------------------------------------------------------------
|
||
def die
|
||
@hp = 0
|
||
clear_states
|
||
clear_buffs
|
||
end
|
||
#--------------------------------------------------------------------------
|
||
# ● 戦闘不能から復活
|
||
#--------------------------------------------------------------------------
|
||
def revive
|
||
@hp = 1 if @hp == 0
|
||
end
|
||
#--------------------------------------------------------------------------
|
||
# ● 逃げる
|
||
#--------------------------------------------------------------------------
|
||
def escape
|
||
hide if $game_party.in_battle
|
||
clear_actions
|
||
clear_states
|
||
Sound.play_escape
|
||
end
|
||
#--------------------------------------------------------------------------
|
||
# ● 能力強化
|
||
#--------------------------------------------------------------------------
|
||
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
|
||
#--------------------------------------------------------------------------
|
||
# ● 能力弱体
|
||
#--------------------------------------------------------------------------
|
||
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
|
||
#--------------------------------------------------------------------------
|
||
# ● 能力強化/弱体の解除
|
||
#--------------------------------------------------------------------------
|
||
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
|
||
#--------------------------------------------------------------------------
|
||
# ● 能力強化/弱体の消去
|
||
#--------------------------------------------------------------------------
|
||
def erase_buff(param_id)
|
||
@buffs[param_id] = 0
|
||
@buff_turns[param_id] = 0
|
||
end
|
||
#--------------------------------------------------------------------------
|
||
# ● 能力強化状態の判定
|
||
#--------------------------------------------------------------------------
|
||
def buff?(param_id)
|
||
@buffs[param_id] > 0
|
||
end
|
||
#--------------------------------------------------------------------------
|
||
# ● 能力弱体状態の判定
|
||
#--------------------------------------------------------------------------
|
||
def debuff?(param_id)
|
||
@buffs[param_id] < 0
|
||
end
|
||
#--------------------------------------------------------------------------
|
||
# ● 能力強化が最大の段階か否かを判定
|
||
#--------------------------------------------------------------------------
|
||
def buff_max?(param_id)
|
||
@buffs[param_id] == 2
|
||
end
|
||
#--------------------------------------------------------------------------
|
||
# ● 能力弱体が最大の段階か否かを判定
|
||
#--------------------------------------------------------------------------
|
||
def debuff_max?(param_id)
|
||
@buffs[param_id] == -2
|
||
end
|
||
#--------------------------------------------------------------------------
|
||
# ● 能力強化/弱体のターン数上書き
|
||
# ターン数が短くなる場合は上書きしない。
|
||
#--------------------------------------------------------------------------
|
||
def overwrite_buff_turns(param_id, turns)
|
||
@buff_turns[param_id] = turns if @buff_turns[param_id].to_i < turns
|
||
end
|
||
#--------------------------------------------------------------------------
|
||
# ● ステートのターンカウント更新
|
||
#--------------------------------------------------------------------------
|
||
def update_state_turns
|
||
states.each do |state|
|
||
@state_turns[state.id] -= 1 if @state_turns[state.id] > 0
|
||
end
|
||
end
|
||
#--------------------------------------------------------------------------
|
||
# ● 強化/弱体のターンカウント更新
|
||
#--------------------------------------------------------------------------
|
||
def update_buff_turns
|
||
@buff_turns.keys.each do |param_id|
|
||
@buff_turns[param_id] -= 1 if @buff_turns[param_id] > 0
|
||
end
|
||
end
|
||
#--------------------------------------------------------------------------
|
||
# ● 戦闘用ステートの解除
|
||
#--------------------------------------------------------------------------
|
||
def remove_battle_states
|
||
states.each do |state|
|
||
remove_state(state.id) if state.remove_at_battle_end
|
||
end
|
||
end
|
||
#--------------------------------------------------------------------------
|
||
# ● 強化/弱体の全解除
|
||
#--------------------------------------------------------------------------
|
||
def remove_all_buffs
|
||
@buffs.size.times {|param_id| remove_buff(param_id) }
|
||
end
|
||
#--------------------------------------------------------------------------
|
||
# ● ステート自動解除
|
||
# timing : タイミング(1:行動終了 2:ターン終了)
|
||
#--------------------------------------------------------------------------
|
||
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
|
||
#--------------------------------------------------------------------------
|
||
# ● 強化/弱体の自動解除
|
||
#--------------------------------------------------------------------------
|
||
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
|
||
#--------------------------------------------------------------------------
|
||
# ● ダメージによるステート解除
|
||
#--------------------------------------------------------------------------
|
||
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
|
||
#--------------------------------------------------------------------------
|
||
# ● 行動回数の決定
|
||
#--------------------------------------------------------------------------
|
||
def make_action_times
|
||
action_plus_set.inject(1) {|r, p| rand < p ? r + 1 : r }
|
||
end
|
||
#--------------------------------------------------------------------------
|
||
# ● 戦闘行動の作成
|
||
#--------------------------------------------------------------------------
|
||
def make_actions
|
||
clear_actions
|
||
return unless movable?
|
||
@actions = Array.new(make_action_times) { Game_Action.new(self) }
|
||
end
|
||
#--------------------------------------------------------------------------
|
||
# ● 行動速度の決定
|
||
#--------------------------------------------------------------------------
|
||
def make_speed
|
||
@speed = @actions.collect {|action| action.speed }.min || 0
|
||
end
|
||
#--------------------------------------------------------------------------
|
||
# ● 現在の戦闘行動を取得
|
||
#--------------------------------------------------------------------------
|
||
def current_action
|
||
@actions[0]
|
||
end
|
||
#--------------------------------------------------------------------------
|
||
# ● 現在の戦闘行動を除去
|
||
#--------------------------------------------------------------------------
|
||
def remove_current_action
|
||
@actions.shift
|
||
end
|
||
#--------------------------------------------------------------------------
|
||
# ● 戦闘行動の強制
|
||
#--------------------------------------------------------------------------
|
||
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
|
||
#--------------------------------------------------------------------------
|
||
# ● ダメージ計算
|
||
#--------------------------------------------------------------------------
|
||
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
|
||
#--------------------------------------------------------------------------
|
||
# ● スキル/アイテムの属性修正値を取得
|
||
#--------------------------------------------------------------------------
|
||
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
|
||
#--------------------------------------------------------------------------
|
||
# ● 属性の最大修正値の取得
|
||
# elements : 属性 ID の配列
|
||
# 与えられた属性の中で最も有効な修正値を返す
|
||
#--------------------------------------------------------------------------
|
||
def elements_max_rate(elements)
|
||
elements.inject([0.0]) {|r, i| r.push(element_rate(i)) }.max
|
||
end
|
||
#--------------------------------------------------------------------------
|
||
# ● クリティカルの適用
|
||
#--------------------------------------------------------------------------
|
||
def apply_critical(damage)
|
||
damage * 3 / 2
|
||
end
|
||
#--------------------------------------------------------------------------
|
||
# ● 分散度の適用
|
||
#--------------------------------------------------------------------------
|
||
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
|
||
#--------------------------------------------------------------------------
|
||
# ● 防御修正の適用
|
||
#--------------------------------------------------------------------------
|
||
def apply_guard(damage)
|
||
damage / (damage > 0 && guard? ? 2 * grd : 1)
|
||
end
|
||
#--------------------------------------------------------------------------
|
||
# ● ダメージの処理
|
||
# 呼び出し前に @result.hp_damage @result.mp_damage @result.hp_drain
|
||
# @result.mp_drain が設定されていること。
|
||
#--------------------------------------------------------------------------
|
||
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
|
||
#--------------------------------------------------------------------------
|
||
# ● スキル/アイテムの使用
|
||
# 行動側に対して呼び出され、使用対象以外に対する効果を適用する。
|
||
#--------------------------------------------------------------------------
|
||
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
|
||
#--------------------------------------------------------------------------
|
||
# ● アイテムの消耗
|
||
#--------------------------------------------------------------------------
|
||
def consume_item(item)
|
||
$game_party.consume_item(item)
|
||
end
|
||
#--------------------------------------------------------------------------
|
||
# ● 使用対象以外に対する使用効果の適用
|
||
#--------------------------------------------------------------------------
|
||
def item_global_effect_apply(effect)
|
||
if effect.code == EFFECT_COMMON_EVENT
|
||
$game_temp.reserve_common_event(effect.data_id)
|
||
end
|
||
end
|
||
#--------------------------------------------------------------------------
|
||
# ● スキル/アイテムの適用テスト
|
||
# 使用対象が全快しているときの回復禁止などを判定する。
|
||
#--------------------------------------------------------------------------
|
||
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
|
||
#--------------------------------------------------------------------------
|
||
# ● スキル/アイテムに有効な使用効果が一つでもあるかを判定
|
||
#--------------------------------------------------------------------------
|
||
def item_has_any_valid_effects?(user, item)
|
||
item.effects.any? {|effect| item_effect_test(user, item, effect) }
|
||
end
|
||
#--------------------------------------------------------------------------
|
||
# ● スキル/アイテムの反撃率計算
|
||
#--------------------------------------------------------------------------
|
||
def item_cnt(user, item)
|
||
return 0 unless item.physical? # 命中タイプが物理ではない
|
||
return 0 unless opposite?(user) # 味方には反撃しない
|
||
return cnt # 反撃率を返す
|
||
end
|
||
#--------------------------------------------------------------------------
|
||
# ● スキル/アイテムの反射率計算
|
||
#--------------------------------------------------------------------------
|
||
def item_mrf(user, item)
|
||
return mrf if item.magical? # 魔法攻撃なら魔法反射率を返す
|
||
return 0
|
||
end
|
||
#--------------------------------------------------------------------------
|
||
# ● スキル/アイテムの命中率計算
|
||
#--------------------------------------------------------------------------
|
||
def item_hit(user, item)
|
||
rate = item.success_rate * 0.01 # 成功率を取得
|
||
rate *= user.hit if item.physical? # 物理攻撃:命中率を乗算
|
||
return rate # 計算した命中率を返す
|
||
end
|
||
#--------------------------------------------------------------------------
|
||
# ● スキル/アイテムの回避率計算
|
||
#--------------------------------------------------------------------------
|
||
def item_eva(user, item)
|
||
return eva if item.physical? # 物理攻撃なら回避率を返す
|
||
return mev if item.magical? # 魔法攻撃なら魔法回避率を返す
|
||
return 0
|
||
end
|
||
#--------------------------------------------------------------------------
|
||
# ● スキル/アイテムの会心率計算
|
||
#--------------------------------------------------------------------------
|
||
def item_cri(user, item)
|
||
item.damage.critical ? user.cri * (1 - cev) : 0
|
||
end
|
||
#--------------------------------------------------------------------------
|
||
# ● 通常攻撃の効果適用
|
||
#--------------------------------------------------------------------------
|
||
def attack_apply(attacker)
|
||
item_apply(attacker, $data_skills[attacker.attack_skill_id])
|
||
end
|
||
#--------------------------------------------------------------------------
|
||
# ● スキル/アイテムの効果適用
|
||
#--------------------------------------------------------------------------
|
||
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
|
||
#--------------------------------------------------------------------------
|
||
# ● 使用効果のテスト
|
||
#--------------------------------------------------------------------------
|
||
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
|
||
#--------------------------------------------------------------------------
|
||
# ● 使用効果の適用
|
||
#--------------------------------------------------------------------------
|
||
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
|
||
#--------------------------------------------------------------------------
|
||
# ● 使用効果[HP 回復]
|
||
#--------------------------------------------------------------------------
|
||
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
|
||
#--------------------------------------------------------------------------
|
||
# ● 使用効果[MP 回復]
|
||
#--------------------------------------------------------------------------
|
||
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
|
||
#--------------------------------------------------------------------------
|
||
# ● 使用効果[TP 増加]
|
||
#--------------------------------------------------------------------------
|
||
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
|
||
#--------------------------------------------------------------------------
|
||
# ● 使用効果[ステート付加]
|
||
#--------------------------------------------------------------------------
|
||
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
|
||
#--------------------------------------------------------------------------
|
||
# ● 使用効果[ステート付加]:通常攻撃
|
||
#--------------------------------------------------------------------------
|
||
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
|
||
#--------------------------------------------------------------------------
|
||
# ● 使用効果[ステート付加]:通常
|
||
#--------------------------------------------------------------------------
|
||
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
|
||
#--------------------------------------------------------------------------
|
||
# ● 使用効果[ステート解除]
|
||
#--------------------------------------------------------------------------
|
||
def item_effect_remove_state(user, item, effect)
|
||
chance = effect.value1
|
||
if rand < chance
|
||
remove_state(effect.data_id)
|
||
@result.success = true
|
||
end
|
||
end
|
||
#--------------------------------------------------------------------------
|
||
# ● 使用効果[能力強化]
|
||
#--------------------------------------------------------------------------
|
||
def item_effect_add_buff(user, item, effect)
|
||
add_buff(effect.data_id, effect.value1)
|
||
@result.success = true
|
||
end
|
||
#--------------------------------------------------------------------------
|
||
# ● 使用効果[能力弱体]
|
||
#--------------------------------------------------------------------------
|
||
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
|
||
#--------------------------------------------------------------------------
|
||
# ● 使用効果[能力強化の解除]
|
||
#--------------------------------------------------------------------------
|
||
def item_effect_remove_buff(user, item, effect)
|
||
remove_buff(effect.data_id) if @buffs[effect.data_id] > 0
|
||
@result.success = true
|
||
end
|
||
#--------------------------------------------------------------------------
|
||
# ● 使用効果[能力弱体の解除]
|
||
#--------------------------------------------------------------------------
|
||
def item_effect_remove_debuff(user, item, effect)
|
||
remove_buff(effect.data_id) if @buffs[effect.data_id] < 0
|
||
@result.success = true
|
||
end
|
||
#--------------------------------------------------------------------------
|
||
# ● 使用効果[特殊効果]
|
||
#--------------------------------------------------------------------------
|
||
def item_effect_special(user, item, effect)
|
||
case effect.data_id
|
||
when SPECIAL_EFFECT_ESCAPE
|
||
escape
|
||
end
|
||
@result.success = true
|
||
end
|
||
#--------------------------------------------------------------------------
|
||
# ● 使用効果[成長]
|
||
#--------------------------------------------------------------------------
|
||
def item_effect_grow(user, item, effect)
|
||
add_param(effect.data_id, effect.value1.to_i)
|
||
@result.success = true
|
||
end
|
||
#--------------------------------------------------------------------------
|
||
# ● 使用効果[スキル習得]
|
||
#--------------------------------------------------------------------------
|
||
def item_effect_learn_skill(user, item, effect)
|
||
learn_skill(effect.data_id) if actor?
|
||
@result.success = true
|
||
end
|
||
#--------------------------------------------------------------------------
|
||
# ● 使用効果[コモンイベント]
|
||
#--------------------------------------------------------------------------
|
||
def item_effect_common_event(user, item, effect)
|
||
end
|
||
#--------------------------------------------------------------------------
|
||
# ● スキル/アイテムの使用者側への効果
|
||
#--------------------------------------------------------------------------
|
||
def item_user_effect(user, item)
|
||
user.tp += item.tp_gain * user.tcr
|
||
end
|
||
#--------------------------------------------------------------------------
|
||
# ● 運による有効度変化率の取得
|
||
#--------------------------------------------------------------------------
|
||
def luk_effect_rate(user)
|
||
[1.0 + (user.luk - luk) * 0.001, 0.0].max
|
||
end
|
||
#--------------------------------------------------------------------------
|
||
# ● 敵対関係の判定
|
||
#--------------------------------------------------------------------------
|
||
def opposite?(battler)
|
||
actor? != battler.actor?
|
||
end
|
||
#--------------------------------------------------------------------------
|
||
# ● マップ上でダメージを受けたときの効果
|
||
#--------------------------------------------------------------------------
|
||
def perform_map_damage_effect
|
||
end
|
||
#--------------------------------------------------------------------------
|
||
# ● TP の初期化
|
||
#--------------------------------------------------------------------------
|
||
def init_tp
|
||
self.tp = rand * 25
|
||
end
|
||
#--------------------------------------------------------------------------
|
||
# ● TP のクリア
|
||
#--------------------------------------------------------------------------
|
||
def clear_tp
|
||
self.tp = 0
|
||
end
|
||
#--------------------------------------------------------------------------
|
||
# ● 被ダメージによる TP チャージ
|
||
#--------------------------------------------------------------------------
|
||
def charge_tp_by_damage(damage_rate)
|
||
self.tp += 50 * damage_rate * tcr
|
||
end
|
||
#--------------------------------------------------------------------------
|
||
# ● HP の再生
|
||
#--------------------------------------------------------------------------
|
||
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
|
||
#--------------------------------------------------------------------------
|
||
# ● スリップダメージの最大値を取得
|
||
#--------------------------------------------------------------------------
|
||
def max_slip_damage
|
||
$data_system.opt_slip_death ? hp : [hp - 1, 0].max
|
||
end
|
||
#--------------------------------------------------------------------------
|
||
# ● MP の再生
|
||
#--------------------------------------------------------------------------
|
||
def regenerate_mp
|
||
@result.mp_damage = -(mmp * mrg).to_i
|
||
self.mp -= @result.mp_damage
|
||
end
|
||
#--------------------------------------------------------------------------
|
||
# ● TP の再生
|
||
#--------------------------------------------------------------------------
|
||
def regenerate_tp
|
||
self.tp += 100 * trg
|
||
end
|
||
#--------------------------------------------------------------------------
|
||
# ● 全ての再生
|
||
#--------------------------------------------------------------------------
|
||
def regenerate_all
|
||
if alive?
|
||
regenerate_hp
|
||
regenerate_mp
|
||
regenerate_tp
|
||
end
|
||
end
|
||
#--------------------------------------------------------------------------
|
||
# ● 戦闘開始処理
|
||
#--------------------------------------------------------------------------
|
||
def on_battle_start
|
||
init_tp unless preserve_tp?
|
||
end
|
||
#--------------------------------------------------------------------------
|
||
# ● 戦闘行動終了時の処理
|
||
#--------------------------------------------------------------------------
|
||
def on_action_end
|
||
@result.clear
|
||
remove_states_auto(1)
|
||
remove_buffs_auto
|
||
end
|
||
#--------------------------------------------------------------------------
|
||
# ● ターン終了処理
|
||
#--------------------------------------------------------------------------
|
||
def on_turn_end
|
||
@result.clear
|
||
regenerate_all
|
||
update_state_turns
|
||
update_buff_turns
|
||
remove_states_auto(2)
|
||
end
|
||
#--------------------------------------------------------------------------
|
||
# ● 戦闘終了処理
|
||
#--------------------------------------------------------------------------
|
||
def on_battle_end
|
||
@result.clear
|
||
remove_battle_states
|
||
remove_all_buffs
|
||
clear_actions
|
||
clear_tp unless preserve_tp?
|
||
appear
|
||
end
|
||
#--------------------------------------------------------------------------
|
||
# ● 被ダメージ時の処理
|
||
#--------------------------------------------------------------------------
|
||
def on_damage(value)
|
||
remove_states_by_damage
|
||
charge_tp_by_damage(value.to_f / mhp)
|
||
end
|
||
end
|