#-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~ # Upgradable Equipment # Author: Eshra # Requested By: Chigoo # First Version: 28 Aug. 2012 # Compatibility: RPG Maker VX Ace # Dependencies: # 1. Tsuki_CustomDataManager # 2. Numeric Form Regex # Recommended (These help to fix bugs among other things): # 3. Custom DM Array Sizes Snippet # 4. Custom DB and Party Inventory Cleaner #-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~ # # -~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~- # * 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||={})["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 # section above everything else or into a separate slot in the editor. # # You will also need to get the other dependencies listed in the header. You # can find them at: http://rascripts.wordpress.com/2012/11/07/upgradable-equipment/ # # -~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~- # - How to Use - # -~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~- # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - # Specifying Equipment as Upgradable: # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - # Use the notetag: # # # # to mark a piece of armor or a weapon as upgradable. # You can also specify how many times the equipment can be upgraded, for example: # # # # means the equipment can be upgraded twice. # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - # Making an Upgrader # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - # Upgraders are items that can be used to modify the stats of equipment that is # upgradable. # # Use any of the following notetags to do this, the first INTEGER should # correspond to the stat you want to modify, the second should be the value that # it will be modified by. # # These are the default stats and their associated INTEGERs: # # Max HP: 0 # Max MP: 1 # Attack Power: 2 # Defense: 3 # Magic Power: 4 # Magic Defense: 5 # Agility: 6 # Luck: 7 # # Notetags: # # # # # # # ** The '+' signs can be replaced with '-' signs, don't forget the '%' signs # where they are required ** # # The first on the list: # # # # will allow you to modify the stat corresponding to the first integer by the # value of the second integer. # For example: # # # # Means the upgrader will increase the magic defense stat of the upgraded item # by 5. # # The second note tag: # # # # Allows a specific stat to be modified by the specified percentage: # # # # Will increase the HP stat by 10 percent. # # The third notetag: # # # # Will modify all stats by the specified percent: # # # # will cause all stats to be decreased by 5 percent on the upgraded equipment. # # The Fourth notetag: # # # # Will cause the upgraded equipment to have a chance of inflicting the state # with an id equal to the first INTEGER, 'the second INTEGER' pecent of the time: # # # # Will cause the upgraded equipment to have a 10 percent chance to inflict the # death state. # Note, the number specified as the first INTEGER is simply the id of the state # as it is listed in the database. # # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - # Restricting Upgrader Usage # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - # # You can restrict which upgraders can be used on which equipment by giving the # upgraders and the upgradable equipment types. # If an upgrader has a type, it can only upgrade upgradable equipment that # shares a type with it. # More than one type can be specified per upgrader and/or upgradable equipment # piece. # # When sepcifying the upgrader type for an upgrader, use the notetag: # # # # ** ANYTHING should be the string representing the upgraders type ** # For example: # # # # would specify an upgrader that could only be used on upgradable equipment that # had a shield type spcified. # # When specifying the upgradable type for a piece of upgradable equipment, use # the notetag: # # # #** ANYTHING should be the string representing the upg equip type ** # For example: # # # # would mean that the equipment item could only upgraded by upgraders that were # marked with the notetag. # # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - # Calling the Script # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - # # The Upgrade Window can be called from an event with this script call: # # ra_upg # # If you want to restrict which upgraders can be used during the upgrading scene # use the script call: # # ra_upg(ARRAY) # # replace 'ARRAY' with an array of strings of the specific upgrader types that # you want to use during that scene. # # For example if you have 2 items in your database, one is marked with the notetag # and the other one is marked with the notetag # # and you only wanted to be able to use the "shield" upgraders during the upgrade # scene, you would use the script call: # # ra_upg(["Shield"]) # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - # Equipment Suffixes # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - # # Upgraders can be specified to add sufixes to the names of the equipments they # are upgrading. # Use the notetag: # # # # ** 'ANYTHING' should be replaced with the string you want to use as a suffix. # To mark the upgrader with a suffix to add onto the equipment it upgrades. # For example, if an upgrader was marked with the notetag: # # # # if it was then used on an upgradable shield named, "Wooded Shield", the # shield's name would be changed to "Wooden Shield +20" after it was upgraded. # # There are several constants that can also be set to modify how many suffixes # are displayed on a piece of equipment, etc.: # # Set Only_Show_Most_Recent_Suffix to true if you only want to show 1 suffix # on the equipment. # # Set Show_Upgrade_Quantity_In_Name to true if you want to display how many # times the equipment was upgraded in the name. # # Change the maximum amount of suffixes that can be displayed in an items name # with Max_Suffixes # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - # 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 # #------------------------------------------------------------------------------ # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - # Update Log: # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - # 14 Dec 2012 - Neatened up the documentation. # 13 Dec 2012 - Major Bug Fixes: # # Can now add suffixes to upgraders to be shown on the upgraded # equipment. # Equipment no longer disappears when you save a game while # wearing upgraded equipment. # # Database is now properly managed (tmk) during runtime but custom # items are no longer deleted from the database because of the # difficulty associated with ensuring an items id is the same # as its location in the database when removing and readding items. # # Known Bug, Not fixing yet: # # If you have a saved game with upgraded equipment and you add a # new item to the database in the editor, then load that saved # game, some of the custom equipment may appear to "disappear" # or you may have different items in your inventory. # # 12 Dec 2012 - Can now use any symbol when specfying upgraders, not just A-Z # slight changes to note tags, can replace 'mod' with 'upg' # 10 Dec 2012 - Fixed Freeze during ugrade scene. # 9 Dec 2012 - Added support to restrict which upgraders can be used during the # upgrade scene. Use the script call: # ra_upg(ARRAY) # ** replace "ARRAY" with an array of strings ** # to only allow upgrader with a type specified in the array to be # used. # 20 Sept 2012 - Upgraders can now be specified to only be used with a specific # Equipment (use the tags and ) # 19 Sept 2012 - Fixed a problem where armor wasn't being upgraded properly. # Was referencing $data_weapons inside deep_copy_clone_2544 of # RPG::Armor, meant to reference $data_armors # 4 Sept 2012 - UpgradeOrientation::Size::WidthValue can now be used to adjust # the width of the windows in the upgrade scene # 3 Sept 2012 - Misnamed method update_data_base_upg_equips inside RPG::Armor, # was corrected. # 29 Aug 2012 - The name of the item has been changed to display how many # upgrades have been used on it. # - Upgraded equipment is now removed from the database also when it # is being removed the party's inventory # - Text now fits correctly in the equipment selection options window # # 28 Aug 2012 - Added notetag support to limit the amount of upgrades that can # be used on an item. limits the item to no more # than nine upgrades. # - Added a nil check to fix a crash that was happening when # selecting a blank item. # - Fixed a NameError. Updated a module constant name I had # forgotten to change after moving the constant to a new module. # - Fixed overlapping text inside the item list window #-------------------------------------------------------------------------------- $imported = {} if $imported.nil? raise "Upgradable Equipment requires Tsuki_CustomDataManager" unless $imported["Tsuki_CustomDataManager"] raise "Upgradable Equipment requires module NumericForm" unless $imported["Numeric Form Regex"] $imported["Ra Upgradable Equipment"] = true #============================================================================== # Settings, these can be modified to customize the script a bit. #============================================================================== # # * UpgradeOrientation # Window orientation # module UpgradeOrientation module Size WidthValue = 0.6 # Modifies the width of the windows in the upgrade scene end end # End - UpgradeOrientation # # * EquipUpgrades # Handles settings the user can modify for various effects. # module EquipUpgrades Only_Show_Most_Recent_Suffix = false # set to false to show all suffixes Show_Upgrade_Quantity_In_Name = false # true = show number of upgrades in name Max_Suffixes = 2 # maximum num of suffixes to be show in an equips name module Regexp # The regular expressions used to parse upgraders, etc. State = /<(?:Mod|upg) STATE(?:=| )(\d+) (\d+)%>/i StatPercent = /<(?:Mod|upg) STAT(?:=| )(\d+|all) (\+|\-)(\d+)%>/i StatRaw = /<(?:Mod|upg) STAT(?:=| )(\d+|all) (\+|\-)(\d+)>/i Upgradable = /<(?:!|)upgradable(?: |)(\d+|)>/i Upgrader = /<(?:!|)(?:upgrader) (.+)>/i # upgraders can be given an upgrader type Upgraded_By = /<(?:!|)(?:upgraded by) (.+)>/i # only effected be upgraders w/ this no. Upg_Suffix = /<\s*upg\s*suffix\s*(.+)>/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 # The width of the icons you're using end # End - Max module EquipPhrase Equips = "Equipment" Upgrader = "Upgrades" end # End - EquipPhrase module Symbols UpgAll = :upgrade_all AcpAll = :accept_all end 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 # # * Draw Item # def draw_item(index) item = @data[index] if item rect = item_rect(index) rect.width -= 4 draw_item_name(item, rect.x, rect.y, enable?(item), 90) draw_item_number(rect, item) end end # # * Draw Item Number # def draw_item_number(rect, item) draw_text(rect, sprintf("%2d", $game_party.item_number(item)), 2) 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_item_name(item,0,0,true,@window_width-40) 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 <= item_number(item) && item.is_upg_dupe end # End - delete_custom? end # End - Game_Party #============================================================================== # ** Scene_UpgradableItem #------------------------------------------------------------------------------ # Allows items to be upgraded by other items #============================================================================== class Scene_UpgradableItem < Scene_ItemBase # # * Start Processing # def start super create_help_window create_equip_select_window create_display_window_upgradable create_upgrade_select_window create_category_window((1-UpgradeOrientation::Size::WidthValue)*Graphics.width,@help_window.height,0,0) create_item_window((1-UpgradeOrientation::Size::WidthValue)*Graphics.width) create_upgrade_list @upg_equip = 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 # # Specify which upgraders can be used to upgrade items here # def specify_upgraders(upg_list) @ok_upgs = upg_list end # # * Window With Options Equipment or Ok # 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 ww = UpgradeOrientation::Size::WidthValue*Graphics.width @item_window = Window_UpgradeItemList.new(x, wy, ww, 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 equip_selected else upgrader_selected end # End - !@item_is_upgrader end # End - on_item_ok # # * Method called when an equipment is selected from on_item_ok # def equip_selected $game_party.gain_item(@upg_equip, 1) unless !@upg_equip @upg_equip = item @display_window.set_item(@upg_equip) $game_party.gain_item(item, -1) on_clear_upgrades @item_window.data.delete(item) if !$game_party.has_item?(item) @item_window.refresh turn_on_upgrades_selection @item_window.deactivate end # # * Method called when an upgrader is selected from on_item_ok # def upgrader_selected if !check_can_upgrade # already max amount of upgrades in list #turn_on_upgrades_selection @item_window.activate Sound.play_buzzer return end @upgraders.push(item) @upgrades_display_window.add_new_icon(item.icon_index) $game_party.gain_item(item, -1) @item_window.data.delete(item) if !$game_party.has_item?(item) @item_window.refresh @item_window.activate end # # * 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 @upgrade_equipment_window.activate unless @upg_equip @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(@upg_equip, 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 can be upgraded by the selected upgrader # def check_can_upgrade # print "item.upgrader_ids = #{item.upgrader_ids.inspect}\n" max = @upg_equip.max_upgrades size = @upg_equip.curr_upgrades.size # amount of upgrades on equip so far return false if size + @upgrades_display_window.content_icons.size >= max included_type = false @ok_upgs ||= [] #print "@ok_upgs = #{@ok_upgs.inspect}\n" #print "@upg_equip.upgraded_by = #{@upg_equip.upgraded_by}\n" #print "item.upgrader_ids = #{item.upgrader_ids}\n" item.upgrader_ids.each do |sym| return true if @ok_upgs.include?(sym.to_s) included_type = true if @upg_equip.upgraded_by[sym] end return false if !@ok_upgs.empty? return true if @upg_equip.upgraded_by[EquipUpgrades::Symbols::AcpAll] return true if item.upgrader_ids.include? EquipUpgrades::Symbols::UpgAll # print "item #{item.name}, upgrader_ids = #{item.upgrader_ids.inspect}\n" # item.upgrader_ids.each{|sym| return true if @upg_equip.upgraded_by[sym]} included_type end # # * Perform the Upgrade # Change the stats on the item that is being upgraded (or downgraded) def perform_upgrade return unless upgrade_is_valid? # Make sure the current upgrade is ok @upg_equip = @upg_equip.deep_copy_clone_2544 # deep copy modify_stats(failure = upgrade_successful?) # Modify stats based on success add_new_features(13) unless failure# 13 is the default code for states set_player_animation(failure) @upg_equip.upgrade_name # Change the name @upg_equip.is_upg_dupe = true $game_party.gain_item(@upg_equip, 1) Era::CleanCDB.clean print "$data_armors = #{$data_armors}\n" print "$data_weapons = #{$data_weapons}\n" print "$custom_armors = #{$custom_armors}\n" print "$custom_weapons = #{$custom_weapons}\n" SceneManager.return end # End - perform_upgrade # * Check if Upgrading is acceptable (i.e. no nil vals/ non-equip items, etc.) def upgrade_is_valid? # Check if the current upgrade is valid, if not then return return true unless (@upgraders.empty? || !@upg_equip.is_a?(RPG::EquipItem)) turn_on_upgrades_selection false end # End - upgrade_is_valid? # # * Was the Upgrade Successful? # def upgrade_successful? rand(EquipUpgrades::Max::BaseRVal) < $game_player.fail_rate_for_upgrades end # End - upgrade_successful? # # * 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]) @upg_equip.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| update_item_upgrades(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 = @upg_equip.params[id] percents[id].sort!.each{ |val| mod = upgrade_failed?(failed, orig_val * val) # handle failure case @upg_equip.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) @upg_equip.params[id]+= val # handle failure case } end # End - if raws[id] } # End - (0...EquipUpgrades::Max::StatId).each end # End - modify_stats # # * Update the Equipments List of Current Upgrades # def update_item_upgrades(item) @upg_equip.curr_upgrades.push(item) @upg_equip.add_suffix_upg_era(item.upgrader_suffix) #print "@upg_equip.upgraded_suffixes = #{@upg_equip.upgraded_suffixes}\n" end # End - update_item_upgrades # # * 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 #============================================================================== # ** Game_Interpreter #============================================================================== class Game_Interpreter def ra_upg(upgs = nil) SceneManager.call(Scene_UpgradableItem) SceneManager.scene.specify_upgraders(upgs) if upgs end end #============================================================================== # -------------------------------End of File----------------------------------- #==============================================================================