Project1
标题:
流星技能升级系统 V2.1的问题
[打印本页]
作者:
sonicdonggua
时间:
2015-1-24 22:01
标题:
流星技能升级系统 V2.1的问题
我又遇到问题了……跪求各位大神,请问为啥一在技能界面按A就会弹出 错误undefined method 'manual_lvup?' for nil:NilClass 跪谢!
作者:
rpg-sheep
时间:
2015-1-24 22:30
本帖最后由 rpg-sheep 于 2015-1-24 22:32 编辑
遇到这类的问题,至少应当将你的范例工程上传上来,否则我们是没法分析的。
至于出现这个错误,应该是对一个本应该成为一个新class的变量赋值了null,在调用manual_lvup?方法时发生错误。
你可以尝试把技能界面的脚本复制到记事本里,搜索引号里面的内容:“.manual_lvup?”然后自己解决。
也可以找Input.trigger?(:X) 或Input.press?(:X),找到调用A键的部分,然后解决。
由于我看不到你的工程,只能帮你到这里了
作者:
sonicdonggua
时间:
2015-1-24 22:41
标题:
RE: 流星技能升级系统 V2.1的问题
本帖最后由 sonicdonggua 于 2015-1-24 23:08 编辑
module Snstar2006
module Skill_LvUp
SKILL_LVUP_NO_FORGET = false # 升级时不遗忘旧技能
SKILL_MANUAL_LVUP = false # 手动升级
SKILL_RES_EXP_BASE = 2 # 升级点数基数,数字越大,获得越少
SKILL_MAN_LVUP_KEY = :X # 手动升级的按键设定
SKILL_EXP_VOCAB = "熟练度" # 技能熟练度术语
SKILL_REXP_VOCAB = "精元点数" # 技能提升点数术语
end
end
class RPG::Skill < RPG::UsableItem
include Snstar2006::Skill_LvUp
#--------------------------------------------------------------------------
# ● 获取技能最高等级
#--------------------------------------------------------------------------
def get_max_skill
self.note.split(/[\r\n]+/).each{ |line|
if line =~ /\[(?:max_level) (\d+)\]/
return $1 ? $1.to_i : 1
end}
return 1
end
#--------------------------------------------------------------------------
# ● 获取技能熟练度基数
#--------------------------------------------------------------------------
def get_exp_base
self.note.split(/[\r\n]+/).each{ |line|
if line =~ /\[(?:exp_base) (\d+)\]/
return $1 ? $1.to_i : 30
end}
return 30
end
#--------------------------------------------------------------------------
# ● 获取技能吸收角色经验值作为熟练度的基础值
#--------------------------------------------------------------------------
def get_exp_part
self.note.split(/[\r\n]+/).each{ |line|
if line =~ /\[(?:exp_part) (\d+)\]/
return $1 ? $1.to_i : 0
end}
return 0
end
#--------------------------------------------------------------------------
# ● 获取技能使用时获取的熟练度
#--------------------------------------------------------------------------
def get_use_exp
self.note.split(/[\r\n]+/).each{ |line|
if line =~ /\[(?:use_exp) (\d+)\]/
return $1 ? $1.to_i : 1
end}
return 1
end
#--------------------------------------------------------------------------
# ● 获取技能升级后变化的技能
#--------------------------------------------------------------------------
def get_on_level(level)
trans_skill_id = 0
self.note.split(/[\r\n]+/).each{ |line|
if line =~ /\[(?:on_level) (\d+)\,(\d+)\]/
trans_skill_id = $2.to_i if level == $1.to_i
end}
return trans_skill_id
end
#--------------------------------------------------------------------------
# ● 获取技能升级后变化的技能
#--------------------------------------------------------------------------
def get_inherit
self.note.split(/[\r\n]+/).each{ |line|
if line =~ /\[(?:inherit) (\d+)\]/
return $1 ? $1.to_i : 0
end}
return 0
end
#--------------------------------------------------------------------------
# ● 判断是否升级后遗忘
#--------------------------------------------------------------------------
def no_forget?
self.note.split(/[\r\n]+/).each{ |line|
if line =~ /\[(?:no_forget)\]/
return true
end}
return false
end
#--------------------------------------------------------------------------
# ● 获取技能升级后变化的伤害值基数
#--------------------------------------------------------------------------
def get_dmg_var
self.note.split(/[\r\n]+/).each{ |line|
if line =~ /\[(?:dmg_var) (\d+)\]/
return $1 ? $1.to_i : 0
end}
return 0
end
#--------------------------------------------------------------------------
# ● 判断是否能升级
#--------------------------------------------------------------------------
def can_lvup?
skill_level_initialize # 技能等级初始化
return @max_level > 1
end
#--------------------------------------------------------------------------
# ● 判断是否获取角色经验当作熟练度
#--------------------------------------------------------------------------
def get_exp_from_actor?
return false unless can_lvup?
return @get_exp > 0
end
#--------------------------------------------------------------------------
# ● 判断是否手动升级
#--------------------------------------------------------------------------
def manual_lvup?
return false unless can_lvup?
return false if transformed
return true if SKILL_MANUAL_LVUP
return false if get_exp_from_actor?
return false if lvup_by_use?
return true
end
#--------------------------------------------------------------------------
# ● 判断是否在使用时提升熟练度
#--------------------------------------------------------------------------
def lvup_by_use?
return false unless can_lvup?
return @use_exp > 0
end
#--------------------------------------------------------------------------
# ● 判断是否继承任何技能设定
#--------------------------------------------------------------------------
def inherit?
@transform_from = get_inherit
return @transform_from > 0
end
#--------------------------------------------------------------------------
# ● 技能等级参数初始化
#--------------------------------------------------------------------------
def skill_level_initialize
return if @skill_level_initialized # 已初始化时跳过
@max_level = get_max_skill
@get_exp = get_exp_part
@use_exp = get_use_exp
@skill_level_initialized = true
initialize_skill_transform
@transformed = false
@transform_from = 0
@dmg_var = get_dmg_var
@fml_altered = false
if @dmg_var > 0
$game_variables[@dmg_var]=1
end
end
#--------------------------------------------------------------------------
# ● 技能等级参数继承
#--------------------------------------------------------------------------
def skill_level_inherit
return unless inherit? # 已设定继承时跳过
old_skill = $data_skills[@transform_from]
@max_level = old_skill.get_max_skill
@get_exp = old_skill.get_exp_part
@use_exp = old_skill.get_use_exp
initialize_skill_transform
end
#--------------------------------------------------------------------------
# ● 获取技能吸取角色经验值的基数
#--------------------------------------------------------------------------
def exp_from_actor
return @get_exp
end
#--------------------------------------------------------------------------
# ● 技能变化资讯初始化
#--------------------------------------------------------------------------
def initialize_skill_transform
@skill_transform = []
1.upto(@max_level){ |level|
t_id = get_on_level(level)
if t_id > 0
@skill_transform = [level, t_id]
break
end
}
end
#--------------------------------------------------------------------------
# ● 判断技能是否会变化
#--------------------------------------------------------------------------
def transform?
return !@skill_transform.empty?
end
#--------------------------------------------------------------------------
# ● 判断技能是否会在某等级变化
#--------------------------------------------------------------------------
def transform_at?(level)
return false unless transform?
return @skill_transform[0] == level
end
def transform_at
return @skill_transform[0]
end
#--------------------------------------------------------------------------
# ● 获取技能变化后的技能ID
#--------------------------------------------------------------------------
def transform_to(level)
return 0 unless transform_at?(level)
return @skill_transform[1]
end
#--------------------------------------------------------------------------
# ● 判断技能是否有指定伤害变量
#--------------------------------------------------------------------------
def dmg_var?
return @dmg_var>0
end
#--------------------------------------------------------------------------
# ● 判断技能是否已修改公式
#--------------------------------------------------------------------------
def fml_altered?
return @fml_altered
end
attr_reader :max_level # 获取最高等级
attr_reader :use_exp # 使用提升熟练度量
attr_accessor :transformed # 已变化技能
attr_accessor :fml_altered # 已修改公式
attr_reader :dmg_var # 升级提升伤害的变量ID
end
class Game_Actor < Game_Battler
include Snstar2006::Skill_LvUp
#--------------------------------------------------------------------------
# ● 初始化
#--------------------------------------------------------------------------
alias skill_level_initialize initialize
def initialize(actor_id)
@skill_level = {} # 纪录技能等级
@skill_exp = {} # 记录技能熟练度
@skill_exp_base = {} # 记录技能熟练度基数
@skill_next_exp = {} # 记录技能下一级熟练度
@skill_dmg_val = {} # 纪录技能伤害变化的变量ID
@skill_res_exp = 0 # 纪录获取的技能升级点数
skill_level_initialize(actor_id)
end
#--------------------------------------------------------------------------
# ● 角色习得技能
#--------------------------------------------------------------------------
alias skill_level_learn_skill learn_skill
def learn_skill(skill_id)
skill_level_learn_skill(skill_id)
skill = $data_skills[skill_id]
if skill.can_lvup? # 判断技能是否可升级
@skill_level[skill_id] = 1
@skill_exp[skill_id] = 0
@skill_exp_base[skill_id] = skill.get_exp_base
@skill_next_exp[skill_id] = @skill_exp_base[skill_id]
if skill.dmg_var?
@skill_dmg_val[skill_id] = skill.dmg_var+@actor_id-1
alter_damage_formula(skill_id)
end
end
end
#--------------------------------------------------------------------------
# ● 修改伤害公式
#--------------------------------------------------------------------------
def alter_damage_formula(skill_id)
skill = $data_skills[skill_id]
return if skill.fml_altered? # 已修改时返回
formula = skill.damage.formula # 获取公式
dmg_var_id = @skill_dmg_val[skill_id]
skill.damage.formula = "(#{formula})*v[#{dmg_var_id}]"
skill.fml_altered = true # 标记为已修改
end
#--------------------------------------------------------------------------
# ● 判断技能是否能升级
#--------------------------------------------------------------------------
def skill_can_lvup?(skill_id)
return false unless $data_skills[skill_id].can_lvup? # 技能不可升级
return false unless @skills.include?(skill_id) # 角色未学习此技能
return @skill_level[skill_id] < max_skill_level(skill_id) # 技能未达最高等级
end
#--------------------------------------------------------------------------
# ● 获取技能最高等级
#--------------------------------------------------------------------------
def max_skill_level(skill_id)
return $data_skills[skill_id].max_level
end
#--------------------------------------------------------------------------
# ● 获取技能等级
#--------------------------------------------------------------------------
def skill_level(skill_id)
return 1 unless $data_skills[skill_id].can_lvup?
return @skill_level[skill_id]
end
#--------------------------------------------------------------------------
# ● 获取技能下一级熟练度
#--------------------------------------------------------------------------
def skill_next_exp(skill_id)
return 0 unless skill_can_lvup?(skill_id)
return @skill_next_exp[skill_id]
end
#--------------------------------------------------------------------------
# ● 获取技能当前熟练度
#--------------------------------------------------------------------------
def skill_exp(skill_id)
return 0 unless skill_can_lvup?(skill_id)
return @skill_exp[skill_id]
end
#--------------------------------------------------------------------------
# ● 角色获得经验值
#--------------------------------------------------------------------------
alias skill_level_gain_exp gain_exp
def gain_exp(exp)
skill_level_gain_exp(exp)
gain_skill_res_exp(exp/SKILL_RES_EXP_BASE)
@skills.each{ |id|
skill = $data_skills[id]
if skill.get_exp_from_actor? # 技能是否吸收经验值
skill_exp = (exp.to_f / skill.exp_from_actor).ceil
gain_skill_exp(id, skill_exp) # 技能提升熟练度
end
}
end
#--------------------------------------------------------------------------
# ● 角色获得技能熟练度
#--------------------------------------------------------------------------
def gain_skill_exp(skill_id, val)
return unless skill_can_lvup?(skill_id)
skill = $data_skills[skill_id]
return if skill.transformed
return if val == 0
@skill_exp[skill_id] += val
if @skill_exp[skill_id] >= @skill_next_exp[skill_id]
skill_lvup(skill_id)
end
end
#--------------------------------------------------------------------------
# ● 使用技能提升熟练度
#--------------------------------------------------------------------------
def gain_skill_exp_by_use(skill)
@gain_skill_exp = 0
if skill.is_a?(RPG::Skill) and skill.lvup_by_use?
@gain_skill_exp = skill.use_exp
end
end
#--------------------------------------------------------------------------
# ● 角色获得技能提升点数
#--------------------------------------------------------------------------
def gain_skill_res_exp(val)
@skill_res_exp += val
end
#--------------------------------------------------------------------------
# ● 返回角色的技能提升点数
#--------------------------------------------------------------------------
def res_exp
return @skill_res_exp
end
#--------------------------------------------------------------------------
# ● 判断是否能手动升级
#--------------------------------------------------------------------------
def can_lv_skill_manually?(skill)
return false unless skill.manual_lvup?
return @skill_res_exp > 0
end
def has_dmg_var?(skill_id)
return @skill_dmg_val.keys.include?(skill_id)
end
#--------------------------------------------------------------------------
# ● 手动提升熟练度
#--------------------------------------------------------------------------
def gain_skill_exp_manual(skill_id)
skill = $data_skills[skill_id]
return unless skill.manual_lvup?
val = [@skill_next_exp[skill_id], @skill_res_exp].min
@skill_res_exp -= val
gain_skill_exp(skill_id, val)
end
#--------------------------------------------------------------------------
# ● 计算使用技能后提升的最终熟练度
#--------------------------------------------------------------------------
def gain_skill_final_exp_by_use(skill, hit)
return if @gain_skill_exp == 0
@gain_skill_exp /= 2 unless hit # 若是技能落空则熟练度减半
gain_skill_exp(skill.id, @gain_skill_exp)
@gain_skill_exp = 0
end
#--------------------------------------------------------------------------
# ● 角色使用技能,技能获得熟练度
#--------------------------------------------------------------------------
alias skill_level_use_item use_item
def use_item(item)
skill_level_use_item(item)
gain_skill_exp_by_use(item)
end
#--------------------------------------------------------------------------
# ● 角色技能升级
#--------------------------------------------------------------------------
def skill_lvup(skill_id, val=1)
return unless skill_can_lvup?(skill_id)
return if $data_skills[skill_id].transformed
temp_level = @skill_level[skill_id] + val
max_level = max_skill_level(skill_id)
@skill_level[skill_id] = [temp_level, max_level].min
level = @skill_level[skill_id]
@skill_exp[skill_id] -= @skill_next_exp[skill_id]
@skill_exp[skill_id] = [@skill_exp[skill_id], 0].max
@skill_next_exp[skill_id] = @skill_exp_base[skill_id] * factorial(level)
if has_dmg_var?(skill_id)
dmg_var_id = @skill_dmg_val[skill_id]
$game_variables[dmg_var_id] = 1+(level.to_f/max_level)
end
process_skill_transform(skill_id, level)
end
#--------------------------------------------------------------------------
# ● 计算技能伤害
#--------------------------------------------------------------------------
alias skill_level_make_damage_value make_damage_value
def make_damage_value(user, item)
skill_level_make_damage_value(user, item) # 呼叫原有方法
end
def process_skill_transform(skill_id, level)
skill = $data_skills[skill_id]
return unless skill.transform_at?(level) # 判断技能是否在这个等级变化
new_skill_id = skill.transform_to(level) # 获取变化后的技能ID
skill.transformed = true
learn_skill(new_skill_id) # 学习新技能
# 将旧技能的等级、熟练度、熟练度基数、下一级熟练度转移到新技能下
$data_skills[new_skill_id].skill_level_inherit # 变化后的技能设定
@skill_level[new_skill_id] = @skill_level[skill_id]
@skill_exp[new_skill_id] = @skill_exp[skill_id]
@skill_exp_base[new_skill_id] = skill.get_exp_base
@skill_next_exp[new_skill_id] = @skill_next_exp[skill_id]
@skill_dmg_val[new_skill_id] = @skill_dmg_val[skill_id]
alter_damage_formula(new_skill_id) # 调整伤害公式
if SKILL_LVUP_NO_FORGET or skill.no_forget? # 若是设定技能升级时不遗忘旧技能
@skill_exp[new_skill_id] = 0 # 熟练度归零
else
forget_skill(skill_id) # 遗忘旧技能
# 删除旧技能的等级、熟练度、熟练度基数、下一级熟练度
@skill_level.delete(skill_id)
@skill_exp.delete(skill_id)
@skill_exp_base.delete(skill_id)
@skill_next_exp.delete(skill_id)
@skill_dmg_val.delete(skill_id)
end
end
end
class Game_Battler < Game_BattlerBase
#--------------------------------------------------------------------------
# ● 技能使用对象的效果应用
#--------------------------------------------------------------------------
alias skill_level_item_apply item_apply
def item_apply(user, item)
skill_level_item_apply(user, item) # 呼叫原有方法
return unless item.is_a?(RPG::Skill) # 不是使用技能时返回
return unless user.actor?
user.gain_skill_final_exp_by_use(item, @result.hit?) # 计算最终熟练度
end
end
class Game_Interpreter
#--------------------------------------------------------------------------
# ● 技能等级提升
#--------------------------------------------------------------------------
def gain_skill_level(actor_id, skill_id, value=1)
$game_actors[actor_id].skill_lvup(skill_id, value)
end
#--------------------------------------------------------------------------
# ● 获得技能升级点数
#--------------------------------------------------------------------------
def gain_res_exp(actor_id, value=1)
$game_actors[actor_id].gain_skill_res_exp(value)
end
end
#--------------------------------------------------------------------------
# ● 计算阶乘(计算技能下一级熟练度使用)
#--------------------------------------------------------------------------
def factorial(val)
if val <= 1
return 1
else
return factorial(val-2) + factorial(val-1)
end
end
复制代码
class Window_SkillLevel < Window_Base
include Snstar2006::Skill_LvUp
attr_reader :skill # 返回当前显示的技能
#--------------------------------------------------------------------------
# ● 初始化
#--------------------------------------------------------------------------
def initialize(x, y, actor, skill=nil)
super(x, y, Graphics.width/2, fitting_height(6))
@actor = actor
[url=home.php?mod=space&uid=260100]@skill[/url] = skill
end
#--------------------------------------------------------------------------
# ● 设定显示的技能
#--------------------------------------------------------------------------
def skill=(skill)
#return if @skill == skill
@skill = skill
refresh
end
#--------------------------------------------------------------------------
# ● 设定当前显示的角色
#--------------------------------------------------------------------------
def actor=(actor)
return if @actor == actor
@actor = actor
refresh
end
#--------------------------------------------------------------------------
# ● 窗口刷新
#--------------------------------------------------------------------------
def refresh
contents.clear
return unless @skill
draw_skill_name(@skill, 0, 0)
if @skill.can_lvup?
draw_skill_max_level(@skill, 24, line_height)
draw_skill_exp(@skill, 24, line_height*2)
draw_actor_res_exp(24, line_height*3)
draw_skill_transform(@skill, 24, line_height*4)
else
text = "此技能无法升级"
draw_text(24, line_height, text_width(text), line_height, text)
end
end
#--------------------------------------------------------------------------
# ● 绘制技能名称
#--------------------------------------------------------------------------
def draw_skill_name(skill, x, y, enabled = true)
return unless skill
return unless skill.is_a?(RPG::Skill)
draw_icon(skill.icon_index, x, y, enabled)
change_color(normal_color, enabled)
skill_name = skill.name
skill_name += " (#{@actor.skill_level(skill.id)}级)" if skill.can_lvup?
text = skill_name
draw_text(x + 24, y, text_width(text), line_height, text)
end
#--------------------------------------------------------------------------
# ● 绘制技能最高等级
#--------------------------------------------------------------------------
def draw_skill_max_level(skill, x, y)
return unless skill.can_lvup?
change_color(system_color)
text = "最高等级"
draw_text(x, y, text_width(text), line_height, text)
change_color(normal_color)
text = "#{skill.max_level} 级"
draw_text(x+108, y, text_width(text), line_height, text)
end
#--------------------------------------------------------------------------
# ● 绘制技能熟练度
#--------------------------------------------------------------------------
def draw_skill_exp(skill, x, y)
return unless skill.can_lvup?
return if skill.transformed
change_color(system_color)
text = SKILL_EXP_VOCAB
draw_text(x, y, text_width(text), line_height, text)
change_color(normal_color)
color1 = text_color(18)
color2 = text_color(20)
current = @actor.skill_exp(skill.id)
if @actor.skill_can_lvup?(skill.id)
max = @actor.skill_next_exp(skill.id)
rate = current.to_f / max
draw_gauge(x+103, y, 120, rate, color1, color2)
draw_current_and_max_values(x+76, y, 150, current, max, normal_color, normal_color)
else
draw_current_and_max_values(x+76, y, 150, "--", "--", normal_color, normal_color)
end
end
#--------------------------------------------------------------------------
# ● 绘制技能变化技
#--------------------------------------------------------------------------
def draw_skill_transform(skill, x, y)
return unless skill.transform?
change_color(system_color)
level = skill.transform_at
new_skill = $data_skills[skill.transform_to(level)]
text = sprintf("升至%s级则习得", level)
draw_text(x, y, text_width(text), line_height, text)
change_color(normal_color)
draw_item_name(new_skill, x+12, y+line_height)
end
def draw_actor_res_exp(x, y)
enabled = @skill.manual_lvup?
text = SKILL_REXP_VOCAB
change_color(system_color, enabled)
draw_text(x, y, text_width(text), line_height, text)
change_color(normal_color, enabled)
text = @actor.res_exp
draw_text(x+108, y, text_width(text), line_height, text)
end
#--------------------------------------------------------------------------
# ● 获得文字宽度
#--------------------------------------------------------------------------
def text_width(text)
return text_size(text).width*1.5
end
end
class Window_SkillList < Window_Selectable
include Snstar2006::Skill_LvUp
attr_reader :skill_level_window # 返回技能等级窗口
#--------------------------------------------------------------------------
# ● 选择技能
#--------------------------------------------------------------------------
alias skill_level_select select
def select(index)
skill_level_select(index)
if !$game_party.in_battle
@skill_level_window.skill = item
@skill_level_window.refresh
if index % 2 == 0
@skill_level_window.x = Graphics.width/2
else
@skill_level_window.x = 0
end
end
end
#--------------------------------------------------------------------------
# ● 设定技能等级窗口
#--------------------------------------------------------------------------
def skill_level_window=(skill_level_window)
@skill_level_window = skill_level_window
call_skill_level
end
#--------------------------------------------------------------------------
# ● 呼叫技能窗口更新
#--------------------------------------------------------------------------
def call_skill_level
update_skill_level if active && @skill_level_window
end
#--------------------------------------------------------------------------
# ● 技能窗口更新
#--------------------------------------------------------------------------
def update_skill_level
@skill_level_window.clear
end
alias skill_level_deactivate deactivate
def deactivate
skill_level_deactivate
return unless @skill_level_window
@skill_level_window.hide
end
alias skill_level_activate activate
def activate
skill_level_activate
return unless @skill_level_window
@skill_level_window.show
end
#--------------------------------------------------------------------------
# ● 处理句柄
#--------------------------------------------------------------------------
alias skill_level_process_handling process_handling
def process_handling
skill_level_process_handling
return manual_skill_lvup if Input.trigger?(SKILL_MAN_LVUP_KEY)
end
#--------------------------------------------------------------------------
# ● 执行手动升级
#--------------------------------------------------------------------------
def manual_skill_lvup
if item.manual_lvup? && @actor.can_lv_skill_manually?(item)
Sound.play_ok
@actor.gain_skill_exp_manual(item.id)
refresh
@skill_level_window.skill = item
else
Sound.play_buzzer
end
Input.update
end
end
class Scene_Skill < Scene_ItemBase
#--------------------------------------------------------------------------
# ● 场景开始
#--------------------------------------------------------------------------
alias skill_level_start start
def start
skill_level_start
create_skill_level_window
@skill_level_window.z = 200
end
#--------------------------------------------------------------------------
# ● 创建技能等级窗口
#--------------------------------------------------------------------------
def create_skill_level_window
y = @help_window.height + 120
@skill_level_window = Window_SkillLevel.new(Graphics.width/2, y, @actor)
@item_window.skill_level_window = @skill_level_window
@skill_level_window.hide
end
end
复制代码
第2个184行 我去IE怎么把工具栏给吃了……
作者:
taroxd
时间:
2015-1-25 16:10
sonicdonggua 发表于 2015-1-24 22:41
第2个184行 我去IE怎么把工具栏给吃了……
在 184 行之前加一句 return unless item 试试看
不保证能解决
欢迎光临 Project1 (https://rpg.blue/)
Powered by Discuz! X3.1