blucalm

Upg equips unique req

Jan 19th, 2013
121
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Ruby 44.82 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:
  8. #     1. Tsuki_CustomDataManager
  9. #     2. Numeric Form Regex
  10. # Recommended (These help to fix bugs among other things):
  11. #     3. Custom DM Array Sizes Snippet
  12. #     4. Custom DB and Party Inventory Cleaner
  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. #  14 Dec 2012 - Neatened up the documentation.
  238. #  13 Dec 2012 - Major Bug Fixes:
  239. #
  240. #                Can now add suffixes to upgraders to be shown on the upgraded
  241. #                equipment.
  242. #                Equipment no longer disappears when you save a game while
  243. #                wearing upgraded equipment.
  244. #
  245. #                Database is now properly managed (tmk) during runtime but custom
  246. #                items are no longer deleted from the database because of the
  247. #                difficulty associated with ensuring an items id is the same
  248. #                as its location in the database when removing and readding items.
  249. #
  250. #                Known Bug, Not fixing yet:
  251. #
  252. #                If you have a saved game with upgraded equipment and you add a
  253. #                new item to the database in the editor, then load that saved
  254. #                game, some of the custom equipment may appear to "disappear"
  255. #                or you may have different items in your inventory.
  256. #
  257. #  12 Dec 2012 - Can now use any symbol when specfying upgraders, not just A-Z
  258. #                slight changes to note tags, can replace 'mod' with 'upg'
  259. #  10 Dec 2012 - Fixed Freeze during ugrade scene.
  260. #  9 Dec 2012  - Added support to restrict which upgraders can be used during the
  261. #                upgrade scene. Use the script call:
  262. #                ra_upg(ARRAY)
  263. #                ** replace "ARRAY" with an array of strings **
  264. #                to only allow upgrader with a type specified in the array to be
  265. #                used.
  266. #  20 Sept 2012 - Upgraders can now be specified to only be used with a specific
  267. #                 Equipment (use the tags <Upgrader "A"> and <Upgraded By "A">)
  268. #  19 Sept 2012 - Fixed a problem where armor wasn't being upgraded properly.
  269. #                 Was referencing $data_weapons inside deep_copy_clone_2544 of
  270. #                 RPG::Armor, meant to reference $data_armors
  271. #  4 Sept 2012  - UpgradeOrientation::Size::WidthValue can now be used to adjust
  272. #                 the width of the windows in the upgrade scene
  273. #  3 Sept 2012  - Misnamed method update_data_base_upg_equips inside RPG::Armor,
  274. #                 was corrected.
  275. #  29 Aug 2012  - The name of the item has been changed to display how many
  276. #                 upgrades have been used on it.
  277. #               - Upgraded equipment is now removed from the database also when it
  278. #                 is being removed the party's inventory
  279. #               - Text now fits correctly in the equipment selection options window
  280. #
  281. #  28 Aug 2012  - Added notetag support to limit the amount of upgrades that can
  282. #                 be used on an item. <!upgradable9> limits the item to no more
  283. #                 than nine upgrades.
  284. #               - Added a nil check to fix a crash that was happening when
  285. #                 selecting a blank item.
  286. #               - Fixed a NameError. Updated a module constant name I had
  287. #                 forgotten to change after moving the constant to a new module.
  288. #               - Fixed overlapping text inside the item list window
  289. #--------------------------------------------------------------------------------
  290.  
  291. $imported = {} if $imported.nil?
  292. raise "Upgradable Equipment requires Tsuki_CustomDataManager" unless $imported["Tsuki_CustomDataManager"]
  293. raise "Upgradable Equipment requires module NumericForm" unless $imported["Numeric Form Regex"]
  294. $imported["Ra Upgradable Equipment"] = true
  295.  
  296. #==============================================================================
  297. # Settings, these can be modified to customize the script a bit.
  298. #==============================================================================
  299. #
  300. # * UpgradeOrientation
  301. # Window orientation
  302. #
  303. module UpgradeOrientation
  304.   module Size
  305.     WidthValue = 0.6 # Modifies the width of the windows in the upgrade scene
  306.   end
  307. end # End - UpgradeOrientation
  308.  
  309. #
  310. # * EquipUpgrades
  311. # Handles settings the user can modify for various effects.
  312. #
  313. module EquipUpgrades
  314.  
  315.   Only_Show_Most_Recent_Suffix = false # set to false to show all suffixes
  316.   Show_Upgrade_Quantity_In_Name = false # true = show number of upgrades in name
  317.   Max_Suffixes = 2 # maximum num of suffixes to be show in an equips name
  318.  
  319.   module Regexp # The regular expressions used to parse upgraders, etc.
  320.     State = /<(?:Mod|upg) STATE(?:=| )(\d+) (\d+)%>/i
  321.     StatPercent = /<(?:Mod|upg) STAT(?:=| )(\d+|all) (\+|\-)(\d+)%>/i
  322.     StatRaw = /<(?:Mod|upg) STAT(?:=| )(\d+|all) (\+|\-)(\d+)>/i
  323.     Upgradable = /<(?:!|)upgradable(?: |)(\d+|)>/i
  324.     Upgrader = /<(?:!|)(?:upgrader) (.+)>/i # upgraders can be given an upgrader type
  325.     Upgraded_By = /<(?:!|)(?:upgraded by) (.+)>/i # only effected be upgraders w/ this no.
  326.     Upg_Suffix = /<\s*upg\s*suffix\s*(.+)>/i
  327.   end # End - Regexp
  328.  
  329.   module Player
  330.     DefaultFailRate = 0 # When determining success, a number is generated between
  331.                          # 0 and 100. if the generated number + 1 is less than
  332.                          # fail_rate then the upgrade is unsuccessful.
  333.                          # By default increasing the DefaultFailRate to 1 gives
  334.                          # a 1% fail rate, 2=2%, etc.
  335.     SuccessAnimation = 33
  336.     FailAnimation = 96
  337.     FailureMod = 0.9 # modifes the effect of failing to upgrade by the
  338.                      # specified rate
  339.     DisplayAnimation = true # Set this to false to turn off the animations
  340.   end # End - Player
  341.  
  342.   module Max
  343.     StatId = 8 # The number of stats the original value in ace is 8
  344.     BaseRVal = 100 # The highest random number generated will be this value
  345.                    # minus 1. the formula for calculating upgrade success is:
  346.                    # random_val < BaseRVal - DefaultFailRate ? success : fail
  347.     IconWidth = 24 # The width of the icons you're using
  348.   end # End - Max
  349.  
  350.   module EquipPhrase
  351.     Equips = "Equipment"
  352.     Upgrader = "Upgrades"
  353.   end # End - EquipPhrase
  354.  
  355.   module Symbols
  356.     UpgAll = :upgrade_all
  357.     AcpAll = :accept_all
  358.   end
  359. end # End - EquipUpgrades
  360. #==============================================================================
  361. # End of Settings, don't modify below here unless you know what you're doing.
  362. #==============================================================================
  363.  
  364. #==============================================================================
  365. # ** Window_Selectable
  366. #==============================================================================
  367. class Window_Selectable < Window_Base
  368.   def get_curr_index
  369.     @index && @index >= 0 ? @index : 0
  370.   end
  371. end # End - Window_Selectable
  372.  
  373. #==============================================================================
  374. # ** Game_Player
  375. #       # new attributes are added to the game player to control upgrade failure
  376. #       # rate.
  377. #==============================================================================
  378. class Game_Player < Game_Character
  379.   attr_accessor :fail_rate_for_upgrades
  380.   attr_accessor :fail_mod_for_upgrades
  381.  
  382.   alias game_pl_init_method_uni_fail_rate_upgrades_1842693 initialize
  383.   def initialize
  384.     game_pl_init_method_uni_fail_rate_upgrades_1842693
  385.     @fail_rate_for_upgrades = EquipUpgrades::Player::DefaultFailRate
  386.     @fail_mod_for_upgrades = EquipUpgrades::Player::FailureMod
  387.   end
  388. end # End - Game_Player
  389.  
  390. #==============================================================================
  391. # ** Window_UpgradeItemList
  392. #------------------------------------------------------------------------------
  393. #  This window displays a upgradable items and items that can be used as
  394. #  upgraders.
  395. #==============================================================================
  396. class Window_UpgradeItemList < Window_ItemList
  397.  
  398.   attr_accessor :data
  399.   attr_accessor :only_enable_upgradables
  400.  
  401.   #
  402.   # Get Activation State of Selection Item
  403.   #
  404.   def current_item_enabled?; enable?(@data[index]); end
  405.  
  406.   #
  407.   # Display in Enabled State?
  408.   #
  409.   def enable?(item)
  410.     only_enable_upgradables ? item && item.is_upgradable : item && item.upgrade_mods
  411.   end
  412.  
  413.   #
  414.   # * Draw Item
  415.   #
  416.   def draw_item(index)
  417.     item = @data[index]
  418.     if item
  419.       rect = item_rect(index)
  420.       rect.width -= 4
  421.       draw_item_name(item, rect.x, rect.y, enable?(item), 90)
  422.       draw_item_number(rect, item)
  423.     end
  424.   end
  425.  
  426.   #
  427.   # * Draw Item Number
  428.   #
  429.   def draw_item_number(rect, item)
  430.     draw_text(rect, sprintf("%2d", $game_party.item_number(item)), 2)
  431.   end
  432. end # End- Window_UpgradeItemList
  433.  
  434. #==============================================================================
  435. # ** Window_UpgradeItemCategory
  436. #------------------------------------------------------------------------------
  437. #  The category window for the upgradable items scene
  438. #==============================================================================
  439. class Window_UpgradeItemCategory < Window_ItemCategory
  440.   def window_width
  441.     Graphics.width * UpgradeOrientation::Size::WidthValue
  442.   end
  443.  
  444.   def col_max
  445.     return 4
  446.   end
  447.  
  448.   #
  449.   # The categories of items that are displayed in the upgradable scene
  450.   #
  451.   def make_command_list
  452.     add_command(Vocab::weapon,   :weapon)
  453.     add_command(Vocab::armor,    :armor)
  454.     add_command(Vocab::item,     :item)
  455.     add_command(Vocab::key_item, :key_item)
  456.   end
  457. end # End - Window_UpgradeItemCategory
  458.  
  459. #==============================================================================
  460. # ** Window_UpgradeItemCategory
  461. #------------------------------------------------------------------------------
  462. #  The window which displays the icons for the items which are being used to do
  463. #  the upgrade
  464. #==============================================================================
  465. class Window_DisplayUpgrades < Window_Base
  466.   attr_accessor :content_icons
  467.  
  468.   def initialize(x,y,h)
  469.     @window_width =(1-UpgradeOrientation::Size::WidthValue)*Graphics.width
  470.     super(x,y,@window_width,h)
  471.     @content_names, @content_icons = [], []
  472.   end # End - initialize
  473.  
  474.   def set_item(item)
  475.     contents.clear
  476.     draw_item_name(item,0,0,true,@window_width-40)
  477.   end # End - set_item
  478.  
  479.   def add_new_icon(id)
  480.     @content_icons.push(id)
  481.     draw_all_icons
  482.   end # End - add_new_icon
  483.  
  484.   def draw_all_icons
  485.     contents.clear
  486.     index, x_pos = 0,0
  487.     @content_icons.each{ |id|
  488.       draw_icon(id, x_pos, line_height * index, true)
  489.       index += 1
  490.       if(index > 6)
  491.         index = 0
  492.         x_pos += EquipUpgrades::Max::IconWidth
  493.       end # End - index > 6
  494.     } # End - @content_icons.each
  495.   end # End - draw_all_icons
  496.  
  497.   def clear_all
  498.     contents.clear
  499.     @content_names = []
  500.     @content_icons = []
  501.   end # End - clear_all
  502. end # End - Window_DisplayUpgrades
  503.  
  504.  
  505.  
  506. class Window_UpgradeSelection < Window_HorzCommand
  507.  
  508.   #
  509.   # Public Instance Variables
  510.   #
  511.   attr_reader   :item_window
  512.  
  513.   #
  514.   # Object Initialization
  515.   #
  516.   def initialize(x,y, upgrader)
  517.     @type = upgrader
  518.     @col_max = upgrader ? 3 : 2
  519.     super(x, y)
  520.   end # End - initialize
  521.  
  522.   #
  523.   # Get Window Width
  524.   #
  525.   def window_width
  526.     Graphics.width * (1-UpgradeOrientation::Size::WidthValue)
  527.   end # End - window_width
  528.  
  529.   #
  530.   # Get Digit Count
  531.   #
  532.   def col_max
  533.     return @col_max
  534.   end # End - col_max
  535.  
  536.   #
  537.   # Create Command List
  538.   #
  539.   def make_command_list
  540.     if !@type
  541.       add_command(EquipUpgrades::EquipPhrase::Equips,     :equip)
  542.       add_command("Ok", :advance)
  543.     else
  544.       add_command(EquipUpgrades::EquipPhrase::Upgrader,     :upgrades)
  545.       add_command("Clear", :clear)
  546.       add_command("Done", :done)
  547.     end # End - if !@type
  548.   end # End - make_command_list
  549. end # End - Window_UpgradeSelection
  550.  
  551. #==============================================================================
  552. # ** DataManager
  553. #==============================================================================
  554. module DataManager
  555.   #
  556.   # * alias load_database
  557.   #
  558.   class <<self; alias load_db_upgrade_mods_82372934 load_database; end
  559.   def self.load_database
  560.     load_db_upgrade_mods_82372934
  561.     load_ntags_upgrade_mods_82372933
  562.   end
  563.  
  564.   #
  565.   # load_ntags_upgrade_mods_82372933
  566.   #
  567.   def self.load_ntags_upgrade_mods_82372933
  568.     groups = [$data_armors, $data_weapons, $data_items]
  569.     for group in groups
  570.       for obj in group
  571.         next if obj.nil?
  572.         obj.load_ntags_upgrade_mods
  573.       end
  574.     end
  575.   end
  576.  
  577. end # DataManager
  578.  
  579. #==============================================================================
  580. # ** RPG::BaseItem
  581. #==============================================================================
  582. class RPG::BaseItem
  583.  
  584.    def to_s
  585.      "#{@name} #{@id}"
  586.    end
  587.  
  588.    attr_accessor :max_upgrades # The max number of upgrades usable on this item
  589.    attr_accessor :curr_upgrades # list of current upgrades on this item
  590.    attr_accessor :upgrade_mods
  591.    attr_accessor :is_upgradable
  592.    attr_accessor :orig_name # Used when making deep copies and it's necessary
  593.                             # to know the name of the original item while still
  594.                             # being able to change the name of the new item.
  595.    attr_accessor :upgraded_by # A hash of symbols corresponding to ids for items
  596.                               # that can be used to upgrade this item.
  597.    attr_accessor :upgrader_ids # symbol representing the type of upgradable equips
  598.                               # this can upgrade.
  599.    attr_accessor :upgrader_suffix # suffix an upgrader adds to the name of an item.
  600.    attr_accessor :upgraded_suffixes # list of suffixes on upgraded equipment
  601.    attr_accessor :is_upg_dupe
  602.    #
  603.    # Parses notetags and stores corresponding data
  604.    #
  605.    def load_ntags_upgrade_mods
  606.     init_fields_upg_era
  607.     self.note.split(/[\r\n]+/).each { |line|
  608.       next unless line != nil# && $1 != nil
  609.       case line
  610.       when EquipUpgrades::Regexp::State
  611.         add_state_upgrade_mods($1.to_i, $2.to_i)
  612.       when EquipUpgrades::Regexp::StatPercent
  613.         add_stat_mod(:percent, $1, $3.to_i, $2)
  614.       when EquipUpgrades::Regexp::StatRaw
  615.         add_stat_mod(:raw, $1, $3.to_i, $2)
  616.       when EquipUpgrades::Regexp::Upgradable
  617.         @is_upgradable = true
  618.         if (val=$1.to_s) =~ NumericForm::Regex #init max upgrades if it was defined
  619.           @max_upgrades = val.to_i
  620.           @curr_upgrades = []
  621.         end
  622.       when EquipUpgrades::Regexp::Upgrader
  623.         (@upgrader_ids ||= []).push($1.to_sym)
  624.       when EquipUpgrades::Regexp::Upgraded_By
  625.         (@upgraded_by ||= {})[$1.to_sym] = true
  626.       when EquipUpgrades::Regexp::Upg_Suffix
  627.         @upgrader_suffix = $1
  628.       end
  629.     }
  630.     init_upgrade_id
  631.   end # End - load_ntags_upgrade_mods
  632.  
  633.   #
  634.   # initializes :accept_all to true inside the upgraded_by hash if it's nil
  635.   #
  636.   def init_upgrade_id
  637.     (@upgraded_by = {})[EquipUpgrades::Symbols::AcpAll] = true if @upgraded_by.nil?
  638.     (@upgrader_ids=[]).push(EquipUpgrades::Symbols::UpgAll) unless !@upgrader_ids.nil?
  639.   end # End - init_upgrade_id_hashes
  640.   #
  641.   #
  642.   #
  643.   def init_fields_upg_era
  644.     @upgrader_suffix, @upgraded_suffixes,@max_upgrades = "",[], 1<<31
  645.     @curr_upgrades = []
  646.   end
  647.  
  648.   #
  649.   # store state modifiers
  650.   #
  651.   def add_state_upgrade_mods(id, val)
  652.     init_upgrade_mods
  653.     @upgrade_mods.store_state_mod(id, val * 0.01)
  654.   end # End - add_state_upgrade_mods
  655.  
  656.   #
  657.   # store base stat modifiers percentages mapped from :percent, raw values from
  658.   # :raw
  659.   #
  660.   def add_stat_mod(sym, id, val, op)
  661.     init_upgrade_mods
  662.     val *= 0.01 if sym == :percent
  663.     val = op.eql?("-") ? -val : val
  664.     @upgrade_mods.store_stat_mod(sym, id, val)
  665.   end
  666.  
  667.   #
  668.   # initialize @upgrade_mods if it is nil
  669.   #
  670.   def init_upgrade_mods
  671.     @upgrade_mods = Equipment_Upgrader.new unless @upgrade_mods
  672.   end
  673.  
  674.   #
  675.   # adds a new feature to the item
  676.   #
  677.   def add_new_feature_upg(feature); @features.push(feature); end
  678.  
  679.   #
  680.   #
  681.   #
  682.   def add_suffix_upg_era(suffix)
  683.     upgraded_suffixes.push(suffix) unless !suffix || suffix.eql?("")
  684.   end
  685.  
  686.   #
  687.   # Check if This is an Armor or Weapon
  688.   #
  689.   def is_equip?
  690.     self.is_a?(RPG::Armor) || self.is_a?(RPG::Weapon)
  691.   end
  692.  
  693.   #
  694.   # * Upgraded Name
  695.   #
  696.   def upgrade_name
  697.    
  698.     @name = @orig_name
  699.     size = @upgraded_suffixes.size
  700.    
  701.     if EquipUpgrades::Only_Show_Most_Recent_Suffix
  702.       @name += (" "<<@upgraded_suffixes[size-1] unless @upgraded_suffixes.empty?)
  703.     else
  704.       @upgraded_suffixes.each_with_index do |s,i|
  705.         @name+=" " if i == 0
  706.         i != size-1 ? @name+=(s<<" ") : @name+=s
  707.         break if i + 1 == EquipUpgrades::Max_Suffixes
  708.       end
  709.     end
  710.    
  711.     if EquipUpgrades::Show_Upgrade_Quantity_In_Name
  712.       @name += " +#{@curr_upgrades.size}"
  713.     end
  714.   end # End - upgrade_name
  715. end # End - RPG::BaseItem
  716.  
  717. #==============================================================================
  718. # ** RPG::Weapon
  719. #------------------------------------------------------------------------------
  720. # A Method to create a deep copy is added
  721. #==============================================================================
  722. class RPG::Weapon < RPG::EquipItem
  723.  
  724.   #
  725.   # * Deep Copy
  726.   #
  727.   def deep_copy_clone_2544
  728.     (wep = Marshal.load(Marshal.dump(self))).id = $data_weapons.size
  729.     wep.orig_name = @orig_name ? @orig_name : (@orig_name = wep.name)
  730.     wep.description = wep.description #+ " (Upgraded)"
  731.     update_database_upg_equips(wep)
  732.     wep
  733.   end # End - deep_copy_clone_2544
  734.  
  735.   #
  736.   # * Update Database
  737.   #
  738.   def update_database_upg_equips(wep=nil)
  739.     #print "custom weapons size before update = #{$custom_weapons.size}\n"
  740.    
  741.     # $custom_weapons.delete(self)
  742.     # $data_weapons.delete(self) if @is_upg_dupe
  743.    
  744.     $custom_weapons.push(wep) unless !wep
  745.     $data_weapons.push(wep) unless !wep # update database
  746.     #print "custom weapons size after update = #{$custom_weapons.size}\n"
  747.   end # End - update_database_upg_equips
  748. end # End - RPG::Weapon
  749.  
  750. #==============================================================================
  751. # ** RPG::Armor
  752. #------------------------------------------------------------------------------
  753. # A Method to create a deep copy is added
  754. #==============================================================================
  755. class RPG::Armor < RPG::EquipItem
  756.  
  757.   #
  758.   # * Deep Copy
  759.   #
  760.   def deep_copy_clone_2544
  761.     (arm = Marshal.load(Marshal.dump(self))).id = $data_armors.size
  762.     arm.orig_name = @orig_name ? @orig_name : (@orig_name = arm.name)
  763.     arm.description = arm.description #+ " (Upgraded)"
  764.     update_database_upg_equips(arm)
  765.   end # End - deep_copy_clone_2544
  766.  
  767.   #
  768.   # * Update Database
  769.   #
  770.   def update_database_upg_equips(arm=nil)
  771.     # print "custom armor size before db update #{$custom_armors.size}\n"
  772.    
  773.     # $custom_armors.delete(self)
  774.     # $data_armors.delete(self) if @is_upg_dupe
  775.    
  776.     $custom_armors.push(arm) unless !arm
  777.     $data_armors.push(arm) unless !arm # update database
  778.     # print "custom armor size after db update #{$custom_armors.size}\n"
  779.     arm
  780.   end
  781. end # End - RPG::Armor
  782.  
  783. #==============================================================================
  784. # ** Equipment_Upgrader
  785. #------------------------------------------------------------------------------
  786. #    This class represents a new property for items which will allow those items
  787. #    to represent upgraders which can increase the stats of weapons and armor.
  788. #==============================================================================
  789. class Equipment_Upgrader
  790.   attr_accessor :states
  791.   attr_accessor :stat_mods
  792.  
  793.   def initialize
  794.     @states = {} # maps state ids to the chance of that state being inflicted
  795.     @stat_mods = {} # A hash mapping stat Ids to the symbols :percent and :raw
  796.                     # these determine how much the effected stat is changed.
  797.   end
  798.  
  799.   # The percentage value is stored as a float between -1.00 and 1.00
  800.   def store_stat_mod(sym, stat_id, val, preserve = false, mod = 1)
  801.     @stat_mods[stat_id.to_i] = {} unless @stat_mods[stat_id.to_i]
  802.     mod_all_stats(sym, stat_id, val, preserve, mod) unless stat_id.to_s =~ NumericForm::Regex
  803.     @stat_mods[stat_id.to_i][sym] = preserve ? @stat_mods[stat_id][sym] + val : val
  804.   end
  805.  
  806.   #
  807.   # stores data which will be added to item.features
  808.   #
  809.   def store_state_mod(state_id, val, preserve = false, mod = 1)
  810.      @states[state_id] = preserve ?  @states[state_id] + val : val
  811.   end
  812.  
  813.   #
  814.   # stores data which will modify the stats stored in item.params
  815.   #
  816.   def mod_all_stats(sym, stat_id, val, preserve = false, mod = 1)
  817.     (0..7).each{ |id| store_stat_mod(sym, id, val, preserve, mod)}
  818.   end
  819.  
  820.   #
  821.   # Percentage value modifications to stats
  822.   #
  823.   def get_stat_mod_percent(stat_id); @stat_mods[stat_id][:percent]; end
  824.  
  825.   #
  826.   # Non percentage value modifications to stats
  827.   #
  828.   def get_stat_mod_raw(stat_id); @stat_mods[stat_id][:raw]; end
  829.  
  830.   #
  831.   # The percent chance of happening this upgrader gives to the state with
  832.   # id = param: state_id
  833.   #
  834.   def get_state_mod(state_id); @states[state_id]; end
  835.  
  836. end # End - Equip_Upgrader
  837.  
  838. #==============================================================================
  839. # ** Game_Party
  840. #------------------------------------------------------------------------------
  841. #    Alias Methods:
  842. #       gain_item: new functionality to remove upgraded equipment when necessary
  843. #==============================================================================
  844. class Game_Party < Game_Unit
  845.   #
  846.   # * alias method: gain_item
  847.   #   removes custom equipment from $custom_[type] if all of param item would
  848.   #   be removed from the party's inventory
  849.   #
  850.   alias gain_item_upg_equips_update_db gain_item
  851.   def gain_item(item, amount, include_equip = false)
  852.     item.update_database_upg_equips if delete_custom?(item, amount)
  853.     gain_item_upg_equips_update_db(item, amount, include_equip)
  854.   end # End - gain_item
  855.   #
  856.   # * Check to Remove Custom Equipment From Database
  857.   #
  858.   def delete_custom?(item, amount)
  859.     # false
  860.     item && item.is_equip? && amount < 0 && -amount >= item_number(item) && item.is_upg_dupe
  861.   end # End - delete_custom?
  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 = false
  1115.     @item_window.only_enable_upgradables = @item_is_upgrader = true
  1116.     @upgrades_selection_window.activate
  1117.     @upgrades_selection_window.select(@upgrades_selection_window.get_curr_index)
  1118.   end # End - turn_on_upgrades_selection
  1119.   #
  1120.   # * Check to see if the current item can be upgraded by the selected upgrader
  1121.   #
  1122.   def check_can_upgrade
  1123.    
  1124.     # print "item.upgrader_ids = #{item.upgrader_ids.inspect}\n"
  1125.    
  1126.     max = @upg_equip.max_upgrades
  1127.     size = @upg_equip.curr_upgrades.size # amount of upgrades on equip so far
  1128.     return false if size + @upgrades_display_window.content_icons.size >= max
  1129.    
  1130.     included_type = false
  1131.     @ok_upgs ||= []
  1132.     #print "@ok_upgs = #{@ok_upgs.inspect}\n"
  1133.     #print "@upg_equip.upgraded_by = #{@upg_equip.upgraded_by}\n"
  1134.     #print "item.upgrader_ids = #{item.upgrader_ids}\n"
  1135.    
  1136.     item.upgrader_ids.each do |sym|
  1137.       return true if @ok_upgs.include?(sym.to_s)
  1138.       included_type = true if @upg_equip.upgraded_by[sym]
  1139.     end
  1140.     return false if !@ok_upgs.empty?
  1141.    
  1142.     return true if @upg_equip.upgraded_by[EquipUpgrades::Symbols::AcpAll]
  1143.     return true if item.upgrader_ids.include? EquipUpgrades::Symbols::UpgAll
  1144.    
  1145.     # print "item #{item.name}, upgrader_ids = #{item.upgrader_ids.inspect}\n"
  1146.     # item.upgrader_ids.each{|sym| return true if @upg_equip.upgraded_by[sym]}
  1147.     included_type
  1148.    
  1149.   end
  1150.   #
  1151.   # * Perform the Upgrade
  1152.   #   Change the stats on the item that is being upgraded (or downgraded)
  1153.   def perform_upgrade
  1154.     return unless upgrade_is_valid? # Make sure the current upgrade is ok
  1155.     @upg_equip = @upg_equip.deep_copy_clone_2544 # deep copy
  1156.     modify_stats(failure = upgrade_successful?) # Modify stats based on success
  1157.     add_new_features(13) unless failure# 13 is the default code for states
  1158.     set_player_animation(failure)
  1159.     @upg_equip.upgrade_name # Change the name
  1160.     @upg_equip.is_upg_dupe = true
  1161.     $game_party.gain_item(@upg_equip, 1)
  1162.    
  1163.     Era::CleanCDB.clean
  1164.     print "$data_armors = #{$data_armors}\n"
  1165.     print "$data_weapons = #{$data_weapons}\n"
  1166.     print "$custom_armors = #{$custom_armors}\n"
  1167.     print "$custom_weapons = #{$custom_weapons}\n"
  1168.    
  1169.     SceneManager.return
  1170.   end # End - perform_upgrade
  1171.  
  1172.   # * Check if Upgrading is acceptable (i.e. no nil vals/ non-equip items, etc.)
  1173.   def upgrade_is_valid?
  1174.     # Check if the current upgrade is valid, if not then return
  1175.     return true unless (@upgraders.empty? || !@upg_equip.is_a?(RPG::EquipItem))
  1176.     turn_on_upgrades_selection
  1177.     false
  1178.   end # End - upgrade_is_valid?
  1179.   #
  1180.   # * Was the Upgrade Successful?
  1181.   #
  1182.   def upgrade_successful?
  1183.     rand(EquipUpgrades::Max::BaseRVal) < $game_player.fail_rate_for_upgrades
  1184.   end # End - upgrade_successful?
  1185.   #
  1186.   # * Set Player Animation
  1187.   #
  1188.   def set_player_animation(fail)
  1189.     return unless EquipUpgrades::Player::DisplayAnimation
  1190.     $game_player.animation_id = EquipUpgrades::Player::SuccessAnimation unless fail
  1191.     $game_player.animation_id = EquipUpgrades::Player::FailAnimation if fail
  1192.   end # End - set_player_animation
  1193.   #
  1194.   # * Add New Features
  1195.   #   Creates new features to add to item.features
  1196.   #
  1197.   def add_new_features(code)
  1198.     @upgraders.each{ |item|
  1199.       states = item.upgrade_mods.states
  1200.       states.keys.each{ |key|
  1201.         feature = RPG::BaseItem::Feature.new(code, key, states[key])
  1202.         @upg_equip.add_new_feature_upg(feature)
  1203.       }
  1204.     }
  1205.   end # End - add_new_features
  1206.   #
  1207.   # * Modify Stats
  1208.   #   percentages are applied to stats starting with the smallest percentage
  1209.   #   increasing to the largest. Percentage bonuses are applied before raw bonuses
  1210.   #
  1211.   def modify_stats(failed = false)
  1212.     percents = {} # maps stat ids to an array of percentages
  1213.     raws = {} # maps stat ids to an array of values
  1214.    
  1215.     # Goes through all the items and condenses all the upgrades into above
  1216.     # two hashes
  1217.     @upgraders.each{  |item|
  1218.       update_item_upgrades(item) #add each 1 to curr upgs list
  1219.       stats = item.upgrade_mods.stat_mods
  1220.       stats.keys.each{ |key|
  1221.         if stats[key]
  1222.           percents[key] = [] if !percents[key]
  1223.           raws[key] = [] if !raws[key]
  1224.          
  1225.           percents[key].push(stats[key][:percent]) unless !stats[key][:percent]
  1226.           raws[key].push(stats[key][:raw]) unless !stats[key][:raw]
  1227.         end # End - if stats[key]
  1228.       }
  1229.     } # End - @upgraders.each
  1230.    
  1231.     (0...EquipUpgrades::Max::StatId).each{|id|
  1232.       if percents[id] # Modify stats by multiplying percentages
  1233.         orig_val = @upg_equip.params[id]
  1234.         percents[id].sort!.each{ |val|
  1235.           mod = upgrade_failed?(failed, orig_val * val) # handle failure case
  1236.           @upg_equip.params[id] = mod + orig_val
  1237.         }
  1238.       end # End - if percents[id]
  1239.      
  1240.       if raws[id] # Modify stats by adding raw values
  1241.         raws[id].each { |val|
  1242.           val = upgrade_failed?(failed, val)
  1243.           @upg_equip.params[id]+= val # handle failure case
  1244.         }
  1245.       end # End - if raws[id]
  1246.     }  # End - (0...EquipUpgrades::Max::StatId).each
  1247.   end # End - modify_stats
  1248.   #
  1249.   # * Update the Equipments List of Current Upgrades
  1250.   #
  1251.   def update_item_upgrades(item)
  1252.     @upg_equip.curr_upgrades.push(item)
  1253.     @upg_equip.add_suffix_upg_era(item.upgrader_suffix)
  1254.     #print "@upg_equip.upgraded_suffixes = #{@upg_equip.upgraded_suffixes}\n"
  1255.   end # End - update_item_upgrades
  1256.   #
  1257.   # * Upgrade Failed
  1258.   #   Calculate the appropriate value to add onto the stat if the upgrade failed
  1259.   #
  1260.   def upgrade_failed?(did_fail, val)
  1261.     mod = $game_player.fail_mod_for_upgrades
  1262.     did_fail ? (val > 0 ? val*-mod : val * mod) : val
  1263.   end # End - upgrade_failed?
  1264. end # End - Scene_UpgradableItem
  1265. #==============================================================================
  1266. # ** Game_Interpreter
  1267. #==============================================================================
  1268. class Game_Interpreter
  1269.   def ra_upg(upgs = nil)
  1270.     SceneManager.call(Scene_UpgradableItem)
  1271.     SceneManager.scene.specify_upgraders(upgs) if upgs
  1272.   end
  1273. end
  1274. #==============================================================================
  1275. # -------------------------------End of File-----------------------------------
  1276. #==============================================================================
Advertisement
Add Comment
Please, Sign In to add comment