blucalm

Upg Equips Regex Correction 12 Dec 12 +Upd Log

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