=begin
使用方法:
在装备/技能/角色/职业上备注 <attackskill x>或<guardskill x>
效果:
装上装备后/学会技能后/设定的角色中/设定的职业中,普通攻击/防御变为第x号技能
优先级:
装备 > 技能 > 角色 > 职业
装备:武器 > 武器2/盾牌 > 头盔 > 铠甲 > 饰品
技能:技能ID小的优先。
[2014.1.17] 添加了防御技能的设置,完善了command_attack的重定义,删除了修改优先级的说明
=end
class Module
#--------------------------------------------------------------------------
# ● 依次把 prefix 作为前缀定义 method1、method2 ... 的别名。
# 返回处理顺序的别名的数组。
#--------------------------------------------------------------------------
def alias_methods(prefix, *methods)
methods.each do |item|
if method_defined?("#{prefix}#{item}")
msgbox("在类 #{self} 中已经定义了方法 #{prefix}#{item}")
exit
end
alias_method("#{prefix}#{item}", item)
end
methods.collect {|item| "#{prefix}#{item}".to_sym }
end
end
class RPG::BaseItem
#--------------------------------------------------------------------------
# ● 获取普通攻击的技能 ID
#--------------------------------------------------------------------------
def attack_skill
/<ATTACK\s*SKILL\s+(\d+)>/i =~ @note ? $1.to_i : nil
end
#--------------------------------------------------------------------------
# ● 获取防御的技能 ID
#--------------------------------------------------------------------------
def guard_skill
/<GUARD\s*SKILL\s+(\d+)>/i =~ @note ? $1.to_i : nil
end
end
class Game_Actor < Game_Battler
alias_methods(:attack_guard_skill_, :attack_skill_id, :guard_skill_id)
#--------------------------------------------------------------------------
# ● 获取普通攻击的技能 ID
#--------------------------------------------------------------------------
def attack_skill_id
(equips.compact + skills + [actor] + [self.class]).each {|item|
return item.attack_skill if item.attack_skill }
attack_guard_skill_attack_skill_id
end
#--------------------------------------------------------------------------
# ● 获取防御的技能 ID
#--------------------------------------------------------------------------
def guard_skill_id
(equips.compact + skills + [actor] + [self.class]).each {|item|
return item.guard_skill if item.guard_skill }
attack_guard_skill_guard_skill_id
end
end
class Scene_Battle < Scene_Base
alias_methods(:attack_guard_skill_, :command_attack, :command_guard)
#--------------------------------------------------------------------------
# ● 普通攻击无需选择目标的情况
#--------------------------------------------------------------------------
def command_attack
skill = $data_skills[BattleManager.actor.attack_skill_id]
if !skill.need_selection?
BattleManager.actor.input.set_attack
next_command
elsif skill.for_opponent?
attack_guard_skill_command_attack
else
BattleManager.actor.input.set_attack
select_actor_selection
end
end
#--------------------------------------------------------------------------
# ● 防御需要选择目标的情况
#--------------------------------------------------------------------------
def command_guard
skill = $data_skills[BattleManager.actor.guard_skill_id]
if skill.need_selection?
BattleManager.actor.input.set_guard
skill.for_opponent? ? select_enemy_selection : select_actor_selection
else
attack_guard_skill_command_guard
end
end
end
class Window_ActorCommand < Window_Command
#--------------------------------------------------------------------------
# ● 更改攻击指令名称
#--------------------------------------------------------------------------
def add_attack_command
name = $data_skills[@actor.attack_skill_id].name
add_command(name, :attack, @actor.attack_usable?)
end
#--------------------------------------------------------------------------
# ● 更改防御指令名称
#--------------------------------------------------------------------------
def add_guard_command
name = $data_skills[@actor.guard_skill_id].name
add_command(name, :guard, @actor.guard_usable?)
end
end