View difference between Paste ID: 72gaDXqh and 4r0KQPrL
SHOW: | | - or go back to the newest paste.
1
#-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~
2
# Custom DM add-on
3
# Author: Eshra
4
# First Version: 30 Oct. 2012 
5
# Compatibility: RPG Maker VX Ace
6
# Dependencies: 
7
#     1. Tsuki_CustomDataManager
8
#-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~
9
#
10
#------------------------------------------------------------------------------
11
# * How to Use
12
#------------------------------------------------------------------------------
13
# This script is for use with the custom database/manager, it provides a notetag
14
# to label a specific item in the database as unique
15
#
16
# <Unique>
17
# 
18
# Once in the party's inventory, the unique item exists as a separate entity in
19
# the database, when it is removed from the party's inventory it is removed from
20
# the database. If properties of the unique item are changed, it will have no
21
# effect on new instances of that type of item.
22
#- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 
23
#
24
# Original Release Date: Unreleased
25
#
26
# Update Log:
27
# 19 Jan. 2013 - Added original_item_era?. Should help to fix several 
28
#                compatibility issues.
29
# 13 Dec. 2012 - Added calls to CleanCDB instead of removing custom items from
30
#                the database incorrectly as I was before.
31
# 3 Nov. 2012 - Fixed problem occuring when adding more than one unique item to
32
#               the party's inventory.
33
# 30 Oct. 2012 - First version completed
34
#
35
#-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~
36
$imported ||= {}
37
raise "Tsuki_CustomDataManager is required for the DM add-on" if !$imported["Tsuki_CustomDataManager"]
38-
$imported["Ra Custom DM add-on"] = 0.2
38+
$imported["Ra Custom DM add-on"] = 0.3
39
40
module Era
41
  CleanCDB_Amt = 400 # number of unique items needed to be gained before cleaning
42
end
43
44
#==============================================================================
45
# ** Unique RPG BaseItem
46
#==============================================================================
47
module UniqueRPGBI
48
  RE = /<Unique>/i
49
end # UniqueRPGBI
50
#==============================================================================
51
# ** RPG::BaseItem
52
#==============================================================================
53
class RPG::BaseItem
54
  attr_accessor :is_unique_rpgbi
55
  attr_accessor :id
56
  #----------------------------------------------------------------------------
57
  # * Is a Potential Unique Item? - Check if this obj. can show up in the 
58
  #     party's inventory.
59
  #----------------------------------------------------------------------------
60
  def valid_uniq_party_item?
61
    self.is_a?(RPG::Item) || self.is_a?(RPG::Armor) || self.is_a?(RPG::Weapon)
62
  end # valid_uniq_party_item?
63
  
64
end # RPG::BaseItem
65
#==============================================================================
66
# ** RPG::Item
67
#==============================================================================
68
class RPG::Item < RPG::UsableItem
69
  #----------------------------------------------------------------------------
70
  # * Add to Custom Database
71
  #----------------------------------------------------------------------------
72
  def add_to_dbases
73
    return if @is_upg_dupe # for compatibility with upg equips script
74
    self.id = $data_items.length
75
    $custom_items.push(self)
76
    $data_items.push(self)
77
  end
78
  #----------------------------------------------------------------------------
79
  # * Remove From Custom Database
80
  #----------------------------------------------------------------------------
81
  def sub_fr_dbase
82
    return if @is_upg_dupe
83
    # $custom_items.delete(self)
84
  end # sub_fr_dbase
85
  
86
end # RPG::Item
87
#==============================================================================
88
# ** RPG::Armor
89
#==============================================================================
90
class RPG::Armor < RPG::EquipItem
91
  #----------------------------------------------------------------------------
92
  # * Add to Custom Database
93
  #----------------------------------------------------------------------------
94
  def add_to_dbases
95
    return if @is_upg_dupe # for compatibility with upg equips script
96
    self.id = $data_armors.length
97
    $custom_armors.push(self)
98
    $data_armors.push(self)
99
  end
100
  #----------------------------------------------------------------------------
101
  # * Remove From Custom Database
102
  #----------------------------------------------------------------------------
103
  def sub_fr_dbase
104
    return if @is_upg_dupe
105
  end # sub_fr_dbase
106
  
107
end # RPG::Armor
108
#==============================================================================
109
# ** RPG::Weapon
110
#==============================================================================
111
class RPG::Weapon < RPG::EquipItem
112
  
113
  #----------------------------------------------------------------------------
114
  # * Add to Custom Database
115
  #----------------------------------------------------------------------------
116
  def add_to_dbases
117
    return if @is_upg_dupe # for compatibility with upg equips script
118
    self.id = $data_weapons.length
119
    $custom_weapons.push(self)
120
    $data_weapons.push(self)
121
  end
122
  #----------------------------------------------------------------------------
123
  # * Remove From Custom Database
124
  #----------------------------------------------------------------------------
125
  def sub_fr_dbase
126
    return if @is_upg_dupe
127
  end # sub_fr_dbase
128
   
129
end # RPG::Weapon
130
131
#==============================================================================
132
# ** DataManager
133
#==============================================================================
134
module DataManager
135
  class << self
136
    alias ldb_ntags_unique_rpgbi_voldb load_database
137
  end
138
  #----------------------------------------------------------------------------
139
  # * Load Database
140
  #----------------------------------------------------------------------------
141
  def self.load_database
142
    ldb_ntags_unique_rpgbi_voldb
143
    ld_vol_db_ntags_uniquerpgi
144
  end
145
  #----------------------------------------------------------------------------
146
  # * Load Tags
147
  #----------------------------------------------------------------------------
148
  def self.ld_vol_db_ntags_uniquerpgi
149
    iter = [$data_items, $data_weapons, $data_armors]
150
    iter.each{ |set|
151
      set.each do |item|
152
        next unless item
153
        item.note.split(/[\r\n]+/).each{ |line|
154
          case line
155
          when UniqueRPGBI::RE
156
            item.is_unique_rpgbi = true
157
          end
158
        }
159
      end
160
    }
161
  end # ld_vol_db_ntags_uniquerpgi
162
163
end # DataManager
164
#==============================================================================
165
# * Game_Party
166
#==============================================================================
167
class Game_Party < Game_Unit
168
  
169
  # Modify gain_item, remove the item from the volatile DB when the party
170
  # no longer has any of them.
171
  
172
  # Make a new entry in the db when the party gains a unique item and modify the
173
  # id of that item such that it is the largest in the db
174
  
175
  #----------------------------------------------------------------------------
176
  # * Alias - gain_item
177
  #----------------------------------------------------------------------------
178
  alias gain_itm_unique_rpgbi_era gain_item
179
  def gain_item(item, amount, include_equip = false)
180
    
181
    
182
    if amount > 1
183
      amount.times{ gain_item(item, 1, include_equip) }
184
      return
185
    end
186
    
187
    item = try_to_eval_unique(item, amount)
188
    gain_itm_unique_rpgbi_era(item, amount, include_equip=false)
189
    
190
    # Clean up the databases if over 200 unique items have been gained
191
    @num_uniques ||= 0;
192
    @num_uniques += 1 if item && item.is_unique_rpgbi
193
    clean = Era::CleanCDB::Clean
194
    if $imported["Ra CleanCDB"] && clean && @num_uniques > Era::CleanCDB_Amt 
195
      Era::CleanCDB.clean; @num_uniques = 0
196
    end
197
  end
198
  #----------------------------------------------------------------------------
199
  # * Each unique item gets a separate slot in the db
200
  #----------------------------------------------------------------------------
201
  def try_to_eval_unique(item, amount)
202
    return item if !eval_unq_ok?(item)
203
    item = Marshal.load(Marshal.dump(old_item = item)) 
204
    item.add_to_dbases if !delete_cust_item?(item, amount)
205
    item
206
  end
207
  #----------------------------------------------------------------------------
208
  # * Try to evaluate a unique item only if it is the original, i.e. wasn't 
209
  #     created during runtime. This should allow compatibility with scripts
210
  #     that expect an item to always have the same id.
211
  #----------------------------------------------------------------------------
212
  def eval_unq_ok?(item)
213
    item && item.is_unique_rpgbi && original_item_era?(item)
214
  end
215
  #----------------------------------------------------------------------------
216
  # * Check to Remove Custom Item From Database
217
  #----------------------------------------------------------------------------
218
  def delete_cust_item?(item, amount)
219
    !item.nil? && item.valid_uniq_party_item? && -amount >= item_number(item) && 
220
    item.is_unique_rpgbi
221
  end # delete_custom?
222
  #----------------------------------------------------------------------------
223
  # * Is the item original?
224
  #----------------------------------------------------------------------------
225
  def original_item_era?(item)
226
    sz = 0
227
    if item.is_a?(RPG::Item); sz = Era.db_array_size(:data_items)
228
    elsif item.is_a?(RPG::Weapon); sz = Era.db_array_size(:data_weapons)
229
    elsif item.is_a?(RPG::Armor); sz = Era.db_array_size(:data_armors)
230
    end
231
    item.id < sz # when the id is > size of orig db array the item was added 
232
                    # during runtime.
233
  end
234
end # Game_Party
235
236
# End of File