Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #==============================================================================
- # DSI Dungeon Rental System
- # -- Last Updated: 2017.03.9
- # -- Author: dsiver144
- # -- Level: Normal
- # -- Requires: n/a
- #==============================================================================
- $imported = {} if $imported.nil?
- $imported["DSI-DungeonRentalSystem"] = true
- #==============================================================================
- # + Updates
- # =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
- # 2017.02.21 - Finish first version.
- # 2017.02.21 - Fixing bugs.
- # - Add notetag for purchase price.
- # 2017.03.09 - Edit for 6 slots.
- #==============================================================================
- # + Instructions
- # =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
- # To install this script, open up your script editor and copy/paste this script
- # to an open slot below ?? Materials/?f?? but above ?? Main. Remember to save.
- # =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
- # + WEAPONS NOTETAGS:
- # <rental_tool> : Define a tool
- # <rental_price: x> : Set rent price for tool
- # <purchase_price: x> : Set purchase price for tool
- # + Script Call:
- # SceneManager.call(Scene_DungeonRental) -> Open the rental shop scene
- #==============================================================================
- # + Compatibility
- # =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
- # This script is made strictly for RPG Maker VX Ace. It is highly unlikely that
- # it will run with RPG Maker VX without adjusting.
- #==============================================================================
- module DSIVER144
- module RENTAL_SYSTEM
- # New here!
- RENTAL_TOOL_ID = [13,14,15,16,17,18] # ID of tool in database
- # Need 6 id for this array.
- # It will automatically
- # remove the last one if
- # there are more than 6 object
- RENTAL_TEXTS = {
- :title => "Dungeon Rental System",
- :purchased => "Purchased!",
- :rented => "Rent!",
- :rent_price => "Rent price: ",
- :buy_price => "Buy price: ",
- }
- PURCHASED_COLOR = Color.new(0,255,102) # Red, Green, Blue
- RENT_COLOR = Color.new(255,102,0) # Red, Green, Blue
- #-------------------------------------------------------------------------
- # Don't touch this please
- #-------------------------------------------------------------------------
- TOOL_REGEXP = /<rental_tool>/i
- PRICE_REGEXP = /<rental_price:\s*(\w+)>/i
- PURCHASE_REGEXP = /<purchase_price:\s*(\w+)>/i
- end # RENTAL_SYSTEM
- end # DSIVER144
- if !$imported["DSI-Bitmap"]
- msgbox_p("Please put DSI-Bitmap script on top of this script!")
- exit
- end
- include DSIVER144::RENTAL_SYSTEM
- #==============================================================================
- # DataManager
- #==============================================================================
- module DataManager
- #--------------------------------------------------------------------------
- # alias method: load_database
- #--------------------------------------------------------------------------
- class <<self; alias load_database_rental_tool load_database; end
- def self.load_database
- load_database_rental_tool
- load_notetags_rental_tools
- end
- #--------------------------------------------------------------------------
- # Load Notetag Rental Weapons
- #--------------------------------------------------------------------------
- def self.load_notetags_rental_tools
- for weapon in $data_weapons
- next if weapon.nil?
- weapon.load_notetags_rental_tool
- end
- end
- end # DataManager
- #==============================================================================
- # ?? RPG::Weapon
- #==============================================================================
- class RPG::Weapon
- #--------------------------------------------------------------------------
- # public instance variables
- #--------------------------------------------------------------------------
- attr_accessor :rental_tool
- attr_accessor :rental_price
- attr_accessor :purchase_price
- #--------------------------------------------------------------------------
- # common cache: load_notetags_sani
- #--------------------------------------------------------------------------
- def load_notetags_rental_tool
- @rental_tool = false
- @rental_price = 0
- @purchase_price = self.price
- self.note.split(/[\r\n]+/).each do |line|
- if line =~ TOOL_REGEXP
- @rental_tool = true
- end
- if line =~ PRICE_REGEXP
- @rental_price = $1.to_i
- end
- if line =~ PURCHASE_REGEXP
- @purchase_price = $1.to_i
- end
- end
- end
- end # RPG::Weapon
- class Game_System
- attr_accessor :rental_list
- attr_accessor :rental_tool
- attr_accessor :bought_tools
- alias_method(:dsiver144_rental_system_init, :initialize)
- #--------------------------------------------------------------------------
- # alias method: initialize
- #--------------------------------------------------------------------------
- def initialize
- @rental_list = []
- @rental_tool = 0
- @bought_tools = []
- dsiver144_rental_system_init
- end
- end # Game_System
- class Window_RentalTitle < Window_Base
- #--------------------------------------------------------------------------
- # new method: draw_title
- #--------------------------------------------------------------------------
- def draw_title
- contents.clear
- draw_text(0,0,contents_width,contents_height,RENTAL_TEXTS[:title],1)
- end
- end # Window_RentalTitle
- class Window_RentalList < Window_HorzCommand
- #--------------------------------------------------------------------------
- # * Get Window Width
- #--------------------------------------------------------------------------
- def window_width
- return 360
- end
- #--------------------------------------------------------------------------
- # * Get Activation State of OK Processing
- #--------------------------------------------------------------------------
- def ok_enabled?
- return false
- end
- #--------------------------------------------------------------------------
- # new method: current_rent_state
- #--------------------------------------------------------------------------
- def current_rent_state
- if current_data
- return current_data[:name].split("-")[1].to_i
- end
- end
- #--------------------------------------------------------------------------
- # new method: current_price_state
- #--------------------------------------------------------------------------
- def current_price_state
- if current_data
- return current_data[:name].split("-")[3].to_i
- end
- end
- #--------------------------------------------------------------------------
- # new method: current_bought_state
- #--------------------------------------------------------------------------
- def current_bought_state
- if current_data
- return current_data[:name].split("-")[2].to_i
- end
- end
- #--------------------------------------------------------------------------
- # new method: current_tool
- #--------------------------------------------------------------------------
- def current_tool
- current_data ? $data_weapons[current_data[:name].split("-")[0].to_i] : nil
- end
- #--------------------------------------------------------------------------
- # overwritten method: make_command_list
- #--------------------------------------------------------------------------
- def make_command_list
- tool_array = RENTAL_TOOL_ID[0..6]
- tool_array.each do |id|
- status = $game_system.rental_tool != id
- status2 = !$game_system.bought_tools.include?(id)
- status3 = $game_party.gold >= $data_weapons[id].rental_price
- check = status ? 1 : 0
- check2 = status2 ? 1 : 0
- check3 = status3 ? 1 : 0
- add_command("#{id}-#{check}-#{check2}-#{check3}", :ok, status && status2)
- end
- end
- #--------------------------------------------------------------------------
- # * Draw Item
- #--------------------------------------------------------------------------
- def draw_item(index)
- rect = item_rect_for_text(index)
- tool_id = @list[index][:name].split("-")[0].to_i
- icon_index = $data_weapons[tool_id].icon_index
- draw_icon(icon_index,rect.x,rect.y + 3,command_enabled?(index))
- #draw_text(item_rect_for_text(index), command_name(index), alignment)
- end
- #--------------------------------------------------------------------------
- # * Get Window Height
- #--------------------------------------------------------------------------
- def window_height
- fitting_height(visible_line_number) + 12
- end
- #--------------------------------------------------------------------------
- # * Get Digit Count
- #--------------------------------------------------------------------------
- def col_max
- return 7
- end
- #--------------------------------------------------------------------------
- # * Get Item Width
- #--------------------------------------------------------------------------
- def item_height
- return 32
- end
- #--------------------------------------------------------------------------
- # * Get Item Width
- #--------------------------------------------------------------------------
- def item_width
- return 32
- end
- #--------------------------------------------------------------------------
- # * Get Spacing for Items Arranged Side by Side
- #--------------------------------------------------------------------------
- def spacing
- return 16
- end
- end # Window_RentalList
- class Window_RentalAction < Window_Command
- attr_accessor :rental_window
- def initialize(x,y,rental_window)
- @rental_window = rental_window
- super(x,y)
- end
- #--------------------------------------------------------------------------
- # * Processing When OK Button Is Pressed
- #--------------------------------------------------------------------------
- def process_ok
- if current_item_enabled?
- #Sound.play_ok
- Input.update
- deactivate
- call_ok_handler
- else
- Sound.play_buzzer
- end
- end
- #--------------------------------------------------------------------------
- # overwrite method: dispose
- #--------------------------------------------------------------------------
- def dispose
- super
- @rental_window = nil
- end
- #--------------------------------------------------------------------------
- # overwrite method: make_command_list
- #--------------------------------------------------------------------------
- def make_command_list
- if @rental_window
- if @rental_window.current_bought_state == 1
- if @rental_window.current_rent_state == 1
- if $game_system.rental_tool > 0 && @rental_window.current_tool.id != $game_system.rental_tool
- add_command("Rent Tool", :rent, false)
- add_command("Buy Tool", :buy, true)
- else
- add_command("Rent Tool", :rent, true)
- add_command("Buy Tool", :buy, true)
- end
- else
- add_command("Return Tool", :return, true)
- add_command("Buy Tool", :buy, false)
- end
- else
- add_command("Rent Tool", :rent, false)
- add_command("Buy Tool", :buy, false)
- end
- end
- add_command("Cancel", :cancel, true)
- end
- #--------------------------------------------------------------------------
- # overwrite method: window_width
- #--------------------------------------------------------------------------
- def window_width
- return 160
- end
- end # Window_RentalAction
- class Window_RentalBackgroud < Window_Base
- #--------------------------------------------------------------------------
- # new method: fill_info_panel
- #--------------------------------------------------------------------------
- def fill_info_panel
- color = Color.new(255,255,255,150)
- contents.fill_rect(8,70,contents_width - 8*2,contents_height-80,color)
- end
- #--------------------------------------------------------------------------
- # * Draw Text with Control Characters
- #--------------------------------------------------------------------------
- def draw_text_ex2(x, y, text, width)
- #reset_font_settings
- text = convert_escape_characters(text)
- pos = {:x => x, :y => y, :new_x => x, :height => calc_line_height(text)}
- process_character2(text.slice!(0, 1), text, pos, width) until text.empty?
- end
- def process_character2(c, text, pos, width)
- c = ' ' if @convert_newlines && c == "\n"
- if @wordwrap && c =~ /[ \t]/
- c = '' if @collapse_whitespace && @lastc =~ /[\s\n\f]/
- if pos[:x] + get_next_word_size(c, text) > width - @right_margin
- process_new_line(text, pos)
- else
- process_normal_character(c, pos)
- end
- @lastc = c
- else
- @lastc = c
- #process_character2(c, text, pos, width)
- end
- end
- #--------------------------------------------------------------------------
- # new method: draw_item_info
- #--------------------------------------------------------------------------
- def draw_item_info(item)
- contents.clear
- fill_info_panel
- x = 15
- y = 60
- contents.font.size = 20
- width = contents_width - 8*2
- height = contents_height-80
- change_color(Color.new(253,213,14))
- draw_text(x,y,width,fitting_height(1),item.name)
- y += 20
- change_color(normal_color)
- contents.font.size = 18
- text = RENTAL_TEXTS[:rent_price]
- draw_text(x,y,width,fitting_height(1),text+"#{item.rental_price}")
- if $game_system.bought_tools.include?(item.id)
- contents.font.size = 22
- change_color(PURCHASED_COLOR)
- text = RENTAL_TEXTS[:purchased]
- draw_text(x+230,y,width,fitting_height(1),text)
- change_color(normal_color)
- contents.font.size = 18
- end
- if $game_system.rental_tool == item.id
- contents.font.size = 22
- change_color(RENT_COLOR)
- text = RENTAL_TEXTS[:rented]
- draw_text(x+250,y,width,fitting_height(1),text)
- change_color(normal_color)
- contents.font.size = 18
- end
- y += 20
- text = RENTAL_TEXTS[:buy_price]
- draw_text(x,y,width,fitting_height(1),text + "#{item.purchase_price}")
- contents.font.size = 20
- draw_text(x,y + 28,width - 32,fitting_height(1)," Description", 1)
- contents.font.size = 18
- y += 85
- x += 12
- color = Color.new(0,0,0,200)
- contents.fill_rect(20,180,contents_width - 20*2,140,color)
- @right_margin = 200
- des_bitmap = Bitmap.new(312,128)
- des_bitmap.font = contents.font
- des_bitmap.turn_on_wordwraping
- des_bitmap.draw_text_ex(0,0,item.description)
- contents.blt(x,y, des_bitmap, des_bitmap.rect)
- end
- #--------------------------------------------------------------------------
- # new method: refresh
- #--------------------------------------------------------------------------
- def refresh
- contents.clear
- fill_info_panel
- end
- end # Window_RentalBackgroud
- class Scene_DungeonRental < Scene_Base
- #--------------------------------------------------------------------------
- # method: start
- #--------------------------------------------------------------------------
- def start
- super
- create_main_windows
- end
- #--------------------------------------------------------------------------
- # new method: create_main_windows
- #--------------------------------------------------------------------------
- def create_main_windows
- @title_window = Window_RentalTitle.new(0,0,Graphics.width,48)
- @title_window.draw_title
- bg_y = @title_window.height
- bg_height = Graphics.height - @title_window.height
- bg_width = Graphics.width - 160
- @background_window = Window_RentalBackgroud.new(0,bg_y,bg_width,bg_height)
- @background_window.refresh
- act_x = @background_window.x + @background_window.width
- act_y = bg_y
- act_height = @background_window.fitting_height(1)
- act_width = Graphics.width - @background_window.width
- @action_name_window = Window_Base.new(act_x,act_y,act_width,act_height)
- ct_w = @action_name_window.contents_width
- ct_h = @action_name_window.contents_height
- @action_name_window.draw_text(0,0,ct_w,ct_h,"Actions",1)
- @gold_window = Window_Gold.new
- @gold_window.x = act_x
- @gold_window.y = Graphics.height - @gold_window.height
- @rental_window = Window_RentalList.new(16,bg_y+16)
- @rental_window.opacity = 0
- new_x = 0.5*(@background_window.width - (32+16)*6) - 5
- @rental_window.back_opacity = 0
- @rental_window.x = new_x
- @last_index = @rental_window.index
- @background_window.draw_item_info(@rental_window.current_tool)
- @rental_act_window = Window_RentalAction.new(act_x,act_height+act_y,@rental_window)
- @rental_act_window.refresh
- @rental_act_window.set_handler(:rent, method(:command_rent))
- @rental_act_window.set_handler(:buy, method(:command_buy))
- @rental_act_window.set_handler(:return, method(:command_return))
- @rental_act_window.set_handler(:cancel, method(:return_scene))
- end
- #--------------------------------------------------------------------------
- # new method: return_scene
- #--------------------------------------------------------------------------
- def return_scene
- super
- Sound.play_cancel
- end
- #--------------------------------------------------------------------------
- # new method: command_rent
- #--------------------------------------------------------------------------
- def command_rent
- if $game_party.gold >= @rental_window.current_tool.rental_price
- $game_system.rental_tool = @rental_window.current_tool.id
- $game_party.lose_gold(@rental_window.current_tool.rental_price)
- $game_party.gain_item(@rental_window.current_tool,1)
- Sound.play_ok
- else
- Sound.play_buzzer
- end
- refresh_windows
- @rental_act_window.activate
- end
- #--------------------------------------------------------------------------
- # new method: command_return
- #--------------------------------------------------------------------------
- def command_return
- if $game_system.rental_tool > 0
- tool = $data_weapons[$game_system.rental_tool]
- #~ $game_party.gain_gold(tool.rental_price)
- $game_party.lose_item(tool,1,true)
- $game_system.rental_tool = 0
- Sound.play_ok
- end
- refresh_windows
- @rental_act_window.activate
- end
- #--------------------------------------------------------------------------
- # new method: command_buy
- #--------------------------------------------------------------------------
- def command_buy
- if $game_party.gold >= @rental_window.current_tool.purchase_price
- $game_system.bought_tools.push(@rental_window.current_tool.id)
- $game_party.lose_gold(@rental_window.current_tool.purchase_price)
- $game_party.gain_item(@rental_window.current_tool,1)
- Sound.play_ok
- else
- Sound.play_buzzer
- end
- refresh_windows
- @rental_act_window.activate
- end
- #--------------------------------------------------------------------------
- # new method: refresh_windows
- #--------------------------------------------------------------------------
- def refresh_windows
- @rental_window.refresh
- @rental_act_window.refresh
- @background_window.draw_item_info(@rental_window.current_tool)
- @gold_window.refresh
- end
- #--------------------------------------------------------------------------
- # new method: update
- #--------------------------------------------------------------------------
- def update
- super
- if @last_index != @rental_window.index
- @last_index = @rental_window.index
- @rental_window.current_rent_state
- @background_window.draw_item_info(@rental_window.current_tool)
- @rental_act_window.refresh
- end
- end
- end # Scene_DungeonRental
- class Window_ShopSell < Window_ItemList
- alias_method(:dsiver144_shop_enable_tool, :enable?)
- def enable?(item)
- dsiver144_shop_enable_tool(item) && !item.rental_tool
- end
- end # Window_ShopSell
- #===============================================================================
- # * END OF FILE
- #===============================================================================
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement