设为首页收藏本站|繁體中文

Project1

 找回密码
 注册会员
搜索
查看: 1232|回复: 3
打印 上一主题 下一主题

[已经解决] 合成物品脚本出错求解

[复制链接]

Lv2.观梦者

梦石
0
星屑
592
在线时间
268 小时
注册时间
2014-7-5
帖子
157
跳转到指定楼层
1
发表于 2015-2-17 16:15:40 | 只看该作者 回帖奖励 |倒序浏览 |阅读模式

加入我们,或者,欢迎回来。

您需要 登录 才可以下载或查看,没有帐号?注册会员

x
本帖最后由 RyanBern 于 2015-2-17 17:31 编辑

RUBY 代码复制
  1. #==============================================================================
  2. # 本脚本来自[url]www.66RPG.com[/url],使用和转载请保留此信息
  3. # 欢迎访问[url]www.66RPG.com[/url]
  4. # 梦想世界,在你手中
  5. #==============================================================================  
  6. #
  7. # Sample master list for crafting script (物品分类增强版) v1.1
  8. # written by Deke
  9. # 增强:叶子
  10. #
  11. # 12-30-2005 v1.0
  12. # 8-17-2006 v1.1
  13. # 修正了返回界面时不显示成品的BUG
  14. # 修正了材料大于8个不显示的BUG
  15. # 描绘物品美化
  16. # 自动检测能否合成
  17. #============================================================================================
  18. # 简介:
  19. # 这是一个很不错的合成物品系统,可以通过游戏的过程,不断学习可以合成的
  20. # 物品方法。
  21. # ------
  22. # 增强版补充说明:
  23. # 在这个增强版中,可以对成品进行手动分类。
  24. # 成品增加了一个分类属性。
  25. # 这个分类纯粹是按自己的意愿,没有规定第几类必须是什么。
  26. # 召唤特定分类的界面,就只会看到特定分类的成品。
  27. #
  28. # 例如:
  29. # 使用脚本$scene = Scene_Craft.new(1),
  30. # 出来的界面就只会显示成品分类为1的东西
  31. # 同样道理,使用脚本$scene = Scene_Craft.new(2),
  32. # 出来的界面就只会显示成品分类为2的东西
  33. #
  34. # 如果使用脚本$scene = Scene_Craft.new或$scene = Scene_Craft.new(0)来召唤界面
  35. # 就可以看到所有成品。
  36. #
  37. # 注意:不要弄混淆“成品种类”和“成品分类”
  38. # 成品种类是指成品是普通物品(0),防具(1)或武器(2)
  39. # 成品分类是指此物品的自定义分类
  40. #
  41. #
  42. # 使用方法:
  43. # 1、召唤界面:使用脚本$scene = Scene_Craft.new(分类的数字)
  44. # 例如:使用脚本$scene = Scene_Craft.new(1),出来分类1的界面
  45. #
  46. # 2、学习合成:$game_party.learn_recipe(合成项目)
  47. #
  48. #  2.1、其实这个脚本可以使同一成品有不同配方
  49. #
  50. #    就这样说可能解释得不清楚,先来解释一下脚本学习配方的原理:
  51. #    $game_party.learn_recipe(合成项目)的处理过程并不是直接学习这个配方,
  52. #    而是在配方库中找到和合成项目成品相同的配方。
  53. #
  54. #    如果配方库中有两个配方成品相同的话,配方版本就变得重要。
  55. #    $game_party.learn_recipe(合成项目,配方版本)
  56. #    配方版本为1的话,学到的配方就是@recipe_list[xx]中与合成项目成品相同且数字最小的配方
  57. #    配方版本为2的话,学到的配方就是数字第二小的配方
  58. #    在上面这个脚本语句中,不填配方版本的话就默认为1
  59. #
  60. #  2.2、忘记配方:$game_party.forget_recipe(合成项目)
  61. #   2.21、同样道理,这个语句也可以写配方版本
  62. #    $game_party.forget_recipe(合成项目,配方版本)
  63. #    配方版本定义见2.1
  64. #
  65. #  2.3、配方版本不能乱填!例如游戏中某一个配方的成品是唯一的,与所有其它配方的成品都不相同
  66. #   那么学习的时候就不用填配方版本。
  67. #   如果这时在配方版本填了2的话,就有可能学不到或者忘不了(-_-||)
  68. #   
  69. #
  70. # 3、合成定义:
  71. # 这个合成脚本可以定义两种合成物品。一种是预先定义好了的,就像下面这样,
  72. # 直接写在这里就可以,另一种是在学习之前现场定义。
  73. #
  74. # 4、举例
  75. #  4.1、学会recipe_list[1]定义的合成:$game_party.learn_recipe($game_temp.recipe_list[1])
  76. #       注意,一行如果输入不下,在(的后面或[的后面按回车换行,否则可能出错
  77. #
  78. #  4.2、在游戏中临时定义一种合成,让玩家学会。使用事件中的脚本如下,   
  79. #  脚本:
  80. #    材料 = [$game_variables[1],$game_variables[2]]  #——材料编号是变量1、2的编号
  81. #    材料种类 = [0,0]                                #——材料是物品
  82. #    材料数量 = [$game_variables[3],$game_variables[4]]  #——需要材料数量是变量3、4的编号
  83. #    成品 = $game_variables[5]                       #——获得结果编号是5
  84. #    成品种类 = 1                                    #——成品是防具类
  85. #    成品分类 = 1                                    #——这一项不写的话默认为0
  86. #    $game_party.learn_recipe(Game_Recipe.new(材料,材料种类,材料数量,成品,成品种类,成品分类))
  87. #    上面这条语句的成品分类这一项不写也行,这样它就默认为0了。
  88. #    (也就是此物品没有分类,不会在分类菜单中出现)
  89. #    省略成品分类的脚本语句可以像下面这样写:
  90. #    $game_party.learn_recipe(Game_Recipe.new(材料,材料种类,材料数量,成品,成品种类))
  91. #
  92. #===========================================================================================
  93. class Game_Temp
  94.   attr_reader :recipe_list  
  95.   alias crafting_temp_initialize initialize
  96.   def initialize
  97.     crafting_temp_initialize
  98.     @recipe_list=[]
  99.     get_recipe_list
  100.   end  
  101.   def get_recipe_list   
  102.     ##########################################################################
  103.     # 1 号合成物品设定 (铃铛×1 + 上古时代的铜锣烧×2  = 大般若长光) 成品分类:1
  104.     ##########################################################################
  105.     材料 = [11, 23]             # 需要材料的数据库编号
  106.     材料种类 = [0, 0]         # 需要材料的种类,0是普通物品,1是防具,2是武器
  107.     材料数量 = [1, 2]         # 需要材料的数量
  108.     成品 = 3                  # 获得物品编号
  109.     成品种类 = 2              # 获得物品种类,0是普通物品,1是防具,2是武器
  110.     成品分类 = 1              # 获得成品分类
  111.     @recipe_list[1] = Game_Recipe.new(材料,材料种类, 材料数量,成品,成品种类,成品分类)
  112.         ##########################################################################
  113.     # 2 号合成物品设定 (徽章×1 + 能弯曲的光线×2  = 弹射空气炮) 成品分类:1
  114.     ##########################################################################
  115.     材料 = [12, 24]             # 需要材料的数据库编号
  116.     材料种类 = [0, 0]         # 需要材料的种类,0是普通物品,1是防具,2是武器
  117.     材料数量 = [1, 2]         # 需要材料的数量
  118.     成品 = 12                  # 获得物品编号
  119.     成品种类 = 2              # 获得物品种类,0是普通物品,1是防具,2是武器
  120.     成品分类 = 1              # 获得成品分类
  121.     @recipe_list[2] = Game_Recipe.new(材料,材料种类, 材料数量,成品,成品种类,成品分类)
  122.         ##########################################################################
  123.     # 3 号合成物品设定 (黄牌×1 + 吃了就死的钙片×2  = 坚固的足球) 成品分类:1
  124.     ##########################################################################
  125.     材料 = [13, 22]             # 需要材料的数据库编号
  126.     材料种类 = [0, 0]         # 需要材料的种类,0是普通物品,1是防具,2是武器
  127.     材料数量 = [1, 2]         # 需要材料的数量
  128.     成品 = 22                  # 获得物品编号
  129.     成品种类 = 2              # 获得物品种类,0是普通物品,1是防具,2是武器
  130.     成品分类 = 1              # 获得成品分类
  131.     @recipe_list[3] = Game_Recipe.new(材料,材料种类, 材料数量,成品,成品种类,成品分类)
  132.         ##########################################################################
  133.     # 4 号合成物品设定 (牛角×1 + 马竹的眼睛×2  = 西洋剑) 成品分类:1
  134.     ##########################################################################
  135.     材料 = [14, 21]             # 需要材料的数据库编号
  136.     材料种类 = [0, 0]         # 需要材料的种类,0是普通物品,1是防具,2是武器
  137.     材料数量 = [1, 2]         # 需要材料的数量
  138.     成品 = 32                  # 获得物品编号
  139.     成品种类 = 2              # 获得物品种类,0是普通物品,1是防具,2是武器
  140.     成品分类 = 1              # 获得成品分类
  141.     @recipe_list[4] = Game_Recipe.new(材料,材料种类, 材料数量,成品,成品种类,成品分类)
  142.             ##########################################################################
  143.     # 5 号合成物品设定 (酱油×1 + 六芒星护身符×2  = 少林棍) 成品分类:1
  144.     ##########################################################################
  145.     材料 = [15, 25]             # 需要材料的数据库编号
  146.     材料种类 = [0, 0]         # 需要材料的种类,0是普通物品,1是防具,2是武器
  147.     材料数量 = [1, 2]         # 需要材料的数量
  148.     成品 = 42                  # 获得物品编号
  149.     成品种类 = 2              # 获得物品种类,0是普通物品,1是防具,2是武器
  150.     成品分类 = 1              # 获得成品分类
  151.     @recipe_list[5] = Game_Recipe.new(材料,材料种类, 材料数量,成品,成品种类,成品分类)
  152.             ##########################################################################
  153.     # 6 号合成物品设定 (围巾×1 + 海中产的海星梨海星梨×2  = 羊角匕) 成品分类:1
  154.     ##########################################################################
  155.     材料 = [16, 19]             # 需要材料的数据库编号
  156.     材料种类 = [0, 0]         # 需要材料的种类,0是普通物品,1是防具,2是武器
  157.     材料数量 = [1, 2]         # 需要材料的数量
  158.     成品 = 52                  # 获得物品编号
  159.     成品种类 = 2              # 获得物品种类,0是普通物品,1是防具,2是武器
  160.     成品分类 = 1              # 获得成品分类
  161.     @recipe_list[6] = Game_Recipe.new(材料,材料种类, 材料数量,成品,成品种类,成品分类)
  162.                 ##########################################################################
  163.     # 7 号合成物品设定 (笛子×1 + 六芒星护身符×2  = 红骨笛) 成品分类:1
  164.     ##########################################################################
  165.     材料 = [17, 25]             # 需要材料的数据库编号
  166.     材料种类 = [0, 0]         # 需要材料的种类,0是普通物品,1是防具,2是武器
  167.     材料数量 = [1, 2]         # 需要材料的数量
  168.     成品 = 62                  # 获得物品编号
  169.     成品种类 = 2              # 获得物品种类,0是普通物品,1是防具,2是武器
  170.     成品分类 = 1              # 获得成品分类
  171.     @recipe_list[7] = Game_Recipe.new(材料,材料种类, 材料数量,成品,成品种类,成品分类)
  172.                 ##########################################################################
  173.     # 8 号合成物品设定 (金杖×1 + 核能结晶×2  = 黄金的权杖) 成品分类:1
  174.     ##########################################################################
  175.     材料 = [18, 20]             # 需要材料的数据库编号
  176.     材料种类 = [0, 0]         # 需要材料的种类,0是普通物品,1是防具,2是武器
  177.     材料数量 = [1, 2]         # 需要材料的数量
  178.     成品 = 72                  # 获得物品编号
  179.     成品种类 = 2              # 获得物品种类,0是普通物品,1是防具,2是武器
  180.     成品分类 = 1              # 获得成品分类
  181.     @recipe_list[8] = Game_Recipe.new(材料,材料种类, 材料数量,成品,成品种类,成品分类)
  182.    end # of get_recipe_list method
  183. end # of updates to Game_Temp Class
  184.  
  185. #================================
  186. # CRAFTING PROGRAM
  187. #----------------------------------------------------------------
  188. #-written by Deke
  189. #-yes_no window code created by Phsylomortis
  190. #----------------------------------------------------------------
  191. #================================
  192.  
  193. #updates to Game_Party class
  194.  
  195. class Game_Party
  196.  
  197.   attr_accessor       :recipes
  198.  
  199.   alias crafting_party_initialize initialize
  200.  
  201.   def initialize
  202.     crafting_party_initialize
  203.     @recipes=[]
  204.   end
  205.  
  206.   #----------------------------------------------------------------------
  207.   def know?(recipe, version = 1)
  208.     unless recipe.is_a?(Game_Recipe)
  209.       recipe = get_recipe_from_master_list(recipe, version)
  210.     end
  211.     return $game_party.recipes.include?(recipe)
  212.   end
  213.  
  214. #----------------------------------------------------------------------
  215.   def learn_recipe(recipe , version = 1)
  216.     unless recipe.is_a?(Game_Recipe)
  217.       recipe = get_recipe_from_master_list(recipe, version)
  218.     end
  219.     if recipe.is_a?(Game_Recipe)
  220.       unless know?(recipe)
  221.         @recipes.push(recipe)
  222.       end
  223.     end
  224.   end
  225.  
  226. #----------------------------------------------------------------------
  227.   def forget_recipe(recipe , version = 1)
  228.     if !recipe.is_a?(Game_Recipe)
  229.       recipe = get_recipe_from_master_list(recipe, version)
  230.     end
  231.     if recipe.is_a?(Game_Recipe)
  232.       for i in [email]0...@recipes.size[/email]
  233.         if recipe == @recipes[i]
  234.           index = i
  235.           break
  236.         end
  237.       end
  238.       if index != nil
  239.         @recipes.delete(@recipes[index])
  240.       end
  241.     end
  242.   end
  243.  
  244. #----------------------------------------------------------------------
  245.   def get_recipe_from_master_list(item, version)
  246.     index = nil
  247.     for i in 0...$game_temp.recipe_list.size
  248.       if item[0] == $game_temp.recipe_list[i].result and item[1] ==$game_temp.recipe_list[i].result_type
  249.         version -= 1
  250.         if version == 0
  251.           index = i
  252.           break
  253.         end
  254.       end
  255.     end
  256.     if index.is_a?(Integer)
  257.       return ($game_temp.recipe_list[index])
  258.     else
  259.       return false
  260.     end
  261.   end
  262.  
  263. end # of Game_Party updates
  264.  
  265. #================================
  266. class Game_Recipe
  267.  
  268.   attr_reader :ingredients
  269.   attr_reader :quantities
  270.   attr_reader :result
  271.   attr_reader :result_type
  272.   attr_reader :ingredient_types
  273.   attr_reader :craft_type  #物品分类
  274.  
  275. #----------------------------------------------------------------------
  276.   def initialize( ingredients, ingredient_types, quantities, result, result_type, craft_type=0)
  277.     @ingredients = ingredients
  278.     @ingredient_types = ingredient_types
  279.     @quantities = quantities
  280.     @result = result
  281.     @result_type = result_type
  282.     @craft_type = craft_type
  283.   end
  284.  
  285. #----------------------------------------------------------------------
  286.   def name
  287.     case @result_type
  288.       when 0
  289.         name = $data_items[@result].name
  290.       when 1
  291.         name = $data_armors[@result].name
  292.       when 2
  293.         name = $data_weapons[@result].name
  294.     end
  295.     return name
  296.   end
  297.  
  298. #----------------------------------------------------------------------
  299.  
  300.   def item
  301.     case @result_type
  302.       when 0
  303.         item = $data_items[@result]
  304.       when 1
  305.         item = $data_armors[@result]
  306.       when 2
  307.         item = $data_weapons[@result]
  308.     end
  309.     return item
  310.   end
  311.  
  312. #----------------------------------------------------------------------
  313.   def have
  314.     have_all = true
  315.     for i in [email]0...@ingredients.size[/email]
  316.       case @ingredient_types[i]
  317.         when 0
  318.           if $game_party.item_number(@ingredients[i]) < @quantities[i]
  319.             have_all=false
  320.           end
  321.         when 1
  322.           if $game_party.armor_number(@ingredients[i]) < @quantities[i]
  323.             have_all=false
  324.           end
  325.         when 2
  326.           if $game_party.weapon_number(@ingredients[i]) < @quantities[i]
  327.             have_all=false
  328.           end
  329.       end
  330.     end
  331.     return have_all
  332.   end
  333.  
  334. #----------------------------------------------------------------------
  335.   def decrement
  336.     for i in [email]0...@ingredients.size[/email]
  337.       case @ingredient_types[i]
  338.       when 0
  339.         $game_party.lose_item(@ingredients[i], @quantities[i])
  340.       when 1
  341.         $game_party.lose_armor(@ingredients[i], @quantities[i])
  342.       when 2
  343.         $game_party.lose_weapon(@ingredients[i], @quantities[i])
  344.       end
  345.     end
  346.   end
  347.  
  348. #----------------------------------------------------------------------
  349.   def make
  350.     if have
  351.       case @result_type
  352.       when 0
  353.         $game_party.gain_item(@result, 1)
  354.       when 1
  355.         $game_party.gain_armor(@result, 1)
  356.       when 2
  357.         $game_party.gain_weapon(@result, 1)
  358.       end
  359.       decrement
  360.     end
  361.   end
  362.  
  363. #----------------------------------------------------------------------
  364.   def == (recipe)
  365.     if recipe.is_a?(Game_Recipe)
  366.       equal = true
  367.       if recipe.ingredients != self.ingredients
  368.         equal = false
  369.       end
  370.       if recipe.ingredient_types != self.ingredient_types
  371.         equal = false
  372.       end
  373.       if recipe.quantities != self.quantities
  374.         equal = false
  375.       end
  376.       if recipe.result != self.result
  377.         equal=false
  378.       end
  379.       if recipe.result_type != self.result_type
  380.         equal = false
  381.       end
  382.     else
  383.       equal = false
  384.     end
  385.     return equal
  386.   end
  387.  
  388. end # of Game_Recipe class
  389.  
  390. #===================================
  391.  
  392. class Window_Craft < Window_Selectable
  393.   attr_reader :data #声明数据
  394.   #--------------------------------------------------------------------------
  395.   def initialize(craft_type=0)
  396.     @craft_type = craft_type
  397.     super(0, 64, 240, 416)
  398.     @column_max = 1
  399.     refresh
  400.     self.index = 0
  401.   end
  402.  
  403.   #--------------------------------------------------------------------------
  404.   def recipe
  405.     return @data[self.index]
  406.   end
  407.  
  408.   #--------------------------------------------------------------------------
  409.   def refresh
  410.     if self.contents != nil
  411.       self.contents.dispose
  412.       self.contents = nil
  413.     end
  414.     @data = []
  415.     for i in 0...$game_party.recipes.size
  416.        #@craft_type为0时就显示全部物品
  417.        #不为0时就显示对应物品
  418.       if @craft_type == 0
  419.         @data.push($game_party.recipes[i])
  420.       elsif $game_party.recipes[i].craft_type == @craft_type
  421.         @data.push($game_party.recipes[i])
  422.       end
  423.     end
  424.     @item_max = @data.size
  425.     if @item_max > 0
  426.       self.contents = Bitmap.new(width - 32, row_max * 32)
  427.       self.contents.font.name = "黑体" # = "黑体"
  428.       self.contents.font.size = 18 # = 18
  429.       for i in 0...@item_max
  430.         x = 16
  431.         y = i * 32
  432.         able = true
  433.         for ingredient in 0...@data[i].ingredients.size
  434.           case @data[i].ingredient_types[ingredient]
  435.           when 0
  436.             count = $game_party.item_number(@data[i].ingredients[ingredient])
  437.           when 1
  438.             count = $game_party.armor_number(@data[i].ingredients[ingredient])
  439.           when 2
  440.             count = $game_party.weapon_number(@data[i].ingredients[ingredient])
  441.           end
  442.           if count < @data[i].quantities[ingredient]
  443.             able = false
  444.             break
  445.           end
  446.         end
  447.         draw_item_name(@data[i].item, x, y, able)
  448.       end
  449.     end
  450.   end
  451.  
  452.   #--------------------------------------------------------------------------
  453.   #def draw_item(index)
  454.   #  recipe = @data[index]
  455.   #  self.contents.font.color = recipe.have ? normal_color : disabled_color
  456.   #  x = 16
  457.   #  y = index * 32
  458.   #  self.contents.draw_text(x , y, self.width-32, 32, recipe.name, 0)
  459.   #end
  460.  
  461.   #--------------------------------------------------------------------------
  462.   # ● 描绘物品名
  463.   #     item : 物品
  464.   #     x    : 描画目标 X 坐标
  465.   #     y    : 描画目标 Y 坐标
  466.   #--------------------------------------------------------------------------
  467.   def draw_item_name(item, x, y, able = true)
  468.     if item == nil
  469.       return
  470.     end
  471.     if !able
  472.       self.contents.font.color = disabled_color
  473.     end
  474.     bitmap = RPG::Cache.icon(item.icon_name)
  475.     self.contents.blt(x, y + 4, bitmap, Rect.new(0, 0, 24, 24))
  476.     self.contents.draw_text(x + 28, y, 212, 32, item.name)
  477.     self.contents.font.color = normal_color
  478.   end
  479.  
  480.   #--------------------------------------------------------------------------
  481.   def update_help
  482.     current_recipe = recipe
  483.     if current_recipe.is_a?(Game_Recipe)
  484.     case current_recipe.result_type
  485.       when 0
  486.         description = $data_items[current_recipe.result].description
  487.       when 1
  488.         description = $data_armors[current_recipe.result].description
  489.       when 2
  490.         description = $data_weapons[current_recipe.result].description
  491.       end
  492.     else
  493.       description = ""
  494.     end
  495.     @help_window.set_text(description)
  496.     @help_window.update
  497.   end
  498.  
  499. end # of Window_Craft
  500.  
  501. #=======================================
  502. class Window_CraftResult < Window_Base
  503.  
  504.   #--------------------------------------------------------------------------
  505.   def initialize
  506.     super(240, 64, 400, 184)
  507.     self.contents = Bitmap.new(width - 32, height - 32)
  508.     self.contents.font.name = "黑体" # = $fontface.is_a?(String) ? $fontface : $defaultfonttype
  509.     self.contents.font.size = 18 # = 20
  510.     @result = nil
  511.     @type = nil
  512.   end
  513.  
  514.   #--------------------------------------------------------------------------
  515.   def refresh
  516.     self.contents.clear
  517.     case @type
  518.       when 0
  519.         item = $data_items[@result]
  520.         if item.recover_hp_rate > item.recover_hp
  521.           hp_string = "HP回复率:"
  522.           hp_stat = item.recover_hp_rate
  523.         else
  524.           hp_string = "HP回复量:"
  525.           hp_stat = item.recover_hp
  526.         end
  527.         if item.recover_sp_rate > item.recover_sp
  528.           sp_string = "SP回复率:"
  529.           sp_stat = item.recover_sp_rate
  530.         else
  531.           sp_string = "SP回复量:"
  532.           sp_stat = item.recover_sp
  533.         end
  534.         @strings = [hp_string, sp_string, "物理防御:" , "魔法防御:", "命中率:", "分散度:"]
  535.         @stats = [hp_stat, sp_stat, item. pdef_f, item.mdef_f, item.hit, item.variance,
  536.                        $game_party.item_number(@result)]
  537.         @bitmap = RPG::Cache.icon(item.icon_name)
  538.       when 1
  539.         item = $data_armors[@result]
  540.         @strings = ["物理防御:", "魔法防御:", "回避修正:", "力量增加:", "灵巧增加:",
  541.                        "速度增加:", "魔力增加:"]
  542.         @stats = [item.pdef, item.mdef, item.eva, item.str_plus, item.dex_plus,
  543.                     item.agi_plus, item.int_plus, $game_party.armor_number(@result) ]
  544.         @bitmap = RPG::Cache.icon(item.icon_name)
  545.       when 2
  546.         item = $data_weapons[@result]
  547.         @strings =["攻击力:", "物理防御:", "魔法防御:", "力量增加:", "灵巧增加:",
  548.                     "速度增加:", "魔力增加:"]
  549.         @stats = [item.atk, item.pdef, item.mdef, item.str_plus, item.dex_plus,
  550.                     item.agi_plus, item.int_plus, $game_party.weapon_number(@result) ]
  551.         @bitmap = RPG::Cache.icon(item.icon_name)
  552.     end
  553.     for i in [email]0...@strings.size[/email]
  554.       x = i%2 * 184
  555.       y = i /2 *28 +32
  556.       self.contents.font.color = normal_color
  557.       self.contents.draw_text(x,y,100, 28,@strings[i])
  558.       self.contents.font.color = system_color
  559.       self.contents.draw_text(x + 110, y, 45, 28, @stats[i].to_s)
  560.     end
  561.     self.contents.blt(0, 0, @bitmap, Rect.new(0, 0, 24, 24), 255)
  562.     self.contents.font.color= normal_color
  563.     self.contents.draw_text(40, 0, 300, 28, "待合成物品的现有数量:")
  564.     self.contents.font.color = system_color
  565.     count = @stats[@stats.size - 1].to_s
  566.     self.contents.draw_text(294, 0, 45, 28, count )
  567.   end
  568.  
  569. #----------------------------------------------------------------------
  570.   def set_result(result , type)
  571.     @result = result
  572.     @type = type
  573.     refresh
  574.   end
  575.  
  576. end #of Window_CraftResult
  577.  
  578. #=======================================
  579. class Window_CraftIngredients < Window_Base
  580.  
  581.   #--------------------------------------------------------------------------
  582.   def initialize
  583.     super(240, 248, 400, 232)
  584.     self.contents = Bitmap.new(width - 32, height - 32)
  585.     self.contents.font.name = "黑体" # = $fontface.is_a?(String) ? $fontface : $defaultfonttype
  586.     self.contents.font.size = 18 # = 20
  587.     @ingredients = []
  588.     @types = []
  589.     @quantities = []
  590.     @item = nil
  591.     @count = 0
  592.     @counter = 0
  593.     @real_oy = 0
  594.   end
  595.  
  596.   #--------------------------------------------------------------------------
  597.   def refresh
  598.     @counter = 0
  599.     self.contents.clear
  600.     self.contents = Bitmap.new(width - 32, @ingredients.size * 26)
  601.     for i in [email]0...@ingredients.size[/email]
  602.       case @types[i]
  603.       when 0
  604.         @item = $data_items[@ingredients[i]]
  605.         @count = $game_party.item_number(@ingredients[i])
  606.       when 1
  607.         @item = $data_armors[@ingredients[i]]
  608.         @count = $game_party.armor_number(@ingredients[i])
  609.       when 2
  610.         @item = $data_weapons[@ingredients[i]]
  611.         @count = $game_party.weapon_number(@ingredients[i])
  612.       end
  613.       y = i *26
  614.       self.contents.blt(0, y, RPG::Cache.icon(@item.icon_name), Rect.new(0, 0, 24, 24), 255)
  615.       self.contents.font.color = @count >= @quantities[i] ? normal_color : disabled_color
  616.       self.contents.draw_text(30, y, 280, 28, @item.name)
  617.       self.contents.draw_text(300, y, 45, 28, @quantities[i].to_s)
  618.       self.contents.font.color = system_color
  619.       self.contents.draw_text(245, y, 45, 28, @count.to_s )     
  620.     end
  621.   end
  622.  
  623.   #--------------------------------------------------------------------------
  624.   def set_ingredients(ingredients , types, quantities)
  625.     @ingredients = ingredients
  626.     @types = types
  627.     @quantities = quantities
  628.     refresh
  629.     if @ingredients.size > 7
  630.       self.oy = -52
  631.       @real_oy = 0
  632.     else
  633.       self.oy = 0
  634.     end
  635.   end
  636.  
  637.   def update
  638.     super
  639.     @counter += 1
  640.     if @ingredients.size > 7 and @counter > 30
  641.       @real_oy = (@real_oy + 1) % ((@ingredients.size - 3) * 26)
  642.       self.oy = @real_oy - 52
  643.     end
  644.   end
  645.  
  646. end # of Window_CraftIngredients
  647.  
  648. #======================================
  649. class Scene_Craft
  650.  
  651.   #--------------------------------------------------------------------------
  652.   # @craft_type:物品种类,0就是全部
  653.   def initialize(craft_type=0,craft_index=0)
  654.     @craft_index=craft_index
  655.     @craft_type = craft_type
  656.   end
  657.  
  658.   #--------------------------------------------------------------------------
  659.   def main
  660.     @craft_window = Window_Craft.new(@craft_type)
  661.     @craft_window.index=@craft_index
  662.     @confirm_window = Window_Base.new(120, 188, 400, 64)
  663.     @confirm_window.contents = Bitmap.new(368, 32)
  664.     @confirm_window.contents.font.name = "黑体"
  665.     @confirm_window.contents.font.size = 20
  666.     @help_window = Window_Help.new
  667.     @craft_window.help_window = @help_window
  668.     @result_window=Window_CraftResult.new
  669.     @ingredients_window=Window_CraftIngredients.new
  670.     if @craft_window.data.size > 0 #本类窗口物品大于0的话
  671.       @result_window.set_result(@craft_window.recipe.result, @craft_window.recipe.result_type)
  672.       @ingredients_window.set_ingredients(@craft_window.recipe.ingredients,
  673.                                                           @craft_window.recipe.ingredient_types,
  674.                                                           @craft_window.recipe.quantities)
  675.     end
  676.     @yes_no_window = Window_Command.new(100, ["确定", "放弃"])
  677.     @confirm_window.visible = false
  678.     @confirm_window.z = 1500
  679.     @yes_no_window.visible = false
  680.     @yes_no_window.active = false
  681.     @yes_no_window.index = 1
  682.     @yes_no_window.x = 270
  683.     @yes_no_window.y = 252
  684.     @yes_no_window.z = 1500
  685.     @label_window = Window_Base.new(450,200,190,52)
  686.     @label_window.contents=Bitmap.new(@label_window.width - 32,@label_window.height - 32)
  687.     @label_window.contents.font.size=20
  688.     @label_window.contents.font.color = @label_window.normal_color
  689.     @label_window.contents.font.name = "黑体"
  690.     @label_window.contents.draw_text(0, 0, @label_window.contents.width, 20, "  现有   需要")
  691.     Graphics.transition
  692.     loop do
  693.       Graphics.update
  694.       Input.update
  695.       update
  696.       if $scene != self
  697.         break
  698.       end
  699.     end
  700.     Graphics.freeze
  701.     @help_window.dispose
  702.     @craft_window.dispose
  703.     @result_window.dispose
  704.     @ingredients_window.dispose
  705.     @confirm_window.dispose
  706.     @yes_no_window.dispose
  707.     @label_window.dispose
  708.   end
  709.  
  710.   #--------------------------------------------------------------------------
  711.   def update
  712.     @craft_window.update
  713.     @ingredients_window.update
  714.     if @craft_window.active
  715.       update_craft
  716.       return
  717.     end
  718.     if @yes_no_window.active
  719.       confirm_update
  720.       return
  721.     end
  722.   end
  723.  
  724.   #--------------------------------------------------------------------------
  725.   def update_craft
  726.     if Input.dir4 != 0
  727.       if @craft_window.data.size > 0 #本类窗口物品大于0的话
  728.         @result_window.set_result(@craft_window.recipe.result, @craft_window.recipe.result_type)
  729.         @ingredients_window.set_ingredients(@craft_window.recipe.ingredients,
  730.                                                            @craft_window.recipe.ingredient_types,
  731.                                                            @craft_window.recipe.quantities)
  732.       end
  733.     end
  734.     if Input.trigger?(Input::B)
  735.       $game_system.se_play($data_system.cancel_se)
  736.       $scene = Scene_Map.new
  737.       return
  738.     end
  739.     if Input.trigger?(Input::C) and $game_party.recipes.size != 0
  740.       @recipe = @craft_window.recipe
  741.       if @recipe != nil
  742.         if @recipe.have
  743.           @yes_no_window.active = true
  744.           @craft_window.active = false
  745.         else
  746.           $game_system.se_play($data_system.buzzer_se)
  747.           return
  748.         end
  749.       else
  750.         $game_system.se_play($data_system.buzzer_se)
  751.         return
  752.       end
  753.     end
  754.   end
  755.  
  756.   #--------------------------------------------------------------------------
  757.   def confirm_update
  758.     @craft_index = @craft_window.index
  759.     @confirm_window.visible = true
  760.     @confirm_window.z = 1500
  761.     @yes_no_window.visible = true
  762.     @yes_no_window.active = true
  763.     @yes_no_window.z = 1500
  764.     @yes_no_window.update
  765.     string = "合成 " + @recipe.name + "?"
  766.     cw = @confirm_window.contents.text_size(string).width
  767.     center = @confirm_window.contents.width/2 - cw /2
  768.     unless @drawn
  769.       @confirm_window.contents.draw_text(center, 0, cw, 30, string)
  770.       @drawn = true
  771.     end
  772.     if Input.trigger?(Input::C)
  773.       if @yes_no_window.index == 0
  774.         $game_system.se_play($data_system.decision_se)
  775.         @recipe.make
  776.         $game_system.se_play($data_system.save_se)
  777.         $scene=Scene_Craft.new(@craft_type,@craft_index)
  778.       else
  779.         $game_system.se_play($data_system.cancel_se)
  780.         $scene=Scene_Craft.new(@craft_type,@craft_index)
  781.       end
  782.     end
  783.     if Input.trigger?(Input::B)
  784.       $game_system.se_play($data_system.cancel_se)
  785.       $scene=Scene_Craft.new(@craft_type,@craft_index)
  786.     end
  787.   end
  788.  
  789. end # of Scene_Craft
  790.  
  791. #==============================================================================
  792. # 本脚本来自[url]www.66RPG.com[/url],使用和转载请保留此信息
  793. # 欢迎访问[url]www.66RPG.com[/url]
  794. # 梦想世界,在你手中
  795. #==============================================================================

获得合成配方时会弹出“脚本“物品合成”的211行发生了NoMethodError。undefined method`include?ˋfor nil:NilClass”
自我感觉不是和其它脚本冲突因为用的大部分脚本都是从以前做的游戏里搬过来的,当时也没这冲突,其它新添加的脚本我删除后还是有这种问题

点评

测试没有问题。  发表于 2015-2-17 16:58

Lv4.逐梦者 (版主)

梦石
0
星屑
9532
在线时间
5073 小时
注册时间
2013-6-21
帖子
3580

开拓者贵宾剧作品鉴家

2
发表于 2015-2-17 17:37:43 | 只看该作者
可能是这个脚本应用于旧存档上导致部分变量没有初始化。
解决方法是在def know?(207行),def learn_recipe(215行),def forget_recipe(227行)
后面加上
RUBY 代码复制
  1. @recipes ||= []

看看能不能解决问题
回复 支持 反对

使用道具 举报

Lv2.观梦者

梦石
0
星屑
592
在线时间
268 小时
注册时间
2014-7-5
帖子
157
3
 楼主| 发表于 2015-2-17 17:52:34 | 只看该作者
RyanBern 发表于 2015-2-17 17:37
可能是这个脚本应用于旧存档上导致部分变量没有初始化。
解决方法是在def know?(207行),def learn_recipe( ...

恩已解决谢谢
回复 支持 反对

使用道具 举报

Lv4.逐梦者

梦石
0
星屑
9280
在线时间
2504 小时
注册时间
2011-5-20
帖子
15389

开拓者

4
发表于 2015-2-17 20:55:34 | 只看该作者
普通的呆毛狼 发表于 2015-2-17 00:52
恩已解决谢谢

@hys111111 问题解决
[img]http://service.t.sina.com.cn/widget/qmd/5339802982/c02e16bd/7.png
回复 支持 反对

使用道具 举报

您需要登录后才可以回帖 登录 | 注册会员

本版积分规则

拿上你的纸笔,建造一个属于你的梦想世界,加入吧。
 注册会员
找回密码

站长信箱:[email protected]|手机版|小黑屋|无图版|Project1游戏制作

GMT+8, 2024-9-22 17:37

Powered by Discuz! X3.1

© 2001-2013 Comsenz Inc.

快速回复 返回顶部 返回列表