class Game_Container
def initialize
$container = []
box = Container.new(10, true, true, true)
barrel = Container.new(12, true)
chest = Container.new(15, true, true, true)
drawer = Container.new(20, false, false, true, false)
$container = [box, barrel, chest, drawer]
check_array($container)
#Call $container[con_id].setup(type, num) to setup items. Do this in event!
end
def check_array(array)
for i in 0..array.length - 1
if array[i] == nil
array.delete_at(i)
end
end
end
end
class Scene_Title
def command_new_game
# Play decision SE
$game_system.se_play($data_system.decision_se)
# Stop BGM
Audio.bgm_stop
# Reset frame count for measuring play time
Graphics.frame_count = 0
# Make each type of game object
$game_temp = Game_Temp.new
$game_system = Game_System.new
$game_switches = Game_Switches.new
$game_variables = Game_Variables.new
$game_self_switches = Game_SelfSwitches.new
$game_screen = Game_Screen.new
$game_actors = Game_Actors.new
$game_party = Game_Party.new
$game_troop = Game_Troop.new
$game_map = Game_Map.new
$game_player = Game_Player.new
$game_container = Game_Container.new
# Set up initial party
$game_party.setup_starting_members
# Set up initial map position
$game_map.setup($data_system.start_map_id)
# Move player to initial position
$game_player.moveto($data_system.start_x, $data_system.start_y)
# Refresh player
$game_player.refresh
# Run automatic change for BGM and BGS set with map
$game_map.autoplay
# Update map (run parallel process event)
$game_map.update
# Switch to map screen
$scene = Scene_Map.new
end
end
class Container
attr_accessor :stored_i #stored items
attr_accessor :stored_w #stored weapons
attr_accessor :stored_a #stored armour
attr_accessor :stored_g #amount of gold
#-----------------------------------------------------------------------------
#initialize(max amount of items, is gold allowed?, weapons?, armour?, items?)
#-----------------------------------------------------------------------------
def initialize(max, gold = false, weapons = false, armour = false, items = true)
@max = max
if @max <= 0
@success = false
elsif @max > 0 && @max <= 100
@success = true
end
if @success == true
create_container(gold, weapons, armour, items)
@stored_i = []
@stored_w = []
@stored_a = []
@stored_g = 0
else
call_error("Container was not a success!")
end
end
def create_container(g, w, a, i)
@allow_g = g
@allow_w = w
@allow_a = a
@allow_i = i
@locked = false
end
def call_error(string = "")
print "Error in class Container:"
print string
exit
end
def lock
@locked = true
end
def unlock
@locked = false
end
def max?
return @max
end
def allow_g?
return @allow_g
end
def allow_w?
return @allow_w
end
def allow_a?
return @allow_a
end
def allow_i?
return @allow_i
end
def fix_count
max = self.max?
#Check for amount of Items
if self.allow_i?
items = self.stored_i.size
else
items = 0
end
#Check for amount of Weapons
if self.allow_w?
weapons = self.stored_w.size
else
weapons = 0
end
#Check for amount of Armour
if self.allow_a?
armour = self.stored_a.size
else
armour = 0
end
#Fix the container
sum = items + weapons + armour
if sum > max
return false
else
return true
end
end
def contains?(type, item_id)
if type == 0 #Item
for i in 0..self.stored_i.length - 1
if self.stored_i[i] == item_id
return true
else
return false
end
end
elsif type == 1 #Weapon
for i in 0..self.stored_w.length - 1
if self.stored_w[i] == item_id
return true
else
return false
end
end
elsif type == 2 #Armour
for i in 0..self.stored_a.length - 1
if self.stored_a[i] == item_id
return true
else
return false
end
end
end
end
def locked?
return @locked
end
def give_item(item_id)
state = locked?
if state == false && $game_party.item_number(item_id) != 0
is_room = self.fix_count
if is_room == true
@stored_i << item_id
end
end
end
def give_weapon(item_id)
state = locked?
if state == false && $game_party.item_number(item_id) != 0
is_room = self.fix_count
if is_room == true
@stored_w << item_id
end
end
end
def give_armour(item_id)
state = locked?
if state == false && $game_party.item_number(item_id) != 0
is_room = self.fix_count
if is_room == true
@stored_a << item_id
end
end
end
def give_gold(amount) #Gold is not affected by @max, but must be less than 9999999
state = locked?
if state == false
if self.allow_g? && amount <= 9999999
self.stored_g += amount
else
call_error("Gold Count reached above 9999999!")
end
end
end
def take_item(item_id)
state = locked?
if state == false
a = self.stored_i.include?(item_id)
if a == true
i = self.stored_i.index(item_id)
self.stored_i.delete_at(i)
$game_party.gain_item(item_id, 1)
end
end
end
def take_weapon(item_id)
state = locked?
if state == false
a = self.stored_w.include?(item_id)
if a == true
i = self.stored_w.index(item_id)
self.stored_w.delete_at(i)
$game_party.gain_weapon(item_id, 1)
end
end
end
def take_armour(item_id)
state = locked?
if state == false
a = self.stored_a.include?(item_id)
if a == true
i = self.stored_a.index(item_id)
self.stored_a.delete_at(i)
$game_party.gain_armor(item_id, 1)
end
end
end
def take_gold(amount)
state = locked?
if state == false
if amount <= self.stored_g
self.stored_g -= amount
$game_party.gain_gold(amount)
end
end
end
def trade_items(player_item, cont_id)
state = locked?
if state == false
take_item(cont_id)
give_item(player_item)
end
end
def trade_weapons(player_item, cont_id)
state = locked?
if state == false
take_weapon(cont_id)
give_weapon(player_item)
end
end
def trade_armour(player_item, cont_id)
state = locked?
if state == false
take_armour(cont_id)
give_armour(player_item)
end
end
def destroy_container
self.stored_i = nil
self.stored_w = nil
self.stored_a = nil
self.stored_g = 0
@max = 0
@allow_g = false
@allow_w = false
@allow_a = false
@allow_i = false
@locked = true
end
def setup(type, num) #where num is an item_id or amount of gold.
if type == 0 #Item
is_room = self.fix_count
if is_room == true
@stored_i << num
end
elsif type == 1 #Weapon
is_room = self.fix_count
if is_room == true
@stored_w << num
end
elsif type == 2 #Armour
is_room = self.fix_count
if is_room == true
@stored_a << num
end
elsif type == 3 #Gold
if num <= 9999999 && @stored_g <= 9999999
a = @stored_g += num
if @stored_g > 9999999
@stored_g = 9999999
else
@stored_g += num
end
end
end
end
end
#==============================================================================
# ** Scene_Container
#------------------------------------------------------------------------------
# This class performs Container screen processing.
#==============================================================================
class Scene_Container
#--------------------------------------------------------------------------
# * Object Initialization
# menu_index : command cursor's initial position
#--------------------------------------------------------------------------
def initialize(container, menu_index = 0)
@con_id = container
@menu_index = menu_index
end
#--------------------------------------------------------------------------
# * Main Processing
#--------------------------------------------------------------------------
def main
$spriteset = Spriteset_Map.new
# Make command window
s1 = "Take"
s2 = "Give"
s3 = "Trade"
s4 = "Exit"
@command_window = Window_Command.new(160, [s1, s2, s3, s4])
@command_window.index = @menu_index
# Execute transition
Graphics.transition
# Main loop
loop do
# Update game screen
Graphics.update
# Update input information
Input.update
# Frame update
update
# Abort loop if screen is changed
if $scene != self
break
end
end
# Prepare for transition
Graphics.freeze
# Dispose of windows
@command_window.dispose
$spriteset.dispose
end
#--------------------------------------------------------------------------
# * Frame Update
#--------------------------------------------------------------------------
def update
$spriteset.update
# Update windows
@command_window.update
# If command window is active: call update_command
if @command_window.active
update_command
return
end
end
#--------------------------------------------------------------------------
# * 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)
# Switch to map screen
$scene = Scene_Map.new
return
end
# If C button was pressed
if Input.trigger?(Input::C)
# If command other than save or end game, and party members = 0
if $game_party.actors.size == 0 and @command_window.index < 4
# Play buzzer SE
$game_system.se_play($data_system.buzzer_se)
return
end
# Branch by command window cursor position
case @command_window.index
when 0 # Take
# Play decision SE
$game_system.se_play($data_system.decision_se)
$scene = Take.new(@con_id)
when 1 # Give
# Play decision SE
$game_system.se_play($data_system.decision_se)
$scene = Give.new(@con_id)
when 2 # Trade
# Play decision SE
$game_system.se_play($data_system.decision_se)
$scene = Trade.new(@con_id)
when 3 # Exit
# Play decision SE
$game_system.se_play($data_system.decision_se)
$scene = Scene_Map.new
end
return
end
end
end
#Take
#==============================================================================
# ** Take
#------------------------------------------------------------------------------
# This class performs item screen processing.
#==============================================================================
class Take
def initialize(con_id)
@con_id = con_id
end
#--------------------------------------------------------------------------
# * Main Processing
#--------------------------------------------------------------------------
def main
# Make help window, item window
@help_window = Window_Help.new
@item_window = Window_Container.new(@con_id)
# Associate help window
@item_window.help_window = @help_window
# Execute transition
Graphics.transition
# Main loop
loop do
# Update game screen
Graphics.update
# Update input information
Input.update
# Frame update
update
# Abort loop if screen is changed
if $scene != self
break
end
end
# Prepare for transition
Graphics.freeze
# Dispose of windows
@help_window.dispose
@item_window.dispose
end
#--------------------------------------------------------------------------
# * Frame Update
#--------------------------------------------------------------------------
def update
# Update windows
@help_window.update
@item_window.update
# If item window is active: call update_item
if @item_window.active
update_item
return
end
end
#--------------------------------------------------------------------------
# * Frame Update (when item window is active)
#--------------------------------------------------------------------------
def update_item
# If B button was pressed
if Input.trigger?(Input::B)
# Play cancel SE
$game_system.se_play($data_system.cancel_se)
# Switch to menu screen
$scene = Scene_Container.new(@con_id)
return
end
# If C button was pressed
if Input.trigger?(Input::C)
# Get currently selected data on the item window
@item = @item_window.item
# If not a use item
unless @item.is_a?(RPG::Item)
# Play buzzer SE
$game_system.se_play($data_system.buzzer_se)
return
end
# Play decision SE
$game_system.se_play($data_system.decision_se)
$container[@con_id].take_item(@item.id)
return
end
end
end
#Give
#==============================================================================
# ** Give
#------------------------------------------------------------------------------
# This class performs item screen processing.
#==============================================================================
class Give
def initialize(con_id)
@con_id = con_id
end
#--------------------------------------------------------------------------
# * Main Processing
#--------------------------------------------------------------------------
def main
# Make help window, item window
@help_window = Window_Help.new
@item_window = Window_Item.new
# Associate help window
@item_window.help_window = @help_window
# Execute transition
Graphics.transition
# Main loop
loop do
# Update game screen
Graphics.update
# Update input information
Input.update
# Frame update
update
# Abort loop if screen is changed
if $scene != self
break
end
end
# Prepare for transition
Graphics.freeze
# Dispose of windows
@help_window.dispose
@item_window.dispose
end
#--------------------------------------------------------------------------
# * Frame Update
#--------------------------------------------------------------------------
def update
# Update windows
@help_window.update
@item_window.update
# If item window is active: call update_item
if @item_window.active
update_item
return
end
end
#--------------------------------------------------------------------------
# * Frame Update (when item window is active)
#--------------------------------------------------------------------------
def update_item
# If B button was pressed
if Input.trigger?(Input::B)
# Play cancel SE
$game_system.se_play($data_system.cancel_se)
# Switch to menu screen
$scene = Scene_Container.new(@con_id)
return
end
# If C button was pressed
if Input.trigger?(Input::C)
# Get currently selected data on the item window
@item = @item_window.item
# If not a use item
unless @item.is_a?(RPG::Item)
# Play buzzer SE
$game_system.se_play($data_system.buzzer_se)
return
end
# Play decision SE
$game_system.se_play($data_system.decision_se)
$container[@con_id].give_item(@item.id)
return
end
end
end
#Trade
#==============================================================================
# ** Trade
#------------------------------------------------------------------------------
# This class performs item screen processing.
#==============================================================================
class Trade
def initialize(con_id)
@con_id = con_id
end
#--------------------------------------------------------------------------
# * Main Processing
#--------------------------------------------------------------------------
def main
# Make help window, item window
@help_window = Window_Help.new
@item_window = Window_Trade1.new(@con_id) #Edited Window_Container
@player_wind = Window_Trade2.new #Edited Window_Item
@player_wind.active = false
@player_wind.visible = false
# Associate help window
@item_window.help_window = @help_window
@player_wind.help_window = @help_window
# Execute transition
Graphics.transition
# Main loop
loop do
# Update game screen
Graphics.update
# Update input information
Input.update
# Frame update
update
# Abort loop if screen is changed
if $scene != self
break
end
end
# Prepare for transition
Graphics.freeze
# Dispose of windows
@help_window.dispose
@item_window.dispose
@player_wind.dispose
end
#--------------------------------------------------------------------------
# * Frame Update
#--------------------------------------------------------------------------
def update
# Update windows
@help_window.update
@item_window.update
@player_wind.update
# If item window is active: call update_item
if @item_window.active
update_item
return
end
# If player's inventory is active: call update_item2
if @player_wind.active
update_item2
return
end
end
#--------------------------------------------------------------------------
# * Frame Update (when item window is active)
#--------------------------------------------------------------------------
def update_item
# If B button was pressed
if Input.trigger?(Input::B)
# Play cancel SE
$game_system.se_play($data_system.cancel_se)
# Switch to menu screen
$scene = Scene_Container.new(@con_id)
return
end
# If C button was pressed
if Input.trigger?(Input::C)
# Get currently selected data on the item window
@item = @item_window.item
# If not a use item
unless @item.is_a?(RPG::Item)
# Play buzzer SE
$game_system.se_play($data_system.buzzer_se)
return
end
# Play decision SE
$game_system.se_play($data_system.decision_se)
# Switch Active Windows!
@player_wind.active = true
@player_wind.visible = true
@item_window.active = false
@item_window.visible = false
return
end
end
#--------------------------------------------------------------------------
# * Frame Update (when ;player inventory is active)
#--------------------------------------------------------------------------
def update_item2
# If B button was pressed
if Input.trigger?(Input::B)
# Play cancel SE
$game_system.se_play($data_system.cancel_se)
# Switch to menu screen
$scene = Scene_Trade.new(@con_id)
return
end
# If C button was pressed
if Input.trigger?(Input::C)
# Get currently selected data on the item window
@item2 = @player_wind.item
# If not a use item
unless @item.is_a?(RPG::Item)
# Play buzzer SE
$game_system.se_play($data_system.buzzer_se)
return
end
# Play decision SE
$game_system.se_play($data_system.decision_se)
$container[@con_id].trade_items(@item.id, @item2.id)
@player_wind.active = false
@player_wind.visible = false
@item_window.active = true
@item_window.visible = true
return
end
end
end
#==============================================================================
# ** Window_Item
#------------------------------------------------------------------------------
# This window displays items in possession on the item and battle screens.
#==============================================================================
class Window_Container < Window_Selectable
#--------------------------------------------------------------------------
# * Object Initialization
#--------------------------------------------------------------------------
def initialize(con_id)
super(0, 64, 640, 416)
@con_id = con_id
@column_max = 2
refresh(@con_id)
self.index = 0
# If in battle, move window to center of screen
# and make it semi-transparent
if $game_temp.in_battle
self.y = 64
self.height = 256
self.back_opacity = 160
end
end
#--------------------------------------------------------------------------
# * Get Item
#--------------------------------------------------------------------------
def item
return @data[self.index]
end
#--------------------------------------------------------------------------
# * Refresh
#--------------------------------------------------------------------------
def refresh(con_id)
if self.contents != nil
self.contents.dispose
self.contents = nil
end
@data = []
# Add item
for i in 1...$data_items.size
if $container[con_id].stored_i.include?(i)
@data.push($data_items[i])
end
end
# Also add weapons and items if outside of battle
unless $game_temp.in_battle
for i in 1...$data_weapons.size
if $container[con_id].stored_w.include?(i)
@data.push($data_weapons[i])
end
end
for i in 1...$data_armors.size
if $container[con_id].stored_a.include?(i)
@data.push($data_armors[i])
end
end
end
# If item count is not 0, make a bit map and draw all items
@item_max = @data.size
if @item_max > 0
self.contents = Bitmap.new(width - 32, row_max * 32)
for i in 0...@item_max
draw_item(i)
end
end
end
#--------------------------------------------------------------------------
# * Draw Item
# index : item number
#--------------------------------------------------------------------------
def draw_item(index)
item = @data[index]
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 item.is_a?(RPG::Item) and
$game_party.item_can_use?(item.id)
self.contents.font.color = normal_color
else
self.contents.font.color = disabled_color
end
x = 4 + index % 2 * (288 + 32)
y = index / 2 * 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 + 240, y, 16, 32, ":", 1)
self.contents.draw_text(x + 256, y, 24, 32, number.to_s, 2)
end
#--------------------------------------------------------------------------
# * Help Text Update
#--------------------------------------------------------------------------
def update_help
@help_window.set_text(self.item == nil ? "" : self.item.description)
end
end
#==============================================================================
# ** Window_Trade1
#------------------------------------------------------------------------------
# This window displays items in possession on the item and battle screens.
#==============================================================================
class Window_Trade1 < Window_Selectable
#--------------------------------------------------------------------------
# * Object Initialization
#--------------------------------------------------------------------------
def initialize(con_id)
super(0, 64, 320, 416)
@con_id = con_id
@column_max = 1
refresh(@con_id)
self.index = 0
# If in battle, move window to center of screen
# and make it semi-transparent
if $game_temp.in_battle
self.y = 64
self.height = 256
self.back_opacity = 160
end
end
#--------------------------------------------------------------------------
# * Get Item
#--------------------------------------------------------------------------
def item
return @data[self.index]
end
#--------------------------------------------------------------------------
# * Refresh
#--------------------------------------------------------------------------
def refresh(con_id)
if self.contents != nil
self.contents.dispose
self.contents = nil
end
@data = []
# Add item
for i in 1...$data_items.size
if $container[con_id].stored_i.include?(i)
@data.push($data_items[i])
end
end
# Also add weapons and items if outside of battle
unless $game_temp.in_battle
for i in 1...$data_weapons.size
if $container[con_id].stored_w.include?(i)
@data.push($data_weapons[i])
end
end
for i in 1...$data_armors.size
if $container[con_id].stored_a.include?(i)
@data.push($data_armors[i])
end
end
end
# If item count is not 0, make a bit map and draw all items
@item_max = @data.size
if @item_max > 0
self.contents = Bitmap.new(width - 32, row_max * 32)
for i in 0...@item_max
draw_item(i)
end
end
end
#--------------------------------------------------------------------------
# * Draw Item
# index : item number
#--------------------------------------------------------------------------
def draw_item(index)
item = @data[index]
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 item.is_a?(RPG::Item) and
$game_party.item_can_use?(item.id)
self.contents.font.color = normal_color
else
self.contents.font.color = disabled_color
end
x = 4 + index % 2 * (288 + 32)
y = index / 2 * 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 + 240, y, 16, 32, ":", 1)
self.contents.draw_text(x + 256, y, 24, 32, number.to_s, 2)
end
#--------------------------------------------------------------------------
# * Help Text Update
#--------------------------------------------------------------------------
def update_help
@help_window.set_text(self.item == nil ? "" : self.item.description)
end
end
#==============================================================================
# ** Window_Trade2
#------------------------------------------------------------------------------
# This window displays items in possession on the item and battle screens.
#==============================================================================
class Window_Trade2 < Window_Selectable
#--------------------------------------------------------------------------
# * Object Initialization
#--------------------------------------------------------------------------
def initialize
super(321, 64, 320, 416)
@column_max = 1
refresh
self.index = 0
# If in battle, move window to center of screen
# and make it semi-transparent
if $game_temp.in_battle
self.y = 64
self.height = 256
self.back_opacity = 160
end
end
#--------------------------------------------------------------------------
# * Get Item
#--------------------------------------------------------------------------
def item
return @data[self.index]
end
#--------------------------------------------------------------------------
# * Refresh
#--------------------------------------------------------------------------
def refresh
if self.contents != nil
self.contents.dispose
self.contents = nil
end
@data = []
# Add item
for i in 1...$data_items.size
if $game_party.item_number(i) > 0
@data.push($data_items[i])
end
end
# Also add weapons and items if outside of battle
unless $game_temp.in_battle
for i in 1...$data_weapons.size
if $game_party.weapon_number(i) > 0
@data.push($data_weapons[i])
end
end
for i in 1...$data_armors.size
if $game_party.armor_number(i) > 0
@data.push($data_armors[i])
end
end
end
# If item count is not 0, make a bit map and draw all items
@item_max = @data.size
if @item_max > 0
self.contents = Bitmap.new(width - 32, row_max * 32)
for i in 0...@item_max
draw_item(i)
end
end
end
#--------------------------------------------------------------------------
# * Draw Item
# index : item number
#--------------------------------------------------------------------------
def draw_item(index)
item = @data[index]
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 item.is_a?(RPG::Item) and
$game_party.item_can_use?(item.id)
self.contents.font.color = normal_color
else
self.contents.font.color = disabled_color
end
x = 4 + index % 2 * (288 + 32)
y = index / 2 * 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 + 240, y, 16, 32, ":", 1)
self.contents.draw_text(x + 256, y, 24, 32, number.to_s, 2)
end
#--------------------------------------------------------------------------
# * Help Text Update
#--------------------------------------------------------------------------
def update_help
@help_window.set_text(self.item == nil ? "" : self.item.description)
end
end