Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #==============================================================================
- # Recycling System
- # Version 1.0
- # By Szyu
- #
- # About:
- # Recycle your items to regain material items.
- #
- # Instructions:
- # - Place below "Materials" but above "Main Process".
- # - Access the recycling menu from game menu, or if disabled, by calling
- # "SceneManager.call(Scene_Recycling)"
- #
- # How to Use:
- # - "<recycling> content </recycling>" marks the area for recycling
- # example:
- # <recycling>
- # i: 2, 50%, 4 => Recycling gives a 50% chance to obtain 1-4 items of id 2
- # w: 13, 70%, 8 => Recycling gives a 70% chance to obtain 1-8 weapons of id 13
- # a: 7, 10%, 1 => Recycling gives a 10% chance to obtain 1 armor of id 7
- # </recycling>
- #
- # Requires:
- # - RPG Maker VX Ace
- #
- # Terms of Use:
- # - Free for commercal and non-commercial use. Please list me
- # in the credits to support my work.
- #
- # Pastebin:
- # http://pastebin.com/0gRUSmcg
- #
- #==============================================================
- # * Configuration
- #==============================================================
- # If you want to use recycling from the menu, set this to true, else false
- MENU_RECYCLING_VOCAB = "Recycling"
- RECYCLING_IN_MENU = true
- # These phrases are shown when you recycle an item, based on its success
- RECYCLING_RESULT_PHRASE = {
- :success => "Success!",
- :failure => "Recycling process failed!"
- }
- # These sounds are played when you recycle an item, based on its success
- # (Taken from SE)
- RECYCLING_SOUNDS = {
- :success => "Item1",
- :failure => "Water1"
- }
- #==============================================================
- # * Scene_Recycling
- #==============================================================
- class Scene_Recycling < Scene_ItemBase
- def start
- super
- create_help_window
- create_category_window
- create_recycling_window
- create_item_window
- end
- def create_category_window
- @category_window = Window_RecyclingCategory.new
- @category_window.viewport = @viewport
- @category_window.help_window = @help_window
- @category_window.y = @help_window.height
- @category_window.set_handler(:ok, method(:on_category_ok))
- @category_window.set_handler(:cancel, method(:return_scene))
- end
- def create_recycling_window
- wx = 240
- wy = @category_window.y + @category_window.height
- ww = Graphics.width - wx
- wh = Graphics.height - wy
- @recycling_window = Window_RecyclingOutput.new(wx,wy,ww,wh)
- @recycling_window.viewport = @viewport
- end
- def create_item_window
- wy = @category_window.y + @category_window.height
- wh = Graphics.height - wy
- @item_window = Window_RecyclingItemList.new(0, wy, 240, wh)
- @item_window.viewport = @viewport
- @item_window.help_window = @help_window
- @item_window.set_handler(:ok, method(:on_item_ok))
- @item_window.set_handler(:cancel, method(:on_item_cancel))
- @item_window.recycling_window = @recycling_window
- @category_window.item_window = @item_window
- end
- def show_result_window(recycled)
- wdth = Graphics.width / 2
- @result_window = Window_RecyclingResult.new((Graphics.width - wdth) / 2, wdth, recycled)
- @result_window.set_handler(:ok, method(:on_result_seen))
- @result_window.set_handler(:cancel, method(:on_result_seen))
- @result_window.show.activate
- end
- def on_category_ok
- @item_window.activate
- @item_window.select_last
- end
- def on_item_ok
- recycle_item
- end
- def on_item_cancel
- @item_window.unselect
- @category_window.activate
- end
- def on_result_seen
- @result_window.hide.deactivate
- @result_window = nil
- @item_window.refresh
- @item_window.activate
- end
- def recycle_item
- item = @item_window.item
- recycled = []
- item.recycling.each do |rec|
- chance = rec[2]
- amount = rand(rec[3]) + 1
- gamble = rand(101)
- if gamble <= chance
- case rec[0]
- when "i"; ri = $data_items[rec[1]]
- when "w"; ri = $data_weapons[rec[1]]
- when "a"; ri = $data_armors[rec[1]]
- end
- $game_party.gain_item(ri, amount)
- recycled.push([ri, amount])
- end
- end
- $game_party.gain_item(item, -1, false)
- if recycled.size > 0
- rsf = RECYCLING_SOUNDS[:success]
- else
- rsf = RECYCLING_SOUNDS[:failure]
- end
- RPG::SE.new(rsf, 100, 50).play
- show_result_window(recycled)
- end
- end
- #==============================================================
- # * Scene_Menu
- #==============================================================
- class Scene_Menu < Scene_MenuBase
- alias add_recycling_menu_entry create_command_window
- def create_command_window
- add_recycling_menu_entry
- @command_window.set_handler(:recycling, method(:open_recycling)) if RECYCLING_IN_MENU
- end
- def open_recycling
- SceneManager.call(Scene_Recycling)
- end
- end
- #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
- #==============================================================
- # * Window_RecyclingCategory
- #==============================================================
- class Window_RecyclingCategory < Window_HorzCommand
- attr_reader :item_window
- def initialize
- super(0, 0)
- end
- def window_width
- Graphics.width
- end
- def col_max
- return 3
- end
- def update
- super
- @item_window.category = current_symbol if @item_window
- end
- def make_command_list
- add_command(Vocab::item, :item)
- add_command(Vocab::weapon, :weapon)
- add_command(Vocab::armor, :armor)
- end
- def item_window=(item_window)
- @item_window = item_window
- update
- end
- end
- #==============================================================
- # * Window_RecyclingItemList
- #==============================================================
- class Window_RecyclingItemList < Window_Selectable
- attr_reader :recycling_window
- def initialize(x, y, width, height)
- super
- @category = :none
- @data = []
- end
- def category=(category)
- return if @category == category
- @category = category
- refresh
- self.oy = 0
- end
- def col_max
- return 1
- end
- def item_max
- @data ? @data.size : 1
- end
- def item
- @data && index >= 0 ? @data[index] : nil
- end
- def current_item_enabled?
- enable?(@data[index])
- end
- def include?(item)
- case @category
- when :item
- item.is_a?(RPG::Item)
- when :weapon
- item.is_a?(RPG::Weapon)
- when :armor
- item.is_a?(RPG::Armor)
- else
- false
- end
- end
- def enable?(item)
- return item != nil
- end
- def make_item_list
- @data = $game_party.all_items.select {|item| include?(item) && item.recycling != nil && item.recycling.size > 0 }
- @data.push(nil) if include?(nil)
- end
- def select_last
- select(@data.index($game_party.last_item.object) || 0)
- end
- def draw_item(index)
- item = @data[index]
- if item
- rect = item_rect(index)
- rect.width -= 4
- draw_item_name(item, rect.x, rect.y, true, width-70)
- draw_item_number(rect, item)
- end
- end
- def draw_item_number(rect, item)
- draw_text(rect, sprintf(":%2d", $game_party.item_number(item)), 2)
- end
- def update_help
- @help_window.set_item(item)
- @recycling_window.item = item if @recycling_window
- end
- def refresh
- make_item_list
- create_contents
- draw_all_items
- end
- def recycling_window=(recycling_window)
- @recycling_window = recycling_window
- update
- end
- def process_ok
- if current_item_enabled?
- Input.update
- deactivate
- call_ok_handler
- else
- Sound.play_buzzer
- end
- end
- alias rec_us_win unselect
- def unselect
- rec_us_win
- @recycling_window.contents.clear
- end
- end
- #==============================================================
- # * Window_RecyclingOutput
- #==============================================================
- class Window_RecyclingOutput < Window_Selectable
- def initialize(x,y,w,h)
- super(x,y,w,h)
- @item = nil
- end
- def item=(item)
- @item = item
- refresh
- end
- def refresh
- contents.clear
- return if !@item
- draw_recycling_output
- end
- def draw_recycling_output
- dx = 0; dy = 0
- dw = (contents.width)
- @item.recycling.each do |rec_item|
- draw_recycling_item(rec_item, dx, dy, dw)
- dy += line_height
- end
- end
- def draw_recycling_item(rec_item, dx, dy, dw)
- draw_background_box(dx, dy, dw)
- change_color(system_color)
- case rec_item[0]
- when "i"; draw_text(dx+4, dy, dw-8, line_height, $data_items[rec_item[1]].name)
- when "w"; draw_text(dx+4, dy, dw-8, line_height, $data_weapons[rec_item[1]].name)
- when "a"; draw_text(dx+4, dy, dw-8, line_height, $data_armors[rec_item[1]].name)
- end
- change_color(normal_color)
- draw_text(dx+4, dy, dw-8, line_height, rec_item[2].to_s + "%" , 2)
- end
- def draw_background_box(dx, dy, dw)
- colour = Color.new(0, 0, 0, translucent_alpha/2)
- rect = Rect.new(dx+1, dy+1, dw-2, line_height-2)
- contents.fill_rect(rect, colour)
- end
- end
- #==============================================================
- # * Window_RecyclingResult
- #==============================================================
- class Window_RecyclingResult < Window_Selectable
- def initialize(x, w, recycled)
- @items = recycled
- h = line_height * (@items.size + 2)
- super(x, (Graphics.height - h) / 2, w, h)
- self.z = 999
- refresh
- end
- def refresh
- contents.clear
- return if !@items
- draw_recycling_output
- end
- def draw_recycling_output
- if @items.size == 0
- draw_text(4, 0, contents.width - 8, line_height, RECYCLING_RESULT_PHRASE[:failure])
- else
- draw_text(4, 0, contents.width - 8, line_height, RECYCLING_RESULT_PHRASE[:success])
- dx = 0
- dy = line_height
- dw = contents.width
- @items.each do |rec_item|
- draw_recycling_item(rec_item, dx, dy, dw)
- dy += line_height
- end
- end
- end
- def draw_recycling_item(rec_item, dx, dy, dw)
- change_color(system_color)
- draw_text(dx+4, dy, dw-8, line_height, rec_item[0].name)
- change_color(normal_color)
- draw_text(dx+4, dy, dw-8, line_height, "x" + rec_item[1].to_s , 2)
- end
- end
- #==============================================================
- # * Window_MenuCommand
- #==============================================================
- class Window_MenuCommand < Window_Command
- alias add_recycling_menu_entry add_main_commands
- def add_main_commands
- add_recycling_menu_entry
- add_command(MENU_RECYCLING_VOCAB, :recycling) if RECYCLING_IN_MENU
- end
- end
- #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
- #==============================================================
- # * Initialize BaseItems
- #==============================================================
- module DataManager
- class << self
- alias load_db_recycling_sz load_database
- end
- def self.load_database
- load_db_recycling_sz
- load_recycling_items
- end
- def self.load_recycling_items
- groups = [$data_items, $data_weapons, $data_armors]
- for group in groups
- for obj in group
- next if obj.nil?
- obj.load_recycling_notetags_sz
- end
- end
- end
- end
- #==============================================================
- # * Content of Recycling Items
- #==============================================================
- class RPG::BaseItem
- attr_accessor :recycling
- def load_recycling_notetags_sz
- @recycling = []
- @scan_recycling = false
- self.note.split(/[\r\n]+/).each do |line|
- case line.downcase
- when /<(?:recycling?)>/i
- @scan_recycling = true
- when /<\/(?:recycling?)>/i
- @scan_recycling = false
- else
- if @scan_recycling == true
- scan_recycling_data(line)
- end
- end
- end
- end
- def scan_recycling_data(line)
- return unless line =~ /(\w+):\s*(\d+)\s*,?\s*(\d+)?%?\s*,\s*(\d+)?/i ? true : false
- type = $1.to_s
- item_id = $2.to_i
- chance = $3.to_i || 100
- amount = $4.to_i || 1
- @recycling.push([type, item_id, chance, amount])
- end
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement