KK20

F0 Blacksmith 2.0 Fix

Jan 2nd, 2014
423
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:
  2. # Blacksmith Shop
  3. # Author: ForeverZer0
  4. # Type: Custom Shop System
  5. # Date: 4.23.2011
  6. # Version: v.2.0
  7. #:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:
  8. #
  9. # Explanation:
  10. #   Will allow you to create a complete blacksmithing system. The player will be
  11. #   able to forge equipment/items by using combinations of weapons, armors, and
  12. #   items in their possession. Also includes a "Enchantment" feature that will
  13. #   allow the player to use special items to add stats, elementel efficiencies,
  14. #   and state altering to weapons and armor. The extraction feature allows for
  15. #   the breaking down of current equipment and items into other ones.
  16. #
  17. # Features:
  18. #   - Completely configurable item requirements for every item.
  19. #   - Configurable blacksmith 'fees' for every weapon/armor
  20. #   - Can use as many different items, with different quantities for each piece
  21. #     of equipment.
  22. #   - Variable "skill" levels for Blacksmith shops, which lets you decide
  23. #     which features the Blacksmith can do.
  24. #   - Only have to use a single script call to for the Blacksmith's shop.
  25. #   - Can recycle old equipment by extracting items from weapons/armors/items.
  26. #
  27. # Instructions:
  28. #   - Place script below debug and above main
  29. #   - Configuration and instructions for each are below
  30. #   - To call blacksmith shop, this script call:
  31. #
  32. #         w = [ WEAPON_IDS ]    (Use as many as needed, seperate with commas)
  33. #         a = [ ARMOR_IDS ]
  34. #         i = [ ITEM_IDS ]
  35. #         $scene = Scene_BlackSmith.new(w, a, i)
  36. #
  37. #   - All IDs that you included in the script call for items will be be
  38. #     available for forging in that shop.
  39. #   - You can also include a fourth argument to the call to set the Blacksmith's
  40. #     "skill level". Just make an array of true/false elemenets, set up like
  41. #     this:
  42. #
  43. #             [CAN_FORGE?, CAN_EXTRACT?, CAN_ENCHANT?]
  44. #
  45. #     If you are not using the Enchant feature, omit the last option. Just make
  46. #     sure that if you do include this argument that the array has a value for
  47. #     each skill.
  48. #
  49. # Credits/Thanks:
  50. #   - ForeverZer0, for the script.
  51. #   - RoseSkye, huge thanks for beta-testing and demo map.
  52. #
  53. # Author's Notes:
  54. #   Please report any bugs/issues at www.chaos-project.com
  55. #
  56. #:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:
  57.  
  58. module Blacksmith
  59.  
  60. #===============================================================================
  61. #                          BEGIN CONFIGURATION
  62. #===============================================================================
  63.  
  64.   FORGE_SE = ['006-System06', 80, 100]
  65.   # SE played when an item is forged. ['FILENAME', VOLUME, PITCH]
  66.   EXTRACT_SE = ['020-Teleport03', 80, 100]
  67.   # SE played when an item extraction is performed. ['FILENAME', VOLUME, PITCH]
  68.   ENCHANT_SE = ['020-Teleport03', 80, 100]
  69.   # SE played when an item enchantment is performed. ['FILENAME', VOLUME, PITCH]
  70.  
  71.   USE_ENCHANTMENTS = true
  72.   # Set to true to enable the "Enchant" feature of the system.
  73.  
  74.   NO_ENCHANT_WEAPONS = []
  75.   NO_ENCHANT_ARMORS = []
  76.   # Include IDs of any equipment that cannot be enchanted in the respective
  77.   # arrays, seperating by commas. Ignore these if not using enchant feature.
  78.  
  79.   # Define the colors used for the text in the Blacksmith shop.
  80.   PLUS_COLOR = Color.new(128, 255, 128)
  81.   MINUS_COLOR = Color.new(255, 128, 128)
  82.  
  83.   MAP_BACK = true
  84.   # Set to true if you would like slightly opaque windows with the map showing
  85.   # through.
  86.  
  87.   #-----------------------------------------------------------------------------
  88.   # FORGE DATABASE
  89.   #-----------------------------------------------------------------------------
  90.   # Define the materials used for each weapon/armor/item that can be forged and
  91.   # extracted. They configuration is slightly different than what it was in the
  92.   # first version of the script. You can seperately define materials that are
  93.   # given during extraction if you like, or ignore it and it will simply return
  94.   # the same materials it takes to forge them. It works like this:
  95.   #
  96.   # STEP 1:
  97.   #   Create a new "case" in the appropriate method below for the type of item
  98.   #   you are trying to define. There are three of them, one each for weapons,
  99.   #   armors, and items. Just use this syntax:
  100.   #      
  101.   #          when DATABASE_ID then []
  102.   #
  103.   # STEP 2:
  104.   #   Now you can begin to add materials to forge the item. Each material has
  105.   #   an number which defines what type of item is is. Here is the "key":
  106.   #
  107.   #       0 = Weapon
  108.   #       1 = Armor
  109.   #       2 = Item
  110.   #
  111.   #   To define a material for an item, you simply create a three element array
  112.   #   using this format:
  113.   #                       [ITEM_TYPE, DATABASE_ID, QUANTITY]
  114.   #
  115.   #   ...and add it the appropriate empty array in the case statement you made
  116.   #   in Step 1. You can add as many different items as you please to forge an
  117.   #   weapon/armor/item, simply seperate the material arrays with commas. See
  118.   #   below for a few examples.
  119.   #-----------------------------------------------------------------------------
  120.   def self.weapon_forges(id)
  121.     return case id
  122.     when 1 then [[2, 33, 3], [2, 42, 1]]            # Bronze Sword
  123.     when 2 then [[0, 1, 1], [2, 34, 2], [2, 42, 1]] # Iron Sword
  124.     when 3 then [[0, 2, 1], [2, 34, 10]]            # Steel Sword
  125.     when 4 then [[0, 2, 2], [2, 35, 3], [2, 41, 1]] # Mythril Sword
  126.     when 5 then [[2, 33, 5], [2, 43, 1]]            # Bronze Spear
  127.     when 6 then [[2, 34, 4], [0, 5, 1], [2, 43, 1]] # Iron Spear
  128.     when 7 then [[0, 6, 2], [2, 34, 2], [2, 43, 1]] # Steel Spear
  129.     when 8 then [[2, 35, 8], [2, 43, 1]]            # Mythril Spear
  130.     end
  131.   end
  132.  
  133.   def self.armor_forges(id)
  134.     return case id
  135.     when 1 then []
  136.     when 2 then []
  137.     when 3 then []
  138.     when 4 then []
  139.     when 5 then []
  140.     end
  141.   end
  142.  
  143.   def self.item_forges(id)
  144.     return case id
  145.     when 2 then [[2, 1, 5]]
  146.     when 3 then [[2, 2, 5]]
  147.     when 5 then [[2, 4, 5]]
  148.     when 6 then [[2, 5, 5]]
  149.     end
  150.   end
  151.  
  152.   #-----------------------------------------------------------------------------
  153.   # EXTRACT DATABASE
  154.   #-----------------------------------------------------------------------------
  155.   # Here you can define the items received when a specific item is extracted.
  156.   # It can be setup the same as way as above. Items left undefined will return
  157.   # the same items that are required to forge it. You can define an item with an
  158.   # empty array to have it return no items, though it can still return gold.
  159.   #-----------------------------------------------------------------------------
  160.   def self.weapon_extractions(id)
  161.     return case id
  162.     when 1 then [[2, 33, 1], [2, 42, 1]]
  163.     when 2 then [[2, 34, 1], [2, 41, 1]]
  164.     when 3 then [[2, 34, 2], [0, 1, 1]]
  165.     when 4 then [[2, 33, 5], [2, 34, 5], [2, 41, 1]]
  166.     when 5 then [[2, 33, 1], [2, 43, 1]]
  167.     when 6 then [[2, 34, 1], [2, 43, 1]]
  168.     when 7 then [[2, 34, 2], [0, 5, 1]]
  169.     when 8 then [[2, 33, 5], [2, 34, 5], [2, 43, 1]]
  170.     else
  171.       self.weapon_forges(id)
  172.     end
  173.      
  174.   end
  175.  
  176.   def self.armor_extractions(id)
  177.     return case id
  178.     when 1 then []
  179.     when 2 then []
  180.     when 3 then []
  181.     when 4 then []
  182.     when 5 then []
  183.     else
  184.       self.armor_forges(id)
  185.     end
  186.   end
  187.  
  188.   def self.item_extractions(id)
  189.     return case id
  190.     when 1 then []                     # Potion
  191.     when 2 then [[2, 1, 2]]            # High Potion
  192.     when 3 then [[2, 2, 2], [2, 1, 2]] # Full Potion
  193.     when 4 then []                     # Perfume
  194.     when 5 then [[2, 4, 2]]            # High Perfume
  195.     when 6 then [[2, 4, 2], [2, 5, 2]] # Full Perfume
  196.     else
  197.       self.item_forges(id)
  198.     end
  199.   end
  200.  
  201.   #-----------------------------------------------------------------------------
  202.   # GOLD DATABASE
  203.   #-----------------------------------------------------------------------------
  204.   # Here you can define the amount of gold that is required to forge an item,
  205.   # and the amount that is given if extracted. There are three methods, one each
  206.   # for weapons, armors, and items. Simply follow this pattern for each
  207.   # category:
  208.   #
  209.   #     when DATABASE_ID then [FORGE_PRICE, EXTRACT_GOLD,]
  210.   #-----------------------------------------------------------------------------
  211.   def self.weapon_gold(id)
  212.     return case id
  213.     when 1 then [200, 50]
  214.     when 2 then [450, 225]
  215.     when 3 then [1000, 525]
  216.     when 4 then [1200, 200]
  217.     when 5 then [300, 75]
  218.     when 6 then [550, 275]
  219.     when 7 then [1200, 600]
  220.     when 8 then [1500, 650]
  221.     else
  222.       [0, 0]
  223.     end
  224.   end
  225.  
  226.   def self.armor_gold(id)
  227.     return case id
  228.     when 1 then [200, 25]
  229.     when 2 then [500, 75]
  230.     when 3 then [1500, 125]
  231.     when 4 then [6000, 400]
  232.     when 5 then [25000, 1000]
  233.     else
  234.       [0, 0]
  235.     end
  236.   end
  237.  
  238.   def self.item_gold(id)
  239.     return case id
  240.     when 1 then [100, 0]
  241.     when 2 then [50, 25]
  242.     when 3 then [250, 25]
  243.     when 4 then [100, 0]
  244.     when 5 then [50, 25]
  245.     when 6 then [250, 25]
  246.     else
  247.       [0, 0]
  248.     end
  249.   end
  250.  
  251.   #-----------------------------------------------------------------------------
  252.   # ENCHANT DATABASE
  253.   #-----------------------------------------------------------------------------
  254.  
  255.   #-----------------------------------------------------------------------------
  256.   # Here you can define what items will alter stats when used to enchant with.
  257.   # You need to create a two element array, and add it to the respective array
  258.   # below that corresponds with the desired item.
  259.   #
  260.   # ex.
  261.   #     when ITEM_ID then [[KEYWORD, VALUE], [KEYWORD, VALUE]]
  262.   #
  263.   #     KEYWORD: See below for a list of possible keywords. Stat changes that
  264.   #              can affect only weapons will have no effect on armors, and
  265.   #              vice-versa.
  266.   #     VALUE : The amount by which to change the stat. Negative values will
  267.   #             lower the stat.
  268.   #-----------------------------------------------------------------------------
  269.   # KEYWORDS:
  270.   #
  271.   #   'ATK' (Weapon Only)           'DEX'               'PDEF'
  272.   #   'EVA' (Armor Only)            'AGI'               'MDEF'
  273.   #   'STR'                         'INT'    
  274.   #
  275.   #   ** Keywords have to be written EXACTLY as they appear.
  276.   #-----------------------------------------------------------------------------
  277.   def self.enchant_stats(item_id)
  278.     return case item_id
  279.     when 39 then [['AGI', 5]]              # Carrot
  280.     when 40 then [['STR', 15], ['ATK', 5]] # Behemoth Juice
  281.     end
  282.   end
  283.  
  284.   #-----------------------------------------------------------------------------
  285.   # Define state altering enchantments.
  286.   #
  287.   # ex.
  288.   #     when ITEM_ID then [[VALUE, STATE_ID], [VALUE, STATE_ID]]
  289.   #
  290.   #     VALUE: One of three different values to represent states efficiency.
  291.   #              -1 = Minus state (Does nothing on armors)
  292.   #               0 = Neutral
  293.   #               1 = Plus state
  294.   #     STATE_ID: The ID in the database of the state.
  295.   #-----------------------------------------------------------------------------
  296.   def self.enchant_states(item_id)
  297.     return case item_id
  298.     when 38 then [[1, 2], [1, 4], [1, 6]] # Chaos Orb
  299.     end
  300.   end
  301.  
  302.   #-----------------------------------------------------------------------------
  303.   # Define element altering enchantments.
  304.   #
  305.   # ex.
  306.   #     when ITEM_ID then [[VALUE, ELEMENT_ID], [VALUE, ELEMENT_ID]]
  307.   #
  308.   #     VALUE: One of two different values to represent element efficiency.
  309.   #              true  = Uses element
  310.   #              false = Doesn't use element (Negates element if present)
  311.   #     ELEMENT_ID: The ID in the database of the element.
  312.   #-----------------------------------------------------------------------------
  313.   def self.enchant_elements(item_id)
  314.     return case item_id
  315.     when 36 then [[true, 3], [false, 5]] # Amethyst
  316.     when 37 then [[true, 1]]             # Ruby ;)
  317.     end
  318.   end  
  319.  
  320.   #-----------------------------------------------------------------------------
  321.   # Define the amount of gold it takes to enchant a weapon or armor with the
  322.   # item.
  323.   #-----------------------------------------------------------------------------
  324.   def self.enchant_gold(item_id)
  325.     return case item_id
  326.     when 36 then 1500
  327.     when 37 then 1100
  328.     when 38 then 1337
  329.     when 39 then 250
  330.     when 40 then 7500
  331.     else
  332.       0
  333.     end
  334.   end
  335.  
  336. #===============================================================================
  337. #                              END CONFIGURATION
  338. #===============================================================================
  339.  
  340.   def self.materials?(type, id)
  341.     # Get the required materials for the item
  342.     materials = case type
  343.     when 0 then [self.weapon_forges(id), self.weapon_gold(id)]
  344.     when 1 then [self.armor_forges(id), self.armor_gold(id)]
  345.     when 2 then [self.item_forges(id), self.item_gold(id)]
  346.     end
  347.     materials[0] = [] if materials[0] == nil
  348.     # Check gold, skipping item check if there is not enough.
  349.     if $game_party.gold >= materials[1][0]
  350.       # Iterate all required materials, making sure enough are in inventory.
  351.       materials[0].each {|item|
  352.         # Branch by the type of the item.
  353.         result = case item[0]
  354.         when 0 then ($game_party.weapon_number(item[1]) >= item[2])
  355.         when 1 then ($game_party.armor_number(item[1]) >= item[2])
  356.         when 2 then ($game_party.item_number(item[1]) >= item[2])
  357.         end
  358.         # End iteration and return false immidiately if missing required item.
  359.         return false unless result
  360.       }
  361.       return true
  362.     end
  363.     return false
  364.   end
  365.   #-----------------------------------------------------------------------------
  366.   def self.update_database(item)
  367.     # Open the Weapons or Armors .rxdata file and add the created item.
  368.     begin
  369.       if item.is_a?(RPG::Weapon)
  370.         file, data = 'Data/Weapons.rxdata', $data_weapons
  371.       elsif item.is_a?(RPG::Armor)
  372.         file, data = 'Data/Armors.rxdata', $data_armors
  373.       else
  374.         return
  375.       end
  376.       data[item.id] = item
  377.       file = File.open(file, 'wb')
  378.       Marshal.dump(data, file)
  379.       file.close
  380.     rescue
  381.       print "Could not add #{item.name} to Database."
  382.     end
  383.   end
  384.   #-----------------------------------------------------------------------------
  385.   def self.create_item(base_item, enchant_item)
  386.     base = base_item.clone
  387.     # Do to clone only making shallow copies, it is necessary to also create
  388.     # seperate clones of the element and state sets, otherwise the original
  389.     # is affected too.
  390.     if base_item.is_a?(RPG::Weapon)
  391.       elem_set = base_item.element_set.clone
  392.       plus_state_set = base_item.plus_state_set.clone
  393.       minus_state_set = base_item.minus_state_set.clone
  394.     else
  395.       guard_elem_set = base_item.guard_element_set.clone
  396.       guard_state_set = base_item.guard_state_set.clone
  397.     end
  398.     # Gather the enchantment data.
  399.     stats = self.enchant_stats(enchant_item.id)
  400.     states = self.enchant_states(enchant_item.id)
  401.     elements = self.enchant_elements(enchant_item.id)
  402.     # Iterate through stats
  403.     if stats != nil
  404.       stats.each {|stat|
  405.         case stat[0]
  406.         when 'ATK'
  407.           if base.is_a?(RPG::Weapon)
  408.             base.atk += stat[1]
  409.           end
  410.         when 'EVA'
  411.           if base.is?(RPG::Armor)
  412.             base.eva += stat[1]
  413.           end
  414.         when 'STR' then base.str_plus += stat[1]
  415.         when 'DEX' then base.dex_plus += stat[1]
  416.         when 'AGI' then base.agi_plus += stat[1]
  417.         when 'INT' then base.int_plus += stat[1]
  418.         when 'PDEF' then base.pdef_plus += stat[1]
  419.         when 'MDEF' then base.mdef_plus += stat[1]
  420.         end
  421.       }
  422.     end
  423.     # Iterate through states
  424.     if states != nil
  425.       states.each {|state|
  426.         id = state[1]
  427.         if base.is_a?(RPG::Weapon)
  428.           case state[0]
  429.           when -1
  430.             minus_state_set.push(id) unless minus_state_set.include?(id)
  431.             plus_state_set -= [id]
  432.           when 0
  433.             minus_state_set -= [id]
  434.             plus_state_set -= [id]
  435.           when 1
  436.             plus_state_set.push(id) unless plus_state_set.include?(id)
  437.             minus_state_set -= [id]
  438.           end
  439.         elsif base.is_a?(RPG::Armor)
  440.           if state[0] == 0
  441.             guard_state_set -= [id]
  442.           elsif state[0] == 1
  443.             guard_state_set.push(id) unless guard_state_set.inlcude?(id)
  444.           end
  445.         end
  446.       }
  447.     end
  448.     # Iterate through elements
  449.     if elements != nil
  450.       elements.each {|element|
  451.         id = element[1]
  452.         if base.is_a?(RPG::Weapon)
  453.           if element[0] && !elem_set.include?(id)
  454.             elem_set.push(id)
  455.           else
  456.             elem_set -= [id]
  457.           end
  458.         elsif base.is_a?(RPG::Armor)
  459.           if element[0] && !guard_elem_set.include?(id)
  460.             guard_elem_set.push(id)
  461.           else
  462.             guard_elem_set -= [id]
  463.           end
  464.         end
  465.       }
  466.     end
  467.     # Give the weapon a new ID, remove the old item, and add the new one.
  468.     if base.is_a?(RPG::Weapon)
  469.       $game_party.lose_weapon(base_item.id, 1)
  470.       base.id = $data_weapons.size
  471.       base.element_set = elem_set
  472.       base.plus_state_set = plus_state_set
  473.       base.minus_state_set = minus_state_set
  474.       $data_weapons[base.id] = base
  475.       $game_party.gain_weapon(base.id, 1)
  476.     elsif base.is_a?(RPG::Armor)
  477.       $game_party.lose_armor(base_item.id, 1)
  478.       base.id = $data_armors.size
  479.       base.guard_element_set = guard_elem_set
  480.       base.guard_state_set = guard_state_set
  481.       $data_armors[base.id] = base
  482.       $game_party.gain_armor(base.id, 1)
  483.     end
  484.     # Add new item to class equipment
  485.     self.update_class_equipment(base_item, base)
  486.     # Save the new item to the database.
  487.     self.update_database(base)
  488.   end
  489.   #-----------------------------------------------------------------------------
  490.   def self.update_class_equipment(old, new)
  491.     # Adds the created item to class equipment that could equip the original
  492.     $data_classes.each_index {|i|
  493.       next if $data_classes[i] == nil
  494.       if old.is_a?(RPG::Weapon) && $data_classes[i].weapon_set.include?(old.id)
  495.         $data_classes[i].weapon_set.push(new.id)
  496.       elsif old.is_a?(RPG::Armor) && $data_classes[i].armor_set.include?(old.id)
  497.         $data_classes[i].armor_set.push(new.id)
  498.       end
  499.     }
  500.     # Marshal the new data.
  501.     begin
  502.       file = File.open('Data/Classes.rxdata', 'wb')
  503.       Marshal.dump($data_classes, file)
  504.       file.close
  505.     rescue
  506.       print "Could not update RPG::Class database."
  507.     end
  508.   end
  509. end
  510.  
  511.  
  512.   $blacksmith = 2.0
  513.  
  514. #===============================================================================
  515. # ** Window_BlacksmithCommand
  516. #===============================================================================
  517.  
  518. class Window_BlacksmithCommand < Window_Selectable
  519.  
  520.   def initialize(level)
  521.     super(0, 64, 480, 64)
  522.     @level = level
  523.     if Blacksmith::USE_ENCHANTMENTS
  524.       @item_max = @column_max = 4
  525.       @commands = ['Forge', 'Extract', 'Enchant', 'Exit']
  526.     else
  527.       @item_max = @column_max = 3
  528.       @commands = ['Forge', 'Extract', 'Exit']
  529.     end
  530.     self.contents = Bitmap.new(self.width - 32, self.height - 32)
  531.     refresh
  532.     self.index = 0
  533.   end
  534.   #-----------------------------------------------------------------------------
  535.   def refresh
  536.     self.contents.clear
  537.     (0...@item_max).each {|i| draw_item(i) }
  538.   end
  539.   #-----------------------------------------------------------------------------
  540.   def draw_item(index)
  541.     w = self.width / @item_max
  542.     self.contents.font.color = @level[index] ? normal_color : disabled_color
  543.     self.contents.draw_text(4 + (w * index), 0, w, 32, @commands[index])
  544.   end
  545. end
  546.  
  547. #===============================================================================
  548. # ** Window_BlacksmithForge
  549. #===============================================================================
  550.  
  551. class Window_BlacksmithForge < Window_Selectable
  552.  
  553.   def initialize(shop_goods)
  554.     super(0, 128, 368, 352)
  555.     # Initialize window and create instance variable to store available goods.
  556.     @shop_goods = shop_goods
  557.     self.active = self.visible = false
  558.     refresh
  559.     self.index = 0
  560.   end
  561.   #-----------------------------------------------------------------------------
  562.   def item
  563.     return @data[self.index]
  564.   end
  565.   #-----------------------------------------------------------------------------
  566.   def refresh(enchanting = false)
  567.     # Dispose bitmap and set to nil if not already.
  568.     if self.contents != nil
  569.       self.contents = self.contents.dispose
  570.     end
  571.     # Set flag for enchanting
  572.     @enchanting = enchanting
  573.     # Create array of equipment, depending on flag
  574.     if @enchanting
  575.       @data = []
  576.       # Add weapons
  577.       ($data_weapons - [nil]).each {|weapon|
  578.         if $game_party.weapon_number(weapon.id) > 0 &&
  579.             !Blacksmith::NO_ENCHANT_WEAPONS.include?(weapon.id)
  580.           @data.push(weapon)
  581.         end
  582.       }
  583.       # Add Armor
  584.       ($data_armors - [nil]).each {|armor|
  585.         if $game_party.armor_number(armor.id) > 0 &&
  586.             !Blacksmith::NO_ENCHANT_ARMORS.include?(armor.id)
  587.           @data.push(armor)
  588.         end
  589.       }
  590.     else
  591.       @data = @shop_goods
  592.     end
  593.     # Create a new bitmap, sized for available items
  594.     @item_max = @data.size
  595.     if @item_max > 0
  596.       self.contents = Bitmap.new(width - 32, row_max * 32)
  597.       (0...@item_max).each {|i| draw_item(i) }
  598.     else
  599.       self.contents = Bitmap.new(width - 32, 32)
  600.     end
  601.   end
  602.   #-----------------------------------------------------------------------------
  603.   def draw_item(index)
  604.     item = @data[index]
  605.     # Set a few local variables depending on the type of item.
  606.     case item
  607.     when RPG::Weapon
  608.       quantity = $game_party.weapon_number(item.id)
  609.       price, type = Blacksmith.weapon_gold(item.id)[0], 0
  610.     when RPG::Armor
  611.       quantity = $game_party.armor_number(item.id)
  612.       price, type = Blacksmith.armor_gold(item.id)[0], 1
  613.     when RPG::Item
  614.       quantity = $game_party.item_number(item.id)
  615.       price, type = Blacksmith.item_gold(item.id)[0], 2
  616.     end
  617.     # Don't check material requirments for forging wjen enchanting
  618.     result = @enchanting ? true : Blacksmith.materials?(type, item.id)
  619.     # Determine the color to use for drawing the item name.
  620.     if quantity < 99 && result
  621.       self.contents.font.color = normal_color
  622.     else
  623.       self.contents.font.color = disabled_color
  624.     end
  625.     # Draw the item name, icon, and price.
  626.     x, y = 4, index * 32
  627.     rect = Rect.new(x, y, self.width - 32, 32)
  628.     self.contents.fill_rect(rect, Color.new(0, 0, 0, 0))
  629.     bitmap = RPG::Cache.icon(item.icon_name)
  630.     opacity = self.contents.font.color == normal_color ? 255 : 128
  631.     self.contents.blt(x, y + 4, bitmap, Rect.new(0, 0, 24, 24), opacity)
  632.     self.contents.draw_text(x + 28, y, 212, 32, item.name, 0)
  633.     if !@enchanting
  634.       self.contents.draw_text(x + 240, y, 88, 32, price.to_s, 2)
  635.     end
  636.   end
  637.   #-----------------------------------------------------------------------------
  638.   def update_help
  639.     @help_window.set_text(self.item == nil ? '' : self.item.description)
  640.   end
  641. end
  642.  
  643. #===============================================================================
  644. # ** Window_BlacksmithExtract
  645. #===============================================================================
  646.  
  647. class Window_BlacksmithExtract < Window_Selectable
  648.  
  649.   def initialize
  650.     super(0, 128, 368, 352)
  651.     self.active = self.visible = false
  652.     refresh
  653.     self.index = 0
  654.   end
  655.   #-----------------------------------------------------------------------------
  656.   def item
  657.     return @data[self.index]
  658.   end
  659.   #-----------------------------------------------------------------------------
  660.   def refresh
  661.     # Dispose current bitmap if defined.
  662.     if self.contents != nil
  663.       self.contents = self.contents.dispose
  664.     end
  665.     # Create list of items in inventory
  666.     @data = []
  667.     (1...$data_weapons.size).each {|i|
  668.       result = (Blacksmith.weapon_extractions(i) != nil ||
  669.         Blacksmith.weapon_gold(i)[1] != 0)
  670.       if $game_party.weapon_number(i) > 0 && result
  671.         @data.push($data_weapons[i])  
  672.       end
  673.     }
  674.     (1...$data_armors.size).each {|i|
  675.       result = (Blacksmith.armor_extractions(i) != nil ||
  676.         Blacksmith.armor_gold(i)[1] != 0)
  677.       if $game_party.armor_number(i) > 0 && result
  678.         @data.push($data_armors[i])  
  679.       end
  680.     }
  681.     (1...$data_items.size).each {|i|
  682.       result = (Blacksmith.item_extractions(i) != nil ||
  683.         Blacksmith.item_gold(i)[1] != 0)
  684.       if $game_party.item_number(i) > 0 && result
  685.         @data.push($data_items[i])
  686.       end
  687.     }
  688.     @item_max = @data.size
  689.     # Create a new bitmap that will contain the listed items
  690.     if @item_max > 0
  691.       self.contents = Bitmap.new(width - 32, row_max * 32)
  692.       (0...@item_max).each {|i| draw_item(i) }
  693.     end
  694.     self.index -= 1 if (self.item.nil? && self.index > 0)
  695.   end
  696.   #-----------------------------------------------------------------------------
  697.   def draw_item(index)
  698.     item = @data[index]
  699.     # Set a few local variables depending on the type of item.
  700.     quantity = case item
  701.     when RPG::Weapon then $game_party.weapon_number(item.id)
  702.     when RPG::Armor then $game_party.armor_number(item.id)
  703.     when RPG::Item then $game_party.item_number(item.id)
  704.     end
  705.     # Draw the name, icon, and quantity of the item.
  706.     x, y = 4, index * 32
  707.     rect = Rect.new(x, y, self.width / @column_max - 32, 32)
  708.     self.contents.fill_rect(rect, Color.new(0, 0, 0, 0))
  709.     bitmap = RPG::Cache.icon(item.icon_name)
  710.     self.contents.blt(x, y + 4, bitmap, Rect.new(0, 0, 24, 24), opacity)
  711.     self.contents.draw_text(x + 28, y, 212, 32, item.name, 0)
  712.   end
  713.   #-----------------------------------------------------------------------------
  714.   def update_help
  715.     @help_window.set_text(self.item == nil ? '' : self.item.description)
  716.   end
  717. end
  718.  
  719. #===============================================================================
  720. # ** Window_BlacksmithMaterials
  721. #===============================================================================
  722.  
  723. class Window_BlacksmithMaterials < Window_Base
  724.  
  725.   attr_accessor :active
  726.  
  727.   def initialize
  728.     # Initialize window size and coordinates.
  729.     super(0, 128, 368, 352)
  730.     self.visible = @active = false
  731.   end
  732.   #-----------------------------------------------------------------------------
  733.   def refresh(item, type = 0)
  734.     # Clear the bitmap and set the new materials.
  735.     if self.contents != nil
  736.       self.contents = self.contents.dispose
  737.     end
  738.     set_materials(item, type)
  739.     # Create a new bitmap, based off the amount of materials
  740.     if @materials != nil && @materials.size > 0
  741.       self.contents = Bitmap.new(self.width - 32, 64 + (@materials.size * 32))
  742.       # Draw each material and quantity required.
  743.       self.contents.font.color = system_color
  744.       word = type == 0 ? 'Cost' : ($data_system.words.gold + ':')
  745.       self.contents.draw_text(4, 0, 212, 32, word, 0)
  746.       text = type == 0 ? 'Required Materials:' : 'Extractable Materials:'
  747.       self.contents.draw_text(4, 32, 368, 32, text, 0)
  748.       self.contents.font.color = normal_color
  749.       self.contents.draw_text(244, 0, 88, 32, @price.to_s, 2)
  750.       # Enumerate through each material.
  751.       @materials.each_index {|i|
  752.         # Set local variable to current item, depending on type.
  753.         case @materials[i][0]
  754.         when 0
  755.           item = $data_weapons[@materials[i][1]]
  756.           enough = $game_party.weapon_number(item.id) >= @materials[i][2]
  757.         when 1
  758.           item = $data_armors[@materials[i][1]]
  759.           enough = $game_party.armor_number(item.id) >= @materials[i][2]
  760.         when 2
  761.           item = $data_items[@materials[i][1]]
  762.           enough = $game_party.item_number(item.id) >= @materials[i][2]
  763.         end
  764.         next if item == nil
  765.         # Set local variable to store required amount of this item.
  766.         required = @materials[i][2]
  767.         # Set color of text, draw grayed if out if forging and not enough.
  768.         self.contents.font.color = normal_color
  769.         if type == 0 && !enough
  770.           self.contents.font.color = disabled_color
  771.         end
  772.         # Set coordinates of current line.
  773.         x, y = 4, 64 + (i * 32)
  774.         # Draw item name, icon, and required amount.
  775.         rect = Rect.new(x, y, self.width - 32, 32)
  776.         self.contents.fill_rect(rect, Color.new(0, 0, 0, 0))
  777.         bitmap = RPG::Cache.icon(item.icon_name)
  778.         opacity = self.contents.font.color == normal_color ? 255 : 128
  779.         self.contents.blt(x, y + 4, bitmap, Rect.new(0, 0, 24, 24), opacity)
  780.         self.contents.draw_text(x + 28, y, 212, 32, item.name)
  781.         self.contents.draw_text(x + 272, y, 48, 32, 'x', 0)
  782.         self.contents.draw_text(x + 272, y, 48, 32, required.to_s, 2)
  783.       }
  784.     elsif @price > 0
  785.       self.contents = Bitmap.new(self.width - 32, 64)
  786.       self.contents.font.color = system_color
  787.       self.contents.draw_text(4, 0, 212, 32, $data_system.words.gold + ':')
  788.       self.contents.font.color = normal_color
  789.       self.contents.draw_text(244, 0, 88, 32, @price.to_s, 2)
  790.       self.contents.draw_text(4, 32, 368, 32, 'No Materials')
  791.     end
  792.   end
  793.   #-----------------------------------------------------------------------------
  794.   def set_materials(item, type)
  795.     # Sets the required/extractable items for the passed item.
  796.     id = item.id
  797.     if item.is_a?(RPG::Weapon)
  798.       @materials = type == 0 ? Blacksmith.weapon_forges(id) :
  799.         Blacksmith.weapon_extractions(id)
  800.       @price = Blacksmith.weapon_gold(id)[type]
  801.     elsif item.is_a?(RPG::Armor)
  802.       @materials = type == 0 ? Blacksmith.armor_forges(id) :
  803.         Blacksmith.armor_extractions(id)
  804.       @price = Blacksmith.armor_gold(id)[type]
  805.     else
  806.       if @materials != 2
  807.         @materials = type == 0 ? Blacksmith.item_forges(id) :
  808.           Blacksmith.item_extractions(id)
  809.         @price = Blacksmith.item_gold(id)[type]
  810.       end
  811.     end
  812.   end
  813.   #-----------------------------------------------------------------------------
  814.   def update
  815.     # Allow scrolling of bitmap if materials don't fit in window.
  816.     if @active && self.contents != nil && self.contents.height > 320
  817.       if Input.trigger?(Input::UP)
  818.         if self.oy > 0
  819.           self.oy -= 32
  820.           $game_system.se_play($data_system.cursor_se)
  821.         end
  822.       elsif Input.trigger?(Input::DOWN)
  823.         if (self.oy + 320) < self.contents.height
  824.           self.oy += 32
  825.           $game_system.se_play($data_system.cursor_se)
  826.         end
  827.       end
  828.     end
  829.   end
  830. end
  831.  
  832. #===============================================================================
  833. # ** Window_BlacksmithStatus
  834. #===============================================================================
  835.  
  836. class Window_BlacksmithStatus < Window_Base
  837.   attr_reader :item
  838.   def initialize
  839.     super(368, 128, 272, 352)
  840.     self.contents = Bitmap.new(width - 32, height - 32)
  841.     # Create array of sprites same size as party
  842.     @sprites = [Sprite.new, Sprite.new, Sprite.new, Sprite.new]
  843.     # Set coordinates of each sprite
  844.     @sprites.each_index {|i|
  845.       @sprites[i].x, @sprites[i].y = 380, 194 + (i * 64)#(i * 34)
  846.       @sprites[i].z = self.z + 10
  847.     }
  848.     self.visible = false
  849.     # Array of flags for walking
  850.     @walk = Array.new($game_party.actors.size, false)
  851.     @count, @item = 0, nil
  852.     refresh
  853.   end
  854.   #-----------------------------------------------------------------------------
  855.   def refresh
  856.     # Clear bitmap and turn off visiblity of each sprite.
  857.     self.contents.clear
  858.     @sprites.each {|sprite| sprite.visible = false }
  859.     # Return if selected item index is undefined.
  860.     return if @item == nil
  861.     self.contents.font.size = Font.default_size + 2
  862.     quantity = case @item
  863.     when RPG::Item then $game_party.item_number(@item.id)
  864.     when RPG::Weapon then $game_party.weapon_number(@item.id)
  865.     when RPG::Armor then $game_party.armor_number(@item.id)
  866.     end
  867.     self.contents.font.color = system_color
  868.     self.contents.draw_text(4, 0, 200, 32, 'Possessed:')
  869.     self.contents.font.color = normal_color
  870.     self.contents.draw_text(204, 0, 32, 32, quantity.to_s, 2)
  871.     # Disable walking animation and end method if selected item is a normal item
  872.     if @item.is_a?(RPG::Item)
  873.       @walk.collect! {|value| false }
  874.       return
  875.     end
  876.     # Change the font size.
  877.     self.contents.font.size = Font.default_size - 1
  878.     # Iterate each actor...
  879.     $game_party.actors.each_index {|i|
  880.       chr = $game_party.actors[i]
  881.       # Set local variable to highlighted piece of equipment.
  882.       if @item.is_a?(RPG::Weapon)
  883.         eqp = $data_weapons[chr.weapon_id]
  884.       else
  885.         armors = [chr.armor1_id, chr.armor2_id, chr.armor3_id, chr.armor4_id]
  886.         eqp = $data_armors[armors[@item.kind]]
  887.       end
  888.       # Draw the actor sprite.
  889.       draw_actor_graphic(i, chr.equippable?(@item))
  890.       # Draw message and return if unequippable.
  891.       unless chr.equippable?(@item)
  892.         self.contents.font.color = normal_color
  893.         self.contents.draw_text(32, 54 + (i * 64), 150, 32, 'Cannot Equip')
  894.         next
  895.       else
  896.         # Create array of stat changes.
  897.         # [str, dex, agi, int, pdef, mdef, (atk || eva)]
  898.         stats = [
  899.           (@item == nil ? 0 : @item.str_plus) - (eqp == nil ? 0 : eqp.str_plus),
  900.           (@item == nil ? 0 : @item.dex_plus) - (eqp == nil ? 0 : eqp.dex_plus),
  901.           (@item == nil ? 0 : @item.agi_plus) - (eqp == nil ? 0 : eqp.agi_plus),
  902.           (@item == nil ? 0 : @item.int_plus) - (eqp == nil ? 0 : eqp.int_plus),
  903.           (@item == nil ? 0 : @item.pdef) - (eqp == nil ? 0 : eqp.pdef),
  904.           (@item == nil ? 0 : @item.mdef) - (eqp == nil ? 0 : eqp.mdef)
  905.         ]
  906.         if @item.is_a?(RPG::Weapon)
  907.           stats.push(
  908.             (@item == nil ? 0 : @item.atk) - (eqp == nil ? 0 : eqp.atk))
  909.         elsif @item.is_a?(RPG::Armor)
  910.           stats.push(
  911.             (@item == nil ? 0 : @item.eva) - (eqp == nil ? 0 : eqp.eva))
  912.         end
  913.         # Set local variable to each piece of equipments' name
  914.         current_name = eqp == nil ? '' : eqp.name
  915.         new_name = @item == nil ? '' : @item.name
  916.         # If stats are all equal, show message and end method.
  917.         if stats.all? {|stat| stat == 0 }
  918.           self.contents.font.color = normal_color
  919.           if current_name != new_name
  920.             self.contents.draw_text(32, 54 + (i * 64), 150, 32, 'No Change')
  921.           else
  922.             self.contents.draw_text(32, 54 + (i * 64), 150, 32, 'Equipped')
  923.           end
  924.           next
  925.         end
  926.         # Draw any stat changes, using colors to show plus/minus changes
  927.         self.contents.font.size = (Font.default_size - 1)
  928.         self.contents.font.color = normal_color
  929.         self.contents.draw_text(104, 42 + (64*i), 32, 32, 'STR ') if stats[0] != 0
  930.         self.contents.draw_text(104, 58 + (64*i), 32, 32, 'DEX ') if stats[1] != 0
  931.         self.contents.draw_text(104, 74 + (64*i), 32, 32, 'AGI ') if stats[2] != 0
  932.         self.contents.draw_text(176, 42 + (64*i), 32, 32, 'INT ') if stats[3] != 0
  933.         self.contents.draw_text(32, 58 + (64*i), 32, 32, 'PDF ') if stats[4] != 0
  934.         self.contents.draw_text(32, 74 + (64*i), 32, 32, 'MDF ') if stats[5] != 0
  935.         if stats[-1] != 0
  936.           # Show stats changes for atk/eva, depending on the equipment type
  937.           stat = @item.is_a?(RPG::Weapon) ? 'ATK ' : 'EVA '
  938.           self.contents.draw_text(32, 42 + (64 * i), 32, 32, stat) if stat != 0
  939.         end
  940.         # Show any stat changes
  941.         stats.each_index {|j|
  942.           next if stats[j] == 0
  943.           xy = case j
  944.           when 0 then [132, 42 + (64 * i)]
  945.           when 1 then [132, 58 + (64 * i)]
  946.           when 2 then [132, 74 + (64 * i)]
  947.           when 3 then [198, 42 + (64 * i)]
  948.           when 4 then [60, 58 + (64 * i)]
  949.           when 5 then [60, 74 + (64 * i)]
  950.           when 6 then [60, 42 + (64 * i)]
  951.           end
  952.           # Set color and operator depending on value
  953.           if stats[j] < 0
  954.             self.contents.font.color, sign = Blacksmith::MINUS_COLOR, '-'
  955.           else
  956.             self.contents.font.color, sign = Blacksmith::PLUS_COLOR, '+'
  957.           end
  958.           self.contents.draw_text(xy[0], xy[1], 8, 32, sign, 1)
  959.           self.contents.draw_text(xy[0] + 10, xy[1], 24, 32, stats[j].abs.to_s)
  960.         }
  961.       end
  962.     }
  963.   end
  964.   #-----------------------------------------------------------------------------
  965.   def item=(item)
  966.     if @item != item
  967.       # Change the item variable and refresh.
  968.       @item = item
  969.       refresh
  970.     end
  971.   end
  972.   #-----------------------------------------------------------------------------
  973.   def draw_actor_graphic(id, equipable)
  974.     # Draws the actor graphic
  975.     actor = $game_party.actors[id]
  976.     @sprites[id].bitmap = RPG::Cache.character(actor.character_name,
  977.       actor.character_hue)
  978.     @sprites[id].src_rect.set(0, 0, @sprites[id].bitmap.width / 4,
  979.     @sprites[id].bitmap.height / 4)
  980.     # Set walking animation if item is equippable.
  981.     @walk[id] = equipable
  982.     @sprites[id].tone = Tone.new(0, 0, 0, equipable ? 0 : 255)
  983.     @sprites[id].visible = true
  984.   end
  985.   #-----------------------------------------------------------------------------
  986.   def update
  987.     super
  988.     # Update the walking animation.
  989.     @count = (@count + 1) % 40
  990.     $game_party.actors.each_index {|i|
  991.       next unless @walk[i]
  992.       if @sprites[i].bitmap != nil
  993.         w = @sprites[i].bitmap.width / 4
  994.         h = @sprites[i].bitmap.height / 4
  995.         x = (@count / 10) * w
  996.         @sprites[i].src_rect.set(x, 0, w, h)
  997.       end
  998.     }
  999.   end
  1000.   #-----------------------------------------------------------------------------
  1001.   def visible=(bool)
  1002.     super
  1003.     # Set visible to the actor sprites as well.
  1004.     @sprites.each {|sprite| sprite.visible = (bool ? !@item.nil? : false)}
  1005.   end
  1006.   #-----------------------------------------------------------------------------
  1007.   def dispose
  1008.     super
  1009.     # Dispose the actor sprites as well.
  1010.     @sprites.each {|sprite| sprite.dispose }
  1011.   end
  1012. end
  1013.  
  1014.  
  1015. #===============================================================================
  1016. # ** Window_BlacksmithEnchant
  1017. #===============================================================================
  1018.  
  1019. class Window_BlacksmithEnchant < Window_Selectable
  1020.  
  1021.   def initialize
  1022.     super(0, 128, 368, 352)
  1023.     self.active = self.visible = false
  1024.     refresh
  1025.     self.index = 0
  1026.   end
  1027.   #-----------------------------------------------------------------------------
  1028.   def item
  1029.     return @data[self.index]
  1030.   end
  1031.   #-----------------------------------------------------------------------------
  1032.   def refresh
  1033.     # Dispose current bitmap if defined.
  1034.     if self.contents != nil
  1035.       self.contents = self.contents.dispose
  1036.     end
  1037.     # Create list of items in inventory
  1038.     @data = []
  1039.     ($data_items - [nil]).each {|item|
  1040.       next if $game_party.item_number(item.id) <= 0
  1041.       result = false
  1042.       result = true if Blacksmith.enchant_stats(item.id) != nil
  1043.       result = true if Blacksmith.enchant_states(item.id) != nil
  1044.       result = true if Blacksmith.enchant_elements(item.id) != nil
  1045.       @data.push(item) if result
  1046.     }
  1047.     @item_max = @data.size
  1048.     # Create a new bitmap that will contain the listed items
  1049.     if @item_max > 0
  1050.       self.contents = Bitmap.new(width - 32, row_max * 32)
  1051.       (0...@item_max).each {|i| draw_item(i) }
  1052.     end
  1053.     self.index -= 1 if (self.item.nil? && self.index > 0)
  1054.   end
  1055.   #-----------------------------------------------------------------------------
  1056.   def draw_item(index)
  1057.     item = @data[index]
  1058.     # Set a few local variables depending on the type of item.
  1059.     quantity = $game_party.item_number(item.id)
  1060.     # Draw the name, icon, and quantity of the item.
  1061.     x, y = 4, index * 32
  1062.     rect = Rect.new(x, y, self.width / @column_max - 32, 32)
  1063.     self.contents.fill_rect(rect, Color.new(0, 0, 0, 0))
  1064.     bitmap = RPG::Cache.icon(item.icon_name)
  1065.     self.contents.blt(x, y + 4, bitmap, Rect.new(0, 0, 24, 24))
  1066.     self.contents.draw_text(x + 28, y, 212, 32, item.name, 0)
  1067.     self.contents.draw_text(x + 240, y, 16, 32, ':', 1)
  1068.     self.contents.draw_text(x + 256, y, 24, 32, quantity.to_s, 2)
  1069.   end
  1070.   #-----------------------------------------------------------------------------
  1071.   def update_help
  1072.     @help_window.set_text(self.item == nil ? '' : self.item.description)
  1073.   end
  1074. end
  1075.  
  1076. #===============================================================================
  1077. # ** Scene_Blacksmith
  1078. #===============================================================================
  1079.  
  1080. class Scene_Blacksmith
  1081.  
  1082.   def initialize(weapons = [], armors = [], items = [], level = nil)
  1083.     # Set available goods for this shop based off passed argument.
  1084.     @goods = []
  1085.     @goods += weapons.collect {|id| $data_weapons[id] }
  1086.     @goods += armors.collect {|id| $data_armors[id] }
  1087.     @goods += items.collect {|id| $data_items[id] }
  1088.     @goods.uniq!
  1089.     # Configure the level variable
  1090.     @level = (level == nil) ? Array.new(4, true) : (level + [true])
  1091.     @enchants = Blacksmith::USE_ENCHANTMENTS
  1092.   end
  1093.   #-----------------------------------------------------------------------------
  1094.   def main
  1095.     # Create a Proc to handle confirmation of choices
  1096.     @confirm_proc = Proc.new {
  1097.       @help_window.set_text('Are you sure?')
  1098.       window = Window_Command.new(160, ['Confirm', 'Cancel'])
  1099.       window.x, window.y, window.z = 224, 192, 9999
  1100.       loop { Graphics.update; Input.update; window.update
  1101.         if Input.trigger?(Input::C) || Input.trigger?(Input::B)
  1102.           result = (Input.trigger?(Input::C) && window.index == 0)
  1103.           $game_system.se_play($data_system.cancel_se) unless result
  1104.           window.dispose
  1105.           break(result)
  1106.         end
  1107.       }
  1108.     }
  1109.     # Initialize the needed windows.
  1110.     @command_window = Window_BlacksmithCommand.new(@level)
  1111.     @forge_window = Window_BlacksmithForge.new(@goods)
  1112.     @extract_window = Window_BlacksmithExtract.new
  1113.     @materials_window = Window_BlacksmithMaterials.new
  1114.     @enchant_window = Window_BlacksmithEnchant.new
  1115.     @status_window = Window_BlacksmithStatus.new
  1116.     @dummy_window = Window_Base.new(0, 128, 640, 352)
  1117.     @gold_window = Window_Gold.new
  1118.     @gold_window.x, @gold_window.y = 480, 64  
  1119.     @help_window = Window_Help.new
  1120.     # Bind the help window to the other windows.
  1121.     @forge_window.help_window = @extract_window.help_window = @help_window
  1122.     @enchant_window.help_window = @help_window
  1123.     # Set a windows array for easier handling of all windows.
  1124.     @windows = [@command_window, @forge_window, @extract_window, @help_window,
  1125.       @materials_window, @status_window, @dummy_window, @gold_window, @enchant_window]
  1126.     # Create map sprite if configured to do so, and set window opacity
  1127.     if Blacksmith::MAP_BACK
  1128.       @spriteset = Spriteset_Map.new
  1129.       @windows.each {|window| window.opacity = 160 }
  1130.     end
  1131.     # Execute the transition and start the main loop.
  1132.     Graphics.transition
  1133.     loop {Graphics.update; Input.update; update; break if $scene != self }
  1134.     # Freeze the Graphics and dispose the windows
  1135.     Graphics.freeze
  1136.     @windows.each {|window| window.dispose }
  1137.     if Blacksmith::MAP_BACK && @spriteset != nil
  1138.       @spriteset.dispose
  1139.     end
  1140.   end
  1141.   #-----------------------------------------------------------------------------
  1142.   def update
  1143.     # Update the windows
  1144.     @windows.each {|window| window.update }
  1145.     # Branch method depending on current action.
  1146.     if @command_window.active
  1147.       update_command
  1148.     elsif @extract_window.active
  1149.       update_extract
  1150.     elsif @forge_window.active
  1151.       update_forge
  1152.     elsif @materials_window.active
  1153.       update_materials
  1154.     elsif @enchant_window.active
  1155.       update_enchant
  1156.     end
  1157.   end
  1158.   #-----------------------------------------------------------------------------
  1159.   def back_to_map
  1160.     # Play SE and return to the map.
  1161.     $game_system.se_play($data_system.cancel_se)
  1162.     $scene = Scene_Map.new
  1163.   end
  1164.   #-----------------------------------------------------------------------------
  1165.   def update_command
  1166.     @forge_window.index = 0
  1167.     @extract_window.index = 0
  1168.     # Set help text depending on the selected index.
  1169.     help_text = case @command_window.index
  1170.     when 0 then 'Use materials to forge new weapons, armors, and items.'
  1171.     when 1 then 'Extract materials from weapons, armors, and items.'
  1172.     when 2 then !@enchants ? 'Exit the shop.' :
  1173.       'Enchant weapons, armors, and items using other items.'
  1174.     when 3 then 'Exit the shop.'
  1175.     end
  1176.     @help_window.set_text(help_text)
  1177.     # Check for Input.
  1178.     if Input.trigger?(Input::B)
  1179.       back_to_map
  1180.     elsif Input.trigger?(Input::C)
  1181.       # Branch depending on command index
  1182.       case @command_window.index
  1183.       when 0
  1184.         # Play SE and return if option is locked.
  1185.         unless @level[0]
  1186.           $game_system.se_play($data_system.buzzer_se)
  1187.           return
  1188.         end
  1189.         $game_system.se_play($data_system.decision_se)
  1190.         # Shift scene to forge phase.
  1191.         @dummy_window.visible = false
  1192.         @forge_window.refresh(false)
  1193.         @command_window.active = false
  1194.         @forge_window.active = @forge_window.visible = true
  1195.         @status_window.item = @forge_window.item
  1196.         @status_window.visible = true
  1197.       when 1
  1198.         # Play SE and return if option is locked.
  1199.         unless @level[1]
  1200.           $game_system.se_play($data_system.buzzer_se)
  1201.           return
  1202.         end
  1203.         $game_system.se_play($data_system.decision_se)
  1204.         # Shift scene to extract phase
  1205.         @extract_window.refresh
  1206.         @command_window.active = @dummy_window.visible = false
  1207.         @extract_window.active = @extract_window.visible = true
  1208.         @status_window.item = @extract_window.item
  1209.         @status_window.visible = true
  1210.       when 2
  1211.         # Play SE and return if option is locked.
  1212.         if @enchants
  1213.           unless @level[2]
  1214.             $game_system.se_play($data_system.buzzer_se)
  1215.             return
  1216.           end
  1217.           $game_system.se_play($data_system.decision_se)
  1218.           # Shift scene to enchant phase.
  1219.           @forge_window.refresh(true)
  1220.           @command_window.active = @dummy_window.visible = false
  1221.           @forge_window.active = @forge_window.visible = true
  1222.           @status_window.item = @forge_window.item
  1223.           @status_window.visible = true
  1224.         else
  1225.           back_to_map
  1226.         end
  1227.       when 3
  1228.         back_to_map
  1229.       end
  1230.     end
  1231.   end
  1232.   #-----------------------------------------------------------------------------
  1233.   def update_forge
  1234.     # Update for input when forge window is active.
  1235.     @item = @status_window.item = @forge_window.item
  1236.     if Input.trigger?(Input::B)
  1237.       $game_system.se_play($data_system.cancel_se)
  1238.       @command_window.active = @dummy_window.visible = true
  1239.       @forge_window.active = @forge_window.visible = false
  1240.       @status_window.visible = false
  1241.     elsif Input.trigger?(Input::C)
  1242.       if @forge_window.item == nil
  1243.         $game_system.se_play($data_system.buzzer_se)
  1244.         return
  1245.       end
  1246.       $game_system.se_play($data_system.decision_se)
  1247.       @forge_window.active = @forge_window.visible = false
  1248.       if @command_window.index == 0
  1249.         @materials_window.refresh(@item, 0)
  1250.         @materials_window.visible = @materials_window.active = true
  1251.       else
  1252.         @enchant_window.refresh
  1253.         @enchant_window.visible = @enchant_window.active = true
  1254.       end
  1255.     end
  1256.   end
  1257.   #-----------------------------------------------------------------------------
  1258.   def update_extract
  1259.     # Update for input when extraction window is active.
  1260.     @item = @status_window.item = @extract_window.item
  1261.     if Input.trigger?(Input::B)
  1262.       $game_system.se_play($data_system.cancel_se)
  1263.       @command_window.active = @dummy_window.visible = true
  1264.       @extract_window.active = @extract_window.visible = false
  1265.       @status_window.visible = false
  1266.     elsif Input.trigger?(Input::C)
  1267.       if @extract_window.item == nil
  1268.         $game_system.se_play($data_system.buzzer_se)
  1269.         return
  1270.       end
  1271.       $game_system.se_play($data_system.decision_se)
  1272.       @materials_window.refresh(@item, 1)
  1273.       @extract_window.active = @extract_window.visible = false
  1274.       @materials_window.visible = @materials_window.active = true
  1275.     end
  1276.   end
  1277.   #-----------------------------------------------------------------------------
  1278.   def update_enchant
  1279.     # Update input on the enchantment items screen.
  1280.     if Input.trigger?(Input::B)
  1281.       # Return to previous screen if cancel button is pressed.
  1282.       $game_system.se_play($data_system.cancel_se)
  1283.       @enchant_window.visible = @enchant_window.active = false
  1284.       @forge_window.active = @forge_window.visible = true
  1285.     elsif Input.trigger?(Input::C)
  1286.       if @enchant_window.item == nil
  1287.         $game_system.se_play($data_system.buzzer_se)
  1288.         return
  1289.       end
  1290.       enchant_item if @confirm_proc.call
  1291.     end
  1292.   end
  1293.   #-----------------------------------------------------------------------------
  1294.   def enchant_item
  1295.     # Apply enchantment to weapon/armor using item
  1296.     $game_party.lose_item(@enchant_window.item.id, 1)
  1297.     Blacksmith.create_item(@forge_window.item, @enchant_window.item)
  1298.     # Play SE
  1299.     $game_system.se_play(RPG::AudioFile.new(*Blacksmith::ENCHANT_SE))
  1300.     # Refesh windows
  1301.     [@enchant_window, @status_window].each {|window| window.refresh }
  1302.     @forge_window.refresh(true)
  1303.     # Return to previous screen
  1304.     @enchant_window.visible = @enchant_window.active = false
  1305.     @forge_window.active = @forge_window.visible = true
  1306.   end
  1307.   #-----------------------------------------------------------------------------
  1308.   def update_materials
  1309.     # Show help text.
  1310.     text = 'Press the Action Button to proceed. Press Cancel to go back'
  1311.     @help_window.set_text(text)
  1312.     if Input.trigger?(Input::B)
  1313.       # Return to previous screen if cancel button is pressed.
  1314.       $game_system.se_play($data_system.cancel_se)
  1315.       @materials_window.visible = @materials_window.active = false
  1316.       if @command_window.index == 0
  1317.         @forge_window.active = @forge_window.visible = true
  1318.       else
  1319.         @extract_window.active = @extract_window.visible = true
  1320.       end
  1321.     elsif Input.trigger?(Input::C) && @confirm_proc.call
  1322.       @command_window.index == 0 ? forge_item : extract_item
  1323.     end
  1324.   end
  1325.   #-----------------------------------------------------------------------------
  1326.   def forge_item
  1327.     # Set local variables depending on item type.
  1328.     case @item
  1329.     when RPG::Weapon
  1330.       quantity, type = $game_party.weapon_number(@item.id), 0
  1331.       materials = Blacksmith.weapon_forges(@item.id)
  1332.       price = Blacksmith.weapon_gold(@item.id)[0]
  1333.     when RPG::Armor
  1334.       quantity, type = $game_party.armor_number(@item.id), 1
  1335.       materials = Blacksmith.armor_forges(@item.id)
  1336.       price = Blacksmith.armor_gold(@item.id)[0]
  1337.     when RPG::Item
  1338.       quantity, type = $game_party.item_number(@item.id), 2
  1339.       materials = Blacksmith.item_forges(@item.id)
  1340.       price = Blacksmith.item_gold(@item.id)[0]
  1341.     end
  1342.     # If player doesn't have the materials or gold, play SE and end method.
  1343.     unless Blacksmith.materials?(type, @item.id)
  1344.       $game_system.se_play($data_system.buzzer_se)
  1345.       return
  1346.     end
  1347.     # End method and play buzzer if inventory is full.
  1348.     return $game_system.se_play($data_system.buzzer_se) if quantity == 99
  1349.     # Play the defined SE used when forging.
  1350.     $game_system.se_play(RPG::AudioFile.new(*Blacksmith::FORGE_SE))
  1351.     # Remove required materials from inventory and subtract gold cost.
  1352.     if materials != nil
  1353.       materials.each {|material|
  1354.         case material[0]
  1355.         when 0 then $game_party.lose_weapon(material[1], material[2])
  1356.         when 1 then $game_party.lose_armor(material[1], material[2])
  1357.         when 2 then $game_party.lose_item(material[1], material[2])
  1358.         end
  1359.       }
  1360.     end
  1361.     $game_party.lose_gold(price)
  1362.     # Add forged item
  1363.     case @item
  1364.     when RPG::Weapon then $game_party.gain_weapon(@item.id, 1)
  1365.     when RPG::Armor then $game_party.gain_armor(@item.id, 1)
  1366.     when RPG::Item then $game_party.gain_item(@item.id, 1)
  1367.     end
  1368.     # Reset windows.
  1369.     @materials_window.visible = @materials_window.active = false
  1370.     @forge_window.active = @forge_window.visible = true
  1371.     # Refresh any windows that may have changed
  1372.     [@status_window, @gold_window, @extract_window, @forge_window,
  1373.       @enchant_window].each {|window| window.refresh }
  1374.   end
  1375.   #-----------------------------------------------------------------------------
  1376.   def extract_item
  1377.     # Set local variables depending on item type.
  1378.     case @item
  1379.     when RPG::Weapon
  1380.       quantity = $game_party.weapon_number(@item.id)
  1381.       materials = Blacksmith.weapon_extractions(@item.id)
  1382.       price = Blacksmith.weapon_gold(@item.id)[1]
  1383.     when RPG::Armor
  1384.       quantity = $game_party.armor_number(@item.id)
  1385.       materials = Blacksmith.armor_extractions(@item.id)
  1386.       price = Blacksmith.armor_gold(@item.id)[1]
  1387.     when RPG::Item
  1388.       quantity = $game_party.item_number(@item.id)
  1389.       materials = Blacksmith.item_extractions(@item.id)
  1390.       price = Blacksmith.item_gold(@item.id)[1]
  1391.     end
  1392.     # If nothing is defined for the extraction, return.
  1393.     if materials == nil || (materials.empty? && price == 0)
  1394.       return $game_system.se_play($data_system.buzzer_se)
  1395.     end
  1396.     # Play extraction SE
  1397.     $game_system.se_play(RPG::AudioFile.new(*Blacksmith::EXTRACT_SE))
  1398.     # Perform extraction, adding materials and increasing gold.
  1399.     materials.each {|material|
  1400.       case material[0]
  1401.       when 0 then $game_party.gain_weapon(material[1], material[2])
  1402.       when 1 then $game_party.gain_armor(material[1], material[2])
  1403.       when 2 then $game_party.gain_item(material[1], material[2])
  1404.       end
  1405.     }
  1406.     $game_party.gain_gold(price)
  1407.     # Remove extracted item from inventory
  1408.     case @item
  1409.     when RPG::Weapon then $game_party.lose_weapon(@item.id, 1)
  1410.     when RPG::Armor then $game_party.lose_armor(@item.id, 1)
  1411.     when RPG::Item then $game_party.lose_item(@item.id, 1)
  1412.     end
  1413.     # Reset windows.
  1414.     @materials_window.visible = @materials_window.active = false
  1415.     @extract_window.active = @extract_window.visible = true
  1416.     # Refresh any windows that may have changed
  1417.     [@status_window, @gold_window, @extract_window].each {|window| window.refresh }
  1418.   end
  1419. end
RAW Paste Data