Guest User

Untitled

a guest
Apr 22nd, 2011
615
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Ruby 12.12 KB | None | 0 0
  1. #===============================================================================
  2. #
  3. # Shanghai Simple Script - Disassemble Shop Fee Add-on
  4. # Last Date Updated: 2010.08.12
  5. # Level: Normal
  6. # Original Script by: Shanghai
  7. # Add-on by: Jet Kobayashi Zala
  8. #
  9. # This script is an add-on for Shanghai Simple Script - Disassemble Shop. It
  10. # adds functionality to allow fees to be charged for disassembling items. The
  11. # script features 4 modes for disassembly in addition to allowing you to specify
  12. # a specific amount in the item's notebox. This script uses a variable to modify
  13. # the mode that the shop uses to determine disassembly costs so that you can
  14. # change it in-game.
  15. #
  16. # Fee Determination Modes:
  17. # 0 - Fee is a flat rate set in the variable specified in the script
  18. # 1 - Fee is a flat rate determined by the item's type. i.e. Item, Weapon, Armor
  19. # 2 - Fee is based on number of components and a rate by the component's item type
  20. # 3 - Same as Mode 2, but fee is a percentage of the item's price by item type
  21. #
  22. # As an add-on, this script requires that you have
  23. # Shanghai Simple Script - Disassemble Shop already installed.
  24. #
  25. # This was not made by Shanghai, but by Jet Kobayashi Zala and without
  26. # Shanghai's consent and so he may end up flayed for this. If you need
  27. # help regarding this add-on, contact Jet about it, not Shanghai.
  28. #
  29. #
  30. #===============================================================================
  31. # Instructions
  32. # -----------------------------------------------------------------------------
  33. # To install this script, open up your script editor and copy/paste this script
  34. # to an open slot below Shanghai Simple Script - Disassemble Shop
  35. # but above ▼ Main. Remember to save.
  36. #
  37. # New notebox tag:
  38. #
  39. # <disassemble fee: x>
  40. # Sets the disassembly fee to x for the item.
  41. # If not used, the default fee/formula is used.
  42. #
  43. # Place this in the notebox of either an item, weapon, or armor and that fee
  44. # will be charged when disassembling the item.
  45. #===============================================================================
  46.  
  47. $imported = {} if $imported == nil
  48. $imported["DisassembleShopFeeAddon"] = true
  49.  
  50. module SSS  
  51.   # Settings for Disassembly Shop Fee Settings
  52.   DISASSEMBLE_FEE    = true                   # Use Disassembly Fee system
  53.   DISASSEMBLE_COST   = "Fee"                  # Text next to disassembly fee
  54.   DISASSEMBLE_FUNDS  = "Funds"                # Text used for party's money
  55.  
  56.   # Game Variable used to store the fee determination mode
  57.   # Custom pricing always supersedes this setting
  58.   DISASSEMBLE_VARIABLE    = 6
  59.   # 0 - Uses a flat rate set in the DISASSEMBLE_RATE_VARIABLE variable
  60.   # 1 - Fee is based on the item's category
  61.   # 2 - Fee is based on item type of the components
  62.   #     that the item disassembles into
  63.   # 3 - Same as 2, but charge is a portion of the cost of
  64.   #     the components the unwanted item disassembles into
  65.  
  66.   # If mode is set to is 0, This is the variable that holds
  67.   # the flat rate for disassembly.
  68.   DISASSEMBLE_RATE_VARIABLE = 7
  69.  
  70.   # If mode is set to 1, This is the flat rate for
  71.   # disassembly based on the original item's type.
  72.   DISASSEMBLE_CATEGORY_ITEM   = 1000
  73.   DISASSEMBLE_CATEGORY_WEAPON = 2000
  74.   DISASSEMBLE_CATEGORY_ARMOR  = 2500
  75.  
  76.   # If mode is set to  2, the fee to disassemble
  77.   # the item is based on what it disassembles into.
  78.   DISASSEMBLE_ITEM_RATE = 100
  79.   DISASSEMBLE_WEAPON_RATE = 200
  80.   DISASSEMBLE_ARMOR_RATE = 250
  81.  
  82.   # If mode is set to 3, the fee to disassemble the
  83.   # item is based on a percentage of each components's cost.
  84.   DISASSEMBLE_ITEM_PERCENT = 0.10
  85.   DISASSEMBLE_WEAPON_PERCENT = 0.20
  86.   DISASSEMBLE_ARMOR_PERCENT = 0.25
  87. end
  88.  
  89. #==============================================================================
  90. # RPG::BaseItem
  91. #==============================================================================
  92.  
  93. class RPG::BaseItem
  94.   #--------------------------------------------------------------------------
  95.   # * Get Disassembly Fee
  96.   #--------------------------------------------------------------------------
  97.   def get_disassembly_fee
  98.     # Return custom fee if set
  99.     return disassembled_fee if !disassembled_fee.nil?
  100.     # Otherwise, use formula/rate settings
  101.     fee = 0
  102.     case $game_variables[SSS::DISASSEMBLE_VARIABLE]
  103.     when 0 # Flat Rate
  104.       fee = $game_variables[SSS::DISASSEMBLE_RATE_VARIABLE]
  105.     when 1 # By Original Item Type
  106.       if self.is_a?(RPG::Item)
  107.         fee = SSS::DISASSEMBLE_CATEGORY_ITEM
  108.       elsif self.is_a?(RPG::Weapon)
  109.         fee = SSS::DISASSEMBLE_CATEGORY_WEAPON
  110.       elsif self.is_a?(RPG::Armor)
  111.         fee = SSS::DISASSEMBLE_CATEGORY_ARMOR
  112.       end
  113.     when 2 # By Item - Flat Rate Per Item
  114.       for component in @disassembled_items
  115.         if component.is_a?(RPG::Item)
  116.           fee += SSS::DISASSEMBLE_ITEM_RATE
  117.         elsif component.is_a?(RPG::Weapon)
  118.           fee += SSS::DISASSEMBLE_WEAPON_RATE
  119.         elsif component.is_a?(RPG::Armor)
  120.           fee += SSS::DISASSEMBLE_ARMOR_RATE
  121.         end
  122.       end
  123.     when 3 # By Item - Percentage of item cost
  124.       for component in @disassembled_items
  125.         if component.is_a?(RPG::Item)
  126.           fee += (SSS::DISASSEMBLE_ITEM_PERCENT * component.price)
  127.         elsif component.is_a?(RPG::Weapon)
  128.           fee += (SSS::DISASSEMBLE_WEAPON_PERCENT * component.price)
  129.         elsif component.is_a?(RPG::Armor)
  130.           fee += (SSS::DISASSEMBLE_ARMOR_PERCENT * component.price)
  131.         end
  132.       end
  133.     end
  134.     return fee.to_i
  135.   end
  136.   #--------------------------------------------------------------------------
  137.   # disassembled_fee
  138.   #--------------------------------------------------------------------------
  139.   def disassembled_fee
  140.     return nil if !SSS::DISASSEMBLE_FEE
  141.     self.note.split(/[\r\n]+/).each { |line|
  142.       case line
  143.       when /<(?:DISASSEMBLE_FEE|disassemble fee):[ ]*(\d+)>/i
  144.         return $1.to_i
  145.       end
  146.     }
  147.     return nil
  148.   end
  149. end
  150.  
  151. #==============================================================================
  152. # ** Window_Disassemble
  153. #==============================================================================
  154.  
  155. class Window_Disassemble < Window_Selectable
  156.   #--------------------------------------------------------------------------
  157.   # * Object Initialization
  158.   #--------------------------------------------------------------------------
  159.   alias sss_original_initialize initialize
  160.   def initialize(help_window)
  161.     if $imported["DisassembleShopFeeAddon"] and SSS::DISASSEMBLE_FEE
  162.       yy = help_window.height + help_window.y + (WLH + 32) + 56
  163.       hh = Graphics.height - yy
  164.       super(0, yy, Graphics.width-240, hh)
  165.       self.active = false
  166.       self.index = -1
  167.       @help_window = help_window
  168.       self.item_type = 0
  169.     else
  170.       sss_original_initialize(help_window)
  171.     end
  172.   end
  173. end
  174.  
  175. #==============================================================================
  176. # ** Window_DisassembleContents
  177. #==============================================================================
  178.  
  179. class Window_DisassembleContents < Window_Base
  180.   #--------------------------------------------------------------------------
  181.   # * Object Initialization
  182.   #--------------------------------------------------------------------------
  183.   alias sss_original_initialize initialize
  184.   def initialize(body_window)
  185.     if $imported["DisassembleShopFeeAddon"] and SSS::DISASSEMBLE_FEE
  186.       @body_window = body_window
  187.       super(@body_window.width, @body_window.y, 240, @body_window.height)
  188.       refresh
  189.     else
  190.       sss_original_initialize(body_window)
  191.     end
  192.   end
  193. end
  194.  
  195. #==============================================================================
  196. # ** Window_DisassembleFee
  197. #==============================================================================
  198.  
  199. class Window_DisassembleFee < Window_Base
  200.   #--------------------------------------------------------------------------
  201.   # * Object Initialization
  202.   #--------------------------------------------------------------------------
  203.   def initialize(contents_window)
  204.     @item = nil
  205.     super(0, contents_window.y - WLH - 32, Graphics.width, WLH + 32)
  206.     refresh
  207.   end
  208.   #--------------------------------------------------------------------------
  209.   # * Refresh
  210.   #--------------------------------------------------------------------------
  211.   def refresh
  212.     self.contents.clear
  213.     self.contents.font.color = normal_color
  214.     self.contents.draw_text(0, 0, self.contents.width / 2 - 15, WLH, SSS::DISASSEMBLE_COST)
  215.     self.contents.draw_text(0, 0, self.contents.width / 2 - 15, WLH, get_disassembly_fee.to_s + Vocab::gold, 2)
  216.     self.contents.draw_text(self.contents.width / 2 + 15, 0, self.contents.width / 2 - 15, WLH, SSS::DISASSEMBLE_FUNDS)
  217.     self.contents.draw_text(self.contents.width / 2 + 15, 0, self.contents.width / 2 - 15, WLH, $game_party.gold.to_s + Vocab::gold, 2)
  218.   end
  219.   #--------------------------------------------------------------------------
  220.   # * Get Disassembly Fee
  221.   #--------------------------------------------------------------------------
  222.   def get_disassembly_fee
  223.     # Return 0 if item is nil
  224.     return 0 if @item == nil
  225.     # Return item's disassembly fee
  226.     return @item.get_disassembly_fee
  227.   end
  228.   #--------------------------------------------------------------------------
  229.   # * Set Item
  230.   #--------------------------------------------------------------------------
  231.   def set_item(item)
  232.     @item = item
  233.     refresh
  234.   end
  235. end
  236.  
  237. #==============================================================================
  238. # ** Scene_Disassemble
  239. #==============================================================================
  240. if $imported["DisassembleShopFeeAddon"] and SSS::DISASSEMBLE_FEE
  241.   class Scene_Disassemble < Scene_Base
  242.     #--------------------------------------------------------------------------
  243.     # * Start processing
  244.     #--------------------------------------------------------------------------
  245.     alias sss_original_start start
  246.     def start
  247.       sss_original_start
  248.       @fee_window = Window_DisassembleFee.new(@contents_window)
  249.     end
  250.     #--------------------------------------------------------------------------
  251.     # * Termination Processing
  252.     #--------------------------------------------------------------------------
  253.     alias sss_original_terminate terminate
  254.     def terminate
  255.       sss_original_terminate
  256.       @fee_window.dispose
  257.     end
  258.     #--------------------------------------------------------------------------
  259.     # * Frame Update
  260.     #--------------------------------------------------------------------------
  261.     alias sss_original_update update
  262.     def update
  263.       sss_original_update
  264.       @fee_window.set_item(@item_window.item)
  265.       @fee_window.update
  266.     end
  267.     #--------------------------------------------------------------------------
  268.     # * Update Item Selection
  269.     #--------------------------------------------------------------------------
  270.     def update_item_selection
  271.       @item_window.update
  272.       if @last_item_index != @item_window.index
  273.         @last_item_index = @item_window.index
  274.         @contents_window.refresh
  275.       end
  276.       if Input.trigger?(Input::B)
  277.         Sound.play_cancel
  278.         @command_window.active = true
  279.         @item_window.active = false
  280.       elsif Input.repeat?(Input::C)
  281.         disassemble_item = @item_window.item
  282.         if disassemble_item.nil? or $game_party.gold < disassemble_item.get_disassembly_fee
  283.           Sound.play_buzzer
  284.         else
  285.           Sound.play_shop
  286.           $game_party.lose_item(disassemble_item, 1)
  287.           for item in disassemble_item.disassembled_items
  288.             next if item.nil?
  289.             $game_party.gain_item(item, 1)
  290.           end
  291.           $game_party.lose_gold(disassemble_item.get_disassembly_fee)
  292.           @item_window.refresh
  293.           @item_window.index = [@item_window.item_max, @item_window.index].min
  294.           @fee_window.refresh
  295.           @contents_window.refresh
  296.         end
  297.       end
  298.     end
  299.   end
  300. end
  301.  
  302. #===============================================================================
  303. #
  304. # END OF FILE
  305. #
  306. #===============================================================================
Advertisement
Add Comment
Please, Sign In to add comment