출처 : KMS
스킬마다 숙련도를 적용할 수 있게 해주는 스크립트입니다. 좋아보여서 퍼왔습니다.
일단 스크립트 원문부터
-------------------------------------------------------------------------------------------------------------------------------------
#_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/
#_/ ◆ 스킬 숙련도 - KMS_SkillLevel ◆ VX Ace ◆
#_/ ◇ Last update : 2012/02/12 (TOMY@Kamesoft) ◇
#_/----------------------------------------------------------------------------
#_/ 스킬에 숙련도의 개념을 추가합니다.
#_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/
#==============================================================================
# ★ 설정 항목 - BEGIN Setting ★
#==============================================================================
module KMS_SkillLevel
# ◆ 숙련도 상한
EXP_MAX = 999
# ◆ 적에게도 숙련도를 적용한다
ENABLE_FOR_ENEMY = false
# ◆ 메뉴 화면에서 사용했을 경우도 숙련도를 올린다
ENABLE_ON_MENU = false
end
#==============================================================================
# ☆ 설정 여기까지 - END Setting ☆
#==============================================================================
$kms_imported = {} if $kms_imported == nil
$kms_imported["SkillLevel"] = true
module KMS_SkillLevel
# 디버그 플래그
DEBUG = false
# 숙련도 증가량
# 기술예 : <숙련도 증가량 2>
REGEX_SXP_GAIN = /<(?:숙련도 증가량|SXP_GAIN)\s*(\d+)>/i
# 숙련도 보정
REGEX_REV = /(?:숙련도 보정|SXP_REV)\s*/i
# 행동 속도 보정
# 기술예 : <숙련도 보정 속도 sxp / 50>
REGEX_SPEED_REV = /<#{REGEX_REV}(?:속도|SPEED)\s+(.+)>/i
# 성공율 보정
# 기술예 : <숙련도 보정 성공율 sxp / 50>
REGEX_SUCCESS_REV = /<#{REGEX_REV}(?:성공율|SUCCESS)\s+(.+)>/i
# 숙련도용 제어 문자
# \SXP / \SXP[actor_id,skill_id] / \SXP[skill_id]
# \S 하지만 정의가 끝난 상태라면 미스가능성이 있으므로 \_SXP 에도 대응
REGEX_TEXT_SXP = /\e_?SXP\[(\d+)\s*,\s*(\d+)]/i
REGEX_TEXT_SXP_HELP = /\e_?SXP(?:\[(\d+)\])?/i
end
# *****************************************************************************
#==============================================================================
# □ KMS_Commands
#==============================================================================
module KMS_Commands
module_function
#--------------------------------------------------------------------------
# ○ 액터의 숙련도의 증감
#--------------------------------------------------------------------------
def gain_actor_skill_exp(actor_id, skill_id, n)
return if $game_actors[actor_id].nil?
$game_actors[actor_id].gain_skill_exp(skill_id, n)
end
#--------------------------------------------------------------------------
# ○ 액터의 숙련도를 클리어
#--------------------------------------------------------------------------
def clear_actor_skill_exp(actor_id)
return if $game_actors[actor_id].nil?
$game_actors[actor_id].clear_skill_exp
end
end
#==============================================================================
# ■ Game_Interpreter
#==============================================================================
class Game_Interpreter
# 이벤트 커멘드로부터 직접 커멘드를 두드릴 수 있도록(듯이) 한다
include KMS_Commands
end
#==============================================================================
# ■ RPG::Skill
#==============================================================================
class RPG::Skill < RPG::UsableItem
#--------------------------------------------------------------------------
# ○ 숙련도 캐쉬 작성
#--------------------------------------------------------------------------
def __create_skill_level_cache
@__skill_exp_gain = 1
@__speed_rev_by_skill_exp_formula = "0"
@__success_rev_by_skill_exp_formula = "0"
note.each_line { |line|
case line
when KMS_SkillLevel::REGEX_SXP_GAIN
@__skill_exp_gain = $1.to_i
when KMS_SkillLevel::REGEX_SPEED_REV
@__speed_rev_by_skill_exp_formula = $1
print "Speed rev[#{id}]: #{$1}\n" if KMS_SkillLevel::DEBUG
when KMS_SkillLevel::REGEX_SUCCESS_REV
@__success_rev_by_skill_exp_formula = $1
print "Success rev[#{id}]: #{$1}\n" if KMS_SkillLevel::DEBUG
end
}
end
protected :__create_skill_level_cache
#--------------------------------------------------------------------------
# ○ 숙련도 증가량 취득
#--------------------------------------------------------------------------
def skill_exp_gain
__create_skill_level_cache if @__skill_exp_gain.nil?
return @__skill_exp_gain
end
#--------------------------------------------------------------------------
# ○ 행동 속도 보정 취득
#--------------------------------------------------------------------------
def speed_rev_by_skill_exp_formula
__create_skill_level_cache if @__speed_rev_by_skill_exp_formula.nil?
return @__speed_rev_by_skill_exp_formula
end
#--------------------------------------------------------------------------
# ○ 성공율 보정 취득
#--------------------------------------------------------------------------
def success_rev_by_skill_exp_formula
__create_skill_level_cache if @__success_rev_by_skill_exp_formula.nil?
return @__success_rev_by_skill_exp_formula
end
end
#==============================================================================
# ■ Game_Action
#==============================================================================
class Game_Action
#--------------------------------------------------------------------------
# ● 행동 속도의 계산
#--------------------------------------------------------------------------
alias speed_KMS_SkillLevel speed
def speed
n = speed_KMS_SkillLevel
# 속도 보정의 적용
n += subject.speed_rev_by_skill_exp(item) if item
return n
end
end
#==============================================================================
# ■ Game_BattlerBase
#==============================================================================
class Game_BattlerBase
#--------------------------------------------------------------------------
# ● 오브젝트 초기화
#--------------------------------------------------------------------------
alias initialize_KMS_SkillLevel initialize
def initialize
initialize_KMS_SkillLevel
@skill_exp = {}
end
#--------------------------------------------------------------------------
# ○ 스킬 숙련도의 취득
#--------------------------------------------------------------------------
def skill_exp(skill_id)
@skill_exp = {} if @skill_exp.nil?
@skill_exp[skill_id] = 0 unless @skill_exp.include?(skill_id)
return @skill_exp[skill_id]
end
#--------------------------------------------------------------------------
# ○ 스킬 숙련도의 가산
#--------------------------------------------------------------------------
def gain_skill_exp(skill_id, n = 1)
# 기본 액션은 가산하지 않는다
return if skill_id == attack_skill_id || skill_id == guard_skill_id
lv = skill_exp(skill_id)
@skill_exp[skill_id] = [ [lv + n, 0 ].max, KMS_SkillLevel::EXP_MAX ].min
if KMS_SkillLevel::DEBUG
print "#{name} 숙련도 [#{skill_id}] = #{@skill_exp[skill_id]}\n"
end
end
#--------------------------------------------------------------------------
# ○ 스킬 숙련도의 초기화
#--------------------------------------------------------------------------
def clear_skill_exp
@skill_exp = {}
end
#--------------------------------------------------------------------------
# ○ 현재의 액션의 숙련도를 취득
# skill_id : 대상 스킬 ID (생략시는 현재의 행동)
#--------------------------------------------------------------------------
def sxp(skill_id = 0)
if skill_id > 0
return skill_exp(skill_id)
else
return current_skill_exp
end
end
#--------------------------------------------------------------------------
# ○ 스킬 숙련도에 의한 행동 속도 보정을 취득
# item : 대상 행동
#--------------------------------------------------------------------------
def speed_rev_by_skill_exp(item)
return 0 unless item.is_a?(RPG::Skill)
formula = item.speed_rev_by_skill_exp_formula
formula = formula.gsub(/sxp/i) { "skill_exp(item.id)" }
return eval(formula)
end
#--------------------------------------------------------------------------
# ○ 스킬 숙련도에 의한 성공율 보정을 취득
# item : 대상 행동
#--------------------------------------------------------------------------
def success_rev_by_skill_exp(item)
return 0 unless item.is_a?(RPG::Skill)
formula = item.success_rev_by_skill_exp_formula
formula = formula.gsub(/sxp/i) { "skill_exp(item.id)" }
return eval(formula)
end
end
#==============================================================================
# ■ Game_Battler
#==============================================================================
class Game_Battler < Game_BattlerBase
#--------------------------------------------------------------------------
# ○ 현재의 행동의 스킬 숙련도를 취득
#--------------------------------------------------------------------------
def current_skill_exp
if current_action.item && current_action.item.is_a?(RPG::Skill)
return skill_exp(current_action.item.id)
else
return 0
end
end
#--------------------------------------------------------------------------
# ○ 스킬 숙련도 가산 처리
#--------------------------------------------------------------------------
def gain_skill_exp_effect(item)
return unless item.is_a?(RPG::Skill)
if $game_party.in_battle || KMS_SkillLevel::ENABLE_ON_MENU
gain_skill_exp(item.id, item.skill_exp_gain)
end
end
#--------------------------------------------------------------------------
# ● 스킬/아이템의 사용
# 행동 측에 대해 불려 가 사용 대상 이외에 대하는 효과를 적용한다.
#--------------------------------------------------------------------------
alias use_item_KMS_SkillLevel use_item
def use_item(item)
use_item_KMS_SkillLevel(item)
gain_skill_exp_effect(item)
end
#--------------------------------------------------------------------------
# ● 스킬/아이템의 명중율 계산
#--------------------------------------------------------------------------
alias item_hit_KMS_SkillLevel item_hit
def item_hit(user, item)
# 숙련도에 의한 성공율 보정치를 가산
rate_rev = user.success_rev_by_skill_exp(item) * 0.01
rate_rev *= user.hit if item.physical?
return item_hit_KMS_SkillLevel(user, item) + rate_rev
end
end
#==============================================================================
# ■ Game_Enemy
#==============================================================================
class Game_Enemy < Game_Battler
#--------------------------------------------------------------------------
# ○ 스킬 숙련도의 가산
#--------------------------------------------------------------------------
def gain_skill_exp(skill_id, n = 1)
# 아무것도 하지 않는다
end
end unless KMS_SkillLevel::ENABLE_FOR_ENEMY
#==============================================================================
# ■ Window_Base
#==============================================================================
class Window_Base < Window
#--------------------------------------------------------------------------
# ● 제어 문자의 사전 변환
#--------------------------------------------------------------------------
alias convert_escape_characters_KMS_SkillLevel convert_escape_characters
def convert_escape_characters(text)
result = convert_escape_characters_KMS_SkillLevel(text).clone
result.gsub!(KMS_SkillLevel::REGEX_TEXT_SXP) {
actor = $game_actors[$1.to_i]
if actor
actor.skill_exp($2.to_i)
else
""
end
}
return result
end
end
#==============================================================================
# ■ Window_Help
#==============================================================================
class Window_Help < Window_Base
#--------------------------------------------------------------------------
# ● 아이템 설정
# item : 스킬, 아이템등
#--------------------------------------------------------------------------
alias set_item_KMS_SkillLevel set_item
def set_item(item)
@current_item = item
set_item_KMS_SkillLevel(item)
end
#--------------------------------------------------------------------------
# ○ 액터의 설정
#--------------------------------------------------------------------------
def set_actor(actor)
@current_actor = actor
end
#--------------------------------------------------------------------------
# ● 제어 문자의 사전 변환
#--------------------------------------------------------------------------
unless method_defined?(:convert_escape_characters_KMS_SkillLevel)
alias convert_escape_characters_KMS_SkillLevel convert_escape_characters
end
def convert_escape_characters(text)
result = convert_escape_characters_KMS_SkillLevel(text).clone
result.gsub!(KMS_SkillLevel::REGEX_TEXT_SXP_HELP) {
if @current_actor
if $1.nil? && @current_item.is_a?(RPG::Skill)
# 현재의 스킬
@current_actor.skill_exp(@current_item.id)
else
# ID 지정
@current_actor.skill_exp($1.to_i)
end
else
""
end
}
return result
end
end
#==============================================================================
# ■ Window_SkillList
#==============================================================================
class Window_SkillList < Window_Selectable
#--------------------------------------------------------------------------
# ● 헬프 텍스트 갱신
#--------------------------------------------------------------------------
alias update_help_KMS_SkillLevel update_help
def update_help
@help_window.set_actor(@actor)
update_help_KMS_SkillLevel
@help_window.set_actor(nil)
end
end
#==============================================================================
# ■ Scene_Skill
#==============================================================================
class Scene_Skill < Scene_ItemBase
#--------------------------------------------------------------------------
# ● 아이템의 사용
#--------------------------------------------------------------------------
alias use_item_KMS_SkillLevel use_item
def use_item
use_item_KMS_SkillLevel
@help_window.set_actor(@actor)
@help_window.refresh
@help_window.set_actor(nil)
end
end
#==============================================================================
# ■ Scene_Battle
#==============================================================================
class Scene_Battle < Scene_Base
#--------------------------------------------------------------------------
# ● 커멘드[스킬]
#--------------------------------------------------------------------------
alias command_skill_KMS_SkillLevel command_skill
def command_skill
@help_window.clear
command_skill_KMS_SkillLevel
end
end
-----------------------------------------------------------------------------------------------------------------------------------------