Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #═╦═════════════════════════════════════════════════════════════════════════════
- # ║ § Affix System (v1.0) by Enelvon [License: CC BY-SA 3.0]
- # ║ <RMVX Ace>
- #═╬═════════════════════════════════════════════════════════════════════════════
- # ║ § Change Log
- #─╫─────────────────────────────────────────────────────────────────────────────
- # ║ v1.0 (January 17th, 2013) - Script released.
- # ║
- #═╬═════════════════════════════════════════════════════════════════════════════
- # ║ § Summary
- #─╫─────────────────────────────────────────────────────────────────────────────
- # ║ This script adds the ability for equipment to have affixes. Affixes can
- # ║ alter the stats of an item or provide new features.
- # ║
- #═╬═════════════════════════════════════════════════════════════════════════════
- # ║ § Required Scripts
- #─╫─────────────────────────────────────────────────────────────────────────────
- # ║ SES - Instance Items v1.0 or higher
- # ║ SES - Parse Features v1.0 or higher
- # ║
- #═╬═════════════════════════════════════════════════════════════════════════════
- # ║ § Known Incompatibilities
- #─╫─────────────────────────────────────────────────────────────────────────────
- # ║ None.
- # ║
- #═╬═════════════════════════════════════════════════════════════════════════════
- # ║ § Installation
- #─╫─────────────────────────────────────────────────────────────────────────────
- # ║ Place this below SES - Instance Items.
- # ║
- #═╬═════════════════════════════════════════════════════════════════════════════
- # ║ § Configuration
- #─╫─────────────────────────────────────────────────────────────────────────────
- # ║ There's no configuration within the script. All of it occurs in a text file
- # ║ that should be placed in the Data folder. Name the file Affixes.txt.
- # ║
- # ║ There are several important tags that you'll be using in this file - it's a
- # ║ lot like the one from External Text.
- # ║
- # ║ First of all there are the tags to determine whether what we're making is
- # ║ a prefix or a suffix, as well as its name. They're simple:
- # ║
- # ║ [!Affix!] !Name!
- # ║
- # ║ Replace !Affix! with either Prefix or Suffix and !Name! with what should be
- # ║ added to the weapon's name. It will be added before the base for prefixes
- # ║ and after it for suffixes (obviously).
- # ║
- # ║ Next there's the tag to determine whether it should be applied to weapons,
- # ║ armor, or both:
- # ║
- # ║ [Type] !Type!
- # ║
- # ║ Type can be Weapon, Armor, or All.
- # ║
- # ║ The last tag is to determine the rarity of the affix. It won't appear on
- # ║ equipment with a lower rarity level than the affix itself, and will appear
- # ║ more frequently on equipment of a higher rarity.
- # ║
- # ║ [Rarity] !Rarity!
- # ║
- # ║ Replace !Rarity! with an integer value representing the affix's rarity.
- # ║
- # ║ To give an affix effects, just add them on lines below the rarity tag.
- # ║ Effects are given with the tags described in the instructions for
- # ║ SES - Parse Features.
- # ║
- #═╬═════════════════════════════════════════════════════════════════════════════
- # ║ § Tags
- #─╫─────────────────────────────────────────────────────────────────────────────
- # ║ ● Weapon/Armor
- # ║ <Rarity: !Num!>
- # ║ Use this to indicate the rarity level of a piece of equipment. The
- # ║ rarity determines which affixes the item can have.
- # ║ ► Replacements:
- # ║ !Num! with the rarity level of the item.
- # ║
- # ║ <Disable: !Type!>
- # ║ Use this to prevent an item from having a certain type of affix.
- # ║ ► Replacements:
- # ║ !Type! with either Pre to disable prefixes or Suf to disable suffixes.
- # ║
- # ║ <Max !Type!: !Num!>
- # ║ Use this to determine the maximum number of prefixes or suffixes an item
- # ║ can have. The default is 1 of each.
- # ║ ► Replacements:
- # ║ !Type! with either Pre to choose the maximum number of prefixes or Suf
- # ║ to choose the number of suffixes.
- # ║ !Num! with the desired maximum.
- # ║
- # ║ <!Type! Chance: !Num!>
- # ║ Use this to determine the chance of an item having prefixes or suffixes.
- # ║ ► Replacements:
- # ║ !Type! with either Pre to choose the likelihood of prefixes or Suf
- # ║ to choose the likelihood of suffixes.
- # ║ !Num! with the desired likelihood (as a percentage).
- # ║
- #═╬═════════════════════════════════════════════════════════════════════════════
- # ║ § Aliased Methods
- #─╫─────────────────────────────────────────────────────────────────────────────
- # ║ ● module Data_Manager
- # ║ self.load_normal_database
- # ║ self.load_battle_test_database
- # ║
- #═╬═════════════════════════════════════════════════════════════════════════════
- # ║ ▼ module SES::Affixes
- #═╩═════════════════════════════════════════════════════════════════════════════
- module SES
- module Affixes
- # Tags for Affixes.txt
- Tags = {
- /^\[Prefix\]\s*(.+)/i =>
- %Q{ affix = :pre; key = $1; specific = nil },
- /^\[Suffix\]\s*(.+)/i =>
- %Q{ affix = :suf; key = $1; specific = nil },
- /^\[Type\]\s*(.+)/i =>
- %Q{ type = $1.downcase.to_sym
- affixes[type][key] = ["", 0, affix] },
- /^\[Rarity\]\s*(\d+)/i =>
- %Q{ affixes[type][key][1] = $1.to_i },
- }
- # Tag for rarity of equipment
- RarityTag = /^<Rarity:\s*(\d+)>/i
- # Tag to disable prefixes or suffixes
- DisableTag = /^<Disable (Pre|Suf)>/i
- # Tag to determine maximum number of prefixes/suffixes
- MaxTag = /^<Max (Pre|Suf):\s*(\d+)>/i
- # Tag to determine chance of having a prefix or suffix
- ChanceTag = /^<(Pre|Suf) Chance:\s*(\d+)>/i
- # Gets all available prefixes for an item
- def self.collectPrefixes(etype, rarity)
- type = etype == RPG::Weapon ? :weapon : :armor
- $game_affixes[type].merge($game_affixes[:all]).select do |k,v|
- v[2] == :pre && v[1] <= rarity
- end
- end
- # Gets all available suffixes for an item
- def self.collectSuffixes(etype, rarity)
- type = etype == RPG::Weapon ? :weapon : :armor
- $game_affixes[type].merge($game_affixes[:all]).select do |k,v|
- v[2] == :suf && v[1] <= rarity
- end
- end
- end
- end
- $imported ||= {}
- if $imported["SES - Instance Items"] < 1.0
- raise("You need SES - Instance Items v1.0 or higher to use SES - Affix System.")
- end
- $imported["SES - Affix System"] = 1.0
- #═╦═════════════════════════════════════════════════════════════════════════════
- # ║ ▲ module SES::Affixes
- #─╫─────────────────────────────────────────────────────────────────────────────
- # ║ ▼ class RPG::EquipItem < RPG::BaseItem
- #═╩═════════════════════════════════════════════════════════════════════════════
- class RPG::EquipItem < RPG::BaseItem
- alias en_af_ei_sn scan_ses_notes
- def scan_ses_notes(tags = {})
- @rarity = 1
- @canHave = {:pre => true, :suf => true}
- @maxAffixes = {:pre => 1, :suf => 1}
- @chanceOfAffix = {:pre => 25, :suf => 25}
- @prefixes, @suffixes = [], []
- tags[SES::Affixes::RarityTag] =
- %Q{@rarity = $1.to_i}
- tags[SES::Affixes::DisableTag] =
- %Q{@canHave[$1.downcase.to_sym] = false}
- tags[SES::Affixes::MaxTag] =
- %Q{@maxAffixes[$1.downcase.to_sym] = $2.to_i}
- tags[SES::Affixes::ChanceTag] =
- %Q{@chanceOfAffix[$1.downcase.to_sym] = $2.to_i}
- en_af_ei_sn(tags)
- end
- [:rarity, :canHave, :maxAffixes, :chanceOfAffix, :prefixes,
- :suffixes].each do |i|
- define_method(i) do
- eval("scan_ses_notes unless @#{i}
- @#{i}")
- end
- end
- def affixAffix
- pres, sufs = {}, {}
- if canHave[:pre]
- pres = SES::Affixes.collectPrefixes(self.class, @rarity)
- end
- if canHave[:suf]
- sufs = SES::Affixes.collectSuffixes(self.class, @rarity)
- end
- return if pres.empty? && sufs.empty?
- prelist, suflist =
- pres.keys.shuffle.shuffle.shuffle, sufs.keys.shuffle.shuffle.shuffle
- [:pre, :suf].each do |i|
- next if eval("#{i}list").empty?
- eval(%Q{if rand(100)+1 <= @chanceOfAffix[:#{i}]
- while #{i}list.size > 0 && @#{i}fixes.size < maxAffixes[:#{i}]
- cur#{i} = #{i}list.pop
- next if cur#{i}.nil? || cur#{i}.empty?
- if (@rarity - #{i}s[cur#{i}][1]) > rand(@rarity) &&
- rand(100)+1 <= @chanceOfAffix[:#{i}]
- @#{i}fixes << cur#{i}
- end
- end
- end})
- end
- prefix, suffix = "", ""
- @prefixes.each do |i| prefix << i << " " end
- @suffixes.each do |i| suffix << " " << i end
- @name = prefix << @name << suffix
- affixEffects = ""
- affixes = pres.merge(sufs)
- (@prefixes + @suffixes).each do |i|
- affixEffects << affixes[i][0] + "\n"
- end
- add_features(affixEffects, "Affixes")
- end
- end
- #═╦═════════════════════════════════════════════════════════════════════════════
- # ║ ▲ class RPG::EquipItem < RPG::BaseItem
- #─╫─────────────────────────────────────────────────────────────────────────────
- # ║ ▼ module DataManager
- #═╩═════════════════════════════════════════════════════════════════════════════
- module DataManager
- class << self
- alias en_af_dm_lnd load_normal_database
- alias en_af_dm_lbd load_battle_test_database
- end
- def self.create_affixes
- affixes = { :all => {}, :weapon => {}, :armor => {}, }
- [:weapon, :armor].each do |i| affixes[i].default = {} end
- affix, type, key = :pre, :all, ""
- File.open("Data/Affixes.txt", "r") do |file|
- file.readlines.each_with_index do |v, i|
- next if v =~ /(^\s*(#|\/\/).*|^\s*$)/
- SES::Affixes::Tags.each_pair do |k,p|
- (instance_eval(p); v = "") if v =~ k
- end
- affixes[type][key][0] << v unless v.empty?
- end
- end
- File.open("Data/Affixes.rvdata2", "w") do |file|
- Marshal.dump(affixes, file)
- end
- end
- def self.load_normal_database
- en_af_dm_lnd
- create_affixes if FileTest.exist?("Data/Affixes.txt")
- $game_affixes = load_data("Data/Affixes.rvdata2")
- end
- def self.load_battle_test_database
- en_af_dm_lbd
- create_affixes if FileTest.exist?("Data/Affixes.txt")
- $game_affixes = load_data("Data/Affixes.rvdata2")
- end
- end
- #═╦═════════════════════════════════════════════════════════════════════════════
- # ║ ▲ module DataManager
- #─╫─────────────────────────────────────────────────────────────────────────────
- # ║ ▼ class Game_Party < Game_Unit
- #═╩═════════════════════════════════════════════════════════════════════════════
- class Game_Party < Game_Unit
- alias en_af_gp_pni process_new_item
- def process_new_item(item)
- item.affixAffix
- en_af_gp_pni(item)
- end
- end
- #═╦═════════════════════════════════════════════════════════════════════════════
- # ║ ▲ class Game_Party < Game_Unit
- #═╩═════════════════════════════════════════════════════════════════════════════
Advertisement
Add Comment
Please, Sign In to add comment