class RPG::UsableItem < RPG::BaseItem
#--------------------------------------------------------------------------
# ● 判断是否为双向技能
#--------------------------------------------------------------------------
def for_both?
return @for_both unless @for_both.nil?
self.note.split(/[\r\n]+/).each{ |line|
if line =~ /\[for_both\]/
return @for_both = true
end}
return @for_both = false
end
#--------------------------------------------------------------------------
# ● 指定双向技能/物品的第二个技能/物品
#--------------------------------------------------------------------------
def twin_item
return self.id unless for_both?
return @twin_item_id unless @twin_item_id.nil?
@twin_item_id = self.id + 1
self.note.split(/[\r\n]+/).each{ |line|
if line =~ /\[twin_item (\d+)\]/
@twin_item_id = $1.to_i
end}
return @twin_item_id
end
end
class Scene_Battle < Scene_Base
#--------------------------------------------------------------------------
# ● 回合开始
#--------------------------------------------------------------------------
alias skill_for_both_turn_start turn_start
def turn_start
selection_reset
skill_for_both_turn_start
end
#--------------------------------------------------------------------------
# ● 目标选择初始化
#--------------------------------------------------------------------------
def selection_reset
@from_enemy_selection = false
@from_actor_selection = false
end
#--------------------------------------------------------------------------
# ● 取消选择敌人目标时
#--------------------------------------------------------------------------
alias skill_for_both_on_enemy_cancel on_enemy_cancel
def on_enemy_cancel
item = current_used_item
if item.for_both? && !@from_actor_selection # 判断是否为双向技能
change_current_item_selection(item)
@from_enemy_selection = true
select_actor_selection # 开启我方队员选择窗口
@enemy_window.hide
else
selection_reset
skill_for_both_on_enemy_cancel # 呼叫原有方法
end
end
#--------------------------------------------------------------------------
# ● 取消选择同伴目标时
#--------------------------------------------------------------------------
alias skill_for_both_on_actor_cancel on_actor_cancel
def on_actor_cancel
item = current_used_item
if item.for_both? && !@from_enemy_selection # 判断是否为双向技能
change_current_item_selection(item)
@from_actor_selection = true
select_enemy_selection # 开启我方队员选择窗口
@actor_window.hide
else
if @actor_command_window.current_symbol == :attack
@actor_command_window.activate
end
selection_reset
skill_for_both_on_actor_cancel # 呼叫原有方法
end
end
#--------------------------------------------------------------------------
# ● 获取当前技能/物品
#--------------------------------------------------------------------------
def current_used_item
case @actor_command_window.current_symbol
when :attack
return $data_skills[1]
when :skill
return @skill
when :item
return @item
end
end
#--------------------------------------------------------------------------
# ● 当前技能/物品替换
#--------------------------------------------------------------------------
def change_current_item_selection(item)
case @actor_command_window.current_symbol
when :attack, :skill
BattleManager.actor.input.set_skill(item.twin_item)
when :item
BattleManager.actor.input.set_item(item.twin_item)
end
end
end
class Game_BattlerBase
#--------------------------------------------------------------------------
# ● 判断物品是否能使用
#--------------------------------------------------------------------------
alias skill_for_both_item_conditions_met? item_conditions_met?
def item_conditions_met?(item)
r_item_id = has_twin_item?(item)
if r_item_id
real_item = $data_items[r_item_id]
return skill_for_both_item_conditions_met?(real_item)
else
skill_for_both_item_conditions_met?(item)
end
end
#--------------------------------------------------------------------------
# ● 判断物品是否双向物品的第二个物品
#--------------------------------------------------------------------------
def has_twin_item?(item)
$data_items.each{ |i|
next unless i
next unless i.for_both?
t_id = i.twin_item
return i.id if t_id == item.id
}
return false
end
end