Project1

标题: XP中合成脚本的非消耗合成 [打印本页]

作者: Mr.Faint    时间: 2015-10-9 15:45
标题: XP中合成脚本的非消耗合成
本帖最后由 Mr.Faint 于 2015-10-8 23:51 编辑

是比较泛用的合成脚本,想制作一个需要锅子才能烹饪的设定,但是烹饪并不会消耗锅子,当然没有锅子也不能进行烹饪。

  1. #==============================================================================
  2. # 本脚本来自[url]www.66RPG.com[/url],使用和转载请保留此信息
  3. #==============================================================================  

  4. # Sample master list for crafting script
  5. # written by Deke
  6. #============================================================================================
  7. # 简介:
  8. # 这是一个很不错的合成物品系统,可以通过游戏的过程,不断学习可以合成的
  9. # 物品方法。
  10. #
  11. # 使用方法:
  12. # 1、召唤界面:使用脚本$scene = Scene_Craft.new
  13. #
  14. # 2、学习合成:$game_party.learn_recipe(合成项目)
  15. #
  16. # 3、合成定义:
  17. # 这个合成脚本可以定义两种合成物品。一种是预先定义好了的,就像下面这样,
  18. # 直接写在这里就可以,另一种是在学习之前现场定义。
  19. #
  20. # 4、举例
  21. #  4.1、学会recipe_list[1]定义的合成:$game_party.learn_recipe($game_temp.recipe_list[1])
  22. #       注意,一行如果输入不下,在(的后面或[的后面按回车换行,否则可能出错
  23. #
  24. #  4.2、在游戏中临时定义一种合成,让玩家学会。使用事件中的脚本如下,   
  25. #  脚本:
  26. #    材料 = [$game_variables[1],$game_variables[2]]  #——材料编号是变量1、2的编号
  27. #    材料种类 = [0,0]                                #——材料是物品
  28. #    材料数量 = [$game_variables[3],$game_variables[4]]  #——需要材料数量是变量3、4的编号
  29. #    成品 = $game_variables[5]                       #——获得结果编号是5
  30. #    成品种类 = 1                                    #——成品是防具类
  31. #    $game_party.learn_recipe(Game_Recipe.new(材料,材料种类, 材料数量,成品,成品种类))
  32. #===========================================================================================
  33. class Game_Temp
  34.   attr_reader :recipe_list  
  35.   alias crafting_temp_initialize initialize
  36.   def initialize
  37.     crafting_temp_initialize
  38.     @recipe_list=[]
  39.     get_recipe_list
  40.   end  
  41.   def get_recipe_list   

  42.     ##########################################################################
  43.     # 1 号合成物品设定 超恢复剂=回复剂*3
  44.     ##########################################################################
  45.     材料 = [1]          # 需要材料的数据库编号
  46.     材料种类 = [0]      # 需要材料的种类,0是普通物品,1是防具,2是武器
  47.     材料数量 = [3]      # 需要材料的数量
  48.     成品 = 2                  # 获得物品编号
  49.     成品种类 = 0              # 获得物品种类,0是普通物品,1是防具,2是武器
  50.     @recipe_list[1] = Game_Recipe.new(材料,材料种类, 材料数量,成品,成品种类)
  51.    
  52.     end # of get_recipe_list method
  53. end # of updates to Game_Temp Class

  54. #================================
  55. # CRAFTING PROGRAM
  56. #----------------------------------------------------------------
  57. #-written by Deke
  58. #-yes_no window code created by Phsylomortis
  59. #----------------------------------------------------------------
  60. #================================

  61. #updates to Game_Party class

  62. class Game_Party
  63.   
  64.   attr_accessor       :recipes
  65.   
  66.   alias crafting_party_initialize initialize
  67.   
  68.   def initialize
  69.     crafting_party_initialize
  70.     @recipes=[]
  71.   end
  72.   
  73.   #----------------------------------------------------------------------
  74.   def know?(recipe, version = 1)
  75.     unless recipe.is_a?(Game_Recipe)
  76.       recipe = get_recipe_from_master_list(recipe, version)
  77.     end
  78.     return $game_party.recipes.include?(recipe)
  79.   end
  80.   
  81. #----------------------------------------------------------------------
  82.   def learn_recipe(recipe , version = 1)
  83.     unless recipe.is_a?(Game_Recipe)
  84.       recipe = get_recipe_from_master_list(recipe, version)
  85.     end
  86.     if recipe.is_a?(Game_Recipe)
  87.       unless know?(recipe)
  88.         @recipes.push(recipe)
  89.       end
  90.     end
  91.   end
  92.   
  93. #----------------------------------------------------------------------
  94.   def forget_recipe(recipe , version = 1)
  95.     if !recipe.is_a?(Game_Recipe)
  96.       recipe = get_recipe_from_master_list(recipe, version)
  97.     end
  98.     if recipe.is_a?(Game_Recipe)
  99.       for i in [email][email protected][/email]
  100.         if recipe == @recipes[i]
  101.           index = i
  102.           break
  103.         end
  104.       end
  105.       if index != nil
  106.         @recipes.delete(@recipes[index])
  107.       end
  108.     end
  109.   end
  110.   
  111. #----------------------------------------------------------------------
  112.   def get_recipe_from_master_list(item, version)
  113.     index = nil
  114.     for i in 0...$game_temp.recipe_list.size
  115.       if item[0] == $game_temp.recipe_list[i].result and item[1] ==$game_temp.recipe_list[i].result_type
  116.         version -= 1
  117.         if version == 0
  118.           index = i
  119.           break
  120.         end
  121.       end
  122.     end
  123.     if index.is_a?(Integer)
  124.       return ($game_temp.recipe_list[index])
  125.     else
  126.       return false
  127.     end
  128.   end
  129.   
  130. end # of Game_Party updates

  131. #================================
  132. class Game_Recipe

  133.   attr_reader :ingredients
  134.   attr_reader :quantities
  135.   attr_reader :result
  136.   attr_reader :result_type
  137.   attr_reader :ingredient_types
  138.   
  139. #----------------------------------------------------------------------
  140.   def initialize( ingredients, ingredient_types, quantities, result, result_type)
  141.     @ingredients = ingredients
  142.     @ingredient_types = ingredient_types
  143.     @quantities = quantities
  144.     @result = result
  145.     @result_type = result_type
  146.   end
  147.   
  148. #----------------------------------------------------------------------
  149.   def name
  150.     case @result_type
  151.       when 0
  152.         name = $data_items[@result].name
  153.       when 1
  154.         name = $data_armors[@result].name
  155.       when 2
  156.         name = $data_weapons[@result].name
  157.     end
  158.     return name
  159.   end

  160. #----------------------------------------------------------------------
  161.   def have
  162.     have_all = true
  163.     for i in [email][email protected][/email]
  164.       case @ingredient_types[i]
  165.         when 0
  166.           if $game_party.item_number(@ingredients[i]) < @quantities[i]
  167.             have_all=false
  168.           end
  169.         when 1
  170.           if $game_party.armor_number(@ingredients[i]) < @quantities[i]
  171.             have_all=false
  172.           end
  173.         when 2
  174.           if $game_party.weapon_number(@ingredients[i]) < @quantities[i]
  175.             have_all=false
  176.           end
  177.       end
  178.     end
  179.     return have_all
  180.   end
  181.   

  182.   

  183. #----------------------------------------------------------------------
  184.   def decrement
  185.     for i in [email protected]
  186.       case @ingredient_types[i]
  187.       when 0
  188.         $game_party.lose_item(@ingredients[i], @quantities[i])
  189.       when 1
  190.         $game_party.lose_armor(@ingredients[i], @quantities[i])
  191.       when 2
  192.         $game_party.lose_weapon(@ingredients[i], @quantities[i])
  193.       end
  194.     end
  195.   end


  196. #----------------------------------------------------------------------
  197.   def make
  198.     if have
  199.       case @result_type
  200.       when 0
  201.         $game_party.gain_item(@result, 1)
  202.       when 1
  203.         $game_party.gain_armor(@result, 1)
  204.       when 2
  205.         $game_party.gain_weapon(@result, 1)
  206.       end
  207.       decrement
  208.     end
  209.   end
  210.   
  211. #----------------------------------------------------------------------
  212.   def == (recipe)
  213.     if recipe.is_a?(Game_Recipe)
  214.       equal = true
  215.       if recipe.ingredients != self.ingredients
  216.         equal = false
  217.       end
  218.       if recipe.ingredient_types != self.ingredient_types
  219.         equal = false
  220.       end
  221.       if recipe.quantities != self.quantities
  222.         equal = false
  223.       end
  224.       if recipe.result != self.result
  225.         equal=false
  226.       end
  227.       if recipe.result_type != self.result_type
  228.         equal = false
  229.       end
  230.     else
  231.       equal = false
  232.     end
  233.     return equal
  234.   end
  235.   
  236. end # of Game_Recipe class

  237. #===================================

  238. class Window_Craft < Window_Selectable

  239.   #--------------------------------------------------------------------------
  240.   def initialize
  241.     super(0, 64, 240, 416)
  242.     @column_max = 1
  243.     refresh
  244.     self.index = 0
  245.   end

  246.   #--------------------------------------------------------------------------
  247.   def recipe
  248.     return @data[self.index]
  249.   end

  250.   #--------------------------------------------------------------------------
  251.   def refresh
  252.     if self.contents != nil
  253.       self.contents.dispose
  254.       self.contents = nil
  255.     end
  256.     @data = []
  257.     for i in 0...$game_party.recipes.size
  258.         @data.push($game_party.recipes[i])
  259.     end
  260.     @item_max = @data.size
  261.     if @item_max > 0
  262.       self.contents = Bitmap.new(width - 32, row_max * 32)
  263.       self.contents.font.name = "黑体" # = "黑体"
  264.       self.contents.font.size = 18 # = 18
  265.       for i in 0...@item_max
  266.         draw_item(i)
  267.       end
  268.     end
  269.   end

  270.   #--------------------------------------------------------------------------
  271.   def draw_item(index)
  272.     recipe = @data[index]
  273.     self.contents.font.color = recipe.have ? normal_color : disabled_color
  274.     x = 16
  275.     y = index * 32
  276.     self.contents.draw_text(x , y, self.width-32, 32, recipe.name, 0)
  277.   end

  278.   #--------------------------------------------------------------------------
  279.   def update_help
  280.     current_recipe = recipe
  281.     if current_recipe.is_a?(Game_Recipe)
  282.     case current_recipe.result_type
  283.       when 0
  284.         description = $data_items[current_recipe.result].description
  285.       when 1
  286.         description = $data_armors[current_recipe.result].description
  287.       when 2
  288.         description = $data_weapons[current_recipe.result].description
  289.       end
  290.     else
  291.       description = ""
  292.     end
  293.     @help_window.set_text(description)
  294.     @help_window.update
  295.   end
  296.   
  297. end # of Window_Craft

  298. #=======================================
  299. class Window_CraftResult < Window_Base

  300.   #--------------------------------------------------------------------------
  301.   def initialize
  302.     super(240, 64, 400, 184)
  303.     self.contents = Bitmap.new(width - 32, height - 32)
  304.     self.contents.font.name = "黑体" # = $fontface.is_a?(String) ? $fontface : $defaultfonttype
  305.     self.contents.font.size = 18 # = 20
  306.     @result = nil
  307.     @type = nil
  308.   end

  309.   #--------------------------------------------------------------------------
  310.   def refresh
  311.     self.contents.clear
  312.     case @type
  313.       when 0
  314.         item = $data_items[@result]
  315.         if item.recover_hp_rate > item.recover_hp
  316.           hp_string = "HP回复率:"
  317.           hp_stat = item.recover_hp_rate
  318.         else
  319.           hp_string = "HP回复量:"
  320.           hp_stat = item.recover_hp
  321.         end
  322.         if item.recover_sp_rate > item.recover_sp
  323.           sp_string = "SP回复率:"
  324.           sp_stat = item.recover_sp_rate
  325.         else
  326.           sp_string = "SP回复量:"
  327.           sp_stat = item.recover_sp
  328.         end
  329.         @strings = [hp_string, sp_string, "物理防御:" , "魔法防御:", "命中率:", "分散度:"]
  330.         @stats = [hp_stat, sp_stat, item. pdef_f, item.mdef_f, item.hit, item.variance,
  331.                        $game_party.item_number(@result)]
  332.         @bitmap = RPG::Cache.icon(item.icon_name)
  333.       when 1
  334.         item = $data_armors[@result]
  335.         @strings = ["物理防御:", "魔法防御:", "回避修正:", "力量增加:", "灵巧增加:",
  336.                        "速度增加:", "魔力增加:"]
  337.         @stats = [item.pdef, item.mdef, item.eva, item.str_plus, item.dex_plus,
  338.                     item.agi_plus, item.int_plus, $game_party.armor_number(@result) ]
  339.         @bitmap = RPG::Cache.icon(item.icon_name)
  340.       when 2
  341.         item = $data_weapons[@result]
  342.         @strings =["攻击力:", "物理防御:", "魔法防御:", "力量增加:", "灵巧增加:",
  343.                        "速度增加:", "魔力增加:"]
  344.         @stats = [item.atk, item.pdef, item.mdef, item.str_plus, item.dex_plus,
  345.                     item.agi_plus, item.int_plus, $game_party.weapon_number(@result) ]
  346.         @bitmap = RPG::Cache.icon(item.icon_name)
  347.     end
  348.     for i in [email][email protected][/email]
  349.       x = i%2 * 184
  350.       y = i /2 *28 +32
  351.       self.contents.font.color = normal_color
  352.       self.contents.draw_text(x,y,100, 28,@strings[i])
  353.       self.contents.font.color = system_color
  354.       self.contents.draw_text(x + 110, y, 45, 28, @stats[i].to_s)
  355.     end
  356.     self.contents.blt(0, 0, @bitmap, Rect.new(0, 0, 24, 24), 255)
  357.     self.contents.font.color= normal_color
  358.     self.contents.draw_text(40, 0, 300, 28, "待合成物品的现有数量:")
  359.     self.contents.font.color = system_color
  360.     count = @stats[@stats.size - 1].to_s
  361.     self.contents.draw_text(294, 0, 45, 28, count )
  362.   end
  363.    
  364. #----------------------------------------------------------------------
  365.   def set_result(result , type)
  366.     @result = result
  367.     @type = type
  368.     refresh
  369.   end

  370. end #of Window_CraftResult

  371. #=======================================
  372. class Window_CraftIngredients < Window_Base

  373.   #--------------------------------------------------------------------------
  374.   def initialize
  375.     super(240, 248, 400, 232)
  376.     self.contents = Bitmap.new(width - 32, height - 32)
  377.     self.contents.font.name = "黑体" # = $fontface.is_a?(String) ? $fontface : $defaultfonttype
  378.     self.contents.font.size = 18 # = 20
  379.     @ingredients = []
  380.     @types = []
  381.     @quantities = []
  382.     @item = nil
  383.     @count = 0
  384.   end

  385.   #--------------------------------------------------------------------------
  386.   def refresh
  387.     self.contents.clear
  388.     for i in [email][email protected][/email]
  389.       case @types[i]
  390.       when 0
  391.         @item = $data_items[@ingredients[i]]
  392.         @count = $game_party.item_number(@ingredients[i])
  393.       when 1
  394.         @item = $data_armors[@ingredients[i]]
  395.         @count = $game_party.armor_number(@ingredients[i])
  396.       when 2
  397.         @item = $data_weapons[@ingredients[i]]
  398.         @count = $game_party.weapon_number(@ingredients[i])
  399.       end
  400.       y = i *26
  401.       self.contents.blt(0, y, RPG::Cache.icon(@item.icon_name), Rect.new(0, 0, 24, 24), 255)
  402.       self.contents.font.color = @count >= @quantities[i] ? normal_color : disabled_color
  403.       self.contents.draw_text(30, y, 280, 28, @item.name)
  404.       self.contents.draw_text(300, y, 45, 28, @quantities[i].to_s)
  405.       self.contents.font.color = system_color
  406.       self.contents.draw_text(245, y, 45, 28, @count.to_s )     
  407.     end
  408.   end
  409.       
  410.   #--------------------------------------------------------------------------
  411.   def set_ingredients(ingredients , types, quantities)
  412.     @ingredients = ingredients
  413.     @types = types
  414.     @quantities = quantities
  415.     refresh
  416.   end

  417. end # of Window_CraftIngredients

  418. #======================================
  419. class Scene_Craft

  420.   #--------------------------------------------------------------------------
  421.   def initialize(craft_index=0)
  422.     @craft_index=craft_index
  423.   end
  424.   
  425.   #--------------------------------------------------------------------------
  426.   def main
  427.     @craft_window = Window_Craft.new
  428.     @craft_window.index=@craft_index
  429.     @confirm_window = Window_Base.new(120, 188, 400, 64)
  430.     @confirm_window.contents = Bitmap.new(368, 32)
  431.     @confirm_window.contents.font.name = "黑体"
  432.     @confirm_window.contents.font.size = 20
  433.     @help_window = Window_Help.new
  434.     @craft_window.help_window = @help_window
  435.     @result_window=Window_CraftResult.new
  436.     @ingredients_window=Window_CraftIngredients.new
  437.     @yes_no_window = Window_Command.new(100, ["确定", "放弃"])
  438.     @confirm_window.visible = false
  439.     @confirm_window.z = 1500
  440.     @yes_no_window.visible = false
  441.     @yes_no_window.active = false
  442.     @yes_no_window.index = 1
  443.     @yes_no_window.x = 270
  444.     @yes_no_window.y = 252
  445.     @yes_no_window.z = 1500
  446.     @label_window = Window_Base.new(450,200,190,52)
  447.     @label_window.contents=Bitmap.new(@label_window.width - 32,@label_window.height - 32)
  448.     @label_window.contents.font.size=20
  449.     @label_window.contents.font.color = @label_window.normal_color
  450.     @label_window.contents.font.name = "黑体"
  451.     @label_window.contents.draw_text(0, 0, @label_window.contents.width, 20, "  现有   需要")
  452.     Graphics.transition
  453.     loop do
  454.       Graphics.update
  455.       Input.update
  456.       update
  457.       if $scene != self
  458.         break
  459.       end
  460.     end
  461.     Graphics.freeze
  462.     @help_window.dispose
  463.     @craft_window.dispose
  464.     @result_window.dispose
  465.     @ingredients_window.dispose
  466.     @confirm_window.dispose
  467.     @yes_no_window.dispose
  468.     @label_window.dispose
  469.   end

  470.   #--------------------------------------------------------------------------
  471.   def update
  472.     @craft_window.update
  473.     @ingredients_window.update
  474.     if $game_party.recipes.size > 0
  475.       @result_window.set_result(@craft_window.recipe.result, @craft_window.recipe.result_type)
  476.       @ingredients_window.set_ingredients(@craft_window.recipe.ingredients,
  477.                                                            @craft_window.recipe.ingredient_types,
  478.                                                            @craft_window.recipe.quantities)
  479.     end
  480.     if @craft_window.active
  481.       update_craft
  482.       return
  483.     end
  484.     if @yes_no_window.active
  485.       confirm_update
  486.       return
  487.     end
  488.   end

  489.   #--------------------------------------------------------------------------
  490.   def update_craft
  491.     if Input.trigger?(Input::B)
  492.       $game_system.se_play($data_system.cancel_se)
  493.       $scene = Scene_Menu.new
  494.       return
  495.     end
  496.     if Input.trigger?(Input::C) and $game_party.recipes.size != 0
  497.       @recipe = @craft_window.recipe
  498.       if @recipe.have
  499.         @yes_no_window.active = true
  500.         @craft_window.active = false
  501.       else
  502.         $game_system.se_play($data_system.buzzer_se)
  503.         return
  504.       end
  505.     end
  506.   end

  507.   #--------------------------------------------------------------------------
  508.   def confirm_update
  509.     @craft_index = @craft_window.index
  510.     @confirm_window.visible = true
  511.     @confirm_window.z = 1500
  512.     @yes_no_window.visible = true
  513.     @yes_no_window.active = true
  514.     @yes_no_window.z = 1500
  515.     @yes_no_window.update
  516.     string = "合成 " + @recipe.name + "?"
  517.     cw = @confirm_window.contents.text_size(string).width
  518.     center = @confirm_window.contents.width/2 - cw /2
  519.     unless @drawn
  520.       @confirm_window.contents.draw_text(center, 0, cw, 30, string)
  521.       @drawn = true
  522.     end
  523.     if Input.trigger?(Input::C)
  524.       if @yes_no_window.index == 0
  525.         $game_system.se_play($data_system.decision_se)
  526.         @recipe.make
  527.         $game_system.se_play($data_system.save_se)
  528.         $scene=Scene_Craft.new(@craft_index)
  529.       else
  530.         $game_system.se_play($data_system.cancel_se)
  531.         $scene=Scene_Craft.new(@craft_index)
  532.       end
  533.     end
  534.     if Input.trigger?(Input::B)
  535.       $game_system.se_play($data_system.cancel_se)
  536.       $scene=Scene_Craft.new(@craft_index)
  537.     end
  538.   end

  539. end # of Scene_Craft

  540. #==============================================================================
  541. # 本脚本来自[url]www.66RPG.com[/url],使用和转载请保留此信息
  542. #==============================================================================
复制代码
处理合成材料消耗的部分如下:
  1.   
  2. def decrement
  3.     for i in [email protected]
  4.       case @ingredient_types[i]
  5.       when 0
  6.         $game_party.lose_item(@ingredients[i], @quantities[i])
  7.       when 1
  8.         $game_party.lose_armor(@ingredients[i], @quantities[i])
  9.       when 2
  10.         $game_party.lose_weapon(@ingredients[i], @quantities[i])
  11.       end
  12.     end
  13.   end
复制代码
已经尝试了定义材料编号判定,材料名称判定,出现的结果居然是所有材料都不消耗,即制造含有锅子作为材料的物品时所有素材都不被消耗
搞不懂为什么0 0.
for循环下如果定义i为对应的物品编号,用if判定的同时加入type的编号,再设定@quantities为0不是应该只对该编号下的物品生效么orz
求详细讲解
作者: 汪汪    时间: 2015-10-9 15:54
本帖最后由 汪汪 于 2015-10-9 19:17 编辑

不会把这个合成脚本的调用写到使用锅子引用的公共事件里吗_(:з」∠)_
就是 $scene = Scene_Craft.new  这一句


额,对这种脚本我是看不明白的


  Game_Recipe  下面的

以及


Game_Temp 下面
使用时


思路,既然减少会很麻烦 ,那么就删除之后添加.......
如此,你也可以做出其他效果比如.........炸锅了




欢迎光临 Project1 (https://rpg.blue/) Powered by Discuz! X3.1