#===============================================================================
# **OECS Equipment Upgrade System v1.1
#-------------------------------------------------------------------------------
# This script allows you to have be able to upgrade equipment. giving it more
# power each upgrade.
#
# Put script above main, below OECS main
#===============================================================================
=begin
Instructions:
Set Options below
To call the upgrade shop, type this in the script section
$scene = Scene_EquipmentUpgradeShop.new
=end
#==============================================================================
# ** OECS::Upgrade
#------------------------------------------------------------------------------
# A module for OECS Equipment Upgrade System Options
#==============================================================================
module OECS
module Upgrade
# OPTIONS:
# Max upgrade level for equipments
MaxEqLevel = 7
# upgrade price ratio in %
UpgradePriceRatio = 10
# besides the upgrade price ratio, this is added to the item's price
# you may make upgradepriceratio to 0 to make a constant price for all.
ConstantPricePlus = 100
# multiply ratio by level, so that it would get more expensive each level
MultiplyRatioByLevel = true
# Growth of non-zero parameters of the equipment per plus in %
ParameterGrowthRatio = 100
# if an equipment parameter is not equal to 0 this is the minimum
# value it can increase at an upgrade
MinimumGrowth = 40
# Show addition in name i.e. Club+7
ShowAdditionInName = true
# terms
# when equipment is maxed
EqMaxed = 'level maxed'
# for those with <cannot_be_upgraded> tag
CantBeUpgraded = "can't be upgraded"
# at the top of the shop
UpgradeShopTerm = 'Upgrade Shop'
# At the requirements
RequirementTerm = 'Requires:'
# at the command window
WeaponTerm = 'Weapon'
ArmorTerm = 'Armor'
# confirmation question
UpgradeWeaponTerm = 'Upgrade Weapon?'
UpgradeArmorTerm = 'Upgrade Armor?'
# confirm choice
AgreeUpgrade = 'Upgrade'
DisagreeUpgrade = 'No'
=begin
EQUIPMENT TAGS:
Put these tags on the weapons/armors
<upgrade_requires: id, id, id >
id is the item id required for equipment to be upgraded.
you may put as many as you want, and you may also put duplicates.
<upgrade_price+: val>
val is added to the price of the upgrade, besides the calculation from the
options above.
<upgrade_price*: val>
val is multiplied by the equipment's level, then added to the upgrade price
<cant_be_upgraded>
for items that cannot be upgraded.
=end
#==============================================================================#
################################################################################
#==============================================================================#
end
end
module RPG
class Weapon
alias oecs_upgrade_name name # Need to alias before mixin.
end
class Armor
alias oecs_upgrade_name name
end
end
#============================================================================
# ** OECS::EquipInclude
#----------------------------------------------------------------------------
# a module for performing mix-ins in both equipment
#============================================================================
module OECS
module EquipInclude
#------------------------------------------------------------------------
# * Public Instance Variables
#------------------------------------------------------------------------
attr_accessor :upgrade_level
def upgrade_plus
text = self.note.scan(/\<upgrade\_price\+:\s*([0-9]+)\s*\>/)
text = text[0]
return 0 if text == nil return text[0].to_i
end
def upgrade_exp text = self.note.scan(/\<upgrade\_price\*:\s*([0-9]+)\s*\>/)
text = text[0]
return 0 if text == nil return text[0].to_i
end
if OECS::Upgrade::ShowAdditionInName
def name
if @upgrade_level == 0
return self.oecs_upgrade_name
else
temp_name = self.oecs_upgrade_name
temp_name += ' +' + @upgrade_level.to_s
return temp_name
end
end
end
def name_no_plus
return self.oecs_upgrade_name
end
def upgrade_requires
hash = {}
text = self.note.scan(/\<upgrade\_requires:\s*(.+)\s*\>/)
text = text[0]
return hash if text == nil
text = text[0]
text.split(/[\,\s]/).each do |num|
num = num.to_i
hash.keys.include?(num) ? hash[num] += 1 : hash[num] = 1
end
return hash
end
end
end
#==============================================================================
# ** Window_UpgradeConfirm
#------------------------------------------------------------------------------
# This window confirms if the player will upgrade the item.
#==============================================================================
class Window_UpgradeConfirm < Window_Selectable
#--------------------------------------------------------------------------
# * Public Instance Variables
#--------------------------------------------------------------------------
attr_accessor :item
#--------------------------------------------------------------------------
# * Object Initialization
#--------------------------------------------------------------------------
def initialize(x, y, item)
row_max = 2
super(x, y, 300, 304, 32)
@commands = [OECS::Upgrade::AgreeUpgrade, OECS::Upgrade::DisagreeUpgrade]
@item_max = 2
@column_max = 1
self.contents.clear
for i in 0...@item_max
draw_item(i)
end
@item = item
self.index = 0
if @item.is_a?(RPG::Weapon)
self.contents.draw_text(0, 50, width - 32, 24, OECS::Upgrade::UpgradeWeaponTerm, 0)
else
self.contents.draw_text(0, 50, width - 32, 24, OECS::Upgrade::UpgradeArmorTerm, 0)
end
draw_item_name(item, 0, 100)
end #--------------------------------------------------------------------------
# * Get rectangle for displaying items
# index : item number
#--------------------------------------------------------------------------
def item_rect(index)
rect = Rect.new(0, 0, 0, 0)
rect.width = (contents.width + @spacing) / @column_max - @spacing
rect.height = WLH
rect.x = index % @column_max * (rect.width + @spacing)
rect.y = index / @column_max * WLH + 160
return rect
end
#--------------------------------------------------------------------------
# * Draw Item
# index : item number
# enabled : enabled flag. When false, draw semi-transparently.
#--------------------------------------------------------------------------
def draw_item(index, enabled = true)
rect = item_rect(index)
rect.x += 4
rect.width -= 10
self.contents.clear_rect(rect)
self.contents.font.color = normal_color
self.contents.font.color.alpha = enabled ? 255 : 128
self.contents.draw_text(rect, @commands[index], 1)
end
alias oecs_upgrade_draw_item_name draw_item_name
def draw_item_name(item, x, y, enabled = true)
oecs_upgrade_draw_item_name(item, x, y, enabled)
rect = Rect.new(x + 24, y, 245, WLH)
self.contents.clear_rect(rect)
self.contents.draw_text(x + 24, y, 240, WLH, item.name) if item != nil
end
end
#==============================================================================
# ** Scene_EquipmentUpgradeShop
#------------------------------------------------------------------------------
# This class performs equipment upgrade shop screen processing.
#==============================================================================
class Scene_EquipmentUpgradeShop < Scene_Base #--------------------------------------------------------------------------
# * Start processing
#--------------------------------------------------------------------------
def start
super
create_menu_background
create_command_window
@help_window = Window_Help.new
@gold_window = Window_Gold.new(384, 56)
@dummy_window = Window_Base.new(0, 112, 544, 304)
@help_window.set_text(OECS::Upgrade::UpgradeShopTerm)
@weapon_window = Window_Upgradeable.new(0, 112, 300, 304, 'weapon')
@details_window = Window_UpgradeDetails.new
@details_window.visible = false
@weapon_window.active = false
@weapon_window.visible = false
@weapon_window.help_window = @details_window
@armor_window = Window_Upgradeable.new(0, 112, 300, 304, 'armor')
@armor_window.active = false
@armor_window.visible = false
@armor_window.help_window = @details_window
end
#--------------------------------------------------------------------------
# * Termination Processing
#--------------------------------------------------------------------------
def terminate
super
dispose_menu_background
@help_window.dispose
@gold_window.dispose
@details_window.dispose
@command_window.dispose
@dummy_window.dispose
@weapon_window.dispose
@armor_window.dispose
end
#--------------------------------------------------------------------------
# * Frame Update
#--------------------------------------------------------------------------
def update
super
update_menu_background
@help_window.update
@dummy_window.update
@gold_window.update
@weapon_window.update
@armor_window.update
@command_window.update
@details_window.update
if @command_window.active
update_command_window
elsif @weapon_window.active
update_weapon_window
elsif @armor_window.active
update_armor_window
elsif @confirm_upgrade_window != nil
update_confirm_upgrade
end
end
#--------------------------------------------------------------------------
# * Update Command Selection
#--------------------------------------------------------------------------
def update_command_window
if Input.trigger?(Input::B)
Sound.play_cancel
$scene = Scene_Map.new
elsif Input.trigger?(Input::C)
Sound.play_decision
case @command_window.index
when 0
@weapon_window.active = true
@weapon_window.visible = true
@details_window.visible = true
@dummy_window.visible = false
@command_window.active = false
when 1
@armor_window.active = true
@armor_window.visible = true
@details_window.visible = true
@dummy_window.visible = false
@command_window.active = false
when 2
Sound.play_cancel
$scene = Scene_Map.new
end
end
end
#--------------------------------------------------------------------------
# * Update Weapon Window
#--------------------------------------------------------------------------
def update_weapon_window
if Input.trigger?(Input::B)
Sound.play_cancel
@weapon_window.active = false
@weapon_window.visible = false
@details_window.visible = false
@dummy_window.visible = true
@command_window.active = true
elsif Input.trigger?(Input::C)
if @weapon_window.item == nil or not @weapon_window.enable?(@weapon_window.item)
Sound.play_buzzer
return
end
Sound.play_decision
@weapon_window.active = false
@weapon_window.visible = false
@confirm_upgrade_window = Window_UpgradeConfirm.new(0, 112, @weapon_window.item)
end
end
#--------------------------------------------------------------------------
# * Update Armor Window
#--------------------------------------------------------------------------
def update_armor_window
if Input.trigger?(Input::B)
Sound.play_cancel
@armor_window.active = false
@armor_window.visible = false
@details_window.visible = false
@dummy_window.visible = true
@command_window.active = true
elsif Input.trigger?(Input::C)
if @armor_window.item == nil or not @armor_window.enable?(@armor_window.item)
Sound.play_buzzer
return
end
Sound.play_decision
@armor_window.active = false
@armor_window.visible = false
@confirm_upgrade_window = Window_UpgradeConfirm.new(0, 112, @armor_window.item)
end
end
#--------------------------------------------------------------------------
# * Update Upgrade Decision
#--------------------------------------------------------------------------
def update_confirm_upgrade
@confirm_upgrade_window.update
if Input.trigger?(Input::B)
Sound.play_cancel
if @confirm_upgrade_window.item.is_a?(RPG::Weapon)
@weapon_window.active = true
@weapon_window.visible = true
else
@armor_window.active = true @armor_window.visible = true
end
@confirm_upgrade_window.dispose
@confirm_upgrade_window = nil
elsif Input.trigger?(Input::C)
if @confirm_upgrade_window.index == 0
upgrade_item(@confirm_upgrade_window.item)
if @confirm_upgrade_window.item.is_a?(RPG::Weapon)
@weapon_window.refresh
else
@armor_window.refresh
end
@details_window.refresh
end
if @confirm_upgrade_window.item.is_a?(RPG::Weapon)
@weapon_window.active = true
@weapon_window.visible = true
else
@armor_window.active = true @armor_window.visible = true
end
@confirm_upgrade_window.dispose
@confirm_upgrade_window = nil
end
end
#--------------------------------------------------------------------------
# * Process Item Upgrade
#--------------------------------------------------------------------------
def upgrade_item(item)
if item.is_a?(RPG::Weapon)
$game_party.lose_gold(@weapon_window.upgrade_price(@weapon_window.item))
else
$game_party.lose_gold(@armor_window.upgrade_price(@armor_window.item))
end
for id in item.upgrade_requires.keys
$game_party.lose_item($data_items[id], item.upgrade_requires[id])
end
item.upgrade_level += 1
upgrade_params(item)
@gold_window.refresh
Sound.play_shop
end
#--------------------------------------------------------------------------
# * Upgrade the item's parameters
#--------------------------------------------------------------------------
def upgrade_params(item)
params_item = item
unless item.mother_item_id == nil
params_item = item.is_a?(RPG::Weapon) ? $data_weapons[item.mother_item_id] : $data_armors[item.mother_item_id]
end
param = (params_item.atk.to_f*OECS::Upgrade::ParameterGrowthRatio/100).to_i
param = OECS::Upgrade::MinimumGrowth if param < OECS::Upgrade::MinimumGrowth and params_item.atk != 0
item.atk += param
param = (params_item.def.to_f*OECS::Upgrade::ParameterGrowthRatio/100).to_i
param = OECS::Upgrade::MinimumGrowth if param < OECS::Upgrade::MinimumGrowth and params_item.def != 0
item.def += param
param = (params_item.spi.to_f*OECS::Upgrade::ParameterGrowthRatio/100).to_i
param = OECS::Upgrade::MinimumGrowth if param < OECS::Upgrade::MinimumGrowth and params_item.spi != 0
item.spi += param
param = (params_item.agi.to_f*OECS::Upgrade::ParameterGrowthRatio/100).to_i
param = OECS::Upgrade::MinimumGrowth if param < OECS::Upgrade::MinimumGrowth and params_item.agi != 0
item.agi += param
end
#--------------------------------------------------------------------------
# * Create Command Window
#--------------------------------------------------------------------------
def create_command_window
s1 = OECS::Upgrade::WeaponTerm
s2 = OECS::Upgrade::ArmorTerm
s3 = Vocab::ShopCancel
@command_window = Window_Command.new(384, [s1, s2, s3], 3)
@command_window.y = 56
end
end
#==============================================================================
# ** Window_Upgradeable
#------------------------------------------------------------------------------
# This window displays a list of inventory items depending on the type
#==============================================================================
class Window_Upgradeable < Window_Item
#--------------------------------------------------------------------------
# * Object Initialization
# x : window x-coordinate
# y : window y-coordinate
# width : window width
# height : window height
# type : item type (weapon or armor)
#--------------------------------------------------------------------------
def initialize(x, y, width, height, type)
@type = type
super(x, y, width, height)
@column_max = 1
refresh
end
#--------------------------------------------------------------------------
# * Draw Item
# index : item number
#--------------------------------------------------------------------------
def draw_item(index)
rect = item_rect(index)
self.contents.clear_rect(rect)
item = @data[index]
if item != nil
number = $game_party.item_number(item)
enabled = enable?(item)
rect.width -= 4
draw_item_name(item, rect.x, rect.y, enabled)
end
end
#--------------------------------------------------------------------------
# * Whether or not to display in enabled state
# item : item
#--------------------------------------------------------------------------
def enable?(item)
return false if item.note.include?("<cant_be_upgraded>")
return false if upgrade_price(item) > $game_party.gold
return false if item.upgrade_level >= OECS::Upgrade::MaxEqLevel
return evaluate_item_requirements(item)
end
def evaluate_item_requirements(item)
for id in item.upgrade_requires.keys
next if id == 0
unless $game_party.items.include?($data_items[id]) and $game_party.item_number($data_items[id]) >= item.upgrade_requires[id]
return false
end
end
return true
end
#--------------------------------------------------------------------------
# * Return the price of the upgrade of the item
#--------------------------------------------------------------------------
def upgrade_price(item)
price = item.price.to_f * (OECS::Upgrade::UpgradePriceRatio.to_f/100)
price *= (item.upgrade_level + 1) if OECS::Upgrade::MultiplyRatioByLevel
price += OECS::Upgrade::ConstantPricePlus
price += item.upgrade_plus
price += item.upgrade_exp*(item.upgrade_level + 1)
price = price.to_i
return price
end
alias oecs_upgrade_draw_item_name draw_item_name
def draw_item_name(item, x, y, enabled = true)
oecs_upgrade_draw_item_name(item, x, y, enabled)
rect = Rect.new(x + 24, y, 240, WLH)
self.contents.clear_rect(rect)
self.contents.draw_text(x + 24, y, 240, WLH, item.name) if item != nil
end
#--------------------------------------------------------------------------
# * Refresh
#--------------------------------------------------------------------------
def refresh
@data = []
for item in $game_party.items
next unless include?(item)
if @type == 'weapon'
next unless item.is_a?(RPG::Weapon)
else
next unless item.is_a?(RPG::Armor)
end
@data.push(item)
end
@data.push(nil) if include?(nil)
@item_max = @data.size
create_contents for i in 0...@item_max
draw_item(i)
end
end
def update_help
return if self.item == nil or @help_window == nil
@help_window.set_data(self.item, upgrade_price(self.item))
end
end
class Window_UpgradeDetails < Window_Base
def initialize
super(300, 112, 244, 304) end
def set_data(item, price, refresh = false)
return if item == @item unless refresh
@item = item
@price = price
self.contents.clear
draw_item_name(item, 0, 0)
if item.note.include?("<cant_be_upgraded>")
self.contents.draw_text(0, WLH, 212, WLH, OECS::Upgrade::CantBeUpgraded, 1)
return
elsif item.upgrade_level < OECS::Upgrade::MaxEqLevel
self.contents.draw_text(0, WLH, 212, WLH, '+ ' + item.upgrade_level.to_s + ' ', 2)
else
self.contents.draw_text(0, WLH, 212, WLH, OECS::Upgrade::EqMaxed, 1)
return
end
self.contents.draw_text(0, WLH*2, 212, WLH, OECS::Upgrade::RequirementTerm)
draw_currency_value(price, 4, WLH*3, 204)
item.upgrade_requires.keys.each_with_index do |id, index|
draw_item_name($data_items[id], 0, WLH*(index + 4))
end
end
def refresh
set_data(@item, @price, true)
end
def draw_item_name(item, x, y, enabled = true)
if item != nil
draw_icon(item.icon_index, x, y, enabled)
self.contents.font.color = normal_color
self.contents.font.color.alpha = enabled ? 255 : 128
if item.is_a?(RPG::Item)
self.contents.draw_text(x + 24, y, 180, WLH, item.name)
else
self.contents.draw_text(x + 24, y, 180, WLH, item.name_no_plus)
end
end
end
def draw_currency_value(value, x, y, width)
cx = contents.text_size(value.to_s).width
self.contents.font.color = normal_color
self.contents.draw_text(x, y, width, WLH, value, 0)
self.contents.font.color = system_color
self.contents.draw_text(x+cx+2, y, width, WLH, Vocab::gold, 0)
end
end
#==============================================================================
# ** Scene_Title
#------------------------------------------------------------------------------
# This class performs the title screen processing.
#==============================================================================
class Scene_Title
#--------------------------------------------------------------------------
# * Alias List
#--------------------------------------------------------------------------
alias oz_oecs_equpgrade_initialize_oecs initialize_oecs
#--------------------------------------------------------------------------
# * Initialize all nil upgrade levels to 0
#--------------------------------------------------------------------------
def initialize_oecs
oz_oecs_equpgrade_initialize_oecs
for weapon in $data_weapons
next if weapon == nil
weapon.upgrade_level = 0 if weapon.upgrade_level == nil
end
for armor in $data_armors
next if armor == nil
armor.upgrade_level = 0 if armor.upgrade_level == nil
end
end
end