Enelvon

SES - Leveled Equipment

Dec 25th, 2012
716
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Ruby 17.70 KB | None | 0 0
  1. #═╦═════════════════════════════════════════════════════════════════════════════
  2. # ║ § Leveled Equipment (v1.1) by Enelvon                [License: CC BY-SA 3.0]
  3. # ║                                                            <RMVX Ace>
  4. #═╬═════════════════════════════════════════════════════════════════════════════
  5. # ║ § Change Log
  6. #─╫─────────────────────────────────────────────────────────────────────────────
  7. # ║ v1.0 (December 25th, 2012) - Script released.
  8. # ║ v1.1 (February 16th, 2013) - Fixed bug with class changing.
  9. # ║
  10. #═╬═════════════════════════════════════════════════════════════════════════════
  11. # ║ § Summary
  12. #─╫─────────────────────────────────────────────────────────────────────────────
  13. # ║ This script allows you to have equipment that levels up by gaining
  14. # ║ experience, much like party members. As it levels up, it can get increased
  15. # ║ stats, have new features, or change its icon, name, and price. The script
  16. # ║ will also allow actors and classes to gain new features through leveling. In
  17. # ║ the case of classes, it will use the associated actor's level to determine
  18. # ║ what bonus features are granted. I may extend this into a full class system
  19. # ║ at some point.
  20. # ║
  21. # ║ At the moment, equipment gains EXP as a portion of the EXP gained by actors.
  22. # ║ I may introduce an AP-style system at some point in the future, but for now
  23. # ║ think the current system is fine.
  24. # ║
  25. # ║ Note that there is currently no way for the player to check how much EXP a
  26. # ║ weapon has or needs to level up. This will be included in a menu overhaul I
  27. # ║ am working on, but I have no idea when that will be ready for release. I'm
  28. # ║ not exactly focusing heavily on it at the moment.
  29. # ║
  30. #═╬═════════════════════════════════════════════════════════════════════════════
  31. # ║ § Required Scripts
  32. #─╫─────────────────────────────────────────────────────────────────────────────
  33. # ║ SES Core v1.0 or higher
  34. # ║ SES - Instance Items v1.0 or higher
  35. # ║
  36. #═╬═════════════════════════════════════════════════════════════════════════════
  37. # ║ § Known Incompatibilities
  38. #─╫─────────────────────────────────────────────────────────────────────────────
  39. # ║ None.
  40. # ║
  41. #═╬═════════════════════════════════════════════════════════════════════════════
  42. # ║ § Installation
  43. #─╫─────────────────────────────────────────────────────────────────────────────
  44. # ║ Put this script below the SES Core and Instance Items.
  45. # ║
  46. #═╬═════════════════════════════════════════════════════════════════════════════
  47. # ║ § Configuration
  48. #─╫─────────────────────────────────────────────────────────────────────────────
  49. # ║ There is only one piece of in-script configuration - the ItemExpRate
  50. # ║ constant in SES::LeveledEquipment. Change its value to determine how much
  51. # ║ EXP weapons gain from battle (as a percentage of the EXP gained by the
  52. # ║ party). By default it is set to 0.25, or 1/4 of the party's EXP.
  53. # ║
  54. #═╬═════════════════════════════════════════════════════════════════════════════
  55. # ║ § Tags
  56. #─╫─────────────────────────────────────────────────────────────────────────────
  57. # ║ ● Weapon/Armor/Actor/Class
  58. # ║   <Level !Level!: !Exp!>
  59. # ║     Place this in a Notes box to set the EXP required to reach a level. It
  60. # ║     also starts the block of added features for the level. For actors and
  61. # ║     classes, omit the ": !Exp!" part - the format for them is just
  62. # ║     <Level !Level!>. Make sure there is one of these for each level an item
  63. # ║     can obtain, or else it will not know how much EXP is required for the
  64. # ║     level, which could cause issues. Note that you do not need one per level
  65. # ║     for actors or classes, just equipment. You can have as many or as few
  66. # ║     of these as you would like - just don't skip levels (except level 1,
  67. # ║     which can be skipped, as it requires 0 EXP to reach and is the default
  68. # ║     level).
  69. # ║     ► Replacements:
  70. # ║       !Level! with the level you want to define.
  71. # ║       !Exp! with the amount of EXP that the item needs to reach !Level!.
  72. # ║
  73. # ║   </Level !Level!>
  74. # ║     Place this in a Notes box to finish adding features for a level. You MUST
  75. # ║     have one of these for each level, even if nothing changes as a result of
  76. # ║     the leveling.
  77. # ║     ► Replacements:
  78. # ║       !Level! with the level you are done defining.
  79. # ║
  80. #═╬═════════════════════════════════════════════════════════════════════════════
  81. # ║ § Adding Level Benefits
  82. #─╫─────────────────────────────────────────────────────────────────────────────
  83. # ║ Add these between the tags for level definition to cause them to be added
  84. # ║ at the proper level (henceforth called 'the new level'). Note that 'item'
  85. # ║ simply refers to whatever object is being altered by these tags - I will
  86. # ║ explicitly note any item-exclusive tags.
  87. # ║
  88. # ║   Example:
  89. # ║     <Level 2: 20>
  90. # ║     Atk: 4
  91. # ║     Atk State: 1, 15
  92. # ║     </Level 2>
  93. # ║
  94. # ║ The example defines level 2 as requiring 20 EXP to reach. When the item
  95. # ║ reaches level 2, it will get +4 to its Atk stat and have a 15% chance of
  96. # ║ instantly killing a target. For a list of tags you can use here, please see
  97. # ║ the "Instructions for Feature Tags" text file.
  98. # ║
  99. #═╬═════════════════════════════════════════════════════════════════════════════
  100. # ║ § Aliased Methods
  101. #─╫─────────────────────────────────────────────────────────────────────────────
  102. # ║ ● module BattleManager
  103. # ║     self.gain_exp
  104. # ║
  105. # ║ ● class Game_Actor
  106. # ║     setup(actor_id)
  107. # ║     level_up
  108. # ║
  109. #═╬═════════════════════════════════════════════════════════════════════════════
  110. # ║ § Redefined Methods
  111. #─╫─────────────────────────────────────────────────────────────────────────────
  112. # ║ ● class Game_Actor
  113. # ║     actor
  114. # ║     class
  115. # ║
  116. #═╬═════════════════════════════════════════════════════════════════════════════
  117. # ║ ▼ module SES::LeveledEquipment
  118. #═╩═════════════════════════════════════════════════════════════════════════════
  119. module SES module LeveledEquipment
  120.   #═╦═══════════════════════════════════════════════════════════════════════════
  121.   # ║ α BEGIN CONFIGURATION
  122.   #═╩═══════════════════════════════════════════════════════════════════════════
  123.     # The rate at which non-actor items gain EXP. Gained EXP will be multiplied
  124.     # by this amount for said items, while remaining at the usual rate for
  125.     # actors. In the future, this may be replaced with an AP-style system.
  126.     ItemExpRate = 0.25
  127.   #═╦═══════════════════════════════════════════════════════════════════════════
  128.   # ║ Ω END CONFIGURATION
  129.   #═╩═══════════════════════════════════════════════════════════════════════════
  130.     # RegExp for defining the amount of EXP an item needs to reach a level.
  131.     EquipLevel = /^<Level (\d+)(?::?)(?:\s*)(\d+?)>/i
  132.  
  133. end end
  134.                               $imported ||= {}
  135.                   if $imported["SES - Instance Items"] < 1.0
  136. raise("You need SES - Instance Items v1.0 or higher to use SES - Leveled Equipment.")
  137.                                   end
  138.                   if $imported["SES - Parse Features"] < 1.0
  139. raise("You need SES - Parse Features v1.0 or higher to use SES - Leveled Equipment.")
  140.                                   end
  141.                  $imported["SES - Leveled Equipment"] = 1.0
  142. #═╦═════════════════════════════════════════════════════════════════════════════
  143. # ║ ▲ module SES::LeveledEquipment
  144. #─╫─────────────────────────────────────────────────────────────────────────────
  145. # ║ ▼ class RPG::BaseItem
  146. #═╩═════════════════════════════════════════════════════════════════════════════
  147. class RPG::BaseItem
  148.  
  149.   # Gets the object's bonuses for a specific level
  150.   def level_data(lvl)
  151.     level = self.note.split(/^<Level #{lvl}(?:[:\s\d]*)>/)
  152.     level[1] ||= ""
  153.     level = level[1].split(/<\/Level #{lvl}>/)
  154.     level[0] ||= ""
  155.     return level
  156.   end
  157.  
  158.   # Grants the object the benefits of leveling
  159.   def levelup_benefits(lvl = @level)
  160.     add_features(level_data(lvl)[0], "Levels")
  161.   end
  162. end
  163. #═╦═════════════════════════════════════════════════════════════════════════════
  164. # ║ ▲ class RPG::BaseItem
  165. #─╫─────────────────────────────────────────────────────────────────────────────
  166. # ║ ▼ class RPG::EquipItem
  167. #═╩═════════════════════════════════════════════════════════════════════════════
  168. class RPG::EquipItem < RPG::BaseItem
  169.  
  170.   alias en_le_ei_sn scan_ses_notes
  171.   def scan_ses_notes(tags = {})
  172.     @level = 1
  173.     @exp = 0
  174.     @levelexp = [nil, 0]
  175.     tags[SES::LeveledEquipment::EquipLevel] =
  176.       %Q{@levelexp[$1.to_i] = $2.to_i}
  177.     en_le_ei_sn(tags)
  178.     levelup_benefits
  179.   end
  180.  
  181.   # Adds EXP to an item
  182.   def gain_exp(xp)
  183.     @exp = [[@exp + xp, @levelexp[@levelexp.size-1]].min, 0].max
  184.     while @levelexp[@level + 1] != nil && @exp >= @levelexp[@level + 1]
  185.       level_up
  186.     end
  187.   end
  188.  
  189.   # Levels up an item and gives it any gained benefits
  190.   def level_up(display = true)
  191.     unless @level == @levelexp[@levelexp.size-1]
  192.       @oname = @name
  193.       @level += 1
  194.       levelup_benefits
  195.       display_level_up if display
  196.     end
  197.   end
  198.  
  199.   # Displays text showing that the item has leveled up
  200.   def display_level_up
  201.     $game_message.new_page
  202.     $game_message.add(sprintf(Vocab::LevelUp, @oname, Vocab::level, @level))
  203.     $game_message.add(sprintf("%s became %s!", @oname, @name)) if @name != @oname
  204.   end
  205.  
  206.   [:level, :exp, :levelexp].each do |i|
  207.     define_method(i) do
  208.       en_scan_notes if eval("@#{i}.nil?")
  209.       return eval("@#{i}")
  210.     end
  211.   end
  212. end
  213. #═╦═════════════════════════════════════════════════════════════════════════════
  214. # ║ ▲ class RPG::EquipItem
  215. #─╫─────────────────────────────────────────────────────────────────────────────
  216. # ║ ▼ module BattleManager
  217. #═╩═════════════════════════════════════════════════════════════════════════════
  218. module BattleManager
  219.    
  220.   class << self; alias en_le_bm_ge gain_exp; end
  221.  
  222.   def self.gain_exp
  223.     en_le_bm_ge
  224.     $game_party.all_members.each do |actor|
  225.       actor.equips.compact.each do |e|
  226.         e.gain_exp([($game_troop.exp_total * SES::LeveledEquipment::ItemExpRate).to_i, 1].max)
  227.       end
  228.     end
  229.     wait_for_message
  230.   end
  231. end
  232. #═╦═════════════════════════════════════════════════════════════════════════════
  233. # ║ ▲ module BattleManager
  234. #─╫─────────────────────────────────────────────────────────────────────────────
  235. # ║ ▼ class Game_Actor
  236. #═╩═════════════════════════════════════════════════════════════════════════════
  237. class Game_Actor < Game_Battler
  238.  
  239.   alias en_le_ga_s setup
  240.   def setup(actor_id)
  241.     en_le_ga_s(actor_id)
  242.     (1..@level).each do |i|
  243.       self.actor.levelup_benefits(i); self.class.levelup_benefits(i)
  244.     end
  245.   end
  246.  
  247.   def actor
  248.     @actor ||= Marshal.load(Marshal.dump($data_actors[@actor_id]))
  249.   end
  250.  
  251.   def class
  252.     @class ||= Marshal.load(Marshal.dump($data_classes[@class_id]))
  253.   end
  254.  
  255.   alias en_le_ga_cc change_class
  256.   def change_class(*args)
  257.     en_le_ga_cc(*args)
  258.     @class = nil
  259.   end
  260.  
  261.   alias en_le_ga_lu level_up
  262.   def level_up
  263.     en_le_ga_lu
  264.     self.actor.levelup_benefits(@level); self.class.levelup_benefits(@level)
  265.   end
  266. end
  267. #═╦═════════════════════════════════════════════════════════════════════════════
  268. # ║ ▲ class Game_Actor
  269. #═╩═════════════════════════════════════════════════════════════════════════════
Advertisement
Add Comment
Please, Sign In to add comment