#============================================================================
# ** Modern Shop
#----------------------------------------------------------------------------
# vpcdmd
# 1.0
# 2/12/2008
#---
# ~ Originally requested by : speedolphins
#============================================================================
#--------------------------------------------------------------------------
# ** Scene_Modern_Shop
#--------------------------------------------------------------------------
class Scene_Modern_Shop
#--------------------------------------------------------------------------
# * Object Initialization
#--------------------------------------------------------------------------
def initialize(item)
@item = item
end
#--------------------------------------------------------------------------
# * Main
#--------------------------------------------------------------------------
def main
@sprite_set = Spriteset_Map.new
@help_window = Window_Help2.new
@help_window.opacity = 200
@command_window = Window_Command.new(160, ['take','place'])
@command_window.y = 64
@command_window.opacity = 200
@number_window = Window_ShopNumber.new
@number_window.active = false
@number_window.visible = false
@number_window.y = 64
@number_window.opacity = 200
@shopping_window = Window_ShoppingCart.new
@shopping_window.active = false
@shopping_window.visible = false
@objects = [@sprite_set, @help_window, @command_window, @number_window, @shopping_window]
Graphics.transition
loop do
Graphics.update
Input.update
@objects.each {|x| x.update}
update
if $scene != self
break
end
end
Graphics.freeze
@objects.each {|object| object.dispose}
end
#--------------------------------------------------------------------------
# * Frame Update
#--------------------------------------------------------------------------
def update
if @command_window.active
update_command
return
end
if @number_window.active
update_number
return
end
end
#--------------------------------------------------------------------------
# * Frame Update (when command window is active)
#--------------------------------------------------------------------------
def update_command
@help_window.set_text('Would you like to take or place '+@item.name+'?', 1)
if Input.trigger?(Input::B)
$game_system.se_play($data_system.cancel_se)
$scene = Scene_Map.new
return
end
if Input.trigger?(Input::C)
case @command_window.index
when 0 # buy
case @item
when RPG::Item
number = $game_party.temp_item_number(@item.id)
when RPG::Weapon
number = $game_party.temp_weapon_number(@item.id)
when RPG::Armor
number = $game_party.temp_armor_number(@item.id)
end
if number == 99
$game_system.se_play($data_system.buzzer_se)
@help_window.set_text('There\'s no room for '+@item.name+'s.', 1)
return
end
$game_system.se_play($data_system.decision_se)
max = @item.price == 0 ? 99 : $game_party.gold / @item.price
max = [max, 99 - number].min
@command_window.active = false
@command_window.visible = false
@number_window.set(@item, max, @item.price)
@number_window.active = true
@number_window.visible = true
when 1 # sell
case @item
when RPG::Item
number = $game_party.temp_item_number(@item.id)
when RPG::Weapon
number = $game_party.temp_weapon_number(@item.id)
when RPG::Armor
number = $game_party.temp_armor_number(@item.id)
end
if number == 0
$game_system.se_play($data_system.buzzer_se)
else
max = number
$game_system.se_play($data_system.decision_se)
@command_window.active = false
@command_window.visible = false
@number_window.set(@item, max, @item.price / 2)
@number_window.active = true
@number_window.visible = true
end
end
return
end
end
#--------------------------------------------------------------------------
# * Frame Update (when quantity input window is active)
#--------------------------------------------------------------------------
def update_number
if Input.trigger?(Input::B)
$game_system.se_play($data_system.cancel_se)
@number_window.active = false
@number_window.visible = false
@command_window.active = true
@command_window.visible = true
end
if @item.price > $game_party.gold
@help_window.set_text('You can\'t afford '+@item.name+'s.', 1)
else
@help_window.set_text('How many '+@item.name+'s.', 1)
end
if Input.trigger?(Input::C)
if @item.price > $game_party.gold
$game_system.se_play($data_system.buzzer_se)
else
$game_system.se_play($data_system.shop_se)
@number_window.active = false
@number_window.visible = false
case @command_window.index
when 0 # buy
case @item
when RPG::Item
$game_party.gain_temp_item(@item.id, @number_window.number)
@shopping_window.refresh
when RPG::Weapon
$game_party.gain_temp_weapon(@item.id, @number_window.number)
@shopping_window.refresh
when RPG::Armor
$game_party.gain_temp_armor(@item.id, @number_window.number)
@shopping_window.refresh
end
@command_window.active = true
@command_window.visible = true
when 1 # sell
case @item
when RPG::Item
$game_party.gain_temp_item(@item.id, (@number_window.number * -1))
@shopping_window.refresh
when RPG::Weapon
$game_party.lose_weapon(@item.id, (@number_window.number * -1))
@shopping_window.refresh
when RPG::Armor
$game_party.lose_armor(@item.id, (@number_window.number * -1))
@shopping_window.refresh
end
@command_window.active = true
@command_window.visible = true
end
end
return
end
end
end
#------------------------------------------------------------------------------
# ** Scene_ShoppingCart
#------------------------------------------------------------------------------
class Scene_ShoppingCart
#--------------------------------------------------------------------------
# * Object Initialization
#--------------------------------------------------------------------------
def initialize(access = 0)
@access = access
end
#--------------------------------------------------------------------------
# * Main
#--------------------------------------------------------------------------
def main
@sprite_set = Spriteset_Map.new
@shopping_cart = Window_ShoppingCart.new
@shopping_cart.active = true
@shopping_cart.index = 0
@shopping_cart.opacity = 200
@command_window = Window_HorizCommand.new(['Ok', 'Cancel'], 320)
@command_window.x = 320
@command_window.y = 288
@command_window.opacity = 200
@total_ammount = @shopping_cart.get_total_ammount
@total_price = @shopping_cart.get_total_price
@shoptotal_window = Window_ShopTotal.new(@total_ammount, @total_price)
@shoptotal_window.opacity = 200
if @access == 1
@command_window.visible = false
@command_window.active = false
end
@objects = [@sprite_set, @shopping_cart, @command_window, @shoptotal_window]
Graphics.transition
loop do
Graphics.update
Input.update
@objects.each {|x| x.update}
update
if $scene != self
break
end
end
Graphics.freeze
@objects.each {|object| object.dispose}
end
#--------------------------------------------------------------------------
# * Frame Update
#--------------------------------------------------------------------------
def update
if Input.trigger?(Input::B)
$game_system.se_play($data_system.cancel_se)
$scene = Scene_Map.new
return
end
if @command_window.active
if Input.trigger?(Input::C)
case @command_window.index
when 0
if @total_price > $game_party.gold
$game_system.se_play($data_system.buzzer_se)
else
$game_system.se_play($data_system.shop_se)
$game_party.lose_gold(@total_price)
@shopping_cart.add_items
@shopping_cart.refresh
$scene = Scene_Map.new
end
when 1
$scene = Scene_Map.new
end
end
end
end
end
#--------------------------------------------------------------------------
# ** Game_Party
#--------------------------------------------------------------------------
class Game_Party
alias vpcdmd_initialize initialize
#--------------------------------------------------------------------------
# * Object Initialization
#--------------------------------------------------------------------------
def initialize
vpcdmd_initialize
@temp_items = {}
@temp_weapons = {}
@temp_armors = {}
end
#--------------------------------------------------------------------------
# * Get Number of Items Possessed
#--------------------------------------------------------------------------
def temp_item_number(item_id)
return @temp_items.include?(item_id) ? @temp_items[item_id] : 0
end
#--------------------------------------------------------------------------
# * Get Number of Weapons Possessed
#--------------------------------------------------------------------------
def temp_weapon_number(weapon_id)
return @temp_weapons.include?(weapon_id) ? @temp_weapons[weapon_id] : 0
end
#--------------------------------------------------------------------------
# * Get Amount of Armor Possessed
#--------------------------------------------------------------------------
def temp_armor_number(armor_id)
return @temp_armors.include?(armor_id) ? @temp_armors[armor_id] : 0
end
#--------------------------------------------------------------------------
# * Gain Items (or lose)
#--------------------------------------------------------------------------
def gain_temp_item(item_id, n)
if item_id > 0
@temp_items[item_id] = [[temp_item_number(item_id) + n, 0].max, 99].min
end
end
#--------------------------------------------------------------------------
# * Gain Weapons (or lose)
#--------------------------------------------------------------------------
def gain_temp_weapon(weapon_id, n)
if weapon_id > 0
@temp_weapons[weapon_id] = [[temp_weapon_number(weapon_id) + n, 0].max, 99].min
end
end
#--------------------------------------------------------------------------
# * Gain Armor (or lose)
#--------------------------------------------------------------------------
def gain_temp_armor(armor_id, n)
if armor_id > 0
@temp_armors[armor_id] = [[temp_armor_number(armor_id) + n, 0].max, 99].min
end
end
end
#------------------------------------------------------------------------------
# ** Scene_Map
#------------------------------------------------------------------------------
class Scene_Map
#--------------------------------------------------------------------------
# * Menu Call
#--------------------------------------------------------------------------
def call_menu
$game_temp.menu_calling = false
if $game_temp.menu_beep
$game_system.se_play($data_system.decision_se)
$game_temp.menu_beep = false
end
$game_player.straighten
if $game_system.in_shop == 1
$scene = Scene_ShoppingCart.new(1)
else
$scene = Scene_Menu.new
end
end
end
#--------------------------------------------------------------------------
# ** Game_System
#--------------------------------------------------------------------------
class Game_System
attr_accessor :in_shop
alias vpcdmd_initialize initialize
#--------------------------------------------------------------------------
# * Initialization
#--------------------------------------------------------------------------
def initialize
vpcdmd_initialize
@in_shop = 0
end
#--------------------------------------------------------------------------
# * In_Shop
#--------------------------------------------------------------------------
def in_shop
return @in_shop
end
end
#------------------------------------------------------------------------------
# ** Window_Help
#------------------------------------------------------------------------------
class Window_Help2 < Window_Base
#--------------------------------------------------------------------------
# * Object Initialization
#--------------------------------------------------------------------------
def initialize
super(0, 0, 320, 64)
self.contents = Bitmap.new(width - 32, height - 32)
end
#--------------------------------------------------------------------------
# * Set Text
def set_text(text, align = 0)
if text != @text or align != @align
self.contents.clear
self.contents.font.color = normal_color
self.contents.draw_text(4, 0, self.width - 40, 32, text, align)
@text = text
@align = align
@actor = nil
end
self.visible = true
end
end
#------------------------------------------------------------------------------
# ** Window_ShoppingCart
#------------------------------------------------------------------------------
class Window_ShoppingCart < Window_Selectable
#--------------------------------------------------------------------------
# * Object Initialization
#--------------------------------------------------------------------------
def initialize
super(320, 0, 320, 160)
self.contents = Bitmap.new(width - 32, height - 32)
refresh
end
#--------------------------------------------------------------------------
# * Refresh
#--------------------------------------------------------------------------
def refresh
if self.contents != nil
self.contents.dispose
self.contents = nil
end
@data = []
for i in 1...$data_items.size
if $game_party.temp_item_number(i) > 0
@data.push($data_items[i])
end
end
for i in 1...$data_weapons.size
if $game_party.temp_weapon_number(i) > 0
@data.push($data_weapons[i])
end
end
for i in 1...$data_armors.size
if $game_party.temp_armor_number(i) > 0
@data.push($data_armors[i])
end
end
@item_max = @data.size
if @item_max > 0
$game_system.in_shop = 1
self.contents = Bitmap.new(width - 32, row_max * 32)
for i in 0...@item_max
draw_item(i)
end
else
$game_system.in_shop = 0
end
end
#--------------------------------------------------------------------------
# * Draw Item
#--------------------------------------------------------------------------
def draw_item(index)
item = @data[index]
case item
when RPG::Item
number = $game_party.temp_item_number(item.id)
when RPG::Weapon
number = $game_party.temp_weapon_number(item.id)
when RPG::Armor
number = $game_party.temp_armor_number(item.id)
end
if item.is_a?(RPG::Item)
self.contents.font.color = normal_color
else
self.contents.font.color = disabled_color
end
x = 4 + index % 1 * (288 + 32)
y = index / 1 * 32
rect = Rect.new(x, y, self.width / @column_max - 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)
self.contents.draw_text(x + 170, y, 16, 32, "x", 1)
self.contents.draw_text(x + 180, y, 24, 32, number.to_s, 2)
self.contents.draw_text(x + 206, y, 54, 32, (item.price*number).to_s, 2)
self.contents.draw_text(x + 250, y, 32, 32, $data_system.words.gold, 2)
end
#--------------------------------------------------------------------------
# * Get_Total_Ammount
#--------------------------------------------------------------------------
def get_total_ammount
total = 0
if @item_max > 0
for i in 0...@item_max
item = @data[i]
case item
when RPG::Item
total += $game_party.temp_item_number(item.id)
when RPG::Weapon
total += $game_party.temp_weapon_number(weapon_id)
when RPG::Armor
total += $game_party.temp_armor_number(armor_id)
end
end
end
return total
end
#--------------------------------------------------------------------------
# * Get_Total_Price
#--------------------------------------------------------------------------
def get_total_price
total = 0
if @item_max > 0
for i in 0...@item_max
item = @data[i]
case item
when RPG::Item
total += item.price * $game_party.temp_item_number(item.id)
when RPG::Weapon
total += item.price * $game_party.temp_weapon_number(weapon_id)
when RPG::Armor
total += item.price * $game_party.temp_armor_number(armor_id)
end
end
end
return total
end
#--------------------------------------------------------------------------
# * Add_Items
#--------------------------------------------------------------------------
def add_items
if @item_max > 0
for i in 0...@item_max
item = @data[i]
case item
when RPG::Item
$game_party.gain_item(item.id, $game_party.temp_item_number(item.id))
when RPG::Weapon
$game_party.gain_weapon(item.id, $game_party.temp_weapon_number(weapon_id))
when RPG::Armor
$game_party.gain_armor(item.id,$game_party.temp_armor_number(armor_id))
end
end
end
empty_list
end
#--------------------------------------------------------------------------
# * Empty_List
#--------------------------------------------------------------------------
def empty_list
if @item_max > 0
for i in 0...@item_max
item = @data[i]
case item
when RPG::Item
$game_party.gain_temp_item(item.id, $game_party.temp_item_number(item.id)*-1)
when RPG::Weapon
$game_party.gain_temp_weapon(item.id, $game_party.temp_weapon_number(weapon_id)*-1)
when RPG::Armor
$game_party.gain_temp_armor(item.id,$game_party.temp_armor_number(armor_id)*-1)
end
end
end
end
end
#------------------------------------------------------------------------------
# ** Window Horizontal Command
#------------------------------------------------------------------------------
class Window_HorizCommand < Window_Selectable
#--------------------------------------------------------------------------
# * Object Initialization
#--------------------------------------------------------------------------
def initialize(commands, width = 640, height = 64)
super(0, 0, width, height)
self.contents = Bitmap.new(width - 32, height - 32)
@commands = commands
@item_max = @commands.size
@column_max = @commands.size
refresh
self.index = 0
end
#--------------------------------------------------------------------------
# * Refresh
#--------------------------------------------------------------------------
def refresh
self.contents.clear
for i in 0...@item_max
draw_item(i, normal_color)
end
end
#--------------------------------------------------------------------------
# * Draw Item
#--------------------------------------------------------------------------
def draw_item(index, color)
self.contents.font.color = color
x = width / @item_max * index
off = width / @item_max - 32
self.contents.draw_text(x, 0, off, 32, @commands[index], 1)
end
#--------------------------------------------------------------------------
# * Disable Item
#--------------------------------------------------------------------------
def disable_item(index)
draw_item(index, disabled_color)
end
end
#------------------------------------------------------------------------------
# ** Window Shop Total
#------------------------------------------------------------------------------
class Window_ShopTotal < Window_Base
#--------------------------------------------------------------------------
# * Object Initialization
#--------------------------------------------------------------------------
def initialize(total_ammount, total_price)
@total_ammount = total_ammount
@total_price = total_price
super(320, 160, 320, 128)
self.contents = Bitmap.new(width - 32, height - 32)
refresh
end
#--------------------------------------------------------------------------
# * Refresh
#--------------------------------------------------------------------------
def refresh
self.contents.clear
self.contents.font.color = normal_color
self.contents.draw_text(4, 0, 160, 32, "Total Ammount")
self.contents.draw_text(160, 0, 160, 32, @total_ammount.to_s)
self.contents.draw_text(4, 32, 160, 32, "Total Price")
self.contents.draw_text(160, 32, 160, 32, @total_price.to_s)
self.contents.draw_text(4, 32, 280, 32, $data_system.words.gold, 2)
self.contents.draw_text(4, 64, 160, 32, "Gold Available")
self.contents.draw_text(160, 64, 160, 32, $game_party.gold.to_s)
self.contents.draw_text(4, 32, 280, 32, $data_system.words.gold, 2)
end
end