Automatic Equipment Optimization
by RPG Advocate
saved from Phylomortis.Com
Introduction
This script modifies the equip screen so that if you press "X", the equipment in the slot selected by the cursor will be optimized, and if you press "Y", then all equipment slots will be optimized. You can change how the algorithm chooses the best equipment by changing the weight constants included with the script. In some games, accessories are not used to boost stats, so optimizing them by stats is pointless. If your game is one of those games, change the constant NO_ACCESSORY_OPTIMIZATION to true to prevent accessories from being subject to the optimization algorithm.
Some lines of code in the optimize algorithm are provided for compatibility with my two-handed weapon script. If you're not using this script, comment out or delete the lines marked in red in the optimize method.
EDIT BY DERVVULFMAN: Lines of code have been added work better with either the two-handed weapon script or the cursed weapons/armor script. In either case, place this script below the other(s).
Optimization will not be possible if a player has a cursed item as that item is intentionally not removable.
# Automatic Equipment Optimization
# by RPG Advocate
#==============================================================================
# ** Game_System
#------------------------------------------------------------------------------
# This class handles data surrounding the system. Backround music, etc.
# is managed here as well. Refer to "$game_system" for the instance of
# this class.
#==============================================================================
class Game_System
#--------------------------------------------------------------------------
# * Public Instance Variables
#--------------------------------------------------------------------------
attr_accessor :cursed_weapons # array of cursed weapons
attr_accessor :cursed_armors # array of cursed armors
attr_accessor :two_handed_weapons # array of two-handed weapons
#--------------------------------------------------------------------------
# * Object Initialization
#--------------------------------------------------------------------------
alias aeo_init initialize
def initialize
aeo_init
# Create empty arrays to prevent errors (unless already created/filled)
@cursed_weapons = [] if @cursed_weapons == nil
@cursed_armors = [] if @cursed_armors == nil
@two_handed_weapons = [] if @two_handed_weapons == nil
end
end
#==============================================================================
# ** Scene_Equip
#------------------------------------------------------------------------------
# This class performs equipment screen processing.
#==============================================================================
class Scene_Equip
#--------------------------------------------------------------------------
# * Constants
#--------------------------------------------------------------------------
WEAPON_ATK_WEIGHT = 1.0
WEAPON_PDF_WEIGHT = 0.0
WEAPON_MDF_WEIGHT = 0.0
WEAPON_STR_WEIGHT = 0.0
WEAPON_DEX_WEIGHT = 0.0
WEAPON_AGI_WEIGHT = 0.0
WEAPON_INT_WEIGHT = 0.0
ARMOR_EVA_WEIGHT = 0.0
ARMOR_PDF_WEIGHT = 0.75
ARMOR_MDF_WEIGHT = 0.25
ARMOR_STR_WEIGHT = 0.0
ARMOR_DEX_WEIGHT = 0.0
ARMOR_AGI_WEIGHT = 0.0
ARMOR_INT_WEIGHT = 0.0
NO_ACCESSORY_OPTIMIZATION = false
#--------------------------------------------------------------------------
# * Frame Update (when right window is active)
#--------------------------------------------------------------------------
alias aeo_update_right update_right
def update_right
# Perform the original call
aeo_update_right
# If X button was pressed
if Input.trigger?(Input::X)
# Play decision SE
$game_system.se_play($data_system.decision_se)
# optimize
optimize(@right_window.index)
# Refresh windows
@left_window.refresh
@right_window.refresh
@item_window1.refresh
@item_window2.refresh
@item_window3.refresh
@item_window4.refresh
@item_window5.refresh
return
end
# If Y button was pressed
if Input.trigger?(Input::Y)
# Play decision SE
$game_system.se_play($data_system.decision_se)
optimize(0)
optimize(1)
optimize(2)
optimize(3)
optimize(4)
@left_window.refresh
@right_window.refresh
@item_window1.refresh
@item_window2.refresh
@item_window3.refresh
@item_window4.refresh
@item_window5.refresh
return
end
end
#--------------------------------------------------------------------------
# * Optimize Equipment
# slot : equipment slot
#--------------------------------------------------------------------------
def optimize(slot)
if slot == 0
# Prevent weapon switch on cursed weapons
if $game_system.cursed_weapons.include?(@actor.weapon_id)
return
end
object = $data_weapons[@actor.weapon_id]
optimal = object.id
current = 0.00
if @actor.weapon_id != 0
current += object.atk * WEAPON_ATK_WEIGHT
current += object.pdef * WEAPON_PDF_WEIGHT
current += object.mdef * WEAPON_MDF_WEIGHT
current += object.str_plus * WEAPON_STR_WEIGHT
current += object.dex_plus * WEAPON_DEX_WEIGHT
current += object.agi_plus * WEAPON_AGI_WEIGHT
current += object.int_plus * WEAPON_INT_WEIGHT
else
optimal = 0
end
max_eval = current
@actor.equip(0, 0)
flag = false
zero_flag = true
for weapon in $data_weapons
if !flag
flag = true
next
end
evaluation = 0.00
evaluation += weapon.atk * WEAPON_ATK_WEIGHT
evaluation += weapon.pdef * WEAPON_PDF_WEIGHT
evaluation += weapon.mdef * WEAPON_MDF_WEIGHT
evaluation += weapon.str_plus * WEAPON_STR_WEIGHT
evaluation += weapon.dex_plus * WEAPON_DEX_WEIGHT
evaluation += weapon.agi_plus * WEAPON_AGI_WEIGHT
evaluation += weapon.int_plus * WEAPON_INT_WEIGHT
if evaluation > 0
zero_flag = false
end
if @actor.equippable?(weapon) &&
$game_party.weapon_number(weapon.id) > 0 && evaluation > max_eval
max_eval = evaluation
optimal = weapon.id
end
end
if zero_flag
optimal = 0
end
@actor.equip(0, optimal)
if $game_system.two_handed_weapons.include?(optimal)
@actor.equip(1, 0)
end
end
if slot >= 1
not_equipped = false
case slot
when 1
if $game_system.two_handed_weapons.include?(@actor.weapon_id)
return
end
if @actor.armor1_id == 0
not_equipped = true
else
object = $data_armors[@actor.armor1_id]
end
when 2
if @actor.armor2_id == 0
not_equipped = true
else
object = $data_armors[@actor.armor2_id]
end
when 3
if @actor.armor3_id == 0
not_equipped = true
else
object = $data_armors[@actor.armor3_id]
end
when 4
if NO_ACCESSORY_OPTIMIZATION
return
end
if @actor.armor4_id == 0
not_equipped = true
else
object = $data_armors[@actor.armor4_id]
end
end
optimal = object.id
if $game_system.cursed_armors.include?(optimal)
return
end
current = 0.00
if not_equipped = false
current += object.eva * ARMOR_EVA_WEIGHT
current += object.pdef * ARMOR_PDF_WEIGHT
current += object.mdef * ARMOR_MDF_WEIGHT
current += object.str_plus * ARMOR_STR_WEIGHT
current += object.dex_plus * ARMOR_DEX_WEIGHT
current += object.agi_plus * ARMOR_AGI_WEIGHT
current += object.int_plus * ARMOR_INT_WEIGHT
else
optimal = 0
end
max_eval = current
@actor.equip(slot, 0)
flag = false
zero_flag = true
for armor in $data_armors
if !flag
flag = true
next
end
if armor.kind != slot-1
next
end
evaluation = 0.00
evaluation += armor.eva * ARMOR_EVA_WEIGHT
evaluation += armor.pdef * ARMOR_PDF_WEIGHT
evaluation += armor.mdef * ARMOR_MDF_WEIGHT
evaluation += armor.str_plus * ARMOR_STR_WEIGHT
evaluation += armor.dex_plus * ARMOR_DEX_WEIGHT
evaluation += armor.agi_plus * ARMOR_AGI_WEIGHT
evaluation += armor.int_plus * ARMOR_INT_WEIGHT
if evaluation > 0
zero_flag = false
end
if @actor.equippable?(armor) &&
$game_party.armor_number(armor.id) > 0 && evaluation > max_eval
max_eval = evaluation
optimal = armor.id
end
end
if zero_flag
optimal = 0
end
@actor.equip(slot, optimal)
end
end
end