Advertisement
roninator2

Yanfly Class System Addons - JP

Dec 9th, 2024
43
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Ruby 9.06 KB | None | 0 0
  1. #==============================================================================
  2. #
  3. # ▼ Yanfly Engine Ace - JP Manager v1.06 Addon for subclass
  4. # -- Last Updated: 2019.10.13
  5. # -- Requires: Yanfly Class System
  6. #              Estriole Subclass Addon
  7. #              Yanfly JP Manager
  8. # -- addon created by: Roninator2
  9. #==============================================================================
  10. # ▼ Updates
  11. # =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
  12. # 2019.10.05 - Started Script
  13. # 2019.10.06 - Added support for subclass to earn battle jp
  14. #            - Added name size cuting for long class names. Display issue
  15. # 2019.10.07 - Fixed several bugs
  16. # 2019.10.09 - Removed global variables
  17. # 2019.10.10 - Fixed JP gain by subclass
  18. # 2019.10.12 - Fixed maintain_levels no longer needs to be false
  19. # 2019.10.13 - Fixed skill cost for Maintain_levels
  20. # 2019.10.13 - Restored support for yanfly Menu system
  21. #==============================================================================
  22. # ▼ Introduction
  23. # =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
  24. # Allow Subclass to gain JP
  25. #==============================================================================
  26.  
  27. module R2_subclass_battle_jp
  28.   Gain_JP = true        # if you want subclasses to gain JP from battles
  29.   JP_factor = 0.50      # JP earned to subclass (value * factor) 10 * 0.5 = 5
  30.   Cut_text = true       # cut the class name if it is too long. Fixes display
  31.   Name_length = 7       # first number of characters in the actors class name
  32. end
  33.  
  34. class Game_Interpreter
  35.   def command_316
  36.    value = operate_value(@params[2], @params[3], @params[4])
  37.    iterate_actor_var(@params[0], @params[1]) do |actor|
  38.      actor.sublevelup = true
  39.      actor.sublevelcnt = value
  40.      actor.change_level(actor.level + value, @params[5])
  41.    end
  42.   end
  43. end
  44.  
  45. class Game_Actor < Game_Battler
  46.  
  47.   attr_accessor   :sublevelup
  48.   attr_accessor   :sublevelcnt
  49.   attr_accessor   :lostjp
  50.  
  51.   def init_jp
  52.     @jp = {}
  53.     @jp[@class_id] = 0
  54.     @jp[@subclass_id] = 0
  55.     @sublevelup = false
  56.     @sublevelcnt = 0
  57.     @lostjp = false
  58.   end
  59.      
  60.   alias r2_game_actor_level_up_jp level_up
  61.   def level_up
  62.     r2_game_actor_level_up_jp
  63.     lose_jp(YEA::JP::LEVEL_UP) if SceneManager.scene_is?(Scene_Class)
  64.     return if !@subclass_id
  65.     return if @subclass_id == 0
  66.     return if YEA::CLASS_SYSTEM::MAINTAIN_LEVELS
  67.     if @sublevelup
  68.       @exp[@subclass_id] = exp_for_level(class_level(@subclass_id).to_i + @sublevelcnt)
  69.     elsif @exp[@subclass_id] == exp_for_level(class_level(@subclass_id).to_i + 1)
  70.       @sublevelup = true
  71.       class_level(@subclass_id).to_i + 1
  72.       @sublevelcnt += 1
  73.     end
  74.     if @sublevelup
  75.       @jp[@subclass_id] += YEA::JP::LEVEL_UP * @sublevelcnt
  76.       @sublevelup = false
  77.       @sublevelcnt = 0
  78.     end
  79.   end
  80.  
  81.   def gain_jp(jp, class_id = nil)
  82.     init_jp if @jp.nil?
  83.     class_id = @class_id if class_id.nil?
  84.     battlejp = jp
  85.     @jp[class_id] = 0 if @jp[class_id].nil?
  86.     @jp[class_id] += jp.to_i
  87.     @jp[class_id] = [[@jp[class_id], YEA::JP::MAX_JP].min, 0].max
  88.     return if @lostjp
  89.     if $game_party.in_battle && R2_subclass_battle_jp::Gain_JP
  90.       jp = (jp * R2_subclass_battle_jp::JP_factor).round
  91.       @jp[@subclass_id] += jp.to_i if (@subclass_id != nil || 0)
  92.     elsif R2_subclass_battle_jp::Gain_JP && YEA::CLASS_SYSTEM::MAINTAIN_LEVELS
  93.       @jp[@subclass_id] = 0 if @jp[@subclass_id].nil?
  94.       @jp[@subclass_id] += jp.to_i
  95.       @jp[@subclass_id] = [[@jp[@subclass_id], YEA::JP::MAX_JP].min, 0].max
  96.     end
  97.     @battle_jp_earned = 0 if @battle_jp_earned.nil? && $game_party.in_battle
  98.     @battle_jp_earned += battlejp.to_i if $game_party.in_battle
  99.   end
  100.  
  101.   alias r2_subclass_add_ecp_82v7b4  subclass_add_exp
  102.   def subclass_add_exp(class_id,value)
  103.     if @subclass_id != nil && @subclass_id != 0
  104.       last_level = class_level(class_id).to_i
  105.       last_skills = skills
  106.       r2_subclass_add_ecp_82v7b4(class_id,value)
  107.     else
  108.         return if !@subclass_id
  109.         return if @subclass_id == 0
  110.         return if YEA::CLASS_SYSTEM::MAINTAIN_LEVELS
  111.         last_level = class_level(class_id).to_i
  112.         last_skills = skills
  113.         exprate = sub_exp_rate(class_id)
  114.         expvalue = (value * exprate).to_i
  115.         expvalue = [expvalue,1].max if ESTRIOLE::SUBCLASS_MIN_1_EXP && value != 0
  116.         @exp[class_id] = @exp[class_id] + expvalue
  117.         @exp[class_id] = [@exp[class_id],subclass.exp_for_level(subclass_max_level)].min
  118.           self.subclass.learnings.each do |learning|
  119.             learn_skill(learning.skill_id) if learning.level <= class_level(class_id).to_i
  120.                if @extra_features && class_level(class_id).to_i > last_level && learning.note =~ /<extratrait (.*)>/i
  121.                 @extra_features.features += $data_weapons[$1.to_i].features if EXTRA_FEATURES_SOURCE == 0
  122.                 @extra_features.features += $data_armors[$1.to_i].features if EXTRA_FEATURES_SOURCE == 1
  123.                 @extra_features.features += $data_states[$1.to_i].features if EXTRA_FEATURES_SOURCE == 2
  124.                end
  125.            end
  126.       display_level_up_sub(skills - last_skills) if class_level(class_id).to_i > last_level
  127.     end
  128.     if R2_subclass_battle_jp::Gain_JP
  129.       sublevelcnt = class_level(class_id).to_i - last_level
  130.       @jp[class_id] += YEA::JP::LEVEL_UP * sublevelcnt if last_level < class_level(class_id).to_i
  131.     end
  132.   end
  133.  
  134. end # Game_Actor
  135.  
  136. class Window_Base < Window
  137.  
  138.   if $imported["YEA-AceMenuEngine"]
  139.     def draw_actor_simple_status(actor, dx, dy)
  140.       dy -= line_height / 2
  141.       draw_actor_name(actor, dx, dy)
  142.       draw_actor_level(actor, dx, dy + line_height * 1)
  143.       draw_actor_icons(actor, dx, dy + line_height * 2)
  144.       dx = dx + 25
  145.       dw = contents.width - dx - 124
  146.       draw_actor_class(actor, dx + 120, dy, dw)
  147.       draw_actor_hp(actor, dx + 120, dy + line_height * 1, dw)
  148.       if YEA::MENU::DRAW_TP_GAUGE && actor.draw_tp? && !actor.draw_mp?
  149.         draw_actor_tp(actor, dx + 120, dy + line_height * 2, dw)
  150.       elsif YEA::MENU::DRAW_TP_GAUGE && actor.draw_tp? && actor.draw_mp?
  151.         if $imported["YEA-BattleEngine"]
  152.           draw_actor_tp(actor, dx + 120, dy + line_height * 2, dw/2 - 1)
  153.           draw_actor_mp(actor, dx + 120 + dw/2, dy + (line_height * 2), dw/2 + 1)
  154.         else
  155.           draw_actor_mp(actor, dx + 120, dy + line_height * 2, dw/2 - 1)
  156.           draw_actor_tp(actor, dx + 120 + dw/2, dy + line_height * 2, dw/2 + 1)
  157.         end
  158.       elsif YEA::MENU::DRAW_TP_GAUGE && actor.draw_mp?
  159.         draw_actor_mp(actor, dx + 120, dy + line_height * 2, dw)
  160.       end
  161.     end
  162.   end
  163.  
  164.   alias r2_draw_actor_class_924v  draw_actor_simple_status
  165.   def draw_actor_simple_status(actor, dx, dy)
  166.     r2_draw_actor_class_924v(actor, dx, dy)
  167.     @class_id = actor.class_id
  168.     @sublass_id = actor.subclass.nil? ? nil : actor.subclass.id
  169.     dy = dy - 10
  170.     draw_actor_jp_class(actor, @class_id, dx, dy + line_height * 2)
  171.     if !actor.subclass.nil?
  172.     draw_actor_jp_subclass(actor, @subclass_id, dx, dy + line_height * 3)
  173.     end
  174.   end
  175.  
  176.   def draw_actor_jp_class(actor, class_id, dx, dy, dw = 112)
  177.     draw_icon(Icon.jp, dx + dw - 24, dy) if Icon.jp > 0
  178.     dw -= 24 if Icon.jp > 0
  179.     change_color(system_color)
  180.     dw = dw - 10
  181.     dy = dy + 5
  182.     if R2_subclass_battle_jp::Cut_text
  183.       text = actor.class.name
  184.       text = text[0..(R2_subclass_battle_jp::Name_length - 1)]
  185.       draw_text(dx, dy, dw, line_height, text, 3)
  186.     else
  187.       draw_text(dx, dy, dw, line_height, actor.class.name, 3)
  188.     end
  189.     dw = dw + 20
  190.     dx = dx + 20 if $imported["YEA-AceMenuEngine"]
  191.     draw_text(dx, dy, dw, line_height, Vocab::jp, 2)
  192.     dw -= text_size(Vocab::jp).width
  193.     change_color(normal_color)
  194.     draw_text(dx, dy, dw, line_height, actor.jp(class_id).group, 2)
  195.   end
  196.  
  197.   def draw_actor_jp_subclass(actor, subclass_id, dx, dy, dw = 112)
  198.     draw_icon(Icon.jp, dx + dw - 24, dy) if Icon.jp > 0
  199.     dw -= 24 if Icon.jp > 0
  200.     change_color(system_color)
  201.     dw = dw - 10
  202.     if R2_subclass_battle_jp::Cut_text
  203.       text = actor.subclass.name
  204.       text = text[0..(R2_subclass_battle_jp::Name_length - 1)]
  205.       draw_text(dx, dy, dw, line_height, text, 3)
  206.     else
  207.       draw_text(dx, dy, dw, line_height, actor.subclass.name, 3)
  208.     end
  209.     dw = dw + 20
  210.     dx = dx + 20 if $imported["YEA-AceMenuEngine"]
  211.     draw_text(dx, dy, dw, line_height, Vocab::jp, 2)
  212.     dw -= text_size(Vocab::jp).width
  213.     change_color(normal_color)
  214.     draw_text(dx, dy, dw, line_height, actor.jp(actor.subclass.id).group, 2)
  215.   end
  216.  
  217. end # Window_Base
  218.  
  219. class Scene_LearnSkill < Scene_Skill
  220.   def on_cost_ok
  221.     Sound.play_use_skill
  222.     skill = @item_window.item
  223.     @actor.learn_skill(skill.id)
  224.     cost = skill.learn_cost[0]
  225.     case skill.learn_cost[1]
  226.     when :jp
  227.         @actor.lostjp = true
  228.         @actor.lose_jp(cost, @cost_front.skill_class)
  229.         @actor.lostjp = false
  230.     when :exp
  231.       @actor.lose_exp_class(cost, @cost_front.skill_class)
  232.     when :gold
  233.       $game_party.lose_gold(cost)
  234.     end
  235.     on_cost_cancel
  236.     refresh_windows
  237.   end
  238. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement