Class and actor exp curves problem

Hi, I made a post about this a couple of days ago, but It was a lot of rambling and suppositions, I've tested much more things and now I have a new perspective on the issue, that's why I'm making a new one.


First of all, I'm using a custom lvl formula for an actor, with this script(Actor Mod Formulas) along with YEA Class System, my exact problem is that the class system, uses the lvl formula of the classes in the database and not the custom one I'm using for the actor, this is just for the text showing the class levels though, because after changing classes it gives me the right level specified by my lvl formula. In other words, it's a visual problem.


I've found the part of Yanfly's code where this happens, lines 608 to 635:

Spoiler
 #————————————————————————–
 # new method: class_level Edited by DisturbedInside
 #————————————————————————–
 def class_level(class_id)
  return @level if YEA::CLASS_SYSTEM::MAINTAIN_LEVELS
   temp_class = $data_classes[class_id]
   @exp[class_id] = 0 if @exp[class_id].nil?
   #declare a max level (using EXP)
   #If you can’t find it, go to the class database and select exp curve
   #then switch view to total at the top
   @exp[max_level] = 2547133 #This is the value to change. It declares a max level
   #You need to calculate how much exp for max level
   #Do it manually if using Yanfly-Adjusting Limits
   #To calculate max level exp if using Yanfly-adjusting limits is all math!!


 


   # Level 99 = 2547133
   # to calculate past there…. have to add on multiples of 50744
   # Level 110 = 3156061
   # To go from 99 -> 110 have to add on 12 multiples of 50744.
   n = 1   
   loop do
    break if temp_class.exp_for_level(n+1) > @exp[class_id]
    n += 1
    #add a restriction to “kick out” of loop if exp exceeds max level exp
    break if temp_class.exp_for_level(n+1) > @exp[max_level]
   end
  return n
 end

The exact part I think I should modify is near the end, where the loop starts. What I understand(sort of) is that, when changing classes, if the exp stored on the temp class is enough to lvl up according to the database class lvl formula, it sums up a lvl and continue to do that until it isn't enough exp to lvl up.


What I don't know how to do, and hopefully will correct this issue, is how do I change the condition to use my lvl formula instead of the database ones?


The custom lvl formula I'm using for the actor is this one: ((((level-1)*4)**2) + (level-1)*500).round.to_i


I would appreciate any help on the matter as I've tested some things but I can't manage to achieve it.
Hi,


Seems you did all the work already. 🙂
temp_class is used as a reference to the settings you did for the class in the database (see line 613). @exp holds a list of experience values the actor has obtained for each class id at this moment. The loop is used to find the lowest class level n that requires additional experience to level up (which is the current class level).


You'd have to modify the temp_class.exp_for_level(n+1) part, which just returns the amount of experience you specified for this class/level in the database. You could do this by either...


- Copy over the changes made in the Actor Mod Formulas script, which could look like this:

Spoiler
  #————————————————————————–
  # new method: class_level Edited by DisturbedInside
  #————————————————————————–
  def class_level(class_id)
    return @level if YEA::CLASS_SYSTEM::MAINTAIN_LEVELS
    temp_class = $data_classes[class_id]
    @exp[class_id] = 0 if @exp[class_id].nil?
    #declare a max level (using EXP)
    #If you can’t find it, go to the class database and select exp curve
    #then switch view to total at the top
    # @exp[max_level] = 2547133 #This is the value to change. It declares a max level
    #You need to calculate how much exp for max level
    #Do it manually if using Yanfly-Adjusting Limits
    #To calculate max level exp if using Yanfly-adjusting limits is all math!!



   


    # Level 99 = 2547133
    # to calculate past there…. have to add on multiples of 50744
    # Level 110 = 3156061
    # To go from 99 -> 110 have to add on 12 multiples of 50744.
    n = 1   
    loop do



      base = temp_class.exp_for_level(n+1)


      next_exp = actor.note_exp_for_level.empty? ? base : efl_eval(actor.note_exp_for_level, n+1, base)
      break if next_exp > @exp[class_id]
      n += 1
      #add a restriction to “kick out” of loop if exp exceeds max level exp
      break if n >= max_level
    end
    return n
  end



- Temporarily change the actors class and use the actors experience_for_level method. I don't know if I would recommend that, but would probably have a better chance to be compatible with other experience-modifying scripts if you ever use some:

Spoiler
  #————————————————————————–
  # new method: class_level Edited by DisturbedInside
  #————————————————————————–
  def class_level(class_id)
    return @level if YEA::CLASS_SYSTEM::MAINTAIN_LEVELS
    # temp_class = $data_classes[class_id]
    # @exp[class_id] = 0 if @exp[class_id].nil?

    #declare a max level (using EXP)
    #If you can’t find it, go to the class database and select exp curve
    #then switch view to total at the top
    # @exp[max_level] = 2547133 #This is the value to change. It declares a max level
    #You need to calculate how much exp for max level
    #Do it manually if using Yanfly-Adjusting Limits
    #To calculate max level exp if using Yanfly-adjusting limits is all math!!



   


    # Level 99 = 2547133
    # to calculate past there…. have to add on multiples of 50744
    # Level 110 = 3156061
    # To go from 99 -> 110 have to add on 12 multiples of 50744.
    n = 1



    original_class = @class_id


    @class_id = class_id  # Change the actors class temporarily
    loop do

      break if exp_for_level(n+1) > @exp[class_id]
      n += 1
      #add a restriction to “kick out” of loop if exp exceeds max level exp
      break if n >= max_level
    end
   
@class_id = original_class  # Revert to the actors original class


    return n
  end





The orange colored changes were made because they don't make sense to me. As mentioned, @exp holds a list of experience values per class, so this line  @exp[max_level] = 2547133 would just modify the experience for the class whose id happens to match the actors maximum level.


In order to stop the loop when reaching the maximum level, comparing the maximum level with n should be enough. I might overlook something here of course.
Thanks for your help Fen, but after implementing your idea the problem wasn't solved, it stayed the same, as I'm typing this I though that it may be because the actor mod formula script is below the class system one, but I already cleaned a lot of stuff and I'm not interested in solving this issue now anyway, after testing stuff, it felt more natural and coherent that after changing classes you stay the same lvl, at least on my project. But thanks really, if not to me your idea could help someone else in the future.

Original thread: https://forums.rpgmakerweb.com/threads/class-and-actor-exp-curves-problem.62971/