blucalm

Same Time Percentage Stack Snipper

Mar 20th, 2013
538
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Ruby 1.96 KB | None | 0 0
  1. # ------------------------------------------------------------------------------
  2. # Same Time Percentage Stack Snippet
  3. # Dependencies: Upg Equips
  4. # ------------------------------------------------------------------------------
  5. # Usage:
  6. # Causes percentages to stack even when all upgrades are used at the same time
  7. # Updates
  8. # 20 Mar 2013 - Initial release
  9. # ------------------------------------------------------------------------------
  10.  
  11. class Scene_UpgradableItem < Scene_ItemBase
  12.   def modify_stats(failed = false)
  13.     percents = {} # maps stat ids to an array of percentages
  14.     raws = {} # maps stat ids to an array of values
  15.    
  16.     # Goes through all the items and condenses all the upgrades into above
  17.     # two hashes
  18.     @upgraders.each{  |item|
  19.       update_item_upgrades(item) #add each 1 to curr upgs list
  20.       stats = item.upgrade_mods.stat_mods
  21.       stats.keys.each{ |key|
  22.         if stats[key]
  23.           percents[key] = [] if !percents[key]
  24.           raws[key] = [] if !raws[key]
  25.          
  26.           percents[key].push(stats[key][:percent]) unless !stats[key][:percent]
  27.           raws[key].push(stats[key][:raw]) unless !stats[key][:raw]
  28.         end # End - if stats[key]
  29.       }
  30.     } # End - @upgraders.each
  31.    
  32.     (0...EquipUpgrades::Max::StatId).each{|id|
  33.       if percents[id] # Modify stats by multiplying percentages
  34.         percents[id].sort!.each do |val|
  35.           curr_val = @upg_equip.params[id]
  36.           mod = upgrade_failed?(failed, curr_val * val) # handle failure case
  37.           @upg_equip.params[id] += mod # + orig_val
  38.         end
  39.       end # End - if percents[id]
  40.      
  41.       if raws[id] # Modify stats by adding raw values
  42.         raws[id].each { |val|
  43.           val = upgrade_failed?(failed, val)
  44.           @upg_equip.params[id]+= val # handle failure case
  45.         }
  46.       end # End - if raws[id]
  47.     }  # End - (0...EquipUpgrades::Max::StatId).each
  48.   end # End - modify_stats
  49. end # End - Scene_UpgradableItem
Advertisement
Add Comment
Please, Sign In to add comment