Advertisement
Guest User

Untitled

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