Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #==============================================================================
- # Item Instances Base
- # Version: 1.0
- # Author: modern algebra (rmrk.net)
- # Date: August 7, 2011
- #++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
- # Description:
- #
- # This is a scripting tool that changes the way items are handled in the
- # game to allow for item instances. This means that items specially marked
- # will be uniquely saved every time you collect them.
- #
- # This script was designed since scripts which require items to be saved as
- # instances, even if they were conceptually simple (like durability), were
- # impractical to make since they required a heavy overhaul of the entire item
- # system. Other scripts that have tried tend to be very bulky and usually
- # incompatible with every other item-based script out there. This script was
- # therefore designed to (a) change the way marked items were saved so as to
- # be more dynamic and saved as instances; (b) be compatible or easily made
- # compatible with most other scripts that deal with items; and (c) be easy
- # to create addons which make use of the framework to create functional
- # changes to items, weapons, and armors.
- #
- # This script makes little functional difference aside from changing how
- # marked items are stacked in the menu and allows you to change the specific
- # stats of items if you add them through the Change Item/Weapon/Armor event
- # commands by using a comment. However, it provides a necessary structure for
- # other scripts, such as a weapon durability or charges script, where the
- # stats necessarily must vary between items of the same type.
- #
- # While I made this script to provide a base for a series of scripts I will
- # make, any scripter is welcome to use this as a base for their own scripts.
- #++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
- # Instructions:
- #
- # This script must be placed ABOVE Main and BELOW every regular custom script
- # that might deal with items, even if they do so only incidentally. However,
- # any scripts that utilize this script as a base must be BELOW it (and still
- # above Main).
- #
- # To mark an item to be stored on an instance by instance basis, just write
- # into its note box the following:
- # \instance
- #
- # This script will apply to any item, weapon or armor that has that marked.
- # For those types of items, you can also directly change the stats of them if
- # you add them through an event command. To do so, make a comment directly
- # underneath the event command that adds a marked item, and put codes of the
- # following format:
- # \II[n].stat[value]
- # n : the number of the item. Set it to 0 unless you are adding more
- # than one item through the same event command. So, if you are adding
- # 3 of the same type of instance item, then you can use this to denote
- # which you wish to change, with 0=> first one, 1=> second one, and so
- # on. To avoid confusion, you should add them one at a time and just
- # always use 0.
- # stat : this is the stat you wish to vary. You can only vary a stat if
- # it contains either a boolean value, a number, or a string. You must
- # use the exact method. The list of stats you can modify are:
- # ITEM - base_damage, variance, atk_f, spi_f, parameter_type,
- # parameter_points, hp_recovery_rate, hp_recovery, scope, speed,
- # occasion, mp_recovery_rate, mp_recovery, price, common_event_id,
- # physical_attack, damage_to_mp, absorb_damage, ignore_defense
- # WEAPON - atk, def, agi, spi, hit, price, two_handed, fast_attack,
- # dual_attack, critical_bonus
- # ARMOR - atk, def, spi, agi, eva, kind, price, prevent_critical,
- # half_mp_cost, double_exp_gain, auto_hp_recover
- # value : the value you want to change it to. It must be either an
- # integer, a boolean value, or a string. You MUST put in the type
- # of value the stat would expect. For properties, such as two_handed,
- # a boolean (true/false) is expected.
- #
- # You can also modify the maximum number you can have of instance items. The
- # default value is at line 150 and is currently 999. If that is fine but you
- # want to change it for only some instance items, like a special potion, you
- # can use the following code in that item's notebox:
- #
- # \INS_MAX[x]
- # x : the maximum number of instances of that item that you want to
- # be able to carry.
- #++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
- # Guidelines:
- #
- # I made this mostly for my own planned scripts. However, if you are a
- # scripter and want to use this as a base for a new script, you should read
- # the script carefully to develop a full understanding, but here are some
- # basic guidelines:
- #
- # To check if a particular item creates instances, you can use the code:
- # item.instance_based?
- #
- # If you are adding a notebox code, you can add the RegExp to the
- # RPG::BaseItem::MA_INSTANCE_CHECKS constant and it will interpret any item
- # with that code as instance based and treat it accordingly. Otherwise, you
- # would need to manually alias the instance_based? method or else require
- # the use of the generic \Instance code.
- #
- # You can get the ID of the base item from an instance item by asking for
- # the item_id attribute, while the id attribute will return the unique
- # index of the instance item. If you ever need the id method to return the
- # base's item ID instead of its unique ID, then you turn the get_item_id
- # attribute to true and it will. This is useful especially for aliasing.
- #
- # If you want instance items to be destroyed when they are lost (which you
- # should do if the player will never have a chance to recover them), you
- # can set $game_party.ii_destroy_lost_instances to true.
- #
- # To create a new instance without going through the gain_item method, you
- # use the code data.create_instance (base_item), where data is either
- # $data_items, $data_weapons, or $data_armors and base_item is an
- # RPG::Item/Weapon/Armor object. To destroy an instance, you use
- # data.destroy_instance (index) where data is the same and index is the
- # item's unique ID.
- #
- # You can retrieve all the existing instance items with a base ID by the
- # code: data.items_with_id (x) where x is the ID in question. For instance,
- # if you want to get all instances of the long sword (ID 2), you'd ask for
- # $data_weapons.items_with_id (2). Note that it will return ALL instance
- # items with that ID and not only those held by the party. For instance, it
- # will also give you them even if they are currently equipped.
- #
- # $data_items, $data_weapons, & $data_armors are all still the arrays they
- # used to be, only with the [] and []= methods altered for instance item
- # support. As such, any array methods will work exactly as they used to -
- # So if you do $data_items.each {} then you will cycle through only the
- # base items and not the instance items.
- #
- # The code $game_party.newest_instance_items will return an array of all
- # the latest items the party has received through the gain_item command.
- #==============================================================================
- $imported = {} unless $imported
- $imported["MAInstanceItemsBase"] = true
- module RPG
- #==============================================================================
- # ** BaseItem
- #++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
- # Summary of Changes:
- # new method - instance_based?
- #==============================================================================
- class BaseItem
- #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
- # * Constants
- #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
- #\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\
- # EDITABLE REGION
- #||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
- MA_INS_ITEM_MAX = 999 # Maximum of any instance items to be carried.
- #||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
- # END EDITABLE REGION
- #//////////////////////////////////////////////////////////////////////////
- MA_INSTANCE_CHECKS = [/\\(INSTANCE|INS_MAX)/i] # An array of REGEXP codes. If any are
- # included in a notebox of an item, it will recognized as an instance item.
- #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
- # * Public Instance Variables
- #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
- attr_writer :ii_item_max # Maximum number of instances to be held in inventory
- alias item_id id # Alias for the ID reader attribute
- #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
- # * Check if this item is instance based
- #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
- def instance_based?
- if !@ins_base
- @ins_base = false
- MA_INSTANCE_CHECKS.each { |check|
- if self.note[check] != nil
- @ins_base = true
- break
- end
- }
- end
- return @ins_base
- end
- #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
- # * Instance Max
- #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
- def ii_item_max
- if !@ii_item_max
- @ii_item_max = self.note[/\\INS_MAX\[(\d+)\]/i].nil? ? MA_INS_ITEM_MAX : $1.to_i
- end
- return @ii_item_max
- end
- #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
- # * Superclass Variables
- #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
- def self.ii_accessor_attributes
- nil_ary = self.instance_methods.select { |method| !method.include? ("=") && self.instance_methods.include? ("#{method}=") }
- set_ary = ["scope", "occasion"] & nil_ary
- set_ary << "note" if $imported["AddEquipmentOptions"]
- # KGC Equipment Options Compatibility
- return nil_ary - set_ary, set_ary
- end
- end
- #==============================================================================
- # ** RPG::Class
- #++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
- # Summary of Changes:
- # aliased methods - weapon_set; armor_set
- #==============================================================================
- class Class
- unless self.method_defined? (:ma_ii_wpnset_4fr1)
- alias ma_ii_wpnset_4fr1 weapon_set
- alias mga_ins_armst_6un8 armor_set
- end
- #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
- # * Weapon Set
- #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
- def weapon_set (*args, &block)
- actual_result = ma_ii_wpnset_4fr1 (*args, &block) # Run Original Method
- result = actual_result.dup
- actual_result.each { |weapon_id|
- result.push *(($data_weapons.items_with_id (weapon_id)).collect { |wpn| wpn.id } )
- }
- return result
- end
- #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
- # * Armor Set
- #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
- def armor_set (*args, &block)
- actual_result = mga_ins_armst_6un8 (*args, &block) # Run Original Method
- result = actual_result.dup
- actual_result.each { |armor_id|
- result.push *(($data_armors.items_with_id (armor_id)).collect { |amr| amr.id } )
- }
- return result
- end
- end
- end
- #==============================================================================
- # *** II_BaseItem
- #++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
- # This module contains the basic setup methods for instance items, to be mixed
- #==============================================================================
- module II_BaseItem
- #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
- # * Constants
- #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
- # A string for replacing attribute methods such that they will return the
- # corresponding attribute from the base item unless it has been changed for
- # the new item. wxyz will be replaced with the name of the method. This
- # code will be evaled in each of the Game_Item/Weapon/Armor classes for
- # every attribute reader method of its superclass. I do it this way so that
- # changes to the items in the database will be reflected unless they are
- # specifically adjusted.
- MAII_ACCESSOR_CODE = <<_END_
- alias maii_alias_wxyz_2ki3 wxyz unless self.method_defined? (:maii_alias_wxyz_2ki3)
- def wxyz (*args, &block)
- # If redefined in II_BaseItem, return that
- return super (*args, &block) if II_BaseItem.method_defined? (:wxyz) && !(super (*args, &block)).nil?
- result = maii_alias_wxyz_2ki3 (*args, &block)
- # If the basic code for this does not return nil, return that
- return result unless result.nil?
- # Return this method from the base item as it is unaltered.
- return base_item.wxyz (*args, &block)
- end
- _END_
- #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
- # * Public Instance Variables
- #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
- attr_reader :item_id
- #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
- # * Object Initialization
- #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
- def initialize (index, item)
- setup (item)
- self.id = index
- end
- #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
- # * Setup
- #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
- def setup (item)
- @item_id = item.id
- @type_id = item.is_a? (RPG::Item) ? 0 : item.is_a? (RPG::Weapon) ? 1 : 2
- nil_ary, set_ary = item.class.ii_accessor_attributes
- nil_ary.each { |name| self.send ("#{name}=", nil) }
- set_ary.each { |name| self.send ("#{name}=", item.send (name)) }
- end
- #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
- # * Get ID
- #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
- def id
- return $game_system.get_item_id ? self.item_id : super
- end
- #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
- # * Base Item
- #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
- def base_item
- # If the base item exists, return it; otherwise return self
- return $game_system.instance_items[@type_id][@item_id].nil? ? self : $game_system.instance_items[@type_id][@item_id]
- end
- end
- #==============================================================================
- # ** Game_Item
- #++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
- # This class holds in-game data for an item instance
- #==============================================================================
- class Game_Item < RPG::Item
- # Include BaseItem
- include II_BaseItem
- # Define all attributes to return base item stats unless it's been altered.
- RPG::Item.ii_accessor_attributes[0].each { |method|
- next if II_BaseItem.method_defined? (method.to_sym)
- eval ( MAII_ACCESSOR_CODE.gsub (/wxyz/) { method.to_s } )
- }
- end
- #==============================================================================
- # ** Game_Weapon
- #++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
- # This class holds in-game data for a weapon
- #==============================================================================
- class Game_Weapon < RPG::Weapon
- # Include BaseItem
- include II_BaseItem
- # Define all attributes to return base item stats unless it's been altered.
- RPG::Weapon.ii_accessor_attributes[0].each { |method|
- next if II_BaseItem.method_defined? (method.to_sym)
- eval ( MAII_ACCESSOR_CODE.gsub (/wxyz/) { method } )
- }
- end
- #==============================================================================
- # ** Game_Armor
- #++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
- # This class holds in-game data for an armor
- #==============================================================================
- class Game_Armor < RPG::Armor
- # Include BaseItem
- include II_BaseItem
- # Define all attributes to return base item stats unless it's been altered.
- RPG::Armor.ii_accessor_attributes[0].each { |method|
- next if II_BaseItem.method_defined? (method.to_sym)
- eval ( MAII_ACCESSOR_CODE.gsub (/wxyz/) { method.to_s } )
- }
- end
- #==============================================================================
- # ** Game_InstanceItems
- #++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
- # This class replaces $data_items, $data_weapons, and $data_armors so as to
- # provide support for instance items.
- #==============================================================================
- class Game_InstanceItems < Array
- #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
- # * Object Initialization
- #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
- def initialize (type_id)
- @items = {}
- @free_indices = []
- @last_index = 1000
- @type_id = type_id
- @type = case @type_id
- when 0 then Game_Item
- when 1 then Game_Weapon
- when 2 then Game_Armor
- end
- end
- #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
- # * Reset Base Data
- #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
- def reset_base_data (data_array)
- self.clear
- for item in data_array do self << item end
- end
- #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
- # * Create Instance
- # base_item : the item to make, either RPG::@type or the ID of it
- #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
- def create_instance (base_item)
- base_item = self[base_item] if base_item.is_a? (Integer)
- return base_item if base_item.is_a? (@type) || !base_item.instance_based?
- # Get next free index
- if @free_indices.empty?
- indx = @last_index
- @last_index += 1
- else
- indx = @free_indices.shift
- end
- @items[indx] = @type.new (indx, base_item)
- return @items[indx]
- end
- #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
- # * Destroy Instance
- # index : the index of the item in the hash
- #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
- def destroy_instance (index)
- @free_indices.push (index)
- @items.delete (index)
- end
- #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
- # * Retrieve Value from key
- #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
- def [] (key)
- return key < 1000 ? super (key) : @items[key]
- end
- #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
- # * Set Value to Key
- #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
- def []=(key, value)
- key < 1000 ? super (key, value) : @items[key] = value
- end
- #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
- # * Items with ID
- # This will return an array of all items with the specified ID
- #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
- def items_with_id (item_id)
- return @items.values.select { |instance| instance.item_id == item_id }
- end
- end
- #==============================================================================
- # ** Game System
- #++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
- # Summary of Changes:
- # new attributes - instance_items; get_item_id
- # aliased method - initialize
- #==============================================================================
- class Game_System
- #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
- # * Public Instance Variables
- #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
- attr_reader :instance_items # The array holding all instances of items
- attr_accessor :get_item_id # A boolean for whether id returns base id
- #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
- # * Object Initialization
- #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
- alias ma_init_instnc_items_9jc3 initialize
- def initialize (*args)
- @get_item_id = false
- ma_init_instnc_items_9jc3 (*args) # Run Original Method
- # Create Weapons and Armors objects
- @instance_items = [Game_InstanceItems.new (0), Game_InstanceItems.new (1),
- Game_InstanceItems.new (2)]
- end
- end
- #==============================================================================
- # ** Game_Actor
- #++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
- # Summary of Changes:
- # aliased method - setup, equippable?
- #==============================================================================
- class Game_Actor
- #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
- # * Setup
- #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
- alias maga_setup_instnc_itms_8kj2 setup
- def setup (*args)
- # If re-initializing, delete the equipped items
- if @weapon_id != nil
- equips.each { |equip|
- next if equip.nil?
- case equip
- when Game_Weapon then $data_weapons.destroy_instance (equip.id)
- when Game_Armor then $data_armors.destroy_instance (equip.id)
- end
- }
- end
- # Run Original Method
- maga_setup_instnc_itms_8kj2 (*args)
- # Create instances of preset equipment
- @weapon_id = $data_weapons.create_instance (@weapon_id).id unless @weapon_id == 0
- if two_swords_style
- @armor1_id = $data_weapons.create_instance (@armor1_id).id unless @armor1_id == 0
- else
- @armor1_id = $data_armors.create_instance (@armor1_id).id unless @armor1_id == 0
- end
- @armor2_id = $data_armors.create_instance (@armor2_id).id unless @armor2_id == 0
- @armor3_id = $data_armors.create_instance (@armor3_id).id unless @armor3_id == 0
- @armor4_id = $data_armors.create_instance (@armor4_id).id unless @armor4_id == 0
- end
- end
- #==============================================================================
- # ** Game_Party
- #++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
- # Summary of Changes:
- # aliased methods - items; item_number; gain_item; consume_item
- # new method - newest_instance_items; gain_instance_item; lose_instance_item
- #==============================================================================
- class Game_Party
- #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
- # * Public Instance Variables
- #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
- attr_accessor :ii_destroy_lost_instances
- #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
- # * Items
- #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
- alias mlg_insite_items_5tg8 items
- def items (*args, &block)
- result = mlg_insite_items_5tg8 (*args, &block) # Run Original Method
- # Sort Items by Item ID, so that like items are together. The other array
- # is in case another script has made a new item object
- sitems, sweapons, sarmors, other = [], [], [], []
- while !result.empty?
- itm = result.shift
- next if itm.instance_based? && !itm.is_a? (II_BaseItem) # Don't add Base
- case itm
- when RPG::Item then sitems << itm
- when RPG::Weapon then sweapons << itm
- when RPG::Armor then sarmors << itm
- else # Category in case any other script makes a strange new item type
- other << itm
- end
- end
- sitems.sort! { |a, b| a.item_id <=> b.item_id }
- sweapons.sort! { |a, b| a.item_id <=> b.item_id }
- sarmors.sort! { |a, b| a.item_id <=> b.item_id }
- return sitems + sweapons + sarmors + other
- end
- #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
- # * Consume Item
- #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
- alias malii_consumeitem_6tg9 consume_item
- def consume_item(*args, &block)
- $game_party.ii_destroy_lost_instances = true
- malii_consumeitem_6tg9 (*args, &block) # Run Original Method
- $game_party.ii_destroy_lost_instances = false
- end
- #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
- # * Gain Items (or lose)
- # item : Item
- # n : Number
- #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
- alias ma_insims_gnim_7yt1 gain_item
- def gain_item (item, n = 1, include_equip = false, *args)
- return if item == nil || n == 0
- @newest_items = []
- type = item.is_a? (RPG::Item) ? 0 : item.is_a? (RPG::Weapon) ? 1 : 2
- # Compatibility with Item Catalogue
- if Game_Party.method_defined? (:item_encounter_array)
- array = item_encounter_array (item)
- array << item.item_id unless array.include? (item.item_id)
- end
- if item.is_a? (II_BaseItem) # n can only be -1 or 1.
- num = item_number (item.base_item)
- return if num >= item.ii_item_max
- data_type = $game_system.instance_items[type]
- if n < 0 # n would have been returned if 0, so can only be < 0 or > 0
- if item_number (item) != 0
- data_type.destroy_instance (item.id) if @ii_destroy_lost_instances
- elsif include_equip
- for actor in members
- if actor.equips.include? (data_type[item.id])
- actor.discard_equip(item)
- data_type.destroy_instance (item.id) if @ii_destroy_lost_instances
- break
- end
- end
- end
- end
- ma_insims_gnim_7yt1 (item, n, false, *args) # Update Hash for item
- # Update Hash for the base item
- [@items, @weapons, @armors][type][item.item_id] = [[num + n, 0].max, item.ii_item_max].min
- elsif item.instance_based? # If gaining new instance items
- num = item_number (item)
- n = [n, item.ii_item_max - num].min if n > 0
- gain_instance_item (item, n, include_equip) # Create new instances
- # Update Hash for the new items
- @newest_items.each { |ins| ma_insims_gnim_7yt1 (ins, (n <=> 0), false, *args) }
- # Update Hash for the base item
- [@items, @weapons, @armors][type][item.id] = [num + n, 0].max
- else
- ma_insims_gnim_7yt1 (item, n, include_equip, *args) # Run Original Method
- end
- end
- #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
- # * Gain Instance
- # item - a RPG::Item/Weapon/Armor object to create new Game_object of
- #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
- def gain_instance_item (item, n = 1, include_equip = false)
- if item.is_a? (II_BaseItem) # If already an instance item, send back
- gain_item (item, n, include_equip)
- return
- end
- case item
- when RPG::Item then data_type, type_id = $data_items, 0
- when RPG::Weapon then data_type, type_id = $data_weapons, 1
- when RPG::Armor then data_type, type_id = $data_armors, 2
- end
- if n > 0
- n.times { |i|
- new_item = data_type.create_instance (item)
- @newest_items.push ( new_item )
- }
- else
- instances = data_type.items_with_id (item.id)
- instances.each { |item2|
- break if n == 0 || item_number (item) == 0
- next if item_number (item2) == 0
- @newest_items.push (item2)
- data_type.destroy_instance (item2.id) if @ii_destroy_lost_instances
- n += 1
- }
- if n < 0 && include_equip
- for actor in members
- equipped_instances = instances & actor.equips
- while n < 0 && !equipped_instances.empty?
- item2 = equipped_instances.shift
- @newest_items.push (item2)
- actor.discard_equip(item2)
- data_type.destroy_instance (item2.id) if @ii_destroy_lost_instances
- n += 1
- end
- end
- end
- end
- end
- #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
- # * Lose Instance Item
- #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
- def lose_instance_item (item, n = 1, include_equip = false)
- gain_instance_item (item, n*-1, include_equip)
- end
- #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
- # * Newest Instance Items
- #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
- def newest_instance_items
- return @newest_items.nil? ? [] : @newest_items
- end
- # YEM Equipment Overhaul Compatibility Patch
- if $imported["EquipmentOverhaul"]
- #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
- # * Items Only / Equip Weapons / Equip Armours
- #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
- [:items_only, :equip_weapons, :equip_armours].each { |method_name|
- alias_method ("mayfly_iiyemeqp_#{method_name}_8uj1".to_sym, method_name)
- define_method (method_name) do |*args|
- result = self.send ("mayfly_iiyemeqp_#{method_name}_8uj1", *args)
- result.select! { |item| item.instance_based? && !item.is_a? (II_BaseItem) }
- return result.sort { |a, b| a.item_id <=> b.item_id }
- end
- }
- end
- end
- #==============================================================================
- # ** Game_Interpreter
- #++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
- # Summary of Changes:
- # aliased methods - command_126, command_127, command_128
- # new method - read_items_comment
- #==============================================================================
- class Game_Interpreter
- #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
- # * Read Item Comment
- # item : the item to modify
- #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
- def ii_read_items_comment
- return if $game_party.newest_instance_items.empty?
- i = @index + 1
- comment = ""
- # Retrieve entire comment
- while i < @list.size && [108, 408].include? (@list[i].code)
- comment += @list[i].parameters[0]
- i += 1
- end
- while comment.slice! (/\\II\[(\d+)\]\.(.+?)\[(.+?)\]/im) != nil
- key, method, value = $1.to_i, $2.to_s, $3.to_s
- value.gsub (/\r\n/) { " " }
- if value[/[^0-9\.]/] == nil # Integer
- value = value.to_i
- elsif value[/\ATRUE\Z/i] != nil # True
- value = true
- elsif value[/\AFALSE\Z/i] != nil # False
- value = false
- end
- begin
- $game_party.newest_instance_items[key].send ("#{method}=", value)
- rescue
- end
- end
- end
- #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
- # * Gain Item/Weapon/Armor
- # Thank Zeriab for this little trick
- #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
- # Go through each gain method and read the following comment
- [126, 127, 128].each { |method|
- alias_method ("ma_gain_command_#{method}".to_sym, "command_#{method}".to_sym)
- define_method ("command_#{method}".to_sym) { |*args|
- $game_party.ii_destroy_lost_instances = true
- result = self.send ("ma_gain_command_#{method}".to_sym, *args)
- $game_party.ii_destroy_lost_instances = false
- ii_read_items_comment
- return result
- }
- }
- end
- #==============================================================================
- # ** Window_Item
- #++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
- # Summary of Changes:
- # aliased method - draw_item
- # new method - clear_item_right; draw_item_right
- #==============================================================================
- class Window_Item
- #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
- # * Clear Item Right
- #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
- def clear_item_right (index)
- rect = index.is_a? (Rect) ? index : item_rect (index)
- erase_text = sprintf(":%2d", $game_party.item_number(@data[index]))
- tw = self.contents.text_size ( erase_text).width
- self.contents.clear_rect (rect.x + rect.width - 4 - tw, rect.y, tw + 4, rect.height)
- end
- #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
- # * Draw Item Right
- #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
- def draw_item_right (index)
- # To be overwritten by subscripts
- end
- #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
- # * Draw Item
- # index : item number
- #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
- alias mlgb_iidrawitm_removenum_5tg1 draw_item
- def draw_item(index, *args, &block)
- mlgb_iidrawitm_removenum_5tg1 (index, *args, &block) # Run Original Method
- if @data[index].is_a? (RPG::BaseItem) && @data[index].instance_based?
- clear_item_right (index)
- draw_item_right (index)
- end
- end
- end
- #==============================================================================
- # ** Scene_Title
- #++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
- # Summary of Changes:
- # aliased methods - create_game_objects
- #==============================================================================
- class Scene_Title
- #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
- # * Create Game Objects
- #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
- alias mala_crtgm_obj_institm_6hf2 create_game_objects
- def create_game_objects (*args)
- # Run Original Method
- mala_crtgm_obj_institm_6hf2 (*args)
- # Preserve Basic Arrays
- $game_system.instance_items[0].reset_base_data ($data_items.dup)
- $game_system.instance_items[1].reset_base_data ($data_weapons.dup)
- $game_system.instance_items[2].reset_base_data ($data_armors.dup)
- # Tie $data_items, $data_weapons, and $data_armors to Game_InstanceItems
- $data_items, $data_weapons, $data_armors = *$game_system.instance_items
- end
- end
- #==============================================================================
- # ** Scene_File
- #++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
- # Summary of Changes:
- # aliased method - read_save_data
- #==============================================================================
- class Scene_File
- #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
- # * Write Save Data
- #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
- alias mdrna_ii_wrtsvda_5tp2 write_save_data
- def write_save_data (*args)
- databases = $game_system.instance_items.dup
- # Purge Basic Data arrays so as not to save basic data
- for i in 0...3 do $game_system.instance_items[i].reset_base_data ([]) end
- mdrna_ii_wrtsvda_5tp2 (*args)
- # Recover Data Arrays
- for i in 0...3 do $game_system.instance_items[i].reset_base_data (databases[i]) end
- end
- #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
- # * Read Save Data
- #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
- alias malbra_insitms_rdsave_6th2 read_save_data
- def read_save_data (*args)
- # Run Original Method
- malbra_insitms_rdsave_6th2 (*args)
- if !$game_system.instance_items
- p "This save file is corrupted as the Instance Items script was installed after it was made. You need to start a new game or else remove the Instance Items script."
- end
- # Preserve Basic Arrays
- $game_system.instance_items[0].reset_base_data ($data_items.dup)
- $game_system.instance_items[1].reset_base_data ($data_weapons.dup)
- $game_system.instance_items[2].reset_base_data ($data_armors.dup)
- # Tie $data_items, $data_weapons, and $data_armors to instance items
- $data_items, $data_weapons, $data_armors = *$game_system.instance_items
- end
- end
- #==============================================================================
- # ** Scene Shop
- #++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
- # Summary of Changes:
- # aliased method - decide_number_input
- #==============================================================================
- class Scene_Shop
- #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
- # * Confirm Number Input
- #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
- alias mlg_ii_decidnuminput_4yg7 decide_number_input
- def decide_number_input (*args, &block)
- $game_party.ii_destroy_lost_instances = true # Destroy any instance lost
- mlg_ii_decidnuminput_4yg7 (*args, &block) # Run Original Method
- $game_party.ii_destroy_lost_instances = false
- end
- end
- # Grid Inventory Compatibility
- if Object.constants.include? ("Game_InventoryGrid")
- #==============================================================================
- # ** Game_InventoryGrid
- #++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
- # Summary of Changes:
- # aliased method - item_search
- #==============================================================================
- class Game_InventoryGrid
- #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
- # * Item Search
- #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
- alias mala_iigrid_itmsrch_6dc4 item_search
- def item_search (*args, &block)
- $game_system.get_item_id = true
- result = mala_iigrid_itmsrch_6dc4 (*args, &block)
- $game_system.get_item_id = false
- return result
- end
- end
- #==============================================================================
- # ** Item_Placement (Grid Inventory)
- #++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
- # Summary of Changes:
- # aliased method - item_id
- #==============================================================================
- class Item_Placement
- #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
- # * Item ID
- #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
- alias mlba_giinsba_itmid_6yh1 item_id
- def item_id (*args, &block)
- return item.item_id if !item.nil? && $game_system.get_item_id
- return mlba_giinsba_itmid_6yh1 (*args, &block) # Run Original Method
- end
- end
- end
- # Limited Inventory Compatibility
- if Object.constants.include? ("Game_LimitedInventory")
- #==============================================================================
- # ** Game_LimitedInventory
- #++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
- # Summary of Changes:
- # aliased methods - add_item; remove_item
- #==============================================================================
- class Game_LimitedInventory
- #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
- # * Add/Remove Item
- #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
- [:add_item, :remove_item].each { |method_name|
- alias_method ("ma_liminvinitm_#{method_name}_6yu8".to_sym, method_name)
- define_method (method_name) do |type, id, *args|
- $game_system.get_item_id = (id < 1000)
- # Run Original Method
- result = self.send ("ma_liminvinitm_#{method_name}_6yu8", type, id, *args)
- $game_system.get_item_id = false
- return result
- end
- }
- end
- #==============================================================================
- # ** Game_LimInvSlot
- #++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
- # Summary of Changes:
- # aliased method - item_id
- #==============================================================================
- class Game_LimInvSlot
- #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
- # * Item ID
- #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
- alias mga_insliminv_itmid_9jb2 item_id
- def item_id (*args, &block)
- return item.item_id if !item.nil? && $game_system.get_item_id
- return mga_insliminv_itmid_9jb2 (*args, &block) # Run Original Method
- end
- end
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement