Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #==============================================================================
- # ** Scene_Spoils
- #------------------------------------------------------------------------------
- # This class controls the scene that allows the player to access chests
- #==============================================================================
- class Scene_Spoils < Scene_Base
- include Overlord_Dave::DRIACS::Settings
- #--------------------------------------------------------------------------
- # * Object Initialisation
- # source : The scene from which the spoils scene was opened
- # head : The name displayed above the chest
- # chest_id : The id of the chest opened (from the $chests hash)
- #--------------------------------------------------------------------------
- def initialize(source, head = nil, chest_id = nil)
- @source = source
- @chest_id = chest_id
- @max_size = chest_id.nil? ? 0 : $chests[chest_id].max_size
- @spoils_head = case @source # 1: from map, 2: from menu, 3: from battle
- when 1,2: USE_CONTAINER_NAME && !head.nil? && head != '' ? head : WIN_CONT_HEAD
- when 3: head # the head is determined in Game_System.init_battle_spoils
- end
- end
- #--------------------------------------------------------------------------
- # * Start processing
- #--------------------------------------------------------------------------
- def start
- super
- create_menu_background
- case SPOILS_INFO_POS
- when 0
- info_y = 0
- titles_y = 56
- items_y = 112
- when 1
- info_y = 360
- titles_y = 0
- items_y = 56
- end
- @info_window = Window_Help.new
- @info_window.y = info_y
- @spoils_title = Window_Help.new
- @spoils_title.y = titles_y
- @spoils_title.width = 544/2.0
- @spoils_title.create_contents
- @inv_title = Window_Help.new
- @inv_title.y = titles_y
- @inv_title.x = 544/2.0
- @inv_title.width = 544/2.0
- @inv_title.create_contents
- @spoils_window = Window_Spoils.new(0, items_y, 544/2.0, 304)
- @spoils_window.chest = $game_temp.temp_chest
- @inv_window = Window_Item.new(544/2.0, items_y, 544/2.0, 304, true)
- @inv_window.column_max = 1
- @inv_window.refresh
- @inv_window.update
- @inv_window.index = 0
- # make the spoils window active unless it is empty
- if $game_temp.temp_chest.all_items == [-1]
- @spoils_window.active = false
- @inv_window.active = true
- else
- @spoils_window.active = true
- @spoils_window.index = 0
- @inv_window.active = false
- end
- update
- end
- #--------------------------------------------------------------------------
- # * Makes the message window appear
- # type : the message window to display (1-5)
- # obj : and object that can be passed to the method if necessary
- # (such as for type 5)
- #--------------------------------------------------------------------------
- def show_message(type, obj = nil)
- @message_window = case type
- when 1: Window_Info.new(LEAVE_ND_MSG, 1) # from inv_window
- when 2: Window_Info.new(INV_FULL, 1) # exiting with an over-size inventory
- when 3: Window_Info.new(SPOILS_FULL, 2) # exiting with an over-size chest
- when 4: Window_Info.new(NO_LEAVE_MSG, 1) # if a chest is not accessable
- when 5: Window_List.new(WARN_FORCED_MSG, 2, obj) # forced items window
- # gold found message (must check whether chest has items to find value
- # of return_to)
- when 6: Window_Info.new(sprintf(GOLD_FOUND, obj), $game_temp.temp_chest.all_items == [-1] ? 1 : 2)
- end
- # play the shop sound for the gold message window
- Sound.play_shop if type == 6 && GOLD_MSG_SOUND
- @message_window.visible = true
- @spoils_window.active = false
- @inv_window.active = false
- end
- #--------------------------------------------------------------------------
- # * Makes the message window disappear
- #--------------------------------------------------------------------------
- def hide_message_window
- case @message_window.return_to
- when 1 # return to inv_window
- @inv_window.active = true
- @spoils_window.active = false
- when 2 # return to spoils_window
- @inv_window.active = false
- @spoils_window.active = true
- end
- @message_window.dispose
- @message_window = nil
- end
- #--------------------------------------------------------------------------
- # * Makes the exit confirmation window appear
- # type : the message window to display (1-4)
- #--------------------------------------------------------------------------
- def show_exit_window(type)
- if @inv_window.active
- return_to = 1
- elsif @spoils_window.active
- return_to = 2
- end
- message = case type
- when 0 :CONF_MSG_0
- when 1 :CONF_MSG_1
- when 2 :CONF_MSG_2
- when 3 :E_MSG_SPOILS
- end
- @inv_window.active = false
- @spoils_window.active = false
- if type == 3 # over-encumbered message
- @exit_window = Window_Option.new(message, E_OPT1_SPOILS, E_OPT2_SPOILS, 4)
- else
- @exit_window = Window_Option.new(message, CONF_OPT1, CONF_OPT2)
- end
- @exit_window.visible = true
- @exit_window.active = true
- @exit_window.index = 0
- @exit_window.return_to = return_to
- end
- #--------------------------------------------------------------------------
- # * Makes the exit confirmation window disappear
- #--------------------------------------------------------------------------
- def hide_exit_window
- case @exit_window.return_to
- when 1 # inv window
- @inv_window.active = true
- when 2 # spoils
- @spoils_window.active = true
- end
- @exit_window.dispose
- @exit_window = nil
- end
- #--------------------------------------------------------------------------
- # * Makes the option window appear when an item is selected from the inventory
- # source : which window it was called from (kept for possible future
- # features)
- #--------------------------------------------------------------------------
- def show_drop_choice_window(source)
- case source
- when 1 # inv_window
- @drop_choice_window = Window_Option.new('', USE_ITEM_OPT1B, USE_ITEM_OPT2, 2)
- @drop_choice_window.draw_window(@item)
- end
- @drop_choice_window.visible = true
- @drop_choice_window.active = true
- @drop_choice_window.index = 0
- @spoils_window.active = false
- @inv_window.active = false
- end
- #--------------------------------------------------------------------------
- # * Makes the option window when an item is selected from the inventory
- # disappear
- #--------------------------------------------------------------------------
- def hide_drop_choice_window
- case @drop_choice_window.type
- when 2 # from inv_window
- @inv_window.active = true
- when 3 # from spoils window
- @spoils_window.active = true
- end
- @drop_choice_window.dispose
- @drop_choice_window = nil
- end
- #--------------------------------------------------------------------------
- # * Makes the number select window appear
- # type : which message is shown above the number (1-3)
- #--------------------------------------------------------------------------
- def show_num_window(type)
- message = case type
- when 1 :LEAVE_SPOILS_MSG
- when 2 :TAKE_SPOILS_MSG
- when 3 :DROP_SPOILS_MSG
- end
- @num_window = Window_NumSelect.new(message, type)
- @num_window.num_max = case type
- when 1 :$game_party.item_number(@item)
- when 2 :$game_temp.temp_chest.item_number(@item, @dropped)
- when 3 :$game_party.item_number(@item)
- end
- hide_drop_choice_window if !@drop_choice_window.nil?
- @spoils_window.active = false
- @inv_window.active = false
- end
- #--------------------------------------------------------------------------
- # * Makes the number select window disappear
- #--------------------------------------------------------------------------
- def hide_num_window
- case @num_window.type
- when 1
- @inv_window.active = true
- when 2
- @spoils_window.active = true
- when 3
- @inv_window.active = true
- end
- @num_window.dispose
- @num_window = nil
- end
- #--------------------------------------------------------------------------
- # * Determines which windows to show after an action is selected from the drop
- # choice window.
- # type : which action has been selected (1-3)
- #--------------------------------------------------------------------------
- def det_move_item(type)
- case type
- when 1 # from inv_window
- case SHOW_MOVE_ITEM
- when 0 # never
- Sound.play_decision
- leave_item(1)
- when 1 # if more than one in stack
- if $game_party.item_number(@item) > 1
- Sound.play_decision
- show_num_window(1)
- else
- Sound.play_decision
- leave_item(1)
- end
- when 2 # always
- Sound.play_decision
- show_num_window(1)
- end
- when 2 # from spoils_window
- if @spoils_window.index == 0 # take all selected
- Sound.play_decision
- take_all
- return
- end
- case SHOW_MOVE_ITEM
- when 0 # never
- Sound.play_decision
- take_item(1)
- when 1 # if more than one in stack
- if $game_temp.temp_chest.item_number(@item, @dropped) > 1
- Sound.play_decision
- show_num_window(2)
- else
- Sound.play_decision
- take_item(1)
- end
- when 2 # always
- Sound.play_decision
- show_num_window(2)
- end
- when 3 # dropping an item
- case SHOW_MOVE_ITEM
- when 0 # never
- Sound.play_drop
- drop_item(1)
- when 1 # if more than one in stack
- if $game_party.item_number(@item) > 1
- Sound.play_decision
- show_num_window(3)
- else
- Sound.play_drop
- drop_item(1)
- end
- when 2 # always
- Sound.play_decision
- show_num_window(3)
- end
- end
- end
- #--------------------------------------------------------------------------
- # * Moves a number of the currently selected item to the chest
- # n : the number of items to move
- #--------------------------------------------------------------------------
- def leave_item(n)
- # these must be determineed before the inventory and chest is modified
- item_lost = true if n >= $game_party.item_number(@item)
- reset_chest = $game_temp.temp_chest.empty? ? true : false
- # modifying chest and inventory...
- $game_party.lose_item(@item, n)
- $game_temp.temp_chest.gain_item(@item, n)
- @spoils_window.index = 0 if reset_chest
- @inv_window.index -= 1 unless @inv_window.index == 0 || item_lost == false
- @inv_window.refresh
- @spoils_window.refresh
- hide_drop_choice_window if !@drop_choice_window.nil?
- end
- #--------------------------------------------------------------------------
- # * Moves a number of the currently selected item to the inventory
- # n : the number of items to move
- #--------------------------------------------------------------------------
- def take_item(n)
- # these must be determineed before the inventory and chest is modified
- if n >= $game_temp.temp_chest.item_number(@item, @dropped)
- item_lost = true
- item_index = @spoils_window.index
- end
- # modifying chest and inventory...
- $game_party.gain_item(@item, n)
- $game_temp.temp_chest.lose_item(@item, n, @dropped)
- if item_lost
- @spoils_window.item_max -= 1
- @spoils_window.index = item_index - 1 if item_index > (@spoils_window.item_max-1)
- end
- # make inventory window active if the chest is empty
- if $game_temp.temp_chest.empty?
- @spoils_window.active = false
- @spoils_window.index = -1
- @inv_window.active = true
- end
- @inv_window.refresh
- @spoils_window.refresh
- end
- #--------------------------------------------------------------------------
- # * Drops a number of the currently selected item
- # n : the number of items to drop
- #--------------------------------------------------------------------------
- def drop_item(n)
- # these must be determineed before the inventory and chest is modified
- item_lost = true if n >= $game_party.item_number(@item)
- reset_chest = $game_temp.temp_chest.empty? ? true : false
- # modifying chest and inventory...
- $game_party.lose_item(@item, n)
- $game_temp.temp_chest.gain_item(@item, n, true)
- @spoils_window.index = 0 if reset_chest
- @inv_window.index -= 1 unless @inv_window.index == 0 || item_lost == false
- @inv_window.refresh
- @spoils_window.refresh
- hide_drop_choice_window if !@drop_choice_window.nil?
- end
- #--------------------------------------------------------------------------
- # * Takes all of the items from the chest an puts them in the player's
- # inventory.
- #--------------------------------------------------------------------------
- def take_all
- items = $game_temp.temp_chest.all_item_objects + $game_temp.temp_chest.all_dropped_objects
- index = 0
- for i in items
- index += 1 # variable is required to use item_dropped? method
- dropped = @spoils_window.item_dropped?(index)
- $game_party.gain_item(i, $game_temp.temp_chest.item_number(i, dropped))
- end
- $game_temp.temp_chest.all_items = [-1]
- $game_temp.temp_chest.all_dropped = [-1]
- @inv_window.refresh
- @spoils_window.refresh
- @spoils_window.active = false
- @spoils_window.index = -1
- @inv_window.active = true
- end
- #--------------------------------------------------------------------------
- # * Determines which action to take when a number is chosen from the number
- # select window.
- #--------------------------------------------------------------------------
- def move_num_items
- case @num_window.type
- when -1
- Print 'ERROR: @num_window\'s source has not been set!'
- when 1
- Sound.play_decision
- leave_item(@num_window.number)
- when 2
- Sound.play_decision
- take_item(@num_window.number)
- when 3
- Sound.play_drop
- drop_item(@num_window.number)
- end
- end
- #--------------------------------------------------------------------------
- # * Determines whether it is possible for the player to exit
- # If it is possible, then confirm_exit is called.
- #--------------------------------------------------------------------------
- def check_exit
- f_item_names = [] # any items with the 'force' tag
- for i in $game_temp.temp_chest.all_item_objects
- f_item_names.push(i.name) if i.force_take?
- end
- if f_item_names != []
- Sound.play_buzzer
- show_message(5, f_item_names)
- return true
- end
- if !ENCUMBER
- if $game_party.total_inv_size <= $max_inv_size && $game_temp.temp_chest.total_size <= $game_temp.temp_chest.max_size
- Sound.play_cancel
- return confirm_exit
- elsif $game_party.total_inv_size > $max_inv_size
- Sound.play_buzzer
- show_message(2)
- return true
- elsif $game_temp.temp_chest.total_size > $game_temp.temp_chest.max_size
- if $game_temp.temp_chest.unlimited?
- Sound.play_cancel
- return confirm_exit
- end
- if !$game_temp.temp_chest.accessable?
- Sound.play_cancel
- return confirm_exit
- end
- Sound.play_buzzer
- show_message(3)
- return true
- end
- else
- Sound.play_cancel
- return confirm_exit
- end
- end
- #--------------------------------------------------------------------------
- # * Determines whether to show an exit window to player, and if so which one
- #--------------------------------------------------------------------------
- def confirm_exit
- # these override the value of CONFIRMATION
- if !CONF_EMPTY_CHEST && $game_temp.temp_chest.total_size == 0
- Sound.play_cancel
- do_exit
- return true
- elsif CONF_MODE_ZERO && $game_temp.temp_chest.mode == 0 && $game_temp.temp_chest.total_size != 0
- show_exit_window(0)
- else # if neither evaluate to true, check CONFIRMATION
- case CONFIRMATION
- when 0 # always
- show_exit_window($game_temp.temp_chest.mode)
- when 1 # never
- Sound.play_cancel
- do_exit
- return true
- when 2 # only if there are 'dropped' items
- if $game_temp.temp_chest.all_dropped != [-1]
- show_exit_window($game_temp.temp_chest.mode)
- else
- Sound.play_cancel
- do_exit
- return true
- end
- end
- end
- end
- #--------------------------------------------------------------------------
- # * Exits the scene, and makes modifications to the $chests hash as
- # necessary
- # exit : variable necessary if the player is exiting whilst
- # over_encumbered. Since 2 exit windows are called, this is
- # used to make sure the first checks the size of the inventory.
- #--------------------------------------------------------------------------
- def do_exit(exit = false)
- unless exit
- # this is because if ENCUMBER is true then two exit windows are called one
- # after the other.
- if $game_party.total_inv_size > $max_inv_size && ENCUMBER && INFORM_E_SPOILS
- show_exit_window(3)
- return
- end
- end
- # empty chest if it is mode zero
- if $game_temp.temp_chest.mode == 0
- $game_temp.temp_chest.all_items = [-1]
- $game_temp.temp_chest.active = false
- end
- # empty dropped items
- $game_temp.temp_chest.all_dropped = [-1]
- $game_temp.temp_chest.opened = true
- if $game_temp.temp_chest.is_a?(Chest) && !@chest_id.nil?
- # transfer temp_chets back to $chests hash
- # This does not occur if the chest is B_Spoils object.
- $chests[@chest_id] = $game_temp.temp_chest.deep_clone
- end
- $game_temp.temp_chest = nil
- $scene = case @source
- when 1: Scene_Map.new # from map
- when 2: Scene_Menu.new # from menu
- when 3: Scene_Map.new # from battle
- end
- end
- #--------------------------------------------------------------------------
- # * Termination Processing
- #--------------------------------------------------------------------------
- def terminate
- super
- dispose_menu_background
- @spoils_window.dispose
- @spoils_title.dispose
- @inv_window.dispose
- @inv_title.dispose
- @info_window.dispose
- @drop_choice_window.dispose unless @drop_choice_window.nil?
- @message_window.dispose unless @message_window.nil?
- @exit_window.dispose unless @exit_window.nil?
- @num_window.dispose unless @num_window.nil?
- end
- #--------------------------------------------------------------------------
- # * Updates all the window objects
- #--------------------------------------------------------------------------
- def update_windows
- @spoils_window.update
- @spoils_title.update
- @inv_window.update
- @inv_title.update
- @info_window.update
- @drop_choice_window.update unless @drop_choice_window.nil?
- @message_window.update unless @message_window.nil?
- @exit_window.update unless @exit_window.nil?
- @num_window.update unless @num_window.nil?
- end
- #--------------------------------------------------------------------------
- # * Main frame update method
- # Checks for input, and calls the appropriate sub-update method depending on
- # which windows are open.
- #--------------------------------------------------------------------------
- def update
- super
- # for gold message delay...
- @gold_counter = 0 if @gold_counter.nil?
- if @inv_window.active || @spoils_window.active
- if Input.trigger?(Input::B)
- return if check_exit
- elsif Input.trigger?(Input::LEFT)
- move_left
- elsif Input.trigger?(Input::RIGHT)
- move_right
- end
- # checks for gold in chest
- if $game_temp.temp_chest.gold != 0 && @gold_counter == GOLD_MSG_DEL
- show_message(6, $game_temp.temp_chest.gold)
- $game_party.gain_gold($game_temp.temp_chest.gold)
- $game_temp.temp_chest.gold = 0
- end
- end
- # window-dependant updates
- if @inv_window.active # Inventory window
- @item = @inv_window.item
- @dropped = false
- update_inv_item_selection if Input.trigger?(Input::C)
- elsif @spoils_window.active # Spoils window
- @item = @spoils_window.item
- @dropped = @spoils_window.item_dropped?(@spoils_window.index)
- det_move_item(2) if Input.trigger?(Input::C)
- elsif !@message_window.nil? # Message window
- if Input.trigger?(Input::C) or Input.trigger?(Input::B)
- Sound.play_cancel
- hide_message_window
- end
- elsif !@drop_choice_window.nil? # 'drop choice' window
- update_drop_choice_window
- elsif !@exit_window.nil? # exit confirmation window
- return if update_exit_window
- elsif !@num_window.nil? # number select window (drop, take or leave)
- @num_window.update_num_selection
- if Input.trigger?(Input::C)
- Sound.play_decision
- move_num_items
- hide_num_window
- elsif Input.trigger?(Input::B)
- Sound.play_cancel
- hide_num_window
- end
- end
- # redefine @item and @dropped before update_infos is called
- if @inv_window.active # Inventory window
- @item = @inv_window.item
- @dropped = false
- elsif @spoils_window.active # Spoils window
- @item = @spoils_window.item
- @dropped = @spoils_window.item_dropped?(@spoils_window.index)
- end
- update_infos
- update_windows
- # for gold message delay...
- @gold_counter += 1 unless @gold_counter >= GOLD_MSG_DEL
- end
- #--------------------------------------------------------------------------
- # * Update exit window option selection
- #--------------------------------------------------------------------------
- def update_exit_window
- if Input.trigger?(Input::B)
- Sound.play_cancel
- hide_exit_window
- return false
- elsif Input.trigger?(Input::C)
- if @exit_window.index == 0
- Sound.play_decision
- exit = (@exit_window.type == 4)
- hide_exit_window
- # if it is the 2nd exit_window, then don't check encumberment
- do_exit(exit)
- return true
- elsif @exit_window.index == 1
- Sound.play_cancel
- hide_exit_window
- return false
- end
- end
- end
- #--------------------------------------------------------------------------
- # * Update drop choice window option selection
- #--------------------------------------------------------------------------
- def update_drop_choice_window
- if Input.trigger?(Input::B)
- Sound.play_cancel
- hide_drop_choice_window
- elsif Input.trigger?(Input::C)
- case @drop_choice_window.index
- when 0 # leave item
- unless $game_temp.temp_chest.accessable?
- Sound.play_buzzer
- unless NO_LEAVE_MSG == -1
- hide_drop_choice_window
- show_message(4)
- end
- return
- end
- det_move_item(1)
- when 1 # drop item
- det_move_item(3)
- end
- end
- end
- #------------------------------------------------------------
Add Comment
Please, Sign In to add comment