blucalm

Upgradable Equipment bug fix 3

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