查看: 1735|回复: 3

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

[复制链接]
梦石
0
星屑
647
在线时间
272 小时
注册时间
2014-7-5
回帖
129
发表于 2015-2-17 16:15:40 | 显示全部楼层 |阅读模式

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

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

×
本帖最后由 RyanBern 于 2015-2-17 17:31 编辑
  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. # CRAFTING PROGRAM
  186. #----------------------------------------------------------------
  187. #-written by Deke
  188. #-yes_no window code created by Phsylomortis
  189. #----------------------------------------------------------------
  190. #================================

  191. #updates to Game_Party class

  192. class Game_Party
  193.   
  194.   attr_accessor       :recipes
  195.   
  196.   alias crafting_party_initialize initialize
  197.   
  198.   def initialize
  199.     crafting_party_initialize
  200.     @recipes=[]
  201.   end
  202.   
  203.   #----------------------------------------------------------------------
  204.   def know?(recipe, version = 1)
  205.     unless recipe.is_a?(Game_Recipe)
  206.       recipe = get_recipe_from_master_list(recipe, version)
  207.     end
  208.     return $game_party.recipes.include?(recipe)
  209.   end
  210.   
  211. #----------------------------------------------------------------------
  212.   def learn_recipe(recipe , version = 1)
  213.     unless recipe.is_a?(Game_Recipe)
  214.       recipe = get_recipe_from_master_list(recipe, version)
  215.     end
  216.     if recipe.is_a?(Game_Recipe)
  217.       unless know?(recipe)
  218.         @recipes.push(recipe)
  219.       end
  220.     end
  221.   end
  222.   
  223. #----------------------------------------------------------------------
  224.   def forget_recipe(recipe , version = 1)
  225.     if !recipe.is_a?(Game_Recipe)
  226.       recipe = get_recipe_from_master_list(recipe, version)
  227.     end
  228.     if recipe.is_a?(Game_Recipe)
  229.       for i in [email]0...@recipes.size[/email]
  230.         if recipe == @recipes[i]
  231.           index = i
  232.           break
  233.         end
  234.       end
  235.       if index != nil
  236.         @recipes.delete(@recipes[index])
  237.       end
  238.     end
  239.   end
  240.   
  241. #----------------------------------------------------------------------
  242.   def get_recipe_from_master_list(item, version)
  243.     index = nil
  244.     for i in 0...$game_temp.recipe_list.size
  245.       if item[0] == $game_temp.recipe_list[i].result and item[1] ==$game_temp.recipe_list[i].result_type
  246.         version -= 1
  247.         if version == 0
  248.           index = i
  249.           break
  250.         end
  251.       end
  252.     end
  253.     if index.is_a?(Integer)
  254.       return ($game_temp.recipe_list[index])
  255.     else
  256.       return false
  257.     end
  258.   end
  259.   
  260. end # of Game_Party updates

  261. #================================
  262. class Game_Recipe

  263.   attr_reader :ingredients
  264.   attr_reader :quantities
  265.   attr_reader :result
  266.   attr_reader :result_type
  267.   attr_reader :ingredient_types
  268.   attr_reader :craft_type  #物品分类
  269.   
  270. #----------------------------------------------------------------------
  271.   def initialize( ingredients, ingredient_types, quantities, result, result_type, craft_type=0)
  272.     @ingredients = ingredients
  273.     @ingredient_types = ingredient_types
  274.     @quantities = quantities
  275.     @result = result
  276.     @result_type = result_type
  277.     @craft_type = craft_type
  278.   end
  279.   
  280. #----------------------------------------------------------------------
  281.   def name
  282.     case @result_type
  283.       when 0
  284.         name = $data_items[@result].name
  285.       when 1
  286.         name = $data_armors[@result].name
  287.       when 2
  288.         name = $data_weapons[@result].name
  289.     end
  290.     return name
  291.   end
  292.   
  293. #----------------------------------------------------------------------

  294.   def item
  295.     case @result_type
  296.       when 0
  297.         item = $data_items[@result]
  298.       when 1
  299.         item = $data_armors[@result]
  300.       when 2
  301.         item = $data_weapons[@result]
  302.     end
  303.     return item
  304.   end

  305. #----------------------------------------------------------------------
  306.   def have
  307.     have_all = true
  308.     for i in [email]0...@ingredients.size[/email]
  309.       case @ingredient_types[i]
  310.         when 0
  311.           if $game_party.item_number(@ingredients[i]) < @quantities[i]
  312.             have_all=false
  313.           end
  314.         when 1
  315.           if $game_party.armor_number(@ingredients[i]) < @quantities[i]
  316.             have_all=false
  317.           end
  318.         when 2
  319.           if $game_party.weapon_number(@ingredients[i]) < @quantities[i]
  320.             have_all=false
  321.           end
  322.       end
  323.     end
  324.     return have_all
  325.   end

  326. #----------------------------------------------------------------------
  327.   def decrement
  328.     for i in [email]0...@ingredients.size[/email]
  329.       case @ingredient_types[i]
  330.       when 0
  331.         $game_party.lose_item(@ingredients[i], @quantities[i])
  332.       when 1
  333.         $game_party.lose_armor(@ingredients[i], @quantities[i])
  334.       when 2
  335.         $game_party.lose_weapon(@ingredients[i], @quantities[i])
  336.       end
  337.     end
  338.   end

  339. #----------------------------------------------------------------------
  340.   def make
  341.     if have
  342.       case @result_type
  343.       when 0
  344.         $game_party.gain_item(@result, 1)
  345.       when 1
  346.         $game_party.gain_armor(@result, 1)
  347.       when 2
  348.         $game_party.gain_weapon(@result, 1)
  349.       end
  350.       decrement
  351.     end
  352.   end
  353.   
  354. #----------------------------------------------------------------------
  355.   def == (recipe)
  356.     if recipe.is_a?(Game_Recipe)
  357.       equal = true
  358.       if recipe.ingredients != self.ingredients
  359.         equal = false
  360.       end
  361.       if recipe.ingredient_types != self.ingredient_types
  362.         equal = false
  363.       end
  364.       if recipe.quantities != self.quantities
  365.         equal = false
  366.       end
  367.       if recipe.result != self.result
  368.         equal=false
  369.       end
  370.       if recipe.result_type != self.result_type
  371.         equal = false
  372.       end
  373.     else
  374.       equal = false
  375.     end
  376.     return equal
  377.   end
  378.   
  379. end # of Game_Recipe class

  380. #===================================

  381. class Window_Craft < Window_Selectable
  382.   attr_reader :data #声明数据
  383.   #--------------------------------------------------------------------------
  384.   def initialize(craft_type=0)
  385.     @craft_type = craft_type
  386.     super(0, 64, 240, 416)
  387.     @column_max = 1
  388.     refresh
  389.     self.index = 0
  390.   end

  391.   #--------------------------------------------------------------------------
  392.   def recipe
  393.     return @data[self.index]
  394.   end

  395.   #--------------------------------------------------------------------------
  396.   def refresh
  397.     if self.contents != nil
  398.       self.contents.dispose
  399.       self.contents = nil
  400.     end
  401.     @data = []
  402.     for i in 0...$game_party.recipes.size
  403.        #@craft_type为0时就显示全部物品
  404.        #不为0时就显示对应物品
  405.       if @craft_type == 0
  406.         @data.push($game_party.recipes[i])
  407.       elsif $game_party.recipes[i].craft_type == @craft_type
  408.         @data.push($game_party.recipes[i])
  409.       end
  410.     end
  411.     @item_max = @data.size
  412.     if @item_max > 0
  413.       self.contents = Bitmap.new(width - 32, row_max * 32)
  414.       self.contents.font.name = "黑体" # = "黑体"
  415.       self.contents.font.size = 18 # = 18
  416.       for i in 0...@item_max
  417.         x = 16
  418.         y = i * 32
  419.         able = true
  420.         for ingredient in 0...@data[i].ingredients.size
  421.           case @data[i].ingredient_types[ingredient]
  422.           when 0
  423.             count = $game_party.item_number(@data[i].ingredients[ingredient])
  424.           when 1
  425.             count = $game_party.armor_number(@data[i].ingredients[ingredient])
  426.           when 2
  427.             count = $game_party.weapon_number(@data[i].ingredients[ingredient])
  428.           end
  429.           if count < @data[i].quantities[ingredient]
  430.             able = false
  431.             break
  432.           end
  433.         end
  434.         draw_item_name(@data[i].item, x, y, able)
  435.       end
  436.     end
  437.   end

  438.   #--------------------------------------------------------------------------
  439.   #def draw_item(index)
  440.   #  recipe = @data[index]
  441.   #  self.contents.font.color = recipe.have ? normal_color : disabled_color
  442.   #  x = 16
  443.   #  y = index * 32
  444.   #  self.contents.draw_text(x , y, self.width-32, 32, recipe.name, 0)
  445.   #end
  446.   
  447.   #--------------------------------------------------------------------------
  448.   # ● 描绘物品名
  449.   #     item : 物品
  450.   #     x    : 描画目标 X 坐标
  451.   #     y    : 描画目标 Y 坐标
  452.   #--------------------------------------------------------------------------
  453.   def draw_item_name(item, x, y, able = true)
  454.     if item == nil
  455.       return
  456.     end
  457.     if !able
  458.       self.contents.font.color = disabled_color
  459.     end
  460.     bitmap = RPG::Cache.icon(item.icon_name)
  461.     self.contents.blt(x, y + 4, bitmap, Rect.new(0, 0, 24, 24))
  462.     self.contents.draw_text(x + 28, y, 212, 32, item.name)
  463.     self.contents.font.color = normal_color
  464.   end
  465.   
  466.   #--------------------------------------------------------------------------
  467.   def update_help
  468.     current_recipe = recipe
  469.     if current_recipe.is_a?(Game_Recipe)
  470.     case current_recipe.result_type
  471.       when 0
  472.         description = $data_items[current_recipe.result].description
  473.       when 1
  474.         description = $data_armors[current_recipe.result].description
  475.       when 2
  476.         description = $data_weapons[current_recipe.result].description
  477.       end
  478.     else
  479.       description = ""
  480.     end
  481.     @help_window.set_text(description)
  482.     @help_window.update
  483.   end
  484.   
  485. end # of Window_Craft

  486. #=======================================
  487. class Window_CraftResult < Window_Base

  488.   #--------------------------------------------------------------------------
  489.   def initialize
  490.     super(240, 64, 400, 184)
  491.     self.contents = Bitmap.new(width - 32, height - 32)
  492.     self.contents.font.name = "黑体" # = $fontface.is_a?(String) ? $fontface : $defaultfonttype
  493.     self.contents.font.size = 18 # = 20
  494.     @result = nil
  495.     @type = nil
  496.   end

  497.   #--------------------------------------------------------------------------
  498.   def refresh
  499.     self.contents.clear
  500.     case @type
  501.       when 0
  502.         item = $data_items[@result]
  503.         if item.recover_hp_rate > item.recover_hp
  504.           hp_string = "HP回复率:"
  505.           hp_stat = item.recover_hp_rate
  506.         else
  507.           hp_string = "HP回复量:"
  508.           hp_stat = item.recover_hp
  509.         end
  510.         if item.recover_sp_rate > item.recover_sp
  511.           sp_string = "SP回复率:"
  512.           sp_stat = item.recover_sp_rate
  513.         else
  514.           sp_string = "SP回复量:"
  515.           sp_stat = item.recover_sp
  516.         end
  517.         @strings = [hp_string, sp_string, "物理防御:" , "魔法防御:", "命中率:", "分散度:"]
  518.         @stats = [hp_stat, sp_stat, item. pdef_f, item.mdef_f, item.hit, item.variance,
  519.                        $game_party.item_number(@result)]
  520.         @bitmap = RPG::Cache.icon(item.icon_name)
  521.       when 1
  522.         item = $data_armors[@result]
  523.         @strings = ["物理防御:", "魔法防御:", "回避修正:", "力量增加:", "灵巧增加:",
  524.                        "速度增加:", "魔力增加:"]
  525.         @stats = [item.pdef, item.mdef, item.eva, item.str_plus, item.dex_plus,
  526.                     item.agi_plus, item.int_plus, $game_party.armor_number(@result) ]
  527.         @bitmap = RPG::Cache.icon(item.icon_name)
  528.       when 2
  529.         item = $data_weapons[@result]
  530.         @strings =["攻击力:", "物理防御:", "魔法防御:", "力量增加:", "灵巧增加:",
  531.                     "速度增加:", "魔力增加:"]
  532.         @stats = [item.atk, item.pdef, item.mdef, item.str_plus, item.dex_plus,
  533.                     item.agi_plus, item.int_plus, $game_party.weapon_number(@result) ]
  534.         @bitmap = RPG::Cache.icon(item.icon_name)
  535.     end
  536.     for i in [email]0...@strings.size[/email]
  537.       x = i%2 * 184
  538.       y = i /2 *28 +32
  539.       self.contents.font.color = normal_color
  540.       self.contents.draw_text(x,y,100, 28,@strings[i])
  541.       self.contents.font.color = system_color
  542.       self.contents.draw_text(x + 110, y, 45, 28, @stats[i].to_s)
  543.     end
  544.     self.contents.blt(0, 0, @bitmap, Rect.new(0, 0, 24, 24), 255)
  545.     self.contents.font.color= normal_color
  546.     self.contents.draw_text(40, 0, 300, 28, "待合成物品的现有数量:")
  547.     self.contents.font.color = system_color
  548.     count = @stats[@stats.size - 1].to_s
  549.     self.contents.draw_text(294, 0, 45, 28, count )
  550.   end
  551.    
  552. #----------------------------------------------------------------------
  553.   def set_result(result , type)
  554.     @result = result
  555.     @type = type
  556.     refresh
  557.   end

  558. end #of Window_CraftResult

  559. #=======================================
  560. class Window_CraftIngredients < Window_Base

  561.   #--------------------------------------------------------------------------
  562.   def initialize
  563.     super(240, 248, 400, 232)
  564.     self.contents = Bitmap.new(width - 32, height - 32)
  565.     self.contents.font.name = "黑体" # = $fontface.is_a?(String) ? $fontface : $defaultfonttype
  566.     self.contents.font.size = 18 # = 20
  567.     @ingredients = []
  568.     @types = []
  569.     @quantities = []
  570.     @item = nil
  571.     @count = 0
  572.     @counter = 0
  573.     @real_oy = 0
  574.   end

  575.   #--------------------------------------------------------------------------
  576.   def refresh
  577.     @counter = 0
  578.     self.contents.clear
  579.     self.contents = Bitmap.new(width - 32, @ingredients.size * 26)
  580.     for i in [email]0...@ingredients.size[/email]
  581.       case @types[i]
  582.       when 0
  583.         @item = $data_items[@ingredients[i]]
  584.         @count = $game_party.item_number(@ingredients[i])
  585.       when 1
  586.         @item = $data_armors[@ingredients[i]]
  587.         @count = $game_party.armor_number(@ingredients[i])
  588.       when 2
  589.         @item = $data_weapons[@ingredients[i]]
  590.         @count = $game_party.weapon_number(@ingredients[i])
  591.       end
  592.       y = i *26
  593.       self.contents.blt(0, y, RPG::Cache.icon(@item.icon_name), Rect.new(0, 0, 24, 24), 255)
  594.       self.contents.font.color = @count >= @quantities[i] ? normal_color : disabled_color
  595.       self.contents.draw_text(30, y, 280, 28, @item.name)
  596.       self.contents.draw_text(300, y, 45, 28, @quantities[i].to_s)
  597.       self.contents.font.color = system_color
  598.       self.contents.draw_text(245, y, 45, 28, @count.to_s )     
  599.     end
  600.   end
  601.       
  602.   #--------------------------------------------------------------------------
  603.   def set_ingredients(ingredients , types, quantities)
  604.     @ingredients = ingredients
  605.     @types = types
  606.     @quantities = quantities
  607.     refresh
  608.     if @ingredients.size > 7
  609.       self.oy = -52
  610.       @real_oy = 0
  611.     else
  612.       self.oy = 0
  613.     end
  614.   end

  615.   def update
  616.     super
  617.     @counter += 1
  618.     if @ingredients.size > 7 and @counter > 30
  619.       @real_oy = (@real_oy + 1) % ((@ingredients.size - 3) * 26)
  620.       self.oy = @real_oy - 52
  621.     end
  622.   end
  623.    
  624. end # of Window_CraftIngredients

  625. #======================================
  626. class Scene_Craft

  627.   #--------------------------------------------------------------------------
  628.   # @craft_type:物品种类,0就是全部
  629.   def initialize(craft_type=0,craft_index=0)
  630.     @craft_index=craft_index
  631.     @craft_type = craft_type
  632.   end
  633.   
  634.   #--------------------------------------------------------------------------
  635.   def main
  636.     @craft_window = Window_Craft.new(@craft_type)
  637.     @craft_window.index=@craft_index
  638.     @confirm_window = Window_Base.new(120, 188, 400, 64)
  639.     @confirm_window.contents = Bitmap.new(368, 32)
  640.     @confirm_window.contents.font.name = "黑体"
  641.     @confirm_window.contents.font.size = 20
  642.     @help_window = Window_Help.new
  643.     @craft_window.help_window = @help_window
  644.     @result_window=Window_CraftResult.new
  645.     @ingredients_window=Window_CraftIngredients.new
  646.     if @craft_window.data.size > 0 #本类窗口物品大于0的话
  647.       @result_window.set_result(@craft_window.recipe.result, @craft_window.recipe.result_type)
  648.       @ingredients_window.set_ingredients(@craft_window.recipe.ingredients,
  649.                                                           @craft_window.recipe.ingredient_types,
  650.                                                           @craft_window.recipe.quantities)
  651.     end
  652.     @yes_no_window = Window_Command.new(100, ["确定", "放弃"])
  653.     @confirm_window.visible = false
  654.     @confirm_window.z = 1500
  655.     @yes_no_window.visible = false
  656.     @yes_no_window.active = false
  657.     @yes_no_window.index = 1
  658.     @yes_no_window.x = 270
  659.     @yes_no_window.y = 252
  660.     @yes_no_window.z = 1500
  661.     @label_window = Window_Base.new(450,200,190,52)
  662.     @label_window.contents=Bitmap.new(@label_window.width - 32,@label_window.height - 32)
  663.     @label_window.contents.font.size=20
  664.     @label_window.contents.font.color = @label_window.normal_color
  665.     @label_window.contents.font.name = "黑体"
  666.     @label_window.contents.draw_text(0, 0, @label_window.contents.width, 20, "  现有   需要")
  667.     Graphics.transition
  668.     loop do
  669.       Graphics.update
  670.       Input.update
  671.       update
  672.       if $scene != self
  673.         break
  674.       end
  675.     end
  676.     Graphics.freeze
  677.     @help_window.dispose
  678.     @craft_window.dispose
  679.     @result_window.dispose
  680.     @ingredients_window.dispose
  681.     @confirm_window.dispose
  682.     @yes_no_window.dispose
  683.     @label_window.dispose
  684.   end

  685.   #--------------------------------------------------------------------------
  686.   def update
  687.     @craft_window.update
  688.     @ingredients_window.update
  689.     if @craft_window.active
  690.       update_craft
  691.       return
  692.     end
  693.     if @yes_no_window.active
  694.       confirm_update
  695.       return
  696.     end
  697.   end

  698.   #--------------------------------------------------------------------------
  699.   def update_craft
  700.     if Input.dir4 != 0
  701.       if @craft_window.data.size > 0 #本类窗口物品大于0的话
  702.         @result_window.set_result(@craft_window.recipe.result, @craft_window.recipe.result_type)
  703.         @ingredients_window.set_ingredients(@craft_window.recipe.ingredients,
  704.                                                            @craft_window.recipe.ingredient_types,
  705.                                                            @craft_window.recipe.quantities)
  706.       end
  707.     end
  708.     if Input.trigger?(Input::B)
  709.       $game_system.se_play($data_system.cancel_se)
  710.       $scene = Scene_Map.new
  711.       return
  712.     end
  713.     if Input.trigger?(Input::C) and $game_party.recipes.size != 0
  714.       @recipe = @craft_window.recipe
  715.       if @recipe != nil
  716.         if @recipe.have
  717.           @yes_no_window.active = true
  718.           @craft_window.active = false
  719.         else
  720.           $game_system.se_play($data_system.buzzer_se)
  721.           return
  722.         end
  723.       else
  724.         $game_system.se_play($data_system.buzzer_se)
  725.         return
  726.       end
  727.     end
  728.   end

  729.   #--------------------------------------------------------------------------
  730.   def confirm_update
  731.     @craft_index = @craft_window.index
  732.     @confirm_window.visible = true
  733.     @confirm_window.z = 1500
  734.     @yes_no_window.visible = true
  735.     @yes_no_window.active = true
  736.     @yes_no_window.z = 1500
  737.     @yes_no_window.update
  738.     string = "合成 " + @recipe.name + "?"
  739.     cw = @confirm_window.contents.text_size(string).width
  740.     center = @confirm_window.contents.width/2 - cw /2
  741.     unless @drawn
  742.       @confirm_window.contents.draw_text(center, 0, cw, 30, string)
  743.       @drawn = true
  744.     end
  745.     if Input.trigger?(Input::C)
  746.       if @yes_no_window.index == 0
  747.         $game_system.se_play($data_system.decision_se)
  748.         @recipe.make
  749.         $game_system.se_play($data_system.save_se)
  750.         $scene=Scene_Craft.new(@craft_type,@craft_index)
  751.       else
  752.         $game_system.se_play($data_system.cancel_se)
  753.         $scene=Scene_Craft.new(@craft_type,@craft_index)
  754.       end
  755.     end
  756.     if Input.trigger?(Input::B)
  757.       $game_system.se_play($data_system.cancel_se)
  758.       $scene=Scene_Craft.new(@craft_type,@craft_index)
  759.     end
  760.   end

  761. end # of Scene_Craft

  762. #==============================================================================
  763. # 本脚本来自[url]www.66RPG.com[/url],使用和转载请保留此信息
  764. # 欢迎访问[url]www.66RPG.com[/url]
  765. # 梦想世界,在你手中
  766. #==============================================================================
复制代码

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

点评

测试没有问题。  发表于 2015-2-17 16:58
梦石
0
星屑
9557
在线时间
5074 小时
注册时间
2013-6-21
回帖
3459

开拓者贵宾剧作品鉴家

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

看看能不能解决问题
回复

使用道具 举报

梦石
0
星屑
647
在线时间
272 小时
注册时间
2014-7-5
回帖
129
 楼主| 发表于 2015-2-17 17:52:34 | 显示全部楼层
RyanBern 发表于 2015-2-17 17:37
可能是这个脚本应用于旧存档上导致部分变量没有初始化。
解决方法是在def know?(207行),def learn_recipe( ...

恩已解决谢谢
回复

使用道具 举报

梦石
0
星屑
9292
在线时间
2504 小时
注册时间
2011-5-20
回帖
14521

开拓者

发表于 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
回复

使用道具 举报

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

本版积分规则

Powered by Discuz! X5.0 © 2001-2026 Discuz! Team.

在本版发帖返回顶部