Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #===============================================================================
- #===============================================================================
- # - Upgradable Equipment 0.0 -
- # - Eshra & Emmanuel Derose -
- #===============================================================================
- #===============================================================================
- # -~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-
- # Version 0.0: Release Date August 28, 2012
- # Updates:
- # 2012 Aug 28 - Added notetag support to limit the amount of upgrades that can
- # be used on an item. <!upgradable9> limits the item to no more
- # than nine upgrades.
- #
- # -----------------------------------------------------------------------------
- # Bug Fixes:
- # -----------------------------------------------------------------------------
- # 2012 Aug 28 - Added a nil check to fix a crash when selecting a blank item.
- # 2012 Aug 28 - Fixed a NameError. Updated a constant name which I had
- # forgotten to change after moving the constant to a new module.
- # -~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-
- # -~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~ Setup -~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~
- # -~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-
- # To install this script, copy and paste it under the materials section and
- # above main. This script requires the following bit of code to work:
- #
- # $imported = {} unless $imported
- # $imported["Numeric Form Regex"] = true
- # module NumericForm
- # Regex = /\A(?:-|)\d+(?:\.|)(?:\d+|)\Z/
- # end
- #
- # This is because I don't want to include it in every script I write that needs
- # it so just copy and paste that module and the imported hash into a this
- # section above everything else or into a separate slot in the editor.
- #
- # -~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-
- # -~-~-~-~-~-~-~-~-~-~-~-~-~-~-~- How to Use -~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~
- # -~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-
- # You can now add notetags to your items which will allow them to be used as
- # upgraders for other items. Add this notetag:
- # <!Upgradable>
- # To each item that you want to be able to upgrade. Currently only equipment can
- # be upgraded.
- # You can also add a number after the word upgradable to limit the amount of
- # upgrades that can be used on that item. For example:
- # <!Upgradable3> limits the amount of upgrades that can be used on an item with
- # this tag to 3.
- # After you've done that you should create an item that can be used as an
- # upgrader. The upgrader notetags should look like this (or just see the regex):
- #
- # <Mod STAT=5 +90>
- # or
- # <Mod STAT=8 +90%>
- # or
- # <Mod STAT=all +90%>
- # or
- # <Mod STATE=5 15%>
- #
- # The numbers can be replaced by other numbers. The + sign can also be
- # a - sign (a hyphen). The percent signs are required except in the first case.
- # When there is no percenet sign present when using the keyword STAT, the
- # number following the + or - is considered a raw value (it is required when
- # using the keyword STATE). Capitalizaton does not matter.
- #
- # STAT=number means the stat with an id equal to 'number' will be modified.
- # The default id numbers for stats in Ace are:
- #
- # Max HP: 0 Max MP: 1 Attack Power: 2 Defense: 3 Magic Power: 4 Magic Defense: 5
- # Agility: 6 Luck: 7
- #
- # The notetag <Mod STAT=5 +143> means
- # This item will increase the magic defense stat of the equipment it is used to
- # upgrade by 143.
- # If there was a percent sign after the 143:
- # <Mod STAT=5 +143%>
- # The magic defense stat for the equipment it was used on would be increased by
- # 143% of its original value. If the + sign was changed to a minus the increases
- # would become decreases instead. When multiple upgraders with percentage
- # modifications are used to upgrade an equipment piece at the same time, the
- # percentages modify the original value in ascending order. The change from each
- # modification is applied in this order, then the next modification is applied.
- #
- # The keyword all can be used after STAT= inplace of a number
- # <Mod STAT=all +15%>
- # This notetag would make all of the stats of the equipment that is upgraded
- # with this item to be increased by 15%.
- #
- # States can also be added to items:
- # <Mod STATE=2 45%>
- # When an upgrader with this notetag is used to upgrade a piece of equipment,
- # that equipment will gain a 45% chance of inflicting state 2.
- #
- # ---------------------------- Calling the Script ------------------------------
- # The Upgrade Window can be brought up from an event with this script call:
- #
- # SceneManager.call(Scene_UpgradableItem)
- #
- # ------------------------------- Failure Rate --------------------------------
- # The chance that an upgrade will be successful can be modified in
- # EquipUpgrades::Player::DefaultFailRate below. Or it can be modified during
- # runtime by accessing $game_player.fail_rate_for_upgrades
- #
- # By default, increasing the value by 1 increases the failure rate by 1%, this
- # will change though if EquipUpgrades::Max::BaseRVal is modified.
- # The failure rate at the start of a new game will be equal to
- # EquipUpgrades::Player::DefaultFailRate/ EquipUpgrades::Max::BaseRVal
- #
- $imported = {} if $imported.nil?
- raise "Upgradable Equipment requires Tsuki_CustomDataManager" unless $imported["Tsuki_CustomDataManager"]
- raise "Upgradable Equipment requires module Numeric Form" unless $imported["Numeric Form Regex"]
- $imported["Upgradable Equipment 0986"] = true
- #==============================================================================
- # Settings, these can be modified to customize the script a bit.
- #==============================================================================
- #
- # Window orientation, not implemented currently
- #
- module UpgradeOrientation
- module Size
- WidthValue = 0.6
- end
- end # End - UpgradeOrientation
- module EquipUpgrades
- module Regexp # The regular expressions used to parse upgraders, etc.
- State = /<Mod STATE=(\d+) (\d+)%>/i
- StatPercent = /<Mod STAT=(\d+|all) (\+|\-)(\d+)%>/i
- StatRaw = /<Mod STAT=(\d+|all) (\+|\-)(\d+)>/i
- Upgradable = /<!Upgradable(\d+|)>/i
- end # End - Regexp
- module Player
- DefaultFailRate = 0 # When determining success, a number is generated between
- # 0 and 100. if the generated number + 1 is less than
- # fail_rate then the upgrade is unsuccessful.
- # By default increasing the DefaultFailRate to 1 gives
- # a 1% fail rate, 2=2%, etc.
- SuccessAnimation = 33
- FailAnimation = 96
- FailureMod = 0.9 # modifes the effect of failing to upgrade by the
- # specified rate
- DisplayAnimation = true # Set this to false to turn off the animations
- end # End - Player
- module Max
- StatId = 8 # The number of stats the original value in ace is 8
- BaseRVal = 100 # The highest random number generated will be this value
- # minus 1. the formula for calculating upgrade success is:
- # random_val < BaseRVal - DefaultFailRate ? success : fail
- IconWidth = 24
- end # End - Max
- module EquipPhrase
- Equips = "Equipment"
- Upgrader = "Upgrades"
- end # End - EquipPhrase
- end # End - EquipUpgrades
- #==============================================================================
- # End of Settings, don't modify below here unless you know what you're doing.
- #==============================================================================
- #==============================================================================
- # ** Window_Selectable
- #==============================================================================
- class Window_Selectable < Window_Base
- def get_curr_index
- @index && @index >= 0 ? @index : 0
- end
- end # End - Window_Selectable
- #==============================================================================
- # ** Game_Player
- # # new attributes are added to the game player to control upgrade failure
- # # rate.
- #==============================================================================
- class Game_Player < Game_Character
- attr_accessor :fail_rate_for_upgrades
- attr_accessor :fail_mod_for_upgrades
- alias game_pl_init_method_uni_fail_rate_upgrades_1842693 initialize
- def initialize
- game_pl_init_method_uni_fail_rate_upgrades_1842693
- @fail_rate_for_upgrades = EquipUpgrades::Player::DefaultFailRate
- @fail_mod_for_upgrades = EquipUpgrades::Player::FailureMod
- end
- end # End - Game_Player
- #==============================================================================
- # ** Window_UpgradeItemList
- #------------------------------------------------------------------------------
- # This window displays a upgradable items and items that can be used as
- # upgraders.
- #==============================================================================
- class Window_UpgradeItemList < Window_ItemList
- attr_accessor :data
- attr_accessor :only_enable_upgradables
- #
- # Get Activation State of Selection Item
- #
- def current_item_enabled?
- enable?(@data[index])
- end
- #
- # Display in Enabled State?
- #
- def enable?(item)
- only_enable_upgradables ? item && item.is_upgradable : item && item.upgrade_mods
- end
- end # End- Window_UpgradeItemList
- #==============================================================================
- # ** Window_UpgradeItemCategory
- #------------------------------------------------------------------------------
- # The category window for the upgradable items scene
- #==============================================================================
- class Window_UpgradeItemCategory < Window_ItemCategory
- def window_width
- Graphics.width * UpgradeOrientation::Size::WidthValue
- end
- def col_max
- return 4
- end
- #
- # The categories of items that are displayed in the upgradable scene
- #
- def make_command_list
- add_command(Vocab::weapon, :weapon)
- add_command(Vocab::armor, :armor)
- add_command(Vocab::item, :item)
- add_command(Vocab::key_item, :key_item)
- end
- end # End - Window_UpgradeItemCategory
- #==============================================================================
- # ** Window_UpgradeItemCategory
- #------------------------------------------------------------------------------
- # The window which displays the icons for the items which are being used to do
- # the upgrade
- #==============================================================================
- class Window_DisplayUpgrades < Window_Base
- attr_accessor :content_icons
- def initialize(x,y,h)
- @window_width =(1-UpgradeOrientation::Size::WidthValue)*Graphics.width
- super(x,y,@window_width,h)
- @content_names, @content_icons = [], []
- end # End - initialize
- def set_item(item)
- contents.clear
- draw_text(0,0,@window_width-6,27,item.name)
- draw_icon(item.icon_index, 170,0,true)
- end # End - set_item
- def add_new_icon(id)
- @content_icons.push(id)
- draw_all_icons
- end # End - add_new_icon
- def draw_all_icons
- contents.clear
- index, x_pos = 0,0
- @content_icons.each{ |id|
- draw_icon(id, x_pos, line_height * index, true)
- index += 1
- if(index > 6)
- index = 0
- x_pos += EquipUpgrades::Max::IconWidth
- end # End - index > 6
- } # End - @content_icons.each
- end # End - draw_all_icons
- def clear_all
- contents.clear
- @content_names = []
- @content_icons = []
- end # End - clear_all
- end # End - Window_DisplayUpgrades
- class Window_UpgradeSelection < Window_HorzCommand
- #
- # Public Instance Variables
- #
- attr_reader :item_window
- #
- # Object Initialization
- #
- def initialize(x,y, upgrader)
- @type = upgrader
- @col_max = upgrader ? 3 : 2
- super(x, y)
- end # End - initialize
- #
- # Get Window Width
- #
- def window_width
- Graphics.width * (1-UpgradeOrientation::Size::WidthValue)
- end # End - window_width
- #
- # Get Digit Count
- #
- def col_max
- return @col_max
- end # End - col_max
- #
- # Create Command List
- #
- def make_command_list
- if !@type
- add_command(EquipUpgrades::EquipPhrase::Equips, :equip)
- add_command("Ok", :advance)
- else
- add_command(EquipUpgrades::EquipPhrase::Upgrader, :upgrades)
- add_command("Clear", :clear)
- add_command("Done", :done)
- end # End - if !@type
- end # End - make_command_list
- end # End - Window_UpgradeSelection
- #==============================================================================
- # ** DataManager
- #==============================================================================
- module DataManager
- #
- # * alias load_database
- #
- class <<self; alias load_db_upgrade_mods_82372934 load_database; end
- def self.load_database
- load_db_upgrade_mods_82372934
- load_ntags_upgrade_mods_82372933
- end
- #
- # load_ntags_upgrade_mods_82372933
- #
- def self.load_ntags_upgrade_mods_82372933
- groups = [$data_armors, $data_weapons, $data_items]
- for group in groups
- for obj in group
- next if obj.nil?
- obj.load_ntags_upgrade_mods
- end
- end
- end
- end # DataManager
- #==============================================================================
- # ** RPG::BaseItem
- #==============================================================================
- class RPG::BaseItem
- attr_accessor :max_upgrades # The max number of upgrades usable on this item
- attr_accessor :curr_upgrades # list of current upgrades on this item
- attr_accessor :upgrade_mods
- attr_accessor :is_upgradable
- attr_accessor :orig_name # Used when making deep copies and it's necessary
- # to know the name of the original item while still
- # being able to change the name of the new item.
- #
- # Parses notetags and stores corresponding data
- #
- def load_ntags_upgrade_mods
- self.note.split(/[\r\n]+/).each { |line|
- next unless line != nil# && $1 != nil
- case line
- when EquipUpgrades::Regexp::State
- add_state_upgrade_mods($1.to_i, $2.to_i)
- when EquipUpgrades::Regexp::StatPercent
- add_stat_mod(:percent, $1, $3.to_i, $2)
- when EquipUpgrades::Regexp::StatRaw
- add_stat_mod(:raw, $1, $3.to_i, $2)
- when EquipUpgrades::Regexp::Upgradable
- @is_upgradable = true
- if (val=$1.to_s) =~ NumericForm::Regex #init max upgrades if it was defined
- @max_upgrades = val.to_i
- @curr_upgrades = []
- end
- end
- }
- end # End - load_ntags_upgrade_mods
- #
- # store state modifiers
- #
- def add_state_upgrade_mods(id, val)
- init_upgrade_mods
- @upgrade_mods.store_state_mod(id, val * 0.01)
- end # End - add_state_upgrade_mods
- #
- # store base stat modifiers percentages mapped from :percent, raw values from
- # :raw
- #
- def add_stat_mod(sym, id, val, op)
- init_upgrade_mods
- val *= 0.01 if sym == :percent
- val = op.eql?("-") ? -val : val
- @upgrade_mods.store_stat_mod(sym, id, val)
- end
- #
- # initialize @upgrade_mods if it is nil
- #
- def init_upgrade_mods
- @upgrade_mods = Equipment_Upgrader.new unless @upgrade_mods
- end
- #
- # adds a new feature to the item
- #
- def add_new_feature_upg(feature)
- @features.push(feature)
- end
- end # End - RPG::BaseItem
- #==============================================================================
- # ** RPG::Weapon
- #------------------------------------------------------------------------------
- # A Method to create a deep copy is added
- #==============================================================================
- class RPG::Weapon < RPG::EquipItem
- #
- # * Deep Copy
- #
- def deep_copy_clone_2544
- wep = Marshal.load(Marshal.dump(self))
- wep.id = $data_weapons.size
- wep.orig_name = @orig_name ? @orig_name : (@orig_name = wep.name)
- wep.name = "Upgraded " + wep.orig_name + "(#{wep.id})"
- wep.description = wep.description + " (Upgraded)"
- $custom_weapons.push(wep)
- $data_weapons.push(wep) # temporarily in data_weapons for use with methods
- # such as gain_item
- wep
- end # End - deep_copy_clone_2544
- end # End - RPG::Weapon
- #==============================================================================
- # ** RPG::Armor
- #------------------------------------------------------------------------------
- # A Method to create a deep copy is added
- #==============================================================================
- class RPG::Armor < RPG::EquipItem
- #
- # * Deep Copy
- #
- def deep_copy_clone_2544
- arm = Marshal.load(Marshal.dump(self))
- arm.id = $data_weapons.size
- arm.orig_name = @orig_name ? @orig_name : (@orig_name = arm.name)
- arm.name = "Upgraded " + arm.name + "(#{arm.id})"
- arm.description = arm.description + " (Upgraded)"
- $custom_armors.push(arm)
- $data_armors.push(arm) # temporarily in data_armors for use with methods
- # such as gain_item
- arm
- end # End - deep_copy_clone_2544
- end # End - RPG::Armor
- #==============================================================================
- # ** Equipment_Upgrader
- #------------------------------------------------------------------------------
- # This class represents a new property for items to allow for certain items
- # to represent upgraders which can increase the stats of others.
- #==============================================================================
- class Equipment_Upgrader
- attr_accessor :states
- attr_accessor :stat_mods
- def initialize
- @states = {} # maps state ids to the chance of that state being inflicted
- @stat_mods = {} # A hash mapping stat Ids to the symbols :percent
- # and :raw these determine how much the effected stat is
- # changed.
- end
- # The percentage value is stored as a float between -1.00 and 1.00
- def store_stat_mod(sym, stat_id, val, preserve = false, mod = 1)
- @stat_mods[stat_id.to_i] = {} unless @stat_mods[stat_id.to_i]
- mod_all_stats(sym, stat_id, val, preserve, mod) unless stat_id.to_s =~ NumericForm::Regex
- @stat_mods[stat_id.to_i][sym] = preserve ? @stat_mods[stat_id][sym] + val : val
- end
- #
- # stores data which will be added to item.features
- #
- def store_state_mod(state_id, val, preserve = false, mod = 1)
- @states[state_id] = preserve ? @states[state_id] + val : val
- end
- #
- # stores data which will modify the stats stored in item.params
- #
- def mod_all_stats(sym, stat_id, val, preserve = false, mod = 1)
- (0..7).each{ |id| store_stat_mod(sym, id, val, preserve, mod)}
- end
- #
- # Percentage value modifications to stats
- #
- def get_stat_mod_percent(stat_id)
- @stat_mods[stat_id][:percent]
- end
- #
- # Non percentage value modifications to stats
- #
- def get_stat_mod_raw(stat_id)
- @stat_mods[stat_id][:raw]
- end
- #
- # The percent chance of happening this upgrader gives to the state with
- # id = param: state_id
- #
- def get_state_mod(state_id)
- @states[state_id]
- end
- end # End - Equip_Upgrader
- #==============================================================================
- # ** Scene_UpgradableItem
- #------------------------------------------------------------------------------
- # This class allows items to be upgraded by other items
- #==============================================================================
- class Scene_UpgradableItem < Scene_ItemBase
- #
- # * Start Processing
- #
- def start
- super
- create_help_window
- #create_help_text_upgradable
- create_equip_select_window
- create_display_window_upgradable
- create_upgrade_select_window
- create_category_window(2*Graphics.width/5,@help_window.height,0,0)
- create_item_window(2*Graphics.width/5)
- create_upgrade_list
- @equipment_to_upgrade = nil
- @upgraders = [] # list of items to be used as upgraders for the equipment
- @item_is_upgrader = false# Determines which list to show items in once clicked
- end # End - start
- def create_display_window_upgradable
- w = Graphics.width * (1-UpgradeOrientation::Size::WidthValue)
- h = 48
- y = @upgrade_equipment_window.height+@help_window.height
- @display_window = Window_DisplayUpgrades.new(0,y,h)
- @display_window.viewport = @viewport
- end # End - create_display_window_upgradable
- #
- # * Create Equip Select Window
- # The base window with options to select on equipment or to just click ok
- #
- def create_equip_select_window
- @upgrade_equipment_window = Window_UpgradeSelection.new(0,@help_window.height, false)
- @upgrade_equipment_window.viewport = @viewport
- @upgrade_equipment_window.deactivate
- @upgrade_equipment_window.unselect
- @upgrade_equipment_window.set_handler(:ok, method(:on_upgrade_equip_ok))
- @upgrade_equipment_window.set_handler(:cancel, method(:on_equip_select_cancel))
- @upgrade_equipment_window.set_handler(:advance, method(:on_equip_select_advance))
- end # End - create_equip_select_window
- #
- # * Upgrade Selection Window
- #
- def create_upgrade_select_window
- y = @help_window.height + @upgrade_equipment_window.height + @display_window.height
- @upgrades_selection_window = Window_UpgradeSelection.new(0,y, true)
- @upgrades_selection_window.viewport = @viewport
- @upgrades_selection_window.set_handler(:upgrades, method(:on_choose_upgrades))
- @upgrades_selection_window.set_handler(:clear, method(:on_clear_upgrades))
- @upgrades_selection_window.set_handler(:done, method(:on_done))
- @upgrades_selection_window.set_handler(:cancel, method(:on_upgrade_cancel))
- @upgrades_selection_window.deactivate
- @upgrades_selection_window.unselect
- end # End - create_upgrade_select_window
- #
- # * Upgrade List
- #
- def create_upgrade_list
- th1, th2 = @help_window.height, @upgrade_equipment_window.height
- th3, th4 = @display_window.height, @upgrades_selection_window.height
- y = th1 + th2 + th3 + th4
- h = Graphics.height - y
- @upgrades_display_window = Window_DisplayUpgrades.new(0,y,h)
- @upgrades_display_window.viewport = @viewport
- end # End - create_upgrade_list
- #
- # * Create Category Window
- #
- def create_category_window(x,y,w,h)
- @category_window = Window_UpgradeItemCategory.new
- @category_window.viewport = @viewport
- @category_window.help_window = @help_window
- @category_window.y = y
- @category_window.x = Graphics.width * (1-UpgradeOrientation::Size::WidthValue)
- @category_window.set_handler(:ok, method(:on_category_ok))
- @category_window.set_handler(:cancel, method(:on_category_cancel))
- end # End - create_category_window
- #
- # * Create Item Window
- #
- def create_item_window(x)
- wy = @category_window.y + @category_window.height
- wh = Graphics.height - wy
- @item_window = Window_UpgradeItemList.new(x, wy, 3*Graphics.width/5, wh)
- @item_window.viewport = @viewport
- @item_window.help_window = @help_window
- @item_window.set_handler(:ok, method(:on_item_ok))
- @item_window.set_handler(:cancel, method(:on_item_cancel))
- @item_window.only_enable_upgradables = true
- @category_window.item_window = @item_window
- end # End - create_item_window
- #
- # * Category [OK]
- #
- def on_category_ok
- @item_window.activate
- @item_window.select_last
- end # End - on_category_ok
- #
- # * Category [Cancel]
- #
- def on_category_cancel
- if !@item_is_upgrader
- @upgrade_equipment_window.activate
- @upgrade_equipment_window.select(@upgrade_equipment_window.get_curr_index)
- @category_window.deactivate
- else
- turn_on_upgrades_selection
- @category_window.deactivate
- end
- end # End - on_category_cancel
- #
- # * Item [OK]
- #
- def on_item_ok
- if !@item_is_upgrader
- $game_party.gain_item(@equipment_to_upgrade, 1) unless !@equipment_to_upgrade
- @equipment_to_upgrade = item
- @display_window.set_item(@equipment_to_upgrade)
- else
- if !check_can_upgrade # already max amount of upgrades in list
- turn_on_upgrades_selection
- @item_window.deactivate
- return
- end
- @upgraders.push(item)
- @upgrades_display_window.add_new_icon(item.icon_index)
- @item_window.refresh
- end # End - !@item_is_upgrader
- $game_party.gain_item(item, -1)
- @item_window.data.delete(item) if !$game_party.has_item?(item)
- @item_window.refresh
- turn_on_upgrades_selection
- @item_window.deactivate
- end # End - on_item_ok
- #
- # * Item [Cancel]
- #
- def on_item_cancel
- @item_window.unselect
- @category_window.activate
- end # End - on_item_cancel
- #
- # Handler method which allows items to be selected as upgraders
- #
- def on_choose_upgrades
- @item_is_upgrader = true
- @item_window.only_enable_upgradables = false
- @upgrades_selection_window.deactivate
- @category_window.activate
- @category_window.select(@category_window.get_curr_index)
- end # End - on_choose_upgrades
- #
- # Handler method which clears all selected upgrades
- #
- def on_clear_upgrades
- empty_upgrades
- turn_on_upgrades_selection
- end # End - on_clear_upgrades
- #
- # Common code used when returning items to player after clearing the
- # upgrade list
- #
- def empty_upgrades
- @upgraders.each{ |item|
- $game_party.gain_item(item, 1)
- }
- @upgraders = []
- @upgrades_display_window.clear_all
- @item_window.refresh
- end # End - empty_upgrades
- #
- # Handler method which allows the equipment to be upgraded
- #
- def on_done
- perform_upgrade
- end # End - on_done
- #
- # Handler method called when upgrade menu is unselected
- #
- def on_upgrade_cancel
- @item_is_upgrader = false
- @item_window.only_enable_upgradables = true
- @upgrades_selection_window.deactivate
- @upgrades_selection_window.unselect
- @category_window.activate
- @category_window.select(@category_window.get_curr_index)
- end # End - on_upgrade_cancel
- #
- # Allows equipment selection
- #
- def on_upgrade_equip_ok
- @upgrade_equipment_window.deactivate
- @category_window.activate
- @category_window.select(@category_window.get_curr_index)
- end # End - on_upgrade_equip_ok
- #
- # Allows advancement to upgrade selection without having to click a new equip
- #
- def on_equip_select_advance
- return unless @equipment_to_upgrade
- @upgrade_equipment_window.deactivate
- turn_on_upgrades_selection
- end # End - on_equip_select_advance
- #
- # About to exit the scene
- #
- def on_equip_select_cancel
- empty_upgrades
- $game_party.gain_item(@equipment_to_upgrade, 1)
- SceneManager.return
- end # End - on_equip_select_cancel
- #
- # Common code used when activating the upgrade selection menu
- #
- def turn_on_upgrades_selection
- @item_window.only_enable_upgradables = false
- @item_window.only_enable_upgradables = @item_is_upgrader = true
- @upgrades_selection_window.activate
- @upgrades_selection_window.select(@upgrades_selection_window.get_curr_index)
- end # End - turn_on_upgrades_selection
- #
- # * Check to see if the current item is at its upgrade limit before adding
- # a new upgrader to the list
- #
- def check_can_upgrade
- return true if !@equipment_to_upgrade.max_upgrades
- max = @equipment_to_upgrade.max_upgrades
- curr_size = @equipment_to_upgrade.curr_upgrades.size
- curr_size + @upgrades_display_window.content_icons.size < max
- end
- #
- # * Perform the Upgrade
- # Change the stats on the item that is being upgraded (or downgraded)
- #
- def perform_upgrade
- # Check if the current upgrade is valid, if not then return
- if @upgraders[0] == nil || !@equipment_to_upgrade.is_a?(RPG::EquipItem)
- turn_on_upgrades_selection
- return
- end # End if
- # Make a deep copy
- @equipment_to_upgrade = @equipment_to_upgrade.deep_copy_clone_2544
- r_val = rand(EquipUpgrades::Max::BaseRVal)
- failed = 1+r_val <= $game_player.fail_rate_for_upgrades
- modify_stats(failed)
- add_new_features(13) unless failed# 13 is the default code for state features
- set_player_animation(failed)
- $game_party.gain_item(@equipment_to_upgrade, 1)
- SceneManager.return
- end # End - perform_upgrade
- #
- # * Set Player Animation
- #
- def set_player_animation(fail)
- return unless EquipUpgrades::Player::DisplayAnimation
- $game_player.animation_id = EquipUpgrades::Player::SuccessAnimation unless fail
- $game_player.animation_id = EquipUpgrades::Player::FailAnimation if fail
- end # End - set_player_animation
- #
- # * Add New Features
- # Creates new features to add to item.features
- #
- def add_new_features(code)
- @upgraders.each{ |item|
- states = item.upgrade_mods.states
- states.keys.each{|key|
- feature = RPG::BaseItem::Feature.new(code, key, states[key])
- @equipment_to_upgrade.add_new_feature_upg(feature)
- }
- }
- end # End - add_new_features
- #
- # * Modify Stats
- # percentages are applied to stats starting with the smallest percentage
- # increasing to the largest. Percentage bonuses are applied before raw bonuses
- #
- def modify_stats(failed = false)
- percents = {} # maps stat ids to an array of percentages
- raws = {} # maps stat ids to an array of values
- # Goes through all the items and condenses all the upgrades into above
- # two hashes
- @upgraders.each{ |item|
- @equipment_to_upgrade.curr_upgrades.push(item) #add each 1 to curr upgs list
- stats = item.upgrade_mods.stat_mods
- stats.keys.each{ |key|
- if stats[key]
- percents[key] = [] if !percents[key]
- raws[key] = [] if !raws[key]
- percents[key].push(stats[key][:percent]) unless !stats[key][:percent]
- raws[key].push(stats[key][:raw]) unless !stats[key][:raw]
- end # End - if stats[key]
- }
- } # End - @upgraders.each
- (0...EquipUpgrades::Max::StatId).each{|id|
- if percents[id] # Modify stats by multiplying percentages
- orig_val = @equipment_to_upgrade.params[id]
- percents[id].sort!.each{ |val|
- mod = upgrade_failed?(failed, orig_val * val) # handle failure case
- @equipment_to_upgrade.params[id] = mod + orig_val
- }
- end # End - if percents[id]
- if raws[id] # Modify stats by adding raw values
- raws[id].each { |val|
- val = upgrade_failed?(failed, val)
- @equipment_to_upgrade.params[id]+= val # handle failure case
- }
- end # End - if raws[id]
- } # End - (0...EquipUpgrades::Max::StatId).each
- end # End - modify_stats
- #
- # * Upgrade Failed
- # Calculate the appropriate value to add onto the stat if the upgrade failed
- #
- def upgrade_failed?(did_fail, val)
- mod = $game_player.fail_mod_for_upgrades
- did_fail ? (val > 0 ? val*-mod : val * mod) : val
- end # End - upgrade_failed?
- end # End - Scene_UpgradableItem
- #==============================================================================
- # -------------------------------End of File-----------------------------------
- #==============================================================================
Advertisement
Add Comment
Please, Sign In to add comment