SHARE
TWEET

Advanced Recipe Crafting

Vlue Apr 13th, 2014 (edited) 4,206 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #Advanced Recipe Crafting v1.2
  2. #----------#
  3. #Features: Advanced Recipe crafting! Hold on tight!
  4. #
  5. #Usage:    Set up your recipes, learn recipes, make items! Yay!
  6. #       $crafting_category = :craft         - call before Scene, craft is category
  7. #       SceneManager.call(Scene_Crafting)   - opens the Crafting menu
  8. #       SceneManager.call(Scene_CraftingAll)- opens the category Crafting menu
  9. #       learn_recipe(id)                    - teaches that recipe
  10. #       forget_recipe(id)                   - forgets that recipe
  11. #
  12. #----------#
  13. #-- Script by: V.M of D.T
  14. #
  15. #- Questions or comments can be:
  16. #    given by email: sumptuaryspade@live.ca
  17. #    provided on facebook: http://www.facebook.com/DaimoniousTailsGames
  18. #   All my other scripts and projects can be found here: http://daimonioustails.weebly.com/
  19. #
  20. #- Free to use in any project with credit given, donations always welcome!
  21.  
  22. module ADV_RECIPE
  23. #Whether or not crafted items use Weapon/Armor Randomization
  24.   USE_WA_RANDOMIZATION = false
  25. #The names of the categories for All Crafting Menu, use :All for all recipes
  26.   CATEGORIES = [:Alchemy,:Blacksmith,:Tailor,:Armorer,:Carpenter,:Builder,:Etceterer]
  27.   DESCRIPTIONS = {
  28.     :Alchemy => "This skill allows you to mix this and that. Potion!",
  29.     :Tailor => "The ability to sew numerous things together to make another thing.",
  30.     :Carpenter => "Everything's made out of wood."
  31.   }
  32. #The icons for categories, same order as above
  33.   CATEGORY_ICONS = [10,199,284,332,0,0,0]
  34. #The icon for player level
  35.   LEVEL_ICON = 117
  36. #Xp needed for crafting level, lvl is used for current level
  37.   XP_NEEDED_EQUATION = "100 * lvl"
  38. #Allow the crafting of multiple items
  39.   CRAFT_MULTIPLE = true
  40. #Allow or disallow menu access to the crafting scene
  41.   ENABLE_MENU_ACCESS = true
  42. #Disable crafting from menu (turning it into a recipe viewer)
  43.   DISABLE_MENU_CRAFT = false
  44. #Font Size of Detail window, smaller font size creates more room for materials
  45.   DETAIL_FONT_SIZE = 18
  46.  
  47.  
  48. #The following options disable the display of certain features. They still work
  49. # however if declared in recipes, so edit recipes accordingly.
  50. #Removes Gold Cost
  51.   DISABLE_GOLD_COST = false
  52. #Removes success rate
  53.   DISABLE_SUCCESS = false
  54. #Removes player level requirement
  55.   DISABLE_PLAYER_LEVEL = false
  56. #Removes crafting level requirement and gauge
  57.   DISABLE_CRAFT_LEVEL = false
  58. #Auto-learn all skills (can use forget_recipe to forget certain ones for later)
  59.   AUTO_LEARN_RECIPES = true
  60.  
  61.  
  62. #The fun (read: complicated) part!
  63. #Recipe symbols:
  64. #
  65. #The crafted item, type is 0 for item, 1 for weapon, 2 for armor
  66. # :result => [type,id,amount]
  67. #
  68. #The materials required, same style as result.
  69. # :materials => [ [type,id,amount,consumed?],[type,id,amount] ... ],
  70. #
  71. #  All the following are optional:
  72. # :gold_cost => amount          - amount of gold to craft, can be 0
  73. # :success => percent           - base percent chance of successful craft
  74. # :success_gain => percent      - percent gain on success per crafting level
  75. # :level => value               - Hero level required to craft
  76. # :craft_level => value         - Crafting level required to craft
  77. # :category => :category        - Crafting category (:Alchemy, :Tailor, etc)
  78. # :multiple => false            - disallows multiple crafts
  79. # :xp => amount                 - base Crafting xp gained per craft
  80. # :xp_deprac => amount          - Xp lost per crafting level
  81. # :pxp => amount                - Player xp gainer per craft
  82.  
  83. # Formula for xp gained is as follows and is never negative:
  84. #  xp gain = xp - (current_level - recipe_level) * xp_deprac
  85.  
  86.   RECIPES = {
  87.   0 => { :result => [0,1,1],
  88.          :materials => [[0,4,2]],
  89.          :gold_cost => 10,
  90.          :success => 95,
  91.          :success_gain => 1,
  92.          :level => 5,
  93.          :craft_level => 1,
  94.          :category => :Alchemy,
  95.          :xp => 50,
  96.          :xp_deprac => 15,},
  97.          
  98.   1 => { :result => [0,2,1],
  99.          :materials => [[1,4,1],[0,5,2,false]],
  100.          :gold_cost => 50,
  101.          :success => 90,
  102.          :success_gain => 2,
  103.          :level => 15,
  104.          :craft_level => 1,
  105.          :category => :Alchemy,
  106.          :xp => 150,
  107.          :xp_deprac => 20,},
  108.          
  109.   2 => { :result => [0,3,1],
  110.          :materials => [[0,4,1],[0,5,1],[0,6,2],[0,7,1],[0,8,1],[0,9,2]],
  111.          :gold_cost => 150,
  112.          :success => 85,
  113.          :success_gain => 3,
  114.          :level => 25,
  115.          :craft_level => 1,
  116.          :category => :Alchemy,
  117.          :xp => 250,
  118.          :xp_deprac => 25,},
  119.          
  120.   }
  121.  
  122. end
  123.  
  124. $crafting_category = :All
  125. class Recipe
  126.   attr_accessor :result
  127.   attr_accessor :materials
  128.   attr_accessor :known
  129.   attr_accessor :id
  130.   attr_accessor :gold_cost
  131.   attr_accessor :level
  132.   attr_accessor :category
  133.   attr_accessor :xp
  134.   def initialize(id,recipe_hash)
  135.     @id = id
  136.     @result = Material.new(recipe_hash[:result])
  137.     @materials = []
  138.     for item in recipe_hash[:materials]
  139.       @materials.push(Material.new(item))
  140.     end
  141.     @known = false
  142.     recipe_hash[:gold_cost] ? @gold_cost = recipe_hash[:gold_cost] : @gold_cost = 0
  143.     recipe_hash[:success] ? @rate = recipe_hash[:success] : @rate = 100
  144.     recipe_hash[:success_gain] ? @rated = recipe_hash[:success_gain] : @rated = 0
  145.     recipe_hash[:level] ? @level = recipe_hash[:level] : @level = 1
  146.     recipe_hash[:category] ? @category = recipe_hash[:category] : @category = CATEGORIES[0]
  147.     recipe_hash[:xp] ? @xp = recipe_hash[:xp] : @xp = 0
  148.     recipe_hash[:xp_deprac] ? @xpd = recipe_hash[:xp_deprac] : @xpd = 0
  149.     recipe_hash[:craft_level] ? @clevel = recipe_hash[:craft_level] : @clevel = 0
  150.     recipe_hash[:pxp] ? @pxp = recipe_hash[:pxp] : @pxp = 0
  151.     !recipe_hash[:multiple].nil? ? @mult = recipe_hash[:multiple] : @mult = true
  152.     @known = ADV_RECIPE::AUTO_LEARN_RECIPES
  153.   end
  154.   def name
  155.     return @result.item.name
  156.   end
  157.   def multiple?
  158.     @mult
  159.   end
  160.   def has_materials?
  161.     for item in @materials
  162.       return false unless $game_party.item_number(item.item) >= item.amount
  163.     end
  164.     return true
  165.   end
  166.   def has_gold?
  167.     $game_party.gold >= @gold_cost
  168.   end
  169.   def has_craft_level?
  170.     craft_level <= $game_party.craft_level_sym(@category)
  171.   end
  172.   def has_level?
  173.     @level <= $game_party.highest_level && has_craft_level?
  174.   end
  175.   def craftable?
  176.     has_gold? && has_materials? && has_level?
  177.   end
  178.   def craft_level
  179.     @clevel
  180.   end
  181.   def amount_craftable?
  182.     mat_amount = []
  183.     for item in @materials
  184.       mat_amount.push($game_party.item_number(item.item) / item.amount)
  185.     end
  186.     if @gold_cost > 0
  187.       return [$game_party.gold / @gold_cost,mat_amount.min].min
  188.     else
  189.       return mat_amount.min
  190.     end
  191.   end
  192.   def craft(fail = 0)
  193.     remove_materials
  194.     if fail < success_rate
  195.       return add_result
  196.     else
  197.       return nil
  198.     end
  199.   end
  200.   def remove_materials
  201.     for item in @materials
  202.       next unless item.consumed?
  203.       $game_party.gain_item(item.item,-item.amount)
  204.     end
  205.     $game_party.gain_gold(-@gold_cost)
  206.   end
  207.   def add_result
  208.     if ADV_RECIPE::USE_WA_RANDOMIZATION
  209.       item = $game_party.add_weapon(@result.item.id,@result.amount) if @result.item.is_a?(RPG::Weapon)
  210.       item = $game_party.add_armor(@result.item.id,@result.amount) if @result.item.is_a?(RPG::Armor)
  211.       item = $game_party.add_item(@result.item.id,@result.amount) if @result.item.is_a?(RPG::Item)
  212.     else
  213.       $game_party.gain_item(@result.item,@result.amount)
  214.       item = @result.item
  215.     end
  216.     $game_party.gain_craft_exp(category_id, xp_gain)
  217.     $game_party.members.each do |actor|
  218.       actor.gain_exp(@pxp)
  219.     end
  220.     item
  221.   end
  222.   def category_id
  223.     ADV_RECIPE::CATEGORIES.index(@category)
  224.   end
  225.   def xp_gain
  226.     level_diff = $game_party.craft_level(category_id) - @clevel
  227.     [@xp - @xpd * level_diff,0].max
  228.   end
  229.   def success_rate
  230.     level_diff = $game_party.craft_level(category_id) - @clevel
  231.     [@rate + @rated * level_diff,100].min
  232.   end
  233. end
  234.  
  235. class Material
  236.   attr_accessor :item
  237.   attr_accessor :amount
  238.   def initialize(mat)
  239.     @item = $data_items[mat[1]] if mat[0] == 0
  240.     @item = $data_weapons[mat[1]] if mat[0] == 1
  241.     @item = $data_armors[mat[1]] if mat[0] == 2
  242.     @amount = mat[2]
  243.     @consumed = mat[3].nil? ? true : mat[3]
  244.   end
  245.   def consumed?
  246.     @consumed
  247.   end
  248. end
  249.  
  250. class Game_Party
  251.   alias recipe_init initialize
  252.   def initialize
  253.     recipe_init
  254.     @crafting_level = [1]*ADV_RECIPE::CATEGORIES.size
  255.     @craft_exp = [0]*ADV_RECIPE::CATEGORIES.size
  256.   end
  257.   def craft_level(id)
  258.     @crafting_level[id]
  259.   end
  260.   def craft_level_sym(sym)
  261.     @crafting_level[ADV_RECIPE::CATEGORIES.index(sym)]
  262.   end
  263.   def craft_exp(id)
  264.     @craft_exp[id]
  265.   end
  266.   def craft_exp_next(id)
  267.     lvl = craft_level(id)
  268.     return eval(ADV_RECIPE::XP_NEEDED_EQUATION)
  269.   end
  270.   def gain_craft_exp(id, val)
  271.     @craft_exp[id] += val
  272.     while craft_exp(id) >= craft_exp_next(id)
  273.       @craft_exp[id] -= craft_exp_next(id)
  274.       @crafting_level[id] += 1
  275.     end
  276.   end
  277. end
  278.  
  279. module DataManager
  280.   class << self
  281.     alias rec_cgo create_game_objects
  282.     alias rec_msc make_save_contents
  283.     alias rec_esc extract_save_contents
  284.   end
  285.   def self.create_game_objects
  286.     rec_cgo
  287.     $game_recipes = create_recipes
  288.   end
  289.   def self.make_save_contents
  290.     contents = rec_msc
  291.     contents[:recipe] = $game_recipes
  292.     contents
  293.   end
  294.   def self.extract_save_contents(contents)
  295.     rec_esc(contents)
  296.     $game_recipes = contents[:recipe]
  297.   end
  298.   def self.create_recipes
  299.     recipes = {}
  300.     ADV_RECIPE::RECIPES.each_pair do |key, val|
  301.       recipes[key] = Recipe.new(key,val)
  302.     end
  303.     recipes
  304.   end
  305. end
  306.  
  307. class Game_Interpreter
  308.   def learn_recipe(id)
  309.     return if $game_recipes[id].nil?
  310.     $game_recipes[id].known = true
  311.   end
  312.   def forget_recipe(id)
  313.     return if $game_recipes[id].nil?
  314.     $game_recipes[id].known = false
  315.   end
  316. end
  317.  
  318. class Window_RecipeList < Window_Selectable
  319.   def initialize(x,y,w,h)
  320.     super
  321.     @data = $game_recipes.values.select {|recipe| include?(recipe)}
  322.     refresh
  323.   end
  324.   def item_max
  325.     @data ? @data.size : 1
  326.   end
  327.   def item
  328.     @data && index >= 0 ? @data[index] : nil
  329.   end
  330.   def current_item_enabled?
  331.     enable?(@data[index])
  332.   end
  333.   def include?(item)
  334.     return false unless item.has_craft_level?
  335.     return false unless item.known
  336.     return true if @category == :All
  337.     return @category == item.category
  338.   end
  339.   def set_category(cat)
  340.     return if cat == @category
  341.     @category = cat
  342.     @data = $game_recipes.values.select {|recipe| include?(recipe)}
  343.     refresh
  344.   end
  345.   def enable?(item)
  346.     return false if item.nil?
  347.     return false if $temp_disable_crafting
  348.     item.craftable?
  349.   end
  350.   def draw_item(index)
  351.     item = @data[index]
  352.     if item
  353.       rect = item_rect(index)
  354.       rect.width -= 4
  355.       enabled = $temp_disable_crafting ? true : enable?(item)
  356.       draw_item_name(item.result.item, rect.x, rect.y, enabled)
  357.       if item.amount_craftable? > 0
  358.         draw_text(rect.x,rect.y,contents.width,24,"x"+item.amount_craftable?.to_s,2)
  359.       end
  360.     end
  361.   end
  362.   def current_item
  363.     index >= 0 ? @data[index] : nil
  364.   end
  365.   def process_ok
  366.     if current_item_enabled?
  367.       Sound.play_ok
  368.       Input.update
  369.       call_ok_handler
  370.     else
  371.       Sound.play_buzzer
  372.     end
  373.   end
  374.   def refresh
  375.     create_contents
  376.     super
  377.   end
  378.   def content_heights
  379.     item_max * 24
  380.   end
  381. end
  382.  
  383. class Window_RecipeDetail < Window_Base
  384.   def initialize(x,y,w,h)
  385.     super
  386.     @recipe = nil
  387.   end
  388.   def set_recipe(recipe)
  389.     @recipe = recipe
  390.     refresh
  391.   end
  392.   def refresh
  393.     contents.clear
  394.     contents.font.size = ADV_RECIPE::DETAIL_FONT_SIZE
  395.     return if @recipe.nil?
  396.     draw_craft_level unless ADV_RECIPE::DISABLE_PLAYER_LEVEL && ADV_RECIPE::DISABLE_CRAFT_LEVEL
  397.     draw_materials
  398.     draw_success_rate unless ADV_RECIPE::DISABLE_SUCCESS
  399.     draw_gold_cost unless ADV_RECIPE::DISABLE_GOLD_COST
  400.   end
  401.   def draw_craft_level
  402.     change_color(system_color, @recipe.has_level?)
  403.     draw_text(0,0,contents.width,contents.font.size,"Craft Level:")
  404.     change_color(normal_color, @recipe.has_level?)
  405.     xx = 0
  406.     if !ADV_RECIPE::DISABLE_PLAYER_LEVEL
  407.       draw_text(0,0,contents.width,contents.font.size,@recipe.level,2)
  408.       draw_icon(ADV_RECIPE::LEVEL_ICON,contents.width - 48,0)
  409.       xx += 48
  410.       text = @recipe.craft_level.to_s + "/"
  411.     else
  412.       text = @recipe.craft_level.to_s
  413.     end
  414.     if !ADV_RECIPE::DISABLE_CRAFT_LEVEL
  415.       draw_text(0,0,contents.width - xx,contents.font.size,text,2)
  416.       draw_icon(ADV_RECIPE::CATEGORY_ICONS[ADV_RECIPE::CATEGORIES.index(@recipe.category)],contents.width - 56 - xx,0)
  417.     end
  418.   end
  419.   def draw_materials
  420.     if ADV_RECIPE::DISABLE_CRAFT_LEVEL && ADV_RECIPE::DISABLE_PLAYER_LEVEL
  421.       yy = 0
  422.     else
  423.       yy = contents.font.size
  424.     end
  425.     change_color(system_color, @recipe.craftable?)
  426.     draw_text(0,yy,self.width,contents.font.size,"Required:")
  427.     yy += contents.font.size
  428.     for item in @recipe.materials
  429.       change_color(normal_color, $game_party.item_number(item.item) >= item.amount)
  430.       draw_icon(item.item.icon_index,0,yy)
  431.       draw_text(24,yy,self.width,contents.font.size,item.item.name)
  432.       string = $game_party.item_number(item.item).to_s + "/" + item.amount.to_s
  433.       draw_text(0,yy,self.contents.width,contents.font.size,string,2)
  434.       yy += contents.font.size
  435.     end
  436.   end
  437.   def draw_success_rate
  438.     change_color(system_color, @recipe.craftable?)
  439.     draw_text(0,contents.height-contents.font.size,contents.width,contents.font.size,"Success Rate:")
  440.     change_color(normal_color, @recipe.craftable?)
  441.     draw_text(0,contents.height-contents.font.size,contents.width,contents.font.size,@recipe.success_rate.to_s + "%",2)
  442.   end
  443.   def draw_gold_cost
  444.     if @recipe.gold_cost > 0
  445.       change_color(system_color, @recipe.has_gold?)
  446.       draw_text(0,contents.height-contents.font.size*2,contents.width,contents.font.size,"Crafting Cost:")
  447.       change_color(normal_color, @recipe.has_gold?)
  448.       draw_currency_value(@recipe.gold_cost,Vocab::currency_unit,0,contents.height-contents.font.size*2,contents.width)
  449.     end  
  450.   end
  451.   def draw_currency_value(value, unit, x, y, width)
  452.     cx = text_size(unit).width
  453.     change_color(normal_color,$game_party.gold >= value)
  454.     draw_text(x, y, width - cx - 2, contents.font.size, value, 2)
  455.     change_color(system_color)
  456.     draw_text(x, y, width, contents.font.size, unit, 2)
  457.   end
  458. end
  459.  
  460. class Window_RecipeConfirm < Window_Selectable
  461.   attr_accessor :amount
  462.   def initialize(x,y,w,h)
  463.     super
  464.     @amount = 1
  465.     refresh
  466.   end
  467.   def item_max; 1; end;
  468.   def enable?(item); true; end;
  469.   def refresh
  470.     super
  471.     draw_text(0,0,self.contents.width,line_height,"Craft",1)
  472.     return unless @recipe && @recipe.craftable?
  473.     draw_text(0,0,contents.width,line_height,"x"+@amount.to_s,2)
  474.   end
  475.   def activate
  476.     super
  477.     select(0)
  478.   end
  479.   def deactivate
  480.     super
  481.     select(-1)
  482.   end
  483.   def set_recipe(rec)
  484.     return if rec == @recipe
  485.     @recipe = rec
  486.     @amount = 1
  487.     refresh
  488.   end
  489.   def cursor_movable?
  490.     active && open? && ADV_RECIPE::CRAFT_MULTIPLE && @recipe.multiple?
  491.   end
  492.   def cursor_down(wrap = false)
  493.     change_amount(-10)
  494.   end
  495.   def cursor_up(wrap = false)
  496.     change_amount(10)
  497.   end
  498.   def cursor_right(wrap = false)
  499.     change_amount(1)
  500.   end
  501.   def cursor_left(wrap = false)
  502.     change_amount(-1)
  503.   end
  504.   def change_amount(val)
  505.     Sound.play_cursor
  506.     @amount += val
  507.     @amount = [[@amount,1].max,@recipe.amount_craftable?].min
  508.     refresh
  509.   end
  510. end
  511.  
  512. class Scene_CraftingAll < Scene_Base
  513.   def start
  514.     super
  515.     @help_window = Window_Help.new
  516.     width = Graphics.width / 2
  517.     height = Graphics.height - @help_window.height - 48
  518.     @list_window = Window_RecipeList.new(0,@help_window.height+48,width,height-48)
  519.     @list_window.set_handler(:ok, method(:list_success))
  520.     @list_window.set_handler(:cancel, method(:cancel))
  521.     @list_window.height += 48 if ADV_RECIPE::DISABLE_CRAFT_LEVEL
  522.     @list_window.create_contents
  523.     @detail_window = Window_RecipeDetail.new(width,@list_window.y,width,height-48*2)
  524.     @detail_window.height += 48 if ADV_RECIPE::DISABLE_GOLD_COST
  525.     @detail_window.create_contents
  526.     height = @detail_window.y + @detail_window.height
  527.     @confirm_window = Window_RecipeConfirm.new(width,height,width,48)
  528.     @confirm_window.set_handler(:ok, method(:craft_success))
  529.     @confirm_window.set_handler(:cancel, method(:confirm_cancel))
  530.     if !ADV_RECIPE::DISABLE_GOLD_COST
  531.       @gold_window = Window_Gold.new
  532.       @gold_window.width = width
  533.       @gold_window.y = Graphics.height - 48
  534.       @gold_window.x = width
  535.     end
  536.     @popup_window = Window_RecPopup.new
  537.     @popup_window.set_handler(:ok, method(:popup_ok))
  538.     @popup_window.set_handler(:cancel, method(:popup_ok))
  539.     @command_window = Window_RecCategory.new
  540.     @command_window.set_handler(:ok, method(:command_ok))
  541.     @command_window.set_handler(:cancel, method(:command_cancel))
  542.     @gauge_window = Window_RecGauge.new unless ADV_RECIPE::DISABLE_CRAFT_LEVEL
  543.   end
  544.   def popup_ok
  545.     @popup_window.deactivate
  546.     @popup_window.close
  547.     @list_window.activate
  548.   end
  549.   def update
  550.     super
  551.     @help_window.set_text(@list_window.current_item.result.item.description) if !@list_window.current_item.nil?
  552.     if @command_window.active
  553.       category = ADV_RECIPE::CATEGORIES[@command_window.index]
  554.       @help_window.set_text(ADV_RECIPE::DESCRIPTIONS[category])
  555.     end
  556.     @detail_window.set_recipe(@list_window.current_item)
  557.     @confirm_window.set_recipe(@list_window.current_item)
  558.     @list_window.set_category(ADV_RECIPE::CATEGORIES[@command_window.index])
  559.     @gauge_window.set_category(ADV_RECIPE::CATEGORIES[@command_window.index]) unless ADV_RECIPE::DISABLE_CRAFT_LEVEL
  560.     return unless @list_window.current_item
  561.     if @list_window.current_item.craftable?
  562.       @confirm_window.opacity = 255
  563.       @confirm_window.contents_opacity = 255
  564.     else
  565.       @confirm_window.opacity = 75
  566.       @confirm_window.contents_opacity = 75
  567.     end
  568.   end
  569.   def list_success
  570.     @list_window.deactivate
  571.     @confirm_window.activate
  572.   end
  573.   def craft_success
  574.     amount = 0
  575.     item = nil
  576.     @confirm_window.amount.times do
  577.       item2 = @list_window.current_item.craft(rand(100))
  578.       if item2
  579.         amount += 1
  580.         item = item2
  581.       end
  582.     end
  583.     if item
  584.       @popup_window.set_text(item, amount)
  585.     else
  586.       @popup_window.set_text_fail
  587.     end
  588.     @confirm_window.change_amount(-1000)
  589.     @gold_window.refresh unless ADV_RECIPE::DISABLE_GOLD_COST
  590.     @list_window.refresh
  591.     @gauge_window.refresh unless ADV_RECIPE::DISABLE_CRAFT_LEVEL
  592.     @popup_window.activate
  593.   end
  594.   def confirm_cancel
  595.     @confirm_window.deactivate
  596.     @list_window.activate
  597.   end
  598.   def command_cancel
  599.     $temp_disable_crafting = false
  600.     SceneManager.return
  601.   end
  602.   def cancel
  603.     @list_window.select(-1)
  604.     @help_window.set_text("")
  605.     @command_window.activate
  606.   end
  607.   def command_ok
  608.     @list_window.select(0)
  609.     @list_window.activate
  610.   end
  611. end
  612.  
  613. class Scene_Crafting < Scene_CraftingAll
  614.   def start
  615.     super
  616.     @command_window.index = ADV_RECIPE::CATEGORIES.index($crafting_category)
  617.     @command_window.deactivate
  618.     @command_window.visible = false
  619.     @list_window.height += 48
  620.     @list_window.y -= 48
  621.     @detail_window.height += 48
  622.     @detail_window.y -= 48
  623.     @list_window.create_contents
  624.     @detail_window.create_contents
  625.     @list_window.select(0)
  626.     @list_window.activate
  627.   end
  628.   def cancel
  629.     SceneManager.return
  630.   end
  631. end
  632.  
  633. class Window_RecCategory < Window_HorzCommand
  634.   def initialize
  635.     super(0,72)
  636.   end
  637.   def window_width; Graphics.width; end
  638.   def window_height; 48; end
  639.   def make_command_list
  640.     ADV_RECIPE::CATEGORIES.each do |command|
  641.       add_command(command.to_s,command)
  642.     end
  643.   end
  644.   def item_width
  645.     120
  646.   end
  647.   def draw_item(index)
  648.     change_color(normal_color, command_enabled?(index))
  649.     rect = item_rect_for_text(index)
  650.     draw_text(rect, command_name(index))
  651.     draw_icon(ADV_RECIPE::CATEGORY_ICONS[index],rect.x-24,rect.y)
  652.   end
  653.   def item_rect_for_text(index)
  654.     rect = item_rect(index)
  655.     rect.x += 28
  656.     rect.width -= 28
  657.     rect
  658.   end
  659. end
  660.  
  661. class Window_RecPopup < Window_Selectable
  662.   def initialize
  663.     super(Graphics.width/2-window_width/2,Graphics.height/2-window_height/2,120,48)
  664.     self.openness = 0
  665.     deactivate
  666.   end
  667.   def window_width; 120; end
  668.   def window_height; 48; end
  669.   def set_text(item, amount)
  670.     contents.clear
  671.     text = amount.to_s + "x " + item.name + " crafted!"
  672.     width = contents.text_size(text).width
  673.     self.width = width + padding*2
  674.     self.x = Graphics.width/2-width/2
  675.     create_contents
  676.     draw_text(24,0,contents.width,line_height,text)
  677.     draw_icon(item.icon_index,0,0)
  678.     open
  679.   end
  680.   def set_text_fail
  681.     contents.clear
  682.     text = "Crafting failed!"
  683.     width = contents.text_size(text).width
  684.     self.width = width + padding*2
  685.     self.x = Graphics.width/2-width/2
  686.     create_contents
  687.     draw_text(12,0,contents.width,line_height,text)
  688.     open
  689.   end
  690.   def process_ok
  691.     if current_item_enabled?
  692.       Input.update
  693.       deactivate
  694.       call_ok_handler
  695.     else
  696.       Sound.play_buzzer
  697.     end
  698.   end
  699. end
  700.  
  701. class Window_RecGauge < Window_Base
  702.   def initialize
  703.     super(0,Graphics.height-48,Graphics.width/2,48)
  704.     @category = :All
  705.   end
  706.   def refresh
  707.     contents.clear
  708.     return if @category == :All
  709.     draw_icon(ADV_RECIPE::CATEGORY_ICONS[cat_index],0,0)
  710.     draw_text(24,0,contents.width,24,$game_party.craft_level(cat_index))
  711.     rate = $game_party.craft_exp(cat_index).to_f / $game_party.craft_exp_next(cat_index)
  712.     draw_gauge(48, -3, contents.width-48, rate, tp_gauge_color1, tp_gauge_color2)
  713.     if Module.const_defined?(:SPECIAL_GAUGES)
  714.       @gauges[[48,-3]].set_extra("XP",$game_party.craft_exp(cat_index),$game_party.craft_exp_next(cat_index))
  715.     else
  716.       text = $game_party.craft_exp(cat_index).to_s+"/"+$game_party.craft_exp_next(cat_index).to_s
  717.       draw_text(0,0,contents.width,24,text,2)
  718.     end
  719.   end
  720.   def set_category(cat)
  721.     return if cat == @category
  722.     @category = cat
  723.     refresh
  724.   end
  725.   def cat_index
  726.     ADV_RECIPE::CATEGORIES.index(@category)
  727.   end
  728. end
  729.  
  730. class Window_MenuCommand < Window_Command
  731.   alias recipe_aoc add_original_commands
  732.   def add_original_commands
  733.     recipe_aoc
  734.     add_command("Crafting", :recipe) if ADV_RECIPE::ENABLE_MENU_ACCESS
  735.   end
  736. end
  737.  
  738. class Scene_Menu < Scene_MenuBase
  739.   alias recipe_create_command_window create_command_window
  740.   def create_command_window
  741.     recipe_create_command_window
  742.     @command_window.set_handler(:recipe,   method(:command_recipe))
  743.   end
  744.   def command_recipe
  745.     $temp_disable_crafting = ADV_RECIPE::DISABLE_MENU_CRAFT
  746.     SceneManager.call(Scene_CraftingAll)
  747.   end
  748. end
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top