Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #===============================================================================
- #===============================================================================
- # - Upgradable Equipment 0.1 -
- # - Eshra -
- # - Requested by: Chigoo -
- #===============================================================================
- #===============================================================================
- # -~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-
- # Version 0.8: Release Date August 28, 2012 -
- # Compatibility: RPG Maker VX Ace
- #
- # Updates:
- # 2012 Dec 10 - Fixed Freeze during ugrade scene.
- # 2012 Dec 9 - 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.
- # 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.
- # 2012 Aug 29 - The name of the item has been changed to display how many
- # upgrades have been used on it.
- # 2012 Sept 4 - UpgradeOrientation::Size::WidthValue can now be used to adjust
- # the width of the windows in the upgrade scene
- # 2012 Sept 20 - Upgraders can now be specified to only be used with a specific
- # Equipment (use the tags <Upgrader "A"> and <Upgraded By "A">)
- # -----------------------------------------------------------------------------
- # Bug Fixes:
- # -----------------------------------------------------------------------------
- # 2012 Aug 28 - Added a nil check to fix a crash that was happening when
- # selecting a blank item.
- # 2012 Aug 28 - Fixed a NameError. Updated a module constant name I had
- # forgotten to change after moving the constant to a new module.
- # 2012 Aug 28 - Fixed overlapping text inside the item list window
- # 2012 Aug 29 - Upgraded equipment is now removed from the database also when it
- # is being removed the party's inventory
- # 2012 Aug 29 - Text now fits correctly in the equipment selection options window
- # 2012 Sept 3 - Misnamed method update_data_base_upg_equips inside RPG::Armor,
- # was corrected.
- # 2012 Sept 19 - 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
- # -~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-
- # -~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~ 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.
- #
- # -~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-
- # - 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.
- #
- # Upgrades can be specified so that they can only be used on corresponding equips
- # Use this tags:
- # <Upgrader A>
- # on the item you want to use as the upgrader, in this example, this upgrader can
- # only be used on upgradable items with this tag: <Upgraded By A>
- # The upgraded by tag should be used on an equipment to control which upgrades can
- # be used on it. Note, the A can be replaced with any word (no spaces, numbers, etc).
- #
- # ---------------------------- Calling the Script ------------------------------
- # The Upgrade Window can be brought up 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
- # <Upgrader Shield> and the other one is marked with the notetag <Upgrader Defensive>
- # 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"])
- #
- # ------------------------------- 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 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
- 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
- Upgrader = /<(?:!|)Upgrader (.+)>/i # upgraders can be given an upgrader number
- Upgraded_By = /<(?:!|)Upgraded By (.+)>/i # only effected be upgraders w/ this no.
- 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 <<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.
- attr_accessor :upgraded_by # A hash of symbols corresponding to ids for items
- # that can be used to upgrade this item.
- attr_accessor :upgrader_ids # symbol representing the type of upgradable equips
- # this can upgrade.
- #
- # 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
- when EquipUpgrades::Regexp::Upgrader
- (@upgrader_ids ||= []).push($1.to_sym)
- when EquipUpgrades::Regexp::Upgraded_By
- (@upgraded_by ||= {})[$1.to_sym] = true
- end
- }
- init_upgrade_id
- end # End - load_ntags_upgrade_mods
- #
- # initializes :accept_all to true inside the upgraded_by hash if it's nil
- #
- def init_upgrade_id
- (@upgraded_by = {})[EquipUpgrades::Symbols::AcpAll] = true if @upgraded_by.nil?
- (@upgrader_ids=[]).push(EquipUpgrades::Symbols::UpgAll) unless !@upgrader_ids.nil?
- end # End - init_upgrade_id_hashes
- #
- # 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
- #
- # Check if This is an Armor or Weapon
- #
- def is_equip?
- self.is_a?(RPG::Armor) || self.is_a?(RPG::Weapon)
- end
- #
- # * Upgraded Name
- #
- def upgrade_name
- @name = "Upgraded " + @orig_name + " +#{@curr_upgrades.size}"
- end # End - upgrade_name
- 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))).id = $data_weapons.size
- wep.orig_name = @orig_name ? @orig_name : (@orig_name = wep.name)
- wep.description = wep.description #+ " (Upgraded)"
- update_database_upg_equips(wep)
- wep
- end # End - deep_copy_clone_2544
- #
- # * Update Database
- #
- def update_database_upg_equips(wep=nil)
- print "custom weapons size before update = #{$custom_weapons.size}\n"
- $custom_weapons.delete(self)
- $custom_weapons.push(wep) unless !wep
- $data_weapons.push(wep) unless !wep # update database
- print "custom weapons size after update = #{$custom_weapons.size}\n"
- end # End - update_database_upg_equips
- 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))).id = $data_armors.size
- arm.orig_name = @orig_name ? @orig_name : (@orig_name = arm.name)
- arm.description = arm.description #+ " (Upgraded)"
- update_database_upg_equips(arm)
- end # End - deep_copy_clone_2544
- #
- # * Update Database
- #
- def update_database_upg_equips(arm=nil)
- print "custom armor size before db update #{$custom_armors.size}\n"
- $custom_armors.delete(self)
- $custom_armors.push(arm) unless !arm
- $data_armors.push(arm) unless !arm # update database
- print "custom armor size after db update #{$custom_armors.size}\n"
- arm
- end
- end # End - RPG::Armor
- #==============================================================================
- # ** Equipment_Upgrader
- #------------------------------------------------------------------------------
- # This class represents a new property for items which will allow those items
- # to represent upgraders which can increase the stats of weapons and armor.
- #==============================================================================
- 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
- #==============================================================================
- # ** Game_Party
- #------------------------------------------------------------------------------
- # Alias Methods:
- # gain_item: new functionality to remove upgraded equipment when necessary
- #==============================================================================
- class Game_Party < Game_Unit
- #
- # * alias method: gain_item
- # removes custom equipment from $custom_[type] if all of param item would
- # be removed from the party's inventory
- #
- alias gain_item_upg_equips_update_db gain_item
- def gain_item(item, amount, include_equip = false)
- item.update_database_upg_equips if delete_custom?(item, amount)
- gain_item_upg_equips_update_db(item, amount, include_equip)
- end # End - gain_item
- #
- # * Check to Remove Custom Equipment From Database
- #
- def delete_custom?(item, amount)
- item && item.is_equip? && amount < 0 && -amount >= item_number(item)
- 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
- $game_party.gain_item(@upg_equip, 1)
- 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)
- 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-----------------------------------
- #==============================================================================
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement