#=============================================================================
# 技能等级系统 Ver 2.0
#-----------------------------------------------------------------------------
# By:RyanBern
#-----------------------------------------------------------------------------
# 主要功能:
# 开放了技能成长值,角色在连续使用同一个技能若干次后,该技能会变得更加强大
# 值得一提的是,技能的等级和角色的等级没有关系,只和你使用它的频率相关,即
# 使角色等级非常高,如果那个技能一直不用的话,技能等级还是不行的。
# 只有产生了效果的技能才会增加技能的熟练度(EXP),在这里产生效果是指:
# 对敌人打出了不为0的伤害/产生状态变化/对同伴有加血作用/
# 也就是说你对着一个满血同伴一直加血的话是不会增加EXP的
# 技能只要满足升级条件立即升级(也就是说在战斗未完成就可以用升级之后的技能)
# 技能升级之后原有技能将会消失。
#-----------------------------------------------------------------------------
# 使用方法:
# 在数据库中定义某技能升级后的技能,方法是在对应的技能说明中的任何位置写:
# %sklv[升级后技能ID,升级所需EXP]
# 例如:1号技能[治疗]可以升级到2号技能[治疗+],需要10个EXP
# %sklv[2,10] <-注意不要写多余的空格
#=============================================================================
module RB
# 使用一次技能之后获得的熟练度(EXP)
BASE_SKILL_EXP = 1
# 升级技能后播放的 SE
SKILL_UP_SE = "Audio/SE/001-GetItem01"
# 显示升级窗口对应的开关:打开该序号开关则升级时不会显示升级窗口
NO_SKILL_UP_WINDOW = 11
end
class RPG::Skill
Regex_Skill = /%sklv\[(\d+),(\d+)\]/i
alias rb_description_20141219 description
def description
text = rb_description_20141219
return text.gsub(Regex_Skill, "")
end
def exp_next
text = rb_description_20141219
Regex_Skill =~ text
return $2.to_i || 0
end
def skill_next
text = rb_description_20141219
Regex_Skill =~ text
return $1.to_i || 0
end
end
class Game_Battler
alias rb_skill_effect_20141219 skill_effect
def skill_effect(user, skill)
effective = rb_skill_effect_20141219(user, skill)
if skill.skill_next != 0 && user.is_a?(Game_Actor)
user.gain_skill_exp(skill.id, RB::BASE_SKILL_EXP) if effective
return effective
end
end
end
class Game_Actor < Game_Battler
alias rb_initialize_20141219 initialize
def initialize(actor_id)
@skills_exp = {}
rb_initialize_20141219(actor_id)
end
#--------------------------------------------------------------------------
# ● 增加技能经验
# skill_id : 特技 ID
# value : 获取值
#--------------------------------------------------------------------------
def gain_skill_exp(skill_id, value)
unless skill_learn?(skill_id)
return
end
@skills_exp ||= {}
if @skills_exp[skill_id] == nil
@skills_exp[skill_id] = 0
end
@skills_exp[skill_id] += value
# 满足条件就升级技能
upgrade_skill(skill_id)
end
#--------------------------------------------------------------------------
# ● 获取技能经验数值
# skill_id : 特技 ID
#--------------------------------------------------------------------------
def skill_exp(skill_id)
return @skills_exp[skill_id] == nil ? 0 : @skills_exp[skill_id]
end
#--------------------------------------------------------------------------
# ● 遗忘特技
# skill_id : 特技 ID
#--------------------------------------------------------------------------
alias rb_forget_skill_20141219 forget_skill
def forget_skill(skill_id)
rb_forget_skill_20141219(skill_id)
@skills_exp ||= {}
@skills_exp.delete(skill_id)
end
#--------------------------------------------------------------------------
# ● 升级特技
# skill_id : 特技 ID
#--------------------------------------------------------------------------
def upgrade_skill(skill_id)
skill_next = $data_skills[skill_id].skill_next
exp_next = $data_skills[skill_id].exp_next
# 技能的下一级别存在的情况下
if $data_skills[skill_id] != nil
# 当前经验高于升级所需经验
if self.skill_exp(skill_id) >= exp_next
# 遗忘上一级别的技能
forget_skill(skill_id)
# 显示窗口
unless $game_switches[RB::NO_SKILL_UP_WINDOW]
Audio.se_play(RB::SKILL_UP_SE, 80, 100) if RB::SKILL_UP_SE != ""
show_skill_up_result(skill_id, skill_next)
end
# 学习新特技
learn_skill(skill_next)
end
end
end
#--------------------------------------------------------------------------
# ● 升级显示处理
#--------------------------------------------------------------------------
def show_skill_up_result(skill_id, skill_next)
skill_learning_window = Window_SkillUpgrade.new(skill_id, skill_next)
# 循环
loop do
# 刷新游戏画面
Graphics.update
# 刷新输入信息
Input.update
for i in 0..50
Graphics.update
end
skill_learning_window.visible = false
return
end
skill_learning_window.dispose
end
end
class Window_SkillUpgrade < Window_Base
def initialize(skill_id, new_skill_id)
super(0, 0, 32, 96)
self.contents = Bitmap.new(1, 1)
self.visible = false
self.back_opacity = 160
# 防止被对话框遮住
self.z = 9000
@old_skill = $data_skills[skill_id]
@new_skill = $data_skills[new_skill_id]
refresh
end
#--------------------------------------------------------------------------
# ● 刷新
#--------------------------------------------------------------------------
def refresh
text1 = @old_skill.name
text2 = "升级"
w = self.contents.text_size(text1).width
self.contents = Bitmap.new(256, 96)
self.width = 288
self.height = 64
self.x = 320 - width / 2
self.y = 240 - height / 2
# 各描写
self.contents.clear
bitmap = RPG::Cache.icon(@old_skill.icon_name)
self.contents.blt(4, 4, bitmap, Rect.new(0,0,24,24))
self.contents.draw_text(40, -16, 256, 64, text1)
self.contents.font.color = Color.new(255, 255, 128, 255)
self.contents.draw_text(40, -16, 212, 64, text2, 2)
self.visible = true
end
end
class Window_Skill < Window_Selectable
def update_help
if self.skill == nil
text = ""
else
text_append = self.skill.skill_next == 0 ? "" \
: sprintf("Exp:%d/%d", @actor.skill_exp(self.skill.id), self.skill.exp_next)
text = self.skill.description + text_append
end
@help_window.set_text(text)
end
end