Advertisement
eugene222

"DIYC"-Advanced

Jun 8th, 2015
373
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Ruby 65.13 KB | None | 0 0
  1. =begin
  2.   "Do It Yourself"-Crafting-Advanced
  3.  
  4.   Author:  Evgenij
  5.   Version: 1.0-beta3
  6.   Date:    31.07.2015
  7.  
  8.   You can find the terms of use at my blog: evgenij-scripts.org
  9.  
  10.   Changelog:
  11.  
  12.     1.0-beta3  :  - Fixed a bug: fixed tool is the same for all types
  13.                     when type list are used on script call
  14.                   - Changed the way the item category window works to
  15.                     make the scene more smooth
  16.                   - Added new recipe list mode for faster crafting of
  17.                     learned recipes
  18.  
  19.     1.0-beta2  :  - Renamed the script to "DIYC-Advanced" to prevent confusion
  20.                     with my old "DIYC" Script
  21.                   - Ingredient slot size is now controllable via a variable
  22.                   - Crafting Types now switchable with L/R (Q/W on Keyboard)
  23.                   - Switched item and ingredient window positions
  24.                   - Removed the start/view results subwindow, now crafting is
  25.                     started via a button and results can be viewed from
  26.                     the general command menu
  27.                   - Updated help window to support commands
  28.                   - Confirmation window to start the crafting added(optional)
  29.  
  30.     1.0-beta   :  - added OWN_INGREDIENT_CONTROL Flag to Settings
  31.  
  32.     1.0-alpha3 :  - Added result amount multiplier to recipes
  33.                   - Type leveling is now optional and
  34.                     can be changed per type
  35.                   - Tools can now be disabled per type and
  36.                     not globally
  37.                   - It is now possible to disable loosing
  38.                     items when crafting fails
  39.                   - It is now possible to disable loosing
  40.                     items when crafting is impossible
  41.  
  42.     1.0-alpha2 :  - Added customization for exp gauge colors
  43.                   - Added customization to cap ingredients
  44.                   - Fixed clear command
  45.  
  46.     1.0-alpha  :  - Pre-Release
  47.  
  48.   Installation:
  49.     Place this Script into the Materials Section in your
  50.     Scripteditor.
  51.  
  52.   Scriptcalls:
  53.  
  54.     Opens the normal crafting scene:
  55.       - EVG::CraftingManager.open(crafting_type)
  56.       - EVG::CraftingManager.open(crafting_type => :tool, ...)
  57.  
  58.     You can use as much crafting types as you want, you will need to separate
  59.     them with a comma.
  60.  
  61.     Examples:
  62.       # Opens crafting scene with alchemy as type
  63.         - EVG::CraftingManager.open(:Alchemy)
  64.  
  65.       # Opens crafting scene with alchemy as type and Item 10 as fixed tool
  66.         - EVG::CraftingManager.open(:Alchemy => :i10)
  67.  
  68.       # Opens crafting scene with switchable types (L/R Buttons)
  69.         - EVG::CraftingManager.open(:Alchemy, :Smithing)
  70.  
  71.       # Opens crafting scene with switchable types and fixed tools
  72.         - EVG::CraftingManager.open(:Alchemy => i10, :Smithing => i11)
  73.  
  74.  
  75.   Notetags:
  76.  
  77.     <no_ingredient>
  78.       This will hide the item in the crafting
  79.       scene.
  80.  
  81.     These notetags can be used multiple times on one item:
  82.  
  83.     <tool: :CraftingType>
  84.       This will also hide the item from the ingredient window
  85.       and will show the item in the tool window in the
  86.       matching CraftingType Scene.
  87.  
  88.     <craft_type: :CraftingType>
  89.       This will only show this item in the ingredient window
  90.       of the correct crafting type.
  91.  
  92.   Defining new types:
  93.  
  94.     Before I will explain how to define new Types I want to
  95.     explain you the word Module I will be using often.
  96.     In Ruby a Module looks like this:
  97.  
  98.     module MODULE_NAME
  99.     end
  100.  
  101.     You will need modules for almost everything in this script.
  102.  
  103.     Then if you see this: :item you will need to replace it with
  104.     the item you want to use.
  105.     Examples:
  106.       Weapon 1  would look like this:   :w1
  107.       Item 1    would look like this:   :i1
  108.       Armor 1   would look like this:   :a1
  109.  
  110.     So lets start:
  111.  
  112.     1. Go into CRAFTING_TYPES Module below.
  113.     2. Copy this Template into the module:
  114.  
  115.     module Your_Type_Name
  116.       Vocab       = "Your Type Vocab"
  117.  
  118.       # Level Settings
  119.       Enable_Leveling = true
  120.       # Exp formula, type_level will be replaced
  121.       # by your current type level
  122.       Exp_Formula     = "100 * type_level"
  123.       Max_Level       = 50
  124.       # Exp Gauge Colors. Use windowskin indexes
  125.       Gauge_Color1    = 24
  126.       Gauge_Color2    = 24
  127.  
  128.       # Tool Settings
  129.       Enable_Tool = true
  130.  
  131.       # Setup visible categories
  132.       # :item, :armor and :weapon possible
  133.       Possible_Categories = [:item, :armor, :weapon]
  134.  
  135.       # How many ingredient slots should be visible?
  136.       # Control this via an ingame variable
  137.       # Use nil if you don't want to control this (unlimited slots)
  138.       Ingredient_Size_Variable = nil
  139.  
  140.       # Loose Items Settings
  141.       Loose_On_Failure    = true
  142.       Loose_On_Impossible = true
  143.  
  144.       #Sound Settings
  145.       Success_Me        = "Item"
  146.       Failure_Me        = "Gag"
  147.       Impossible_Me     = "Mystery"
  148.  
  149.       module Recipes
  150.       end
  151.     end
  152.  
  153.     It should look like this:
  154.  
  155.     module CRAFTING_TYPES
  156.       module Your_Type_Name
  157.         #...
  158.  
  159.         module Recipes
  160.         end
  161.       end
  162.     end
  163.  
  164.  
  165.     3. Now you need to change all the variables to your liking
  166.     4. Recipes are missing, so you need to copy this template
  167.        into the Recipes module in your type module:
  168.  
  169.     module Your_Recipe_Name
  170.  
  171.       # Tool can be nil or :item
  172.       Tool            = nil
  173.       Ingredients     = {:item => amount, :item => amount}
  174.       Results         = {:item => amount}
  175.       Base_Level      = 1       # Used for exp and success formulas
  176.       Success         = 100     # Base Success Percentage
  177.       Success_Change  = 1       # Success-Change every level
  178.       Exp             = 20      # Base Exp
  179.       Exp_Change      = 1       # Exp Change every level
  180.  
  181.       # Result Multiplier Settings
  182.       Result_Multiplier = 1
  183.       Result_Proc_Level = 1     # First Level for more results
  184.       Result_Proc_Rate  = 0     # Chance to multiply result amount
  185.     end
  186.  
  187.     It should look like this now:
  188.  
  189.     module CRAFTING_TYPES
  190.       module Your_Type_Name
  191.         #...
  192.  
  193.         module Recipes
  194.  
  195.           module Your_Recipe_Name
  196.             #...
  197.           end
  198.  
  199.         end
  200.       end
  201.     end
  202.  
  203.     You can add as many types and recipes as you want.
  204.     Its important that every Type has a unique< name.
  205.  
  206.     I have predefined two types with recipes. So take
  207.     a look at them if you don't understand something.
  208. =end
  209. module EVG
  210.   module CRAFTING_SETTINGS
  211.  
  212.     # This button needs to be pressed to start crafting
  213.     CRAFTING_START_BUTTON = :X
  214.  
  215.     # For easier clearing
  216.     CRAFTING_CLEAR_BUTTON = :SHIFT
  217.  
  218.     # Lets a confirmation window popup before the actual
  219.     # crafting starts
  220.     USE_CONFIRMATION_WINDOW = false
  221.  
  222.  
  223.     # Here you can define which types will be
  224.     # shown in your main menu.
  225.     # Keep in mind that this was designed for the
  226.     # vanilla menu, so any custom menu may need
  227.     # a compatibility patch.
  228.     #              :type_name => enable_switch_id,
  229.     TYPES_IN_MENU = {:Alchemy => 1}
  230.  
  231.     # If you for example have more than one Type added to your
  232.     # menu this flag will allow switching with L and R through
  233.     # your menu types
  234.     CAN_SWITCH_MENU_TYPES = true
  235.  
  236.     # Learned recipes can be directly crafted when the switch
  237.     # mode is on.
  238.     # The player just needs to press the X-Button (S on Keyboard)
  239.     # to switch through the crafting modes
  240.     CAN_SWITCH_TO_RECIPE_MODE = true
  241.  
  242.     # if this is set to true, you will need to specify
  243.     # all items with <craft_type: :type> to mark them
  244.     # as ingredient otherwise they will be handled as
  245.     # no ingredient.
  246.     OWN_INGREDIENT_CONTROL = false
  247.  
  248.     #These Settings should be self explanatory
  249.     NO_TOOL_VOCAB      = "Hands"
  250.     NO_TOOL_ICON_INDEX = 481
  251.  
  252.     COMMAND_VOCABS = {
  253.         :Add          => "Add",
  254.         :Remove       => "Remove",
  255.         :Clear        => "Clear",
  256.         :Tool         => "Tool",
  257.         :View_Results => "Results",
  258.     }
  259.  
  260.     COMMAND_DESCRIPTIONS  = {
  261.         :Add          => "Add ingredients into the slot list",
  262.         :Remove       => "Remove ingredients from the slot list",
  263.         :Clear        => "Clear slot list and tool",
  264.         :Tool         => "Choose a tool you want to use",
  265.         :View_Results => "View results if your current recipe yields a\npossible result",
  266.     }
  267.  
  268.     SUCCESS_VOCAB         = "Success:"
  269.     EXP_VOCAB             = "EXP:"
  270.  
  271.     CRAFTING_START_VOCAB  = "Press \"A\" to start crafting"
  272.     RECIPE_LEARNED_VOCAB  = "New recipe learned!"
  273.     SUCCESS_CRAFT_VOCAB   = "Successful crafted:"
  274.     EXP_GAIN_VOCAB        = "Got %d EXP"
  275.     FAILED_CRAFT_VOCAB    = "Crafting failed!"
  276.     IMPOSSIBLE_VOCAB      = "Impossible recipe!"
  277.  
  278.     PREV_CATEGORY_VOCAB = "<-Q"
  279.     NEXT_CATEGORY_VOCAB = "W->"
  280.  
  281.     # Here you can define a switch id
  282.     # When the switch with this switch id is
  283.     # on, the player will only be able to add
  284.     # items into the pool which lead to possible
  285.     # recipes.
  286.     PERFECT_CRAFTING_SWITCH_ID = 0
  287.     # This feature may lead to long waiting times
  288.     # when you have defined too many recipes, so
  289.     # if you use it and have slowdowns, send me a
  290.     # demo with your config.
  291.     # When I get a demo with many recipes I will
  292.     # try to optimize this feature.
  293.   end
  294.   # Here you will define all your crafting types
  295.   module CRAFTING_TYPES
  296.     # Smithing
  297.     module Smithing
  298.  
  299.       Vocab       = "Smithing"
  300.  
  301.       # Level Settings
  302.       Enable_Leveling = true
  303.       # Exp formula, type_level will be replaced
  304.       # by your current type level
  305.       Exp_Formula     = "100 * type_level"
  306.       Max_Level       = 50
  307.       # Exp Gauge Colors. Use windowskin indexes
  308.       Gauge_Color1    = 24
  309.       Gauge_Color2    = 24
  310.  
  311.       # Tool Settings
  312.       Enable_Tool = true
  313.  
  314.       # Setup visible categories
  315.       # :item, :armor and :weapon possible
  316.       Possible_Categories = [:item, :armor, :weapon]
  317.  
  318.       # How many ingredient slots should be visible?
  319.       # Control this via an ingame variable
  320.       # Use nil if you don't want to control this (unlimited slots)
  321.       Ingredient_Size_Variable = nil
  322.  
  323.       # Loose Items Settings
  324.       Loose_On_Failure    = true
  325.       Loose_On_Impossible = true
  326.  
  327.       #Sound Settings
  328.       Success_Me        = "Item"
  329.       Failure_Me        = "Gag"
  330.       Impossible_Me     = "Mystery"
  331.  
  332.       module Recipes
  333.         # Normal Recipes:
  334.         module Axe1
  335.           Tool            = nil
  336.           Ingredients     = {:i26 => 1, :w1 => 1}
  337.           Results         = {:w2 => 1}
  338.           Base_Level      = 1
  339.           Success         = 90
  340.           Success_Change  = 5
  341.           Exp             = 25
  342.           Exp_Change      = 5
  343.           # Result Multiplier Settings
  344.           Result_Multiplier = 1
  345.           Result_Proc_Level = 1
  346.           Result_Proc_Rate  = 0
  347.         end
  348.  
  349.         module Axe2
  350.           Tool            = nil
  351.           Ingredients     = {:i26 => 1, :w2 => 1}
  352.           Results         = {:w3 => 1}
  353.           Base_Level      = 2
  354.           Success         = 80
  355.           Success_Change  = 5
  356.           Exp             = 40
  357.           Exp_Change      = 7
  358.           # Result Multiplier Settings
  359.           Result_Multiplier = 1
  360.           Result_Proc_Level = 1
  361.           Result_Proc_Rate  = 0
  362.         end
  363.  
  364.         module Axe3
  365.           Tool            = nil
  366.           Ingredients     = {:i26 => 1, :w3 => 1}
  367.           Results         = {:w4 => 1}
  368.           Base_Level      = 5
  369.           Success         = 75
  370.           Success_Change  = 5
  371.           Exp             = 60
  372.           Exp_Change      = 10
  373.           # Result Multiplier Settings
  374.           Result_Multiplier = 1
  375.           Result_Proc_Level = 1
  376.           Result_Proc_Rate  = 0
  377.         end
  378.       end
  379.     end # Smithing END
  380.  
  381.     # Alchemy
  382.     module Alchemy
  383.  
  384.       Vocab       = "Alchemy"
  385.       # Level Settings
  386.       Enable_Leveling = true
  387.       # Exp formula, type_level will be replaced
  388.       # by your current type level
  389.       Exp_Formula     = "100 * type_level"
  390.       Max_Level       = 50
  391.       # Exp Gauge Colors. Use windowskin indexes
  392.       Gauge_Color1    = 24
  393.       Gauge_Color2    = 24
  394.  
  395.       # Tool Settings
  396.       Enable_Tool = true
  397.  
  398.       # Setup visible categories
  399.       # :item, :armor and :weapon possible
  400.       Possible_Categories = [:item]
  401.  
  402.       # How many ingredient slots should be visible?
  403.       # Control this via an ingame variable
  404.       # Use nil if you don't want to control this (unlimited slots)
  405.       Ingredient_Size_Variable = nil
  406.  
  407.       # Loose Items Settings
  408.       Loose_On_Failure    = true
  409.       Loose_On_Impossible = true
  410.  
  411.       #Sound Settings
  412.       Success_Me        = "Item"
  413.       Failure_Me        = "Gag"
  414.       Impossible_Me     = "Mystery"
  415.  
  416.       module Recipes
  417.  
  418.         # Extractor Recipes:
  419.         module Life_Powder
  420.           Tool            = :i21
  421.           Ingredients     = {:i24 => 1}
  422.           Results         = {:i22 => 1}
  423.           Base_Level      = 1
  424.           Success         = 90
  425.           Success_Change  = 5
  426.           Exp             = 20
  427.           Exp_Change      = 5
  428.           # Result Multiplier Settings
  429.           Result_Multiplier = 1
  430.           Result_Proc_Level = 1
  431.           Result_Proc_Rate  = 0
  432.         end
  433.  
  434.         # Normal Recipes:
  435.         module Potion
  436.           Tool            = nil
  437.           Ingredients     = {:i22 => 2, :i23 => 1}
  438.           Results         = {:i1 => 1}
  439.           Base_Level      = 1
  440.           Success         = 90
  441.           Success_Change  = 5
  442.           Exp             = 25
  443.           Exp_Change      = 5
  444.           # Result Multiplier Settings
  445.           Result_Multiplier = 3
  446.           Result_Proc_Level = 1
  447.           Result_Proc_Rate  = 0
  448.         end
  449.  
  450.         module Potion2
  451.           Tool            = nil
  452.           Ingredients     = {:i22 => 3, :i23 => 1}
  453.           Results         = {:i2 => 1}
  454.           Base_Level      = 2
  455.           Success         = 80
  456.           Success_Change  = 5
  457.           Exp             = 40
  458.           Exp_Change      = 7
  459.           # Result Multiplier Settings
  460.           Result_Multiplier = 1
  461.           Result_Proc_Level = 1
  462.           Result_Proc_Rate  = 0
  463.         end
  464.  
  465.         module Potion3
  466.           Tool            = nil
  467.           Ingredients     = {:i22 => 4, :i23 => 1}
  468.           Results         = {:i3 => 1}
  469.           Base_Level      = 4
  470.           Success         = 75
  471.           Success_Change  = 5
  472.           Exp             = 60
  473.           Exp_Change      = 10
  474.           # Result Multiplier Settings
  475.           Result_Multiplier = 1
  476.           Result_Proc_Level = 1
  477.           Result_Proc_Rate  = 0
  478.         end
  479.       end
  480.     end # Alchemy END
  481.   end
  482.   # Do not edit anything further here
  483. end
  484. class Window_MenuCommand
  485.   alias_method(:evg_wmc_aoc_diyc2, :add_original_commands)
  486.   def add_original_commands
  487.     evg_wmc_aoc_diyc2
  488.     EVG::CRAFTING_SETTINGS::TYPES_IN_MENU.each do |type_id, switch_id|
  489.       vocab = EVG::CraftingTypes[type_id][:Vocab]
  490.       add_command(vocab, type_id, $game_switches[switch_id])
  491.     end
  492.   end
  493. end
  494. class Scene_Menu
  495.   alias_method(:evg_sm_start_diyc2, :start)
  496.   def start
  497.     evg_sm_start_diyc2
  498.     EVG::CRAFTING_SETTINGS::TYPES_IN_MENU.each do |type_id, switch_id|
  499.       @command_window.set_handler(type_id, method("on_command_#{type_id}".to_sym))
  500.     end
  501.   end
  502.   EVG::CRAFTING_SETTINGS::TYPES_IN_MENU.each do |type_id, switch_id|
  503.     class_eval(%Q{def on_command_#{type_id}
  504.       if EVG::CRAFTING_SETTINGS::CAN_SWITCH_MENU_TYPES
  505.        type_ids = EVG::CRAFTING_SETTINGS::TYPES_IN_MENU.keys
  506.        return EVG::CraftingManager.open(*type_ids)
  507.       end
  508.       EVG::CraftingManager.open(:#{type_id})
  509.     end})
  510.   end
  511. end
  512. class RPG::BaseItem
  513.   def ingredient?
  514.     !@note.include?("<no_ingredient>")
  515.   end
  516.  
  517.   def correct_type?(type_id)
  518.     (!EVG::CRAFTING_SETTINGS::OWN_INGREDIENT_CONTROL && craft_type_ids.empty?) || craft_type_ids.include?(type_id)
  519.   end
  520.  
  521.   def craft_type_ids
  522.     @craft_type_ids ||= @note.scan(/<craft_type: *(\w+) *>/i).flatten.map(&:to_sym)
  523.   end
  524.  
  525.   def tool_type_ids
  526.     @tool_type_ids ||= @note.scan(/<tool: *(\w+) *>/i).flatten.map(&:to_sym)
  527.   end
  528.  
  529.   def tool?
  530.     !@tool_type_ids.empty?
  531.   end
  532. end
  533. class RPG::Item
  534.   def to_sym
  535.     "i#{id}".to_sym
  536.   end
  537. end
  538. class RPG::Weapon
  539.   def to_sym
  540.     "w#{id}".to_sym
  541.   end
  542. end
  543. class RPG::Armor
  544.   def to_sym
  545.     "a#{id}".to_sym
  546.   end
  547. end
  548. module EVG
  549.   module Converter
  550.     WEAPON_REGEX  = /^(w|weapon|waffe)-?_?(\d+)$/i
  551.     ITEM_REGEX    = /^(i|item)-?_?(\d+)$/i
  552.     ARMOR_REGEX   = /^(a|armor|r|rüstung)-?_?(\d+)$/i
  553.  
  554.     def self.sym_to_item(sym)
  555.       case sym.to_s
  556.         when WEAPON_REGEX
  557.           $data_weapons[$2.to_i]
  558.         when ITEM_REGEX
  559.           $data_items[$2.to_i]
  560.         when ARMOR_REGEX
  561.           $data_armors[$2.to_i]
  562.         else
  563.           nil
  564.       end
  565.     end
  566.  
  567.     def self.module_to_hash(modul)
  568.       module_hash = {}
  569.       modul.constants.each do |const|
  570.         module_hash[const.to_sym] = if modul.const_get(const).is_a?(Module)
  571.                                       module_to_hash(modul.const_get(const))
  572.                                     else
  573.                                       modul.const_get(const)
  574.                                     end
  575.       end if modul.respond_to?(:constants)
  576.       module_hash
  577.     end
  578.   end
  579. end
  580. module EVG
  581.   CraftingTypes = Converter.module_to_hash(CRAFTING_TYPES)
  582. end
  583. module EVG
  584.   module CraftingManager
  585.     def self.open(*args)
  586.       SceneManager.call(Scene_Crafting)
  587.       types = args[0].is_a?(Hash) ? args[0] : Hash[args.map{|t| [t, nil]}]
  588.       init(types)
  589.     end
  590.  
  591.     def self.open_shop(*args)
  592.       SceneManager.call(Scene_Crafting)
  593.       types = args[0].is_a?(Hash) ? args[0] : Hash[args.map{|t| [t, nil]}]
  594.       init(types, true)
  595.     end
  596.  
  597.     def self.init(types, index = 0, shop = false, recipe_mode = false)
  598.       current_recipe.clear
  599.       @index       = index
  600.       @types       = types
  601.       @custom_tool = nil
  602.       @shop        = shop
  603.       @recipe_mode = recipe_mode
  604.       calculate_recipes
  605.     end
  606.  
  607.     def self.type_id
  608.       @types.keys[@index]
  609.     end
  610.  
  611.     def self.crafting_type
  612.       $game_system.crafting_types[type_id]
  613.     end
  614.  
  615.     def self.current_recipe
  616.       @current_recipe ||= Pseudo_CraftingRecipe.new
  617.     end
  618.  
  619.     def self.current_tool
  620.       fixed_tool? && fixed_tool || custom_tool
  621.     end
  622.  
  623.     def self.custom_tool
  624.       @custom_tool
  625.     end
  626.  
  627.     def self.fixed_tool
  628.       @types[type_id]
  629.     end
  630.  
  631.     def self.fixed_tool?
  632.       !!fixed_tool
  633.     end
  634.  
  635.     def self.shop?
  636.       @shop
  637.     end
  638.  
  639.     def self.matching_recipe
  640.       @matching_recipes.first
  641.     end
  642.  
  643.     def self.impossible_recipe?
  644.       crafting_type.impossible_recipes.include?(current_recipe)
  645.     end
  646.  
  647.     def self.can_switch_categories?
  648.       @types.size > 1
  649.     end
  650.  
  651.     def self.recipe_mode?
  652.       @recipe_mode
  653.     end
  654.  
  655.     def self.next_type
  656.       id = @types.keys[(@index + 1) % @types.size]
  657.       $game_system.crafting_types[id]
  658.     end
  659.  
  660.     def self.previous_type
  661.       id = @types.keys[(@index - 1) % @types.size]
  662.       $game_system.crafting_types[id]
  663.     end
  664.  
  665.     def self.next_category
  666.       @index = (@index + 1) % @types.size
  667.       init(@types, @index, @shop, @recipe_mode)
  668.     end
  669.  
  670.     def self.previous_category
  671.       @index = (@index - 1) % @types.size
  672.       init(@types, @index, @shop, @recipe_mode)
  673.     end
  674.  
  675.     def self.toggle_recipe_mode
  676.       @recipe_mode = !@recipe_mode
  677.       clear
  678.     end
  679.  
  680.     def self.calc_possible_recipes(cur_recipe, recipe_list)
  681.       recipe_list.select do |recipe|
  682.         cur_recipe.tool == recipe.tool &&
  683.             (cur_recipe.ingredients.keys - recipe.ingredients.keys).empty? &&
  684.             cur_recipe.ingredients.keys.all? do |ingredient|
  685.               recipe.ingredients[ingredient] - cur_recipe.ingredients[ingredient] >= 0
  686.             end
  687.       end
  688.     end
  689.  
  690.     def self.calculate_recipes
  691.       @possible_recipes = calc_possible_recipes(current_recipe, crafting_type.recipes)
  692.       @matching_recipes = @possible_recipes.select{|recipe| recipe == current_recipe}
  693.     end
  694.  
  695.     def self.rec_calculate_recipes
  696.       @possible_recipes = calc_possible_recipes(current_recipe, @possible_recipes)
  697.       @matching_recipes = @possible_recipes.select{|recipe| recipe == current_recipe}
  698.     end
  699.  
  700.     def self.can_change?(ingredient, amount)
  701.       next_recipe = Marshal.load(Marshal.dump(current_recipe))
  702.       next_recipe.change_ingredient(ingredient, amount)
  703.       !calc_possible_recipes(next_recipe, @possible_recipes).empty?
  704.     end
  705.  
  706.     def self.can_craft?(recipe = nil)
  707.       return false if $game_switches[CRAFTING_SETTINGS::PERFECT_CRAFTING_SWITCH_ID] && !matching_recipe
  708.       recipe ||= current_recipe
  709.       !recipe.ingredients.empty? && recipe.ingredients.all? do |ingredient, amount|
  710.         $game_party.item_number(Converter.sym_to_item(ingredient)) >= amount
  711.       end
  712.     end
  713.  
  714.     def self.clear
  715.       current_recipe.clear
  716.       calculate_recipes
  717.     end
  718.  
  719.     def self.set_tool(tool)
  720.       @custom_tool = tool && tool.to_sym
  721.       calculate_recipes
  722.     end
  723.  
  724.     def self.add_ingredient(ingredient, amount)
  725.       current_recipe.change_ingredient(ingredient, amount.abs)
  726.       rec_calculate_recipes
  727.     end
  728.  
  729.     def self.remove_ingredient(ingredient, amount)
  730.       current_recipe.change_ingredient(ingredient, -(amount.abs))
  731.       calculate_recipes
  732.     end
  733.  
  734.     def self.set_recipe(recipe)
  735.       current_recipe.set(recipe)
  736.       calculate_recipes
  737.     end
  738.   end
  739. end
  740. module EVG
  741.   module Comparable_Recipe
  742.     def ==(other)
  743.       return false unless (other.respond_to?(:ingredients) &&
  744.           other.respond_to?(:tool))
  745.       ingredients == other.ingredients && tool == other.tool
  746.     end
  747.     alias_method(:eql?, :==)
  748.   end
  749.   class Pseudo_CraftingRecipe
  750.     include Comparable_Recipe
  751.     attr_reader :ingredients
  752.     def initialize(ingredients = {})
  753.       @ingredients = ingredients
  754.     end
  755.  
  756.     def set(recipe)
  757.       return unless recipe
  758.       clear
  759.       recipe.ingredients.each{|i, a| change_ingredient(i, a)}
  760.       CraftingManager.set_tool(recipe.tool)
  761.     end
  762.  
  763.     def change_ingredient(ingredient, amount)
  764.       return unless ingredient
  765.       @ingredients[ingredient.to_sym] ||= 0
  766.       @ingredients[ingredient.to_sym] += amount
  767.       @ingredients.delete_if{|i, a| a <= 0}
  768.     end
  769.  
  770.     def tool
  771.       CraftingManager.current_tool
  772.     end
  773.  
  774.     def clear
  775.       @ingredients.clear
  776.     end
  777.   end
  778.   class Impossible_CraftingRecipe
  779.     include Comparable_Recipe
  780.     attr_reader :ingredients, :tool
  781.     def initialize(ingredients = {}, tool = nil)
  782.       @ingredients = ingredients
  783.       @tool        = tool
  784.     end
  785.   end
  786.   class CraftingRecipe
  787.     include Comparable_Recipe
  788.     attr_reader :id, :type, :vocab
  789.  
  790.     def initialize(type, recipe_id)
  791.       @type  = type
  792.       @id    = recipe_id
  793.       @vocab = @id.to_s.split("_").join(" ")
  794.     end
  795.  
  796.     def recipe_data
  797.       EVG::CraftingTypes[@type.id][:Recipes][@id]
  798.     end
  799.  
  800.     def tool
  801.       recipe_data[:Tool]
  802.     end
  803.  
  804.     def ingredients
  805.       recipe_data[:Ingredients]
  806.     end
  807.  
  808.     def results
  809.       recipe_data[:Results]
  810.     end
  811.  
  812.     def success_rate
  813.       [(recipe_data[:Success] + success_change + success_plus) * success_mult / 100.to_f, 1].min
  814.     end
  815.  
  816.     def success_change
  817.       return 0 unless @type.leveling_enabled?
  818.       (@type.level - recipe_data[:Base_Level]) *
  819.           recipe_data[:Success_Change]
  820.     end
  821.  
  822.     def success_plus
  823.       0
  824.     end
  825.  
  826.     def success_mult
  827.       1
  828.     end
  829.  
  830.     def exp
  831.       [((recipe_data[:Exp] +
  832.           (recipe_data[:Base_Level] - @type.level) *
  833.               recipe_data[:Exp_Change]) +
  834.           exp_plus) * exp_mult, 0].max.to_i
  835.     end
  836.  
  837.     def exp_plus
  838.       0
  839.     end
  840.  
  841.     def exp_mult
  842.       1
  843.     end
  844.  
  845.     def result_amount(result)
  846.       amount = results[result]
  847.       amount *= result_multiplier if more_results?
  848.       amount
  849.     end
  850.  
  851.     def result_multiplier
  852.       recipe_data[:Result_Multiplier]
  853.     end
  854.  
  855.     def result_proc_level
  856.       recipe_data[:Result_Proc_Level]
  857.     end
  858.  
  859.     def result_proc_rate
  860.       recipe_data[:Result_Proc_Rate] / 100.to_f
  861.     end
  862.  
  863.     def more_results?
  864.       return false if @type.level < result_proc_level
  865.       rand <= result_proc_rate
  866.     end
  867.  
  868.     def gold_cost
  869.       recipe_data[:Gold_Cost] || @type.default_gold_cost || 0
  870.     end
  871.   end
  872. end
  873. module EVG
  874.   class CraftingType
  875.     attr_reader :id, :level, :exp, :learned_recipes, :impossible_recipes
  876.  
  877.     def initialize(type_id)
  878.       @id = type_id
  879.       @exp = 0
  880.       @level = 1
  881.       @learned_recipes = []
  882.       @impossible_recipes = []
  883.       reload_data
  884.     end
  885.  
  886.     def type_data
  887.       EVG::CraftingTypes[@id]
  888.     end
  889.  
  890.     def reload_data
  891.       collect_tools
  892.       create_recipe_objects
  893.       correct_impossible_recipes
  894.       create_exp_table
  895.       change_exp(0)
  896.     end
  897.  
  898.     def collect_tools
  899.       @tools = ($data_items | $data_weapons | $data_armors).compact.select{|item| item.tool_type_ids.include?(@id)}
  900.     end
  901.  
  902.     def create_recipe_objects
  903.       @recipes = Hash[type_data[:Recipes].map do |recipe_id, settings|
  904.         [recipe_id, CraftingRecipe.new(self, recipe_id)]
  905.       end]
  906.     end
  907.  
  908.     def correct_impossible_recipes
  909.       @impossible_recipes.delete_if{|recipe| recipes.include?(recipe)}
  910.     end
  911.  
  912.     def create_exp_table
  913.       @exp_table = []
  914.       max_level.times do |level|
  915.         level_exp = eval(type_data[:Exp_Formula]
  916.                              .gsub("type_level", level.to_s))
  917.         level_exp += @exp_table[level] if level > 0
  918.         @exp_table[level + 1] = level_exp
  919.       end
  920.     end
  921.  
  922.     def recipes_hash
  923.       @recipes
  924.     end
  925.  
  926.     def recipes
  927.       recipes_hash.values
  928.     end
  929.  
  930.     def vocab
  931.       type_data[:Vocab]
  932.     end
  933.  
  934.     def leveling_enabled?
  935.       type_data[:Enable_Leveling]
  936.     end
  937.  
  938.     def tool_enabled?
  939.       type_data[:Enable_Tool]
  940.     end
  941.  
  942.     def loose_on_failure?
  943.       type_data[:Loose_On_Failure]
  944.     end
  945.  
  946.     def loose_on_impossible?
  947.       type_data[:Loose_On_Impossible]
  948.     end
  949.  
  950.     def max_level
  951.       type_data[:Max_Level]
  952.     end
  953.  
  954.     def possible_categories
  955.       type_data[:Possible_Categories]
  956.     end
  957.  
  958.     def success_me
  959.       type_data[:Success_Me]
  960.     end
  961.  
  962.     def failure_me
  963.       type_data[:Failure_Me]
  964.     end
  965.  
  966.     def impossible_me
  967.       type_data[:Impossible_Me]
  968.     end
  969.  
  970.     def gauge_color1
  971.       type_data[:Gauge_Color1]
  972.     end
  973.  
  974.     def gauge_color2
  975.       type_data[:Gauge_Color2]
  976.     end
  977.  
  978.     def ingredient_cap
  979.       id = type_data[:Ingredient_Size_Variable]
  980.       id && $game_variables[id]
  981.     end
  982.  
  983.     def result_cap
  984.       type_data[:Result_Size]
  985.     end
  986.  
  987.     def default_gold_cost
  988.       type_data[:Default_Gold_Cost]
  989.     end
  990.  
  991.     def impossible_gold_cost_min
  992.       type_data[:Impossible_Gold_Cost_Min]
  993.     end
  994.  
  995.     def impossible_gold_cost_max
  996.       type_data[:Impossible_Gold_Cost_Max]
  997.     end
  998.  
  999.     def max_level?
  1000.       @level == max_level
  1001.     end
  1002.  
  1003.     def tools
  1004.       @tools
  1005.     end
  1006.  
  1007.     def next_level_exp
  1008.       @exp_table[@level + 1]
  1009.     end
  1010.  
  1011.     def current_level_exp
  1012.       @exp_table[@level]
  1013.     end
  1014.  
  1015.     def exp_rate
  1016.       return 1 if max_level?
  1017.       cur_exp  = @exp - current_level_exp
  1018.       next_exp = next_level_exp - current_level_exp
  1019.       [cur_exp / next_exp.to_f, 1].min
  1020.     end
  1021.  
  1022.     def change_exp(exp)
  1023.       @exp = [@exp + exp, 0].max.to_i
  1024.       level_up    until max_level? || self.exp < next_level_exp
  1025.       level_down  while self.exp < current_level_exp
  1026.     end
  1027.  
  1028.     def level_up
  1029.       @level += 1
  1030.     end
  1031.  
  1032.     def level_down
  1033.       @level -= 1
  1034.     end
  1035.  
  1036.     def learn_recipe(recipe_id)
  1037.       return if @learned_recipes.include?(recipe_id)
  1038.       @learned_recipes.push(recipe_id)
  1039.     end
  1040.  
  1041.     def forget_recipe(recipe_id)
  1042.       @learned_recipes.delete(recipe_id)
  1043.     end
  1044.  
  1045.     def add_impossible_recipe(ingredients, tool)
  1046.       recipe = Impossible_CraftingRecipe.new(ingredients.dup, tool)
  1047.       return if @impossible_recipes.include?(recipe)
  1048.       @impossible_recipes.push(recipe)
  1049.     end
  1050.   end
  1051. end
  1052. class Game_System
  1053.   attr_reader :crafting_types
  1054.  
  1055.   alias_method(:evg_gs_initialize_diyc2, :initialize)
  1056.   def initialize
  1057.     evg_gs_initialize_diyc2
  1058.     @crafting_types = initialize_crafting_types
  1059.   end
  1060.  
  1061.   def initialize_crafting_types
  1062.     Hash[EVG::CraftingTypes.map do |type_id, settings|
  1063.            [type_id, EVG::CraftingType.new(type_id)]
  1064.          end]
  1065.   end
  1066. end
  1067.  
  1068. module DataManager
  1069.   class << self
  1070.     alias_method(:evg_dn_esc_diyc2, :extract_save_contents)
  1071.   end
  1072.  
  1073.   def self.extract_save_contents(contents)
  1074.     evg_dn_esc_diyc2(contents)
  1075.     $game_system.crafting_types.values.each(&:reload_data)
  1076.   end
  1077. end
  1078. class Game_Temp
  1079.   attr_reader :crafting_recipes
  1080.  
  1081.   alias_method(:evg_gt_initialize_diyc2, :initialize)
  1082.   def initialize
  1083.     evg_gt_initialize_diyc2
  1084.   end
  1085. end
  1086. module EVG
  1087.   class Window_CraftingList < Window_Selectable
  1088.     def initialize(x, y, width, height)
  1089.       @col_max = (width - standard_padding * 2) / (item_width + spacing)
  1090.       super(x, y, width, height)
  1091.       @list = []
  1092.       refresh
  1093.     end
  1094.  
  1095.     def col_max
  1096.       @col_max
  1097.     end
  1098.  
  1099.     def max_rows
  1100.       contents_height / (item_height + spacing)
  1101.     end
  1102.  
  1103.     def reset_font_settings
  1104.       super
  1105.       contents.font.size = 14
  1106.       contents.font.bold = true
  1107.     end
  1108.  
  1109.     def contents_height
  1110.       [height - standard_padding * 2, row_max * (item_height + spacing)].max
  1111.     end
  1112.  
  1113.     def update_padding
  1114.       super
  1115.       self.padding_bottom = padding
  1116.     end
  1117.  
  1118.     def top_row
  1119.       oy / (item_height + spacing)
  1120.     end
  1121.  
  1122.     def top_row=(row)
  1123.       row = 0 if row < 0
  1124.       row = row_max - 1 if row > row_max - 1
  1125.       self.oy = row * (item_height + spacing)
  1126.     end
  1127.  
  1128.     def page_row_max
  1129.       (height - padding - padding_bottom) / (item_height + spacing)
  1130.     end
  1131.  
  1132.     def item_width
  1133.       32
  1134.     end
  1135.  
  1136.     def item_height
  1137.       32
  1138.     end
  1139.  
  1140.     def spacing
  1141.       2
  1142.     end
  1143.  
  1144.     def item_max
  1145.       @list ? @list.size : 0
  1146.     end
  1147.  
  1148.     def item_rect(index)
  1149.       rect = Rect.new
  1150.       rect.width = item_width
  1151.       rect.height = item_height
  1152.       rect.x = index % col_max * (item_width + spacing)
  1153.       rect.y = index / col_max * (item_height + spacing)
  1154.       rect
  1155.     end
  1156.  
  1157.     def icon_rect(index)
  1158.       icon_rect = item_rect(index)
  1159.       icon_rect.x += (item_width - 24) / 2
  1160.       icon_rect.y += (item_height - 24) / 2
  1161.       icon_rect.width = 24
  1162.       icon_rect.height = 24
  1163.       icon_rect
  1164.     end
  1165.  
  1166.     def background_rect(index)
  1167.       bg_rect = item_rect(index)
  1168.       bg_rect.x += 2
  1169.       bg_rect.y += 2
  1170.       bg_rect.width -= 4
  1171.       bg_rect.height -= 4
  1172.       bg_rect
  1173.     end
  1174.  
  1175.     def amount_x(index)
  1176.       item_rect(index).x + 4
  1177.     end
  1178.  
  1179.     def amount_y(index)
  1180.       item_rect(index).y + item_rect(index).height - 18
  1181.     end
  1182.  
  1183.     def clear_list
  1184.       @list.clear
  1185.     end
  1186.  
  1187.     def add_item(item, amount)
  1188.       @list.push(item: Converter.sym_to_item(item.to_sym), amount: amount)
  1189.     end
  1190.  
  1191.     def item(index)
  1192.       @list[index] ? @list[index][:item] : nil
  1193.     end
  1194.  
  1195.     def amount(index)
  1196.       @list[index][:amount]
  1197.     end
  1198.  
  1199.     def amount_string(index)
  1200.       amount(index).to_s
  1201.     end
  1202.  
  1203.     def item_enabled?(index)
  1204.       true
  1205.     end
  1206.  
  1207.     def current_item
  1208.       item(@index)
  1209.     end
  1210.  
  1211.     def current_item_enabled?
  1212.       item_enabled?(@index)
  1213.     end
  1214.  
  1215.     def draw_item(index)
  1216.       draw_icon(item(index).icon_index, icon_rect(index).x, icon_rect(index).y, item_enabled?(index))
  1217.       draw_text_ex(amount_x(index), amount_y(index), amount_string(index)) if amount(index) > 1
  1218.     end
  1219.  
  1220.     def draw_background(index)
  1221.       contents.fill_rect(background_rect(index), background_color)
  1222.     end
  1223.  
  1224.     def draw_backgrounds
  1225.       background_times.times {|index| draw_background(index)}
  1226.     end
  1227.  
  1228.     def background_times
  1229.       item_max < (max_rows * col_max) ? (max_rows * col_max) : item_max
  1230.     end
  1231.  
  1232.     def draw_backgrounds?
  1233.       false
  1234.     end
  1235.  
  1236.     def background_color
  1237.       Color.new(0, 0, 0, 128)
  1238.     end
  1239.  
  1240.     def update_help
  1241.       @help_window.set_item(current_item)
  1242.     end
  1243.  
  1244.     def refresh
  1245.       clear_item_list
  1246.       make_item_list
  1247.       create_contents
  1248.       draw_backgrounds if draw_backgrounds?
  1249.       draw_all_items
  1250.     end
  1251.  
  1252.     def clear_item_list
  1253.       @list.clear
  1254.     end
  1255.  
  1256.     def make_item_list
  1257.     end
  1258.   end
  1259. end
  1260.  
  1261. class Window_Base
  1262.   def draw_underline(x, y, width)
  1263.     contents.fill_rect(x, y + line_height - 1, width, 1, underline_color)
  1264.   end
  1265.  
  1266.   def underline_color
  1267.     Color.new(0,0,0,128)
  1268.   end
  1269. end
  1270. module EVG
  1271.   class Scene_Crafting < Scene_MenuBase
  1272.     def start
  1273.       super
  1274.       create_help_window
  1275.       create_header_window
  1276.       create_command_window
  1277.       create_item_category_window
  1278.       create_item_window
  1279.       create_tool_window
  1280.       create_result_window
  1281.       create_ingredient_window
  1282.       create_result_list_window
  1283.       create_recipe_window
  1284.       create_confirmation_window
  1285.       create_notification_window
  1286.       collect_all_windows
  1287.       @sound = RPG::ME.new
  1288.     end
  1289.  
  1290.     def create_help_window
  1291.       @help_window = Window_CraftingHelp.new
  1292.     end
  1293.  
  1294.     def create_header_window
  1295.       @header_window = Window_CraftingHeader.new
  1296.     end
  1297.  
  1298.     def create_command_window
  1299.       @command_window = Window_CraftingCommand.new
  1300.       @command_window.set_handler(:cancel, method(:return_scene))
  1301.       @command_window.set_handler(:pageup, method(:on_command_pageup))
  1302.       @command_window.set_handler(:pagedown, method(:on_command_pagedown))
  1303.       @command_window.set_handler(:switch_mode, method(:on_command_switch))
  1304.       @command_window.set_handler(:Add, method(:on_command_add))
  1305.       @command_window.set_handler(:Remove, method(:on_command_remove))
  1306.       @command_window.set_handler(:Clear, method(:on_command_clear))
  1307.       @command_window.set_handler(:Tool, method(:on_command_tool))
  1308.       @command_window.set_handler(:View_Results, method(:on_command_view_results))
  1309.       @command_window.help_window = @help_window
  1310.     end
  1311.  
  1312.     def create_item_category_window
  1313.       y = @command_window.y + @command_window.height
  1314.       height = Graphics.height - y - @help_window.height
  1315.       @item_category_window = Window_CraftingItemCategory.new(0, y, Graphics.width / 2, height)
  1316.     end
  1317.  
  1318.     def create_item_window
  1319.       y = @item_category_window.y + @command_window.height
  1320.       height = Graphics.height - y - @help_window.height
  1321.       @item_window = Window_CraftingItemList.new(0, y, Graphics.width / 2, height)
  1322.       @item_window.set_handler(:cancel, method(:on_item_cancel))
  1323.       @item_window.set_handler(:ok, method(:on_item_ok))
  1324.       @item_window.help_window = @help_window
  1325.       @item_window.category_window = @item_category_window
  1326.     end
  1327.  
  1328.     def create_recipe_window
  1329.       y = @command_window.y + @command_window.height
  1330.       height = Graphics.height - y - @help_window.height
  1331.       @recipe_window = Window_CraftingRecipeList.new(0, y, Graphics.width / 2, height)
  1332.       @recipe_window.set_handler(:ok, method(:on_recipe_ok))
  1333.       @recipe_window.set_handler(:cancel, method(:on_recipe_cancel))
  1334.       @recipe_window.windows_to_refresh = [@result_list_window, @dummy_window, @ingredient_window, @command_window]
  1335.     end
  1336.  
  1337.     def create_tool_window
  1338.       y = @command_window.y + @command_window.height
  1339.       height = Graphics.height - y - @help_window.height
  1340.       @tool_window = Window_CraftingToolList.new(0, y, Graphics.width / 2, height)
  1341.       @tool_window.help_window = @help_window
  1342.       @tool_window.set_handler(:cancel, method(:on_tool_cancel))
  1343.       @tool_window.set_handler(:ok, method(:on_tool_ok))
  1344.     end
  1345.  
  1346.     def create_result_window
  1347.       x = Graphics.width / 2
  1348.       y = @command_window.y + @command_window.height
  1349.       height = Graphics.height - y - @help_window.height
  1350.       @dummy_window = Window_CraftingDummy.new(x, y, Graphics.width / 2, height)
  1351.       @dummy_window.set_handler(:Craft, method(:on_dummy_start))
  1352.       @dummy_window.set_handler(:Clear, method(:on_dummy_clear))
  1353.     end
  1354.  
  1355.     def create_ingredient_window
  1356.       x = Graphics.width / 2
  1357.       y = @dummy_window.y + @command_window.height
  1358.       @ingredient_window = Window_CraftingIngredientList.new(x, y)
  1359.       @ingredient_window.help_window = @help_window
  1360.       @ingredient_window.set_handler(:cancel, method(:on_ingredient_cancel))
  1361.       @ingredient_window.set_handler(:ok, method(:on_ingredient_ok))
  1362.     end
  1363.  
  1364.     def create_result_list_window
  1365.       x = Graphics.width / 2
  1366.       y = Graphics.height - @help_window.height - @ingredient_window.height
  1367.       @result_list_window = Window_CraftingResultList.new(x, y)
  1368.       @result_list_window.help_window = @help_window
  1369.       @result_list_window.set_handler(:cancel, method(:on_result_list_cancel))
  1370.     end
  1371.  
  1372.     def create_confirmation_window
  1373.       @confirmation_window = Window_CraftingConfirmation.new
  1374.       @confirmation_window.set_handler(:Yes, method(:on_confirmation_yes))
  1375.       @confirmation_window.set_handler(:No, method(:on_confirmation_no))
  1376.       @confirmation_window.set_handler(:cancel, method(:on_confirmation_no))
  1377.     end
  1378.  
  1379.     def create_notification_window
  1380.       @notification_window = Window_CraftingNotification.new
  1381.       @notification_window.set_handler(:ok, method(:on_notification_ok))
  1382.     end
  1383.  
  1384.     def collect_all_windows
  1385.       @windows = instance_variables.each.select{|v| instance_variable_get(v).is_a?(Window)}
  1386.       @windows.map!{|w| instance_variable_get(w)}
  1387.     end
  1388.  
  1389.     def on_command_pagedown
  1390.       CraftingManager.next_category
  1391.       refresh_windows
  1392.       @item_category_window.deactivate
  1393.       @item_category_window.select(0)
  1394.       @command_window.activate
  1395.     end
  1396.  
  1397.     def on_command_pageup
  1398.       CraftingManager.previous_category
  1399.       refresh_windows
  1400.       @item_category_window.deactivate
  1401.       @item_category_window.select(0)
  1402.       @command_window.activate
  1403.     end
  1404.  
  1405.     def on_command_switch
  1406.       if CraftingManager.recipe_mode?
  1407.         @recipe_window.close
  1408.         @item_category_window.open
  1409.         @item_window.open
  1410.         @command_window.activate
  1411.       else
  1412.         @item_category_window.close
  1413.         @item_window.close
  1414.         @recipe_window.open
  1415.         @command_window.activate
  1416.       end
  1417.       CraftingManager.toggle_recipe_mode
  1418.       refresh_windows
  1419.     end
  1420.  
  1421.     def on_command_add
  1422.       @command_window.deactivate
  1423.       if CraftingManager.recipe_mode?
  1424.         @recipe_window.activate
  1425.       else
  1426.         @item_category_window.activate
  1427.         @item_category_window.refresh
  1428.         @item_window.select(0)
  1429.         @item_window.activate
  1430.       end
  1431.     end
  1432.  
  1433.     def on_command_remove
  1434.       @command_window.deactivate
  1435.       @ingredient_window.activate
  1436.       @ingredient_window.select(0)
  1437.     end
  1438.  
  1439.     def on_command_clear
  1440.       CraftingManager.clear
  1441.       refresh_windows
  1442.       @command_window.activate
  1443.     end
  1444.  
  1445.     def on_command_tool
  1446.       if CraftingManager.recipe_mode?
  1447.         @recipe_window.close
  1448.       else
  1449.         @item_category_window.close
  1450.         @item_window.close
  1451.       end
  1452.       @tool_window.open
  1453.       @command_window.deactivate
  1454.       @tool_window.activate
  1455.       @tool_window.select(0)
  1456.     end
  1457.  
  1458.     def on_command_view_results
  1459.       @command_window.deactivate
  1460.       @result_list_window.activate
  1461.       @result_list_window.select(0)
  1462.     end
  1463.  
  1464.  
  1465.     def on_item_cancel
  1466.       @item_category_window.deactivate
  1467.       @item_category_window.refresh
  1468.       @item_window.deactivate
  1469.       @item_window.select(-1)
  1470.       @help_window.reset
  1471.       @command_window.activate
  1472.     end
  1473.  
  1474.     def on_item_ok
  1475.       CraftingManager.add_ingredient(@item_window.current_item, 1)
  1476.       refresh_windows
  1477.       @item_window.activate
  1478.     end
  1479.  
  1480.     def on_recipe_ok
  1481.       @recipe_window.activate
  1482.       on_dummy_start
  1483.     end
  1484.  
  1485.     def on_recipe_cancel
  1486.       @recipe_window.deactivate
  1487.       @command_window.activate
  1488.     end
  1489.  
  1490.     def on_tool_cancel
  1491.       if CraftingManager.recipe_mode?
  1492.         @recipe_window.open
  1493.       else
  1494.         @item_category_window.open
  1495.         @item_window.open
  1496.       end
  1497.       @tool_window.close
  1498.       @tool_window.deactivate
  1499.       @command_window.activate
  1500.       @help_window.set_item(nil)
  1501.     end
  1502.  
  1503.     def on_tool_ok
  1504.       new_tool = same_tool? ? nil : @tool_window.current_item
  1505.       CraftingManager.set_tool(new_tool)
  1506.       refresh_windows
  1507.       @tool_window.activate
  1508.     end
  1509.  
  1510.     def on_result_cancel
  1511.       @dummy_window.deactivate
  1512.       @command_window.activate
  1513.     end
  1514.  
  1515.     def on_dummy_start
  1516.       @active_windows = get_active_windows
  1517.       @active_windows.each(&:deactivate)
  1518.       if CRAFTING_SETTINGS::USE_CONFIRMATION_WINDOW
  1519.         @confirmation_window.open
  1520.         @confirmation_window.activate
  1521.       else
  1522.         start_crafting
  1523.         @notification_window.open
  1524.       end
  1525.     end
  1526.  
  1527.     def on_dummy_clear
  1528.       CraftingManager.clear unless @recipe_window.active
  1529.       refresh_windows
  1530.     end
  1531.  
  1532.     def on_ingredient_cancel
  1533.       @ingredient_window.deactivate
  1534.       @ingredient_window.select(-1)
  1535.       @command_window.activate
  1536.       @help_window.reset
  1537.     end
  1538.  
  1539.     def on_ingredient_ok
  1540.       CraftingManager.remove_ingredient(@ingredient_window.current_item, 1)
  1541.       refresh_windows
  1542.       if CraftingManager.current_recipe.ingredients.empty?
  1543.         on_ingredient_cancel
  1544.       else
  1545.         @ingredient_window.activate
  1546.       end
  1547.     end
  1548.  
  1549.     def on_result_list_cancel
  1550.       @result_list_window.deactivate
  1551.       @result_list_window.select(-1)
  1552.       @command_window.activate
  1553.       @help_window.reset
  1554.     end
  1555.  
  1556.     def on_confirmation_yes
  1557.       @confirmation_window.deactivate
  1558.       @confirmation_window.close
  1559.       start_crafting
  1560.       @notification_window.open
  1561.     end
  1562.  
  1563.     def on_confirmation_no
  1564.       @confirmation_window.deactivate
  1565.       @confirmation_window.close
  1566.       @active_windows.each(&:activate) if @active_windows
  1567.     end
  1568.  
  1569.     def on_notification_ok
  1570.       @notification_window.close
  1571.       @active_windows.each(&:activate) if @active_windows
  1572.       RPG::ME.stop
  1573.     end
  1574.  
  1575.     def refresh_windows
  1576.       @windows.each(&:refresh)
  1577.     end
  1578.  
  1579.     def get_active_windows
  1580.       @windows.select{|w| w.active }
  1581.     end
  1582.  
  1583.     def same_tool?
  1584.       old_tool = CraftingManager.current_recipe.tool
  1585.       new_tool = @tool_window.current_item
  1586.       (old_tool && old_tool.to_sym) == (new_tool && new_tool.to_sym)
  1587.     end
  1588.  
  1589.     def crafting_successful?
  1590.       r = rand
  1591.       r <= CraftingManager.matching_recipe.success_rate
  1592.     end
  1593.  
  1594.     def start_crafting
  1595.       if CraftingManager.matching_recipe
  1596.         crafting_successful? ? on_crafting_success : on_crafting_failure
  1597.       else
  1598.         on_crafting_impossible
  1599.       end
  1600.       refresh_windows
  1601.     end
  1602.  
  1603.     def on_crafting_success
  1604.       remove_items_from_party
  1605.       learn_recipe if first_time_crafted?
  1606.       claim_all_results
  1607.       add_exp if CraftingManager.crafting_type.leveling_enabled?
  1608.       play_sound(CraftingManager.crafting_type.success_me)
  1609.     end
  1610.  
  1611.     def on_crafting_failure
  1612.       remove_items_from_party if CraftingManager.crafting_type.loose_on_failure?
  1613.       @notification_window.add_line(CRAFTING_SETTINGS::FAILED_CRAFT_VOCAB)
  1614.       play_sound(CraftingManager.crafting_type.failure_me)
  1615.     end
  1616.  
  1617.     def on_crafting_impossible
  1618.       remove_items_from_party if CraftingManager.crafting_type.loose_on_impossible?
  1619.       ingredients = CraftingManager.current_recipe.ingredients
  1620.       tool = CraftingManager.current_recipe.tool
  1621.       CraftingManager.crafting_type.add_impossible_recipe(ingredients, tool)
  1622.       @notification_window.add_line(CRAFTING_SETTINGS::IMPOSSIBLE_VOCAB)
  1623.       play_sound(CraftingManager.crafting_type.impossible_me)
  1624.     end
  1625.  
  1626.     def remove_items_from_party
  1627.       CraftingManager.current_recipe.ingredients.each do |ingredient, amount|
  1628.         $game_party.lose_item(Converter.sym_to_item(ingredient), amount)
  1629.       end
  1630.     end
  1631.  
  1632.     def add_exp
  1633.       exp = CraftingManager.matching_recipe.exp
  1634.       CraftingManager.crafting_type.change_exp(exp)
  1635.       @notification_window.add_line("")
  1636.       @notification_window.add_line(CRAFTING_SETTINGS::EXP_GAIN_VOCAB % exp)
  1637.     end
  1638.  
  1639.     def learn_recipe
  1640.       recipe_id = CraftingManager.matching_recipe.id
  1641.       CraftingManager.crafting_type.learn_recipe(recipe_id)
  1642.       @notification_window.add_line(CRAFTING_SETTINGS::RECIPE_LEARNED_VOCAB)
  1643.     end
  1644.  
  1645.     def first_time_crafted?
  1646.       recipe_id = CraftingManager.matching_recipe.id
  1647.       !CraftingManager.crafting_type.learned_recipes.include?(recipe_id)
  1648.     end
  1649.  
  1650.     def claim_all_results
  1651.       @notification_window.add_line(CRAFTING_SETTINGS::SUCCESS_CRAFT_VOCAB)
  1652.       CraftingManager.matching_recipe.results.each do |result, amount|
  1653.         item = Converter.sym_to_item(result)
  1654.         amount = CraftingManager.matching_recipe.result_amount(result)
  1655.         $game_party.gain_item(item, amount)
  1656.         line = "[item=#{result}][amount=#{amount}]"
  1657.         @notification_window.add_line(line)
  1658.       end
  1659.     end
  1660.  
  1661.     def play_sound(name)
  1662.       RPG::ME.stop
  1663.       @sound.name = name || ""
  1664.       @sound.play
  1665.     end
  1666.   end
  1667. end
  1668. module EVG
  1669.   class Window_CraftingCommand < Window_HorzCommand
  1670.     def initialize
  1671.       super(0, fitting_height(1))
  1672.     end
  1673.  
  1674.     def col_max
  1675.       use_tool_feature? ? 5 : 4
  1676.     end
  1677.  
  1678.     def window_width
  1679.       Graphics.width
  1680.     end
  1681.  
  1682.     def type_id
  1683.       CraftingManager.crafting_type && CraftingManager.crafting_type.id
  1684.     end
  1685.  
  1686.     def make_command_list
  1687.       add_command(CRAFTING_SETTINGS::COMMAND_VOCABS[:Add], :Add)
  1688.       add_command(CRAFTING_SETTINGS::COMMAND_VOCABS[:Remove], :Remove, remove_enabled?)
  1689.       add_command(CRAFTING_SETTINGS::COMMAND_VOCABS[:Clear], :Clear,  clear_enabled?)
  1690.       add_command(CRAFTING_SETTINGS::COMMAND_VOCABS[:Tool], :Tool,   tool_enabled?) if use_tool_feature?
  1691.       add_command(CRAFTING_SETTINGS::COMMAND_VOCABS[:View_Results], :View_Results, view_results?)
  1692.     end
  1693.  
  1694.     def update_help
  1695.       @help_window.set_command(current_data)
  1696.     end
  1697.  
  1698.     def call_handler(current_symbol)
  1699.       super(current_symbol)
  1700.       @help_window.set_command(nil) if ![:pagedown, :pageup].include?(current_symbol)
  1701.     end
  1702.  
  1703.     def process_handling
  1704.       return unless open? && active
  1705.       return process_ok       if ok_enabled?        && Input.trigger?(:C)
  1706.       return process_cancel   if cancel_enabled?    && Input.trigger?(:B)
  1707.       cwc = CraftingManager.can_switch_categories?
  1708.       return process_pagedown if handle?(:pagedown) && Input.trigger?(:R) && cwc
  1709.       return process_pageup   if handle?(:pageup)   && Input.trigger?(:L) && cwc
  1710.       sm_on = CRAFTING_SETTINGS::CAN_SWITCH_TO_RECIPE_MODE
  1711.       return process_switch_mode if handle?(:switch_mode) && Input.trigger?(:Y) && sm_on
  1712.     end
  1713.  
  1714.     def process_switch_mode
  1715.       Input.update
  1716.       call_handler(:switch_mode)
  1717.     end
  1718.  
  1719.     def remove_enabled?
  1720.       !CraftingManager.current_recipe.ingredients.empty?
  1721.     end
  1722.  
  1723.     def clear_enabled?
  1724.       remove_enabled? || CraftingManager.fixed_tool != CraftingManager.current_recipe.tool
  1725.     end
  1726.  
  1727.     def tool_enabled?
  1728.       return false if CraftingManager.fixed_tool?
  1729.       $game_party.all_items.count{|item| item.tool_type_ids.include?(type_id)} > 0
  1730.     end
  1731.  
  1732.     def view_results?
  1733.       CraftingManager.matching_recipe && learned_recipe?
  1734.     end
  1735.  
  1736.     def craft_enabled?
  1737.       CraftingManager.can_craft?
  1738.     end
  1739.  
  1740.     def learned_recipe?
  1741.       CraftingManager.crafting_type.learned_recipes.include?(CraftingManager.matching_recipe.id)
  1742.     end
  1743.  
  1744.     def use_tool_feature?
  1745.       CraftingManager.crafting_type.tool_enabled?
  1746.     end
  1747.   end
  1748. end
  1749. module EVG
  1750.   class Window_CraftingConfirmation < Window_HorzCommand
  1751.     def initialize
  1752.       super(window_x, window_y)
  1753.       deactivate
  1754.       self.openness = 0
  1755.     end
  1756.  
  1757.     def window_x
  1758.       (Graphics.width - window_width) / 2
  1759.     end
  1760.  
  1761.     def window_y
  1762.       (Graphics.height - window_height) / 2
  1763.     end
  1764.  
  1765.     def window_width
  1766.       Graphics.width / 2
  1767.     end
  1768.  
  1769.     def window_height
  1770.       fitting_height(2)
  1771.     end
  1772.  
  1773.     def col_max
  1774.       2
  1775.     end
  1776.  
  1777.     def contents_height
  1778.       window_height - standard_padding * 2
  1779.     end
  1780.  
  1781.  
  1782.     def item_rect(index)
  1783.       rect = super(index)
  1784.       rect.y += line_height
  1785.       rect
  1786.     end
  1787.  
  1788.     def make_command_list
  1789.       add_command("Yes", :Yes)
  1790.       add_command("No", :No)
  1791.     end
  1792.  
  1793.     def refresh
  1794.       super
  1795.       draw_text(0, 0, contents.width, line_height, "Proceed with crafting?", 1)
  1796.     end
  1797.  
  1798.     def process_handling
  1799.       return unless open? && active
  1800.       ok_triggers = [:C, CRAFTING_SETTINGS::CRAFTING_START_BUTTON]
  1801.       return process_ok       if ok_enabled?        && ok_triggers.any?{|t| Input.trigger?(t)}
  1802.       return process_cancel   if cancel_enabled?    && Input.trigger?(:B)
  1803.       return process_pagedown if handle?(:pagedown) && Input.trigger?(:R)
  1804.       return process_pageup   if handle?(:pageup)   && Input.trigger?(:L)
  1805.     end
  1806.   end
  1807. end
  1808. module EVG
  1809.   class Window_CraftingDummy < Window_Selectable
  1810.     def initialize(x, y, width, height)
  1811.       super(x, y, width, height)
  1812.       activate
  1813.       refresh
  1814.     end
  1815.  
  1816.     def can_start?
  1817.       CraftingManager.can_craft?
  1818.     end
  1819.  
  1820.     def view?
  1821.       CraftingManager.matching_recipe && learned_recipe?
  1822.     end
  1823.  
  1824.     def learned_recipe?
  1825.       CraftingManager.crafting_type.learned_recipes.include?(CraftingManager.matching_recipe.id)
  1826.     end
  1827.  
  1828.     def process_handling
  1829.       return unless open? && active
  1830.       return process_ok       if ok_enabled?        && Input.trigger?(:C)
  1831.       return process_cancel   if cancel_enabled?    && Input.trigger?(:B)
  1832.       return process_pagedown if handle?(:pagedown) && Input.trigger?(:R)
  1833.       return process_pageup   if handle?(:pageup)   && Input.trigger?(:L)
  1834.       return process_crafting if handle?(:Craft)    && Input.trigger?(:X)
  1835.       return process_clearing if handle?(:Clear)    && Input.trigger?(CRAFTING_SETTINGS::CRAFTING_CLEAR_BUTTON)
  1836.     end
  1837.  
  1838.     def process_crafting
  1839.       Input.update
  1840.       call_handler(:Craft) if can_start?
  1841.     end
  1842.  
  1843.     def process_clearing
  1844.       Input.update
  1845.       call_handler(:Clear)
  1846.     end
  1847.  
  1848.     def refresh
  1849.       super
  1850.       change_color(normal_color, can_start?)
  1851.       draw_text(0,0, contents.width, line_height, CRAFTING_SETTINGS::CRAFTING_START_VOCAB, 1)
  1852.       draw_lines
  1853.       draw_result_info unless CraftingManager.current_recipe.ingredients.empty?
  1854.     end
  1855.  
  1856.     def draw_lines
  1857.       draw_underline(0, line_height / 2, contents.width)
  1858.       draw_underline(0, line_height * 2.7, contents.width)
  1859.       draw_underline(0, contents.height - line_height * 2.5, contents.width)
  1860.     end
  1861.  
  1862.     def draw_result_info
  1863.       change_color(normal_color)
  1864.       draw_text(0, line_height * 4, contents.width, line_height, CRAFTING_SETTINGS::SUCCESS_VOCAB)
  1865.       draw_text(0, line_height * 4, contents.width, line_height, success, 2)
  1866.       draw_text(0, line_height * 5, contents.width, line_height, CRAFTING_SETTINGS::EXP_VOCAB)
  1867.       draw_text(0, line_height * 5, contents.width, line_height, exp, 2)
  1868.     end
  1869.  
  1870.     def success
  1871.       rate = "???"
  1872.       rate = "0" if impossible_recipe?
  1873.       rate = success_rate.to_s if view?
  1874.       "%s%" % rate
  1875.     end
  1876.  
  1877.     def exp
  1878.       exp = "???"
  1879.       exp = "0" if impossible_recipe?
  1880.       exp = exp_amount.to_s if view?
  1881.       "%s" % exp
  1882.     end
  1883.  
  1884.     def impossible_recipe?
  1885.       return false if $game_switches[CRAFTING_SETTINGS::PERFECT_CRAFTING_SWITCH_ID]
  1886.       CraftingManager.impossible_recipe?
  1887.     end
  1888.  
  1889.     def success_rate
  1890.       (CraftingManager.matching_recipe.success_rate * 100).to_i
  1891.     end
  1892.  
  1893.     def exp_amount
  1894.       CraftingManager.matching_recipe.exp
  1895.     end
  1896.   end
  1897. end
  1898. module EVG
  1899.   class Window_CraftingHeader < Window_Base
  1900.     def initialize
  1901.       super(0,0, Graphics.width, fitting_height(1))
  1902.       @tool =
  1903.       refresh
  1904.     end
  1905.  
  1906.     def type
  1907.       CraftingManager.crafting_type
  1908.     end
  1909.  
  1910.     def type_id
  1911.       type && type.id
  1912.     end
  1913.  
  1914.     def tool
  1915.       Converter.sym_to_item(CraftingManager.current_recipe.tool)
  1916.     end
  1917.  
  1918.     def refresh
  1919.       contents.clear
  1920.       draw_exp_gauge(0, 0, Graphics.width / 2 - 12) if type.leveling_enabled?
  1921.       draw_type_name(0, 0, Graphics.width / 2 - 12, line_height)
  1922.       draw_item_text(Graphics.width / 2, 0, Graphics.width / 2) if type.tool_enabled?
  1923.     end
  1924.  
  1925.     def draw_exp_gauge(x, y, width)
  1926.       draw_gauge(x, y, width, type.exp_rate, color1, color2)
  1927.       change_color(system_color)
  1928.       draw_text(width - 56, y, 32, line_height, Vocab::level_a)
  1929.       change_color(normal_color)
  1930.       draw_text(width - 24, y, 24, line_height, type.level, 2)
  1931.     end
  1932.  
  1933.     def draw_type_name(x, y, width, height)
  1934.       draw_text(x, y, width, height, type.vocab)
  1935.     end
  1936.  
  1937.     def draw_item_text(x, y, width)
  1938.       draw_underline(x, y, width)
  1939.       draw_icon(tool_icon, x + 4, y)
  1940.       draw_text(x + 28, y, width, line_height, tool_name)
  1941.     end
  1942.  
  1943.     def tool_icon
  1944.       tool ? tool.icon_index : EVG::CRAFTING_SETTINGS::NO_TOOL_ICON_INDEX
  1945.     end
  1946.  
  1947.     def tool_name
  1948.       tool ? tool.name : EVG::CRAFTING_SETTINGS::NO_TOOL_VOCAB
  1949.     end
  1950.  
  1951.     def color1
  1952.       text_color(CraftingManager.crafting_type.gauge_color1 || default_color1)
  1953.     end
  1954.  
  1955.     def color2
  1956.       text_color(CraftingManager.crafting_type.gauge_color2 || default_color2)
  1957.     end
  1958.  
  1959.     def default_color1
  1960.       24
  1961.     end
  1962.  
  1963.     def default_color2
  1964.       24
  1965.     end
  1966.   end
  1967. end
  1968. module EVG
  1969.   class Window_CraftingHelp < Window_Base
  1970.     def initialize
  1971.       super(0, Graphics.height - fitting_height(3), Graphics.width, fitting_height(3))
  1972.       refresh
  1973.     end
  1974.  
  1975.     def set_item(item)
  1976.       @item = item
  1977.       refresh
  1978.     end
  1979.  
  1980.     def set_command(command)
  1981.       @command = command
  1982.       refresh
  1983.     end
  1984.  
  1985.     def reset
  1986.       @command = nil
  1987.       @item = nil
  1988.       refresh
  1989.     end
  1990.  
  1991.     def refresh
  1992.       contents.clear
  1993.       change_color(normal_color)
  1994.       draw_underline(0, 1, contents.width)
  1995.       draw_item_info if @item
  1996.       draw_command_info if @command
  1997.     end
  1998.  
  1999.     def draw_item_info
  2000.       draw_item_name(0, 0)
  2001.       draw_text_ex(0, line_height, item_description)
  2002.     end
  2003.  
  2004.     def draw_item_name(x, y)
  2005.       draw_icon(icon_index, x, y)
  2006.       draw_text_ex(x + 26, y,  item_name)
  2007.     end
  2008.  
  2009.     def icon_index
  2010.       @item.icon_index
  2011.     end
  2012.  
  2013.     def item_name
  2014.       @item.name
  2015.     end
  2016.  
  2017.     def item_description
  2018.       @item.description
  2019.     end
  2020.  
  2021.     def draw_command_info
  2022.       draw_categories if CraftingManager.can_switch_categories?
  2023.       draw_text(0, 0, contents.width, line_height, @command[:name], 1)
  2024.       draw_text_ex(x, line_height,  CRAFTING_SETTINGS::COMMAND_DESCRIPTIONS[@command[:symbol]])
  2025.     end
  2026.  
  2027.     def draw_categories
  2028.       prev_text = "#{CRAFTING_SETTINGS::PREV_CATEGORY_VOCAB} #{CraftingManager.previous_type.vocab}"
  2029.       next_text = "#{CraftingManager.next_type.vocab} #{CRAFTING_SETTINGS::NEXT_CATEGORY_VOCAB}"
  2030.       draw_text(0, 0, contents.width, line_height, prev_text)
  2031.       draw_text(0, 0, contents.width, line_height, next_text, 2)
  2032.     end
  2033.   end
  2034. end
  2035. module EVG
  2036.   class Window_CraftingIngredientList < Window_CraftingList
  2037.  
  2038.     def initialize(x, y)
  2039.       super(x, y, window_width, window_height)
  2040.       self.opacity = 0
  2041.     end
  2042.  
  2043.     def window_width
  2044.       Graphics.width / 2
  2045.     end
  2046.  
  2047.     def window_height
  2048.       item_height + standard_padding * 2 + spacing
  2049.     end
  2050.  
  2051.     def type_id
  2052.       CraftingManager.crafting_type && CraftingManager.crafting_type.id
  2053.     end
  2054.  
  2055.     def amount_string(index)
  2056.       amount = amount(index)
  2057.       c_id = $game_party.item_number(item(index)) < amount ? 25 : 0
  2058.       "\\c[#{c_id}]#{amount}"
  2059.     end
  2060.  
  2061.     def draw_item(index)
  2062.       draw_icon(item(index).icon_index, icon_rect(index).x, icon_rect(index).y, item_enabled?(index))
  2063.       draw_text_ex(amount_x(index), amount_y(index), amount_string(index)) if draw_amount?(index)
  2064.     end
  2065.  
  2066.     def draw_amount?(index)
  2067.       amount(index) > 1 || $game_party.item_number(item(index)) < amount(index)
  2068.     end
  2069.  
  2070.     def make_item_list
  2071.       CraftingManager.current_recipe.ingredients.each{|ingredient, amount| add_item(ingredient, amount)}
  2072.     end
  2073.  
  2074.     def background_times
  2075.       return super unless CraftingManager.crafting_type.ingredient_cap
  2076.       CraftingManager.crafting_type.ingredient_cap
  2077.     end
  2078.  
  2079.     def draw_backgrounds?
  2080.       true
  2081.     end
  2082.   end
  2083. end
  2084. module EVG
  2085.   class Window_CraftingItemCategory < Window_Base
  2086.     def initialize(x, y, width, height)
  2087.       super(x, y, width, height)
  2088.       @index = 0
  2089.       deactivate
  2090.       refresh
  2091.     end
  2092.  
  2093.     def categories
  2094.       CraftingManager.crafting_type.possible_categories
  2095.     end
  2096.  
  2097.     def category
  2098.       categories[@index]
  2099.     end
  2100.  
  2101.     def next_category
  2102.       @index = (@index + 1) % categories.size
  2103.       refresh
  2104.     end
  2105.  
  2106.     def prev_category
  2107.       @index = (@index - 1) % categories.size
  2108.       refresh
  2109.     end
  2110.  
  2111.     def select(index)
  2112.       @index = [index, categories.size].min
  2113.       refresh
  2114.     end
  2115.  
  2116.     def draw_symbols
  2117.       prev_text = CRAFTING_SETTINGS::PREV_CATEGORY_VOCAB
  2118.       next_text = CRAFTING_SETTINGS::NEXT_CATEGORY_VOCAB
  2119.       draw_text(0, 0, contents.width, line_height, prev_text)
  2120.       draw_text(0, 0, contents.width, line_height, next_text, 2)
  2121.     end
  2122.  
  2123.     def refresh
  2124.       contents.clear
  2125.       return unless category
  2126.       change_color(normal_color, active)
  2127.       draw_symbols if categories.size > 1
  2128.       change_color(normal_color)
  2129.       draw_text(0,0, contents.width, line_height, Vocab.send(category), 1)
  2130.       draw_underline(0, line_height / 2, contents.width)
  2131.     end
  2132.   end
  2133. end
  2134. module EVG
  2135.   class Window_CraftingItemList < Window_CraftingList
  2136.     attr_accessor :category_window
  2137.  
  2138.     def initialize(x, y, width, height)
  2139.       super(x, y, width, height)
  2140.       self.opacity = 0
  2141.     end
  2142.  
  2143.     def item_height
  2144.       34
  2145.     end
  2146.  
  2147.     def spacing
  2148.       3
  2149.     end
  2150.  
  2151.     def type_id
  2152.       CraftingManager.crafting_type && CraftingManager.crafting_type.id
  2153.     end
  2154.  
  2155.     def category
  2156.       @category_window && @category_window.category
  2157.     end
  2158.  
  2159.     def category_window=(window)
  2160.       @category_window = window
  2161.       refresh
  2162.     end
  2163.  
  2164.     def include?(item)
  2165.       item.ingredient? && correct_category?(item) && !item.tool? && item.correct_type?(type_id)
  2166.     end
  2167.  
  2168.     def correct_category?(item)
  2169.       case category
  2170.         when :item
  2171.           item.is_a?(RPG::Item) && !item.key_item?
  2172.         when :weapon
  2173.           item.is_a?(RPG::Weapon)
  2174.         when :armor
  2175.           item.is_a?(RPG::Armor)
  2176.         else
  2177.           false
  2178.       end
  2179.     end
  2180.  
  2181.     def item_enabled?(index)
  2182.       return false if ingredients_full?(index)
  2183.       return true  if force_item_enabled?
  2184.       CraftingManager.can_change?(item(index), 1)
  2185.     end
  2186.  
  2187.     def force_item_enabled?
  2188.       !$game_switches[CRAFTING_SETTINGS::PERFECT_CRAFTING_SWITCH_ID]
  2189.     end
  2190.  
  2191.     def ingredients_full?(index)
  2192.       return false unless CraftingManager.crafting_type.ingredient_cap
  2193.       return false if CraftingManager.current_recipe.ingredients[item(index).to_sym]
  2194.       CraftingManager.current_recipe.ingredients.size >= CraftingManager.crafting_type.ingredient_cap
  2195.     end
  2196.  
  2197.     def make_item_list
  2198.       $game_party.all_items.each {|item| add_item(item, $game_party.item_number(item)) if include?(item)}
  2199.     end
  2200.  
  2201.     def cursor_movable?
  2202.       active && open? && !@cursor_fix && !@cursor_all
  2203.     end
  2204.  
  2205.     def process_cursor_move
  2206.       return unless cursor_movable?
  2207.       if item_max > 0
  2208.         last_index = @index
  2209.         cursor_down (Input.trigger?(:DOWN))  if Input.repeat?(:DOWN)
  2210.         cursor_up   (Input.trigger?(:UP))    if Input.repeat?(:UP)
  2211.         cursor_right(Input.trigger?(:RIGHT)) if Input.repeat?(:RIGHT)
  2212.         cursor_left (Input.trigger?(:LEFT))  if Input.repeat?(:LEFT)
  2213.         Sound.play_cursor if @index != last_index
  2214.       end
  2215.       cursor_pagedown   if !handle?(:pagedown) && Input.trigger?(:R)
  2216.       cursor_pageup     if !handle?(:pageup)   && Input.trigger?(:L)
  2217.     end
  2218.     def cursor_pagedown
  2219.       @category_window && @category_window.next_category
  2220.       select(0)
  2221.       refresh
  2222.       Sound.play_cursor
  2223.     end
  2224.  
  2225.     def cursor_pageup
  2226.       @category_window && @category_window.prev_category
  2227.       select(0)
  2228.       refresh
  2229.       Sound.play_cursor
  2230.     end
  2231.   end
  2232. end
  2233. module EVG
  2234.   class Window_CraftingNotification < Window_Selectable
  2235.     def initialize
  2236.       super(0, 0, Graphics.width / 2, 0)
  2237.       self.openness = 0
  2238.       @lines = []
  2239.     end
  2240.  
  2241.     def add_line(line)
  2242.       @lines.push(line)
  2243.     end
  2244.  
  2245.     def open
  2246.       activate
  2247.       refresh
  2248.       super
  2249.     end
  2250.  
  2251.     def close
  2252.       @lines.clear
  2253.       super
  2254.     end
  2255.  
  2256.     def refresh
  2257.       correct_position
  2258.       create_contents
  2259.       draw_lines
  2260.     end
  2261.  
  2262.     def correct_position
  2263.       self.height = standard_padding * 2 + line_height * @lines.size
  2264.       self.x = (Graphics.width - self.width) / 2
  2265.       self.y = (Graphics.height - self.height) / 2
  2266.     end
  2267.  
  2268.     def draw_lines
  2269.       @lines.each_with_index do |line, i|
  2270.         line.include?("item=") ? draw_item(line, i) : draw_line(line, i)
  2271.       end
  2272.     end
  2273.  
  2274.     def draw_item(line, i)
  2275.       regex = /\[item=(.+)\]\[amount=(\d+)\]/i
  2276.       matches = regex.match(line)
  2277.       return unless matches
  2278.       item = Converter.sym_to_item(matches[1].to_sym)
  2279.       amount = matches[2].to_i
  2280.       draw_icon(item.icon_index, 0, line_height * i)
  2281.       draw_text(24, line_height * i, contents.width, line_height, item.name)
  2282.       if amount != CraftingManager.matching_recipe.results[item.to_sym]
  2283.         change_color(power_up_color)
  2284.       end
  2285.       draw_text(0, line_height * i, contents.width, line_height, "x%d" % amount, 2)
  2286.       change_color(normal_color)
  2287.     end
  2288.  
  2289.     def draw_line(line, i)
  2290.       draw_text(0, i * line_height, contents.width, line_height, line, 1)
  2291.     end
  2292.  
  2293.     def process_ok
  2294.       Sound.play_ok
  2295.       Input.update
  2296.       deactivate
  2297.       call_ok_handler
  2298.     end
  2299.  
  2300.     def process_handling
  2301.       return unless open? && active
  2302.       inputs = [:C, :B, CRAFTING_SETTINGS::CRAFTING_START_BUTTON]
  2303.       process_ok if ok_enabled? && inputs.any?{|i| Input.trigger?(i)}
  2304.     end
  2305.   end
  2306. end
  2307. module EVG
  2308.   class Window_CraftingRecipeList < Window_Command
  2309.     attr_accessor :windows_to_refresh
  2310.     def initialize(x, y, width, height)
  2311.       @custom_width = width
  2312.       @custom_height = height
  2313.       super(x, y)
  2314.       self.openness = 0
  2315.       self.active = false
  2316.     end
  2317.  
  2318.     def window_width
  2319.       @custom_width
  2320.     end
  2321.  
  2322.     def window_height
  2323.       @custom_height
  2324.     end
  2325.  
  2326.     def type_id
  2327.       CraftingManager.crafting_type && CraftingManager.crafting_type.id
  2328.     end
  2329.  
  2330.     def include?(recipe)
  2331.       recipe.tool == CraftingManager.current_tool
  2332.     end
  2333.  
  2334.     def recipe(id)
  2335.       CraftingManager.crafting_type.recipes_hash[id]
  2336.     end
  2337.  
  2338.     def make_command_list
  2339.       CraftingManager.crafting_type.learned_recipes.each do |id|
  2340.         recipe = recipe(id)
  2341.         add_command(recipe.vocab, recipe.id, enabled?(id)) if include?(recipe)
  2342.       end
  2343.     end
  2344.  
  2345.     def enabled?(id)
  2346.       CraftingManager.can_craft?(recipe(id))
  2347.     end
  2348.  
  2349.     def call_update_help
  2350.       super
  2351.       if self.openness <= 0 && !active
  2352.         return CraftingManager.clear
  2353.       end
  2354.       CraftingManager.set_recipe(recipe(current_symbol))
  2355.       @windows_to_refresh.each(&:refresh) if @windows_to_refresh
  2356.       refresh
  2357.     end
  2358.   end
  2359. end
  2360. module EVG
  2361.   class Window_CraftingResultList < Window_CraftingList
  2362.     def initialize(x, y)
  2363.       super(x, y, window_width, window_height)
  2364.       self.opacity = 0
  2365.     end
  2366.  
  2367.     def window_width
  2368.       Graphics.width / 2
  2369.     end
  2370.  
  2371.     def window_height
  2372.       item_height + standard_padding * 2 + spacing
  2373.     end
  2374.  
  2375.     def draw_backgrounds?
  2376.       true
  2377.     end
  2378.  
  2379.     def make_item_list
  2380.       return unless CraftingManager.matching_recipe
  2381.       return unless learned_recipe?
  2382.       CraftingManager.matching_recipe.results.each do |item, amount|
  2383.         add_item(item, amount)
  2384.       end
  2385.     end
  2386.  
  2387.     def learned_recipe?
  2388.       CraftingManager.crafting_type.learned_recipes.include?(CraftingManager.matching_recipe.id)
  2389.     end
  2390.  
  2391.     def draw_item(index)
  2392.       draw_icon(item_icon_index(index), icon_rect(index).x, icon_rect(index).y, item_enabled?(index))
  2393.       draw_text_ex(amount_x(index), amount_y(index), amount_string(index)) if draw_amount?(index)
  2394.     end
  2395.  
  2396.     def item_icon_index(index)
  2397.       learned_recipe? ? item(index).icon_index : 16
  2398.     end
  2399.  
  2400.     def amount_string(index)
  2401.       learned_recipe? ? super(index) : "??"
  2402.     end
  2403.  
  2404.     def background_times
  2405.       return super unless CraftingManager.crafting_type.result_cap
  2406.       CraftingManager.crafting_type.result_cap
  2407.     end
  2408.  
  2409.     def draw_amount?(index)
  2410.       !learned_recipe? || amount(index) > 1
  2411.     end
  2412.   end
  2413. end
  2414. module EVG
  2415.   class Window_CraftingToolList < Window_CraftingList
  2416.     def initialize(x, y, width, height)
  2417.       super(x, y, width, height)
  2418.       self.openness = 0
  2419.     end
  2420.  
  2421.     def type_id
  2422.       CraftingManager.crafting_type && CraftingManager.crafting_type.id
  2423.     end
  2424.  
  2425.     def tool
  2426.       CraftingManager.current_recipe.tool
  2427.     end
  2428.  
  2429.     def include?(item)
  2430.       item.tool_type_ids.include?(type_id)
  2431.     end
  2432.  
  2433.     def enable_item?(item)
  2434.       true
  2435.     end
  2436.  
  2437.     def make_item_list
  2438.       $game_party.all_items.each {|item| add_item(item, 1) if include?(item)}
  2439.     end
  2440.  
  2441.     def draw_item(index)
  2442.       draw_background(index) if tool && tool.to_sym == item(index).to_sym
  2443.       super
  2444.     end
  2445.   end
  2446. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement