blucalm

Upgradable Equipment Updates August 29th

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