blucalm

Upg Equips unique req

Jan 19th, 2013
200
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Ruby 44.01 KB | None | 0 0
  1. #-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~
  2. # Upgradable Equipment
  3. # Author: Eshra
  4. # Requested By: Chigoo
  5. # First Version: 28 Aug. 2012
  6. # Compatibility: RPG Maker VX Ace
  7. # Dependencies (place them in this order from top to bottom):
  8. #     1. Tsuki_CustomDataManager
  9. #     2. Numeric Form Regex
  10. #     3. Custom DM Array Sizes Snippet
  11. #     4. Custom DB and Party Inventory Cleaner
  12. #     5. Unique Items
  13. #-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~
  14. #
  15. # -~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-
  16. # * Setup
  17. # -~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-
  18. # To install this script, copy and paste it under the materials section and
  19. # above main. This script requires the following bit of code to work:
  20. #
  21. # ($imported||={})["Numeric Form Regex"] = true
  22. #
  23. # module NumericForm
  24. #  Regex = /\A(?:-|)\d+(?:\.|)(?:\d+|)\Z/
  25. # end
  26. #
  27. # This is because I don't want to include it in every script I write that needs
  28. # it so just copy and paste that module and the imported hash into a
  29. # section above everything else or into a separate slot in the editor.
  30. #
  31. # You will also need to get the other dependencies listed in the header. You
  32. # can find them at: http://rascripts.wordpress.com/2012/11/07/upgradable-equipment/
  33. #
  34. # -~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-
  35. #                                 - How to Use -
  36. # -~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-
  37. # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
  38. # Specifying Equipment as Upgradable:
  39. # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
  40. # Use the notetag:
  41. #
  42. # <upgradable>
  43. #
  44. # to mark a piece of armor or a weapon as upgradable.
  45. # You can also specify how many times the equipment can be upgraded, for example:
  46. #
  47. # <upgradabe 2>
  48. #
  49. # means the equipment can be upgraded twice.
  50. #
  51. # All equipment that is upgradable must also have the <unique> notetag from
  52. # the unique items script.
  53. # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
  54. # Making an Upgrader
  55. # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
  56. # Upgraders are items that can be used to modify the stats of equipment that is
  57. # upgradable.
  58. #
  59. # Use any of the following notetags to do this, the first INTEGER should
  60. # correspond to the stat you want to modify, the second should be the value that
  61. # it will be modified by.
  62. #
  63. # These are the default stats and their associated INTEGERs:
  64. #
  65. # Max HP: 0
  66. # Max MP: 1
  67. # Attack Power: 2
  68. # Defense: 3
  69. # Magic Power: 4
  70. # Magic Defense: 5
  71. # Agility: 6
  72. # Luck: 7
  73. #
  74. # Notetags:
  75. #
  76. # <upg stat INTEGER +INTEGER>
  77. # <upg stat INTEGER +INTEGER%>
  78. # <upg stat all +INTEGER%>
  79. # <upg state INTEGER INTEGER%>
  80. #
  81. # ** The '+' signs can be replaced with '-' signs, don't forget the '%' signs
  82. #    where they are required **
  83. #
  84. # The first on the list:
  85. #
  86. # <upg stat INTEGER +INTEGER>
  87. #
  88. # will allow you to modify the stat corresponding to the first integer by the
  89. # value of the second integer.
  90. # For example:
  91. #
  92. # <upg stat 5 +143>
  93. #
  94. # Means the upgrader will increase the magic defense stat of the upgraded item
  95. # by 5.
  96. #
  97. # The second note tag:
  98. #
  99. # <upg stat INTEGER +INTEGER%>
  100. #
  101. # Allows a specific stat to be modified by the specified percentage:
  102. #
  103. # <upg stat 0 +10%>
  104. #
  105. # Will increase the HP stat by 10 percent.
  106. #
  107. # The third notetag:
  108. #
  109. # <upg stat all +INTEGER%>
  110. #
  111. # Will modify all stats by the specified percent:
  112. #
  113. # <upg stat all -5%>
  114. #
  115. # will cause all stats to be decreased by 5 percent on the upgraded equipment.
  116. #
  117. # The Fourth notetag:
  118. #
  119. # <upg state INTEGER INTEGER%>
  120. #
  121. # Will cause the upgraded equipment to have a chance of inflicting the state
  122. # with an id equal to the first INTEGER, 'the second INTEGER' pecent of the time:
  123. #
  124. # <upg state 0 10%>
  125. #
  126. # Will cause the upgraded equipment to have a 10 percent chance to inflict the
  127. # death state.
  128. # Note, the number specified as the first INTEGER is simply the id of the state
  129. # as it is listed in the database.
  130. #
  131. # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
  132. # Restricting Upgrader Usage
  133. # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
  134. #
  135. # You can restrict which upgraders can be used on which equipment by giving the
  136. # upgraders and the upgradable equipment types.
  137. # If an upgrader has a type, it can only upgrade upgradable equipment that
  138. # shares a type with it.
  139. # More than one type can be specified per upgrader and/or upgradable equipment
  140. # piece.
  141. #
  142. # When sepcifying the upgrader type for an upgrader, use the notetag:
  143. #
  144. # <upgrader ANYTHING>
  145. #
  146. # ** ANYTHING should be the string representing the upgraders type **
  147. # For example:
  148. #
  149. # <upgrader shield>
  150. #
  151. # would specify an upgrader that could only be used on upgradable equipment that
  152. # had a shield type spcified.
  153. #
  154. # When specifying the upgradable type for a piece of upgradable equipment, use
  155. # the notetag:
  156. #
  157. # <upgraded by ANYTHING>
  158. #
  159. #** ANYTHING should be the string representing the upg equip type **
  160. # For example:
  161. #
  162. # <upgraded by shield>
  163. #
  164. # would mean that the equipment item could only upgraded by upgraders that were
  165. # marked with the <upgrader shield> notetag.
  166. #
  167. # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
  168. # Calling the Script
  169. # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
  170. #
  171. # The Upgrade Window can be called from an event with this script call:
  172. #
  173. # ra_upg
  174. #
  175. # If you want to restrict which upgraders can be used during the upgrading scene
  176. # use the script call:
  177. #
  178. # ra_upg(ARRAY)
  179. #
  180. # replace 'ARRAY' with an array of strings of the specific upgrader types that
  181. # you want to use during that scene.
  182. #
  183. # For example if you have 2 items in your database, one is marked with the notetag
  184. # <upgrader shield> and the other one is marked with the notetag
  185. # <upgrader defensive>
  186. # and you only wanted to be able to use the "shield" upgraders during the upgrade
  187. # scene, you would use the script call:
  188. #
  189. # ra_upg(["Shield"])
  190. # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
  191. # Equipment Suffixes
  192. # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
  193. #
  194. # Upgraders can be specified to add sufixes to the names of the equipments they
  195. # are upgrading.
  196. # Use the notetag:
  197. #
  198. # <upg suffix ANYTHING>
  199. #
  200. # ** 'ANYTHING' should be replaced with the string you want to use as a suffix.
  201. # To mark the upgrader with a suffix to add onto the equipment it upgrades.
  202. # For example, if an upgrader was marked with the notetag:
  203. #
  204. # <upg suffix +20 Dec>
  205. #
  206. # if it was then used on an upgradable shield named, "Wooded Shield", the
  207. # shield's name would be changed to "Wooden Shield +20" after it was upgraded.
  208. #
  209. # There are several constants that can also be set to modify how many suffixes
  210. # are displayed on a piece of equipment, etc.:
  211. #
  212. # Set Only_Show_Most_Recent_Suffix to true if you only want to show 1 suffix
  213. # on the equipment.
  214. #
  215. # Set Show_Upgrade_Quantity_In_Name to true if you want to display how many
  216. # times the equipment was upgraded in the name.
  217. #
  218. # Change the maximum amount of suffixes that can be displayed in an items name
  219. # with Max_Suffixes
  220. # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
  221. # Failure Rate
  222. # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
  223. #
  224. # The chance that an upgrade will be successful can be modified in
  225. # EquipUpgrades::Player::DefaultFailRate below. Or it can be modified during
  226. # runtime by accessing $game_player.fail_rate_for_upgrades
  227. #
  228. # By default, increasing the value by 1 increases the failure rate by 1%, this
  229. # will change though if EquipUpgrades::Max::BaseRVal is modified.
  230. # The failure rate at the start of a new game will be equal to
  231. # EquipUpgrades::Player::DefaultFailRate/ EquipUpgrades::Max::BaseRVal
  232. #
  233. #------------------------------------------------------------------------------
  234. # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
  235. # Update Log:
  236. # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
  237. #  19 Jan 2013 - Unique Items is now a dependency.
  238. #  14 Dec 2012 - Neatened up the documentation.
  239. #  13 Dec 2012 - Major Bug Fixes:
  240. #
  241. #                Can now add suffixes to upgraders to be shown on the upgraded
  242. #                equipment.
  243. #                Equipment no longer disappears when you save a game while
  244. #                wearing upgraded equipment.
  245. #
  246. #                Database is now properly managed (tmk) during runtime but custom
  247. #                items are no longer deleted from the database because of the
  248. #                difficulty associated with ensuring an items id is the same
  249. #                as its location in the database when removing and readding items.
  250. #
  251. #                Known Bug, Not fixing yet:
  252. #
  253. #                If you have a saved game with upgraded equipment and you add a
  254. #                new item to the database in the editor, then load that saved
  255. #                game, some of the custom equipment may appear to "disappear"
  256. #                or you may have different items in your inventory.
  257. #
  258. #  12 Dec 2012 - Can now use any symbol when specfying upgraders, not just A-Z
  259. #                slight changes to note tags, can replace 'mod' with 'upg'
  260. #  10 Dec 2012 - Fixed Freeze during ugrade scene.
  261. #  9 Dec 2012  - Added support to restrict which upgraders can be used during the
  262. #                upgrade scene. Use the script call:
  263. #                ra_upg(ARRAY)
  264. #                ** replace "ARRAY" with an array of strings **
  265. #                to only allow upgrader with a type specified in the array to be
  266. #                used.
  267. #  20 Sept 2012 - Upgraders can now be specified to only be used with a specific
  268. #                 Equipment (use the tags <Upgrader "A"> and <Upgraded By "A">)
  269. #  19 Sept 2012 - Fixed a problem where armor wasn't being upgraded properly.
  270. #                 Was referencing $data_weapons inside deep_copy_clone_2544 of
  271. #                 RPG::Armor, meant to reference $data_armors
  272. #  4 Sept 2012  - UpgradeOrientation::Size::WidthValue can now be used to adjust
  273. #                 the width of the windows in the upgrade scene
  274. #  3 Sept 2012  - Misnamed method update_data_base_upg_equips inside RPG::Armor,
  275. #                 was corrected.
  276. #  29 Aug 2012  - The name of the item has been changed to display how many
  277. #                 upgrades have been used on it.
  278. #               - Upgraded equipment is now removed from the database also when it
  279. #                 is being removed the party's inventory
  280. #               - Text now fits correctly in the equipment selection options window
  281. #
  282. #  28 Aug 2012  - Added notetag support to limit the amount of upgrades that can
  283. #                 be used on an item. <!upgradable9> limits the item to no more
  284. #                 than nine upgrades.
  285. #               - Added a nil check to fix a crash that was happening when
  286. #                 selecting a blank item.
  287. #               - Fixed a NameError. Updated a module constant name I had
  288. #                 forgotten to change after moving the constant to a new module.
  289. #               - Fixed overlapping text inside the item list window
  290. #--------------------------------------------------------------------------------
  291.  
  292. $imported = {} if $imported.nil?
  293. raise "Upgradable Equipment requires Tsuki_CustomDataManager" unless $imported["Tsuki_CustomDataManager"]
  294. raise "Upgradable Equipment requires module NumericForm" unless $imported["Numeric Form Regex"]
  295. $imported["Ra Upgradable Equipment"] = true
  296.  
  297. #==============================================================================
  298. # Settings, these can be modified to customize the script a bit.
  299. #==============================================================================
  300. #
  301. # * UpgradeOrientation
  302. # Window orientation
  303. #
  304. module UpgradeOrientation
  305.   module Size
  306.     WidthValue = 0.6 # Modifies the width of the windows in the upgrade scene
  307.   end
  308. end # End - UpgradeOrientation
  309.  
  310. #
  311. # * EquipUpgrades
  312. # Handles settings the user can modify for various effects.
  313. #
  314. module EquipUpgrades
  315.  
  316.   Only_Show_Most_Recent_Suffix = false # set to false to show all suffixes
  317.   Show_Upgrade_Quantity_In_Name = false # true = show number of upgrades in name
  318.   Max_Suffixes = 2 # maximum num of suffixes to be show in an equips name
  319.  
  320.   module Regexp # The regular expressions used to parse upgraders, etc.
  321.     State = /<(?:Mod|upg) STATE(?:=| )(\d+) (\d+)%>/i
  322.     StatPercent = /<(?:Mod|upg) STAT(?:=| )(\d+|all) (\+|\-)(\d+)%>/i
  323.     StatRaw = /<(?:Mod|upg) STAT(?:=| )(\d+|all) (\+|\-)(\d+)>/i
  324.     Upgradable = /<(?:!|)upgradable(?: |)(\d+|)>/i
  325.     Upgrader = /<(?:!|)(?:upgrader) (.+)>/i # upgraders can be given an upgrader type
  326.     Upgraded_By = /<(?:!|)(?:upgraded by) (.+)>/i # only effected be upgraders w/ this no.
  327.     Upg_Suffix = /<\s*upg\s*suffix\s*(.+)>/i
  328.   end # End - Regexp
  329.  
  330.   module Player
  331.     DefaultFailRate = 0 # When determining success, a number is generated between
  332.                          # 0 and 100. if the generated number + 1 is less than
  333.                          # fail_rate then the upgrade is unsuccessful.
  334.                          # By default increasing the DefaultFailRate to 1 gives
  335.                          # a 1% fail rate, 2=2%, etc.
  336.     SuccessAnimation = 33
  337.     FailAnimation = 96
  338.     FailureMod = 0.9 # modifes the effect of failing to upgrade by the
  339.                      # specified rate
  340.     DisplayAnimation = true # Set this to false to turn off the animations
  341.   end # End - Player
  342.  
  343.   module Max
  344.     StatId = 8 # The number of stats the original value in ace is 8
  345.     BaseRVal = 100 # The highest random number generated will be this value
  346.                    # minus 1. the formula for calculating upgrade success is:
  347.                    # random_val < BaseRVal - DefaultFailRate ? success : fail
  348.     IconWidth = 24 # The width of the icons you're using
  349.   end # End - Max
  350.  
  351.   module EquipPhrase
  352.     Equips = "Equipment"
  353.     Upgrader = "Upgrades"
  354.   end # End - EquipPhrase
  355.  
  356.   module Symbols
  357.     UpgAll = :upgrade_all
  358.     AcpAll = :accept_all
  359.   end
  360. end # End - EquipUpgrades
  361. #==============================================================================
  362. # End of Settings, don't modify below here unless you know what you're doing.
  363. #==============================================================================
  364.  
  365. #==============================================================================
  366. # ** Window_Selectable
  367. #==============================================================================
  368. class Window_Selectable < Window_Base
  369.   def get_curr_index
  370.     @index && @index >= 0 ? @index : 0
  371.   end
  372. end # End - Window_Selectable
  373.  
  374. #==============================================================================
  375. # ** Game_Player
  376. #       # new attributes are added to the game player to control upgrade failure
  377. #       # rate.
  378. #==============================================================================
  379. class Game_Player < Game_Character
  380.   attr_accessor :fail_rate_for_upgrades
  381.   attr_accessor :fail_mod_for_upgrades
  382.  
  383.   alias game_pl_init_method_uni_fail_rate_upgrades_1842693 initialize
  384.   def initialize
  385.     game_pl_init_method_uni_fail_rate_upgrades_1842693
  386.     @fail_rate_for_upgrades = EquipUpgrades::Player::DefaultFailRate
  387.     @fail_mod_for_upgrades = EquipUpgrades::Player::FailureMod
  388.   end
  389. end # End - Game_Player
  390.  
  391. #==============================================================================
  392. # ** Window_UpgradeItemList
  393. #------------------------------------------------------------------------------
  394. #  This window displays a upgradable items and items that can be used as
  395. #  upgraders.
  396. #==============================================================================
  397. class Window_UpgradeItemList < Window_ItemList
  398.  
  399.   attr_accessor :data
  400.   attr_accessor :only_enable_upgradables
  401.  
  402.   #
  403.   # Get Activation State of Selection Item
  404.   #
  405.   def current_item_enabled?; enable?(@data[index]); end
  406.  
  407.   #
  408.   # Display in Enabled State?
  409.   #
  410.   def enable?(item)
  411.     only_enable_upgradables ? item && item.is_upgradable : item && item.upgrade_mods
  412.   end
  413.  
  414.   #
  415.   # * Draw Item
  416.   #
  417.   def draw_item(index)
  418.     item = @data[index]
  419.     if item
  420.       rect = item_rect(index)
  421.       rect.width -= 4
  422.       draw_item_name(item, rect.x, rect.y, enable?(item), 90)
  423.       draw_item_number(rect, item)
  424.     end
  425.   end
  426.  
  427.   #
  428.   # * Draw Item Number
  429.   #
  430.   def draw_item_number(rect, item)
  431.     draw_text(rect, sprintf("%2d", $game_party.item_number(item)), 2)
  432.   end
  433. end # End- Window_UpgradeItemList
  434.  
  435. #==============================================================================
  436. # ** Window_UpgradeItemCategory
  437. #------------------------------------------------------------------------------
  438. #  The category window for the upgradable items scene
  439. #==============================================================================
  440. class Window_UpgradeItemCategory < Window_ItemCategory
  441.   def window_width
  442.     Graphics.width * UpgradeOrientation::Size::WidthValue
  443.   end
  444.  
  445.   def col_max
  446.     return 4
  447.   end
  448.  
  449.   #
  450.   # The categories of items that are displayed in the upgradable scene
  451.   #
  452.   def make_command_list
  453.     add_command(Vocab::weapon,   :weapon)
  454.     add_command(Vocab::armor,    :armor)
  455.     add_command(Vocab::item,     :item)
  456.     add_command(Vocab::key_item, :key_item)
  457.   end
  458. end # End - Window_UpgradeItemCategory
  459.  
  460. #==============================================================================
  461. # ** Window_UpgradeItemCategory
  462. #------------------------------------------------------------------------------
  463. #  The window which displays the icons for the items which are being used to do
  464. #  the upgrade
  465. #==============================================================================
  466. class Window_DisplayUpgrades < Window_Base
  467.   attr_accessor :content_icons
  468.  
  469.   def initialize(x,y,h)
  470.     @window_width =(1-UpgradeOrientation::Size::WidthValue)*Graphics.width
  471.     super(x,y,@window_width,h)
  472.     @content_names, @content_icons = [], []
  473.   end # End - initialize
  474.  
  475.   def set_item(item)
  476.     contents.clear
  477.     draw_item_name(item,0,0,true,@window_width-40)
  478.   end # End - set_item
  479.  
  480.   def add_new_icon(id)
  481.     @content_icons.push(id)
  482.     draw_all_icons
  483.   end # End - add_new_icon
  484.  
  485.   def draw_all_icons
  486.     contents.clear
  487.     index, x_pos = 0,0
  488.     @content_icons.each{ |id|
  489.       draw_icon(id, x_pos, line_height * index, true)
  490.       index += 1
  491.       if(index > 6)
  492.         index = 0
  493.         x_pos += EquipUpgrades::Max::IconWidth
  494.       end # End - index > 6
  495.     } # End - @content_icons.each
  496.   end # End - draw_all_icons
  497.  
  498.   def clear_all
  499.     contents.clear
  500.     @content_names = []
  501.     @content_icons = []
  502.   end # End - clear_all
  503. end # End - Window_DisplayUpgrades
  504.  
  505.  
  506.  
  507. class Window_UpgradeSelection < Window_HorzCommand
  508.  
  509.   #
  510.   # Public Instance Variables
  511.   #
  512.   attr_reader   :item_window
  513.  
  514.   #
  515.   # Object Initialization
  516.   #
  517.   def initialize(x,y, upgrader)
  518.     @type = upgrader
  519.     @col_max = upgrader ? 3 : 2
  520.     super(x, y)
  521.   end # End - initialize
  522.  
  523.   #
  524.   # Get Window Width
  525.   #
  526.   def window_width
  527.     Graphics.width * (1-UpgradeOrientation::Size::WidthValue)
  528.   end # End - window_width
  529.  
  530.   #
  531.   # Get Digit Count
  532.   #
  533.   def col_max
  534.     return @col_max
  535.   end # End - col_max
  536.  
  537.   #
  538.   # Create Command List
  539.   #
  540.   def make_command_list
  541.     if !@type
  542.       add_command(EquipUpgrades::EquipPhrase::Equips,     :equip)
  543.       add_command("Ok", :advance)
  544.     else
  545.       add_command(EquipUpgrades::EquipPhrase::Upgrader,     :upgrades)
  546.       add_command("Clear", :clear)
  547.       add_command("Done", :done)
  548.     end # End - if !@type
  549.   end # End - make_command_list
  550. end # End - Window_UpgradeSelection
  551.  
  552. #==============================================================================
  553. # ** DataManager
  554. #==============================================================================
  555. module DataManager
  556.   #
  557.   # * alias load_database
  558.   #
  559.   class <<self; alias load_db_upgrade_mods_82372934 load_database; end
  560.   def self.load_database
  561.     load_db_upgrade_mods_82372934
  562.     load_ntags_upgrade_mods_82372933
  563.   end
  564.  
  565.   #
  566.   # load_ntags_upgrade_mods_82372933
  567.   #
  568.   def self.load_ntags_upgrade_mods_82372933
  569.     groups = [$data_armors, $data_weapons, $data_items]
  570.     for group in groups
  571.       for obj in group
  572.         next if obj.nil?
  573.         obj.load_ntags_upgrade_mods
  574.       end
  575.     end
  576.   end
  577.  
  578. end # DataManager
  579.  
  580. #==============================================================================
  581. # ** RPG::BaseItem
  582. #==============================================================================
  583. class RPG::BaseItem
  584.  
  585.    def to_s
  586.      "#{@name} #{@id}"
  587.    end
  588.  
  589.    attr_accessor :max_upgrades # The max number of upgrades usable on this item
  590.    attr_accessor :curr_upgrades # list of current upgrades on this item
  591.    attr_accessor :upgrade_mods
  592.    attr_accessor :is_upgradable
  593.    attr_accessor :orig_name # Used when making deep copies and it's necessary
  594.                             # to know the name of the original item while still
  595.                             # being able to change the name of the new item.
  596.    attr_accessor :upgraded_by # A hash of symbols corresponding to ids for items
  597.                               # that can be used to upgrade this item.
  598.    attr_accessor :upgrader_ids # symbol representing the type of upgradable equips
  599.                               # this can upgrade.
  600.    attr_accessor :upgrader_suffix # suffix an upgrader adds to the name of an item.
  601.    attr_accessor :upgraded_suffixes # list of suffixes on upgraded equipment
  602.    attr_accessor :is_upg_dupe
  603.    attr_accessor :name
  604.    
  605.    #
  606.    # Parses notetags and stores corresponding data
  607.    #
  608.    def load_ntags_upgrade_mods
  609.     init_fields_upg_era
  610.     self.note.split(/[\r\n]+/).each { |line|
  611.       next unless line != nil# && $1 != nil
  612.       case line
  613.       when EquipUpgrades::Regexp::State
  614.         add_state_upgrade_mods($1.to_i, $2.to_i)
  615.       when EquipUpgrades::Regexp::StatPercent
  616.         add_stat_mod(:percent, $1, $3.to_i, $2)
  617.       when EquipUpgrades::Regexp::StatRaw
  618.         add_stat_mod(:raw, $1, $3.to_i, $2)
  619.       when EquipUpgrades::Regexp::Upgradable
  620.         @is_upgradable = true
  621.         if (val=$1.to_s) =~ NumericForm::Regex #init max upgrades if it was defined
  622.           @max_upgrades = val.to_i
  623.           @curr_upgrades = []
  624.         end
  625.       when EquipUpgrades::Regexp::Upgrader
  626.         (@upgrader_ids ||= []).push($1.to_sym)
  627.       when EquipUpgrades::Regexp::Upgraded_By
  628.         (@upgraded_by ||= {})[$1.to_sym] = true
  629.       when EquipUpgrades::Regexp::Upg_Suffix
  630.         @upgrader_suffix = $1
  631.       end
  632.     }
  633.     init_upgrade_id
  634.   end # End - load_ntags_upgrade_mods
  635.  
  636.   #
  637.   # initializes :accept_all to true inside the upgraded_by hash if it's nil
  638.   #
  639.   def init_upgrade_id
  640.     (@upgraded_by = {})[EquipUpgrades::Symbols::AcpAll] = true if @upgraded_by.nil?
  641.     (@upgrader_ids=[]).push(EquipUpgrades::Symbols::UpgAll) unless !@upgrader_ids.nil?
  642.   end # End - init_upgrade_id_hashes
  643.   #
  644.   #
  645.   #
  646.   def init_fields_upg_era
  647.     @upgrader_suffix, @upgraded_suffixes,@max_upgrades = "",[], 1<<31
  648.     @curr_upgrades = []
  649.   end
  650.  
  651.   #
  652.   # store state modifiers
  653.   #
  654.   def add_state_upgrade_mods(id, val)
  655.     init_upgrade_mods
  656.     @upgrade_mods.store_state_mod(id, val * 0.01)
  657.   end # End - add_state_upgrade_mods
  658.  
  659.   #
  660.   # store base stat modifiers percentages mapped from :percent, raw values from
  661.   # :raw
  662.   #
  663.   def add_stat_mod(sym, id, val, op)
  664.     init_upgrade_mods
  665.     val *= 0.01 if sym == :percent
  666.     val = op.eql?("-") ? -val : val
  667.     @upgrade_mods.store_stat_mod(sym, id, val)
  668.   end
  669.  
  670.   #
  671.   # initialize @upgrade_mods if it is nil
  672.   #
  673.   def init_upgrade_mods
  674.     @upgrade_mods = Equipment_Upgrader.new unless @upgrade_mods
  675.   end
  676.  
  677.   #
  678.   # adds a new feature to the item
  679.   #
  680.   def add_new_feature_upg(feature); @features.push(feature); end
  681.  
  682.   #
  683.   #
  684.   #
  685.   def add_suffix_upg_era(suffix)
  686.     upgraded_suffixes.push(suffix) unless !suffix || suffix.eql?("")
  687.   end
  688.  
  689.   #
  690.   # Check if This is an Armor or Weapon
  691.   #
  692.   def is_equip?
  693.     self.is_a?(RPG::Armor) || self.is_a?(RPG::Weapon)
  694.   end
  695.  
  696.   #
  697.   # * Upgraded Name
  698.   #
  699.   def upgrade_name
  700.    
  701.     @name = @orig_name
  702.     size = @upgraded_suffixes.size
  703.    
  704.     if EquipUpgrades::Only_Show_Most_Recent_Suffix
  705.       @name += (" "<<@upgraded_suffixes[size-1] unless @upgraded_suffixes.empty?)
  706.     else
  707.       @upgraded_suffixes.each_with_index do |s,i|
  708.         @name+=" " if i == 0
  709.         i != size-1 ? @name+=(s<<" ") : @name+=s
  710.         break if i + 1 == EquipUpgrades::Max_Suffixes
  711.       end
  712.     end
  713.    
  714.     if EquipUpgrades::Show_Upgrade_Quantity_In_Name
  715.       @name += " +#{@curr_upgrades.size}"
  716.     end
  717.   end # End - upgrade_name
  718. end # End - RPG::BaseItem
  719.  
  720. #==============================================================================
  721. # ** RPG::Weapon
  722. #------------------------------------------------------------------------------
  723. # A Method to create a deep copy is added
  724. #==============================================================================
  725. class RPG::Weapon < RPG::EquipItem
  726.  
  727.   #
  728.   # * Deep Copy - Not used left for compat
  729.   #
  730.   def deep_copy_clone_2544
  731.       (wep = Marshal.load(Marshal.dump(self))).id = $data_weapons.size
  732.       wep.orig_name = @orig_name ? @orig_name : (@orig_name = wep.name)
  733.       wep.description = wep.description #+ " (Upgraded)"
  734.       update_database_upg_equips(wep)
  735.       wep
  736.   end
  737.  
  738.   #
  739.   # * Update Database -  Not used left for compat
  740.   #
  741.   def update_database_upg_equips(wep=nil)
  742.     $custom_weapons.push(wep) unless !wep
  743.     $data_weapons.push(wep) unless !wep # update database
  744.   end
  745. end # RPG::Weapon
  746.  
  747. #==============================================================================
  748. # ** RPG::Armor
  749. #------------------------------------------------------------------------------
  750. # A Method to create a deep copy is added
  751. #==============================================================================
  752. class RPG::Armor < RPG::EquipItem
  753.  
  754.   #
  755.   # * Deep Copy -  Not used left for compat
  756.   #
  757.   def deep_copy_clone_2544
  758.     (arm = Marshal.load(Marshal.dump(self))).id = $data_armors.size
  759.     arm.orig_name = @orig_name ? @orig_name : (@orig_name = arm.name)
  760.     arm.description = arm.description #+ " (Upgraded)"
  761.     update_database_upg_equips(arm)
  762.   end # End - deep_copy_clone_2544
  763.  
  764.   #
  765.   # * Update Database -  Not used left for compat
  766.   #
  767.   def update_database_upg_equips(arm=nil)
  768.     $custom_armors.push(arm) unless !arm
  769.     $data_armors.push(arm) unless !arm # update database
  770.     arm
  771.   end
  772. end # End - RPG::Armor
  773.  
  774. #==============================================================================
  775. # ** Equipment_Upgrader
  776. #------------------------------------------------------------------------------
  777. #    This class represents a new property for items which will allow those items
  778. #    to represent upgraders which can increase the stats of weapons and armor.
  779. #==============================================================================
  780. class Equipment_Upgrader
  781.   attr_accessor :states
  782.   attr_accessor :stat_mods
  783.  
  784.   def initialize
  785.     @states = {} # maps state ids to the chance of that state being inflicted
  786.     @stat_mods = {} # A hash mapping stat Ids to the symbols :percent and :raw
  787.                     # these determine how much the effected stat is changed.
  788.   end
  789.  
  790.   # The percentage value is stored as a float between -1.00 and 1.00
  791.   def store_stat_mod(sym, stat_id, val, preserve = false, mod = 1)
  792.     @stat_mods[stat_id.to_i] = {} unless @stat_mods[stat_id.to_i]
  793.     mod_all_stats(sym, stat_id, val, preserve, mod) unless stat_id.to_s =~ NumericForm::Regex
  794.     @stat_mods[stat_id.to_i][sym] = preserve ? @stat_mods[stat_id][sym] + val : val
  795.   end
  796.  
  797.   #
  798.   # stores data which will be added to item.features
  799.   #
  800.   def store_state_mod(state_id, val, preserve = false, mod = 1)
  801.      @states[state_id] = preserve ?  @states[state_id] + val : val
  802.   end
  803.  
  804.   #
  805.   # stores data which will modify the stats stored in item.params
  806.   #
  807.   def mod_all_stats(sym, stat_id, val, preserve = false, mod = 1)
  808.     (0..7).each{ |id| store_stat_mod(sym, id, val, preserve, mod)}
  809.   end
  810.  
  811.   #
  812.   # Percentage value modifications to stats
  813.   #
  814.   def get_stat_mod_percent(stat_id); @stat_mods[stat_id][:percent]; end
  815.  
  816.   #
  817.   # Non percentage value modifications to stats
  818.   #
  819.   def get_stat_mod_raw(stat_id); @stat_mods[stat_id][:raw]; end
  820.  
  821.   #
  822.   # The percent chance of happening this upgrader gives to the state with
  823.   # id = param: state_id
  824.   #
  825.   def get_state_mod(state_id); @states[state_id]; end
  826.  
  827. end # End - Equip_Upgrader
  828.  
  829. #==============================================================================
  830. # ** Game_Party
  831. #------------------------------------------------------------------------------
  832. #    Alias Methods:
  833. #       gain_item: new functionality to remove upgraded equipment when necessary
  834. #==============================================================================
  835. class Game_Party < Game_Unit
  836.   #
  837.   # * alias method: gain_item
  838.   #   removes custom equipment from $custom_[type] if all of param item would
  839.   #   be removed from the party's inventory
  840.   #
  841.   alias gain_item_upg_equips_update_db gain_item
  842.   def gain_item(item, amount, include_equip = false)
  843.     item.update_database_upg_equips if delete_custom?(item, amount)
  844.     gain_item_upg_equips_update_db(item, amount, include_equip)
  845.   end # End - gain_item
  846.   #
  847.   # * Check to Remove Custom Equipment From Database
  848.   #
  849.   def delete_custom?(item, amount)
  850.     # false
  851.     item && item.is_equip? && amount < 0 && -amount >= item_number(item) && item.is_upg_dupe
  852.   end # End - delete_custom?
  853.   #
  854.   # * Alias try_to_eval_unique from the unique items script.
  855.   #
  856.   alias try_to_eval_unique_upg_era try_to_eval_unique
  857.   def try_to_eval_unique(*args)
  858.     item = try_to_eval_unique_upg_era(*args)
  859.     (item.orig_name = item.name) if item
  860.     item
  861.   end
  862. end # End - Game_Party
  863.  
  864. #==============================================================================
  865. # ** Scene_UpgradableItem
  866. #------------------------------------------------------------------------------
  867. #  Allows items to be upgraded by other items
  868. #==============================================================================
  869.  
  870. class Scene_UpgradableItem < Scene_ItemBase
  871.   #
  872.   # * Start Processing
  873.   #
  874.   def start
  875.     super
  876.     create_help_window
  877.     create_equip_select_window
  878.     create_display_window_upgradable
  879.     create_upgrade_select_window
  880.     create_category_window((1-UpgradeOrientation::Size::WidthValue)*Graphics.width,@help_window.height,0,0)
  881.     create_item_window((1-UpgradeOrientation::Size::WidthValue)*Graphics.width)
  882.     create_upgrade_list
  883.    
  884.     @upg_equip = nil
  885.     @upgraders = [] # list of items to be used as upgraders for the equipment
  886.     @item_is_upgrader = false# Determines which list to show items in once clicked
  887.   end # End - start
  888.   #
  889.   # Specify which upgraders can be used to upgrade items here
  890.   #
  891.   def specify_upgraders(upg_list)
  892.     @ok_upgs = upg_list
  893.   end
  894.   #
  895.   # * Window With Options Equipment or Ok
  896.   #
  897.   def create_display_window_upgradable
  898.     w = Graphics.width * (1-UpgradeOrientation::Size::WidthValue)
  899.     h = 48
  900.     y = @upgrade_equipment_window.height+@help_window.height
  901.    
  902.     @display_window = Window_DisplayUpgrades.new(0,y,h)
  903.     @display_window.viewport = @viewport
  904.   end # End - create_display_window_upgradable
  905.   #
  906.   # * Create Equip Select Window
  907.   #   The base window with options to select on equipment or to just click ok
  908.   #
  909.   def create_equip_select_window
  910.     @upgrade_equipment_window = Window_UpgradeSelection.new(0,@help_window.height, false)
  911.     @upgrade_equipment_window.viewport = @viewport
  912.     @upgrade_equipment_window.deactivate
  913.     @upgrade_equipment_window.unselect
  914.     @upgrade_equipment_window.set_handler(:ok, method(:on_upgrade_equip_ok))
  915.     @upgrade_equipment_window.set_handler(:cancel, method(:on_equip_select_cancel))
  916.     @upgrade_equipment_window.set_handler(:advance, method(:on_equip_select_advance))
  917.   end # End - create_equip_select_window
  918.   #
  919.   # * Upgrade Selection Window
  920.   #
  921.   def create_upgrade_select_window
  922.     y = @help_window.height + @upgrade_equipment_window.height + @display_window.height
  923.     @upgrades_selection_window = Window_UpgradeSelection.new(0,y, true)
  924.     @upgrades_selection_window.viewport = @viewport
  925.     @upgrades_selection_window.set_handler(:upgrades, method(:on_choose_upgrades))
  926.     @upgrades_selection_window.set_handler(:clear, method(:on_clear_upgrades))
  927.     @upgrades_selection_window.set_handler(:done, method(:on_done))
  928.     @upgrades_selection_window.set_handler(:cancel, method(:on_upgrade_cancel))
  929.     @upgrades_selection_window.deactivate
  930.     @upgrades_selection_window.unselect
  931.   end # End - create_upgrade_select_window
  932.   #
  933.   # * Upgrade List
  934.   #
  935.   def create_upgrade_list
  936.     th1, th2 = @help_window.height, @upgrade_equipment_window.height
  937.     th3, th4 = @display_window.height, @upgrades_selection_window.height
  938.     y = th1 + th2 + th3 + th4
  939.     h = Graphics.height - y
  940.     @upgrades_display_window = Window_DisplayUpgrades.new(0,y,h)
  941.     @upgrades_display_window.viewport = @viewport
  942.   end # End - create_upgrade_list
  943.   #
  944.   # * Create Category Window
  945.   #
  946.   def create_category_window(x,y,w,h)
  947.     @category_window = Window_UpgradeItemCategory.new
  948.     @category_window.viewport = @viewport
  949.     @category_window.help_window = @help_window
  950.     @category_window.y = y
  951.     @category_window.x = Graphics.width * (1-UpgradeOrientation::Size::WidthValue)
  952.     @category_window.set_handler(:ok,     method(:on_category_ok))
  953.     @category_window.set_handler(:cancel, method(:on_category_cancel))
  954.   end # End - create_category_window
  955.   #
  956.   # * Create Item Window
  957.   #
  958.   def create_item_window(x)
  959.     wy = @category_window.y + @category_window.height
  960.     wh = Graphics.height - wy
  961.     ww = UpgradeOrientation::Size::WidthValue*Graphics.width
  962.     @item_window = Window_UpgradeItemList.new(x, wy, ww, wh)
  963.     @item_window.viewport = @viewport
  964.     @item_window.help_window = @help_window
  965.     @item_window.set_handler(:ok,     method(:on_item_ok))
  966.     @item_window.set_handler(:cancel, method(:on_item_cancel))
  967.     @item_window.only_enable_upgradables = true
  968.     @category_window.item_window = @item_window
  969.   end # End - create_item_window
  970.   #
  971.   # * Category [OK]
  972.   #
  973.   def on_category_ok
  974.     @item_window.activate
  975.     @item_window.select_last
  976.   end # End - on_category_ok
  977.   #
  978.   # * Category [Cancel]
  979.   #
  980.   def on_category_cancel
  981.     if !@item_is_upgrader
  982.       @upgrade_equipment_window.activate
  983.       @upgrade_equipment_window.select(@upgrade_equipment_window.get_curr_index)
  984.       @category_window.deactivate
  985.     else
  986.       turn_on_upgrades_selection
  987.       @category_window.deactivate
  988.     end
  989.   end # End - on_category_cancel
  990.   #
  991.   # * Item [OK]
  992.   #
  993.   def on_item_ok
  994.     if !@item_is_upgrader
  995.       equip_selected
  996.     else
  997.       upgrader_selected
  998.     end # End - !@item_is_upgrader
  999.   end # End - on_item_ok
  1000.   #
  1001.   # * Method called when an equipment is selected from on_item_ok
  1002.   #
  1003.   def equip_selected
  1004.     $game_party.gain_item(@upg_equip, 1) unless !@upg_equip
  1005.     @upg_equip = item
  1006.     @display_window.set_item(@upg_equip)
  1007.     $game_party.gain_item(item, -1)
  1008.     on_clear_upgrades
  1009.     @item_window.data.delete(item) if !$game_party.has_item?(item)
  1010.     @item_window.refresh
  1011.     turn_on_upgrades_selection
  1012.     @item_window.deactivate
  1013.    
  1014.   end
  1015.   #
  1016.   # * Method called when an upgrader is selected from on_item_ok
  1017.   #
  1018.   def upgrader_selected
  1019.     if !check_can_upgrade # already max amount of upgrades in list
  1020.         #turn_on_upgrades_selection
  1021.         @item_window.activate
  1022.         Sound.play_buzzer
  1023.         return
  1024.       end
  1025.       @upgraders.push(item)
  1026.       @upgrades_display_window.add_new_icon(item.icon_index)
  1027.       $game_party.gain_item(item, -1)
  1028.       @item_window.data.delete(item) if !$game_party.has_item?(item)
  1029.       @item_window.refresh
  1030.       @item_window.activate
  1031.   end
  1032.   #
  1033.   # * Item [Cancel]
  1034.   #
  1035.   def on_item_cancel
  1036.     @item_window.unselect
  1037.     @category_window.activate
  1038.   end # End - on_item_cancel
  1039.   #
  1040.   # Handler method which allows items to be selected as upgraders
  1041.   #
  1042.   def on_choose_upgrades
  1043.     @item_is_upgrader = true
  1044.     @item_window.only_enable_upgradables = false
  1045.     @upgrades_selection_window.deactivate
  1046.     @category_window.activate
  1047.     @category_window.select(@category_window.get_curr_index)
  1048.   end # End - on_choose_upgrades
  1049.   #
  1050.   # Handler method which clears all selected upgrades
  1051.   #
  1052.   def on_clear_upgrades
  1053.     empty_upgrades
  1054.     turn_on_upgrades_selection
  1055.   end # End - on_clear_upgrades
  1056.   #
  1057.   # Common code used when returning items to player after clearing the
  1058.   # upgrade list
  1059.   #
  1060.   def empty_upgrades
  1061.     @upgraders.each{ |item|
  1062.       $game_party.gain_item(item, 1)
  1063.     }
  1064.     @upgraders = []
  1065.     @upgrades_display_window.clear_all
  1066.     @item_window.refresh
  1067.   end # End - empty_upgrades
  1068.   #
  1069.   # Handler method which allows the equipment to be upgraded
  1070.   #
  1071.   def on_done
  1072.     perform_upgrade
  1073.   end # End - on_done
  1074.   #
  1075.   # Handler method called when upgrade menu is unselected
  1076.   #
  1077.   def on_upgrade_cancel
  1078.     @item_is_upgrader = false
  1079.     @item_window.only_enable_upgradables = true
  1080.     @upgrades_selection_window.deactivate
  1081.     @upgrades_selection_window.unselect
  1082.     @category_window.activate
  1083.     @category_window.select(@category_window.get_curr_index)
  1084.   end # End - on_upgrade_cancel
  1085.   #
  1086.   # Allows equipment selection
  1087.   #
  1088.   def on_upgrade_equip_ok
  1089.     @upgrade_equipment_window.deactivate
  1090.     @category_window.activate
  1091.     @category_window.select(@category_window.get_curr_index)
  1092.   end # End - on_upgrade_equip_ok
  1093.   #
  1094.   # * Allows advancement to upgrade selection without having to click a new equip
  1095.   #
  1096.   def on_equip_select_advance
  1097.    
  1098.     return @upgrade_equipment_window.activate unless @upg_equip
  1099.     @upgrade_equipment_window.deactivate
  1100.     turn_on_upgrades_selection
  1101.   end # End - on_equip_select_advance
  1102.   #
  1103.   # * About to exit the scene
  1104.   #
  1105.   def on_equip_select_cancel
  1106.     empty_upgrades
  1107.     $game_party.gain_item(@upg_equip, 1)
  1108.     SceneManager.return
  1109.   end # End - on_equip_select_cancel
  1110.   #
  1111.   # * Common code used when activating the upgrade selection menu
  1112.   #
  1113.   def turn_on_upgrades_selection
  1114.     @item_window.only_enable_upgradables = @item_is_upgrader = true
  1115.     @upgrades_selection_window.activate
  1116.     @upgrades_selection_window.select(@upgrades_selection_window.get_curr_index)
  1117.   end # End - turn_on_upgrades_selection
  1118.   #
  1119.   # * Check to see if the current item can be upgraded by the selected upgrader
  1120.   #
  1121.   def check_can_upgrade
  1122.    
  1123.     max = @upg_equip.max_upgrades
  1124.     size = @upg_equip.curr_upgrades.size # amount of upgrades on equip so far
  1125.     return false if size + @upgrades_display_window.content_icons.size >= max
  1126.    
  1127.     included_type = false
  1128.     @ok_upgs ||= []
  1129.    
  1130.     item.upgrader_ids.each do |sym|
  1131.       return true if @ok_upgs.include?(sym.to_s)
  1132.       included_type = true if @upg_equip.upgraded_by[sym]
  1133.     end
  1134.     return false if !@ok_upgs.empty?
  1135.    
  1136.     return true if @upg_equip.upgraded_by[EquipUpgrades::Symbols::AcpAll]
  1137.     return true if item.upgrader_ids.include? EquipUpgrades::Symbols::UpgAll
  1138.    
  1139.     included_type
  1140.    
  1141.   end
  1142.   #
  1143.   # * Perform the Upgrade
  1144.   #   Change the stats on the item that is being upgraded (or downgraded)
  1145.   def perform_upgrade
  1146.     return unless upgrade_is_valid? # Make sure the current upgrade is ok
  1147.     modify_stats(failure = upgrade_successful?) # Modify stats based on success
  1148.     add_new_features(13) unless failure# 13 is the default code for states
  1149.     set_player_animation(failure)
  1150.     @upg_equip.upgrade_name # Change the name
  1151.     $game_party.gain_item(@upg_equip, 1)
  1152.     Era::CleanCDB.clean if Era::CleanCDB::Clean
  1153.     return_scene
  1154.   end # End - perform_upgrade
  1155.  
  1156.   # * Check if Upgrading is acceptable (i.e. no nil vals/ non-equip items, etc.)
  1157.   def upgrade_is_valid?
  1158.     # Check if the current upgrade is valid, if not then return
  1159.     return true unless (@upgraders.empty? || !@upg_equip.is_a?(RPG::EquipItem))
  1160.     turn_on_upgrades_selection
  1161.     false
  1162.   end # End - upgrade_is_valid?
  1163.   #
  1164.   # * Was the Upgrade Successful?
  1165.   #
  1166.   def upgrade_successful?
  1167.     rand(EquipUpgrades::Max::BaseRVal) < $game_player.fail_rate_for_upgrades
  1168.   end # End - upgrade_successful?
  1169.   #
  1170.   # * Set Player Animation
  1171.   #
  1172.   def set_player_animation(fail)
  1173.     return unless EquipUpgrades::Player::DisplayAnimation
  1174.     $game_player.animation_id = EquipUpgrades::Player::SuccessAnimation unless fail
  1175.     $game_player.animation_id = EquipUpgrades::Player::FailAnimation if fail
  1176.   end # End - set_player_animation
  1177.   #
  1178.   # * Add New Features
  1179.   #   Creates new features to add to item.features
  1180.   #
  1181.   def add_new_features(code)
  1182.     @upgraders.each{ |item|
  1183.       states = item.upgrade_mods.states
  1184.       states.keys.each{ |key|
  1185.         feature = RPG::BaseItem::Feature.new(code, key, states[key])
  1186.         @upg_equip.add_new_feature_upg(feature)
  1187.       }
  1188.     }
  1189.   end # End - add_new_features
  1190.   #
  1191.   # * Modify Stats
  1192.   #   percentages are applied to stats starting with the smallest percentage
  1193.   #   increasing to the largest. Percentage bonuses are applied before raw bonuses
  1194.   #
  1195.   def modify_stats(failed = false)
  1196.     percents = {} # maps stat ids to an array of percentages
  1197.     raws = {} # maps stat ids to an array of values
  1198.    
  1199.     # Goes through all the items and condenses all the upgrades into above
  1200.     # two hashes
  1201.     @upgraders.each{  |item|
  1202.       update_item_upgrades(item) #add each 1 to curr upgs list
  1203.       stats = item.upgrade_mods.stat_mods
  1204.       stats.keys.each{ |key|
  1205.         if stats[key]
  1206.           percents[key] = [] if !percents[key]
  1207.           raws[key] = [] if !raws[key]
  1208.          
  1209.           percents[key].push(stats[key][:percent]) unless !stats[key][:percent]
  1210.           raws[key].push(stats[key][:raw]) unless !stats[key][:raw]
  1211.         end # End - if stats[key]
  1212.       }
  1213.     } # End - @upgraders.each
  1214.    
  1215.     (0...EquipUpgrades::Max::StatId).each{|id|
  1216.       if percents[id] # Modify stats by multiplying percentages
  1217.         orig_val = @upg_equip.params[id]
  1218.         percents[id].sort!.each{ |val|
  1219.           mod = upgrade_failed?(failed, orig_val * val) # handle failure case
  1220.           @upg_equip.params[id] = mod + orig_val
  1221.         }
  1222.       end # End - if percents[id]
  1223.      
  1224.       if raws[id] # Modify stats by adding raw values
  1225.         raws[id].each { |val|
  1226.           val = upgrade_failed?(failed, val)
  1227.           @upg_equip.params[id]+= val # handle failure case
  1228.         }
  1229.       end # End - if raws[id]
  1230.     }  # End - (0...EquipUpgrades::Max::StatId).each
  1231.   end # End - modify_stats
  1232.   #
  1233.   # * Update the Equipments List of Current Upgrades
  1234.   #
  1235.   def update_item_upgrades(item)
  1236.     @upg_equip.curr_upgrades.push(item)
  1237.     @upg_equip.add_suffix_upg_era(item.upgrader_suffix)
  1238.     #print "@upg_equip.upgraded_suffixes = #{@upg_equip.upgraded_suffixes}\n"
  1239.   end # End - update_item_upgrades
  1240.   #
  1241.   # * Upgrade Failed
  1242.   #   Calculate the appropriate value to add onto the stat if the upgrade failed
  1243.   #
  1244.   def upgrade_failed?(did_fail, val)
  1245.     mod = $game_player.fail_mod_for_upgrades
  1246.     did_fail ? (val > 0 ? val*-mod : val * mod) : val
  1247.   end # End - upgrade_failed?
  1248. end # End - Scene_UpgradableItem
  1249. #==============================================================================
  1250. # ** Game_Interpreter
  1251. #==============================================================================
  1252. class Game_Interpreter
  1253.   def ra_upg(upgs = nil)
  1254.     SceneManager.call(Scene_UpgradableItem)
  1255.     SceneManager.scene.specify_upgraders(upgs) if upgs
  1256.   end
  1257. end
  1258. #==============================================================================
  1259. # -------------------------------End of File-----------------------------------
  1260. #==============================================================================
Advertisement
Add Comment
Please, Sign In to add comment