blucalm

Upg Equips Neatened Doc 14 Dec 2012

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