blucalm

Upgradable Equipment

Aug 28th, 2012
150
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 31.48 KB | None | 0 0
  1. #===============================================================================
  2. #===============================================================================
  3. # - Upgradable Equipment 0.0 -
  4. # - Eshra & Emmanuel Derose -
  5. #===============================================================================
  6. #===============================================================================
  7. # -~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-
  8. # Version 0.0: Release Date August 28, 2012
  9. # Updates:
  10. # 2012 Aug 28 - Added notetag support to limit the amount of upgrades that can
  11. # be used on an item. <!upgradable9> limits the item to no more
  12. # than nine upgrades.
  13. #
  14. # -----------------------------------------------------------------------------
  15. # Bug Fixes:
  16. # -----------------------------------------------------------------------------
  17. # 2012 Aug 28 - Added a nil check to fix a crash when selecting a blank item.
  18. # 2012 Aug 28 - Fixed a NameError. Updated a constant name which I had
  19. # forgotten to change after moving the constant to a new module.
  20. # -~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-
  21. # -~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~ Setup -~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~
  22. # -~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-
  23. # To install this script, copy and paste it under the materials section and
  24. # above main. This script requires the following bit of code to work:
  25. #
  26. # $imported = {} unless $imported
  27. # $imported["Numeric Form Regex"] = true
  28.  
  29. # module NumericForm
  30. # Regex = /\A(?:-|)\d+(?:\.|)(?:\d+|)\Z/
  31. # end
  32. #
  33. # This is because I don't want to include it in every script I write that needs
  34. # it so just copy and paste that module and the imported hash into a this
  35. # section above everything else or into a separate slot in the editor.
  36. #
  37. # -~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-
  38. # -~-~-~-~-~-~-~-~-~-~-~-~-~-~-~- How to Use -~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~
  39. # -~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-
  40. # You can now add notetags to your items which will allow them to be used as
  41. # upgraders for other items. Add this notetag:
  42. # <!Upgradable>
  43. # To each item that you want to be able to upgrade. Currently only equipment can
  44. # be upgraded.
  45. # You can also add a number after the word upgradable to limit the amount of
  46. # upgrades that can be used on that item. For example:
  47. # <!Upgradable3> limits the amount of upgrades that can be used on an item with
  48. # this tag to 3.
  49. # After you've done that you should create an item that can be used as an
  50. # upgrader. The upgrader notetags should look like this (or just see the regex):
  51. #
  52. # <Mod STAT=5 +90>
  53. # or
  54. # <Mod STAT=8 +90%>
  55. # or
  56. # <Mod STAT=all +90%>
  57. # or
  58. # <Mod STATE=5 15%>
  59. #
  60. # The numbers can be replaced by other numbers. The + sign can also be
  61. # a - sign (a hyphen). The percent signs are required except in the first case.
  62. # When there is no percenet sign present when using the keyword STAT, the
  63. # number following the + or - is considered a raw value (it is required when
  64. # using the keyword STATE). Capitalizaton does not matter.
  65. #
  66. # STAT=number means the stat with an id equal to 'number' will be modified.
  67. # The default id numbers for stats in Ace are:
  68. #
  69. # Max HP: 0 Max MP: 1 Attack Power: 2 Defense: 3 Magic Power: 4 Magic Defense: 5
  70. # Agility: 6 Luck: 7
  71. #
  72. # The notetag <Mod STAT=5 +143> means
  73. # This item will increase the magic defense stat of the equipment it is used to
  74. # upgrade by 143.
  75. # If there was a percent sign after the 143:
  76. # <Mod STAT=5 +143%>
  77. # The magic defense stat for the equipment it was used on would be increased by
  78. # 143% of its original value. If the + sign was changed to a minus the increases
  79. # would become decreases instead. When multiple upgraders with percentage
  80. # modifications are used to upgrade an equipment piece at the same time, the
  81. # percentages modify the original value in ascending order. The change from each
  82. # modification is applied in this order, then the next modification is applied.
  83. #
  84. # The keyword all can be used after STAT= inplace of a number
  85. # <Mod STAT=all +15%>
  86. # This notetag would make all of the stats of the equipment that is upgraded
  87. # with this item to be increased by 15%.
  88. #
  89. # States can also be added to items:
  90. # <Mod STATE=2 45%>
  91. # When an upgrader with this notetag is used to upgrade a piece of equipment,
  92. # that equipment will gain a 45% chance of inflicting state 2.
  93. #
  94. # ---------------------------- Calling the Script ------------------------------
  95. # The Upgrade Window can be brought up from an event with this script call:
  96. #
  97. # SceneManager.call(Scene_UpgradableItem)
  98. #
  99. # ------------------------------- Failure Rate --------------------------------
  100. # The chance that an upgrade will be successful can be modified in
  101. # EquipUpgrades::Player::DefaultFailRate below. Or it can be modified during
  102. # runtime by accessing $game_player.fail_rate_for_upgrades
  103. #
  104. # By default, increasing the value by 1 increases the failure rate by 1%, this
  105. # will change though if EquipUpgrades::Max::BaseRVal is modified.
  106. # The failure rate at the start of a new game will be equal to
  107. # EquipUpgrades::Player::DefaultFailRate/ EquipUpgrades::Max::BaseRVal
  108. #
  109.  
  110.  
  111. $imported = {} if $imported.nil?
  112. raise "Upgradable Equipment requires Tsuki_CustomDataManager" unless $imported["Tsuki_CustomDataManager"]
  113. raise "Upgradable Equipment requires module Numeric Form" unless $imported["Numeric Form Regex"]
  114.  
  115. $imported["Upgradable Equipment 0986"] = true
  116.  
  117. #==============================================================================
  118. # Settings, these can be modified to customize the script a bit.
  119. #==============================================================================
  120. #
  121. # Window orientation, not implemented currently
  122. #
  123. module UpgradeOrientation
  124. module Size
  125. WidthValue = 0.6
  126. end
  127. end # End - UpgradeOrientation
  128.  
  129. module EquipUpgrades
  130. module Regexp # The regular expressions used to parse upgraders, etc.
  131. State = /<Mod STATE=(\d+) (\d+)%>/i
  132. StatPercent = /<Mod STAT=(\d+|all) (\+|\-)(\d+)%>/i
  133. StatRaw = /<Mod STAT=(\d+|all) (\+|\-)(\d+)>/i
  134. Upgradable = /<!Upgradable(\d+|)>/i
  135. end # End - Regexp
  136.  
  137. module Player
  138. DefaultFailRate = 0 # When determining success, a number is generated between
  139. # 0 and 100. if the generated number + 1 is less than
  140. # fail_rate then the upgrade is unsuccessful.
  141. # By default increasing the DefaultFailRate to 1 gives
  142. # a 1% fail rate, 2=2%, etc.
  143. SuccessAnimation = 33
  144. FailAnimation = 96
  145. FailureMod = 0.9 # modifes the effect of failing to upgrade by the
  146. # specified rate
  147. DisplayAnimation = true # Set this to false to turn off the animations
  148. end # End - Player
  149.  
  150. module Max
  151. StatId = 8 # The number of stats the original value in ace is 8
  152. BaseRVal = 100 # The highest random number generated will be this value
  153. # minus 1. the formula for calculating upgrade success is:
  154. # random_val < BaseRVal - DefaultFailRate ? success : fail
  155. IconWidth = 24
  156. end # End - Max
  157.  
  158. module EquipPhrase
  159. Equips = "Equipment"
  160. Upgrader = "Upgrades"
  161. end # End - EquipPhrase
  162. end # End - EquipUpgrades
  163. #==============================================================================
  164. # End of Settings, don't modify below here unless you know what you're doing.
  165. #==============================================================================
  166.  
  167. #==============================================================================
  168. # ** Window_Selectable
  169. #==============================================================================
  170. class Window_Selectable < Window_Base
  171. def get_curr_index
  172. @index && @index >= 0 ? @index : 0
  173. end
  174. end # End - Window_Selectable
  175.  
  176. #==============================================================================
  177. # ** Game_Player
  178. # # new attributes are added to the game player to control upgrade failure
  179. # # rate.
  180. #==============================================================================
  181. class Game_Player < Game_Character
  182. attr_accessor :fail_rate_for_upgrades
  183. attr_accessor :fail_mod_for_upgrades
  184.  
  185. alias game_pl_init_method_uni_fail_rate_upgrades_1842693 initialize
  186. def initialize
  187. game_pl_init_method_uni_fail_rate_upgrades_1842693
  188. @fail_rate_for_upgrades = EquipUpgrades::Player::DefaultFailRate
  189. @fail_mod_for_upgrades = EquipUpgrades::Player::FailureMod
  190. end
  191. end # End - Game_Player
  192.  
  193. #==============================================================================
  194. # ** Window_UpgradeItemList
  195. #------------------------------------------------------------------------------
  196. # This window displays a upgradable items and items that can be used as
  197. # upgraders.
  198. #==============================================================================
  199. class Window_UpgradeItemList < Window_ItemList
  200.  
  201. attr_accessor :data
  202. attr_accessor :only_enable_upgradables
  203.  
  204. #
  205. # Get Activation State of Selection Item
  206. #
  207. def current_item_enabled?
  208. enable?(@data[index])
  209. end
  210.  
  211. #
  212. # Display in Enabled State?
  213. #
  214. def enable?(item)
  215. only_enable_upgradables ? item && item.is_upgradable : item && item.upgrade_mods
  216. end
  217. end # End- Window_UpgradeItemList
  218.  
  219. #==============================================================================
  220. # ** Window_UpgradeItemCategory
  221. #------------------------------------------------------------------------------
  222. # The category window for the upgradable items scene
  223. #==============================================================================
  224. class Window_UpgradeItemCategory < Window_ItemCategory
  225. def window_width
  226. Graphics.width * UpgradeOrientation::Size::WidthValue
  227. end
  228.  
  229. def col_max
  230. return 4
  231. end
  232.  
  233. #
  234. # The categories of items that are displayed in the upgradable scene
  235. #
  236. def make_command_list
  237. add_command(Vocab::weapon, :weapon)
  238. add_command(Vocab::armor, :armor)
  239. add_command(Vocab::item, :item)
  240. add_command(Vocab::key_item, :key_item)
  241. end
  242. end # End - Window_UpgradeItemCategory
  243.  
  244. #==============================================================================
  245. # ** Window_UpgradeItemCategory
  246. #------------------------------------------------------------------------------
  247. # The window which displays the icons for the items which are being used to do
  248. # the upgrade
  249. #==============================================================================
  250. class Window_DisplayUpgrades < Window_Base
  251. attr_accessor :content_icons
  252.  
  253. def initialize(x,y,h)
  254. @window_width =(1-UpgradeOrientation::Size::WidthValue)*Graphics.width
  255. super(x,y,@window_width,h)
  256. @content_names, @content_icons = [], []
  257. end # End - initialize
  258.  
  259. def set_item(item)
  260. contents.clear
  261. draw_text(0,0,@window_width-6,27,item.name)
  262. draw_icon(item.icon_index, 170,0,true)
  263. end # End - set_item
  264.  
  265. def add_new_icon(id)
  266. @content_icons.push(id)
  267. draw_all_icons
  268. end # End - add_new_icon
  269.  
  270. def draw_all_icons
  271. contents.clear
  272. index, x_pos = 0,0
  273. @content_icons.each{ |id|
  274. draw_icon(id, x_pos, line_height * index, true)
  275. index += 1
  276. if(index > 6)
  277. index = 0
  278. x_pos += EquipUpgrades::Max::IconWidth
  279. end # End - index > 6
  280. } # End - @content_icons.each
  281. end # End - draw_all_icons
  282.  
  283. def clear_all
  284. contents.clear
  285. @content_names = []
  286. @content_icons = []
  287. end # End - clear_all
  288. end # End - Window_DisplayUpgrades
  289.  
  290.  
  291.  
  292. class Window_UpgradeSelection < Window_HorzCommand
  293.  
  294. #
  295. # Public Instance Variables
  296. #
  297. attr_reader :item_window
  298.  
  299. #
  300. # Object Initialization
  301. #
  302. def initialize(x,y, upgrader)
  303. @type = upgrader
  304. @col_max = upgrader ? 3 : 2
  305. super(x, y)
  306. end # End - initialize
  307.  
  308. #
  309. # Get Window Width
  310. #
  311. def window_width
  312. Graphics.width * (1-UpgradeOrientation::Size::WidthValue)
  313. end # End - window_width
  314.  
  315. #
  316. # Get Digit Count
  317. #
  318. def col_max
  319. return @col_max
  320. end # End - col_max
  321.  
  322. #
  323. # Create Command List
  324. #
  325. def make_command_list
  326. if !@type
  327. add_command(EquipUpgrades::EquipPhrase::Equips, :equip)
  328. add_command("Ok", :advance)
  329. else
  330. add_command(EquipUpgrades::EquipPhrase::Upgrader, :upgrades)
  331. add_command("Clear", :clear)
  332. add_command("Done", :done)
  333. end # End - if !@type
  334. end # End - make_command_list
  335. end # End - Window_UpgradeSelection
  336.  
  337. #==============================================================================
  338. # ** DataManager
  339. #==============================================================================
  340. module DataManager
  341. #
  342. # * alias load_database
  343. #
  344. class <<self; alias load_db_upgrade_mods_82372934 load_database; end
  345. def self.load_database
  346. load_db_upgrade_mods_82372934
  347. load_ntags_upgrade_mods_82372933
  348. end
  349.  
  350. #
  351. # load_ntags_upgrade_mods_82372933
  352. #
  353. def self.load_ntags_upgrade_mods_82372933
  354. groups = [$data_armors, $data_weapons, $data_items]
  355. for group in groups
  356. for obj in group
  357. next if obj.nil?
  358. obj.load_ntags_upgrade_mods
  359. end
  360. end
  361. end
  362.  
  363. end # DataManager
  364.  
  365. #==============================================================================
  366. # ** RPG::BaseItem
  367. #==============================================================================
  368. class RPG::BaseItem
  369. attr_accessor :max_upgrades # The max number of upgrades usable on this item
  370. attr_accessor :curr_upgrades # list of current upgrades on this item
  371. attr_accessor :upgrade_mods
  372. attr_accessor :is_upgradable
  373. attr_accessor :orig_name # Used when making deep copies and it's necessary
  374. # to know the name of the original item while still
  375. # being able to change the name of the new item.
  376. #
  377. # Parses notetags and stores corresponding data
  378. #
  379. def load_ntags_upgrade_mods
  380. self.note.split(/[\r\n]+/).each { |line|
  381. next unless line != nil# && $1 != nil
  382. case line
  383. when EquipUpgrades::Regexp::State
  384. add_state_upgrade_mods($1.to_i, $2.to_i)
  385. when EquipUpgrades::Regexp::StatPercent
  386. add_stat_mod(:percent, $1, $3.to_i, $2)
  387. when EquipUpgrades::Regexp::StatRaw
  388. add_stat_mod(:raw, $1, $3.to_i, $2)
  389. when EquipUpgrades::Regexp::Upgradable
  390. @is_upgradable = true
  391. if (val=$1.to_s) =~ NumericForm::Regex #init max upgrades if it was defined
  392. @max_upgrades = val.to_i
  393. @curr_upgrades = []
  394. end
  395. end
  396. }
  397. end # End - load_ntags_upgrade_mods
  398.  
  399. #
  400. # store state modifiers
  401. #
  402. def add_state_upgrade_mods(id, val)
  403. init_upgrade_mods
  404. @upgrade_mods.store_state_mod(id, val * 0.01)
  405. end # End - add_state_upgrade_mods
  406.  
  407. #
  408. # store base stat modifiers percentages mapped from :percent, raw values from
  409. # :raw
  410. #
  411. def add_stat_mod(sym, id, val, op)
  412. init_upgrade_mods
  413. val *= 0.01 if sym == :percent
  414. val = op.eql?("-") ? -val : val
  415. @upgrade_mods.store_stat_mod(sym, id, val)
  416. end
  417.  
  418. #
  419. # initialize @upgrade_mods if it is nil
  420. #
  421. def init_upgrade_mods
  422. @upgrade_mods = Equipment_Upgrader.new unless @upgrade_mods
  423. end
  424.  
  425. #
  426. # adds a new feature to the item
  427. #
  428. def add_new_feature_upg(feature)
  429. @features.push(feature)
  430. end
  431. end # End - RPG::BaseItem
  432.  
  433. #==============================================================================
  434. # ** RPG::Weapon
  435. #------------------------------------------------------------------------------
  436. # A Method to create a deep copy is added
  437. #==============================================================================
  438. class RPG::Weapon < RPG::EquipItem
  439.  
  440. #
  441. # * Deep Copy
  442. #
  443. def deep_copy_clone_2544
  444. wep = Marshal.load(Marshal.dump(self))
  445. wep.id = $data_weapons.size
  446.  
  447. wep.orig_name = @orig_name ? @orig_name : (@orig_name = wep.name)
  448. wep.name = "Upgraded " + wep.orig_name + "(#{wep.id})"
  449. wep.description = wep.description + " (Upgraded)"
  450. $custom_weapons.push(wep)
  451. $data_weapons.push(wep) # temporarily in data_weapons for use with methods
  452. # such as gain_item
  453. wep
  454. end # End - deep_copy_clone_2544
  455. end # End - RPG::Weapon
  456.  
  457. #==============================================================================
  458. # ** RPG::Armor
  459. #------------------------------------------------------------------------------
  460. # A Method to create a deep copy is added
  461. #==============================================================================
  462. class RPG::Armor < RPG::EquipItem
  463.  
  464. #
  465. # * Deep Copy
  466. #
  467. def deep_copy_clone_2544
  468. arm = Marshal.load(Marshal.dump(self))
  469. arm.id = $data_weapons.size
  470.  
  471. arm.orig_name = @orig_name ? @orig_name : (@orig_name = arm.name)
  472. arm.name = "Upgraded " + arm.name + "(#{arm.id})"
  473. arm.description = arm.description + " (Upgraded)"
  474. $custom_armors.push(arm)
  475. $data_armors.push(arm) # temporarily in data_armors for use with methods
  476. # such as gain_item
  477. arm
  478. end # End - deep_copy_clone_2544
  479. end # End - RPG::Armor
  480.  
  481. #==============================================================================
  482. # ** Equipment_Upgrader
  483. #------------------------------------------------------------------------------
  484. # This class represents a new property for items to allow for certain items
  485. # to represent upgraders which can increase the stats of others.
  486. #==============================================================================
  487. class Equipment_Upgrader
  488. attr_accessor :states
  489. attr_accessor :stat_mods
  490.  
  491. def initialize
  492. @states = {} # maps state ids to the chance of that state being inflicted
  493. @stat_mods = {} # A hash mapping stat Ids to the symbols :percent
  494. # and :raw these determine how much the effected stat is
  495. # changed.
  496. end
  497.  
  498. # The percentage value is stored as a float between -1.00 and 1.00
  499. def store_stat_mod(sym, stat_id, val, preserve = false, mod = 1)
  500. @stat_mods[stat_id.to_i] = {} unless @stat_mods[stat_id.to_i]
  501. mod_all_stats(sym, stat_id, val, preserve, mod) unless stat_id.to_s =~ NumericForm::Regex
  502. @stat_mods[stat_id.to_i][sym] = preserve ? @stat_mods[stat_id][sym] + val : val
  503. end
  504.  
  505. #
  506. # stores data which will be added to item.features
  507. #
  508. def store_state_mod(state_id, val, preserve = false, mod = 1)
  509. @states[state_id] = preserve ? @states[state_id] + val : val
  510. end
  511.  
  512. #
  513. # stores data which will modify the stats stored in item.params
  514. #
  515. def mod_all_stats(sym, stat_id, val, preserve = false, mod = 1)
  516. (0..7).each{ |id| store_stat_mod(sym, id, val, preserve, mod)}
  517. end
  518.  
  519. #
  520. # Percentage value modifications to stats
  521. #
  522. def get_stat_mod_percent(stat_id)
  523. @stat_mods[stat_id][:percent]
  524. end
  525.  
  526. #
  527. # Non percentage value modifications to stats
  528. #
  529. def get_stat_mod_raw(stat_id)
  530. @stat_mods[stat_id][:raw]
  531. end
  532.  
  533. #
  534. # The percent chance of happening this upgrader gives to the state with
  535. # id = param: state_id
  536. #
  537. def get_state_mod(state_id)
  538. @states[state_id]
  539. end
  540.  
  541. end # End - Equip_Upgrader
  542.  
  543. #==============================================================================
  544. # ** Scene_UpgradableItem
  545. #------------------------------------------------------------------------------
  546. # This class allows items to be upgraded by other items
  547. #==============================================================================
  548.  
  549. class Scene_UpgradableItem < Scene_ItemBase
  550. #
  551. # * Start Processing
  552. #
  553. def start
  554. super
  555. create_help_window
  556. #create_help_text_upgradable
  557. create_equip_select_window
  558.  
  559. create_display_window_upgradable
  560. create_upgrade_select_window
  561. create_category_window(2*Graphics.width/5,@help_window.height,0,0)
  562. create_item_window(2*Graphics.width/5)
  563. create_upgrade_list
  564.  
  565. @equipment_to_upgrade = nil
  566. @upgraders = [] # list of items to be used as upgraders for the equipment
  567. @item_is_upgrader = false# Determines which list to show items in once clicked
  568. end # End - start
  569.  
  570. def create_display_window_upgradable
  571. w = Graphics.width * (1-UpgradeOrientation::Size::WidthValue)
  572. h = 48
  573. y = @upgrade_equipment_window.height+@help_window.height
  574.  
  575. @display_window = Window_DisplayUpgrades.new(0,y,h)
  576. @display_window.viewport = @viewport
  577. end # End - create_display_window_upgradable
  578.  
  579. #
  580. # * Create Equip Select Window
  581. # The base window with options to select on equipment or to just click ok
  582. #
  583. def create_equip_select_window
  584. @upgrade_equipment_window = Window_UpgradeSelection.new(0,@help_window.height, false)
  585. @upgrade_equipment_window.viewport = @viewport
  586. @upgrade_equipment_window.deactivate
  587. @upgrade_equipment_window.unselect
  588. @upgrade_equipment_window.set_handler(:ok, method(:on_upgrade_equip_ok))
  589. @upgrade_equipment_window.set_handler(:cancel, method(:on_equip_select_cancel))
  590. @upgrade_equipment_window.set_handler(:advance, method(:on_equip_select_advance))
  591. end # End - create_equip_select_window
  592.  
  593. #
  594. # * Upgrade Selection Window
  595. #
  596. def create_upgrade_select_window
  597. y = @help_window.height + @upgrade_equipment_window.height + @display_window.height
  598. @upgrades_selection_window = Window_UpgradeSelection.new(0,y, true)
  599. @upgrades_selection_window.viewport = @viewport
  600. @upgrades_selection_window.set_handler(:upgrades, method(:on_choose_upgrades))
  601. @upgrades_selection_window.set_handler(:clear, method(:on_clear_upgrades))
  602. @upgrades_selection_window.set_handler(:done, method(:on_done))
  603. @upgrades_selection_window.set_handler(:cancel, method(:on_upgrade_cancel))
  604. @upgrades_selection_window.deactivate
  605. @upgrades_selection_window.unselect
  606. end # End - create_upgrade_select_window
  607.  
  608. #
  609. # * Upgrade List
  610. #
  611. def create_upgrade_list
  612. th1, th2 = @help_window.height, @upgrade_equipment_window.height
  613. th3, th4 = @display_window.height, @upgrades_selection_window.height
  614. y = th1 + th2 + th3 + th4
  615. h = Graphics.height - y
  616. @upgrades_display_window = Window_DisplayUpgrades.new(0,y,h)
  617. @upgrades_display_window.viewport = @viewport
  618. end # End - create_upgrade_list
  619.  
  620. #
  621. # * Create Category Window
  622. #
  623. def create_category_window(x,y,w,h)
  624. @category_window = Window_UpgradeItemCategory.new
  625. @category_window.viewport = @viewport
  626. @category_window.help_window = @help_window
  627. @category_window.y = y
  628. @category_window.x = Graphics.width * (1-UpgradeOrientation::Size::WidthValue)
  629. @category_window.set_handler(:ok, method(:on_category_ok))
  630. @category_window.set_handler(:cancel, method(:on_category_cancel))
  631. end # End - create_category_window
  632.  
  633. #
  634. # * Create Item Window
  635. #
  636. def create_item_window(x)
  637. wy = @category_window.y + @category_window.height
  638. wh = Graphics.height - wy
  639. @item_window = Window_UpgradeItemList.new(x, wy, 3*Graphics.width/5, wh)
  640. @item_window.viewport = @viewport
  641. @item_window.help_window = @help_window
  642. @item_window.set_handler(:ok, method(:on_item_ok))
  643. @item_window.set_handler(:cancel, method(:on_item_cancel))
  644. @item_window.only_enable_upgradables = true
  645. @category_window.item_window = @item_window
  646. end # End - create_item_window
  647.  
  648. #
  649. # * Category [OK]
  650. #
  651. def on_category_ok
  652. @item_window.activate
  653. @item_window.select_last
  654. end # End - on_category_ok
  655.  
  656. #
  657. # * Category [Cancel]
  658. #
  659. def on_category_cancel
  660. if !@item_is_upgrader
  661. @upgrade_equipment_window.activate
  662. @upgrade_equipment_window.select(@upgrade_equipment_window.get_curr_index)
  663. @category_window.deactivate
  664. else
  665. turn_on_upgrades_selection
  666. @category_window.deactivate
  667. end
  668. end # End - on_category_cancel
  669.  
  670. #
  671. # * Item [OK]
  672. #
  673. def on_item_ok
  674. if !@item_is_upgrader
  675. $game_party.gain_item(@equipment_to_upgrade, 1) unless !@equipment_to_upgrade
  676. @equipment_to_upgrade = item
  677. @display_window.set_item(@equipment_to_upgrade)
  678. else
  679. if !check_can_upgrade # already max amount of upgrades in list
  680. turn_on_upgrades_selection
  681. @item_window.deactivate
  682. return
  683. end
  684. @upgraders.push(item)
  685. @upgrades_display_window.add_new_icon(item.icon_index)
  686. @item_window.refresh
  687. end # End - !@item_is_upgrader
  688.  
  689. $game_party.gain_item(item, -1)
  690. @item_window.data.delete(item) if !$game_party.has_item?(item)
  691. @item_window.refresh
  692.  
  693. turn_on_upgrades_selection
  694. @item_window.deactivate
  695. end # End - on_item_ok
  696.  
  697. #
  698. # * Item [Cancel]
  699. #
  700. def on_item_cancel
  701. @item_window.unselect
  702. @category_window.activate
  703. end # End - on_item_cancel
  704.  
  705. #
  706. # Handler method which allows items to be selected as upgraders
  707. #
  708. def on_choose_upgrades
  709. @item_is_upgrader = true
  710. @item_window.only_enable_upgradables = false
  711. @upgrades_selection_window.deactivate
  712. @category_window.activate
  713. @category_window.select(@category_window.get_curr_index)
  714. end # End - on_choose_upgrades
  715.  
  716. #
  717. # Handler method which clears all selected upgrades
  718. #
  719. def on_clear_upgrades
  720. empty_upgrades
  721. turn_on_upgrades_selection
  722. end # End - on_clear_upgrades
  723.  
  724. #
  725. # Common code used when returning items to player after clearing the
  726. # upgrade list
  727. #
  728. def empty_upgrades
  729. @upgraders.each{ |item|
  730. $game_party.gain_item(item, 1)
  731. }
  732. @upgraders = []
  733. @upgrades_display_window.clear_all
  734. @item_window.refresh
  735. end # End - empty_upgrades
  736.  
  737. #
  738. # Handler method which allows the equipment to be upgraded
  739. #
  740. def on_done
  741. perform_upgrade
  742.  
  743. end # End - on_done
  744.  
  745. #
  746. # Handler method called when upgrade menu is unselected
  747. #
  748. def on_upgrade_cancel
  749. @item_is_upgrader = false
  750. @item_window.only_enable_upgradables = true
  751. @upgrades_selection_window.deactivate
  752. @upgrades_selection_window.unselect
  753. @category_window.activate
  754. @category_window.select(@category_window.get_curr_index)
  755. end # End - on_upgrade_cancel
  756.  
  757. #
  758. # Allows equipment selection
  759. #
  760. def on_upgrade_equip_ok
  761. @upgrade_equipment_window.deactivate
  762. @category_window.activate
  763. @category_window.select(@category_window.get_curr_index)
  764. end # End - on_upgrade_equip_ok
  765.  
  766. #
  767. # Allows advancement to upgrade selection without having to click a new equip
  768. #
  769. def on_equip_select_advance
  770. return unless @equipment_to_upgrade
  771. @upgrade_equipment_window.deactivate
  772. turn_on_upgrades_selection
  773. end # End - on_equip_select_advance
  774.  
  775. #
  776. # About to exit the scene
  777. #
  778. def on_equip_select_cancel
  779. empty_upgrades
  780. $game_party.gain_item(@equipment_to_upgrade, 1)
  781. SceneManager.return
  782. end # End - on_equip_select_cancel
  783.  
  784. #
  785. # Common code used when activating the upgrade selection menu
  786. #
  787. def turn_on_upgrades_selection
  788. @item_window.only_enable_upgradables = false
  789. @item_window.only_enable_upgradables = @item_is_upgrader = true
  790. @upgrades_selection_window.activate
  791. @upgrades_selection_window.select(@upgrades_selection_window.get_curr_index)
  792. end # End - turn_on_upgrades_selection
  793.  
  794. #
  795. # * Check to see if the current item is at its upgrade limit before adding
  796. # a new upgrader to the list
  797. #
  798. def check_can_upgrade
  799. return true if !@equipment_to_upgrade.max_upgrades
  800. max = @equipment_to_upgrade.max_upgrades
  801. curr_size = @equipment_to_upgrade.curr_upgrades.size
  802. curr_size + @upgrades_display_window.content_icons.size < max
  803. end
  804.  
  805. #
  806. # * Perform the Upgrade
  807. # Change the stats on the item that is being upgraded (or downgraded)
  808. #
  809. def perform_upgrade
  810. # Check if the current upgrade is valid, if not then return
  811. if @upgraders[0] == nil || !@equipment_to_upgrade.is_a?(RPG::EquipItem)
  812. turn_on_upgrades_selection
  813. return
  814. end # End if
  815.  
  816. # Make a deep copy
  817. @equipment_to_upgrade = @equipment_to_upgrade.deep_copy_clone_2544
  818.  
  819. r_val = rand(EquipUpgrades::Max::BaseRVal)
  820. failed = 1+r_val <= $game_player.fail_rate_for_upgrades
  821. modify_stats(failed)
  822. add_new_features(13) unless failed# 13 is the default code for state features
  823.  
  824. set_player_animation(failed)
  825. $game_party.gain_item(@equipment_to_upgrade, 1)
  826. SceneManager.return
  827. end # End - perform_upgrade
  828.  
  829. #
  830. # * Set Player Animation
  831. #
  832. def set_player_animation(fail)
  833. return unless EquipUpgrades::Player::DisplayAnimation
  834. $game_player.animation_id = EquipUpgrades::Player::SuccessAnimation unless fail
  835. $game_player.animation_id = EquipUpgrades::Player::FailAnimation if fail
  836. end # End - set_player_animation
  837. #
  838. # * Add New Features
  839. # Creates new features to add to item.features
  840. #
  841. def add_new_features(code)
  842. @upgraders.each{ |item|
  843. states = item.upgrade_mods.states
  844. states.keys.each{|key|
  845. feature = RPG::BaseItem::Feature.new(code, key, states[key])
  846. @equipment_to_upgrade.add_new_feature_upg(feature)
  847. }
  848. }
  849. end # End - add_new_features
  850.  
  851. #
  852. # * Modify Stats
  853. # percentages are applied to stats starting with the smallest percentage
  854. # increasing to the largest. Percentage bonuses are applied before raw bonuses
  855. #
  856. def modify_stats(failed = false)
  857. percents = {} # maps stat ids to an array of percentages
  858. raws = {} # maps stat ids to an array of values
  859.  
  860. # Goes through all the items and condenses all the upgrades into above
  861. # two hashes
  862. @upgraders.each{ |item|
  863. @equipment_to_upgrade.curr_upgrades.push(item) #add each 1 to curr upgs list
  864. stats = item.upgrade_mods.stat_mods
  865. stats.keys.each{ |key|
  866. if stats[key]
  867. percents[key] = [] if !percents[key]
  868. raws[key] = [] if !raws[key]
  869.  
  870. percents[key].push(stats[key][:percent]) unless !stats[key][:percent]
  871. raws[key].push(stats[key][:raw]) unless !stats[key][:raw]
  872. end # End - if stats[key]
  873. }
  874. } # End - @upgraders.each
  875.  
  876. (0...EquipUpgrades::Max::StatId).each{|id|
  877. if percents[id] # Modify stats by multiplying percentages
  878. orig_val = @equipment_to_upgrade.params[id]
  879. percents[id].sort!.each{ |val|
  880. mod = upgrade_failed?(failed, orig_val * val) # handle failure case
  881. @equipment_to_upgrade.params[id] = mod + orig_val
  882. }
  883. end # End - if percents[id]
  884.  
  885. if raws[id] # Modify stats by adding raw values
  886. raws[id].each { |val|
  887. val = upgrade_failed?(failed, val)
  888. @equipment_to_upgrade.params[id]+= val # handle failure case
  889. }
  890. end # End - if raws[id]
  891. } # End - (0...EquipUpgrades::Max::StatId).each
  892. end # End - modify_stats
  893.  
  894. #
  895. # * Upgrade Failed
  896. # Calculate the appropriate value to add onto the stat if the upgrade failed
  897. #
  898. def upgrade_failed?(did_fail, val)
  899. mod = $game_player.fail_mod_for_upgrades
  900. did_fail ? (val > 0 ? val*-mod : val * mod) : val
  901. end # End - upgrade_failed?
  902. end # End - Scene_UpgradableItem
  903.  
  904. #==============================================================================
  905. # -------------------------------End of File-----------------------------------
  906. #==============================================================================
Advertisement
Add Comment
Please, Sign In to add comment