Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- ################################################################################
- # LOOT CONTAINERS 1.0a
- # By: Ixfuru
- ################################################################################
- # This script enables you to create Containers. Containers are objects which
- # hold items which the player can find. There is a lot of customization you can
- # do to this script, and with it, you can make as many containers as you want
- # to. The first step for you to use this script will be to go into the
- # Containers module and create containers under the 'CONTAINERS' constant.
- #
- # There you can give the container a name, capacity, create its initial contents
- # and gold, as well as several other settings. Once you create the container,
- # Then go to the script call command of any event and call:
- #
- # $scene = Scene_Container(x)
- #
- # With 'x' being the ID of the container you created in the CONTAINER hash.
- #
- # For further script calls related to the system, see the section titled:
- # 'Extended Script Calls'
- #
- #-------------------------------------------------------------------------------
- # Make sure you follow the instructions carefully for best results, and if you
- # have any trouble, be sure to contact me in the RPGMakerVX.net forums or
- # the RMRK.net forums for assistance. You can either post in the topic where
- # you found the script or you contact me via personal message.
- #-------------------------------------------------------------------------------
- # This script is non-commercially free. If you choose to use it in a commercial
- # project, you must receive my (Ixfuru's) permission and you either way,
- # I must be creditted.
- #-------------------------------------------------------------------------------
- #
- # VERSIONS:
- #
- # 1.0a : Redid the Scene File read/write methods in order to make them more
- # compatible with other scripts. The script now Aliases both methods.
- # : Fixed a bug where if the contents of a container was empty, it
- # would say empty even if the box was locked.
- #===============================================================================
- #===============================================================================
- # Module Containers
- #===============================================================================
- module Ixfuru
- module Containers
- ############################################################################
- #!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
- # CREATING A CONTAINER
- #!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
- ############################################################################
- # Below is the CONTAINERS hash. In it, you will set up all the properties
- # of the container. There are some settings which are NECESSARY and some
- # that aren't. For instance, if your container is not 'lockable' you don't
- # have to have the setting for :locked or :key.
- #
- # Here is a list of settings your container MUST HAVE:
- #
- # :name
- # :capacity
- # :contents
- # :lockable
- # :gold
- #
- # It doesn't matter what order you place them in, as long as they are
- # present in your container. If not, your container will give an
- # error message when you try to access it.
- #
- # Here is a list of optional settings your container can have.
- #
- # :graphic
- # :opening_se
- # :closing_se
- # :locked (:key)
- #
- # If you do not provide these settings, the system will assume you want to
- # use the default settings for these. However, it is important to note that
- # if you place a :locked setting then you MUST HAVE a :key setting.
- #---------------------------------------------------------------------------
- #
- # So, to create the container, follow this formula:
- #
- # container_id => {settings => properties}
- #
- # For example:
- #
- # 3 => {:name => "Container",
- # :capacity => 8,
- # :contents => [],
- # :gold => 44,
- # :lockable => true},
- #
- # In the example, if you were to call $scene = Scene_Container.new(3),
- # this container would be opened in the new scene.
- #
- #---------------------------------------------------------------------------
- #
- # The following is a list of all the settings with a description of each,
- # including what the system expects to find for the properties of each.
- #
- # :name - This is just a string, double-quoted ("") which will be used to
- # display to the player what container he/she is in. You can have
- # multiple containers with the same name, it's basically just for
- # looks. Here are some examples of good :name settings:
- #
- # "Box", "Sack", "Bag", "Crate", "Urn", etc.
- #
- # ***
- #
- # :capacity - This value should be an integer, at least one, but there is no
- # limit to how big :capacity can be. :capacity sets how many
- # items can be placed into the container before it is full and
- # can no longer accept more items.
- #
- # ***
- #
- # :contents - This is an array, holding the items (if any) which are to be
- # in the container at the start of the game. This must be
- # set up precisely to the rules found below. Note that if you
- # want to start out with an empty container, simply use [] as the
- # properties for :contents.
- #
- # Each item in the :contents array is made up of a two-element
- # inner array:
- #
- # [item_type, item_id]
- #
- # item_type : 0 for item, 1 for weapon, 2 for armor
- # item_id : the database ID of the item you wish to place in
- # the container at startup.
- #
- # So by placing:
- #
- # [2, 21]
- #
- # We are saying, place the armor with the ID of 21 in the database
- # into the chest at start up. So, a full :contents property can
- # be as many of these entries as you prefer. Here's an example
- # of a contents property with five starting items.
- #
- # [[0, 2], [1, 4], [0, 6], [2, 2], [2, 5]]
- #
- # In the above example, the container would start out with
- # database items 2 and 6, database weapon 4 and armors 2 and 5.
- #
- # Conversely, you can use a string as the argument instead of
- # an array. The string must say:
- #
- # "MFx"
- #
- # With X being the id of the item pool from which you want to
- # get the item to be placed. By using a string instead of an
- # array, you are telling the system to pick an item at random
- # from the TREASURES hash in the 'Creating Manifested
- # Treasures' settings found below the container's settings.
- # So, by calling: "MF2", you are saying, get the item from
- # the TREASURES pool with an ID of 2. For more on this, skip
- # to that section for details on how to set up the item pools
- # for use with :contents string elements.
- #
- # ***
- #
- # :gold - This is the amount of gold you want the container to start out with.
- # You can start it out as 0, or as much as you want. It just needs
- # to be an integer for a preset amount.
- #
- # Conversely, you can use a string in order to pull a random
- # number of gold from the GOLDS hash in the section titled
- # 'Creating Manifested Treasures'. Basically, this involves you
- # placing the string:
- #
- # "Gx"
- #
- # With 'x' being the ID of the gold pool you provide in the GOLDS
- # hash. For further details, see the settings of that section.
- #
- # :lockable - This is a boolean value (true or false) which tells whether or
- # not the container can be locked. If a container is locked,
- # the player must have a key in order to unlock it or lock it
- # again.
- #
- # :graphic - This is a two-element array:
- #
- # [graphic_when_locked, graphic_when_unlocked]
- #
- # graphic_when_locked : [filename, index]
- # graphic_when_unlocked : [filename, index]
- #
- # filename : the name of the graphic in the "Graphics/Characters/"
- # folder of your project.
- # index : the index on the character sheet
- #
- # So, the :graphic array should look like this:
- #
- # [["Chest", 3], ["Chest", 5]]
- #
- # In the above example, the container would display Chest-3 when
- # locked, and Chest-5 when unlocked.
- #
- # The graphic setting is optional, and if you don't set it, it will
- # not use a graphic in the container. The setting is basically for
- # looks. It has no bearing in functionality. But if you use a
- # graphic, it will be displayed next to the name of the container
- # during the scene.
- #
- # :opening_se/:closing_se - This setting tells the system what sound effect to
- # play when the container is opening and closing.
- # It is a three element array:
- #
- # [filename, volume, pitch]
- #
- # filename : the file from your "Audio/SE" folder
- # volumne : how loud the sound should be
- # pitch : the pitch of the sound effect when played
- #
- # :locked - This setting is a boolean (true or false). It tells the system
- # whether or not the container should be locked or not at startup.
- # If a container is locked, you will be unable to see the contents
- # of the container until it is unlocked. If you set this to true
- # YOU MUST also give a ':key' setting in order to unlock it at
- # runtime.
- #
- # :key - This is the database ID of the item you wish to use for unlocking/
- # locking the container.
- #
- #===========================================================================
- #
- #
- CONTAINERS = {# Don't delete that.
- 0 => {:name => "Box",
- :capacity => 5,
- :contents => [[0, 12], [0, 4], [1, 8], [2, 3], [0, 25]],
- :lockable => false,
- :graphic => [["!Chest", 6], ["!Chest", 6]],
- :gold => 156,
- :opening_se => ["Chest", 80, 100],
- :closing_se => ["Close1", 80, 100],
- :locked => false,
- :key => nil},
- 1 => {:name => "Chest",
- :capacity => 10,
- :contents => ["MF0", "MF0", "MF1", "MF2", "MF3", "MF4"],
- :lockable => true,
- :graphic => [["!Chest", 4], ["!Chest", 4]],
- :gold => "G3",
- :locked => true,
- :key => 25},
- }
- ############################################################################
- #!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
- ############################################################################
- # The text you want to be displayed if the container is locked
- LOCKED_TEXT = "LOCKED!"
- # The text color of LOCKED_TEXT when displayed
- LOCKED_COLOR = 2
- # The button which will perform locking/unlocking procedure
- LOCK_BUTTON = Input::Y
- # The SE [filename, volume, pitch] which will played when you lock/unlock the
- # container
- LOCK_SOUND = ["Key", 80, 100]
- # The index of the icon you wan to use in the gold windows
- GOLD_LOOT_INDEX = 147
- # The text you want to display when a slot of the container has nothing in it
- LOOT_EMPTY_TEXT = "-EMPTY-"
- # The text you want to display when the container is locked and you can't
- # see the contents.
- HIDDEN_LOOT_TEXT = "?????"
- # The button you want to take ALL the contents/gold of the container
- TAKE_ALL_BUTTON = Input::A
- # This sets which buttons you wish to control how you jump from one
- # window to the next in the scene. If you use 0, you will push Q and W
- # in order to change the active windows. If you use 1, you'll use the
- # arrow keys right and left instead.
- WINDOW_CONTROL_INPUT = 1
- # The sound you want to play when you take a single item from the container
- # [filename, volume, pitch]
- TAKE_SOUND = ["Decision2", 80, 100]
- # The sound played when you modify gold in the gold windows
- # [filename, volume, pitch]
- GOLD_SOUND = ["Shop", 80, 100]
- # The sound played when you Take ALL of the items in the container/gold window
- TAKE_ALL_SOUND = ["Sword3", 80, 100]
- # The sound played when you place an item from the party into the container
- GIVE_SOUND = ["Close2", 80, 100]
- # The sound played when the container opens (if not set in the settings)
- DEFAULT_OPENING_SE = ["Chest", 80, 100]
- # The sound played when the container closes (if not set in the settings)
- DEFAULT_CLOSING_SE = ["Close1", 80, 100]
- end
- #=============================================================================
- # Module Manifest Treasure
- #=============================================================================
- module ManifestTreasure
- ############################################################################
- #!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
- # Creating Manifested Treasures
- ############################################################################
- # Manifested treasures are treasures chosen from a pool you create. This will
- # make it so that even you, as the creator, can't say exactly what is in the
- # containers you create. When you place "MFx" as a :content entry in the
- # CONTAINERS hash above, the system will sort through the TREASURES hash,
- # find the one with the ID of x and choose an item from the pools given.
- #
- # So to create one, you need to use this formula:
- #
- # treasure_id => {:items => [item_ids],
- # :weapons => [weapon_ids],
- # :armors => [armor_id]},
- #
- # You don't have to have all three (:items, :weapons, :armors) keys in the
- # hash. If you just wnat the pool to render items, just put the :items one.
- # for the item_ids/weapon_ids/armor_ids place the database ID of the item
- # you want to be placed into the pool
- #
- # For example:
- #
- # 5 => {:items => [4, 6, 7, 8],
- # :armors => [12, 25]},
- #
- # In the above example, the pool will consist of items 4, 6, 7, and 8, as wells
- # as armors 12 and 25. And to choose from this pool, you would place "MF5"
- # in the :contents setting of a container.
- ############################################################################
- TREASURES = {
- # Curing Rations
- 0 => {:items => [5, 6, 7, 8]},
- # Potions
- 1 => {:items => [1, 2, 3, 4]},
- # Weapons
- 2 => {:weapons => [1, 2, 3, 4, 5]},
- # Armors
- 3 => {:armors => [1, 2, 3, 4, 5]},
- # Mixed Bag
- 4 => {:items => [1, 2, 3, 4, 5, 6, 7, 8],
- :weapons => [1, 2, 3, 4, 5],
- :armors => [1, 2, 3, 4, 5]},
- }
- #===========================================================================
- # Manifested gold acts much the same as the manifested treasures pool.
- # The difference is that you call it by placing "Gx" in the :gold setting
- # of a container. And you only need to provide a low and high amount in the
- # pools.
- #
- # For example:
- #
- # 3 => [52, 88],
- #
- # The above example would place gold amount between 52 and 88 inside the
- # container and you would call the pool by using "G3" in the :gold setting
- # of a container you create.
- #===========================================================================
- GOLDS = {
- 0 => [1, 10],
- 1 => [11, 25],
- 2 => [26, 50],
- 3 => [51, 100],
- 4 => [101, 200],
- 5 => [201, 400],
- 6 => [401, 800],
- 7 => [801, 1600],
- }
- end
- ##############################################################################
- #!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
- # Extended Script Calls
- #!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
- # All containers can be called with the script call:
- #
- # $containers[x]
- #
- # With 'x' being the ID of the container.
- #
- # There are a number of procedures you can use to access and perform actions
- # on the containers:
- #-----------------------------------------------------------------------------
- # ***
- # $containers[x].add_gold(amount, true)
- #
- # add amount to container x's gold
- #-----------------------------------------------------------------------------
- # $containers[x].full?
- #
- # checks to see if container x is full
- #-----------------------------------------------------------------------------
- # ***
- # $containers[x].add_to_contents(item, true)
- #
- # item : database item/weapon/armor you want to add to container x
- #-----------------------------------------------------------------------------
- # ***
- # $containers[x].locked?
- #
- # checks to see if container x is locked
- #-----------------------------------------------------------------------------
- # ***
- # $containers[x].add_capacity(amount)
- #
- # adds amount to container x capacity
- #-----------------------------------------------------------------------------
- # ***
- # $containers[x].decrease_capacity(amount)
- #
- # reduces the space of container[x] by amount
- #-----------------------------------------------------------------------------
- # ***
- # $containers[x].lock(true)
- #
- # locks container[x]
- #-----------------------------------------------------------------------------
- # ***
- # $containers[x].unlock
- #
- # unlocks container x
- #-----------------------------------------------------------------------------
- #+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
- # DON'T EDIT FURTHER! DON'T EDIT FURTHER!
- #+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
- #=============================================================================
- # Module Regexp
- #=============================================================================
- module Regexp
- NO_CONTAINER = /<no_container>/i
- MANIFEST_TREASURE = /MF(\d+)/i
- MANIFEST_GOLD = /G(\d+)/i
- end
- end
- ################################################################################
- #*******************************************************************************
- # RPG::BaseItem
- ################################################################################
- class RPG::BaseItem
- #-----------------------------------------------------------------------------
- # No Container
- #-----------------------------------------------------------------------------
- def no_container
- self.note.split(/[\r\n]/).each { |line|
- case line
- when Ixfuru::Regexp::NO_CONTAINER
- return true
- end
- }
- return false
- end
- end
- ################################################################################
- #*******************************************************************************
- # Scene Title
- ################################################################################
- class Scene_Title < Scene_Base
- #--------------------------------------------------------------------------
- # * Create Game Objects (Aliased)*
- #--------------------------------------------------------------------------
- alias ixfuru_containers_create_game_objects create_game_objects unless $@
- def create_game_objects
- ixfuru_containers_create_game_objects
- $containers = {}
- end
- end
- ################################################################################
- #*******************************************************************************
- # Scene File
- ################################################################################
- class Scene_File < Scene_Base
- #--------------------------------------------------------------------------
- # * Write Save Data (Aliased)*
- # file : write file object (opened)
- #--------------------------------------------------------------------------
- alias ixfuru_containers_write write_save_data unless $@
- def write_save_data(file)
- ixfuru_containers_write(file)
- Marshal.dump($containers, file)
- end
- #--------------------------------------------------------------------------
- # * Read Save Data (OVERWRITTEN!)
- # file : file object for reading (opened)
- #--------------------------------------------------------------------------
- alias ixfuru_containers_read read_save_data unless $@
- def read_save_data(file)
- ixfuru_containers_read(file)
- $containers = Marshal.load(file)
- end
- end
- ################################################################################
- #*******************************************************************************
- # Container
- ################################################################################
- class Container
- attr_reader :container_id
- attr_accessor :name
- attr_accessor :capacity
- attr_accessor :contents
- attr_accessor :gold
- attr_accessor :locked
- attr_accessor :lockable
- attr_accessor :key
- def initialize(container_id)
- @container_id = container_id
- setup
- end
- #-----------------------------------------------------------------------------
- # Setup
- #-----------------------------------------------------------------------------
- def setup
- base = Ixfuru::Containers::CONTAINERS[@container_id]
- @name = base[:name]
- @capacity = base[:capacity]
- @contents = base[:contents]
- @lockable = base[:lockable]
- @locked = base[:locked].nil? ? false : base[:locked]
- @key = base[:key].nil? ? nil : base[:key]
- @graphic = base[:graphic].nil? ? [] : base[:graphic]
- @opening_se = base[:opening_se].nil? ? Ixfuru::Containers::DEFAULT_OPENING_SE : base[:opening_se]
- @closing_se = base[:closing_se].nil? ? Ixfuru::Containers::DEFAULT_CLOSING_SE : base[:closing_se]
- @gold = base[:gold].nil? ? 0 : base[:gold]
- update_manifests
- $containers[@container_id] = self
- end
- #-----------------------------------------------------------------------------
- # Update Manifests
- #-----------------------------------------------------------------------------
- def update_manifests
- for i in 0...@contents.size
- next unless @contents[i].is_a?(String)
- next unless Ixfuru::Regexp::MANIFEST_TREASURE =~ @contents[i]
- t = $1.to_i
- picks = []
- treasures = Ixfuru::ManifestTreasure::TREASURES[t]
- if treasures.has_key?(:items)
- for item in treasures[:items]
- picks.push([0, item])
- end
- end
- if treasures.has_key?(:weapons)
- for weapon in treasures[:weapons]
- picks.push([1, weapon])
- end
- end
- if treasures.has_key?(:armors)
- for armor in treasures[:armors]
- picks.push([2, armor])
- end
- end
- @contents[i] = picks[rand(picks.size)]
- end
- if @gold.is_a?(String) && Ixfuru::Regexp::MANIFEST_GOLD =~ @gold
- g = $1.to_i
- amounts = []
- golds = Ixfuru::ManifestTreasure::GOLDS[g]
- for a in golds[0]..golds[1]
- amounts.push(a)
- end
- @gold = amounts[rand(amounts.size)]
- end
- end
- #-----------------------------------------------------------------------------
- # Open
- #-----------------------------------------------------------------------------
- def open
- se = @opening_se
- RPG::SE.new(se[0], se[1], se[2]).play
- end
- #-----------------------------------------------------------------------------
- # Close
- #-----------------------------------------------------------------------------
- def close
- se = @closing_se
- RPG::SE.new(se[0], se[1], se[2]).play
- end
- #-----------------------------------------------------------------------------
- # Character
- #-----------------------------------------------------------------------------
- def character
- return nil if @graphic.empty?
- return @graphic[0] if locked?
- return @graphic[1]
- end
- #-----------------------------------------------------------------------------
- # Current Contents
- #-----------------------------------------------------------------------------
- def current_contents
- result = []
- return result if @contents.empty?
- for content in @contents
- case content[0]
- when 0 # item
- result.push($data_items[content[1]])
- when 1 # weapon
- result.push($data_weapons[content[1]])
- when 2 # Armor
- result.push($data_armors[content[1]])
- end
- end
- return result
- end
- #-----------------------------------------------------------------------------
- # Toggler
- #
- # direction : button to jump left or right
- #-----------------------------------------------------------------------------
- def toggler(direction)
- case Ixfuru::Containers::WINDOW_CONTROL_INPUT
- when 0
- case direction
- when 0 # left
- return Input::L
- when 1 # right
- return Input::R
- end
- when 1
- case direction
- when 0 # left
- return Input::LEFT
- when 1 # right
- return Input::RIGHT
- end
- end
- end
- #-----------------------------------------------------------------------------
- # Add Gold
- #-----------------------------------------------------------------------------
- def add_gold(amount, bypass = false)
- if bypass
- @gold += amount
- return
- end
- if $game_party.gold - amount >= 0
- play_gold
- @gold += amount
- $game_party.lose_gold(amount)
- end
- end
- #-----------------------------------------------------------------------------
- # Take Gold
- #-----------------------------------------------------------------------------
- def take_gold(amount)
- if @gold - amount >= 0
- play_gold
- @gold -= amount
- $game_party.gain_gold(amount)
- end
- end
- #-----------------------------------------------------------------------------
- # Gold Amount
- #-----------------------------------------------------------------------------
- def gold_amount
- return @gold
- end
- #-----------------------------------------------------------------------------
- # Take All Button
- #-----------------------------------------------------------------------------
- def take_all_button
- return Ixfuru::Containers::TAKE_ALL_BUTTON
- end
- #-----------------------------------------------------------------------------
- # Locked?
- #-----------------------------------------------------------------------------
- def locked?
- return false if !@lockable
- return @locked
- end
- #-----------------------------------------------------------------------------
- # Full?
- #-----------------------------------------------------------------------------
- def full?
- return true if @contents.size == @capacity
- return false
- end
- #-----------------------------------------------------------------------------
- # Add Capacity
- #-----------------------------------------------------------------------------
- def add_capacity(space)
- @capacity += space
- end
- #-----------------------------------------------------------------------------
- # Decrease Capacity
- #-----------------------------------------------------------------------------
- def decrease_capacity(space)
- @capacity -= space
- end
- #-----------------------------------------------------------------------------
- # Take All
- #-----------------------------------------------------------------------------
- def take_all
- return if @contents.empty?
- play_take_all
- for content in current_contents
- $game_party.gain_item(content, 1)
- end
- @contents.clear
- end
- #-----------------------------------------------------------------------------
- # Play Take All
- #-----------------------------------------------------------------------------
- def play_take_all
- se = Ixfuru::Containers::TAKE_ALL_SOUND
- RPG::SE.new(se[0], se[1], se[2]).play
- end
- #-----------------------------------------------------------------------------
- # Add To Contents
- #
- # When adding gold to the contents, you need to pass a string "gold" appended
- # with the amount you wish to add, "gold456" would add 456 gold.
- #-----------------------------------------------------------------------------
- def add_to_contents(item, bypass = false)
- i = content_item(item)
- if bypass
- @contents.push(i)
- return
- end
- play_give
- @contents.push(i)
- $game_party.lose_item(item, 1)
- end
- #-----------------------------------------------------------------------------
- # Content Item
- #-----------------------------------------------------------------------------
- def content_item(item)
- case item
- when RPG::Item
- i = 0
- a = item.id
- when RPG::Weapon
- i = 1
- a = item.id
- when RPG::Armor
- i = 2
- a = item.id
- end
- return [i, a]
- end
- #-----------------------------------------------------------------------------
- # Play Lock
- #-----------------------------------------------------------------------------
- def play_lock
- se = Ixfuru::Containers::LOCK_SOUND
- RPG::SE.new(se[0], se[1], se[2]).play
- end
- #-----------------------------------------------------------------------------
- # Lock
- #-----------------------------------------------------------------------------
- def lock(bypass = false)
- return if locked?
- return if !@lockable
- if bypass
- @locked = true
- return
- end
- k = container_key
- return if !$game_party.has_item?(k)
- play_lock
- @locked = true
- end
- #-----------------------------------------------------------------------------
- # Container Key
- #-----------------------------------------------------------------------------
- def container_key
- return $data_items[@key]
- end
- #-----------------------------------------------------------------------------
- # Unlock
- #-----------------------------------------------------------------------------
- def unlock(bypass = false)
- return if !locked?
- return if !@lockable
- if bypass
- @locked = false
- return
- end
- k = container_key
- return if k.nil?
- return if !$game_party.has_item?(k)
- play_lock
- @locked = false
- end
- #-----------------------------------------------------------------------------
- # Take
- #-----------------------------------------------------------------------------
- def take(index)
- i = content_item(@contents[index])
- play_take
- $game_party.gain_item(current_contents[index], 1)
- @contents.delete_at(index)
- end
- #-----------------------------------------------------------------------------
- # Play Gold
- #-----------------------------------------------------------------------------
- def play_gold
- se = Ixfuru::Containers::GOLD_SOUND
- RPG::SE.new(se[0], se[1], se[2]).play
- end
- #-----------------------------------------------------------------------------
- # Play Take
- #-----------------------------------------------------------------------------
- def play_take
- se = Ixfuru::Containers::TAKE_SOUND
- RPG::SE.new(se[0], se[1], se[2]).play
- end
- #-----------------------------------------------------------------------------
- # Play Give
- #-----------------------------------------------------------------------------
- def play_give
- se = Ixfuru::Containers::GIVE_SOUND
- RPG::SE.new(se[0], se[1], se[2]).play
- end
- end
- ################################################################################
- #*******************************************************************************
- # WINDOW CONTAINER INSTRUCTIONS
- ################################################################################
- class Window_ContainerInstructions < Window_Base
- attr_accessor :active_window
- #-----------------------------------------------------------------------------
- # Initialize
- #-----------------------------------------------------------------------------
- def initialize(container, active_window)
- super(0, 0, 272, 80)
- @container = container
- @active_window = active_window
- refresh
- end
- #-----------------------------------------------------------------------------
- # Refresh
- #-----------------------------------------------------------------------------
- def refresh
- self.contents.clear
- ss = select_string
- ls = lock_string
- tas = take_all_string
- self.contents.font.size = 12
- lh = 16
- self.contents.font.color = system_color
- self.contents.draw_text(0, 0, self.width - 32, lh, ss, 1)
- self.contents.draw_text(0, lh, self.width - 32, lh, ls, 1)
- unless @active_window.is_a?(Window_Belongings) ||
- @active_window.is_a?(Window_ContainerGold) && @party
- self.contents.draw_text(0, lh * 2, self.width - 32, lh, tas, 1)
- end
- end
- #-----------------------------------------------------------------------------
- # Select String
- #-----------------------------------------------------------------------------
- def select_string
- if @active_window.is_a?(Window_ContainerContents)
- return "Press SPACE to take"
- elsif @active_window.is_a?(Window_Belongings)
- return "Press SPACE to place item in " + @container.name
- elsif @active_window.is_a?(Window_ContainerGold)
- case @active_window.party
- when true
- return "Press SPACE to place " + Vocab::gold + " into " + @container.name
- when false
- return "Press SPACE to take " + Vocab::gold
- end
- end
- end
- #-----------------------------------------------------------------------------
- # Button Return String
- #-----------------------------------------------------------------------------
- def button_return_string(button)
- case button
- when Input::C
- return "SPACE"
- when Input::B
- return "X"
- when Input::A
- return "SHIFT"
- when Input::X
- return "A"
- when Input::Y
- return "S"
- when Input::Z
- return "D"
- when Input::L
- return "Q"
- when Input::R
- return "W"
- end
- end
- #-----------------------------------------------------------------------------
- # Lock String
- #-----------------------------------------------------------------------------
- def lock_string
- button = Ixfuru::Containers::LOCK_BUTTON
- str = @container.locked? ? "unlock" : "lock"
- return "Press " + button_return_string(button) + " to " + str
- end
- #-----------------------------------------------------------------------------
- # Take All String
- #-----------------------------------------------------------------------------
- def take_all_string
- button = Ixfuru::Containers::TAKE_ALL_BUTTON
- return "Press " + button_return_string(button) + " " + "to take all"
- end
- end
- ################################################################################
- #*******************************************************************************
- # WINDOW CONTAINTER STATUS
- ################################################################################
- class Window_ContainerStatus < Window_Base
- attr_accessor :container
- #-----------------------------------------------------------------------------
- # Initialize
- #-----------------------------------------------------------------------------
- def initialize(container)
- super(272, 0, 272, 80)
- @container = container
- @name = @container.name
- @character = @container.character
- refresh
- end
- #-----------------------------------------------------------------------------
- # Refresh
- #-----------------------------------------------------------------------------
- def refresh
- self.contents.clear
- @holdings = @container.contents.size
- @capacity = @container.capacity
- self.contents.font.color = system_color
- if !@character.nil?
- nts = self.contents.text_size(@name).width + 72
- name_pointx = ((self.width - 32) / 2) - (nts / 2)
- draw_character(@character[0], @character[1], name_pointx, 32)
- self.contents.draw_text(name_pointx + 36, 0, self.width - 32, WLH, @name)
- else
- nts = self.contents.text_size(@name)
- name_pointx = ((self.width - 32) / 2) - (nts / 2)
- self.contents.draw_text(name_pointx, 0, self.width - 32, WLH, @name)
- end
- if @container.locked?
- self.contents.font.color = text_color(Ixfuru::Containers::LOCKED_COLOR)
- self.contents.draw_text(0, WLH, self.width - 32, WLH, Ixfuru::Containers::LOCKED_TEXT, 1)
- else
- self.contents.font.color = normal_color
- self.contents.draw_text(0, WLH, self.width - 32, WLH, "(" + @holdings.to_s + "/" + @capacity.to_s + ")", 1)
- end
- end
- end
- ################################################################################
- #*******************************************************************************
- # WINDOW CONTAINER CONTENTS
- ################################################################################
- class Window_ContainerContents < Window_Selectable
- attr_accessor :container
- attr_accessor :loot
- #-----------------------------------------------------------------------------
- # Initialize
- #-----------------------------------------------------------------------------
- def initialize(container)
- super(272, 80, 272, 280)
- @container = container
- @loot = @container.current_contents
- refresh
- self.index = 0
- end
- #-----------------------------------------------------------------------------
- # Refresh
- #-----------------------------------------------------------------------------
- def refresh
- @loot = @container.current_contents
- @item_max = @container.capacity
- create_contents
- for i in 0...@item_max
- draw_loot(i)
- end
- end
- #-----------------------------------------------------------------------------
- # Draw Loot
- #-----------------------------------------------------------------------------
- def draw_loot(index)
- rect = item_rect(index)
- rect.x += 4
- rect.width += 8
- if @container.locked?
- self.contents.font.color = system_color
- self.contents.draw_text(rect, Ixfuru::Containers::HIDDEN_LOOT_TEXT)
- elsif @loot[index].nil?
- self.contents.font.color = system_color
- self.contents.draw_text(rect, Ixfuru::Containers::LOOT_EMPTY_TEXT, 1)
- else
- self.contents.font.color = normal_color
- draw_item_name(@loot[index], rect.x, rect.y)
- end
- end
- end
- ################################################################################
- #*******************************************************************************
- # WINDOW BELONGINGS
- ################################################################################
- class Window_Belongings < Window_Selectable
- attr_accessor :belongings
- #-----------------------------------------------------------------------------
- # Initialize
- #-----------------------------------------------------------------------------
- def initialize
- super(0, 80, 272, 280)
- refresh
- self.index = 0
- self.active = false
- end
- #------------------------------------------------------------------------------
- # Refresh
- #-----------------------------------------------------------------------------
- def refresh
- @belongings = $game_party.items
- @item_max = @belongings.size
- create_contents
- unless @belongings.empty?
- for i in 0...@item_max
- draw_belonging(i)
- end
- end
- end
- #-----------------------------------------------------------------------------
- # Draw Belonging
- #-----------------------------------------------------------------------------
- def draw_belonging(index)
- rect = item_rect(index)
- rect.x += 4
- rect.width -= 8
- self.contents.font.color.alpha = enabled?(index) ? 255 : 128
- draw_item_name(@belongings[index], rect.x, rect.y, enabled?(index))
- self.contents.draw_text(rect, $game_party.item_number(@belongings[index]), 2)
- end
- #-----------------------------------------------------------------------------
- # Enabled?
- #-----------------------------------------------------------------------------
- def enabled?(index)
- return false if @belongings[index].no_container
- return true
- end
- end
- ################################################################################
- #*******************************************************************************
- # WINDOW CONTAINER GOLD
- ################################################################################
- class Window_ContainerGold < Window_Selectable
- attr_reader :party
- #-----------------------------------------------------------------------------
- # Initialize
- #-----------------------------------------------------------------------------
- def initialize(container, party = false)
- @container = container
- @party = party
- if @party
- super(0, 360, 272, 56)
- else
- super(272, 360, 272, 56)
- end
- @item_max = 1
- refresh
- self.index = 0
- self.active = false
- end
- #-----------------------------------------------------------------------------
- # Window Gold
- #-----------------------------------------------------------------------------
- def window_gold
- return $game_party.gold if @party
- return @container.gold
- end
- #-----------------------------------------------------------------------------
- # Refresh
- #-----------------------------------------------------------------------------
- def refresh
- self.contents.clear
- @gold = window_gold
- for i in 0...@item_max
- draw_gold(i)
- end
- end
- #-----------------------------------------------------------------------------
- # Draw Gold
- #-----------------------------------------------------------------------------
- def draw_gold(index)
- rect = item_rect(index)
- rect.x += 4
- rect.width -= 8
- gw = self.contents.text_size(@gold.to_s).width + 26
- xpoint = ((self.width - 32) / 2) - (gw / 2)
- draw_icon(Ixfuru::Containers::GOLD_LOOT_INDEX, xpoint, 0)
- if @container.locked? && !@party
- str = Ixfuru::Containers::HIDDEN_LOOT_TEXT
- self.contents.font.color = system_color
- self.contents.draw_text(xpoint + 26, 0, self.width - 32, WLH, str)
- else
- self.contents.font.color = normal_color
- self.contents.draw_text(xpoint + 26, 0, self.width - 32, WLH, @gold.to_s)
- end
- end
- end
- ################################################################################
- #*******************************************************************************
- # SCENE CONTAINER
- ################################################################################
- class Scene_Container < Scene_Base
- #-----------------------------------------------------------------------------
- # Initialize
- #-----------------------------------------------------------------------------
- def initialize(container_id)
- @container_id = container_id
- if $containers.has_key?(container_id)
- @container = $containers[container_id]
- else
- @container = Container.new(container_id)
- end
- @amount_return = 1
- end
- #-----------------------------------------------------------------------------
- # Start
- #-----------------------------------------------------------------------------
- def start
- super
- create_menu_background
- @win_status = Window_ContainerStatus.new(@container)
- @win_contents = Window_ContainerContents.new(@container)
- @win_belongings = Window_Belongings.new
- @win_partygold = Window_ContainerGold.new(@container, true)
- @win_containergold = Window_ContainerGold.new(@container)
- @win_instructions = Window_ContainerInstructions.new(@container, @win_belongings)
- @container.open
- end
- #-----------------------------------------------------------------------------
- # Update
- #-----------------------------------------------------------------------------
- def update
- super
- update_lock
- if @win_partygold.active
- update_partygold
- elsif @win_containergold.active
- update_containergold
- elsif @win_contents.active
- update_contents
- elsif @win_belongings.active
- update_belongings
- end
- end
- #-----------------------------------------------------------------------------
- # Refresh Windows
- #-----------------------------------------------------------------------------
- def refresh_windows
- @win_partygold.refresh
- @win_containergold.refresh
- @win_belongings.refresh
- @win_contents.refresh
- @win_status.refresh
- @win_instructions.refresh
- end
- #-----------------------------------------------------------------------------
- # Update Lock
- #-----------------------------------------------------------------------------
- def update_lock
- if Input.trigger?(Ixfuru::Containers::LOCK_BUTTON)
- if @container.locked?
- @container.unlock
- else
- @container.lock
- end
- refresh_windows
- end
- end
- #-----------------------------------------------------------------------------
- # Update Instructions
- #-----------------------------------------------------------------------------
- def update_instructions
- caw = current_active_window
- return if caw.nil?
- @win_instructions.active_window = caw
- @win_instructions.refresh
- end
- #-----------------------------------------------------------------------------
- # Currently Active Window
- #-----------------------------------------------------------------------------
- def current_active_window
- windows = [@win_belongings, @win_contents, @win_partygold, @win_containergold]
- for window in windows
- if window.active
- return window
- end
- end
- return nil
- end
- #-----------------------------------------------------------------------------
- # Update Contents
- #-----------------------------------------------------------------------------
- def update_contents
- @win_contents.update
- item = @win_contents.loot[@win_contents.index]
- if Input.trigger?(Input::C)
- if !item.nil? && !@container.locked?
- @container.take(@win_contents.index)
- @win_contents.refresh
- @win_belongings.refresh
- @win_status.refresh
- else
- Sound.play_buzzer
- end
- elsif Input.trigger?(Input::B)
- @container.close
- $scene = Scene_Map.new
- elsif Input.trigger?(@container.toggler(0)) # jump left
- Sound.play_decision
- @win_contents.active = false
- @win_partygold.active = true
- update_instructions
- elsif Input.trigger?(@container.toggler(1)) # jump right
- Sound.play_decision
- @win_contents.active = false
- @win_containergold.active = true
- update_instructions
- elsif Input.trigger?(@container.take_all_button) && !@container.locked?
- @container.take_all
- @win_contents.refresh
- @win_belongings.refresh
- @win_status.refresh
- end
- end
- #-----------------------------------------------------------------------------
- # Update Belongings
- #-----------------------------------------------------------------------------
- def update_belongings
- @win_belongings.update
- item = @win_belongings.belongings[@win_belongings.index]
- if Input.trigger?(Input::C)
- if !@container.full? && !item.nil? && !item.no_container && !@container.locked?
- @container.add_to_contents(item)
- @win_contents.refresh
- @win_belongings.refresh
- @win_status.refresh
- if @win_belongings.index >= @win_belongings.belongings.size
- @win_belongings.index = @win_belongings.belongings.size - 1
- end
- else
- Sound.play_buzzer
- end
- elsif Input.trigger?(Input::B)
- @container.close
- $scene = Scene_Map.new
- elsif Input.trigger?(@container.toggler(0)) # jump left
- Sound.play_decision
- @win_belongings.active = false
- @win_containergold.active = true
- update_instructions
- elsif Input.trigger?(@container.toggler(1)) # jump right
- Sound.play_decision
- @win_belongings.active = false
- @win_partygold.active = true
- update_instructions
- end
- end
- #-----------------------------------------------------------------------------
- # Update Gold Windows
- #-----------------------------------------------------------------------------
- def update_gold_windows
- @win_partygold.refresh
- @win_containergold.refresh
- end
- #-----------------------------------------------------------------------------
- # Update Partygold
- #-----------------------------------------------------------------------------
- def update_partygold
- @win_partygold.update
- if Input.press?(Input::C)
- unless @container.locked?
- @container.add_gold(1)
- update_gold_windows
- end
- elsif Input.trigger?(Input::B)
- @container.close
- $scene = Scene_Map.new
- elsif Input.trigger?(@container.toggler(0)) #jump left
- Sound.play_decision
- @win_partygold.active = false
- @win_belongings.index = 0
- @win_belongings.active = true
- update_instructions
- elsif Input.trigger?(@container.toggler(1)) # jump right
- Sound.play_decision
- @win_partygold.active = false
- @win_contents.index = 0
- @win_contents.active = true
- update_instructions
- end
- end
- #-----------------------------------------------------------------------------
- # Update ContainerGold
- #------------------------------------------------------------------------------
- def update_containergold
- @win_containergold.update
- if Input.press?(Input::C)
- unless @container.locked?
- @container.take_gold(1)
- update_gold_windows
- end
- elsif Input.trigger?(Input::B)
- @container.close
- $scene = Scene_Map.new
- elsif Input.trigger?(@container.take_all_button) && !@container.locked?
- @container.play_gold
- @container.take_gold(@container.gold)
- update_gold_windows
- elsif Input.trigger?(@container.toggler(0)) # jump left
- Sound.play_decision
- @win_containergold.active = false
- @win_contents.index = 0
- @win_contents.active = true
- update_instructions
- elsif Input.trigger?(@container.toggler(1)) # jump right
- Sound.play_decision
- @win_containergold.active = false
- @win_belongings.index = 0
- @win_belongings.active = true
- update_instructions
- end
- end
- #-----------------------------------------------------------------------------
- # Terminate
- #-----------------------------------------------------------------------------
- def terminate
- super
- dispose_menu_background
- windows = [@win_containergold, @win_partygold, @win_belongings, @win_status,
- @win_contents, @win_instructions]
- for window in windows
- window.dispose
- end
- end
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement