Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~
- # Custom DM add-on
- # Author: Eshra
- # First Version: 30 Oct. 2012
- # Compatibility: RPG Maker VX Ace
- # Dependencies:
- # 1. Tsuki_CustomDataManager
- #-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~
- #
- #------------------------------------------------------------------------------
- # * How to Use
- #------------------------------------------------------------------------------
- # This script is for use with the custom database/manager, it provides a notetag
- # to label a specific item in the database as unique
- #
- # <Unique>
- #
- # Once in the party's inventory, the unique item exists as a separate entity in
- # the database, when it is removed from the party's inventory it is removed from
- # the database. If properties of the unique item are changed, it will have no
- # effect on new instances of that type of item.
- #- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
- #
- # Original Release Date: Unreleased
- #
- # Update Log:
- # 19 Jan. 2013 - Added original_item_era?. Should help to fix several
- # compatibility issues.
- # 13 Dec. 2012 - Added calls to CleanCDB instead of removing custom items from
- # the database incorrectly as I was before.
- # 3 Nov. 2012 - Fixed problem occuring when adding more than one unique item to
- # the party's inventory.
- # 30 Oct. 2012 - First version completed
- #
- #-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~
- $imported ||= {}
- raise "Tsuki_CustomDataManager is required for the DM add-on" if !$imported["Tsuki_CustomDataManager"]
- $imported["Ra Custom DM add-on"] = 0.3
- module Era
- CleanCDB_Amt = 400 # number of unique items needed to be gained before cleaning
- end
- #==============================================================================
- # ** Unique RPG BaseItem
- #==============================================================================
- module UniqueRPGBI
- RE = /<Unique>/i
- end # UniqueRPGBI
- #==============================================================================
- # ** RPG::BaseItem
- #==============================================================================
- class RPG::BaseItem
- attr_accessor :is_unique_rpgbi
- attr_accessor :id
- #----------------------------------------------------------------------------
- # * Is a Potential Unique Item? - Check if this obj. can show up in the
- # party's inventory.
- #----------------------------------------------------------------------------
- def valid_uniq_party_item?
- self.is_a?(RPG::Item) || self.is_a?(RPG::Armor) || self.is_a?(RPG::Weapon)
- end # valid_uniq_party_item?
- end # RPG::BaseItem
- #==============================================================================
- # ** RPG::Item
- #==============================================================================
- class RPG::Item < RPG::UsableItem
- #----------------------------------------------------------------------------
- # * Add to Custom Database
- #----------------------------------------------------------------------------
- def add_to_dbases
- return if @is_upg_dupe # for compatibility with upg equips script
- self.id = $data_items.length
- $custom_items.push(self)
- $data_items.push(self)
- end
- #----------------------------------------------------------------------------
- # * Remove From Custom Database
- #----------------------------------------------------------------------------
- def sub_fr_dbase
- return if @is_upg_dupe
- # $custom_items.delete(self)
- end # sub_fr_dbase
- end # RPG::Item
- #==============================================================================
- # ** RPG::Armor
- #==============================================================================
- class RPG::Armor < RPG::EquipItem
- #----------------------------------------------------------------------------
- # * Add to Custom Database
- #----------------------------------------------------------------------------
- def add_to_dbases
- return if @is_upg_dupe # for compatibility with upg equips script
- self.id = $data_armors.length
- $custom_armors.push(self)
- $data_armors.push(self)
- end
- #----------------------------------------------------------------------------
- # * Remove From Custom Database
- #----------------------------------------------------------------------------
- def sub_fr_dbase
- return if @is_upg_dupe
- end # sub_fr_dbase
- end # RPG::Armor
- #==============================================================================
- # ** RPG::Weapon
- #==============================================================================
- class RPG::Weapon < RPG::EquipItem
- #----------------------------------------------------------------------------
- # * Add to Custom Database
- #----------------------------------------------------------------------------
- def add_to_dbases
- return if @is_upg_dupe # for compatibility with upg equips script
- self.id = $data_weapons.length
- $custom_weapons.push(self)
- $data_weapons.push(self)
- end
- #----------------------------------------------------------------------------
- # * Remove From Custom Database
- #----------------------------------------------------------------------------
- def sub_fr_dbase
- return if @is_upg_dupe
- end # sub_fr_dbase
- end # RPG::Weapon
- #==============================================================================
- # ** DataManager
- #==============================================================================
- module DataManager
- class << self
- alias ldb_ntags_unique_rpgbi_voldb load_database
- end
- #----------------------------------------------------------------------------
- # * Load Database
- #----------------------------------------------------------------------------
- def self.load_database
- ldb_ntags_unique_rpgbi_voldb
- ld_vol_db_ntags_uniquerpgi
- end
- #----------------------------------------------------------------------------
- # * Load Tags
- #----------------------------------------------------------------------------
- def self.ld_vol_db_ntags_uniquerpgi
- iter = [$data_items, $data_weapons, $data_armors]
- iter.each{ |set|
- set.each do |item|
- next unless item
- item.note.split(/[\r\n]+/).each{ |line|
- case line
- when UniqueRPGBI::RE
- item.is_unique_rpgbi = true
- end
- }
- end
- }
- end # ld_vol_db_ntags_uniquerpgi
- end # DataManager
- #==============================================================================
- # * Game_Party
- #==============================================================================
- class Game_Party < Game_Unit
- # Modify gain_item, remove the item from the volatile DB when the party
- # no longer has any of them.
- # Make a new entry in the db when the party gains a unique item and modify the
- # id of that item such that it is the largest in the db
- #----------------------------------------------------------------------------
- # * Alias - gain_item
- #----------------------------------------------------------------------------
- alias gain_itm_unique_rpgbi_era gain_item
- def gain_item(item, amount, include_equip = false)
- if amount > 1
- amount.times{ gain_item(item, 1, include_equip) }
- return
- end
- item = try_to_eval_unique(item, amount)
- gain_itm_unique_rpgbi_era(item, amount, include_equip=false)
- # Clean up the databases if over 200 unique items have been gained
- @num_uniques ||= 0;
- @num_uniques += 1 if item && item.is_unique_rpgbi
- clean = Era::CleanCDB::Clean
- if $imported["Ra CleanCDB"] && clean && @num_uniques > Era::CleanCDB_Amt
- Era::CleanCDB.clean; @num_uniques = 0
- end
- end
- #----------------------------------------------------------------------------
- # * Each unique item gets a separate slot in the db
- #----------------------------------------------------------------------------
- def try_to_eval_unique(item, amount)
- return item if !eval_unq_ok?(item)
- item = Marshal.load(Marshal.dump(old_item = item))
- item.add_to_dbases if !delete_cust_item?(item, amount)
- item
- end
- #----------------------------------------------------------------------------
- # * Try to evaluate a unique item only if it is the original, i.e. wasn't
- # created during runtime. This should allow compatibility with scripts
- # that expect an item to always have the same id.
- #----------------------------------------------------------------------------
- def eval_unq_ok?(item)
- item && item.is_unique_rpgbi && original_item_era?(item)
- end
- #----------------------------------------------------------------------------
- # * Check to Remove Custom Item From Database
- #----------------------------------------------------------------------------
- def delete_cust_item?(item, amount)
- !item.nil? && item.valid_uniq_party_item? && -amount >= item_number(item) &&
- item.is_unique_rpgbi
- end # delete_custom?
- #----------------------------------------------------------------------------
- # * Is the item original?
- #----------------------------------------------------------------------------
- def original_item_era?(item)
- sz = 0
- if item.is_a?(RPG::Item); sz = Era.db_array_size(:data_items)
- elsif item.is_a?(RPG::Weapon); sz = Era.db_array_size(:data_weapons)
- elsif item.is_a?(RPG::Armor); sz = Era.db_array_size(:data_armors)
- end
- item.id < sz # when the id is > size of orig db array the item was added
- # during runtime.
- end
- end # Game_Party
- # End of File
Advertisement
Add Comment
Please, Sign In to add comment