SHARE
TWEET

[RMXP] Blacksmith System 2.0

ForeverZer0 May 21st, 2011 264 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.weapon_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 []
  229.     when 2 then []
  230.     when 3 then []
  231.     when 4 then []
  232.     when 5 then []
  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.     end
  599.   end
  600.   #-----------------------------------------------------------------------------
  601.   def draw_item(index)
  602.     item = @data[index]
  603.     # Set a few local variables depending on the type of item.
  604.     case item
  605.     when RPG::Weapon
  606.       quantity = $game_party.weapon_number(item.id)
  607.       price, type = Blacksmith.weapon_gold(item.id)[0], 0
  608.     when RPG::Armor
  609.       quantity = $game_party.armor_number(item.id)
  610.       price, type = Blacksmith.armor_gold(item.id)[0], 1
  611.     when RPG::Item
  612.       quantity = $game_party.item_number(item.id)
  613.       price, type = Blacksmith.item_gold(item.id)[0], 2
  614.     end
  615.     # Don't check material requirments for forging wjen enchanting
  616.     result = @enchanting ? true : Blacksmith.materials?(type, item.id)
  617.     # Determine the color to use for drawing the item name.
  618.     if quantity < 99 && result
  619.       self.contents.font.color = normal_color
  620.     else
  621.       self.contents.font.color = disabled_color
  622.     end
  623.     # Draw the item name, icon, and price.
  624.     x, y = 4, index * 32
  625.     rect = Rect.new(x, y, self.width - 32, 32)
  626.     self.contents.fill_rect(rect, Color.new(0, 0, 0, 0))
  627.     bitmap = RPG::Cache.icon(item.icon_name)
  628.     opacity = self.contents.font.color == normal_color ? 255 : 128
  629.     self.contents.blt(x, y + 4, bitmap, Rect.new(0, 0, 24, 24), opacity)
  630.     self.contents.draw_text(x + 28, y, 212, 32, item.name, 0)
  631.     if !@enchanting
  632.       self.contents.draw_text(x + 240, y, 88, 32, price.to_s, 2)
  633.     end
  634.   end
  635.   #-----------------------------------------------------------------------------
  636.   def update_help
  637.     @help_window.set_text(self.item == nil ? '' : self.item.description)
  638.   end
  639. end
  640.  
  641. #===============================================================================
  642. # ** Window_BlacksmithExtract
  643. #===============================================================================
  644.  
  645. class Window_BlacksmithExtract < Window_Selectable
  646.  
  647.   def initialize
  648.     super(0, 128, 368, 352)
  649.     self.active = self.visible = false
  650.     refresh
  651.     self.index = 0
  652.   end
  653.   #-----------------------------------------------------------------------------
  654.   def item
  655.     return @data[self.index]
  656.   end
  657.   #-----------------------------------------------------------------------------
  658.   def refresh
  659.     # Dispose current bitmap if defined.
  660.     if self.contents != nil
  661.       self.contents = self.contents.dispose
  662.     end
  663.     # Create list of items in inventory
  664.     @data = []
  665.     (1...$data_weapons.size).each {|i|
  666.       result = (Blacksmith.weapon_extractions(i) != nil ||
  667.         Blacksmith.weapon_gold(i)[1] != 0)
  668.       if $game_party.weapon_number(i) > 0 && result
  669.         @data.push($data_weapons[i])  
  670.       end
  671.     }
  672.     (1...$data_armors.size).each {|i|
  673.       result = (Blacksmith.armor_extractions(i) != nil ||
  674.         Blacksmith.armor_gold(i)[1] != 0)
  675.       if $game_party.armor_number(i) > 0 && result
  676.         @data.push($data_armors[i])  
  677.       end
  678.     }
  679.     (1...$data_items.size).each {|i|
  680.       result = (Blacksmith.item_extractions(i) != nil ||
  681.         Blacksmith.item_gold(i)[1] != 0)
  682.       if $game_party.item_number(i) > 0 && result
  683.         @data.push($data_items[i])
  684.       end
  685.     }
  686.     @item_max = @data.size
  687.     # Create a new bitmap that will contain the listed items
  688.     if @item_max > 0
  689.       self.contents = Bitmap.new(width - 32, row_max * 32)
  690.       (0...@item_max).each {|i| draw_item(i) }
  691.     end
  692.   end
  693.   #-----------------------------------------------------------------------------
  694.   def draw_item(index)
  695.     item = @data[index]
  696.     # Set a few local variables depending on the type of item.
  697.     quantity = case item
  698.     when RPG::Weapon then $game_party.weapon_number(item.id)
  699.     when RPG::Armor then $game_party.armor_number(item.id)
  700.     when RPG::Item then $game_party.item_number(item.id)
  701.     end
  702.     # Draw the name, icon, and quantity of the item.
  703.     x, y = 4, index * 32
  704.     rect = Rect.new(x, y, self.width / @column_max - 32, 32)
  705.     self.contents.fill_rect(rect, Color.new(0, 0, 0, 0))
  706.     bitmap = RPG::Cache.icon(item.icon_name)
  707.     self.contents.blt(x, y + 4, bitmap, Rect.new(0, 0, 24, 24), opacity)
  708.     self.contents.draw_text(x + 28, y, 212, 32, item.name, 0)
  709.   end
  710.   #-----------------------------------------------------------------------------
  711.   def update_help
  712.     @help_window.set_text(self.item == nil ? '' : self.item.description)
  713.   end
  714. end
  715.  
  716. #===============================================================================
  717. # ** Window_BlacksmithMaterials
  718. #===============================================================================
  719.  
  720. class Window_BlacksmithMaterials < Window_Base
  721.  
  722.   attr_accessor :active
  723.  
  724.   def initialize
  725.     # Initialize window size and coordinates.
  726.     super(0, 128, 368, 352)
  727.     self.visible = @active = false
  728.   end
  729.   #-----------------------------------------------------------------------------
  730.   def refresh(item, type = 0)
  731.     # Clear the bitmap and set the new materials.
  732.     if self.contents != nil
  733.       self.contents = self.contents.dispose
  734.     end
  735.     set_materials(item, type)
  736.     # Create a new bitmap, based off the amount of materials
  737.     if @materials != nil && @materials.size > 0
  738.       self.contents = Bitmap.new(self.width - 32, 64 + (@materials.size * 32))
  739.       # Draw each material and quantity required.
  740.       self.contents.font.color = system_color
  741.       word = type == 0 ? 'Cost' : ($data_system.words.gold + ':')
  742.       self.contents.draw_text(4, 0, 212, 32, word, 0)
  743.       text = type == 0 ? 'Required Materials:' : 'Extractable Materials:'
  744.       self.contents.draw_text(4, 32, 368, 32, text, 0)
  745.       self.contents.font.color = normal_color
  746.       self.contents.draw_text(244, 0, 88, 32, @price.to_s, 2)
  747.       # Enumerate through each material.
  748.       @materials.each_index {|i|
  749.         # Set local variable to current item, depending on type.
  750.         case @materials[i][0]
  751.         when 0
  752.           item = $data_weapons[@materials[i][1]]
  753.           enough = $game_party.weapon_number(item.id) >= @materials[i][2]
  754.         when 1
  755.           item = $data_armors[@materials[i][1]]
  756.           enough = $game_party.armor_number(item.id) >= @materials[i][2]
  757.         when 2
  758.           item = $data_items[@materials[i][1]]
  759.           enough = $game_party.item_number(item.id) >= @materials[i][2]
  760.         end
  761.         next if item == nil
  762.         # Set local variable to store required amount of this item.
  763.         required = @materials[i][2]
  764.         # Set color of text, draw grayed if out if forging and not enough.
  765.         self.contents.font.color = normal_color
  766.         if type == 0 && !enough
  767.           self.contents.font.color = disabled_color
  768.         end
  769.         # Set coordinates of current line.
  770.         x, y = 4, 64 + (i * 32)
  771.         # Draw item name, icon, and required amount.
  772.         rect = Rect.new(x, y, self.width - 32, 32)
  773.         self.contents.fill_rect(rect, Color.new(0, 0, 0, 0))
  774.         bitmap = RPG::Cache.icon(item.icon_name)
  775.         opacity = self.contents.font.color == normal_color ? 255 : 128
  776.         self.contents.blt(x, y + 4, bitmap, Rect.new(0, 0, 24, 24), opacity)
  777.         self.contents.draw_text(x + 28, y, 212, 32, item.name)
  778.         self.contents.draw_text(x + 272, y, 48, 32, 'x', 0)
  779.         self.contents.draw_text(x + 272, y, 48, 32, required.to_s, 2)
  780.       }
  781.     elsif @price > 0
  782.       self.contents = Bitmap.new(self.width - 32, 64)
  783.       self.contents.font.color = system_color
  784.       self.contents.draw_text(4, 0, 212, 32, $data_system.words.gold + ':')
  785.       self.contents.font.color = normal_color
  786.       self.contents.draw_text(244, 0, 88, 32, @price.to_s, 2)
  787.       self.contents.draw_text(4, 32, 368, 32, 'No Materials')
  788.     end
  789.   end
  790.   #-----------------------------------------------------------------------------
  791.   def set_materials(item, type)
  792.     # Sets the required/extractable items for the passed item.
  793.     id = item.id
  794.     if item.is_a?(RPG::Weapon)
  795.       @materials = type == 0 ? Blacksmith.weapon_forges(id) :
  796.         Blacksmith.weapon_extractions(id)
  797.       @price = Blacksmith.weapon_gold(id)[type]
  798.     elsif item.is_a?(RPG::Armor)
  799.       @materials = type == 0 ? Blacksmith.armor_forges(id) :
  800.         Blacksmith.armor_extractions(id)
  801.       @price = Blacksmith.armor_gold(id)[type]
  802.     else
  803.       if @materials != 2
  804.         @materials = type == 0 ? Blacksmith.item_forges(id) :
  805.           Blacksmith.item_extractions(id)
  806.         @price = Blacksmith.item_gold(id)[type]
  807.       end
  808.     end
  809.   end
  810.   #-----------------------------------------------------------------------------
  811.   def update
  812.     # Allow scrolling of bitmap if materials don't fit in window.
  813.     if @active && self.contents != nil && self.contents.height > 320
  814.       if Input.trigger?(Input::UP)
  815.         if self.oy > 0
  816.           self.oy -= 32
  817.           $game_system.se_play($data_system.cursor_se)
  818.         end
  819.       elsif Input.trigger?(Input::DOWN)
  820.         if (self.oy + 320) < self.contents.height
  821.           self.oy += 32
  822.           $game_system.se_play($data_system.cursor_se)
  823.         end
  824.       end
  825.     end
  826.   end
  827. end
  828.  
  829. #===============================================================================
  830. # ** Window_BlacksmithStatus
  831. #===============================================================================
  832.  
  833. class Window_BlacksmithStatus < Window_Base
  834.  
  835.   def initialize
  836.     super(368, 128, 272, 352)
  837.     self.contents = Bitmap.new(width - 32, height - 32)
  838.     # Create array of sprites same size as party
  839.     @sprites = [Sprite.new, Sprite.new, Sprite.new, Sprite.new]
  840.     #@sprites = Array.new($game_party.actors.size, Sprite.new)
  841.     # Set coordinates of each sprite
  842.     @sprites.each_index {|i|
  843.       @sprites[i].x, @sprites[i].y = 380, 194 + (i * 64)#(i * 34)
  844.       @sprites[i].z = self.z + 10
  845.     }
  846.     self.visible = false
  847.     # Array of flags for walking
  848.     @walk = Array.new($game_party.actors.size, false)
  849.     @count, @item = 0, nil
  850.     refresh
  851.   end
  852.   #-----------------------------------------------------------------------------
  853.   def refresh
  854.     # Clear bitmap and turn off visiblity of each sprite.
  855.     self.contents.clear
  856.     @sprites.each {|sprite| sprite.visible = false }
  857.     # Return if selected item index is undefined.
  858.     return if @item == nil
  859.     self.contents.font.size = Font.default_size + 2
  860.     quantity = case @item
  861.     when RPG::Item then $game_party.item_number(@item.id)
  862.     when RPG::Weapon then $game_party.weapon_number(@item.id)
  863.     when RPG::Armor then $game_party.armor_number(@item.id)
  864.     end
  865.     self.contents.font.color = system_color
  866.     self.contents.draw_text(4, 0, 200, 32, 'Possessed:')
  867.     self.contents.font.color = normal_color
  868.     self.contents.draw_text(204, 0, 32, 32, quantity.to_s, 2)
  869.     # Disable walking animation and end method if selected item is a normal item
  870.     if @item.is_a?(RPG::Item)
  871.       @walk.collect! {|value| false }
  872.       return
  873.     end
  874.     # Change the font size.
  875.     self.contents.font.size = Font.default_size - 1
  876.     # Iterate each actor...
  877.     $game_party.actors.each_index {|i|
  878.       chr = $game_party.actors[i]
  879.       # Set local variable to highlighted piece of equipment.
  880.       if @item.is_a?(RPG::Weapon)
  881.         eqp = $data_weapons[chr.weapon_id]
  882.       else
  883.         armors = [chr.armor1_id, chr.armor2_id, chr.armor3_id, chr.armor4_id]
  884.         eqp = $data_armors[armors[@item.kind]]
  885.       end
  886.       # Draw the actor sprite.
  887.       draw_actor_graphic(i, chr.equippable?(@item))
  888.       # Draw message and return if unequippable.
  889.       unless chr.equippable?(@item)
  890.         self.contents.font.color = normal_color
  891.         self.contents.draw_text(32, 54 + (i * 64), 150, 32, 'Cannot Equip')
  892.         next
  893.       else
  894.         # Create array of stat changes.
  895.         # [str, dex, agi, int, pdef, mdef, (atk || eva)]
  896.         stats = [
  897.           (@item == nil ? 0 : @item.str_plus) - (eqp == nil ? 0 : eqp.str_plus),
  898.           (@item == nil ? 0 : @item.dex_plus) - (eqp == nil ? 0 : eqp.dex_plus),
  899.           (@item == nil ? 0 : @item.agi_plus) - (eqp == nil ? 0 : eqp.agi_plus),
  900.           (@item == nil ? 0 : @item.int_plus) - (eqp == nil ? 0 : eqp.int_plus),
  901.           (@item == nil ? 0 : @item.pdef) - (eqp == nil ? 0 : eqp.pdef),
  902.           (@item == nil ? 0 : @item.mdef) - (eqp == nil ? 0 : eqp.mdef)
  903.         ]
  904.         if @item.is_a?(RPG::Weapon)
  905.           stats.push(
  906.             (@item == nil ? 0 : @item.atk) - (eqp == nil ? 0 : eqp.atk))
  907.         elsif @item.is_a?(RPG::Armor)
  908.           stats.push(
  909.             (@item == nil ? 0 : @item.eva) - (eqp == nil ? 0 : eqp.eva))
  910.         end
  911.         # Set local variable to each piece of equipments' name
  912.         current_name = eqp == nil ? '' : eqp.name
  913.         new_name = @item == nil ? '' : @item.name
  914.         # If stats are all equal, show message and end method.
  915.         if stats.all? {|stat| stat == 0 }
  916.           self.contents.font.color = normal_color
  917.           if current_name != new_name
  918.             self.contents.draw_text(32, 54 + (i * 64), 150, 32, 'No Change')
  919.           else
  920.             self.contents.draw_text(32, 54 + (i * 64), 150, 32, 'Equipped')
  921.           end
  922.           next
  923.         end
  924.         # Draw any stat changes, using colors to show plus/minus changes
  925.         self.contents.font.size = (Font.default_size - 1)
  926.         self.contents.font.color = normal_color
  927.         self.contents.draw_text(104, 42 + (64*i), 32, 32, 'STR ') if stats[0] != 0
  928.         self.contents.draw_text(104, 58 + (64*i), 32, 32, 'DEX ') if stats[1] != 0
  929.         self.contents.draw_text(104, 74 + (64*i), 32, 32, 'AGI ') if stats[2] != 0
  930.         self.contents.draw_text(176, 42 + (64*i), 32, 32, 'INT ') if stats[3] != 0
  931.         self.contents.draw_text(32, 58 + (64*i), 32, 32, 'PDF ') if stats[4] != 0
  932.         self.contents.draw_text(32, 74 + (64*i), 32, 32, 'MDF ') if stats[5] != 0
  933.         if stats[-1] != 0
  934.           # Show stats changes for atk/eva, depending on the equipment type
  935.           stat = @item.is_a?(RPG::Weapon) ? 'ATK ' : 'EVA '
  936.           self.contents.draw_text(32, 42 + (64 * i), 32, 32, stat) if stat != 0
  937.         end
  938.         # Show any stat changes
  939.         stats.each_index {|j|
  940.           next if stats[j] == 0
  941.           xy = case j
  942.           when 0 then [132, 42 + (64 * i)]
  943.           when 1 then [132, 58 + (64 * i)]
  944.           when 2 then [132, 74 + (64 * i)]
  945.           when 3 then [198, 42 + (64 * i)]
  946.           when 4 then [60, 58 + (64 * i)]
  947.           when 5 then [60, 74 + (64 * i)]
  948.           when 6 then [60, 42 + (64 * i)]
  949.           end
  950.           # Set color and operator depending on value
  951.           if stats[j] < 0
  952.             self.contents.font.color, sign = Blacksmith::MINUS_COLOR, '-'
  953.           else
  954.             self.contents.font.color, sign = Blacksmith::PLUS_COLOR, '+'
  955.           end
  956.           self.contents.draw_text(xy[0], xy[1], 8, 32, sign, 1)
  957.           self.contents.draw_text(xy[0] + 10, xy[1], 24, 32, stats[j].abs.to_s)
  958.         }
  959.       end
  960.     }
  961.   end
  962.   #-----------------------------------------------------------------------------
  963.   def item=(item)
  964.     if @item != item
  965.       # Change the item variable and refresh.
  966.       @item = item
  967.       refresh
  968.     end
  969.   end
  970.   #-----------------------------------------------------------------------------
  971.   def draw_actor_graphic(id, equipable)
  972.     # Draws the actor graphic
  973.     actor = $game_party.actors[id]
  974.     @sprites[id].bitmap = RPG::Cache.character(actor.character_name,
  975.       actor.character_hue)
  976.     @sprites[id].src_rect.set(0, 0, @sprites[id].bitmap.width / 4,
  977.     @sprites[id].bitmap.height / 4)
  978.     # Set walking animation if item is equippable.
  979.     @walk[id] = equipable
  980.     @sprites[id].tone = Tone.new(0, 0, 0, equipable ? 0 : 255)
  981.     @sprites[id].visible = true
  982.   end
  983.   #-----------------------------------------------------------------------------
  984.   def update
  985.     super
  986.     # Update the walking animation.
  987.     @count = (@count + 1) % 40
  988.     $game_party.actors.each_index {|i|
  989.       next unless @walk[i]
  990.       if @sprites[i].bitmap != nil
  991.         w = @sprites[i].bitmap.width / 4
  992.         h = @sprites[i].bitmap.height / 4
  993.         x = (@count / 10) * w
  994.         @sprites[i].src_rect.set(x, 0, w, h)
  995.       end
  996.     }
  997.   end
  998.   #-----------------------------------------------------------------------------
  999.   def visible=(bool)
  1000.     super
  1001.     # Set visible to the actor sprites as well.
  1002.     @sprites.each {|sprite| sprite.visible = bool }
  1003.   end
  1004.   #-----------------------------------------------------------------------------
  1005.   def dispose
  1006.     super
  1007.     # Dispose the actor sprites as well.
  1008.     @sprites.each {|sprite| sprite.dispose }
  1009.   end
  1010. end
  1011.  
  1012.  
  1013. #===============================================================================
  1014. # ** Window_BlacksmithExtract
  1015. #===============================================================================
  1016.  
  1017. class Window_BlacksmithEnchant < Window_Selectable
  1018.  
  1019.   def initialize
  1020.     super(0, 128, 368, 352)
  1021.     self.active = self.visible = false
  1022.     refresh
  1023.     self.index = 0
  1024.   end
  1025.   #-----------------------------------------------------------------------------
  1026.   def item
  1027.     return @data[self.index]
  1028.   end
  1029.   #-----------------------------------------------------------------------------
  1030.   def refresh
  1031.     # Dispose current bitmap if defined.
  1032.     if self.contents != nil
  1033.       self.contents = self.contents.dispose
  1034.     end
  1035.     # Create list of items in inventory
  1036.     @data = []
  1037.     ($data_items - [nil]).each {|item|
  1038.       result = false
  1039.       result = true if Blacksmith.enchant_stats(item.id) != nil
  1040.       result = true if Blacksmith.enchant_states(item.id) != nil
  1041.       result = true if Blacksmith.enchant_elements(item.id) != nil
  1042.       @data.push(item) if result
  1043.     }
  1044.     @item_max = @data.size
  1045.     # Create a new bitmap that will contain the listed items
  1046.     if @item_max > 0
  1047.       self.contents = Bitmap.new(width - 32, row_max * 32)
  1048.       (0...@item_max).each {|i| draw_item(i) }
  1049.     end
  1050.   end
  1051.   #-----------------------------------------------------------------------------
  1052.   def draw_item(index)
  1053.     item = @data[index]
  1054.     # Set a few local variables depending on the type of item.
  1055.     quantity = $game_party.item_number(item.id)
  1056.     # Draw the name, icon, and quantity of the item.
  1057.     x, y = 4, index * 32
  1058.     rect = Rect.new(x, y, self.width / @column_max - 32, 32)
  1059.     self.contents.fill_rect(rect, Color.new(0, 0, 0, 0))
  1060.     bitmap = RPG::Cache.icon(item.icon_name)
  1061.     self.contents.blt(x, y + 4, bitmap, Rect.new(0, 0, 24, 24))
  1062.     self.contents.draw_text(x + 28, y, 212, 32, item.name, 0)
  1063.     self.contents.draw_text(x + 240, y, 16, 32, ':', 1)
  1064.     self.contents.draw_text(x + 256, y, 24, 32, quantity.to_s, 2)
  1065.   end
  1066.   #-----------------------------------------------------------------------------
  1067.   def update_help
  1068.     @help_window.set_text(self.item == nil ? '' : self.item.description)
  1069.   end
  1070. end
  1071.  
  1072. #===============================================================================
  1073. # ** Scene_Blacksmith
  1074. #===============================================================================
  1075.  
  1076. class Scene_Blacksmith
  1077.  
  1078.   def initialize(weapons = [], armors = [], items = [], level = nil)
  1079.     # Set available goods for this shop based off passed argument.
  1080.     @goods = []
  1081.     @goods += weapons.collect {|id| $data_weapons[id] }
  1082.     @goods += armors.collect {|id| $data_armors[id] }
  1083.     @goods += items.collect {|id| $data_items[id] }
  1084.     @goods.uniq!
  1085.     # Configure the level variable
  1086.     @level = (level == nil) ? Array.new(4, true) : (level + [true])
  1087.     @enchants = Blacksmith::USE_ENCHANTMENTS
  1088.   end
  1089.   #-----------------------------------------------------------------------------
  1090.   def main
  1091.     # Create a Proc to handle confirmation of choices
  1092.     @confirm_proc = Proc.new {
  1093.       @help_window.set_text('Are you sure?')
  1094.       window = Window_Command.new(160, ['Confirm', 'Cancel'])
  1095.       window.x, window.y, window.z = 224, 192, 9999
  1096.       loop { Graphics.update; Input.update; window.update
  1097.         if Input.trigger?(Input::C) || Input.trigger?(Input::B)
  1098.           result = (Input.trigger?(Input::C) && window.index == 0)
  1099.           $game_system.se_play($data_system.cancel_se) unless result
  1100.           window.dispose
  1101.           break(result)
  1102.         end
  1103.       }
  1104.     }
  1105.     # Initialize the needed windows.
  1106.     @command_window = Window_BlacksmithCommand.new(@level)
  1107.     @forge_window = Window_BlacksmithForge.new(@goods)
  1108.     @extract_window = Window_BlacksmithExtract.new
  1109.     @materials_window = Window_BlacksmithMaterials.new
  1110.     @enchant_window = Window_BlacksmithEnchant.new
  1111.     @status_window = Window_BlacksmithStatus.new
  1112.     @dummy_window = Window_Base.new(0, 128, 640, 352)
  1113.     @gold_window = Window_Gold.new
  1114.     @gold_window.x, @gold_window.y = 480, 64  
  1115.     @help_window = Window_Help.new
  1116.     # Bind the help window to the other windows.
  1117.     @forge_window.help_window = @extract_window.help_window = @help_window
  1118.     @enchant_window.help_window = @help_window
  1119.     # Set a windows array for easier handling of all windows.
  1120.     @windows = [@command_window, @forge_window, @extract_window, @help_window,
  1121.       @materials_window, @status_window, @dummy_window, @gold_window, @enchant_window]
  1122.     # Create map sprite if configured to do so, and set window opacity
  1123.     if Blacksmith::MAP_BACK
  1124.       @spriteset = Spriteset_Map.new
  1125.       @windows.each {|window| window.opacity = 160 }
  1126.     end
  1127.     # Execute the transition and start the main loop.
  1128.     Graphics.transition
  1129.     loop {Graphics.update; Input.update; update; break if $scene != self }
  1130.     # Freeze the Graphics and dispose the windows
  1131.     Graphics.freeze
  1132.     @windows.each {|window| window.dispose }
  1133.     if Blacksmith::MAP_BACK && @spriteset != nil
  1134.       @spriteset.dispose
  1135.     end
  1136.   end
  1137.   #-----------------------------------------------------------------------------
  1138.   def update
  1139.     # Update the windows
  1140.     @windows.each {|window| window.update }
  1141.     # Branch method depending on current action.
  1142.     if @command_window.active
  1143.       update_command
  1144.     elsif @extract_window.active
  1145.       update_extract
  1146.     elsif @forge_window.active
  1147.       update_forge
  1148.     elsif @materials_window.active
  1149.       update_materials
  1150.     elsif @enchant_window.active
  1151.       update_enchant
  1152.     end
  1153.   end
  1154.   #-----------------------------------------------------------------------------
  1155.   def back_to_map
  1156.     # Play SE and return to the map.
  1157.     $game_system.se_play($data_system.cancel_se)
  1158.     $scene = Scene_Map.new
  1159.   end
  1160.   #-----------------------------------------------------------------------------
  1161.   def update_command
  1162.     # Set help text depending on the selected index.
  1163.     help_text = case @command_window.index
  1164.     when 0 then 'Use materials to forge new weapons, armors, and items.'
  1165.     when 1 then 'Extract materials from weapons, armors, and items.'
  1166.     when 2 then !@enchants ? 'Exit the shop.' :
  1167.       'Enchant weapons, armors, and items using other items.'
  1168.     when 3 then 'Exit the shop.'
  1169.     end
  1170.     @help_window.set_text(help_text)
  1171.     # Check for Input.
  1172.     if Input.trigger?(Input::B)
  1173.       back_to_map
  1174.     elsif Input.trigger?(Input::C)
  1175.       $game_system.se_play($data_system.decision_se)
  1176.       # Branch depending on command index
  1177.       case @command_window.index
  1178.       when 0
  1179.         # Play SE and return if option is locked.
  1180.         unless @level[0]
  1181.           $game_system.se_play($data_system.buzzer_se)
  1182.           return
  1183.         end
  1184.         # Shift scene to forge phase.
  1185.         @dummy_window.visible = false
  1186.         @forge_window.refresh(false)
  1187.         @command_window.active = false
  1188.         @forge_window.active = @forge_window.visible = true
  1189.         @status_window.visible = true
  1190.       when 1
  1191.         # Play SE and return if option is locked.
  1192.         unless @level[1]
  1193.           $game_system.se_play($data_system.buzzer_se)
  1194.           return
  1195.         end
  1196.         # Shift scene to extract phase
  1197.         @extract_window.refresh
  1198.         @command_window.active = @dummy_window.visible = false
  1199.         @extract_window.active = @extract_window.visible = true
  1200.         @status_window.visible = true
  1201.       when 2
  1202.         # Play SE and return if option is locked.
  1203.         if @enchants
  1204.           unless @level[2]
  1205.             $game_system.se_play($data_system.buzzer_se)
  1206.             return
  1207.           end
  1208.           # Shift scene to enchant phase.
  1209.           @forge_window.refresh(true)
  1210.           @command_window.active = @dummy_window.visible = false
  1211.           @forge_window.active = @forge_window.visible = true
  1212.           @status_window.visible = true
  1213.         else
  1214.           back_to_map
  1215.         end
  1216.       when 3
  1217.         back_to_map
  1218.       end
  1219.     end
  1220.   end
  1221.   #-----------------------------------------------------------------------------
  1222.   def update_forge
  1223.     # Update for input when forge window is active.
  1224.     @item = @status_window.item = @forge_window.item
  1225.     if Input.trigger?(Input::B)
  1226.       $game_system.se_play($data_system.cancel_se)
  1227.       @command_window.active = @dummy_window.visible = true
  1228.       @forge_window.active = @forge_window.visible = false
  1229.       @status_window.visible = false
  1230.     elsif Input.trigger?(Input::C)
  1231.       $game_system.se_play($data_system.decision_se)
  1232.       @forge_window.active = @forge_window.visible = false
  1233.       if @command_window.index == 0
  1234.         @materials_window.refresh(@item, 0)
  1235.         @materials_window.visible = @materials_window.active = true
  1236.       else
  1237.         @enchant_window.refresh
  1238.         @enchant_window.visible = @enchant_window.active = true
  1239.       end
  1240.     end
  1241.   end
  1242.   #-----------------------------------------------------------------------------
  1243.   def update_extract
  1244.     # Update for input when extraction window is active.
  1245.     @item = @status_window.item = @extract_window.item
  1246.     if Input.trigger?(Input::B)
  1247.       $game_system.se_play($data_system.cancel_se)
  1248.       @command_window.active = @dummy_window.visible = true
  1249.       @extract_window.active = @extract_window.visible = false
  1250.       @status_window.visible = false
  1251.     elsif Input.trigger?(Input::C)
  1252.       $game_system.se_play($data_system.decision_se)
  1253.       @materials_window.refresh(@item, 1)
  1254.       @extract_window.active = @extract_window.visible = false
  1255.       @materials_window.visible = @materials_window.active = true
  1256.     end
  1257.   end
  1258.   #-----------------------------------------------------------------------------
  1259.   def update_enchant
  1260.     # Update input on the enchantment items screen.
  1261.     if Input.trigger?(Input::B)
  1262.       # Return to previous screen if cancel button is pressed.
  1263.       $game_system.se_play($data_system.cancel_se)
  1264.       @enchant_window.visible = @enchant_window.active = false
  1265.       @forge_window.active = @forge_window.visible = true
  1266.     elsif Input.trigger?(Input::C) && @confirm_proc.call
  1267.       enchant_item
  1268.     end
  1269.   end
  1270.   #-----------------------------------------------------------------------------
  1271.   def enchant_item
  1272.     # Apply enchantment to weapon/armor using item
  1273.     $game_party.lose_item(@enchant_window.item.id, 1)
  1274.     Blacksmith.create_item(@forge_window.item, @enchant_window.item)
  1275.     # Play SE
  1276.     $game_system.se_play(RPG::AudioFile.new(*Blacksmith::ENCHANT_SE))
  1277.     # Refesh windows
  1278.     [@enchant_window, @status_window].each {|window| window.refresh }
  1279.     @forge_window.refresh(true)
  1280.     # Return to previous screen
  1281.     @enchant_window.visible = @enchant_window.active = false
  1282.     @forge_window.active = @forge_window.visible = true
  1283.   end
  1284.   #-----------------------------------------------------------------------------
  1285.   def update_materials
  1286.     # Show help text.
  1287.     text = 'Press the Action Button to proceed. Press Cancel to go back'
  1288.     @help_window.set_text(text)
  1289.     if Input.trigger?(Input::B)
  1290.       # Return to previous screen if cancel button is pressed.
  1291.       $game_system.se_play($data_system.cancel_se)
  1292.       @materials_window.visible = @materials_window.active = false
  1293.       if @command_window.index == 0
  1294.         @forge_window.active = @forge_window.visible = true
  1295.       else
  1296.         @extract_window.active = @extract_window.visible = true
  1297.       end
  1298.     elsif Input.trigger?(Input::C) && @confirm_proc.call
  1299.       @command_window.index == 0 ? forge_item : extract_item
  1300.     end
  1301.   end
  1302.   #-----------------------------------------------------------------------------
  1303.   def forge_item
  1304.     # Set local variables depending on item type.
  1305.     case @item
  1306.     when RPG::Weapon
  1307.       quantity, type = $game_party.weapon_number(@item.id), 0
  1308.       materials = Blacksmith.weapon_forges(@item.id)
  1309.       price = Blacksmith.weapon_gold(@item.id)[0]
  1310.     when RPG::Armor
  1311.       quantity, type = $game_party.armor_number(@item.id), 1
  1312.       materials = Blacksmith.armor_forges(@item.id)
  1313.       price = Blacksmith.armor_gold(@item.id)[0]
  1314.     when RPG::Item
  1315.       quantity, type = $game_party.item_number(@item.id), 2
  1316.       materials = Blacksmith.item_forges(@item.id)
  1317.       price = Blacksmith.item_gold(@item.id)[0]
  1318.     end
  1319.     # If player doesn't have the materials or gold, play SE and end method.
  1320.     unless Blacksmith.materials?(type, @item.id)
  1321.       $game_system.se_play($data_system.buzzer_se)
  1322.       return
  1323.     end
  1324.     # End method and play buzzer if inventory is full.
  1325.     return $game_system.se_play($data_system.buzzer_se) if quantity == 99
  1326.     # Play the defined SE used when forging.
  1327.     $game_system.se_play(RPG::AudioFile.new(*Blacksmith::FORGE_SE))
  1328.     # Remove required materials from inventory and subtract gold cost.
  1329.     if materials != nil
  1330.       materials.each {|material|
  1331.         case material[0]
  1332.         when 0 then $game_party.lose_weapon(material[1], material[2])
  1333.         when 1 then $game_party.lose_armor(material[1], material[2])
  1334.         when 2 then $game_party.lose_item(material[1], material[2])
  1335.         end
  1336.       }
  1337.     end
  1338.     $game_party.lose_gold(price)
  1339.     # Add forged item
  1340.     case @item
  1341.     when RPG::Weapon then $game_party.gain_weapon(@item.id, 1)
  1342.     when RPG::Armor then $game_party.gain_armor(@item.id, 1)
  1343.     when RPG::Item then $game_party.gain_item(@item.id, 1)
  1344.     end
  1345.     # Reset windows.
  1346.     @materials_window.visible = @materials_window.active = false
  1347.     @forge_window.active = @forge_window.visible = true
  1348.     # Refresh any windows that may have changed
  1349.     [@status_window, @gold_window, @extract_window, @forge_window,
  1350.       @enchant_window].each {|window| window.refresh }
  1351.   end
  1352.   #-----------------------------------------------------------------------------
  1353.   def extract_item
  1354.     # Set local variables depending on item type.
  1355.     case @item
  1356.     when RPG::Weapon
  1357.       quantity = $game_party.weapon_number(@item.id)
  1358.       materials = Blacksmith.weapon_extractions(@item.id)
  1359.       price = Blacksmith.weapon_gold(@item.id)[1]
  1360.     when RPG::Armor
  1361.       quantity = $game_party.armor_number(@item.id)
  1362.       materials = Blacksmith.armor_extractions(@item.id)
  1363.       price = Blacksmith.armor_gold(@item.id)[1]
  1364.     when RPG::Item
  1365.       quantity = $game_party.item_number(@item.id)
  1366.       materials = Blacksmith.item_extractions(@item.id)
  1367.       price = Blacksmith.item_gold(@item.id)[1]
  1368.     end
  1369.     # If nothing is defined for the extraction, return.
  1370.     if materials == nil || (materials.empty? && price == 0)
  1371.       return $game_system.se_play($data_system.buzzer_se)
  1372.     end
  1373.     # Play extraction SE
  1374.     $game_system.se_play(RPG::AudioFile.new(*Blacksmith::EXTRACT_SE))
  1375.     # Perform extraction, adding materials and increasing gold.
  1376.     materials.each {|material|
  1377.       case material[0]
  1378.       when 0 then $game_party.gain_weapon(material[1], material[2])
  1379.       when 1 then $game_party.gain_armor(material[1], material[2])
  1380.       when 2 then $game_party.gain_item(material[1], material[2])
  1381.       end
  1382.     }
  1383.     $game_party.gain_gold(price)
  1384.     # Remove extracted item from inventory
  1385.     case @item
  1386.     when RPG::Weapon then $game_party.lose_weapon(@item.id, 1)
  1387.     when RPG::Armor then $game_party.lose_armor(@item.id, 1)
  1388.     when RPG::Item then $game_party.lose_item(@item.id, 1)
  1389.     end
  1390.     # Reset windows.
  1391.     @materials_window.visible = @materials_window.active = false
  1392.     @extract_window.active = @extract_window.visible = true
  1393.     # Refresh any windows that may have changed
  1394.     [@status_window, @gold_window, @extract_window].each {|window| window.refresh }
  1395.   end
  1396. end
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
Not a member of Pastebin yet?
Sign Up, it unlocks many cool features!
 
Top