Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #═╦═════════════════════════════════════════════════════════════════════════════
- # ║ § Instance Items (v1.4) by Enelvon [License: CC BY-SA 3.0]
- # ║ <RMVX Ace>
- #═╬═════════════════════════════════════════════════════════════════════════════
- # ║ § Change Log
- #─╫─────────────────────────────────────────────────────────────────────────────
- # ║ v1.0 (December 25th, 2012) - Released the script for the first time
- # ║ v1.1 (December 26th, 2012) - Fixed a single-word error that could cause
- # ║ issues with non-unique armor
- # ║ v1.2 (February 16th, 2013) - Added the ability to check if an item is
- # ║ instanced
- # ║ v1.3 (February 17th, 2013) - Fixed a bug with equipping items
- # ║ v1.4 (May 26th, 2013) - Fixed a bug with the Remove X event commands
- # ║
- #═╬═════════════════════════════════════════════════════════════════════════════
- # ║ § Summary
- #─╫─────────────────────────────────────────────────────────────────────────────
- # ║ This script adds the ability to have 'instances' of items. Each instance may
- # ║ have slightly different stats/effects than the base item. This script
- # ║ contains only the ability to have stat variance on equip items - it is
- # ║ intended to be extended by others in order to add more features.
- #═╬═════════════════════════════════════════════════════════════════════════════
- # ║ § Required Scripts
- #─╫─────────────────────────────────────────────────────────────────────────────
- # ║ SES Core
- # ║
- #═╬═════════════════════════════════════════════════════════════════════════════
- # ║ § Known Incompatibilities
- #─╫─────────────────────────────────────────────────────────────────────────────
- # ║ None.
- # ║
- #═╬═════════════════════════════════════════════════════════════════════════════
- # ║ § Installation
- #─╫─────────────────────────────────────────────────────────────────────────────
- # ║ Place this below Materials and the SES Script Core, and above all other
- # ║ non-SES custom scripts (though make sure it's above any Instance Item
- # ║ extensions).
- # ║
- #═╬═════════════════════════════════════════════════════════════════════════════
- # ║ § Configuration
- #─╫─────────────────────────────────────────────────────────────────────────────
- # ║ There is some simple configuration required to use this script. Locate
- # ║ All_Unique in the SES::InstanceItems module (that should not be hard - it's
- # ║ at the top of the script). Change the value of each key to change whether or
- # ║ not items of that type will be treated as unique by default.
- # ║
- #═╬═════════════════════════════════════════════════════════════════════════════
- # ║ § Tags
- #─╫─────────────────────────────────────────────────────────────────────────────
- # ║ ● Weapon/Armor
- # ║ <Unique>
- # ║ Placing this in the Notes box of an item will toggle uniqueness. If its
- # ║ item type defaults to being unique, the item will be nonunique. If the
- # ║ item type defaults to nonunique, the item will be unique.
- # ║
- # ║ <Vary !Stat!: !Value!, !Chance!>
- # ║ Place this in a Notes box to set a variance of !Value! for !Stat!.
- # ║ !Chance is the likelihood (as a percentage) that variance will occur.
- # ║ This is a very basic implementation of variance - created items of the
- # ║ type will have a value of up to the given number added or subtracted
- # ║ from their base value for the stat. Don't expect it to work miracles,
- # ║ just for it to work.
- # ║ ► Replacements:
- # ║ !Stat! with hp, mp, atk, def, mat, mdf, agi, or luk.
- # ║ !Value! with an integer for the maximum variance of the stat.
- # ║ !Chance! with a percentage chance of variance occurring.
- # ║
- # ║ ● Item
- # ║ <Unique>
- # ║ Placing this in the Notes box of an item will toggle uniqueness. If its
- # ║ item type defaults to being unique, the item will be nonunique. If the
- # ║ item type defaults to nonunique, the item will be unique.
- # ║
- #═╬═════════════════════════════════════════════════════════════════════════════
- # ║ § Aliased Methods
- #─╫─────────────────────────────────────────────────────────────────────────────
- # ║ ● module DataManager
- # ║ self.create_game_objects
- # ║ self.make_save_contents
- # ║ self.extract_save_contents
- # ║
- # ║ ● class Game_BaseItem
- # ║ initialize
- # ║
- # ║ ● class Game_Party
- # ║ gain_item - as trade_item so instancing can be avoided
- # ║
- #═╬═════════════════════════════════════════════════════════════════════════════
- # ║ § Redefined Methods
- #─╫─────────────────────────────────────────────────────────────────────────────
- # ║ ● class Game_BaseItem
- # ║ object
- # ║ set_equip(is_weapon, item_id, unique)
- # ║
- # ║ ● class Game_Actor
- # ║ equips_include?(item)
- # ║ init_equips(equips)
- # ║ trade_item_with_party(new_item, old_item)
- # ║ change_equip_by_id(slot_id, item_id)
- # ║
- # ║ ● class Game_Party
- # ║ gain_item(item, amount, include_equip = false)
- # ║ lose_item(item, amount, include_equip = false)
- # ║
- # ║ ● class Window_ItemList
- # ║ draw_item(index)
- # ║
- #═╬═════════════════════════════════════════════════════════════════════════════
- # ║ § New Methods
- #─╫─────────────────────────────────────────────────────────────────────────────
- # ║ ● class Game_Party
- # ║ new_item(item, type)
- # ║
- #═╬═════════════════════════════════════════════════════════════════════════════
- # ║ ▼ module SES::InstanceItems
- #═╩═════════════════════════════════════════════════════════════════════════════
- module SES module InstanceItems
- #═╦═══════════════════════════════════════════════════════════════════════════
- # ║ α BEGIN CONFIGURATION
- #═╩═══════════════════════════════════════════════════════════════════════════
- # The hash defining the base uniqueness value of each type of item. Setting
- # one of these to true makes items of the given type be true by default.
- # Setting it to false will have them default to nonunique, as in base VXAce.
- All_Unique = {
- RPG::Weapon => true,
- RPG::Armor => true,
- RPG::Item => false,
- }
- #═╦═══════════════════════════════════════════════════════════════════════════
- # ║ Ω END CONFIGURATION
- #═╩═══════════════════════════════════════════════════════════════════════════
- # RegExp for toggling uniqueness of an item.
- Unique = /^<Unique>/i
- # RegExp for stat variance.
- StatVariance = /^<Vary (\w+):\s*(\d+),\s*(\d+)%?>/i
- # List of stat indices. You can add custom stats to this to allow them to
- # be varied, but the custom stats must be added to the game as part of the
- # params array for this to have any effect.
- StatIndex = ['hp', 'mp', 'atk', 'def', 'mat', 'mdf', 'agi', 'luk']
- end end
- ($imported ||= {})["SES - Instance Items"] = 1.0
- #═╦═════════════════════════════════════════════════════════════════════════════
- # ║ ▲ module SES::InstanceItems
- #─╫─────────────────────────────────────────────────────────────────────────────
- # ║ ▼ class RPG::BaseItem
- #═╩═════════════════════════════════════════════════════════════════════════════
- class RPG::BaseItem
- attr_accessor :old_id; attr_accessor :instanced
- def unique; scan_ses_notes if !@unique; return @unique end
- end
- #═╦═════════════════════════════════════════════════════════════════════════════
- # ║ ▲ class RPG::BaseItem
- #─╫─────────────────────────────────────────────────────────────────────────────
- # ║ ▼ class RPG::EquipItem
- #═╩═════════════════════════════════════════════════════════════════════════════
- class RPG::EquipItem < RPG::BaseItem
- # Scans the notes box of the item
- alias en_ii_ei_ssn scan_ses_notes
- def scan_ses_notes(tags = {})
- @variances = [[0,100]] * 8
- @unique = SES::InstanceItems::All_Unique[self.class]
- tags[SES::InstanceItems::StatVariance] =
- "stat = SES::InstanceItems::StatIndex.index($1.to_s.downcase)
- @variances[stat] = [$2.to_i, $3.to_i]"
- tags[SES::InstanceItems::Unique] = "@unique = !@unique"
- en_ii_ei_ssn(tags)
- end
- def variances; scan_ses_notes if !@variances; return @variances end
- # Allows basic variance
- def vary
- unless @varied
- (0...@params.size).each do |i|
- v = rand(variances[i][0]).to_i; v *= -1 if rand(8) <= 3
- @params[i] += v if rand(100) < variances[i][1]
- end
- @varied = true
- end
- end
- end
- #═╦═════════════════════════════════════════════════════════════════════════════
- # ║ ▲ class RPG::EquipItem
- #─╫─────────────────────────────────────────────────────────────────────────────
- # ║ ▼ class RPG::Item
- #═╩═════════════════════════════════════════════════════════════════════════════
- class RPG::Item < RPG::UsableItem
- # Scans the Notes box of the item
- alias en_ii_i_ssn scan_ses_notes
- def scan_ses_notes(tags = {})
- @unique = SES::InstanceItems::All_Unique[self.class]
- tags[SES::InstanceItems::Unique] = "@unique = !@unique"
- en_ii_i_ssn(tags)
- end
- end
- #═╦═════════════════════════════════════════════════════════════════════════════
- # ║ ▲ class RPG::Item
- #─╫─────────────────────────────────────────────────────────────────────────────
- # ║ ▼ module DataManager
- #═╩═════════════════════════════════════════════════════════════════════════════
- module DataManager
- class << self
- alias en_fs_dm_cgo create_game_objects
- alias en_fs_dm_msc make_save_contents
- alias en_fs_dm_esc extract_save_contents
- end
- def self.create_game_objects
- en_fs_dm_cgo
- $game_armors, $game_weapons, $game_items =
- $data_armors, $data_weapons, $data_items
- end
- def self.make_save_contents
- contents = en_fs_dm_msc
- contents[:armors], contents[:weapons], contents[:items] =
- $game_armors, $game_weapons, $game_items
- contents
- end
- def self.extract_save_contents(contents)
- en_fs_dm_esc(contents)
- $game_armors, $game_weapons, $game_items =
- contents[:armors], contents[:weapons], contents[:items]
- end
- end
- #═╦═════════════════════════════════════════════════════════════════════════════
- # ║ ▲ module DataManager
- #─╫─────────────────────────────────────────────────────────────────────────────
- # ║ ▼ class Game_BaseItem
- #═╩═════════════════════════════════════════════════════════════════════════════
- class Game_BaseItem
- alias en_ii_gbi_i initialize
- def initialize
- en_ii_gbi_i
- @unique = false
- end
- def object
- id = @item_id
- return $data_skills[@item_id] if is_skill?
- if is_item? then return $game_items[id]
- elsif is_weapon? then return $game_weapons[id]
- elsif is_armor? then return $game_armors[id] end
- return nil
- end
- def set_equip(is_weapon, item_id, unique = false)
- @class = is_weapon ? RPG::Weapon : RPG::Armor
- @item_id = item_id
- @unique = unique
- end
- end
- #═╦═════════════════════════════════════════════════════════════════════════════
- # ║ ▲ class Game_BaseItem
- #─╫─────────────────────────────────────────────────────────────────────────────
- # ║ ▼ class Game_Actor
- #═╩═════════════════════════════════════════════════════════════════════════════
- class Game_Actor < Game_Battler
- def equips_include?(item)
- equips.compact.each do |e|
- return true if e.old_id == item.id && e.class == item.class
- end
- return false
- end
- def init_equips(equips)
- @equips = Array.new(equip_slots.size) { Game_BaseItem.new }
- equips.each_with_index do |item_id, i|
- etype_id = index_to_etype_id(i)
- slot_id = empty_slot(etype_id)
- if etype_id == 0 then i, t = $data_weapons[item_id], :weapon
- else i, t = $data_armors[item_id], :armor end
- if !i.nil? && i.unique then id, u = $game_party.new_item(i, t).id, true
- elsif i.nil? then id, u = 0, false
- else id, u = i.id, false end
- @equips[slot_id].set_equip(etype_id == 0, id, u) if slot_id
- end
- refresh
- end
- def trade_item_with_party(new_item, old_item)
- return false if new_item && !$game_party.has_item?(new_item)
- $game_party.trade_item(old_item, 1)
- $game_party.lose_item(new_item, 1)
- return true
- end
- def change_equip_by_id(slot_id, item_id)
- if equip_slots[slot_id] == 0
- change_equip(slot_id, $game_weapons[item_id])
- else change_equip(slot_id, $game_armors[item_id]) end
- end
- end
- #═╦═════════════════════════════════════════════════════════════════════════════
- # ║ ▲ class Game_Actor
- #─╫─────────────────────────────────────────────────────────────────────────────
- # ║ ▼ class Game_Party
- #═╩═════════════════════════════════════════════════════════════════════════════
- class Game_Party < Game_Unit
- alias trade_item gain_item
- def new_item(item, type)
- newi = Marshal.load(Marshal.dump(item))
- newi.old_id = item.id
- newi.instanced = true
- newi.id = eval("$game_#{type}s.size")
- newi = process_new_item(newi)
- eval("$game_#{type}s.push(newi)
- $game_#{type}s[newi.id].vary unless type == :item
- return $game_#{type}s[newi.id]")
- end
- def process_new_item(item)
- return item
- end
- [:items, :weapons, :armors].each do |i|
- define_method(i) do
- eval("@#{i}.keys.sort.collect { |id| $game_#{i}[id] }")
- end
- end
- def gain_item(*args)
- oitem = args[0] if !args[0].nil?
- if args[1] > 0
- args[1].times do
- item = oitem
- if item && item.unique
- args[0] = if item.is_a?(RPG::Weapon) then new_item(item, :weapon)
- elsif item.is_a?(RPG::Armor) then args[0] = new_item(item, :armor)
- elsif item.is_a?(RPG::Item) then args[0] = new_item(item, :item) end
- end
- trade_item(args[0], 1)
- end
- elsif args[1] < 0
- item = args[0]
- if item.unique
- container = if item.is_a?(RPG::Weapon) then weapons
- elsif item.is_a?(RPG::Armor) then armors
- elsif item.is_a?(RPG::Item) then items end
- args[1].abs.times do
- trade_item(container.select {|i| i.old_id == item.id }[0], -1)
- end
- else
- trade_item(item, args[1])
- end
- end
- end
- def lose_item(*args)
- args[1] *= -1
- trade_item(*args)
- end
- end
- #═╦═════════════════════════════════════════════════════════════════════════════
- # ║ ▲ class Game_Party
- #─╫─────────────────────────────────────────────────────────────────────────────
- # ║ ▼ class Window_ItemList
- #═╩═════════════════════════════════════════════════════════════════════════════
- class Window_ItemList < Window_Selectable
- def draw_item(index)
- item = @data[index]
- if item
- rect = item_rect(index)
- rect.width -= 4
- draw_item_name(item, rect.x, rect.y, enable?(item))
- draw_item_number(rect, item) unless item.unique
- end
- end
- end
- #═╦═════════════════════════════════════════════════════════════════════════════
- # ║ ▲ class Window_ItemList
- #═╩═════════════════════════════════════════════════════════════════════════════
Advertisement
Add Comment
Please, Sign In to add comment