Advertisement
mrbubble

Dismantle Items

Jul 21st, 2012
169
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Ruby 49.00 KB | None | 0 0
  1. #==============================================================================
  2. # ++ Dismantle Items ++                                         v1.1 (7/21/12)
  3. #==============================================================================
  4. # Script by:
  5. #     Mr. Bubble ( http://mrbubblewand.wordpress.com/ )
  6. #--------------------------------------------------------------------------
  7. # This script is based off the Dismantling mechanic from Final Fantasy 13.
  8. # However, copying that exact system isn't very fun so I added a few
  9. # extra optional features. You can also define the chance for items to
  10. # be dismantled from the original item. Item dismantle information can
  11. # also be masked until the player dismantles the item.
  12. #
  13. # My motivation for making this script comes from wanting to learn how
  14. # windows interact with each other in VXA scenes. While the process of
  15. # making this script took much longer than I wanted, it was very much
  16. # worth it.
  17. #--------------------------------------------------------------------------
  18. #   ++ Changelog ++
  19. #--------------------------------------------------------------------------
  20. # v1.1 : DISMANTLABLE_ITEMS_MASK_ICON_ID now works. (7/21/2012)
  21. # v1.0 : Initial release. (7/21/2012)
  22. #--------------------------------------------------------------------------
  23. #   ++ Installation ++
  24. #--------------------------------------------------------------------------
  25. # Install this script in the Materials section in your project's
  26. # script editor.
  27. #==============================================================================
  28. #   ++ Dismantle Notetags ++
  29. #==============================================================================
  30. # Note: Some tags are given shorter tags for typing convenience. You only
  31. #       need to use one <tag> from a given group for a notebox.
  32. #       Use common sense.
  33. #
  34. # The following Notetags are for Items, Weapons, and Armors only:
  35. #
  36. # <dismantle>
  37. # setting
  38. # setting
  39. # </dismantle>
  40. #   This tag allows you define custom dismantle settings. You can add as many
  41. #   settings between the <dismantle> tags as you like. Only items with this tag
  42. #   will appear in the Dismantle Shop. Any settings you do not include will
  43. #   use the default values defined in the customization module if there are
  44. #   any. The following settings are available:
  45. #  
  46. #     item: id
  47. #     item: id, chance%
  48. #     i: id
  49. #     i: id, chance%
  50. #       This setting defines the item that is dismantled from the original
  51. #       item, armor, or weapon where id is the Item ID number found in
  52. #       your database. Chance is a value between 0.0 and 100.0. If chance
  53. #       is omitted, it will use the default chance value defined in the
  54. #       customization module. This setting can be used multiple times
  55. #       within the tags.
  56. #  
  57. #     weapon: id
  58. #     weapon: id, chance%
  59. #     w: id
  60. #     w: id, chance%
  61. #       This setting defines the weapon that is dismantled from the original
  62. #       item, armor, or weapon where id is the Weapon ID number found in
  63. #       your database. Chance is a value between 0.0 and 100.0. If chance
  64. #       is omitted, it will use the default chance value defined in the
  65. #       customization module. This setting can be used multiple times
  66. #       within the tags.
  67. #  
  68. #     armor: id
  69. #     armor: id, chance%
  70. #     armour: id
  71. #     armour: id, chance%
  72. #     a: id
  73. #     a: id, chance%
  74. #       This setting defines the armor that is dismantled from the original
  75. #       item, armor, or weapon where id is the Armor ID number found in
  76. #       your database. Chance is a value between 0.0 and 100.0. If chance
  77. #       is omitted, it will use the default chance value defined in the
  78. #       customization module. This setting can be used multiple times
  79. #       within the tags.
  80. #  
  81. #     fee: amount
  82. #       This setting defines the amount of Gold required to dismantle the
  83. #       item, armor, or weapon where amount is any amount of gold. If this
  84. #       setting is omitted, it will use the default fee defined in the
  85. #       customization module.
  86. #  
  87. # Here are some examples of proper <dismantle> tags:
  88. #
  89. #     <dismantle>
  90. #     item: 18
  91. #     item: 19
  92. #     item: 17
  93. #     fee: 1000
  94. #     </dismantle>
  95. #
  96. # In this example, each item setting has omitted the chance value.
  97. # This means that it will use the default chance value defined in
  98. # the customization module.
  99. #
  100. #     <dismantle>
  101. #     i: 18
  102. #     i: 18
  103. #     i: 18, 25%
  104. #     w: 4, 30%
  105. #     a: 5, 5%
  106. #     </dismantle>
  107. #
  108. # In this example, each line uses the short-hand version of a setting.
  109. # The dismantle chance values are included for some settings, but not
  110. # all.  The “fee” setting is omitted meaning it will use the default
  111. # fee value defined in the customization module.
  112. #==============================================================================
  113. #   ++ Dismantle Script Calls ++
  114. #==============================================================================
  115. # The following Script Calls are meant to be used in "Script..." event
  116. # commands found under Tab 3 when creating a new event.
  117. #
  118. # open_dismantle_shop
  119. #   This script call opens up a Dismantle Shop scene.
  120. #
  121. # remove_dismantle_mask(:item, id)
  122. # remove_dismantle_mask(:weapon, id)
  123. # remove_dismantle_mask(:armor, id)
  124. #   This script call allows you to remove the dismantle information mask
  125. #   for a specified item, weapon, or armor where id is the database ID
  126. #   number
  127. #  
  128. # remove_all_dismantle_masks
  129. #   This script call removes all dismantle information masks on all
  130. #   dismantlable items, weapons, and armors in the database.
  131. #  
  132. # get_dismantle_count(:item, id)
  133. # get_dismantle_count(:weapon, id)
  134. # get_dismantle_count(:armor, id)
  135. #   This script call returns the "Times Dismantled" value of the
  136. #   specified item, weapon, and armor where id is the database ID number.
  137. #   This script call is meant to be used in the "Script" box within
  138. #   "Control Variable" event commands.
  139. #  
  140. # get_all_dismantle_count
  141. #   This script call returns the cumulative "Times Dismantled"
  142. #   value of all items, weapons, and armors. This script call is meant to
  143. #   be used in the "Script" box within "Control Variable" event commands.
  144. #  
  145. #--------------------------------------------------------------------------
  146. #   ++ Compatibility ++
  147. #--------------------------------------------------------------------------
  148. # This script aliases the following default VXA methods:
  149. #
  150. #     DataManager#load_database
  151. #    
  152. # There are no default method overwrites.
  153. #
  154. # Requests for compatibility with other scripts are welcome.
  155. #--------------------------------------------------------------------------
  156. #   ++ Terms and Conditions ++
  157. #--------------------------------------------------------------------------
  158. # Please do not repost this script elsewhere without permission.
  159. # Free for non-commercial use. For commercial use, contact me first.
  160. #
  161. # Newest versions of this script can be found at
  162. #                                           http://mrbubblewand.wordpress.com/
  163. #==============================================================================
  164.  
  165. $imported = {} if $imported.nil?
  166. $imported["BubsDismantle"] = true
  167.  
  168. #==========================================================================
  169. # ++ START OF USER CUSTOMIZATION MODULE ++
  170. #==========================================================================
  171. module Bubs
  172.   #==========================================================================
  173.   # ++ Dismantle Shop Settings
  174.   #==========================================================================
  175.   module Dismantle
  176.   #--------------------------------------------------------------------------
  177.   #   Dismantle Command Vocab
  178.   #--------------------------------------------------------------------------
  179.   DISMANTLE_COMMAND_TEXT = "Dismantle"
  180.  
  181.   #--------------------------------------------------------------------------
  182.   #   Dismantle Shop Category Setting
  183.   #--------------------------------------------------------------------------
  184.   # This setting determines what item categories appear in the
  185.   # Dismantle Shop category window. If a category is not included
  186.   # in the array then those types of items are not dismantlable.
  187.   #
  188.   # Available Categories:
  189.   #   :items, :weapons, :armors, :key_items
  190.   SHOP_CATEGORIES = [:items, :weapons, :armors]
  191.  
  192.   #--------------------------------------------------------------------------
  193.   # Disable Dismantle Confirm Window Game Switch
  194.   #--------------------------------------------------------------------------
  195.   # This setting allows you to assign a switch ID that toggles
  196.   # whether the "Confirm Dismantle" window is used.
  197.   #
  198.   # If the Game Switch is OFF, the confirm window is used.
  199.   # If the Game Switch is ON, the confirm window is disabled.
  200.   DISABLE_CONFIRM_WINDOW_SWITCH_ID = 1
  201.  
  202.   #--------------------------------------------------------------------------
  203.   #   Default Dismantle Chance
  204.   #--------------------------------------------------------------------------
  205.   # This setting determines the default chance for all dismantlable
  206.   # items if a custom chance tag is not found.
  207.   DEFAULT_DISMANTLE_CHANCE = 100.0  # (%)
  208.  
  209.   #--------------------------------------------------------------------------
  210.   #   Show Dismantle Chance
  211.   #--------------------------------------------------------------------------
  212.   # Dismantle chance rates will still be used even if chance values
  213.   # are hidden
  214.   #
  215.   # true  : Show dismantle chance info.
  216.   # false : Hide dismantle chance info.
  217.   SHOW_DISMANTLE_CHANCE = true
  218.  
  219.   #--------------------------------------------------------------------------
  220.   #   Default Dismantle Fee
  221.   #--------------------------------------------------------------------------
  222.   # This setting determines the default Gold fee for all dismantlable
  223.   # items if a custom fee tag is not found.
  224.   DEFAULT_DISMANTLE_FEE = 250
  225.    
  226.   #--------------------------------------------------------------------------
  227.   #   Dismantle Fee Text Settings
  228.   #--------------------------------------------------------------------------
  229.   # This setting determines whether the "Fee" for dismantlable items
  230.   # can be see in the info window.
  231.   #
  232.   # true  : Fee can be seen in dismantle info window.
  233.   # false : Fee is hidden.
  234.   SHOW_DISMANTLE_FEE = true
  235.   DISMANTLE_FEE_TEXT = "Dismantle Fee" # Dismantle Gold Fee Text
  236.  
  237.   #--------------------------------------------------------------------------
  238.   #   Dismantlable Items List Settings
  239.   #--------------------------------------------------------------------------
  240.   # This setting toggles the Dismantlable Items list.
  241.   #
  242.   # true  : Player can see what item can dismantle into.
  243.   # false : Player cannot see Dismantlable Items list.
  244.   SHOW_DISMANTLABLE_ITEMS_LIST = true
  245.   #--------------------------------------------------------------------------
  246.   #   Dismantlable Items Info Window Settings
  247.   #--------------------------------------------------------------------------
  248.   DISMANTLABLE_ITEMS_LIST_TEXT = "Dismantlable Items" # Items List Text  
  249.   DISMANTLABLE_COUNTER_TEXT    = "Times Dismantled" # Dismantle Counter Text
  250.   RESULTS_HEADER_TEXT          = "You Received" # Results Header Window Text
  251.  
  252.   #--------------------------------------------------------------------------
  253.   # Use Dismantlable Items Mask Setting
  254.   #--------------------------------------------------------------------------
  255.   # This setting allows you to use a mask for an item under the
  256.   # "Dismantlable Items" list if the item has not yet been
  257.   # dismantled from the item. The item's name and chance is
  258.   # revealed when the player successfully dismantles that item.
  259.   USE_DISMANTLABLE_ITEMS_MASK = true
  260.   #--------------------------------------------------------------------------
  261.   # Item Mask Settings
  262.   #--------------------------------------------------------------------------
  263.   DISMANTLABLE_ITEMS_MASK_ICON_ID = 0     # Mask Iconset ID
  264.   DISMANTLABLE_ITEMS_MASK = "?????"       # Item Name Mask
  265.   DISMANTLABLE_ITEMS_CHANCE_MASK = "??%"  # Chance Mask
  266.  
  267.   #--------------------------------------------------------------------------
  268.   # Dismantle Sound Effect
  269.   #--------------------------------------------------------------------------
  270.   #               "filename", volume, pitch
  271.   DISMANTLE_SE = [  "Hammer",     80,   100]
  272.  
  273.   end # module Dismantle
  274. end # module Bubs
  275.  
  276. #==========================================================================
  277. # ++ END OF USER CUSTOMIZATION MODULE ++
  278. #==========================================================================
  279.  
  280.  
  281.  
  282. #==========================================================================
  283. # ++ Bubs::Regexp
  284. #==========================================================================
  285. module Bubs
  286.   module Regexp
  287.     module BaseItem
  288.       DISMANTLE_START = /<DISMANTLE>/i
  289.       DISMANTLE_END   = /<\/DISMANTLE>/i
  290.     end # module BaseItem
  291.   end # module Regexp
  292. end # module Bubs
  293.  
  294.  
  295. #==============================================================================
  296. # ++ Sound
  297. #==============================================================================
  298. module Vocab
  299.   #--------------------------------------------------------------------------
  300.   # new method : dismantle
  301.   #--------------------------------------------------------------------------
  302.   def self.dismantle
  303.     Bubs::Dismantle::DISMANTLE_COMMAND_TEXT
  304.   end
  305.  
  306. end # module Vocab
  307.  
  308.  
  309. #==============================================================================
  310. # ++ Sound
  311. #==============================================================================
  312. module Sound
  313.   #--------------------------------------------------------------------------
  314.   # new method : play_dismantle
  315.   #--------------------------------------------------------------------------
  316.   def self.play_dismantle
  317.     filename = Bubs::Dismantle::DISMANTLE_SE[0]
  318.     volume = Bubs::Dismantle::DISMANTLE_SE[1]
  319.     pitch = Bubs::Dismantle::DISMANTLE_SE[2]
  320.     Audio.se_play("/Audio/SE/" + filename, volume, pitch)
  321.   end
  322.  
  323. end # module Sound
  324.  
  325.  
  326. #==========================================================================
  327. # ++ DataManager
  328. #==========================================================================
  329. module DataManager
  330.   #--------------------------------------------------------------------------
  331.   # alias : load_database
  332.   #--------------------------------------------------------------------------
  333.   class << self; alias load_database_bubs_dismantle load_database; end
  334.   def self.load_database
  335.     load_database_bubs_dismantle # alias
  336.     load_notetags_bubs_dismantle
  337.   end
  338.  
  339.   #--------------------------------------------------------------------------
  340.   # new method : load_notetags_bubs_dismantle
  341.   #--------------------------------------------------------------------------
  342.   def self.load_notetags_bubs_dismantle
  343.     groups = [$data_items, $data_weapons, $data_armors]
  344.     for group in groups
  345.       for obj in group
  346.         next if obj.nil?
  347.         obj.load_notetags_bubs_dismantle
  348.       end # for obj
  349.     end # for group
  350.   end # def
  351.  
  352. end # module DataManager
  353.  
  354.  
  355. #==========================================================================
  356. # ++ RPG::BaseItem
  357. #==========================================================================
  358. class RPG::BaseItem
  359.   attr_accessor :dismantle_items
  360.   attr_accessor :dismantle_gold_fee
  361.   attr_accessor :dismantle_reagents
  362.   attr_accessor :dismantle_counter
  363.   #--------------------------------------------------------------------------
  364.   # common cache : load_notetags_bubs_dismantle
  365.   #--------------------------------------------------------------------------
  366.   def load_notetags_bubs_dismantle
  367.     @dismantle_items = [] # [[item_obj, chance, mask_flag], ...]
  368.     @dismantle_gold_fee = Bubs::Dismantle::DEFAULT_DISMANTLE_FEE
  369.     @dismantle_reagents = {}
  370.     @dismantle_counter = 0
  371.    
  372.     dismantle_tag = false
  373.    
  374.     self.note.split(/[\r\n]+/).each { |line|
  375.       case line
  376.       when /<dismantle>/i
  377.         dismantle_tag = true
  378.       when /<\/dismantle>/i
  379.         dismantle_tag = false
  380.       when /(\w+):\s*(\d+)\s*[,:]?\s*(\d+\.?\d*)?/i
  381.         next unless dismantle_tag
  382.        
  383.         chance = Bubs::Dismantle::DEFAULT_DISMANTLE_CHANCE
  384.         mask_flag = !Bubs::Dismantle::USE_DISMANTLABLE_ITEMS_MASK
  385.        
  386.         case $1.upcase
  387.         when "I", "ITEM"
  388.           chance = $3.to_f unless $3.nil?
  389.           @dismantle_items.push( [$data_items[$2.to_i], chance, mask_flag] )
  390.          
  391.         when "W", "WEAPON", "WEP"
  392.           chance = $3.to_f unless $3.nil?
  393.           @dismantle_items.push( [$data_weapons[$2.to_i], chance, mask_flag] )
  394.          
  395.         when "A", "ARMOR", "ARMOUR", "ARM"
  396.           chance = $3.to_f unless $3.nil?
  397.           @dismantle_items.push( [$data_armors[$2.to_i], chance, mask_flag] )
  398.          
  399.         when "F", "FEE"
  400.           @dismantle_gold_fee = $2.to_i
  401.          
  402.         end # case
  403.       end # case
  404.     } # self.note.split
  405.   end
  406.   #--------------------------------------------------------------------------
  407.   # new method : dismantlable?
  408.   #--------------------------------------------------------------------------
  409.   def dismantlable?
  410.     return false unless self.is_a?(RPG::Item) || self.is_a?(RPG::EquipItem)
  411.     return true unless @dismantle_items.empty?
  412.     return false
  413.   end
  414.   #--------------------------------------------------------------------------
  415.   # new method : set_dismantle_mask_flags
  416.   #--------------------------------------------------------------------------
  417.   def set_dismantle_mask_flags(flag = true)
  418.     return unless self.is_a?(RPG::Item) || self.is_a?(RPG::EquipItem)
  419.     @dismantle_items.each do |array| array[2] = flag end
  420.   end
  421. end # class RPG::BaseItem
  422.  
  423.  
  424. #==============================================================================
  425. # ++ Window_DismantleShopCommand
  426. #==============================================================================
  427. class Window_DismantleShopCommand < Window_HorzCommand
  428.   #--------------------------------------------------------------------------
  429.   # initialize
  430.   #--------------------------------------------------------------------------
  431.   def initialize(window_width)
  432.     @window_width = window_width
  433.     super(0, 0)
  434.   end
  435.  
  436.   #--------------------------------------------------------------------------
  437.   # window_width
  438.   #--------------------------------------------------------------------------
  439.   def window_width
  440.     @window_width
  441.   end
  442.  
  443.   #--------------------------------------------------------------------------
  444.   # col_max
  445.   #--------------------------------------------------------------------------
  446.   def col_max
  447.     return 2
  448.   end
  449.  
  450.   #--------------------------------------------------------------------------
  451.   # make_command_list
  452.   #--------------------------------------------------------------------------
  453.   def make_command_list
  454.     add_command(Vocab::dismantle,  :dismantle)
  455.     add_command(Vocab::ShopCancel, :cancel)
  456.   end
  457. end
  458.  
  459.  
  460. #==============================================================================
  461. # ++ Window_DismantleShopItemList
  462. #------------------------------------------------------------------------------
  463. #  This window displays a list of items in possession for dismantling on the
  464. # shop screen.
  465. #==============================================================================
  466.  
  467. class Window_DismantleShopItemList < Window_ItemList
  468.   #--------------------------------------------------------------------------
  469.   # initialize
  470.   #--------------------------------------------------------------------------
  471.   def initialize(x, y, width, height)
  472.     super(x, y, window_width, height)
  473.   end
  474.  
  475.   #--------------------------------------------------------------------------
  476.   # window_width
  477.   #--------------------------------------------------------------------------
  478.   def window_width
  479.     Graphics.width / 2
  480.   end
  481.  
  482.   #--------------------------------------------------------------------------
  483.   # current_item_enabled?           # Get Activation State of Selection Item
  484.   #--------------------------------------------------------------------------
  485.   def current_item_enabled?
  486.     enable?(@data[index])
  487.   end
  488.  
  489.   #--------------------------------------------------------------------------
  490.   # enable?                               # Display in Enabled State?
  491.   #--------------------------------------------------------------------------
  492.   def enable?(item)
  493.     return false if item.nil?
  494.     return false if $game_party.gold < item.dismantle_gold_fee
  495.     return item.dismantlable?
  496.   end
  497.  
  498.   #--------------------------------------------------------------------------
  499.   # col_max
  500.   #--------------------------------------------------------------------------
  501.   def col_max
  502.     return 1
  503.   end
  504.  
  505.   #--------------------------------------------------------------------------
  506.   # include?                              # Include in Item List?
  507.   #--------------------------------------------------------------------------
  508.   def include?(item)
  509.     case @category
  510.     when :item
  511.       item.is_a?(RPG::Item) && !item.key_item? && item.dismantlable?
  512.     when :weapon
  513.       item.is_a?(RPG::Weapon) && item.dismantlable?
  514.     when :armor
  515.       item.is_a?(RPG::Armor) && item.dismantlable?
  516.     when :key_item
  517.       item.is_a?(RPG::Item) && item.key_item? && item.dismantlable?
  518.     else
  519.       false
  520.     end
  521.   end
  522.  
  523.   #--------------------------------------------------------------------------
  524.   # status_window=
  525.   #--------------------------------------------------------------------------
  526.   def status_window=(status_window)
  527.     @status_window = status_window
  528.     call_update_help
  529.   end
  530.  
  531.   #--------------------------------------------------------------------------
  532.   # update_help
  533.   #--------------------------------------------------------------------------
  534.   def update_help
  535.     @help_window.set_item(item) if @help_window
  536.     @status_window.item = item if @status_window
  537.   end
  538.  
  539. end # class Window_DismantleShopItemList
  540.  
  541.  
  542. #==============================================================================
  543. # ++ Window_DismantleShopCategory
  544. #==============================================================================
  545. class Window_DismantleShopCategory < Window_HorzCommand
  546.   #--------------------------------------------------------------------------
  547.   # public instance variables
  548.   #--------------------------------------------------------------------------
  549.   attr_reader   :item_window
  550.  
  551.   #--------------------------------------------------------------------------
  552.   # initialize
  553.   #--------------------------------------------------------------------------
  554.   def initialize
  555.     super(0, 0)
  556.   end
  557.  
  558.   #--------------------------------------------------------------------------
  559.   # window_width
  560.   #--------------------------------------------------------------------------
  561.   def window_width
  562.     Graphics.width / 2
  563.   end
  564.  
  565.   #--------------------------------------------------------------------------
  566.   # col_max
  567.   #--------------------------------------------------------------------------
  568.   def col_max
  569.     Bubs::Dismantle::SHOP_CATEGORIES.size
  570.   end
  571.  
  572.   #--------------------------------------------------------------------------
  573.   # update
  574.   #--------------------------------------------------------------------------
  575.   def update
  576.     super
  577.     @item_window.category = current_symbol if @item_window
  578.   end
  579.  
  580.   #--------------------------------------------------------------------------
  581.   # make_command_list
  582.   #--------------------------------------------------------------------------
  583.   def make_command_list
  584.     config = Bubs::Dismantle::SHOP_CATEGORIES
  585.     add_command(Vocab::item,     :item)     if config.include?(:items)
  586.     add_command(Vocab::weapon,   :weapon)   if config.include?(:weapons)
  587.     add_command(Vocab::armor,    :armor)    if config.include?(:armors)
  588.     add_command(Vocab::key_item, :key_item) if config.include?(:key_items)
  589.   end
  590.  
  591.   #--------------------------------------------------------------------------
  592.   # item_window=
  593.   #--------------------------------------------------------------------------
  594.   def item_window=(item_window)
  595.     @item_window = item_window
  596.     update
  597.   end
  598.  
  599. end # class Window_DismantleShopCategory
  600.  
  601.  
  602. #==============================================================================
  603. # ++ Window_DismantleShopInfo
  604. #==============================================================================
  605. class Window_DismantleShopInfo < Window_Base
  606.   #--------------------------------------------------------------------------
  607.   # initialize
  608.   #--------------------------------------------------------------------------
  609.   def initialize(x, y, width, height)
  610.     super(x, y, width, height)
  611.     @item = nil
  612.     @page_index = 0
  613.     refresh
  614.   end
  615.  
  616.   #--------------------------------------------------------------------------
  617.   # refresh
  618.   #--------------------------------------------------------------------------
  619.   def refresh
  620.     contents.clear
  621.     draw_dismantle_counter(4, 0)
  622.     draw_dismantle_fee(4, line_height * 1)
  623.     draw_dismantle_info(4, line_height * 3)
  624.   end
  625.  
  626.   #--------------------------------------------------------------------------
  627.   # draw_dismantle_fee
  628.   #--------------------------------------------------------------------------
  629.   def draw_dismantle_fee(x, y)
  630.     return unless Bubs::Dismantle::SHOW_DISMANTLE_FEE
  631.     rect = Rect.new(x, y, contents.width - 4 - x, line_height)
  632.     change_color(system_color)
  633.     draw_text(rect, Bubs::Dismantle::DISMANTLE_FEE_TEXT)
  634.     if @item
  635.       draw_currency_value(@item.dismantle_gold_fee, Vocab::currency_unit, x, y, contents.width - 4 - x)
  636.     else
  637.       change_color(normal_color)
  638.       draw_text(rect, "-", 2)
  639.     end # if
  640.   end
  641.  
  642.   #--------------------------------------------------------------------------
  643.   # draw_dismantle_info
  644.   #--------------------------------------------------------------------------
  645.   def draw_dismantle_info(x, y)
  646.     return unless Bubs::Dismantle::SHOW_DISMANTLABLE_ITEMS_LIST
  647.     rect = Rect.new(x, y, contents.width - 4 - x, line_height)
  648.     change_color(system_color)
  649.     draw_text(rect, Bubs::Dismantle::DISMANTLABLE_ITEMS_LIST_TEXT)
  650.     return unless @item
  651.     @item.dismantle_items.each_with_index do |array, i|
  652.       if array[2]
  653.         draw_normal_dismantle_info(array, x, y + line_height * (i + 1))
  654.       else
  655.         draw_masked_item_info(x, y + line_height * (i + 1))
  656.       end # if
  657.     end # do
  658.   end
  659.  
  660.   #--------------------------------------------------------------------------
  661.   # draw_normal_dismantle_info
  662.   #--------------------------------------------------------------------------
  663.   def draw_normal_dismantle_info(array, x, y)
  664.     width = Bubs::Dismantle::SHOW_DISMANTLE_CHANCE ? 172 : contents.width
  665.     draw_item_name(array[0], x, y, true, width)
  666.     draw_dismantle_chance(array[1], x, y)
  667.   end
  668.  
  669.   #--------------------------------------------------------------------------
  670.   # draw_masked_item_info
  671.   #--------------------------------------------------------------------------
  672.   def draw_masked_item_info(x, y)
  673.     draw_masked_item_name(x, y)
  674.     draw_masked_dismantle_chance(x, y)
  675.   end
  676.  
  677.   #--------------------------------------------------------------------------
  678.   # draw_masked_item_name
  679.   #--------------------------------------------------------------------------
  680.   def draw_masked_item_name(x, y)
  681.     draw_icon(Bubs::Dismantle::DISMANTLABLE_ITEMS_MASK_ICON_ID, x, y)
  682.     change_color(normal_color)
  683.     draw_text(x + 24, y, width, line_height, Bubs::Dismantle::DISMANTLABLE_ITEMS_MASK)
  684.   end
  685.  
  686.   #--------------------------------------------------------------------------
  687.   # draw_masked_dismantle_chance
  688.   #--------------------------------------------------------------------------
  689.   def draw_masked_dismantle_chance(x, y)
  690.     return unless Bubs::Dismantle::SHOW_DISMANTLE_CHANCE
  691.     rect = Rect.new(x, y + 3, contents.width - 4 - x, line_height)
  692.     contents.font.size = 16
  693.     draw_text(rect, Bubs::Dismantle::DISMANTLABLE_ITEMS_CHANCE_MASK, 2)
  694.     contents.font.size = Font.default_size
  695.   end
  696.  
  697.   #--------------------------------------------------------------------------
  698.   # draw_dismantle_chance
  699.   #--------------------------------------------------------------------------
  700.   def draw_dismantle_chance(chance, x, y)
  701.     return unless Bubs::Dismantle::SHOW_DISMANTLE_CHANCE
  702.     rect = Rect.new(x, y + 3, contents.width - 4 - x, line_height)
  703.     contents.font.size = 16
  704.     draw_text(rect, sprintf("%3.1f%%", chance), 2)
  705.     contents.font.size = Font.default_size
  706.   end
  707.  
  708.   #--------------------------------------------------------------------------
  709.   # item=                                        # Set Item
  710.   #--------------------------------------------------------------------------
  711.   def item=(item)
  712.     @item = item
  713.     refresh
  714.   end
  715.  
  716.   #--------------------------------------------------------------------------
  717.   # draw_dismantle_counter
  718.   #--------------------------------------------------------------------------
  719.   def draw_dismantle_counter(x, y)
  720.     rect = Rect.new(x, y, contents.width - 4 - x, line_height)
  721.     change_color(system_color)
  722.     draw_text(rect, Bubs::Dismantle::DISMANTLABLE_COUNTER_TEXT)
  723.     change_color(normal_color)
  724.     counter = @item ? @item.dismantle_counter : "-"
  725.     draw_text(rect, counter.to_s, 2)
  726.   end
  727.  
  728. end # class Window_DismantleShopInfo
  729.  
  730.  
  731. #==============================================================================
  732. # ++ Window_DismantleShopConfirm
  733. #==============================================================================
  734. class Window_DismantleShopConfirm < Window_Command
  735.   #--------------------------------------------------------------------------
  736.   # initialize
  737.   #--------------------------------------------------------------------------
  738.   def initialize
  739.     super(0, 0)
  740.   end
  741.  
  742.   #--------------------------------------------------------------------------
  743.   # make_command_list
  744.   #--------------------------------------------------------------------------
  745.   def make_command_list
  746.     add_command(Vocab::dismantle,   :ok)
  747.     add_command(Vocab::ShopCancel, :cancel)
  748.   end
  749.  
  750. end # class Window_DismantleShopConfirm
  751.  
  752.  
  753. #==============================================================================
  754. # ++ Window_DismantleResults
  755. #==============================================================================
  756. class Window_DismantleResults < Window_ItemList
  757.   #--------------------------------------------------------------------------
  758.   # initialize
  759.   #--------------------------------------------------------------------------
  760.   def initialize(x, y)
  761.     @gained_items = []
  762.     super(x, y, window_width, window_height)
  763.   end
  764.  
  765.   #--------------------------------------------------------------------------
  766.   # window_width
  767.   #--------------------------------------------------------------------------
  768.   def window_width
  769.     Graphics.width / 2
  770.   end
  771.  
  772.   #--------------------------------------------------------------------------
  773.   # window_height
  774.   #--------------------------------------------------------------------------
  775.   def window_height
  776.     fitting_height( [[@gained_items.uniq.size, 1].max, 8].min )
  777.   end
  778.  
  779.   #--------------------------------------------------------------------------
  780.   # current_item_enabled?
  781.   #--------------------------------------------------------------------------
  782.   def current_item_enabled?
  783.     enable?(@data[index])
  784.   end
  785.  
  786.   #--------------------------------------------------------------------------
  787.   # enable?                                 # Display in Enabled State?
  788.   #--------------------------------------------------------------------------
  789.   def enable?(item)
  790.     true
  791.   end
  792.  
  793.   #--------------------------------------------------------------------------
  794.   # col_max
  795.   #--------------------------------------------------------------------------
  796.   def col_max
  797.     return 1
  798.   end
  799.  
  800.   #--------------------------------------------------------------------------
  801.   # items=
  802.   #--------------------------------------------------------------------------
  803.   def items=(item_array)
  804.     @gained_items = item_array
  805.     refresh
  806.   end
  807.  
  808.   #--------------------------------------------------------------------------
  809.   # clear
  810.   #--------------------------------------------------------------------------
  811.   def clear
  812.     @gained_items = []
  813.   end
  814.  
  815.   #--------------------------------------------------------------------------
  816.   # make_item_list
  817.   #--------------------------------------------------------------------------
  818.   def make_item_list
  819.     @data = @gained_items.uniq
  820.   end
  821.  
  822.   #--------------------------------------------------------------------------
  823.   # draw_item
  824.   #--------------------------------------------------------------------------
  825.   def draw_item(index)
  826.     item = @data[index]
  827.     if item
  828.       rect = item_rect(index)
  829.       rect.width -= 4
  830.       draw_item_name(item, rect.x, rect.y, enable?(item))
  831.       draw_gained_item_number(rect, item)
  832.     end
  833.   end
  834.  
  835.   #--------------------------------------------------------------------------
  836.   # draw_gained_item_number
  837.   #--------------------------------------------------------------------------
  838.   def draw_gained_item_number(rect, item)
  839.     draw_text(rect, sprintf(":%2d", @gained_items.count(item)), 2)
  840.   end
  841.  
  842.   #--------------------------------------------------------------------------
  843.   # status_window=                          # Set Status Window
  844.   #--------------------------------------------------------------------------
  845.   def status_window=(status_window)
  846.     @status_window = status_window
  847.     call_update_help
  848.   end
  849.  
  850.   #--------------------------------------------------------------------------
  851.   # update_help                             # Update Help Text
  852.   #--------------------------------------------------------------------------
  853.   def update_help
  854.     @help_window.set_item(item) if @help_window
  855.     @status_window.item = item if @status_window
  856.   end
  857.  
  858. end # Window_DismantleResults
  859.  
  860.  
  861. #==============================================================================
  862. # ++ Window_DismantleResultsHeader
  863. #==============================================================================
  864. class Window_DismantleResultsHeader < Window_Base
  865.   #--------------------------------------------------------------------------
  866.   # initialize
  867.   #--------------------------------------------------------------------------
  868.   def initialize(x, y)
  869.     super(x, y, window_width, window_height)
  870.     refresh
  871.   end
  872.  
  873.   #--------------------------------------------------------------------------
  874.   # window_width
  875.   #--------------------------------------------------------------------------
  876.   def window_width
  877.     Graphics.width / 2
  878.   end
  879.  
  880.   #--------------------------------------------------------------------------
  881.   # window_height
  882.   #--------------------------------------------------------------------------
  883.   def window_height
  884.     fitting_height(1)
  885.   end
  886.  
  887.   #--------------------------------------------------------------------------
  888.   # refresh
  889.   #--------------------------------------------------------------------------
  890.   def refresh
  891.     contents.clear
  892.     draw_dismantle_header_text(4, 0)
  893.   end
  894.  
  895.   #--------------------------------------------------------------------------
  896.   # draw_dismantle_header_text
  897.   #--------------------------------------------------------------------------
  898.   def draw_dismantle_header_text(x, y)
  899.     rect = Rect.new(x, y, contents.width - 4 - x, line_height)
  900.     change_color(system_color)
  901.     draw_text(rect, Bubs::Dismantle::RESULTS_HEADER_TEXT, 1)
  902.   end
  903.  
  904. end # class Window_DismantleResultsHeader
  905.  
  906.  
  907. #==============================================================================
  908. # ++ Game_Interpreter
  909. #==============================================================================
  910. class Game_Interpreter
  911.   #--------------------------------------------------------------------------
  912.   # new method : open_dismantle_shop
  913.   #--------------------------------------------------------------------------
  914.   def open_dismantle_shop
  915.     SceneManager.call(Scene_DismantleShop)
  916.   end
  917.   #--------------------------------------------------------------------------
  918.   # new method : remove_dismantle_mask
  919.   #--------------------------------------------------------------------------
  920.   def remove_dismantle_mask(key, id)
  921.     case key
  922.     when :item
  923.       $data_items[id].set_dismantle_mask_flags(true)
  924.     when :armor
  925.       $data_armors[id].set_dismantle_mask_flags(true)
  926.     when :weapon
  927.       $data_weapons[id].set_dismantle_mask_flags(true)
  928.     end
  929.   end
  930.  
  931.   #--------------------------------------------------------------------------
  932.   # new method : remove_all_dismantle_masks
  933.   #--------------------------------------------------------------------------
  934.   def remove_all_dismantle_masks
  935.     groups = [$data_items, $data_armors, $data_weapons]
  936.     for group in groups
  937.       for obj in group
  938.         next if obj.nil?
  939.         obj.set_dismantle_mask_flags(true)
  940.       end # for
  941.     end # for
  942.   end # def
  943.  
  944.   #--------------------------------------------------------------------------
  945.   # new method : get_dismantle_count
  946.   #--------------------------------------------------------------------------
  947.   def get_dismantle_count(key, id)
  948.     case key
  949.     when :item
  950.       $data_items[id].dismantle_counter
  951.     when :armor
  952.       $data_armors[id].dismantle_counter
  953.     when :weapon
  954.       $data_weapons[id].dismantle_counter
  955.     end # case
  956.   end # def
  957.  
  958.   #--------------------------------------------------------------------------
  959.   # new method : get_all_dismantle_count
  960.   #--------------------------------------------------------------------------
  961.   def get_all_dismantle_count
  962.     count = 0
  963.     groups = [$data_items, $data_armors, $data_weapons]
  964.     for group in groups
  965.       for obj in group
  966.         next if obj.nil?
  967.         count += obj.dismantle_counter
  968.       end # for
  969.     end # for
  970.     return count
  971.   end # def
  972.  
  973. end # class Game_Interpreter
  974.  
  975.  
  976. #==============================================================================
  977. # ++ Scene_DismantleShop
  978. #==============================================================================
  979. class Scene_DismantleShop < Scene_MenuBase
  980.   #--------------------------------------------------------------------------
  981.   # start
  982.   #--------------------------------------------------------------------------
  983.   def start
  984.     super
  985.     create_help_window
  986.     create_gold_window
  987.     create_command_window
  988.     create_dummy_window
  989.     create_info_window
  990.     create_category_window
  991.     create_itemlist_window
  992.     create_dummy2_window
  993.     create_confirm_window
  994.     create_results_header_window
  995.     create_results_window
  996.   end
  997.  
  998.   #--------------------------------------------------------------------------
  999.   # create_results_window
  1000.   #--------------------------------------------------------------------------
  1001.   def create_results_header_window
  1002.     wx = Graphics.width / 4
  1003.     wy = @category_window.y - 24
  1004.     @header_window = Window_DismantleResultsHeader.new(wx, wy)
  1005.     @header_window.viewport = @viewport
  1006.     @header_window.hide
  1007.   end
  1008.  
  1009.   #--------------------------------------------------------------------------
  1010.   # create_results_window
  1011.   #--------------------------------------------------------------------------
  1012.   def create_results_window
  1013.     wx = Graphics.width / 4
  1014.     wy = @header_window.y + @header_window.height
  1015.     @results_window = Window_DismantleResults.new(wx, wy)
  1016.     @results_window.viewport = @viewport
  1017.     @results_window.help_window = @help_window
  1018.     @results_window.hide
  1019.     @results_window.close
  1020.     @results_window.set_handler(:ok,     method(:on_results_ok))
  1021.     @results_window.set_handler(:cancel, method(:on_results_cancel))
  1022.   end
  1023.    
  1024.   #--------------------------------------------------------------------------
  1025.   # create_dummy2_window
  1026.   #--------------------------------------------------------------------------
  1027.   def create_dummy2_window
  1028.     wx = @itemlist_window.width
  1029.     wy = @gold_window.y + @gold_window.height
  1030.     wh = Graphics.height - wy
  1031.     ww = Graphics.width - wx
  1032.     @dummy2_window = Window_Base.new(wx, wy, ww, wh)
  1033.     @dummy2_window.viewport = @viewport
  1034.     @dummy2_window.hide
  1035.   end
  1036.  
  1037.   #--------------------------------------------------------------------------
  1038.   # create_confirm_window
  1039.   #--------------------------------------------------------------------------
  1040.   def create_confirm_window
  1041.     @confirm_window = Window_DismantleShopConfirm.new
  1042.     @confirm_window.viewport = @viewport
  1043.     @confirm_window.x = (Graphics.width / 2) - @confirm_window.width / 2
  1044.     @confirm_window.y = (Graphics.height / 2) - @confirm_window.height / 2
  1045.     @confirm_window.set_handler(:ok,     method(:on_confirm_ok))
  1046.     @confirm_window.set_handler(:cancel, method(:on_confirm_cancel))
  1047.     @confirm_window.hide
  1048.   end
  1049.  
  1050.   #--------------------------------------------------------------------------
  1051.   # create_gold_window
  1052.   #--------------------------------------------------------------------------
  1053.   def create_gold_window
  1054.     @gold_window = Window_Gold.new
  1055.     @gold_window.viewport = @viewport
  1056.     @gold_window.x = Graphics.width - @gold_window.width
  1057.     @gold_window.y = @help_window.height
  1058.   end
  1059.  
  1060.   #--------------------------------------------------------------------------
  1061.   # create_command_window
  1062.   #--------------------------------------------------------------------------
  1063.   def create_command_window
  1064.     @command_window = Window_DismantleShopCommand.new(@gold_window.x)
  1065.     @command_window.viewport = @viewport
  1066.     @command_window.y = @help_window.height
  1067.     @command_window.set_handler(:dismantle,   method(:command_dismantle))
  1068.     @command_window.set_handler(:cancel,      method(:return_scene))
  1069.   end
  1070.  
  1071.   #--------------------------------------------------------------------------
  1072.   # create_dummy_window
  1073.   #--------------------------------------------------------------------------
  1074.   def create_dummy_window
  1075.     wy = @command_window.y + @command_window.height
  1076.     wh = Graphics.height - wy
  1077.     @dummy_window = Window_Base.new(0, wy, Graphics.width, wh)
  1078.     @dummy_window.viewport = @viewport
  1079.   end
  1080.  
  1081.   #--------------------------------------------------------------------------
  1082.   # create_info_window
  1083.   #--------------------------------------------------------------------------
  1084.   def create_info_window
  1085.     wx = Graphics.width / 2
  1086.     wy = @dummy_window.y
  1087.     ww = Graphics.width - wx
  1088.     wh = @dummy_window.height
  1089.     @info_window = Window_DismantleShopInfo.new(wx, wy, ww, wh)
  1090.     @info_window.viewport = @viewport
  1091.     @info_window.hide
  1092.   end
  1093.  
  1094.   #--------------------------------------------------------------------------
  1095.   # create_category_window
  1096.   #--------------------------------------------------------------------------
  1097.   def create_category_window
  1098.     @category_window = Window_DismantleShopCategory.new
  1099.     @category_window.viewport = @viewport
  1100.     @category_window.help_window = @help_window
  1101.     @category_window.y = @dummy_window.y
  1102.     @category_window.hide.deactivate
  1103.     @category_window.set_handler(:ok,     method(:on_category_ok))
  1104.     @category_window.set_handler(:cancel, method(:on_category_cancel))
  1105.   end
  1106.  
  1107.   #--------------------------------------------------------------------------
  1108.   # create_itemlist_window
  1109.   #--------------------------------------------------------------------------
  1110.   def create_itemlist_window
  1111.     wy = @category_window.y + @category_window.height
  1112.     wh = Graphics.height - wy
  1113.     @itemlist_window = Window_DismantleShopItemList.new(0, wy, Graphics.width, wh)
  1114.     @itemlist_window.viewport = @viewport
  1115.     @itemlist_window.help_window = @help_window
  1116.     @itemlist_window.status_window = @info_window
  1117.     @itemlist_window.hide
  1118.     @itemlist_window.set_handler(:ok,     method(:on_itemlist_ok))
  1119.     @itemlist_window.set_handler(:cancel, method(:on_itemlist_cancel))
  1120.     @category_window.item_window = @itemlist_window
  1121.   end
  1122.  
  1123.   #--------------------------------------------------------------------------
  1124.   # activate_itemlist_window
  1125.   #--------------------------------------------------------------------------
  1126.   def activate_itemlist_window
  1127.     @category_window.show
  1128.     @itemlist_window.show.activate
  1129.     @itemlist_window.select_last
  1130.     refresh
  1131.   end
  1132.  
  1133.   #--------------------------------------------------------------------------
  1134.   # command_dismantle
  1135.   #--------------------------------------------------------------------------
  1136.   def command_dismantle
  1137.     @dummy_window.hide
  1138.     @category_window.show.activate
  1139.     @itemlist_window.show
  1140.     @itemlist_window.unselect
  1141.     @dummy2_window.show
  1142.     refresh
  1143.   end
  1144.  
  1145.   #--------------------------------------------------------------------------
  1146.   # on_category_ok
  1147.   #--------------------------------------------------------------------------
  1148.   def on_category_ok
  1149.     activate_itemlist_window
  1150.     @info_window.show
  1151.     @dummy2_window.hide
  1152.     @itemlist_window.select(0)
  1153.   end
  1154.  
  1155.   #--------------------------------------------------------------------------
  1156.   # on_category_cancel
  1157.   #--------------------------------------------------------------------------
  1158.   def on_category_cancel
  1159.     @command_window.activate
  1160.     @dummy_window.show
  1161.     @category_window.hide
  1162.     @itemlist_window.hide
  1163.     @dummy2_window.hide
  1164.   end
  1165.  
  1166.   #--------------------------------------------------------------------------
  1167.   # on_itemlist_ok
  1168.   #--------------------------------------------------------------------------
  1169.   def on_itemlist_ok
  1170.     @item = @itemlist_window.item
  1171.     $game_party.last_item.object = @item
  1172.     @info_window.item = @item
  1173.     @confirm_window.show.activate
  1174.   end
  1175.  
  1176.   #--------------------------------------------------------------------------
  1177.   # on_itemlist_cancel
  1178.   #--------------------------------------------------------------------------
  1179.   def on_itemlist_cancel
  1180.     @info_window.hide
  1181.     @dummy2_window.show
  1182.     @itemlist_window.unselect
  1183.     @category_window.activate
  1184.     @help_window.clear
  1185.   end
  1186.  
  1187.   #--------------------------------------------------------------------------
  1188.   # on_results_ok
  1189.   #--------------------------------------------------------------------------
  1190.   def on_results_ok
  1191.     @header_window.hide
  1192.     @results_window.close
  1193.     @results_window.clear
  1194.     @results_window.hide
  1195.     activate_itemlist_window
  1196.   end
  1197.  
  1198.   #--------------------------------------------------------------------------
  1199.   # on_results_cancel
  1200.   #--------------------------------------------------------------------------
  1201.   def on_results_cancel
  1202.     on_results_ok
  1203.   end
  1204.  
  1205.   #--------------------------------------------------------------------------
  1206.   # on_confirm_ok
  1207.   #--------------------------------------------------------------------------
  1208.   def on_confirm_ok
  1209.     @confirm_window.hide
  1210.     process_dismantle
  1211.   end
  1212.  
  1213.   #--------------------------------------------------------------------------
  1214.   # on_confirm_cancel
  1215.   #--------------------------------------------------------------------------
  1216.   def on_confirm_cancel
  1217.     activate_itemlist_window
  1218.     @info_window.show
  1219.     @confirm_window.hide
  1220.   end
  1221.  
  1222.   #--------------------------------------------------------------------------
  1223.   # process_dismantle
  1224.   #--------------------------------------------------------------------------
  1225.   def process_dismantle
  1226.     return unless @item
  1227.     $game_party.last_item.object = @item
  1228.     @item.dismantle_counter += 1
  1229.     $game_party.lose_item(@item, 1)
  1230.     $game_party.lose_gold(@item.dismantle_gold_fee)
  1231.     gained_items = determine_dismantled_items
  1232.     gain_dismantled_items(gained_items)
  1233.     @results_window.items = gained_items
  1234.     @results_window.height = @results_window.window_height
  1235.     @header_window.show
  1236.     @results_window.open
  1237.     @results_window.show.activate.select(0)
  1238.     Sound.play_dismantle
  1239.     refresh
  1240.   end
  1241.  
  1242.   #--------------------------------------------------------------------------
  1243.   # determine_dismantled_items
  1244.   #--------------------------------------------------------------------------
  1245.   def determine_dismantled_items
  1246.     gained_items = []
  1247.     @item.dismantle_items.each_with_index do |array, index|
  1248.       if rand < (array[1] * 0.01)
  1249.         gained_items.push(array[0])
  1250.         array[2] = true
  1251.       end
  1252.     end
  1253.     return gained_items
  1254.   end
  1255.  
  1256.   #--------------------------------------------------------------------------
  1257.   # gain_dismantled_items
  1258.   #--------------------------------------------------------------------------
  1259.   def gain_dismantled_items(items)
  1260.     items.each do |item|
  1261.       $game_party.gain_item(item, 1)
  1262.     end
  1263.   end
  1264.  
  1265.   #--------------------------------------------------------------------------
  1266.   # refresh
  1267.   #--------------------------------------------------------------------------
  1268.   def refresh
  1269.     @results_window.refresh
  1270.     @gold_window.refresh
  1271.     @info_window.refresh
  1272.     @header_window.refresh
  1273.     @help_window.refresh
  1274.     @itemlist_window.refresh
  1275.   end
  1276.  
  1277.   #--------------------------------------------------------------------------
  1278.   # currency_unit
  1279.   #--------------------------------------------------------------------------
  1280.   def currency_unit
  1281.     @gold_window.currency_unit
  1282.   end
  1283.  
  1284. end # class Scene_DismantleShop
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement