blucalm

Upg equips for demo v0.12 Mar 20 2013

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