赞 | 0 |
VIP | 0 |
好人卡 | 0 |
积分 | 1 |
经验 | 1430 |
最后登录 | 2017-9-30 |
在线时间 | 32 小时 |
Lv1.梦旅人
- 梦石
- 0
- 星屑
- 50
- 在线时间
- 32 小时
- 注册时间
- 2017-9-3
- 帖子
- 26
|
加入我们,或者,欢迎回来。
您需要 登录 才可以下载或查看,没有帐号?注册会员
x
本帖最后由 星辰007 于 2017-9-5 22:24 编辑
多脚本结合
脚本一:技能熟练升级及其界面绘制
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 < 1
@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
脚本2:关于物品制造
#encoding:utf-8
#==============================================================================
# 本腳本來自www.66RPG.com,使用和轉載請保留此信息
#==============================================================================
#==============================================================================
#
#每添加一个制造的类型,最上面的类别菜单就会多一项。
#
#添加类型的方法是:
#$game_party.add_cook_type(类别名称,类别介绍, 类别状态-默认false)
#
#举例:
#$game_party.add_cook_type("制药","调配药品", true)
#
#添加配方的方法:
#$game_party.add_cookbook(配方名称, 配方介绍, 配方类别名称,材料的二维数组,产出物的二维数组,配方状态)
#
#举例:
#$game_party.add_cookbook("初级补血药水", "制作初级补血药水", "制药",[[18,2]],[[1,1]],true)
#
#调用窗口的方法:SceneManager.call(Scene_Cook)
#
#
#==============================================================================
#==============================================================================
# ■ Cookbook_Type
#------------------------------------------------------------------------------
# 食谱类型类。
#==============================================================================
class Cookbook_Type
attr_reader :index
attr_reader :name
attr_reader :description
attr_reader :enabled
#--------------------------------------------------------------------------
# ● 初始化对象
#--------------------------------------------------------------------------
def initialize(index, name, description, enabled = false)
@index = index
@name = name
@description = description
@enabled = enabled
end
def enable(en)
@enabled = en
end
end
#==============================================================================
# ■ Cookbook
#------------------------------------------------------------------------------
# 食谱类。本类在 Game_Task 类的内部使用。
# 食谱属性:食谱序号,食谱名称,食谱类型,食谱介绍,原料,成品
#==============================================================================
class Cookbook
attr_reader :index
attr_reader :name
attr_reader :description
attr_reader :type
attr_reader :input
attr_reader :output
attr_reader :enabled
#--------------------------------------------------------------------------
# ● 初始化对象
#--------------------------------------------------------------------------
def initialize(index, name, description, type, input, output, enabled = true)
@index = index
@name = name
@description = description
@type = type
@input = input
@output = output
@enabled = enabled
end
def enable(en)
@enabled = en
end
#--------------------------------------------------------------------------
# ● 查询列表中的物品
#--------------------------------------------------------------------------
def in_list?(item, list)
list.each do |arr|
return true if arr[0] == item.id
end
return false
end
#--------------------------------------------------------------------------
# ● 查询是否是材料列表中的物品
#--------------------------------------------------------------------------
def resource?(item)
in_list?(item, @input)
end
#--------------------------------------------------------------------------
# ● 查询是否是产出列表中的物品
#--------------------------------------------------------------------------
def output?(item)
in_list?(item, @output)
end
#--------------------------------------------------------------------------
# ● 查询材料需求量
#--------------------------------------------------------------------------
def amount(item, i)
if i == 0
@input.each do |arr|
return arr[1] if arr[0] == item.id
end
else
@output.each do |arr|
return arr[1] if arr[0] == item.id
end
end
return 0
end
#--------------------------------------------------------------------------
# ● 查询材料是否足够
#--------------------------------------------------------------------------
def enough?
input.each do |arr|
return false if $data_items[arr[0]] && arr[1] > $game_party.item_number($data_items[arr[0]])
end
return true
end
#--------------------------------------------------------------------------
# ● 查询某件材料是否足够
#--------------------------------------------------------------------------
def item_enough?(item)
input.each do |arr|
return false if arr[0] == item.id && arr[1] > $game_party.item_number(item)
end
return true
end
end
#==============================================================================
# ■ Game_Party
#==============================================================================
class Game_Party < Game_Unit
#--------------------------------------------------------------------------
# ● 初始化对象
#--------------------------------------------------------------------------
alias old_init initialize
def initialize
old_init
@cook_types = []
@cookbooks = []
end
#--------------------------------------------------------------------------
# ● 添加新的制造类型
#--------------------------------------------------------------------------
def add_cook_type(n, d, en)
@cook_types.push(Cookbook_Type.new(@cook_types.size, n, d, en)) if !have_cook_type?(n)
end
#--------------------------------------------------------------------------
# ● 添加新的食谱
#--------------------------------------------------------------------------
def add_cookbook(n, d, type, input, output, en)
if !have_cookbook?(n) && have_cook_type?(type)
@cookbooks.push(Cookbook.new(@cookbooks.size, n, d, type, input, output, en))
end
end
#--------------------------------------------------------------------------
# ● 判断名称为n的制造类型是否存在
#--------------------------------------------------------------------------
def have_cook_type?(n)
@cook_types.each do |x|
return true if x.name == n
end
return false
end
#--------------------------------------------------------------------------
# ● 判断名称为n的食谱是否存在
#--------------------------------------------------------------------------
def have_cookbook?(n)
@cookbooks.each do |x|
return true if x.name == n
end
return false
end
#--------------------------------------------------------------------------
# ● 返回制造类型列表
#--------------------------------------------------------------------------
def cook_types
return @cook_types
end
#--------------------------------------------------------------------------
# ● 返回食谱列表
#--------------------------------------------------------------------------
def cookbooks(type = nil)
return @cookbooks if type == nil
arr = []
@cookbooks.each do |x|
arr.push(x) if x.type == type
end
return arr
end
#--------------------------------------------------------------------------
# ● 更改序号为i的制造类型的使用状态
#--------------------------------------------------------------------------
def set_cook_type(i, en)
@cook_types.enable(en)
end
#--------------------------------------------------------------------------
# ● 更改序号为i的食谱的使用状态
#--------------------------------------------------------------------------
def set_cookbook(i, en)
@cookbooks.enable(en)
end
#--------------------------------------------------------------------------
# ● 返回制造类型数目
#--------------------------------------------------------------------------
def cook_types_size
return @cook_types.size
end
#--------------------------------------------------------------------------
# ● 查询名称为n的制造类型的描述
#--------------------------------------------------------------------------
def cook_type_description(n)
@cook_types.each do |x|
return x.description if x.name == n
end
return ""
end
end
#==============================================================================
# ■ Scene_Cook
#------------------------------------------------------------------------------
# 制造画面
#==============================================================================
class Scene_Cook < Scene_ItemBase
#--------------------------------------------------------------------------
# ● 开始处理
#--------------------------------------------------------------------------
def start
super
create_category_window
create_cookbook_window
create_description_window
create_needs_window
end
#--------------------------------------------------------------------------
# ● 生成分类窗口
#--------------------------------------------------------------------------
def create_category_window
@category_window = Window_CookCategory.new
@category_window.viewport = @viewport
@category_window.y = 0
@category_window.set_handler(:ok, method(:on_category_ok))
@category_window.set_handler(:cancel, method(:return_scene))
end
#--------------------------------------------------------------------------
# ● 生成食谱窗口
#--------------------------------------------------------------------------
def create_cookbook_window
wy = @category_window.height
wh = Graphics.height - wy
@item_window = Window_CookList.new(0, wy, Graphics.width*0.5 , wh)
@item_window.viewport = @viewport
@item_window.set_handler(:ok, method(:on_item_ok))
@item_window.set_handler(:cancel, method(:on_item_cancel))
@category_window.item_window = @item_window
end
#--------------------------------------------------------------------------
# ● 生成描述窗口
#--------------------------------------------------------------------------
def create_description_window
wy = @category_window.height
@help_window = Window_Description.new(Graphics.width*0.5, wy)
@help_window.viewport = @viewport
@item_window.help_window = @help_window
@category_window.help_window = @help_window
end
#--------------------------------------------------------------------------
# ● 生成材料窗口
#--------------------------------------------------------------------------
def create_needs_window
wy = @category_window.height + @help_window.height
wh = Graphics.height - wy
@needs_window = Window_NeedsList.new(Graphics.width*0.5, wy, Graphics.width*0.5 , wh)
#@item_window.viewport = @viewport
@item_window.needs_window = @needs_window
end
#--------------------------------------------------------------------------
# ● 分类“确定”
#--------------------------------------------------------------------------
def on_category_ok
@item_window.activate
@item_window.select_last
end
#--------------------------------------------------------------------------
# ● 食谱“确定”
#--------------------------------------------------------------------------
def on_item_ok
#$game_party.last_item.object = item
cook
end
#--------------------------------------------------------------------------
# ● 食谱“取消”
#--------------------------------------------------------------------------
def on_item_cancel
@item_window.unselect
@category_window.activate
end
#--------------------------------------------------------------------------
# ● 制造
#--------------------------------------------------------------------------
def cook
if item.enough?
play_se_for_item
use_item
@needs_window.refresh
@item_window.refresh
activate_item_window
end
end
#--------------------------------------------------------------------------
# ● 播放制作声效
#--------------------------------------------------------------------------
def play_se_for_item
Sound.play_recovery
end
#--------------------------------------------------------------------------
# ● 使用食谱
#--------------------------------------------------------------------------
def use_item
#super
#@item_window.redraw_current_item
$data_items.each do |it|
if it && !it.name.empty?
$game_party.gain_item(it,-item.amount(it,0)) if item.resource?(it)
$game_party.gain_item(it,item.amount(it,1)) if item.output?(it)
end
end
end
end
#==============================================================================
# ■ Window_CookCategory
#------------------------------------------------------------------------------
# 制造画面中,显示制造类型的窗口。
#==============================================================================
class Window_CookCategory < Window_HorzCommand
#--------------------------------------------------------------------------
# ● 定义实例变量
#--------------------------------------------------------------------------
attr_reader :item_window
#--------------------------------------------------------------------------
# ● 初始化对象
#--------------------------------------------------------------------------
def initialize
super(0, 0)
end
#--------------------------------------------------------------------------
# ● 获取窗口的宽度
#--------------------------------------------------------------------------
def window_width
Graphics.width
end
#--------------------------------------------------------------------------
# ● 获取列数
#--------------------------------------------------------------------------
def col_max
return $game_party.cook_types_size
end
#--------------------------------------------------------------------------
# ● 更新画面
#--------------------------------------------------------------------------
def update
super
#@item_window.category = current_symbol if @item_window
@item_window.category = current_data[:name] if @item_window
end
#--------------------------------------------------------------------------
# ● 生成制造列表
#--------------------------------------------------------------------------
def make_command_list
$game_party.cook_types.each do |t|
add_command(t.name, t.index, t.enabled)
end
end
#--------------------------------------------------------------------------
# ● 设置制造列表窗口
#--------------------------------------------------------------------------
def item_window=(item_window)
@item_window = item_window
update
end
#--------------------------------------------------------------------------
# ● 更新帮助内容
#--------------------------------------------------------------------------
def update_help
@help_window.set_text($game_party.cook_type_description(current_data[:name]))
end
end
#==============================================================================
# ■ Window_CookList
#------------------------------------------------------------------------------
# 任务画面中,显示已获得任务的窗口。
#==============================================================================
class Window_CookList < Window_Selectable
#--------------------------------------------------------------------------
# ● 定义实例变量
#--------------------------------------------------------------------------
attr_reader :needs_window
#--------------------------------------------------------------------------
# ● 初始化对象
#--------------------------------------------------------------------------
def initialize(x, y, width, height)
super
@data = []
@category = $game_party.cook_types_size > 0 ? $game_party.cook_types[0].name : nil
refresh
end
#--------------------------------------------------------------------------
# ● 设置分类
#--------------------------------------------------------------------------
def category=(category)
return if @category == category
@category = category
refresh
self.oy = 0
end
#--------------------------------------------------------------------------
# ● 设置材料窗口
#--------------------------------------------------------------------------
def needs_window=(needs_window)
@needs_window = needs_window
update
end
#--------------------------------------------------------------------------
# ● 获取列数
#--------------------------------------------------------------------------
def col_max
return 1
end
#--------------------------------------------------------------------------
# ● 获取项目数
#--------------------------------------------------------------------------
def item_max
@data ? @data.size : 1
end
#--------------------------------------------------------------------------
# ● 获取食谱
#--------------------------------------------------------------------------
def item
@data && index >= 0 ? @data[index] : nil
end
#--------------------------------------------------------------------------
# ● 获取选择食谱的有效状态
#--------------------------------------------------------------------------
def current_item_enabled?
enable?(@data[index])
end
#--------------------------------------------------------------------------
# ● 查询此食谱是否可用
#--------------------------------------------------------------------------
def enable?(item)
item.enabled && item.enough?
end
#--------------------------------------------------------------------------
# ● 生成食谱列表
#--------------------------------------------------------------------------
def make_item_list
@data = $game_party.cookbooks(@category)
end
#--------------------------------------------------------------------------
# ● 返回上一个选择的位置
#--------------------------------------------------------------------------
def select_last
select(0)
end
#--------------------------------------------------------------------------
# ● 绘制项目
#--------------------------------------------------------------------------
def draw_item(index)
item = @data[index]
if item
rect = item_rect(index)
rect.width -= 4
draw_item_name(item, rect.x, rect.y, enable?(item))
end
end
#--------------------------------------------------------------------------
# ● 绘制名称
# enabled : 有效的标志。false 的时候使用半透明效果绘制
#--------------------------------------------------------------------------
def draw_item_name(item, x, y, enabled = true, width = 300)
return unless item
text = item.name
text += "[材料不足]" if !item.enough?
change_color(normal_color, enabled)
draw_text(x, y, width, line_height, text)
end
#--------------------------------------------------------------------------
# ● 更新帮助内容
#--------------------------------------------------------------------------
def update_help
@help_window.set_item(item)
end
#--------------------------------------------------------------------------
# ● 更新食谱清单
#--------------------------------------------------------------------------
def update_needslist
@needs_window.set_item(item)
end
#--------------------------------------------------------------------------
# ● 调用帮助窗口的更新方法
#--------------------------------------------------------------------------
def call_update_help
update_help if @help_window
update_needslist if @needs_window
end
#--------------------------------------------------------------------------
# ● 刷新
#--------------------------------------------------------------------------
def refresh
make_item_list
create_contents
draw_all_items
end
end
#==============================================================================
# ■ Window_Description
#------------------------------------------------------------------------------
# 显示食谱的说明的窗口
#==============================================================================
class Window_Description < Window_Base
#--------------------------------------------------------------------------
# ● 初始化对象
#--------------------------------------------------------------------------
def initialize(x, y)
super(x, y, Graphics.width*0.5, fitting_height(4))
end
#--------------------------------------------------------------------------
# ● 设置内容
#--------------------------------------------------------------------------
def set_text(text)
if text != @text
@text = text
refresh
end
end
#--------------------------------------------------------------------------
# ● 清除
#--------------------------------------------------------------------------
def clear
set_text("")
end
#--------------------------------------------------------------------------
# ● 设置食谱的介绍
#--------------------------------------------------------------------------
def set_item(item)
set_text(item ? item.description : "")
end
#--------------------------------------------------------------------------
# ● 刷新
#--------------------------------------------------------------------------
def refresh
contents.clear
draw_text_ex(4, 0, @text)
end
end
#==============================================================================
# ■ Window_NeedsList
#------------------------------------------------------------------------------
# 制造画面中,显示食谱所需材料的窗口。
#==============================================================================
class Window_NeedsList < Window_Selectable
#--------------------------------------------------------------------------
# ● 初始化对象
#--------------------------------------------------------------------------
def initialize(x, y, width, height)
super
@category = :item
@cookbook = nil
@data = []
refresh
end
#--------------------------------------------------------------------------
# ● 获取列数
#--------------------------------------------------------------------------
def col_max
return 1
end
#--------------------------------------------------------------------------
# ● 获取项目数
#--------------------------------------------------------------------------
def item_max
@data ? @data.size : 1
end
#--------------------------------------------------------------------------
# ● 获取物品
#--------------------------------------------------------------------------
def item
@data && index >= 0 ? @data[index] : nil
end
#--------------------------------------------------------------------------
# ● 查询列表中是否含有此物品
#--------------------------------------------------------------------------
def include?(item)
item.is_a?(RPG::Item) && !item.key_item?
end
#--------------------------------------------------------------------------
# ● 获取选择食谱的有效状态
#--------------------------------------------------------------------------
def current_item_enabled?
enable?(@data[index])
end
#--------------------------------------------------------------------------
# ● 查询此食谱是否可用
#--------------------------------------------------------------------------
def enable?(item)
$game_party.usable?(item) && @cookbook.item_enough?(item)
end
#--------------------------------------------------------------------------
# ● 生成物品列表
#--------------------------------------------------------------------------
def make_item_list
@data = []
return if @cookbook== nil
tmp1 = []
tmp2 = []
$data_items.each do |item|
tmp1.push([item, 0]) if item && !item.name.empty? && @cookbook.resource?(item)
tmp2.push([item, 1]) if item && !item.name.empty? && @cookbook.output?(item)
end
if tmp1.size > 0 && tmp2.size > 0
@data.push(["需要材料:",0])
@data += tmp1
@data.push(["可以获得:",1])
@data += tmp2
end
end
#--------------------------------------------------------------------------
# ● 返回上一个选择的位置
#--------------------------------------------------------------------------
def select_last
select(0)
end
#--------------------------------------------------------------------------
# ● 绘制项目
#--------------------------------------------------------------------------
def draw_item(index)
item = @data[index]
if item
rect = item_rect(index)
rect.width -= 4
if item[0].is_a?(RPG::Item)
draw_item_name(item, rect.x, rect.y, enable?(item[0]))
draw_item_number(rect, item[0])
else
draw_input_output(item, rect.x, rect.y)
end
end
end
#--------------------------------------------------------------------------
# ● 绘制物品名称
# enabled : 有效的标志。false 的时候使用半透明效果绘制
#--------------------------------------------------------------------------
def draw_item_name(item, x, y, enabled = true, width = 172)
return unless item
text = item[0].name + "*" + String(@cookbook.amount(item[0], item[1]))
draw_icon(item[0].icon_index, x, y, enabled)
change_color(normal_color, enable?(item[0]))
draw_text(x + 24, y, width, line_height, text)
end
#--------------------------------------------------------------------------
# ● 绘制输入和产出
#--------------------------------------------------------------------------
def draw_input_output(item, x, y, enabled = false, width = 172)
return unless item
if item[1] == 0
text = "[需要]"
else
text = "[可以获得]"
end
change_color(normal_color, @cookbook.enough?)
draw_text(x , y, width, line_height, text)
end
#--------------------------------------------------------------------------
# ● 绘制物品个数
#--------------------------------------------------------------------------
def draw_item_number(rect, item)
draw_text(rect, sprintf("现有%2d", $game_party.item_number(item)), 2)
end
#--------------------------------------------------------------------------
# ● 刷新
#--------------------------------------------------------------------------
def refresh
make_item_list
create_contents
draw_all_items
end
#--------------------------------------------------------------------------
# ● 设置食谱的材料
#--------------------------------------------------------------------------
def set_item(item)
@cookbook = item
refresh
end
end
#==============================================================================
# 本腳本來自www.66RPG.com,使用和轉載請保留此信息
#==============================================================================
# add by Sion 2013.12.17
# 作者修改了原范例的菜单,但是在原系统脚本里改的。
# 整理出来写在这里, 不需要改菜单的同学把这些删掉就可以。
class Scene_Menu
def command_cook
SceneManager.call(Scene_Cook)
end
alias_method :s20131217_create_command_window, :create_command_window
def create_command_window
s20131217_create_command_window
@command_window.set_handler(:cook, method(:command_cook))
end
end
class Window_MenuCommand
alias_method :s20131217_add_main_commands, :add_main_commands
def add_main_commands
s20131217_add_main_commands
add_command("制造", :cook, main_commands_enabled)
end
end
就是这俩脚本,看看问题出现在哪??? |
|