Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- =begin
- #==============================================================================
- # Improved Shop
- # By gerkrt/gerrtunk
- # Version: 1
- # License: GPL, credits
- #==============================================================================
- This script add a lost feature from old rpgmakers: the option to select if you
- wanted to buy, sell or both.
- Also adds the option of modifing the price based in %. Buy and sell discount are
- separated, so you can make any combination.
- --------INSTRUCTIONS---------
- Before calling a shop, call this script:
- $game_temp.type = 1
- $game_temp.buy_discount = 1.2
- $game_temp.sell_discount = 0.8
- These is a call example.
- $game_temp.type : When 2 player can only sell. When 1 player can only buy. When 0
- can do both.
- $game_temp.buy_discount : When you buy items the price is multiplied with this number.
- $game_temp.sell_discount : When you sell items the price is multiplied with this number.
- Note that 0.2 , the . is like a ,.
- After the sop call, these values are restored to default ones. This means that
- you can call a shop wiyhout adding the script call and that it will use:
- Type = Buy & Sell
- Buy & Sell discounts = 1
- =end
- class Game_Temp
- attr_accessor :type # 2: Sell/1: Buy/0: Both
- attr_accessor :buy_discount # Buy discount +- %
- attr_accessor :sell_discount # Sell discount +- %
- alias gt_init initialize
- def initialize
- gt_init
- @type= 0
- @buy_discount = 1
- @sell_discount= 1
- end
- end
- class Scene_Shop
- #--------------------------------------------------------------------------
- # * Frame Update (when command window is active)
- #--------------------------------------------------------------------------
- def update_command
- # If B button was pressed
- if Input.trigger?(Input::B)
- # Play cancel SE
- $game_system.se_play($data_system.cancel_se)
- # Reset shop variables
- $game_temp.type = 0
- $game_temp.buy_discount = 1
- $game_temp.sell_discount = 1
- # Switch to map screen
- $scene = Scene_Map.new
- return
- end
- # If C button was pressed
- if Input.trigger?(Input::C)
- # Branch by command window cursor position
- case @command_window.index
- when 0 # buy
- if $game_temp.type== 0 or $game_temp.type== 1
- # Play decision SE
- $game_system.se_play($data_system.decision_se)
- # Change windows to buy mode
- @command_window.active = false
- @dummy_window.visible = false
- @buy_window.active = true
- @buy_window.visible = true
- @buy_window.refresh
- @status_window.visible = true
- else
- $game_system.se_play($data_system.cancel_se)
- return
- end
- when 1 # sell
- if $game_temp.type== 0 or $game_temp.type== 2
- # Play decision SE
- $game_system.se_play($data_system.decision_se)
- # Change windows to sell mode
- @command_window.active = false
- @dummy_window.visible = false
- @sell_window.active = true
- @sell_window.visible = true
- @sell_window.refresh
- else
- $game_system.se_play($data_system.cancel_se)
- return
- end
- when 2 # quit
- # Play decision SE
- $game_system.se_play($data_system.decision_se)
- # Reset shop variables
- $game_temp.type = 0
- $game_temp.buy_discount = 1
- $game_temp.sell_discount = 1
- # Switch to map screen
- $scene = Scene_Map.new
- end
- return
- end
- end
- #--------------------------------------------------------------------------
- # * Frame Update (when buy window is active)
- #--------------------------------------------------------------------------
- def update_buy
- # Set status window item
- @status_window.item = @buy_window.item
- # If B button was pressed
- if Input.trigger?(Input::B)
- # Play cancel SE
- $game_system.se_play($data_system.cancel_se)
- # Change windows to initial mode
- @command_window.active = true
- @dummy_window.visible = true
- @buy_window.active = false
- @buy_window.visible = false
- @status_window.visible = false
- @status_window.item = nil
- # Erase help text
- @help_window.set_text("")
- return
- end
- # If C button was pressed
- if Input.trigger?(Input::C)
- # Get item
- @item = @buy_window.item
- # If item is invalid, or price is higher than money possessed
- if @item == nil or @item.price > $game_party.gold
- # Play buzzer SE
- $game_system.se_play($data_system.buzzer_se)
- return
- end
- # Get items in possession count
- case @item
- when RPG::Item
- number = $game_party.item_number(@item.id)
- when RPG::Weapon
- number = $game_party.weapon_number(@item.id)
- when RPG::Armor
- number = $game_party.armor_number(@item.id)
- end
- # If 99 items are already in possession
- if number == 99
- # Play buzzer SE
- $game_system.se_play($data_system.buzzer_se)
- return
- end
- # Play decision SE
- $game_system.se_play($data_system.decision_se)
- # Calculate maximum amount possible to buy
- rebaja = @item.price*$game_temp.buy_discount
- max = @item.price == 0 ? 99 : $game_party.gold / rebaja.to_i
- max = [max, 99 - number].min
- # Change windows to quantity input mode
- @buy_window.active = false
- @buy_window.visible = false
- descuento = @item.price * $game_temp.buy_discount
- @number_window.set(@item, max, descuento.to_i)
- @number_window.active = true
- @number_window.visible = true
- end
- end
- #--------------------------------------------------------------------------
- # * Frame Update (when sell window is active)
- #--------------------------------------------------------------------------
- def update_sell
- # If B button was pressed
- if Input.trigger?(Input::B)
- # Play cancel SE
- $game_system.se_play($data_system.cancel_se)
- # Change windows to initial mode
- @command_window.active = true
- @dummy_window.visible = true
- @sell_window.active = false
- @sell_window.visible = false
- @status_window.item = nil
- # Erase help text
- @help_window.set_text("")
- return
- end
- # If C button was pressed
- if Input.trigger?(Input::C)
- # Get item
- @item = @sell_window.item
- # Set status window item
- @status_window.item = @item
- # If item is invalid, or item price is 0 (unable to sell)
- if @item == nil or @item.price == 0
- # Play buzzer SE
- $game_system.se_play($data_system.buzzer_se)
- return
- end
- # Play decision SE
- $game_system.se_play($data_system.decision_se)
- # Get items in possession count
- case @item
- when RPG::Item
- number = $game_party.item_number(@item.id)
- when RPG::Weapon
- number = $game_party.weapon_number(@item.id)
- when RPG::Armor
- number = $game_party.armor_number(@item.id)
- end
- # Maximum quanitity to sell = number of items in possession
- max = number
- # Change windows to quantity input mode
- @sell_window.active = false
- @sell_window.visible = false
- descuento = (@item.price * $game_temp.vend_desc) / 2
- @number_window.set(@item, max, descuento.to_i)
- @number_window.active = true
- @number_window.visible = true
- @status_window.visible = true
- end
- end
- #--------------------------------------------------------------------------
- # * Frame Update (when quantity input window is active)
- #--------------------------------------------------------------------------
- def update_number
- # If B button was pressed
- if Input.trigger?(Input::B)
- # Play cancel SE
- $game_system.se_play($data_system.cancel_se)
- # Set quantity input window to inactive / invisible
- @number_window.active = false
- @number_window.visible = false
- # Branch by command window cursor position
- case @command_window.index
- when 0 # buy
- # Change windows to buy mode
- @buy_window.active = true
- @buy_window.visible = true
- when 1 # sell
- # Change windows to sell mode
- @sell_window.active = true
- @sell_window.visible = true
- @status_window.visible = false
- end
- return
- end
- # If C button was pressed
- if Input.trigger?(Input::C)
- # Play shop SE
- $game_system.se_play($data_system.shop_se)
- # Set quantity input window to inactive / invisible
- @number_window.active = false
- @number_window.visible = false
- # Branch by command window cursor position
- case @command_window.index
- when 0 # buy
- # Buy process
- modificado = @number_window.number * @item.price * $game_temp.buy_discount
- $game_party.lose_gold(modificado.to_i)
- case @item
- when RPG::Item
- $game_party.gain_item(@item.id, @number_window.number)
- when RPG::Weapon
- $game_party.gain_weapon(@item.id, @number_window.number)
- when RPG::Armor
- $game_party.gain_armor(@item.id, @number_window.number)
- end
- # Refresh each window
- @gold_window.refresh
- @buy_window.refresh
- @status_window.refresh
- # Change windows to buy mode
- @buy_window.active = true
- @buy_window.visible = true
- when 1 # sell
- # Sell process
- modificado = (@item.price * $game_temp.vend_desc) / 2
- $game_party.gain_gold(@number_window.number * modificado.to_i)
- case @item
- when RPG::Item
- $game_party.lose_item(@item.id, @number_window.number)
- when RPG::Weapon
- $game_party.lose_weapon(@item.id, @number_window.number)
- when RPG::Armor
- $game_party.lose_armor(@item.id, @number_window.number)
- end
- # Refresh each window
- @gold_window.refresh
- @sell_window.refresh
- @status_window.refresh
- # Change windows to sell mode
- @sell_window.active = true
- @sell_window.visible = true
- @status_window.visible = false
- end
- return
- end
- end
- end
- #==============================================================================
- # ** Window_ShopCommand
- #------------------------------------------------------------------------------
- # This window is used to choose your business on the shop screen.
- #==============================================================================
- class Window_ShopCommand < Window_Selectable
- #--------------------------------------------------------------------------
- # * Object Initialization
- #--------------------------------------------------------------------------
- def initialize
- super(0, 64, 480, 64)
- self.contents = Bitmap.new(width - 32, height - 32)
- @item_max = 3
- @column_max = 3
- #Excepciones de tipo
- case $game_temp.type
- when 0; @commands = ["Comprar", "Vender", "Salir"]
- when 1; @commands = ["Comprar", "Vender", "Salir"]
- when 2; @commands = ["Comprar", "Vender", "Salir"]
- end
- refresh
- self.index = 0
- end
- #--------------------------------------------------------------------------
- # * Refresh
- #--------------------------------------------------------------------------
- def refresh
- self.contents.clear
- for i in 0...@item_max
- draw_item(i)
- end
- end
- #--------------------------------------------------------------------------
- # * Draw Item
- # index : item number
- #--------------------------------------------------------------------------
- def draw_item(index)
- x = 4 + index * 160
- #Excepciones de tipo
- case $game_temp.type
- when 1
- #Canvio de color de fuente y retorno de la misma
- if index == 1
- self.contents.font.color = disabled_color
- end
- if index == 2
- self.contents.font.color = normal_color
- end
- when 2
- #Canvio de color de fuente y retorno de la misma
- if index == 0
- self.contents.font.color = disabled_color
- end
- if index == 1...2
- self.contents.font.color = normal_color
- end
- end
- self.contents.draw_text(x, 0, 128, 32, @commands[index])
- end
- end
- #==============================================================================
- # ** Window_ShopBuy
- #------------------------------------------------------------------------------
- # This window displays buyable goods on the shop screen.
- #==============================================================================
- class Window_ShopBuy < Window_Selectable
- #--------------------------------------------------------------------------
- # * Draw Item
- # index : item number
- #--------------------------------------------------------------------------
- def draw_item(index)
- item = @data[index]
- # Get items in possession
- case item
- when RPG::Item
- number = $game_party.item_number(item.id)
- when RPG::Weapon
- number = $game_party.weapon_number(item.id)
- when RPG::Armor
- number = $game_party.armor_number(item.id)
- end
- # If price is less than money in possession, and amount in possession is
- # not 99, then set to normal text color. Otherwise set to disabled color
- if item.price * $game_temp.buy_discount <= $game_party.gold and number < 99
- self.contents.font.color = normal_color
- else
- self.contents.font.color = disabled_color
- end
- x = 4
- y = index * 32
- rect = Rect.new(x, y, self.width - 32, 32)
- self.contents.fill_rect(rect, Color.new(0, 0, 0, 0))
- bitmap = RPG::Cache.icon(item.icon_name)
- opacity = self.contents.font.color == normal_color ? 255 : 128
- self.contents.blt(x, y + 4, bitmap, Rect.new(0, 0, 24, 24), opacity)
- self.contents.draw_text(x + 28, y, 212, 32, item.name, 0)
- rebajado = item.price * $game_temp.buy_discount
- rebajado = rebajado.to_i
- self.contents.draw_text(x + 240, y, 88, 32, rebajado.to_s, 2)
- end
- end
- #==============================================================================
- # ** Window_ShopBuy
- #------------------------------------------------------------------------------
- # This window displays buyable goods on the shop screen.
- #==============================================================================
- class Window_ShopBuy < Window_Selectable
- #--------------------------------------------------------------------------
- # * Draw Item
- # index : item number
- #--------------------------------------------------------------------------
- def draw_item(index)
- item = @data[index]
- # Get items in possession
- case item
- when RPG::Item
- number = $game_party.item_number(item.id)
- when RPG::Weapon
- number = $game_party.weapon_number(item.id)
- when RPG::Armor
- number = $game_party.armor_number(item.id)
- end
- # If price is less than money in possession, and amount in possession is
- # not 99, then set to normal text color. Otherwise set to disabled color
- if item.price * $game_temp.buy_discount <= $game_party.gold and number < 99
- self.contents.font.color = normal_color
- else
- self.contents.font.color = disabled_color
- end
- x = 4
- y = index * 32
- rect = Rect.new(x, y, self.width - 32, 32)
- self.contents.fill_rect(rect, Color.new(0, 0, 0, 0))
- bitmap = RPG::Cache.icon(item.icon_name)
- opacity = self.contents.font.color == normal_color ? 255 : 128
- self.contents.blt(x, y + 4, bitmap, Rect.new(0, 0, 24, 24), opacity)
- self.contents.draw_text(x + 28, y, 212, 32, item.name, 0)
- rebajado = item.price * $game_temp.buy_discount
- rebajado = rebajado.to_i
- self.contents.draw_text(x + 240, y, 88, 32, rebajado.to_s, 2)
- end
- end
Advertisement
Add Comment
Please, Sign In to add comment