neonblack

Class EXP based skills

Feb 17th, 2014
124
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. class Game_Actor < Game_Battler
  2.   ActorSwitchHash ={
  3.     1 => 100,
  4.     2 => 101,
  5.   }
  6.   LearnVocab = "<name> learned <skill>!"
  7.  
  8.   alias_method "cp_maus_02172014_change_exp", "change_exp"
  9.   def change_exp(*args)
  10.     exp_dif = [args[0], 0].max - @exp[@class_id]
  11.     return cp_maus_02172014_change_exp(*args) unless exp_dif > 0
  12.     last_level = @level
  13.     last_skills = skills
  14.     class_exp_v(exp_dif) if check_actor_switch_hash
  15.     cp_maus_02172014_change_exp(*args)
  16.     return unless @level == last_level
  17.     set_class_based_skills
  18.     display_skills_up(skills - last_skills) if args[1]
  19.   end
  20.  
  21.   def display_skills_up(new_skills)
  22.     return if new_skills.nil? || new_skills.empty?
  23.     $game_message.new_page
  24.     new_skills.each do |skill|
  25.       text = LearnVocab.clone
  26.       text.gsub!('<name>', name)
  27.       text.gsub!('<skill>', skill.name)
  28.       $game_message.add(text)
  29.     end
  30.   end
  31.  
  32.   def class_exp_v(add = 0)
  33.     @class_exp_hash ||= {}
  34.     @class_exp_hash[self.class.id] ||= 0
  35.     @class_exp_hash[self.class.id] += add
  36.     return @class_exp_hash[self.class.id]
  37.   end
  38.  
  39.   def check_actor_switch_hash
  40.     return true unless ActorSwitchHash.include?(id)
  41.     return $game_switches[ActorSwitchHash[id]]
  42.   end
  43.  
  44.   def set_class_based_skills
  45.     self.class.learnings.each do |learning|
  46.       result = learning.level <= @level
  47.       if learning.note =~ /learn exp\[(\d+)\]/i
  48.         result = result && $1.to_i <= class_exp_v
  49.       end
  50.       if learning.note =~ /forget exp\[(\d+)\]/i
  51.         result = result && $1.to_i > class_exp_v
  52.       end
  53.       result ? learn_skill(learning.skill_id) : forget_skill(learning.skill_id)
  54.     end
  55.   end
  56.  
  57.   def init_skills
  58.     @skills = []
  59.     set_class_based_skills
  60.   end
  61.  
  62.   def level_up
  63.     @level += 1
  64.     set_class_based_skills
  65.   end
  66. end
RAW Paste Data