module Sound
def self.play_buzzer
$game_system.se_play($data_system.buzzer_se)
end
end
class Game_Actor
def attack_sp_enough?
return true if !RPG::State::SP_COST_FORBID_ATTACK
return true if !@states.map{|i|$data_states}.any?{|s|s.sp_cost_state?}
@sp >= attack_sp_cost
end
def attack_sp_cost
cost = 0
sp_cost_states = @states.map{|i|$data_states}.select{|s|s.sp_cost_state?}
return cost if sp_cost_states.empty?
# 百分比消耗
sp_percentage_states = sp_cost_states.select{|s|s.sp_cost_percentage?}
if !sp_percentage_states.empty?
max_cost_percentage = sp_percentage_states.sort_by{|s|s.sp_cost}.first.sp_cost
max_cost_percentage = [max_cost_percentage.to_i, 100].min
cost += @sp * (100 - max_cost_percentage) / 100
end
# 固定值消耗
sp_states = sp_cost_states - sp_percentage_states
if !sp_states.empty?
cost += sp_states.collect{|s|s.sp_cost}.inject{|s,n|s+n}
end
return cost
end
end
class Scene_Battle
#--------------------------------------------------------------------------
# ● 刷新画面
#--------------------------------------------------------------------------
alias cld99_update update
def update
if @actor_command_window && @active_battler && @active_battler.is_a?(Game_Actor)
if !@active_battler.attack_sp_enough?
@actor_command_window.disable_item(0)
else
@actor_command_window.refresh
end
end
cld99_update
end
#--------------------------------------------------------------------------
# ● 刷新画面 (角色命令回合 : 基本命令)
#--------------------------------------------------------------------------
alias cld99_update_phase3_basic_command update_phase3_basic_command
def update_phase3_basic_command
if Input.trigger?(Input::C)
if @actor_command_window.index == 0 #攻击
return Sound.play_buzzer if !@active_battler.attack_sp_enough?
end
end
cld99_update_phase3_basic_command
end
#--------------------------------------------------------------------------
# ● 生成基本行动结果
#--------------------------------------------------------------------------
alias make_basic_action_result_for_sp_cost make_basic_action_result
def make_basic_action_result
# 攻击的情况下
if @active_battler.current_action.basic == 0
@active_battler.sp -= @active_battler.attack_sp_cost if @active_battler.is_a?(Game_Actor)
end
make_basic_action_result_for_sp_cost
end
end
[/pre]