Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #═╦═════════════════════════════════════════════════════════════════════════════
- # ║ § Leveled Equipment (v1.1) by Enelvon [License: CC BY-SA 3.0]
- # ║ <RMVX Ace>
- #═╬═════════════════════════════════════════════════════════════════════════════
- # ║ § Change Log
- #─╫─────────────────────────────────────────────────────────────────────────────
- # ║ v1.0 (December 25th, 2012) - Script released.
- # ║ v1.1 (February 16th, 2013) - Fixed bug with class changing.
- # ║
- #═╬═════════════════════════════════════════════════════════════════════════════
- # ║ § Summary
- #─╫─────────────────────────────────────────────────────────────────────────────
- # ║ This script allows you to have equipment that levels up by gaining
- # ║ experience, much like party members. As it levels up, it can get increased
- # ║ stats, have new features, or change its icon, name, and price. The script
- # ║ will also allow actors and classes to gain new features through leveling. In
- # ║ the case of classes, it will use the associated actor's level to determine
- # ║ what bonus features are granted. I may extend this into a full class system
- # ║ at some point.
- # ║
- # ║ At the moment, equipment gains EXP as a portion of the EXP gained by actors.
- # ║ I may introduce an AP-style system at some point in the future, but for now
- # ║ think the current system is fine.
- # ║
- # ║ Note that there is currently no way for the player to check how much EXP a
- # ║ weapon has or needs to level up. This will be included in a menu overhaul I
- # ║ am working on, but I have no idea when that will be ready for release. I'm
- # ║ not exactly focusing heavily on it at the moment.
- # ║
- #═╬═════════════════════════════════════════════════════════════════════════════
- # ║ § Required Scripts
- #─╫─────────────────────────────────────────────────────────────────────────────
- # ║ SES Core v1.0 or higher
- # ║ SES - Instance Items v1.0 or higher
- # ║
- #═╬═════════════════════════════════════════════════════════════════════════════
- # ║ § Known Incompatibilities
- #─╫─────────────────────────────────────────────────────────────────────────────
- # ║ None.
- # ║
- #═╬═════════════════════════════════════════════════════════════════════════════
- # ║ § Installation
- #─╫─────────────────────────────────────────────────────────────────────────────
- # ║ Put this script below the SES Core and Instance Items.
- # ║
- #═╬═════════════════════════════════════════════════════════════════════════════
- # ║ § Configuration
- #─╫─────────────────────────────────────────────────────────────────────────────
- # ║ There is only one piece of in-script configuration - the ItemExpRate
- # ║ constant in SES::LeveledEquipment. Change its value to determine how much
- # ║ EXP weapons gain from battle (as a percentage of the EXP gained by the
- # ║ party). By default it is set to 0.25, or 1/4 of the party's EXP.
- # ║
- #═╬═════════════════════════════════════════════════════════════════════════════
- # ║ § Tags
- #─╫─────────────────────────────────────────────────────────────────────────────
- # ║ ● Weapon/Armor/Actor/Class
- # ║ <Level !Level!: !Exp!>
- # ║ Place this in a Notes box to set the EXP required to reach a level. It
- # ║ also starts the block of added features for the level. For actors and
- # ║ classes, omit the ": !Exp!" part - the format for them is just
- # ║ <Level !Level!>. Make sure there is one of these for each level an item
- # ║ can obtain, or else it will not know how much EXP is required for the
- # ║ level, which could cause issues. Note that you do not need one per level
- # ║ for actors or classes, just equipment. You can have as many or as few
- # ║ of these as you would like - just don't skip levels (except level 1,
- # ║ which can be skipped, as it requires 0 EXP to reach and is the default
- # ║ level).
- # ║ ► Replacements:
- # ║ !Level! with the level you want to define.
- # ║ !Exp! with the amount of EXP that the item needs to reach !Level!.
- # ║
- # ║ </Level !Level!>
- # ║ Place this in a Notes box to finish adding features for a level. You MUST
- # ║ have one of these for each level, even if nothing changes as a result of
- # ║ the leveling.
- # ║ ► Replacements:
- # ║ !Level! with the level you are done defining.
- # ║
- #═╬═════════════════════════════════════════════════════════════════════════════
- # ║ § Adding Level Benefits
- #─╫─────────────────────────────────────────────────────────────────────────────
- # ║ Add these between the tags for level definition to cause them to be added
- # ║ at the proper level (henceforth called 'the new level'). Note that 'item'
- # ║ simply refers to whatever object is being altered by these tags - I will
- # ║ explicitly note any item-exclusive tags.
- # ║
- # ║ Example:
- # ║ <Level 2: 20>
- # ║ Atk: 4
- # ║ Atk State: 1, 15
- # ║ </Level 2>
- # ║
- # ║ The example defines level 2 as requiring 20 EXP to reach. When the item
- # ║ reaches level 2, it will get +4 to its Atk stat and have a 15% chance of
- # ║ instantly killing a target. For a list of tags you can use here, please see
- # ║ the "Instructions for Feature Tags" text file.
- # ║
- #═╬═════════════════════════════════════════════════════════════════════════════
- # ║ § Aliased Methods
- #─╫─────────────────────────────────────────────────────────────────────────────
- # ║ ● module BattleManager
- # ║ self.gain_exp
- # ║
- # ║ ● class Game_Actor
- # ║ setup(actor_id)
- # ║ level_up
- # ║
- #═╬═════════════════════════════════════════════════════════════════════════════
- # ║ § Redefined Methods
- #─╫─────────────────────────────────────────────────────────────────────────────
- # ║ ● class Game_Actor
- # ║ actor
- # ║ class
- # ║
- #═╬═════════════════════════════════════════════════════════════════════════════
- # ║ ▼ module SES::LeveledEquipment
- #═╩═════════════════════════════════════════════════════════════════════════════
- module SES module LeveledEquipment
- #═╦═══════════════════════════════════════════════════════════════════════════
- # ║ α BEGIN CONFIGURATION
- #═╩═══════════════════════════════════════════════════════════════════════════
- # The rate at which non-actor items gain EXP. Gained EXP will be multiplied
- # by this amount for said items, while remaining at the usual rate for
- # actors. In the future, this may be replaced with an AP-style system.
- ItemExpRate = 0.25
- #═╦═══════════════════════════════════════════════════════════════════════════
- # ║ Ω END CONFIGURATION
- #═╩═══════════════════════════════════════════════════════════════════════════
- # RegExp for defining the amount of EXP an item needs to reach a level.
- EquipLevel = /^<Level (\d+)(?::?)(?:\s*)(\d+?)>/i
- end end
- $imported ||= {}
- if $imported["SES - Instance Items"] < 1.0
- raise("You need SES - Instance Items v1.0 or higher to use SES - Leveled Equipment.")
- end
- if $imported["SES - Parse Features"] < 1.0
- raise("You need SES - Parse Features v1.0 or higher to use SES - Leveled Equipment.")
- end
- $imported["SES - Leveled Equipment"] = 1.0
- #═╦═════════════════════════════════════════════════════════════════════════════
- # ║ ▲ module SES::LeveledEquipment
- #─╫─────────────────────────────────────────────────────────────────────────────
- # ║ ▼ class RPG::BaseItem
- #═╩═════════════════════════════════════════════════════════════════════════════
- class RPG::BaseItem
- # Gets the object's bonuses for a specific level
- def level_data(lvl)
- level = self.note.split(/^<Level #{lvl}(?:[:\s\d]*)>/)
- level[1] ||= ""
- level = level[1].split(/<\/Level #{lvl}>/)
- level[0] ||= ""
- return level
- end
- # Grants the object the benefits of leveling
- def levelup_benefits(lvl = @level)
- add_features(level_data(lvl)[0], "Levels")
- end
- end
- #═╦═════════════════════════════════════════════════════════════════════════════
- # ║ ▲ class RPG::BaseItem
- #─╫─────────────────────────────────────────────────────────────────────────────
- # ║ ▼ class RPG::EquipItem
- #═╩═════════════════════════════════════════════════════════════════════════════
- class RPG::EquipItem < RPG::BaseItem
- alias en_le_ei_sn scan_ses_notes
- def scan_ses_notes(tags = {})
- @level = 1
- @exp = 0
- @levelexp = [nil, 0]
- tags[SES::LeveledEquipment::EquipLevel] =
- %Q{@levelexp[$1.to_i] = $2.to_i}
- en_le_ei_sn(tags)
- levelup_benefits
- end
- # Adds EXP to an item
- def gain_exp(xp)
- @exp = [[@exp + xp, @levelexp[@levelexp.size-1]].min, 0].max
- while @levelexp[@level + 1] != nil && @exp >= @levelexp[@level + 1]
- level_up
- end
- end
- # Levels up an item and gives it any gained benefits
- def level_up(display = true)
- unless @level == @levelexp[@levelexp.size-1]
- @oname = @name
- @level += 1
- levelup_benefits
- display_level_up if display
- end
- end
- # Displays text showing that the item has leveled up
- def display_level_up
- $game_message.new_page
- $game_message.add(sprintf(Vocab::LevelUp, @oname, Vocab::level, @level))
- $game_message.add(sprintf("%s became %s!", @oname, @name)) if @name != @oname
- end
- [:level, :exp, :levelexp].each do |i|
- define_method(i) do
- en_scan_notes if eval("@#{i}.nil?")
- return eval("@#{i}")
- end
- end
- end
- #═╦═════════════════════════════════════════════════════════════════════════════
- # ║ ▲ class RPG::EquipItem
- #─╫─────────────────────────────────────────────────────────────────────────────
- # ║ ▼ module BattleManager
- #═╩═════════════════════════════════════════════════════════════════════════════
- module BattleManager
- class << self; alias en_le_bm_ge gain_exp; end
- def self.gain_exp
- en_le_bm_ge
- $game_party.all_members.each do |actor|
- actor.equips.compact.each do |e|
- e.gain_exp([($game_troop.exp_total * SES::LeveledEquipment::ItemExpRate).to_i, 1].max)
- end
- end
- wait_for_message
- end
- end
- #═╦═════════════════════════════════════════════════════════════════════════════
- # ║ ▲ module BattleManager
- #─╫─────────────────────────────────────────────────────────────────────────────
- # ║ ▼ class Game_Actor
- #═╩═════════════════════════════════════════════════════════════════════════════
- class Game_Actor < Game_Battler
- alias en_le_ga_s setup
- def setup(actor_id)
- en_le_ga_s(actor_id)
- (1..@level).each do |i|
- self.actor.levelup_benefits(i); self.class.levelup_benefits(i)
- end
- end
- def actor
- @actor ||= Marshal.load(Marshal.dump($data_actors[@actor_id]))
- end
- def class
- @class ||= Marshal.load(Marshal.dump($data_classes[@class_id]))
- end
- alias en_le_ga_cc change_class
- def change_class(*args)
- en_le_ga_cc(*args)
- @class = nil
- end
- alias en_le_ga_lu level_up
- def level_up
- en_le_ga_lu
- self.actor.levelup_benefits(@level); self.class.levelup_benefits(@level)
- end
- end
- #═╦═════════════════════════════════════════════════════════════════════════════
- # ║ ▲ class Game_Actor
- #═╩═════════════════════════════════════════════════════════════════════════════
Advertisement
Add Comment
Please, Sign In to add comment