Advertisement
modern_algebra

Item Instances Base

Aug 7th, 2011
833
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Ruby 40.56 KB | None | 0 0
  1. #==============================================================================
  2. #    Item Instances Base
  3. #    Version: 1.0
  4. #    Author: modern algebra (rmrk.net)
  5. #    Date: August 7, 2011
  6. #++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
  7. #  Description:
  8. #
  9. #    This is a scripting tool that changes the way items are handled in the
  10. #   game to allow for item instances. This means that items specially marked
  11. #   will be uniquely saved every time you collect them.
  12. #
  13. #    This script was designed since scripts which require items to be saved as
  14. #   instances, even if they were conceptually simple (like durability), were
  15. #   impractical to make since they required a heavy overhaul of the entire item
  16. #   system. Other scripts that have tried tend to be very bulky and usually
  17. #   incompatible with every other item-based script out there. This script was
  18. #   therefore designed to (a) change the way marked items were saved so as to
  19. #   be more dynamic and saved as instances; (b) be compatible or easily made
  20. #   compatible with most other scripts that deal with items; and (c) be easy
  21. #   to create addons which make use of the framework to create functional
  22. #   changes to items, weapons, and armors.
  23. #
  24. #    This script makes little functional difference aside from changing how
  25. #   marked items are stacked in the menu and allows you to change the specific
  26. #   stats of items if you add them through the Change Item/Weapon/Armor event
  27. #   commands by using a comment. However, it provides a necessary structure for
  28. #   other scripts, such as a weapon durability or charges script, where the
  29. #   stats necessarily must vary between items of the same type.
  30. #
  31. #    While I made this script to provide a base for a series of scripts I will
  32. #   make, any scripter is welcome to use this as a base for their own scripts.
  33. #++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
  34. #  Instructions:
  35. #
  36. #   This script must be placed ABOVE Main and BELOW every regular custom script
  37. #  that might deal with items, even if they do so only incidentally. However,
  38. #  any scripts that utilize this script as a base must be BELOW it (and still
  39. #  above Main).
  40. #
  41. #    To mark an item to be stored on an instance by instance basis, just write
  42. #   into its note box the following:
  43. #        \instance
  44. #
  45. #    This script will apply to any item, weapon or armor that has that marked.
  46. #   For those types of items, you can also directly change the stats of them if
  47. #   you add them through an event command. To do so, make a comment directly
  48. #   underneath the event command that adds a marked item, and put codes of the
  49. #   following format:
  50. #      \II[n].stat[value]
  51. #        n : the number of the item. Set it to 0 unless you are adding more
  52. #         than one item through the same event command. So, if you are adding
  53. #         3 of the same type of instance item, then you can use this to denote
  54. #         which you wish to change, with 0=> first one, 1=> second one, and so
  55. #         on. To avoid confusion, you should add them one at a time and just
  56. #         always use 0.
  57. #       stat : this is the stat you wish to vary. You can only vary a stat if
  58. #         it contains either a boolean value, a number, or a string. You must
  59. #         use the exact method. The list of stats you can modify are:
  60. #           ITEM - base_damage, variance, atk_f, spi_f, parameter_type,
  61. #             parameter_points, hp_recovery_rate, hp_recovery, scope, speed,
  62. #             occasion, mp_recovery_rate, mp_recovery, price, common_event_id,
  63. #             physical_attack, damage_to_mp, absorb_damage, ignore_defense
  64. #           WEAPON - atk, def, agi, spi, hit, price, two_handed, fast_attack,
  65. #             dual_attack, critical_bonus
  66. #           ARMOR - atk, def, spi, agi, eva, kind, price, prevent_critical,
  67. #             half_mp_cost, double_exp_gain, auto_hp_recover
  68. #        value : the value you want to change it to. It must be either an
  69. #          integer, a boolean value, or a string. You MUST put in the type
  70. #          of value the stat would expect. For properties, such as two_handed,
  71. #          a boolean (true/false) is expected.
  72. #
  73. #    You can also modify the maximum number you can have of instance items. The
  74. #   default value is at line 150 and is currently 999. If that is fine but you
  75. #   want to change it for only some instance items, like a special potion, you
  76. #   can use the following code in that item's notebox:
  77. #
  78. #     \INS_MAX[x]
  79. #         x : the maximum number of instances of that item that you want to
  80. #            be able to carry.
  81. #++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
  82. #  Guidelines:
  83. #
  84. #    I made this mostly for my own planned scripts. However, if you are a
  85. #   scripter and want to use this as a base for a new script, you should read
  86. #   the script carefully to develop a full understanding, but here are some
  87. #   basic guidelines:
  88. #
  89. #      To check if a particular item creates instances, you can use the code:
  90. #         item.instance_based?
  91. #
  92. #      If you are adding a notebox code, you can add the RegExp to the
  93. #     RPG::BaseItem::MA_INSTANCE_CHECKS constant and it will interpret any item
  94. #     with that code as instance based and treat it accordingly. Otherwise, you
  95. #     would need to manually alias the instance_based? method or else require
  96. #     the use of the generic \Instance code.
  97. #
  98. #      You can get the ID of the base item from an instance item by asking for
  99. #     the item_id attribute, while the id attribute will return the unique
  100. #     index of the instance item. If you ever need the id method to return the
  101. #     base's item ID instead of its unique ID, then you turn the get_item_id
  102. #     attribute to true and it will. This is useful especially for aliasing.
  103. #
  104. #      If you want instance items to be destroyed when they are lost (which you
  105. #     should do if the player will never have a chance to recover them), you
  106. #     can set $game_party.ii_destroy_lost_instances to true.
  107. #
  108. #      To create a new instance without going through the gain_item method, you
  109. #     use the code data.create_instance (base_item), where data is either
  110. #     $data_items, $data_weapons, or $data_armors and base_item is an
  111. #     RPG::Item/Weapon/Armor object. To destroy an instance, you use
  112. #     data.destroy_instance (index) where data is the same and index is the
  113. #     item's unique ID.
  114. #
  115. #      You can retrieve all the existing instance items with a base ID by the
  116. #     code: data.items_with_id (x) where x is the ID in question. For instance,
  117. #     if you want to get all instances of the long sword (ID 2), you'd ask for
  118. #     $data_weapons.items_with_id (2). Note that it will return ALL instance
  119. #     items with that ID and not only those held by the party. For instance, it
  120. #     will also give you them even if they are currently equipped.
  121. #
  122. #      $data_items, $data_weapons, & $data_armors are all still the arrays they
  123. #     used to be, only with the [] and []= methods altered for instance item
  124. #     support. As such, any array methods will work exactly as they used to -
  125. #     So if you do $data_items.each {} then you will cycle through only the
  126. #     base items and not the instance items.
  127. #
  128. #      The code $game_party.newest_instance_items will return an array of all
  129. #     the latest items the party has received through the gain_item command.
  130. #==============================================================================
  131.  
  132. $imported = {} unless $imported
  133. $imported["MAInstanceItemsBase"] = true
  134.  
  135. module RPG
  136. #==============================================================================
  137. # ** BaseItem
  138. #++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
  139. #  Summary of Changes:
  140. #    new method - instance_based?
  141. #==============================================================================
  142.  
  143. class BaseItem
  144.   #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  145.   # * Constants
  146.   #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  147.   #\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\
  148.   #  EDITABLE REGION
  149.   #||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
  150.   MA_INS_ITEM_MAX = 999 # Maximum of any instance items to be carried.
  151.   #||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
  152.   #  END EDITABLE REGION
  153.   #//////////////////////////////////////////////////////////////////////////
  154.   MA_INSTANCE_CHECKS = [/\\(INSTANCE|INS_MAX)/i] # An array of REGEXP codes. If any are
  155.   # included in a notebox of an item, it will recognized as an instance item.
  156.   #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  157.   # * Public Instance Variables
  158.   #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  159.   attr_writer :ii_item_max # Maximum number of instances to be held in inventory
  160.   alias item_id id         # Alias for the ID reader attribute
  161.   #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  162.   # * Check if this item is instance based
  163.   #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  164.   def instance_based?
  165.     if !@ins_base
  166.       @ins_base = false
  167.       MA_INSTANCE_CHECKS.each { |check|
  168.         if self.note[check] != nil
  169.           @ins_base = true
  170.           break
  171.         end
  172.       }
  173.     end
  174.     return @ins_base
  175.   end
  176.   #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  177.   # * Instance Max
  178.   #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  179.   def ii_item_max
  180.     if !@ii_item_max
  181.       @ii_item_max = self.note[/\\INS_MAX\[(\d+)\]/i].nil? ? MA_INS_ITEM_MAX : $1.to_i
  182.     end
  183.     return @ii_item_max
  184.   end
  185.   #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  186.   # * Superclass Variables
  187.   #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  188.   def self.ii_accessor_attributes
  189.     nil_ary = self.instance_methods.select { |method| !method.include? ("=") && self.instance_methods.include? ("#{method}=") }
  190.     set_ary = ["scope", "occasion"] & nil_ary
  191.     set_ary << "note" if $imported["AddEquipmentOptions"]
  192.     # KGC Equipment Options Compatibility
  193.     return nil_ary - set_ary, set_ary
  194.   end
  195. end
  196.  
  197. #==============================================================================
  198. # ** RPG::Class
  199. #++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
  200. #  Summary of Changes:
  201. #    aliased methods - weapon_set; armor_set
  202. #==============================================================================
  203.  
  204. class Class
  205.   unless self.method_defined? (:ma_ii_wpnset_4fr1)
  206.     alias ma_ii_wpnset_4fr1 weapon_set
  207.     alias mga_ins_armst_6un8 armor_set
  208.   end
  209.   #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  210.   # * Weapon Set
  211.   #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  212.   def weapon_set (*args, &block)
  213.     actual_result = ma_ii_wpnset_4fr1 (*args, &block) # Run Original Method
  214.     result = actual_result.dup
  215.     actual_result.each { |weapon_id|
  216.       result.push *(($data_weapons.items_with_id (weapon_id)).collect { |wpn| wpn.id } )
  217.     }
  218.     return result
  219.   end
  220.   #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  221.   # * Armor Set
  222.   #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  223.   def armor_set (*args, &block)
  224.     actual_result = mga_ins_armst_6un8 (*args, &block) # Run Original Method
  225.     result = actual_result.dup
  226.     actual_result.each { |armor_id|
  227.       result.push *(($data_armors.items_with_id (armor_id)).collect { |amr| amr.id } )
  228.     }
  229.     return result
  230.   end
  231. end
  232.  
  233. end
  234.  
  235. #==============================================================================
  236. # *** II_BaseItem
  237. #++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
  238. #  This module contains the basic setup methods for instance items, to be mixed
  239. #==============================================================================
  240.  
  241. module II_BaseItem
  242.   #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  243.   # * Constants
  244.   #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  245.   #   A string for replacing attribute methods such that they will return the
  246.   # corresponding attribute from the base item unless it has been changed for
  247.   # the new item. wxyz will be replaced with the name of the method. This
  248.   # code will be evaled in each of the Game_Item/Weapon/Armor classes for
  249.   # every attribute reader method of its superclass. I do it this way so that
  250.   # changes to the items in the database will be reflected unless they are
  251.   # specifically adjusted.
  252.   MAII_ACCESSOR_CODE = <<_END_
  253.   alias maii_alias_wxyz_2ki3 wxyz unless self.method_defined? (:maii_alias_wxyz_2ki3)
  254.   def wxyz (*args, &block)
  255.     # If redefined in II_BaseItem, return that
  256.     return super (*args, &block) if II_BaseItem.method_defined? (:wxyz) && !(super (*args, &block)).nil?
  257.     result = maii_alias_wxyz_2ki3 (*args, &block)
  258.     # If the basic code for this does not return nil, return that
  259.     return result unless result.nil?
  260.     # Return this method from the base item as it is unaltered.
  261.     return base_item.wxyz (*args, &block)
  262.   end
  263. _END_
  264.   #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  265.   # * Public Instance Variables
  266.   #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  267.   attr_reader   :item_id
  268.   #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  269.   # * Object Initialization
  270.   #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  271.   def initialize (index, item)
  272.     setup (item)
  273.     self.id = index
  274.   end
  275.   #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  276.   # * Setup
  277.   #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  278.   def setup (item)
  279.     @item_id = item.id
  280.     @type_id = item.is_a? (RPG::Item) ? 0 : item.is_a? (RPG::Weapon) ? 1 : 2
  281.     nil_ary, set_ary = item.class.ii_accessor_attributes
  282.     nil_ary.each { |name| self.send ("#{name}=", nil) }
  283.     set_ary.each { |name| self.send ("#{name}=", item.send (name)) }
  284.   end
  285.   #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  286.   # * Get ID
  287.   #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  288.   def id
  289.     return $game_system.get_item_id ? self.item_id : super
  290.   end
  291.   #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  292.   # * Base Item
  293.   #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  294.   def base_item
  295.     # If the base item exists, return it; otherwise return self
  296.     return $game_system.instance_items[@type_id][@item_id].nil? ? self : $game_system.instance_items[@type_id][@item_id]
  297.   end
  298. end
  299.  
  300. #==============================================================================
  301. # ** Game_Item
  302. #++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
  303. #  This class holds in-game data for an item instance
  304. #==============================================================================
  305.  
  306. class Game_Item < RPG::Item
  307.   # Include BaseItem
  308.   include II_BaseItem
  309.   # Define all attributes to return base item stats unless it's been altered.
  310.   RPG::Item.ii_accessor_attributes[0].each { |method|
  311.     next if II_BaseItem.method_defined? (method.to_sym)
  312.     eval ( MAII_ACCESSOR_CODE.gsub (/wxyz/) { method.to_s } )
  313.   }
  314. end
  315.  
  316. #==============================================================================
  317. # ** Game_Weapon
  318. #++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
  319. #  This class holds in-game data for a weapon
  320. #==============================================================================
  321.  
  322. class Game_Weapon < RPG::Weapon
  323.   # Include BaseItem
  324.   include II_BaseItem
  325.   # Define all attributes to return base item stats unless it's been altered.
  326.   RPG::Weapon.ii_accessor_attributes[0].each { |method|
  327.     next if II_BaseItem.method_defined? (method.to_sym)
  328.     eval ( MAII_ACCESSOR_CODE.gsub (/wxyz/) { method } )
  329.   }
  330. end
  331.  
  332. #==============================================================================
  333. # ** Game_Armor
  334. #++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
  335. #  This class holds in-game data for an armor
  336. #==============================================================================
  337.  
  338. class Game_Armor < RPG::Armor
  339.   # Include BaseItem
  340.   include II_BaseItem
  341.   # Define all attributes to return base item stats unless it's been altered.
  342.   RPG::Armor.ii_accessor_attributes[0].each { |method|
  343.     next if II_BaseItem.method_defined? (method.to_sym)
  344.     eval ( MAII_ACCESSOR_CODE.gsub (/wxyz/) { method.to_s } )
  345.   }
  346. end
  347.  
  348. #==============================================================================
  349. # ** Game_InstanceItems
  350. #++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
  351. #  This class replaces $data_items, $data_weapons, and $data_armors so as to
  352. # provide support for instance items.
  353. #==============================================================================
  354.  
  355. class Game_InstanceItems < Array
  356.   #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  357.   # * Object Initialization
  358.   #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  359.   def initialize (type_id)
  360.     @items = {}
  361.     @free_indices = []
  362.     @last_index = 1000
  363.     @type_id = type_id
  364.     @type = case @type_id
  365.     when 0 then Game_Item
  366.     when 1 then Game_Weapon
  367.     when 2 then Game_Armor
  368.     end
  369.   end
  370.   #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  371.   # * Reset Base Data
  372.   #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  373.   def reset_base_data (data_array)
  374.     self.clear
  375.     for item in data_array do self << item end
  376.   end
  377.   #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  378.   # * Create Instance
  379.   #    base_item : the item to make, either RPG::@type or the ID of it
  380.   #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  381.   def create_instance (base_item)
  382.     base_item = self[base_item] if base_item.is_a? (Integer)
  383.     return base_item if base_item.is_a? (@type) || !base_item.instance_based?
  384.     # Get next free index
  385.     if @free_indices.empty?
  386.       indx = @last_index
  387.       @last_index += 1
  388.     else
  389.       indx = @free_indices.shift
  390.     end
  391.     @items[indx] = @type.new (indx, base_item)
  392.     return @items[indx]
  393.   end
  394.   #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  395.   # * Destroy Instance
  396.   #    index : the index of the item in the hash
  397.   #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  398.   def destroy_instance (index)
  399.     @free_indices.push (index)
  400.     @items.delete (index)
  401.   end
  402.   #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  403.   # * Retrieve Value from key
  404.   #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  405.   def [] (key)
  406.     return key < 1000 ? super (key) : @items[key]
  407.   end
  408.   #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  409.   # * Set Value to Key
  410.   #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  411.   def []=(key, value)
  412.     key < 1000 ? super (key, value) : @items[key] = value
  413.   end
  414.   #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  415.   # * Items with ID
  416.   #    This will return an array of all items with the specified ID
  417.   #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  418.   def items_with_id (item_id)
  419.     return @items.values.select { |instance| instance.item_id == item_id }
  420.   end
  421. end
  422.  
  423. #==============================================================================
  424. # ** Game System
  425. #++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
  426. #  Summary of Changes:
  427. #    new attributes - instance_items; get_item_id
  428. #    aliased method - initialize
  429. #==============================================================================
  430.  
  431. class Game_System
  432.   #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  433.   # * Public Instance Variables
  434.   #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  435.   attr_reader   :instance_items   # The array holding all instances of items
  436.   attr_accessor :get_item_id      # A boolean for whether id returns base id
  437.   #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  438.   # * Object Initialization
  439.   #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  440.   alias ma_init_instnc_items_9jc3 initialize
  441.   def initialize (*args)
  442.     @get_item_id = false
  443.     ma_init_instnc_items_9jc3 (*args) # Run Original Method
  444.     # Create Weapons and Armors objects
  445.     @instance_items = [Game_InstanceItems.new (0), Game_InstanceItems.new (1),
  446.       Game_InstanceItems.new (2)]
  447.   end
  448. end
  449.  
  450. #==============================================================================
  451. # ** Game_Actor
  452. #++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
  453. #  Summary of Changes:
  454. #    aliased method - setup, equippable?
  455. #==============================================================================
  456.  
  457. class Game_Actor
  458.   #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  459.   # * Setup
  460.   #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  461.   alias maga_setup_instnc_itms_8kj2 setup
  462.   def setup (*args)
  463.     # If re-initializing, delete the equipped items
  464.     if @weapon_id != nil
  465.       equips.each { |equip|
  466.         next if equip.nil?
  467.         case equip
  468.         when Game_Weapon then $data_weapons.destroy_instance (equip.id)
  469.         when Game_Armor then $data_armors.destroy_instance (equip.id)
  470.         end
  471.       }
  472.     end
  473.     # Run Original Method
  474.     maga_setup_instnc_itms_8kj2 (*args)
  475.     # Create instances of preset equipment
  476.     @weapon_id = $data_weapons.create_instance (@weapon_id).id unless @weapon_id == 0
  477.     if two_swords_style
  478.       @armor1_id = $data_weapons.create_instance (@armor1_id).id unless @armor1_id == 0
  479.     else
  480.       @armor1_id = $data_armors.create_instance (@armor1_id).id unless @armor1_id == 0
  481.     end
  482.     @armor2_id = $data_armors.create_instance (@armor2_id).id unless @armor2_id == 0
  483.     @armor3_id = $data_armors.create_instance (@armor3_id).id unless @armor3_id == 0
  484.     @armor4_id = $data_armors.create_instance (@armor4_id).id unless @armor4_id == 0
  485.   end
  486. end
  487.  
  488. #==============================================================================
  489. # ** Game_Party
  490. #++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
  491. #  Summary of Changes:
  492. #    aliased methods - items; item_number; gain_item; consume_item
  493. #    new method - newest_instance_items; gain_instance_item; lose_instance_item
  494. #==============================================================================
  495.  
  496. class Game_Party
  497.   #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  498.   # * Public Instance Variables
  499.   #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  500.   attr_accessor :ii_destroy_lost_instances
  501.   #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  502.   # * Items
  503.   #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  504.   alias mlg_insite_items_5tg8 items
  505.   def items (*args, &block)
  506.     result = mlg_insite_items_5tg8 (*args, &block) # Run Original Method
  507.     #  Sort Items by Item ID, so that like items are together. The other array
  508.     # is in case another script has made a new item object
  509.     sitems, sweapons, sarmors, other = [], [], [], []
  510.     while !result.empty?
  511.       itm = result.shift
  512.       next if itm.instance_based? && !itm.is_a? (II_BaseItem) # Don't add Base
  513.       case itm
  514.       when RPG::Item then sitems << itm
  515.       when RPG::Weapon then sweapons << itm
  516.       when RPG::Armor then sarmors << itm
  517.       else # Category in case any other script makes a strange new item type
  518.         other << itm
  519.       end
  520.     end
  521.     sitems.sort! { |a, b| a.item_id <=> b.item_id }
  522.     sweapons.sort! { |a, b| a.item_id <=> b.item_id }
  523.     sarmors.sort! { |a, b| a.item_id <=> b.item_id }
  524.     return sitems + sweapons + sarmors + other
  525.   end
  526.   #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  527.   # * Consume Item
  528.   #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  529.   alias malii_consumeitem_6tg9 consume_item
  530.   def consume_item(*args, &block)
  531.     $game_party.ii_destroy_lost_instances = true
  532.     malii_consumeitem_6tg9 (*args, &block) # Run Original Method
  533.     $game_party.ii_destroy_lost_instances = false
  534.   end
  535.   #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  536.   # * Gain Items (or lose)
  537.   #     item          : Item
  538.   #     n             : Number
  539.   #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  540.   alias ma_insims_gnim_7yt1 gain_item
  541.   def gain_item (item, n = 1, include_equip = false, *args)
  542.     return if item == nil || n == 0
  543.     @newest_items = []
  544.     type = item.is_a? (RPG::Item) ? 0 : item.is_a? (RPG::Weapon) ? 1 : 2
  545.     # Compatibility with Item Catalogue
  546.     if Game_Party.method_defined? (:item_encounter_array)
  547.       array = item_encounter_array (item)
  548.       array << item.item_id unless array.include? (item.item_id)
  549.     end
  550.     if item.is_a? (II_BaseItem) # n can only be -1 or 1.
  551.       num = item_number (item.base_item)
  552.       return if num >= item.ii_item_max
  553.       data_type = $game_system.instance_items[type]
  554.       if n < 0 # n would have been returned if 0, so can only be < 0 or > 0
  555.         if item_number (item) != 0
  556.           data_type.destroy_instance (item.id) if @ii_destroy_lost_instances
  557.         elsif include_equip
  558.           for actor in members
  559.             if actor.equips.include? (data_type[item.id])
  560.               actor.discard_equip(item)
  561.               data_type.destroy_instance (item.id) if @ii_destroy_lost_instances
  562.               break
  563.             end
  564.           end
  565.         end
  566.       end
  567.       ma_insims_gnim_7yt1 (item, n, false, *args) # Update Hash for item
  568.       # Update Hash for the base item
  569.       [@items, @weapons, @armors][type][item.item_id] = [[num + n, 0].max, item.ii_item_max].min
  570.     elsif item.instance_based? # If gaining new instance items
  571.       num = item_number (item)
  572.       n = [n, item.ii_item_max - num].min if n > 0
  573.       gain_instance_item (item, n, include_equip) # Create new instances
  574.       # Update Hash for the new items
  575.       @newest_items.each { |ins| ma_insims_gnim_7yt1 (ins, (n <=> 0), false, *args) }
  576.       # Update Hash for the base item
  577.       [@items, @weapons, @armors][type][item.id] = [num + n, 0].max
  578.     else
  579.       ma_insims_gnim_7yt1 (item, n, include_equip, *args) # Run Original Method
  580.     end
  581.   end
  582.   #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  583.   # * Gain Instance
  584.   #    item - a RPG::Item/Weapon/Armor object to create new Game_object of
  585.   #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  586.   def gain_instance_item (item, n = 1, include_equip = false)
  587.     if item.is_a? (II_BaseItem) # If already an instance item, send back
  588.       gain_item (item, n, include_equip)
  589.       return
  590.     end
  591.     case item
  592.     when RPG::Item then data_type, type_id = $data_items, 0
  593.     when RPG::Weapon then data_type, type_id = $data_weapons, 1
  594.     when RPG::Armor then data_type, type_id = $data_armors, 2
  595.     end
  596.     if n > 0
  597.       n.times { |i|
  598.         new_item = data_type.create_instance (item)
  599.         @newest_items.push ( new_item )
  600.       }
  601.     else
  602.       instances = data_type.items_with_id (item.id)
  603.       instances.each { |item2|
  604.         break if n == 0 || item_number (item) == 0
  605.         next if item_number (item2) == 0
  606.         @newest_items.push (item2)
  607.         data_type.destroy_instance (item2.id) if @ii_destroy_lost_instances
  608.         n += 1
  609.       }
  610.       if n < 0 && include_equip
  611.         for actor in members
  612.           equipped_instances = instances & actor.equips
  613.           while n < 0 && !equipped_instances.empty?
  614.             item2 = equipped_instances.shift
  615.             @newest_items.push (item2)
  616.             actor.discard_equip(item2)
  617.             data_type.destroy_instance (item2.id) if @ii_destroy_lost_instances
  618.             n += 1
  619.           end
  620.         end
  621.       end
  622.     end
  623.   end
  624.   #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  625.   # * Lose Instance Item
  626.   #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  627.   def lose_instance_item (item, n = 1, include_equip = false)
  628.     gain_instance_item (item, n*-1, include_equip)
  629.   end
  630.   #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  631.   # * Newest Instance Items
  632.   #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  633.   def newest_instance_items
  634.     return @newest_items.nil? ? [] : @newest_items
  635.   end
  636.   # YEM Equipment Overhaul Compatibility Patch
  637.   if $imported["EquipmentOverhaul"]
  638.   #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  639.   # * Items Only / Equip Weapons / Equip Armours
  640.   #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  641.   [:items_only, :equip_weapons, :equip_armours].each { |method_name|
  642.     alias_method ("mayfly_iiyemeqp_#{method_name}_8uj1".to_sym, method_name)
  643.     define_method (method_name) do |*args|
  644.       result = self.send ("mayfly_iiyemeqp_#{method_name}_8uj1", *args)
  645.       result.select! { |item| item.instance_based? && !item.is_a? (II_BaseItem) }
  646.       return result.sort { |a, b| a.item_id <=> b.item_id }
  647.     end
  648.   }
  649.   end
  650. end
  651.  
  652. #==============================================================================
  653. # ** Game_Interpreter
  654. #++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
  655. #  Summary of Changes:
  656. #    aliased methods - command_126, command_127, command_128
  657. #    new method - read_items_comment
  658. #==============================================================================
  659.  
  660. class Game_Interpreter
  661.   #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  662.   # * Read Item Comment
  663.   #    item : the item to modify
  664.   #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  665.   def ii_read_items_comment
  666.     return if $game_party.newest_instance_items.empty?
  667.     i = @index + 1
  668.     comment = ""
  669.     # Retrieve entire comment
  670.     while i < @list.size && [108, 408].include? (@list[i].code)
  671.       comment += @list[i].parameters[0]
  672.       i += 1
  673.     end
  674.     while comment.slice! (/\\II\[(\d+)\]\.(.+?)\[(.+?)\]/im) != nil
  675.       key, method, value = $1.to_i, $2.to_s, $3.to_s
  676.       value.gsub (/\r\n/) { " " }
  677.       if value[/[^0-9\.]/] == nil # Integer
  678.         value = value.to_i
  679.       elsif value[/\ATRUE\Z/i] != nil # True
  680.         value = true
  681.       elsif value[/\AFALSE\Z/i] != nil # False
  682.         value = false
  683.       end
  684.       begin
  685.         $game_party.newest_instance_items[key].send ("#{method}=", value)
  686.       rescue
  687.       end
  688.     end
  689.   end
  690.   #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  691.   # * Gain Item/Weapon/Armor
  692.   #    Thank Zeriab for this little trick
  693.   #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  694.   # Go through each gain method and read the following comment
  695.   [126, 127, 128].each { |method|
  696.     alias_method ("ma_gain_command_#{method}".to_sym, "command_#{method}".to_sym)
  697.     define_method ("command_#{method}".to_sym) { |*args|
  698.       $game_party.ii_destroy_lost_instances = true
  699.       result = self.send ("ma_gain_command_#{method}".to_sym, *args)
  700.       $game_party.ii_destroy_lost_instances = false
  701.       ii_read_items_comment
  702.       return result
  703.     }
  704.   }
  705. end
  706.  
  707. #==============================================================================
  708. # ** Window_Item
  709. #++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
  710. #  Summary of Changes:
  711. #    aliased method - draw_item
  712. #    new method - clear_item_right; draw_item_right
  713. #==============================================================================
  714.  
  715. class Window_Item
  716.   #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  717.   # * Clear Item Right
  718.   #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  719.   def clear_item_right (index)
  720.     rect = index.is_a? (Rect) ? index : item_rect (index)
  721.     erase_text = sprintf(":%2d", $game_party.item_number(@data[index]))
  722.     tw = self.contents.text_size ( erase_text).width
  723.     self.contents.clear_rect (rect.x + rect.width - 4 - tw, rect.y, tw + 4, rect.height)
  724.   end
  725.   #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  726.   # * Draw Item Right
  727.   #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  728.   def draw_item_right (index)
  729.     # To be overwritten by subscripts
  730.   end
  731.   #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  732.   # * Draw Item
  733.   #     index : item number
  734.   #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  735.   alias mlgb_iidrawitm_removenum_5tg1 draw_item
  736.   def draw_item(index, *args, &block)
  737.     mlgb_iidrawitm_removenum_5tg1 (index, *args, &block) # Run Original Method
  738.     if @data[index].is_a? (RPG::BaseItem) && @data[index].instance_based?
  739.       clear_item_right (index)
  740.       draw_item_right (index)
  741.     end
  742.   end
  743. end
  744.  
  745. #==============================================================================
  746. # ** Scene_Title
  747. #++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
  748. #  Summary of Changes:
  749. #    aliased methods - create_game_objects
  750. #==============================================================================
  751.  
  752. class Scene_Title
  753.   #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  754.   # * Create Game Objects
  755.   #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  756.   alias mala_crtgm_obj_institm_6hf2 create_game_objects
  757.   def create_game_objects (*args)
  758.     # Run Original Method
  759.     mala_crtgm_obj_institm_6hf2 (*args)
  760.     # Preserve Basic Arrays
  761.     $game_system.instance_items[0].reset_base_data ($data_items.dup)
  762.     $game_system.instance_items[1].reset_base_data ($data_weapons.dup)
  763.     $game_system.instance_items[2].reset_base_data ($data_armors.dup)
  764.     # Tie $data_items, $data_weapons, and $data_armors to Game_InstanceItems
  765.     $data_items, $data_weapons, $data_armors = *$game_system.instance_items
  766.   end
  767. end
  768.  
  769. #==============================================================================
  770. # ** Scene_File
  771. #++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
  772. #  Summary of Changes:
  773. #    aliased method - read_save_data
  774. #==============================================================================
  775.  
  776. class Scene_File
  777.   #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  778.   # * Write Save Data
  779.   #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  780.   alias mdrna_ii_wrtsvda_5tp2 write_save_data
  781.   def write_save_data (*args)
  782.     databases = $game_system.instance_items.dup
  783.     # Purge Basic Data arrays so as not to save basic data
  784.     for i in 0...3 do $game_system.instance_items[i].reset_base_data ([]) end
  785.     mdrna_ii_wrtsvda_5tp2 (*args)
  786.     # Recover Data Arrays
  787.     for i in 0...3 do $game_system.instance_items[i].reset_base_data (databases[i]) end
  788.   end
  789.   #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  790.   # * Read Save Data
  791.   #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  792.   alias malbra_insitms_rdsave_6th2 read_save_data
  793.   def read_save_data (*args)
  794.     # Run Original Method
  795.     malbra_insitms_rdsave_6th2 (*args)
  796.     if !$game_system.instance_items
  797.       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."
  798.     end
  799.     # Preserve Basic Arrays
  800.     $game_system.instance_items[0].reset_base_data ($data_items.dup)
  801.     $game_system.instance_items[1].reset_base_data ($data_weapons.dup)
  802.     $game_system.instance_items[2].reset_base_data ($data_armors.dup)
  803.     # Tie $data_items, $data_weapons, and $data_armors to instance items
  804.     $data_items, $data_weapons, $data_armors = *$game_system.instance_items
  805.   end
  806. end
  807.  
  808. #==============================================================================
  809. # ** Scene Shop
  810. #++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
  811. #  Summary of Changes:
  812. #    aliased method - decide_number_input
  813. #==============================================================================
  814.  
  815. class Scene_Shop
  816.   #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  817.   # * Confirm Number Input
  818.   #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  819.   alias mlg_ii_decidnuminput_4yg7 decide_number_input
  820.   def decide_number_input (*args, &block)
  821.     $game_party.ii_destroy_lost_instances = true # Destroy any instance lost
  822.     mlg_ii_decidnuminput_4yg7 (*args, &block) # Run Original Method
  823.     $game_party.ii_destroy_lost_instances = false
  824.   end
  825. end
  826.  
  827. # Grid Inventory Compatibility
  828. if Object.constants.include? ("Game_InventoryGrid")
  829. #==============================================================================
  830. # ** Game_InventoryGrid
  831. #++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
  832. #  Summary of Changes:
  833. #    aliased method - item_search
  834. #==============================================================================
  835.  
  836. class Game_InventoryGrid
  837.   #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  838.   # * Item Search
  839.   #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  840.   alias mala_iigrid_itmsrch_6dc4 item_search
  841.   def item_search (*args, &block)
  842.     $game_system.get_item_id = true
  843.     result = mala_iigrid_itmsrch_6dc4 (*args, &block)
  844.     $game_system.get_item_id = false
  845.     return result
  846.   end
  847. end
  848.  
  849. #==============================================================================
  850. # ** Item_Placement (Grid Inventory)
  851. #++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
  852. #  Summary of Changes:
  853. #    aliased method - item_id
  854. #==============================================================================
  855.  
  856. class Item_Placement
  857.   #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  858.   # * Item ID
  859.   #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  860.   alias mlba_giinsba_itmid_6yh1 item_id
  861.   def item_id (*args, &block)
  862.     return item.item_id if !item.nil? && $game_system.get_item_id
  863.     return mlba_giinsba_itmid_6yh1 (*args, &block) # Run Original Method
  864.   end
  865. end
  866.  
  867. end
  868.  
  869. # Limited Inventory Compatibility
  870. if Object.constants.include? ("Game_LimitedInventory")
  871. #==============================================================================
  872. # ** Game_LimitedInventory
  873. #++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
  874. #  Summary of Changes:
  875. #    aliased methods - add_item; remove_item
  876. #==============================================================================
  877.  
  878. class Game_LimitedInventory
  879.   #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  880.   # * Add/Remove Item
  881.   #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  882.   [:add_item, :remove_item].each { |method_name|
  883.     alias_method ("ma_liminvinitm_#{method_name}_6yu8".to_sym, method_name)
  884.     define_method (method_name) do |type, id, *args|
  885.       $game_system.get_item_id = (id < 1000)
  886.       # Run Original Method
  887.       result = self.send ("ma_liminvinitm_#{method_name}_6yu8", type, id, *args)
  888.       $game_system.get_item_id = false
  889.       return result
  890.     end
  891.   }
  892. end
  893.  
  894. #==============================================================================
  895. # ** Game_LimInvSlot
  896. #++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
  897. #  Summary of Changes:
  898. #    aliased method - item_id
  899. #==============================================================================
  900.  
  901. class Game_LimInvSlot
  902.   #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  903.   # * Item ID
  904.   #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  905.   alias mga_insliminv_itmid_9jb2 item_id
  906.   def item_id (*args, &block)
  907.     return item.item_id if !item.nil? && $game_system.get_item_id
  908.     return mga_insliminv_itmid_9jb2 (*args, &block) # Run Original Method
  909.   end
  910. end
  911.  
  912. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement