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:
- # 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.1
- #==============================================================================
- # ** Unique RPG BaseItem
- #==============================================================================
- module UniqueRPGBI
- RE = /<Unique>/
- 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
- self.id = $data_items.length
- $custom_items.push(self)
- $data_items.push(self)
- end
- #----------------------------------------------------------------------------
- # * Remove From Custom Database
- #----------------------------------------------------------------------------
- def sub_fr_dbase
- $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
- self.id = $data_armors.length
- $custom_armors.push(self)
- $data_armors.push(self)
- end
- #----------------------------------------------------------------------------
- # * Remove From Custom Database
- #----------------------------------------------------------------------------
- def sub_fr_dbase
- $custom_armors.delete(self)
- end # sub_fr_dbase
- end # RPG::Armor
- #==============================================================================
- # ** RPG::Weapon
- #==============================================================================
- class RPG::Weapon < RPG::EquipItem
- #----------------------------------------------------------------------------
- # * Add to Custom Database
- #----------------------------------------------------------------------------
- def add_to_dbases
- self.id = $data_weapons.length
- $custom_weapons.push(self)
- $data_weapons.push(self)
- end
- #----------------------------------------------------------------------------
- # * Remove From Custom Database
- #----------------------------------------------------------------------------
- def sub_fr_dbase
- $custom_weapons.delete(self)
- 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{ |item|
- next unless item
- item.note.split(/[\r\n]+/).each{ |line|
- case line
- when UniqueRPGBI::RE
- item.is_unique_rpgbi = true
- 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)
- end
- #----------------------------------------------------------------------------
- # * Each unique item gets a separate slot in the db
- #----------------------------------------------------------------------------
- def try_to_eval_unique(item, amount)
- return item unless !item.nil? && item.is_unique_rpgbi
- item = Marshal.load(Marshal.dump(item))
- delete_cust_item?(item,amount) ? item.sub_fr_dbase : item.add_to_dbases
- 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?
- end # Game_Party
- # End of File
Advertisement
Add Comment
Please, Sign In to add comment