#==============================================================================
# ** Team Scriptastic's Random Enchants
# Version 0.10
#------------------------------------------------------------------------------
# This script will give pre-specifiec weapons a random enchant when they are
# given to the player.
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
# * Version History
# - - - - - - - - - - - - - - - - - - - - - - - - - -
# Version [0.10] --------------------------------------------- ([2009-07-02])
# -Initial version
# -Author: Glitchfinder
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
# * Instructions
# - - - - - - - - - - - - - - - - - - - - - - - - - -
# Place this script above Main, and below the default scripts. (I realize this
# is obvious to most, but some people don't get it.)
#
# This script requires a slight knowledge of scripting. To enable an item to
# have random variants, simply add a tag to the notes box, that looks like the
# following:
# <random +10>
# Where 10 is the value you want added to the stats enchanted.
#
# Below is a list of all possible enchantments. An enchantment looks like the
# following hash:
#
# @enchants['of Strength'] = {'atk' => true, 'def' => false,
# 'spi' => false, 'agi' => false,
# 'critical' => false, 'eva' => false}
#
# Where 'of Strength' is the string added to the name of the base item. This
# also serves as an identifier for this enchantment, so two enchantments with
# the same name will result in only the latter occuring.
#
# 'atk' => false | if this is true, it would add XX from <random +xx>
# | to the weapon's attack stat.
# 'def' => false | if this is true, it would add XX from <random +xx>
# | to the weapon's defense stat.
# 'spi' => false | if this is true, it would add XX from <random +xx>
# | to the weapon's spirit stat.
# 'agi' => false | if this is true, it would add XX from <random +xx>
# | to the weapon's agility stat.
# 'eva' => false | if this is true, it would add XX from <random +xx>
# | to the weapon's evasion stat.
# 'critical' => false | if this is true, it would add XX from <random +xx>
# | to the weapon's critical hit ratio.
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
# * Terms of Service
# - - - - - - - - - - - - - - - - - - - - - - - - - -
# This script is free for use in private or commercial applications, under the
# condition that this header remains intact and credit to Team Scriptastic and
# all authors mentioned in the version history is mentioned in an appropriate
# section visible to users of the product.
#==============================================================================
#==============================================================================
# + Enchants (Module)
#==============================================================================
module Enchants
@enchants = {}
@enchants.default = {'atk' => false, 'def' => false,
'spi' => false, 'agi' => false,
'critical' => false, 'eva' => false}
@enchants['of Strength'] = {'atk' => true, 'def' => false,
'spi' => false, 'agi' => false,
'critical' => false, 'eva' => false}
@enchants['of Defense'] = {'atk' => false, 'def' => true,
'spi' => false, 'agi' => false,
'critical' => false, 'eva' => false}
@enchants['of Intellect'] = {'atk' => false, 'def' => false,
'spi' => true, 'agi' => false,
'critical' => false, 'eva' => false}
@enchants['of Agility'] = {'atk' => false, 'def' => false,
'spi' => false, 'agi' => true,
'critical' => false, 'eva' => false}
@enchants['of the Warrior'] = {'atk' => true, 'def' => true,
'spi' => false, 'agi' => false,
'critical' => false, 'eva' => false}
@enchants['of the Sorcerer'] = {'atk' => true, 'def' => false,
'spi' => true, 'agi' => false,
'critical' => false, 'eva' => false}
@enchants['of the Berserker'] = {'atk' => true, 'def' => false,
'spi' => false, 'agi' => true,
'critical' => false, 'eva' => false}
@enchants['of the Medic'] = {'atk' => false, 'def' => true,
'spi' => true, 'agi' => false,
'critical' => false, 'eva' => false}
@enchants['of the Monk'] = {'atk' => false, 'def' => true,
'spi' => false, 'agi' => true,
'critical' => false, 'eva' => false}
@enchants['of the Focused'] = {'atk' => false, 'def' => false,
'spi' => true, 'agi' => true,
'critical' => false, 'eva' => false}
@enchants['of the Cruel'] = {'atk' => true, 'def' => false,
'spi' => false, 'agi' => false,
'critical' => true, 'eva' => false}
@enchants['of the Cunning'] = {'atk' => false, 'def' => false,
'spi' => false, 'agi' => true,
'critical' => true, 'eva' => false}
@enchants['of the Sly'] = {'atk' => false, 'def' => false,
'spi' => false, 'agi' => true,
'critical' => false, 'eva' => true}
#--------------------------------------------------------------------------
# * Enchant Weapon
# weapon : data for specific weapon
#--------------------------------------------------------------------------
def self.enchant(weapon)
# Check if the random tag is in the notes box
if weapon.note.include?('<random +')
# If so, load the default weapon index
weapon_data = load_data("Data/Weapons.rvdata")
# Check which id the weapon is based on
weapon_id = weapon.id * rand(@enchants.keys.size) + weapon_data.size
# Return this weapon data
weapon = $data_weapons[weapon_id]
end
return weapon
end
#--------------------------------------------------------------------------
# * Create Enchanted Weapons
# weapon : data for specific weapon
#--------------------------------------------------------------------------
def self.create_enchants
# Create blank weapon array
weapons = []
# Iterate through all weapons in $data_weapons
for weapon in $data_weapons
# Skip if the current weapon is nil
next if weapon == nil
# If the weapon includes the random tag
if weapon.note.include?('<random +')
# Add the enchanted weapons to the appropriate classes
enchant_class(weapon)
# Iterate through all enchants
for enchant in @enchants.keys
# Clone and enchant current weapon
new_weapon = weapon.clone
new_weapon = enchant_stats(new_weapon, enchant)
# Remove the random tag from the enchanted weapon
new_weapon.note = new_weapon.note.gsub(/<random \+([0-9]+)>/) {''}
# Push new weapon data to $data_weapons
$data_weapons.push new_weapon
# Push new weapons into weapons array
weapons.push new_weapon
end
end
end
# Save the new data using the weapons array
save_enchant(weapons) unless weapons.empty?
end
#--------------------------------------------------------------------------
# * Create Enchant
# weapon : data for specific weapon
# str : name of specific enchant
#--------------------------------------------------------------------------
def self.enchant_stats(weapon, str)
# Set new weapon id
weapon.id = $data_weapons.size
# Set new weapon name
weapon.name += ' ' + str
# Remove the tag from the weapon note
value = weapon.note.slice(/<random \+([0-9]+)>/)
value.gsub!(/<random \+/) {''}
value.gsub!(/>/) {''}
# Convert the number within the tag string to an integer
value = value.to_i
# Add the value to the appropriate stat
weapon.atk += value if @enchants[str]['atk']
weapon.def += value if @enchants[str]['def']
weapon.spi += value if @enchants[str]['spi']
weapon.agi += value if @enchants[str]['agi']
weapon.critical += value if @enchants[str]['critical']
weapon.eva += value if @enchants[str]['eva']
# Return the weapon data
return weapon
end
#--------------------------------------------------------------------------
# * Add Enchanted Weapon to Class Lists
# weapon : data for specific weapon
#--------------------------------------------------------------------------
def self.enchant_class(weapon)
# Create base class array
classes = [nil]
# Iterate through all classes
for new_class in $data_classes
# Skip if the current class is nil
next if new_class == nil
# If the class used the base weapon
if new_class.weapon_set.include? weapon.id
# Iterate through all IDs for the enchanted version
for id in [email=0...@enchants.keys.size]0...@enchants.keys.size[/email]
# Add the new IDs to the useable weapons array
new_class.weapon_set.push $data_weapons.size + id
end
end
# Add the modified class to the classes array
classes.push new_class
end
# Replace the default classes array with the modified one
$data_classes = classes
end
#--------------------------------------------------------------------------
# * Save Enchanted Weapon Data
# weapons : data for specific weapon
#--------------------------------------------------------------------------
def self.save_enchant(weapons)
# If the file exists
if FileTest.exist?('Data/EnchantedWeapons.rvdata')
# Open the file and load the data
file = File.open('Data/EnchantedWeapons.rvdata', "rb")
weapon_data = Marshal.load(file)
class_data = Marshal.load(file)
else
# Otherwise, default to nil
weapon_data = [nil]
class_data = [nil]
end
# Iterate through all weapons in the weapons variable
for weapon in weapons
# Push weapons into a temporary container
weapon_data.push weapon
end
# Iterate through all classes in $data_classes
for old_class in $data_classes
# Skip if the current class it nil
next if old_class == nil
# Create new instance of extended class data
new_class = RPG::ClassExtension.new
# Add the ID and weapon set of the current class
new_class.id = old_class.id
new_class.weapon_set = old_class.weapon_set
# Push new class datas into a temporary container
class_data.push new_class
end
# Open the enchants file and dump data
file = File.open('Data/EnchantedWeapons.rvdata', "wb")
Marshal.dump(weapon_data, file)
Marshal.dump(class_data, file)
end
# Protect private class methods
private_class_method :enchant_stats
private_class_method :enchant_class
private_class_method :save_enchant
end
#==============================================================================
# + RPG::BaseItem (module)
#==============================================================================
module RPG
class BaseItem
def initialize
@id = 0
@name = ""
@icon_index = 0
@description = ""
@note = ""
@atk = 0
@def = 0
@spi = 0
@agi = 0
@critical = 0
@eva = 0
end
attr_accessor :id
attr_accessor :name
attr_accessor :icon_index
attr_accessor :description
attr_accessor :note
attr_accessor :atk
attr_accessor :def
attr_accessor :spi
attr_accessor :agi
attr_accessor :critical
attr_accessor :eva
end
#============================================================================
# + RPG::ClassExtension (module)
#============================================================================
class ClassExtension
def initialize
@id = 0
@weapon_set = []
end
attr_accessor :id
attr_accessor :weapon_set
end
end
#==============================================================================
# ** Game_Actor
#------------------------------------------------------------------------------
# This class handles actors. It's used within the Game_Actors class
# ($game_actors) and referenced by the Game_Party class ($game_party).
#==============================================================================
class Game_Actor < Game_Battler
#--------------------------------------------------------------------------
# * Get Evasion Rate
#--------------------------------------------------------------------------
def eva
n = 5
# Add the enchanted weapon's evasion stat
for item in equips.compact do n += item.eva end
return n
end
#--------------------------------------------------------------------------
# * Get Critical Ratio
#--------------------------------------------------------------------------
def cri
n = 4
n += 4 if actor.critical_bonus
for weapon in weapons.compact
n += 4 if weapon.critical_bonus
# Add the enchanted weapon's critical ratio
n += weapon.critical
end
return n
end
end
#==============================================================================
# ** Game_Party
#------------------------------------------------------------------------------
# This class handles the party. It includes information on amount of gold
# and items. The instance of this class is referenced by $game_party.
#==============================================================================
class Game_Party < Game_Unit
#--------------------------------------------------------------------------
# * Alias Methods
#--------------------------------------------------------------------------
alias scriptastic_rand_enchant_game_party_gain_item gain_item
#--------------------------------------------------------------------------
# * Gain Items (or lose)
# item : Item
# n : Number
# include_equip : Include equipped items
#--------------------------------------------------------------------------
def gain_item(item, n, include_equip = false)
# Reaplace item data with that of an enchanted item instead, if applicable
item = Enchants::enchant(item) if item.is_a? RPG::Weapon
# Call the original method
scriptastic_rand_enchant_game_party_gain_item(item, n, include_equip)
end
end
#==============================================================================
# ** Scene_Title (Data Conversion)
#------------------------------------------------------------------------------
# This script converts RGSS data structure to RGSS2 to increase compatibility.
#==============================================================================
class Scene_Title < Scene_Base
#--------------------------------------------------------------------------
# * Alias Methods
#--------------------------------------------------------------------------
alias scriptastic_rand_enchant_scene_title_load_database load_database
alias scriptastic_rand_enchant_scene_title_load_bt_database load_bt_database
#--------------------------------------------------------------------------
# * Load Database
#--------------------------------------------------------------------------
def load_database
# Call the original method
scriptastic_rand_enchant_scene_title_load_database
# Load normal weapon data
$data_weapons = load_weapons
# Load enchanted weapon data
load_enchants
end
#--------------------------------------------------------------------------
# * Load Battle Test Database
#--------------------------------------------------------------------------
def load_bt_database
# Call the original method
scriptastic_rand_enchant_scene_title_load_bt_database
# Load normal weapon data
$data_weapons = load_weapons
# Load enchanted weapon data
load_enchants
end
#--------------------------------------------------------------------------
# * Load and Convert Weapons
#--------------------------------------------------------------------------
def load_weapons
# Load base weapon data
if $BTEST
default_data = load_data("Data/BT_Weapons.rvdata")
else
default_data = load_data("Data/Weapons.rvdata")
end
# Add base for new $data_weapons array
new_data = [nil]
# Iterate through all weapons
for weapon in default_data
# Skip if weapon is nil
next if weapon == nil
# Create new instance of RPG::Weapon, with new data included
new_weapon = RPG::Weapon.new
# Add data from old weapon to the new weapon
new_weapon.id = weapon.id
new_weapon.name = weapon.name
new_weapon.icon_index = weapon.icon_index
new_weapon.description = weapon.description
new_weapon.note = weapon.note
new_weapon.animation_id = weapon.animation_id
new_weapon.price = weapon.price
new_weapon.hit = weapon.hit
new_weapon.atk = weapon.atk
new_weapon.def = weapon.def
new_weapon.spi = weapon.spi
new_weapon.agi = weapon.agi
new_weapon.two_handed = weapon.two_handed
new_weapon.fast_attack = weapon.fast_attack
new_weapon.dual_attack = weapon.dual_attack
new_weapon.critical_bonus = weapon.critical_bonus
new_weapon.element_set = weapon.element_set
new_weapon.state_set = weapon.state_set
# Push the new weapon into the new_data array
new_data.push new_weapon
end
# return new_data
return new_data
end
#--------------------------------------------------------------------------
# * Load Enchanted Weapons
#--------------------------------------------------------------------------
def load_enchants
# Check for enchanted weapon file
if FileTest.exist?('Data/EnchantedWeapons.rvdata')
# If in debug mode
if $TEST
# Delete and recompile enchanted weapon file
File.delete('Data/EnchantedWeapons.rvdata')
Enchants::create_enchants
else
# Open and load enchanted weapon file
file = File.open('Data/EnchantedWeapons.rvdata', "rb")
weapon_data = Marshal.load(file)
class_data = Marshal.load(file)
# Iterate through all enchanted weapons
for weapon in weapon_data
# Skip if the weapon is nil
next if weapon == nil
# Add new weapon to $data_weapons
$data_weapons.push weapon
end
# Iterate through all loaded classes
for new_class in class_data
# Skip if class is nil
next if new_class == nil
# Skip if original class is nil
next if $data_classes[new_class.id] == nil
# Replace original weapon set with updated one
$data_classes[new_class.id].weapon_set = new_class.weapon_set
end
end
else
# Create new enchant file
Enchants::create_enchants
end
end
end