Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #Equipment and Skill Levels v1.0
- #----------#
- #Features: Allows individual equipment and skills gain exp and levels, thus
- # becoming stronger!
- #
- #Usage: Plug and play, customize as needed
- # Notetags, use these to override defaults:
- # <MLVL #> - sets the max level for the object
- # <PARAM #> - sets the parameter increase for the object
- # <XPRATE #> - sets the xp rate for the object
- # <XPRATIO #> - sets the ratio of xp gained
- # <MPCOST #> - sets the mp cost increase for skills
- #
- #----------#
- #-- Script by: V.M of D.T
- #
- #- Questions or comments can be:
- # posted on the thread for the script
- # given by email: [email protected]
- # provided on facebook: http://www.facebook.com/DaimoniousTailsGames
- #
- #- Free to use in any project with credit given, donations always welcome!
- module LVLUP
- #Default change to parameters per level in percentage
- PARAMETER_INCREASE = 0.25
- #Default exp needed to level. It's current_level * EXP_RATE
- EXP_RATE = 100
- #Default ratio of exp gained for equipped items in percentage
- #E.g 0.5 means items gain 50 exp for every 100 gained by the actor
- EXP_MULTIPLIER = 0.5
- #Display of the item's name, as a String
- ITEM_NAME = "'Lvl ' + item.get_level.to_s + ' ' + item.name"
- #Display of the skill's name, as a String
- SKILL_NAME = "'Lvl ' + @actor.get_skill_level(item.id).to_s + ' ' + item.name"
- #Whether to draw the exp bar over the icon or not
- DRAW_EXP_BAR = true
- #Default max level for objects
- MAX_LEVEL = 99
- #Whether to level up skills or not
- LEVEL_UP_SKILLS = true
- #Whether to level up equipment or not
- LEVEL_UP_ITEMS = true
- #Default increase to skill costs per level
- MP_COST = 0.1
- def self.mlvl(note)
- note =~ /<MLVL (\d+)>/
- $~ ? $~[1].to_i : MAX_LEVEL
- end
- def self.param(note)
- note =~ /<PARAM (\d+)>/
- $~ ? $~[1].to_i : PARAMETER_INCREASE
- end
- def self.xprate(note)
- note =~ /<XPRATE (\d+)>/
- $~ ? $~[1].to_i : EXP_RATE
- end
- def self.xpratio(note)
- note =~ /<XPRATIO (\d+)>/
- $~ ? $~[1].to_i : EXP_MULTIPLIER
- end
- def self.mpcost(note)
- note =~ /<MPCOST (\d+)>/
- $~ ? $~[1].to_i : MP_COST
- end
- end
- class RPG::EquipItem < RPG::BaseItem
- def params
- return @params if !LVLUP::LEVEL_UP_ITEMS
- stats = [0] * 8
- stats.each_index do |i|
- stats[i] = @params[i] * (1 + get_level * LVLUP.param(@note))
- end
- stats
- end
- def change_exp(value)
- get_exp
- @current_exp += value * LVLUP.xpratio(@note)
- check_level
- end
- def check_level
- while get_exp > get_level * LVLUP.xprate(@note)
- @level += 1
- @current_exp -= get_level * LVLUP.xprate(@note)
- @level = LVLUP.mlvl(@note) if @level > LVLUP.mlvl(@note)
- end
- end
- def get_level
- @level = 1 if @level.nil?
- @level
- end
- def get_exp
- @current_exp = 0 if @current_exp.nil?
- @current_exp
- end
- def exp_rate
- return 1 if get_level == LVLUP.mlvl(@note)
- get_exp.to_f / (get_level * LVLUP.xprate(@note))
- end
- end
- class Game_Actor
- alias level_up_change change_exp
- alias level_up_init initialize
- alias level_up_mdv make_damage_value
- alias level_up_mp_cost skill_mp_cost
- alias level_up_tp_cost skill_tp_cost
- def initialize(*args)
- level_up_init(*args)
- @skill_exp = {}
- @skill_level = {}
- increase_skill_exp(1)
- refresh
- end
- def change_exp(exp,show)
- level_up_change(exp,show)
- increase_item_exp(exp) if LVLUP::LEVEL_UP_ITEMS
- increase_skill_exp(exp) if LVLUP::LEVEL_UP_SKILLS
- end
- def increase_item_exp(exp)
- items = equips
- items.each do |item|
- next if item.nil?
- item.change_exp(exp)
- end
- end
- def increase_skill_exp(exp)
- skills.each do |skill|
- next if skill.nil?
- @skill_exp[skill.id] = 0 if @skill_exp[skill.id].nil?
- @skill_exp[skill.id] += exp * LVLUP.xpratio(@note)
- while @skill_exp[skill.id] > get_skill_level(skill.id) * 100
- @skill_level[skill.id] += 1
- @skill_exp[skill.id] -= @skill_level[skill.id] * 100
- @skill_level[skill.id] = LVLUP.mlvl(@note) if @skill_level[skill.id] > LVLUP.mlvl(@note)
- end
- end
- end
- def get_skill_level(id)
- @skill_level[id] = 1 if @skill_level[id].nil?
- @skill_level[id]
- end
- def get_skill_exp_rate(id)
- @skill_exp[id] / (@skill_level[id] * 100)
- end
- def skill_mp_cost(skill)
- return level_up_mp_cost(skill) if !LVLUP::LEVEL_UP_SKILLS
- (skill.mp_cost * mcr * (1 + get_skill_level(skill.id) * LVLUP.mpcost(@note))).to_i
- end
- def skill_tp_cost(skill)
- return level_up_tp_cost(skill) if !LVLUP::LEVEL_UP_SKILLS
- (skill.tp_cost * (1 + get_skill_level(skill.id) * LVLUP.mpcost(@note))).to_i
- end
- def slvl(id)
- get_skill_level(id)
- end
- def make_damage_value(user,item)
- $last_actor_skill = item.id
- level_up_mdv(user,item)
- end
- end
- class Game_Party
- alias lvl_initialize initialize
- def initialize
- lvl_initialize
- @saved_weapons = $data_weapons
- @saved_armors = $data_armors
- end
- attr_accessor :saved_weapons
- attr_accessor :saved_armors
- def gain_item(item, amount, include_equip = false)
- container = item_container(item.class)
- return unless container
- last_number = item_number(item)
- if item.is_a?(RPG::EquipItem) && last_number != 0
- data = $data_weapons if item.is_a?(RPG::Weapon)
- data = $data_armors if item.is_a?(RPG::Armor)
- item = Marshal.load(Marshal.dump(data[item.id]))
- data.push(item)
- item.id = data.size
- end
- last_number = item_number(item)
- new_number = last_number + amount
- container[item.id] = [[new_number, 0].max, max_item_number(item)].min
- container.delete(item.id) if container[item.id] == 0
- if include_equip && new_number < 0
- discard_members_equip(item, -new_number)
- end
- $game_map.need_refresh = true
- end
- end
- class Scene_Load
- alias lvl_on_load_success on_load_success
- def on_load_success
- lvl_on_load_success
- $data_weapons = $game_party.saved_weapons
- $data_armors = $game_party.saved_armors
- end
- end
- class RPG::UsableItem::Damage
- alias level_up_eval eval
- def eval(a, b, v)
- return level_up_eval(a,b,v) if !LVLUP::LEVEL_UP_SKILLS
- val = [Kernel.eval(@formula), 0].max * sign rescue 0
- val *= (1 + a.slvl($last_actor_skill) * LVLUP.param(@note)) if a.is_a?(Game_Actor)
- val
- end
- end
- class Window_Base
- alias level_up_din draw_item_name
- def draw_item_name(item, x, y, enabled = true, width = 172)
- return unless item
- if !LVLUP::LEVEL_UP_SKILLS && item.is_a?(RPG::Skill)
- return level_up_din(item,x,y,enabled,width)
- elsif !LVLUP::LEVEL_UP_ITEMS && (item.is_a?(RPG::Weapon) || item.is_a?(RPG::Armor))
- return level_up_din(item,x,y,enabled,width)
- end
- draw_icon(item.icon_index, x, y, enabled)
- change_color(normal_color, enabled)
- if item.is_a?(RPG::EquipItem) && LVLUP::DRAW_EXP_BAR
- draw_item_gauge(item,x,y)
- elsif item.is_a?(RPG::Skill) && LVLUP::DRAW_EXP_BAR && @actor
- draw_skill_gauge(item,x,y)
- end
- change_color(item.color, enabled) if Module.const_defined?(:AFFIXES)
- text = item.name
- text = eval(LVLUP::ITEM_NAME) if !item.is_a?(RPG::Skill) && !item.is_a?(RPG::Item)
- text = eval(LVLUP::SKILL_NAME) if item.is_a?(RPG::Skill) && @actor
- draw_text(x + 24, y, width, line_height, text)
- change_color(normal_color, enabled)
- end
- def draw_item_gauge(item,x,y)
- fill_w = (24 * item.exp_rate).to_i
- gauge_y = y + line_height - 8
- contents.fill_rect(x, gauge_y, 24, 6, gauge_back_color)
- contents.gradient_fill_rect(x, gauge_y, fill_w, 6, Color.new(0,255,0), Color.new(75,200,75))
- contents.font.size = 14
- draw_text(x+6,y+line_height-12,36,14,(item.exp_rate * 100).to_i.to_s + "%")
- contents.font.size = Font.default_size
- end
- def draw_skill_gauge(item,x,y)
- exp_rate = @actor.get_skill_exp_rate(item.id)
- fill_w = (24 * exp_rate).to_i
- gauge_y = y + line_height - 8
- contents.fill_rect(x, gauge_y, 24, 6, gauge_back_color)
- contents.gradient_fill_rect(x, gauge_y, fill_w, 6, Color.new(0,255,0), Color.new(75,200,75))
- contents.font.size = 14
- draw_text(x+6,y+line_height-12,36,14,(exp_rate * 100).to_i.to_s + "%")
- contents.font.size = Font.default_size
- end
- end
Advertisement
Add Comment
Please, Sign In to add comment