Advertisement
Guest User

Untitled

a guest
Apr 22nd, 2011
998
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Ruby 13.24 KB | None | 0 0
  1. #===============================================================================
  2. #
  3. # Shanghai Simple Script - Disassemble Shop
  4. # Last Date Updated: 2010.06.13
  5. # Level: Normal
  6. #
  7. # This script creates a new scene where players can disassemble their unwanted
  8. # items or break them down into something more basic. That broadsword which has
  9. # been replaced by a mightier broadsword can now be broken down into various
  10. # components and aid the player one last time rather than just sitting there in
  11. # the inventory to rust.
  12. #===============================================================================
  13. # Instructions
  14. # -----------------------------------------------------------------------------
  15. # To install this script, open up your script editor and copy/paste this script
  16. # to an open slot below ▼ Materials but above ▼ Main. Remember to save.
  17. #
  18. # To load the disassemble shop, use the following evented script call:
  19. # $scene = Scene_Disassemble.new
  20. #
  21. # Inside the shop, it will only list items with the following tag set inside of
  22. # their noteboxes.
  23. #
  24. # <disassemble>
  25. # weapon 1
  26. # armor 2
  27. # item 3
  28. # </disassemble>
  29. # Place this in the notebox of either an item, weapon, or armor and that item
  30. # can then be disassembled into the materials you've placed in between the
  31. # disassemble tags.
  32. #===============================================================================
  33.  
  34. $imported = {} if $imported == nil
  35. $imported["DisassembleShop"] = true
  36.  
  37. module SSS
  38.   # This is the text that appears in the disassemble shop.
  39.   DISASSEMBLE_ITEM   = "Items"
  40.   DISASSEMBLE_WEAPON = "Weapons"
  41.   DISASSEMBLE_ARMOR  = "Armors"
  42.   DISASSEMBLE_EXIT   = "Finish"
  43.   DISASSEMBLE_INTO   = "Disassembles Into"
  44. end
  45.  
  46. #==============================================================================
  47. # RPG::BaseItem
  48. #==============================================================================
  49.  
  50. class RPG::BaseItem
  51.   #--------------------------------------------------------------------------
  52.   # disassembled_items
  53.   #--------------------------------------------------------------------------
  54.   def disassembled_items
  55.     return @disassembled_items if @disassembled_items != nil
  56.     @disassembled_items = []
  57.     disassembled = false
  58.     self.note.split(/[\r\n]+/).each { |line|
  59.       case line
  60.       when /<(?:DISASSEMBLE|disassmbled)>/i
  61.         disassembled = true
  62.       when /<\/(?:DISASSEMBLE|disassmbled)>/i
  63.         disassembled = false
  64.       when /(.*)[ ](\d+)/i
  65.         next unless disassembled
  66.         case $1.upcase
  67.         when "WEAPON", "W", "WEP"
  68.           @disassembled_items.push($data_weapons[$2.to_i])
  69.         when "ARMOR", "ARMOUR", "A", "ARM"
  70.           @disassembled_items.push($data_armors[$2.to_i])
  71.         when "ITEM", "I"
  72.           @disassembled_items.push($data_items[$2.to_i])
  73.         end
  74.       end
  75.     }
  76.     return @disassembled_items
  77.   end
  78. end
  79.  
  80. #==============================================================================
  81. # ** Window_Disassemble
  82. #==============================================================================
  83.  
  84. class Window_Disassemble < Window_Selectable
  85.   #--------------------------------------------------------------------------
  86.   # * Object Initialization
  87.   #--------------------------------------------------------------------------
  88.   def initialize(help_window)
  89.     yy = help_window.height + help_window.y + 56
  90.     hh = Graphics.height - yy
  91.     super(0, yy, Graphics.width-240, hh)
  92.     self.active = false
  93.     self.index = -1
  94.     @help_window = help_window
  95.     self.item_type = 0
  96.   end
  97.   #--------------------------------------------------------------------------
  98.   # * Get Item
  99.   #--------------------------------------------------------------------------
  100.   def item
  101.     return @data[[self.index, 0].max]
  102.   end
  103.   #--------------------------------------------------------------------------
  104.   # * Item Type Change
  105.   #--------------------------------------------------------------------------
  106.   def item_type=(new_type)
  107.     if [0, 1, 2].include?(new_type)
  108.       @item_type = new_type
  109.       refresh
  110.       update_help
  111.     end
  112.   end
  113.   #--------------------------------------------------------------------------
  114.   # * Refresh
  115.   #--------------------------------------------------------------------------
  116.   def refresh
  117.     @data = []
  118.     for item in $game_party.items
  119.       next if item.nil?
  120.       case @item_type
  121.       when 0
  122.         next unless item.is_a?(RPG::Item)
  123.       when 1
  124.         next unless item.is_a?(RPG::Weapon)
  125.       when 2
  126.         next unless item.is_a?(RPG::Armor)
  127.       else
  128.         break
  129.       end
  130.       next if item.disassembled_items.empty?
  131.       @data.push(item)
  132.     end
  133.     self.index = -1 unless self.active
  134.     @item_max = @data.size
  135.     create_contents
  136.     for i in 0...@item_max
  137.       draw_item(i)
  138.     end
  139.   end
  140.   #--------------------------------------------------------------------------
  141.   # * Draw Item
  142.   #--------------------------------------------------------------------------
  143.   def draw_item(index)
  144.     rect = item_rect(index)
  145.     self.contents.clear_rect(rect)
  146.     item = @data[index]
  147.     if item != nil
  148.       number = $game_party.item_number(item)
  149.       enabled = true
  150.       draw_obj_name(item, rect.clone, enabled)
  151.       if $imported["BattleEngineMelody"]
  152.         draw_obj_total(item, rect.clone, enabled)
  153.       else
  154.         self.contents.draw_text(rect, sprintf(":%2d", number), 2)
  155.       end
  156.     end
  157.   end
  158.   #--------------------------------------------------------------------------
  159.   # * Draw Object Name
  160.   #--------------------------------------------------------------------------
  161.   def draw_obj_name(obj, rect, enabled)
  162.     draw_icon(obj.icon_index, rect.x, rect.y, enabled)
  163.     self.contents.font.size = Font.default_size
  164.     self.contents.font.color = normal_color
  165.     self.contents.font.color.alpha = enabled ? 255 : 128
  166.     rect.width -= 48
  167.     self.contents.draw_text(rect.x+24, rect.y, rect.width-24, WLH, obj.name)
  168.   end
  169.   #--------------------------------------------------------------------------
  170.   # * Draw Object Total
  171.   #--------------------------------------------------------------------------
  172.   def draw_obj_total(obj, rect, enabled)
  173.     hash = YEM::BATTLE_ENGINE::ITEM_SETTINGS
  174.     number = $game_party.item_number(obj)
  175.     dx = rect.x + rect.width - 36; dy = rect.y; dw = 32
  176.     text = sprintf(hash[:text], number)
  177.     self.contents.font.size = hash[:size]
  178.     self.contents.font.color = text_color(hash[:colour])
  179.     self.contents.font.color.alpha = enabled ? 255 : 128
  180.     self.contents.draw_text(dx, dy, dw, WLH, text, 2)
  181.   end
  182.   #--------------------------------------------------------------------------
  183.   # * Update Help Text
  184.   #--------------------------------------------------------------------------
  185.   def update_help
  186.     @help_window.set_text(item == nil ? "" : item.description)
  187.   end
  188. end
  189.  
  190. #==============================================================================
  191. # ** Window_DisassembleContents
  192. #==============================================================================
  193.  
  194. class Window_DisassembleContents < Window_Base
  195.   #--------------------------------------------------------------------------
  196.   # * Object Initialization
  197.   #--------------------------------------------------------------------------
  198.   def initialize(body_window)
  199.     @body_window = body_window
  200.     super(@body_window.width, @body_window.y, 240, @body_window.height)
  201.     refresh
  202.   end
  203.   #--------------------------------------------------------------------------
  204.   # * Refresh
  205.   #--------------------------------------------------------------------------
  206.   def refresh
  207.     self.contents.clear
  208.     @item = @body_window.item
  209.     draw_disassembled_contents unless @item.nil?
  210.   end
  211.   #--------------------------------------------------------------------------
  212.   # * Draw Disassembled Contents
  213.   #--------------------------------------------------------------------------
  214.   def draw_disassembled_contents
  215.     self.contents.font.size = Font.default_size
  216.     self.contents.font.color = system_color
  217.     text = SSS::DISASSEMBLE_INTO
  218.     self.contents.draw_text(0, WLH/2, contents.width, WLH, text, 1)
  219.     self.contents.font.color = normal_color
  220.     yy = WLH*2
  221.     @item_amount = {}
  222.     for item in @item.disassembled_items
  223.       next if item.nil?
  224.       @item_amount[item] = 0 if @item_amount[item].nil?
  225.       @item_amount[item] += 1
  226.     end
  227.     for item in @item.disassembled_items.uniq
  228.       next if item.nil?
  229.       draw_item(item, 0, yy)
  230.       yy += WLH
  231.     end
  232.   end
  233.   #--------------------------------------------------------------------------
  234.   # * Draw Item
  235.   #--------------------------------------------------------------------------
  236.   def draw_item(item, xx, yy)
  237.     draw_icon(item.icon_index, xx, yy)
  238.     name = item.name
  239.     self.contents.font.size = Font.default_size
  240.     self.contents.draw_text(xx + 24, yy, contents.width - xx - 56, WLH, name)
  241.     amount = @item_amount[item]
  242.     if $imported["BattleEngineMelody"]
  243.       hash = YEM::BATTLE_ENGINE::ITEM_SETTINGS
  244.       text = sprintf(hash[:text], amount)
  245.       self.contents.font.size = hash[:size]
  246.       self.contents.font.color = text_color(hash[:colour])
  247.     else
  248.       text = sprintf(":%2d", amount)
  249.     end
  250.     self.contents.draw_text(xx, yy, contents.width-4, WLH, text, 2)
  251.   end
  252. end
  253.  
  254. #==============================================================================
  255. # ** Scene_Disassemble
  256. #==============================================================================
  257.  
  258. class Scene_Disassemble < Scene_Base
  259.   #--------------------------------------------------------------------------
  260.   # * Start processing
  261.   #--------------------------------------------------------------------------
  262.   def start
  263.     super
  264.     create_menu_background
  265.     @help_window = Window_Help.new
  266.     @item_window = Window_Disassemble.new(@help_window)
  267.     @contents_window = Window_DisassembleContents.new(@item_window)
  268.     create_command_window
  269.   end
  270.   #--------------------------------------------------------------------------
  271.   # * Termination Processing
  272.   #--------------------------------------------------------------------------
  273.   def terminate
  274.     super
  275.     dispose_menu_background
  276.     @command_window.dispose
  277.     @help_window.dispose
  278.     @item_window.dispose
  279.     @contents_window.dispose
  280.   end
  281.   #--------------------------------------------------------------------------
  282.   # * Frame Update
  283.   #--------------------------------------------------------------------------
  284.   def update
  285.     super
  286.     update_menu_background
  287.     if @command_window.active
  288.       update_command_selection
  289.     elsif @item_window.active
  290.       update_item_selection
  291.     end
  292.   end
  293.   #--------------------------------------------------------------------------
  294.   # * Create Command Window
  295.   #--------------------------------------------------------------------------
  296.   def create_command_window
  297.     array = []
  298.     array.push(SSS::DISASSEMBLE_ITEM)
  299.     array.push(SSS::DISASSEMBLE_WEAPON)
  300.     array.push(SSS::DISASSEMBLE_ARMOR)
  301.     array.push(SSS::DISASSEMBLE_EXIT)
  302.     width = Graphics.width
  303.     @command_window = Window_Command.new(width, array, array.size, 1, 8)
  304.     @command_window.y = @help_window.y + @help_window.height
  305.     @last_command_index = 0
  306.   end
  307.   #--------------------------------------------------------------------------
  308.   # * Update Command Selection
  309.   #--------------------------------------------------------------------------
  310.   def update_command_selection
  311.     @command_window.update
  312.     if @last_command_index != @command_window.index
  313.       @last_command_index = @command_window.index
  314.       @item_window.item_type = @last_command_index
  315.       @contents_window.refresh
  316.     end
  317.     if Input.trigger?(Input::B)
  318.       Sound.play_cancel
  319.       $scene = Scene_Map.new
  320.     elsif Input.trigger?(Input::C)
  321.       Sound.play_decision
  322.       case @command_window.index
  323.       when 3
  324.         $scene = Scene_Map.new
  325.       else
  326.         @command_window.active = false
  327.         @item_window.active = true
  328.         @item_window.index = 0 if @item_window.index == -1
  329.       end
  330.     end
  331.   end
  332.   #--------------------------------------------------------------------------
  333.   # * Update Item Selection
  334.   #--------------------------------------------------------------------------
  335.   def update_item_selection
  336.     @item_window.update
  337.     if @last_item_index != @item_window.index
  338.       @last_item_index = @item_window.index
  339.       @contents_window.refresh
  340.     end
  341.     if Input.trigger?(Input::B)
  342.       Sound.play_cancel
  343.       @command_window.active = true
  344.       @item_window.active = false
  345.     elsif Input.repeat?(Input::C)
  346.       disassemble_item = @item_window.item
  347.       if disassemble_item.nil?
  348.         Sound.play_buzzer
  349.       else
  350.         Sound.play_shop
  351.         $game_party.lose_item(disassemble_item, 1)
  352.         for item in disassemble_item.disassembled_items
  353.           next if item.nil?
  354.           $game_party.gain_item(item, 1)
  355.         end
  356.         @item_window.refresh
  357.         @item_window.index = [@item_window.item_max, @item_window.index].min
  358.         @contents_window.refresh
  359.       end
  360.     end
  361.   end
  362. end
  363.  
  364. #===============================================================================
  365. #
  366. # END OF FILE
  367. #
  368. #===============================================================================
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement