blucalm

Upg Equips Major Bug Fix 13 Dec 2012

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