Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #===============================================================================
- #
- # Shanghai Simple Script - Disassemble Shop
- # Last Date Updated: 2010.06.13
- # Level: Normal
- #
- # This script creates a new scene where players can disassemble their unwanted
- # items or break them down into something more basic. That broadsword which has
- # been replaced by a mightier broadsword can now be broken down into various
- # components and aid the player one last time rather than just sitting there in
- # the inventory to rust.
- #===============================================================================
- # Instructions
- # -----------------------------------------------------------------------------
- # To install this script, open up your script editor and copy/paste this script
- # to an open slot below ▼ Materials but above ▼ Main. Remember to save.
- #
- # To load the disassemble shop, use the following evented script call:
- # $scene = Scene_Disassemble.new
- #
- # Inside the shop, it will only list items with the following tag set inside of
- # their noteboxes.
- #
- # <disassemble>
- # weapon 1
- # armor 2
- # item 3
- # </disassemble>
- # Place this in the notebox of either an item, weapon, or armor and that item
- # can then be disassembled into the materials you've placed in between the
- # disassemble tags.
- #===============================================================================
- $imported = {} if $imported == nil
- $imported["DisassembleShop"] = true
- module SSS
- # This is the text that appears in the disassemble shop.
- DISASSEMBLE_ITEM = "Items"
- DISASSEMBLE_WEAPON = "Weapons"
- DISASSEMBLE_ARMOR = "Armors"
- DISASSEMBLE_EXIT = "Finish"
- DISASSEMBLE_INTO = "Disassembles Into"
- end
- #==============================================================================
- # RPG::BaseItem
- #==============================================================================
- class RPG::BaseItem
- #--------------------------------------------------------------------------
- # disassembled_items
- #--------------------------------------------------------------------------
- def disassembled_items
- return @disassembled_items if @disassembled_items != nil
- @disassembled_items = []
- disassembled = false
- self.note.split(/[\r\n]+/).each { |line|
- case line
- when /<(?:DISASSEMBLE|disassmbled)>/i
- disassembled = true
- when /<\/(?:DISASSEMBLE|disassmbled)>/i
- disassembled = false
- when /(.*)[ ](\d+)/i
- next unless disassembled
- case $1.upcase
- when "WEAPON", "W", "WEP"
- @disassembled_items.push($data_weapons[$2.to_i])
- when "ARMOR", "ARMOUR", "A", "ARM"
- @disassembled_items.push($data_armors[$2.to_i])
- when "ITEM", "I"
- @disassembled_items.push($data_items[$2.to_i])
- end
- end
- }
- return @disassembled_items
- end
- end
- #==============================================================================
- # ** Window_Disassemble
- #==============================================================================
- class Window_Disassemble < Window_Selectable
- #--------------------------------------------------------------------------
- # * Object Initialization
- #--------------------------------------------------------------------------
- def initialize(help_window)
- yy = help_window.height + help_window.y + 56
- hh = Graphics.height - yy
- super(0, yy, Graphics.width-240, hh)
- self.active = false
- self.index = -1
- @help_window = help_window
- self.item_type = 0
- end
- #--------------------------------------------------------------------------
- # * Get Item
- #--------------------------------------------------------------------------
- def item
- return @data[[self.index, 0].max]
- end
- #--------------------------------------------------------------------------
- # * Item Type Change
- #--------------------------------------------------------------------------
- def item_type=(new_type)
- if [0, 1, 2].include?(new_type)
- @item_type = new_type
- refresh
- update_help
- end
- end
- #--------------------------------------------------------------------------
- # * Refresh
- #--------------------------------------------------------------------------
- def refresh
- @data = []
- for item in $game_party.items
- next if item.nil?
- case @item_type
- when 0
- next unless item.is_a?(RPG::Item)
- when 1
- next unless item.is_a?(RPG::Weapon)
- when 2
- next unless item.is_a?(RPG::Armor)
- else
- break
- end
- next if item.disassembled_items.empty?
- @data.push(item)
- end
- self.index = -1 unless self.active
- @item_max = @data.size
- create_contents
- for i in 0...@item_max
- draw_item(i)
- end
- end
- #--------------------------------------------------------------------------
- # * Draw Item
- #--------------------------------------------------------------------------
- def draw_item(index)
- rect = item_rect(index)
- self.contents.clear_rect(rect)
- item = @data[index]
- if item != nil
- number = $game_party.item_number(item)
- enabled = true
- draw_obj_name(item, rect.clone, enabled)
- if $imported["BattleEngineMelody"]
- draw_obj_total(item, rect.clone, enabled)
- else
- self.contents.draw_text(rect, sprintf(":%2d", number), 2)
- end
- end
- end
- #--------------------------------------------------------------------------
- # * Draw Object Name
- #--------------------------------------------------------------------------
- def draw_obj_name(obj, rect, enabled)
- draw_icon(obj.icon_index, rect.x, rect.y, enabled)
- self.contents.font.size = Font.default_size
- self.contents.font.color = normal_color
- self.contents.font.color.alpha = enabled ? 255 : 128
- rect.width -= 48
- self.contents.draw_text(rect.x+24, rect.y, rect.width-24, WLH, obj.name)
- end
- #--------------------------------------------------------------------------
- # * Draw Object Total
- #--------------------------------------------------------------------------
- def draw_obj_total(obj, rect, enabled)
- hash = YEM::BATTLE_ENGINE::ITEM_SETTINGS
- number = $game_party.item_number(obj)
- dx = rect.x + rect.width - 36; dy = rect.y; dw = 32
- text = sprintf(hash[:text], number)
- self.contents.font.size = hash[:size]
- self.contents.font.color = text_color(hash[:colour])
- self.contents.font.color.alpha = enabled ? 255 : 128
- self.contents.draw_text(dx, dy, dw, WLH, text, 2)
- end
- #--------------------------------------------------------------------------
- # * Update Help Text
- #--------------------------------------------------------------------------
- def update_help
- @help_window.set_text(item == nil ? "" : item.description)
- end
- end
- #==============================================================================
- # ** Window_DisassembleContents
- #==============================================================================
- class Window_DisassembleContents < Window_Base
- #--------------------------------------------------------------------------
- # * Object Initialization
- #--------------------------------------------------------------------------
- def initialize(body_window)
- @body_window = body_window
- super(@body_window.width, @body_window.y, 240, @body_window.height)
- refresh
- end
- #--------------------------------------------------------------------------
- # * Refresh
- #--------------------------------------------------------------------------
- def refresh
- self.contents.clear
- @item = @body_window.item
- draw_disassembled_contents unless @item.nil?
- end
- #--------------------------------------------------------------------------
- # * Draw Disassembled Contents
- #--------------------------------------------------------------------------
- def draw_disassembled_contents
- self.contents.font.size = Font.default_size
- self.contents.font.color = system_color
- text = SSS::DISASSEMBLE_INTO
- self.contents.draw_text(0, WLH/2, contents.width, WLH, text, 1)
- self.contents.font.color = normal_color
- yy = WLH*2
- @item_amount = {}
- for item in @item.disassembled_items
- next if item.nil?
- @item_amount[item] = 0 if @item_amount[item].nil?
- @item_amount[item] += 1
- end
- for item in @item.disassembled_items.uniq
- next if item.nil?
- draw_item(item, 0, yy)
- yy += WLH
- end
- end
- #--------------------------------------------------------------------------
- # * Draw Item
- #--------------------------------------------------------------------------
- def draw_item(item, xx, yy)
- draw_icon(item.icon_index, xx, yy)
- name = item.name
- self.contents.font.size = Font.default_size
- self.contents.draw_text(xx + 24, yy, contents.width - xx - 56, WLH, name)
- amount = @item_amount[item]
- if $imported["BattleEngineMelody"]
- hash = YEM::BATTLE_ENGINE::ITEM_SETTINGS
- text = sprintf(hash[:text], amount)
- self.contents.font.size = hash[:size]
- self.contents.font.color = text_color(hash[:colour])
- else
- text = sprintf(":%2d", amount)
- end
- self.contents.draw_text(xx, yy, contents.width-4, WLH, text, 2)
- end
- end
- #==============================================================================
- # ** Scene_Disassemble
- #==============================================================================
- class Scene_Disassemble < Scene_Base
- #--------------------------------------------------------------------------
- # * Start processing
- #--------------------------------------------------------------------------
- def start
- super
- create_menu_background
- @help_window = Window_Help.new
- @item_window = Window_Disassemble.new(@help_window)
- @contents_window = Window_DisassembleContents.new(@item_window)
- create_command_window
- end
- #--------------------------------------------------------------------------
- # * Termination Processing
- #--------------------------------------------------------------------------
- def terminate
- super
- dispose_menu_background
- @command_window.dispose
- @help_window.dispose
- @item_window.dispose
- @contents_window.dispose
- end
- #--------------------------------------------------------------------------
- # * Frame Update
- #--------------------------------------------------------------------------
- def update
- super
- update_menu_background
- if @command_window.active
- update_command_selection
- elsif @item_window.active
- update_item_selection
- end
- end
- #--------------------------------------------------------------------------
- # * Create Command Window
- #--------------------------------------------------------------------------
- def create_command_window
- array = []
- array.push(SSS::DISASSEMBLE_ITEM)
- array.push(SSS::DISASSEMBLE_WEAPON)
- array.push(SSS::DISASSEMBLE_ARMOR)
- array.push(SSS::DISASSEMBLE_EXIT)
- width = Graphics.width
- @command_window = Window_Command.new(width, array, array.size, 1, 8)
- @command_window.y = @help_window.y + @help_window.height
- @last_command_index = 0
- end
- #--------------------------------------------------------------------------
- # * Update Command Selection
- #--------------------------------------------------------------------------
- def update_command_selection
- @command_window.update
- if @last_command_index != @command_window.index
- @last_command_index = @command_window.index
- @item_window.item_type = @last_command_index
- @contents_window.refresh
- end
- if Input.trigger?(Input::B)
- Sound.play_cancel
- $scene = Scene_Map.new
- elsif Input.trigger?(Input::C)
- Sound.play_decision
- case @command_window.index
- when 3
- $scene = Scene_Map.new
- else
- @command_window.active = false
- @item_window.active = true
- @item_window.index = 0 if @item_window.index == -1
- end
- end
- end
- #--------------------------------------------------------------------------
- # * Update Item Selection
- #--------------------------------------------------------------------------
- def update_item_selection
- @item_window.update
- if @last_item_index != @item_window.index
- @last_item_index = @item_window.index
- @contents_window.refresh
- end
- if Input.trigger?(Input::B)
- Sound.play_cancel
- @command_window.active = true
- @item_window.active = false
- elsif Input.repeat?(Input::C)
- disassemble_item = @item_window.item
- if disassemble_item.nil?
- Sound.play_buzzer
- else
- Sound.play_shop
- $game_party.lose_item(disassemble_item, 1)
- for item in disassemble_item.disassembled_items
- next if item.nil?
- $game_party.gain_item(item, 1)
- end
- @item_window.refresh
- @item_window.index = [@item_window.item_max, @item_window.index].min
- @contents_window.refresh
- end
- end
- end
- end
- #===============================================================================
- #
- # END OF FILE
- #
- #===============================================================================
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement