blucalm

Upg Equips Major Bug Fix 13 Dec 2012

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