Advertisement
roninator2

Vindaca Promotion System Addon - Require Item

Dec 4th, 2024
48
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Ruby 13.26 KB | None | 0 0
  1. =begin
  2. #=====================================================================
  3. #   AMN V's Promotions - Add-on
  4. #   Version 1.2
  5. #   Author: AMoonlessNight
  6. #   Date: 23 Mar 2018
  7. #   Latest: 24 Mar 2018
  8. #=====================================================================#
  9. #   UPDATE LOG
  10. #---------------------------------------------------------------------#
  11. # 23 Mar 2018 - created the add-on script for V's Promotions
  12. # 24 Mar 2018 - fixed level up and gain exp methods
  13. #             - added greyed out colour for actors that are promotable
  14. #               but don't have the correct items
  15. #             - fixed gain exp method
  16. #=====================================================================#
  17.  
  18. This script was requested as an add-on to V's Promotions script.
  19. It will not work without it.
  20.  
  21. V's Promotions script can be found here:
  22. https://forums.rpgmakerweb.com/index.php?threads/vs-promotion-system-v0-2.18875/
  23.  
  24. Requested by Roninator2
  25.  
  26. #=====================================================================#
  27.           NOTETAGS
  28. #=====================================================================#
  29.  
  30. Notetag actors as many times as you require with the following:
  31.  
  32.     * <Promotion: Level, Graphic_Name, Graphic_Index, Cost, Class, Item>
  33.   #----------------------------------------------------------------#
  34.   # Item is a new addition and should be replaced with the number
  35.   # of the item that the party must have in order for this actor
  36.   # to be promoted (e.g. 5 for Stimulant).
  37.   #----------------------------------------------------------------#
  38.  
  39. =end
  40.  
  41.  
  42. #==============================================================================
  43. #
  44. # ** Please do not edit below this point unless you know what you are doing.
  45. #
  46. #==============================================================================
  47.  
  48.  
  49.  
  50. #==============================================================================
  51. # ** Game_Actor
  52. #------------------------------------------------------------------------------
  53. #  This class handles actors. It is used within the Game_Actors class
  54. # ($game_actors) and is also referenced from the Game_Party class ($game_party).
  55. #==============================================================================
  56.  
  57. class Game_Actor < Game_Battler
  58.  
  59.   #--------------------------------------------------------------------------
  60.   # * Public Instance Variables
  61.   #--------------------------------------------------------------------------
  62.   attr_accessor :next_promotion_item             # Item needed to promote actor
  63.   attr_accessor :next_promo_level                # The next promotion level
  64.  
  65.   #--------------------------------------------------------------------------
  66.   # * Setup                                                  # ALIAS METHOD #
  67.   #--------------------------------------------------------------------------
  68.   alias :amn_vpromo_gameactor_setup :setup
  69.   def setup(actor_id)
  70.     @next_promotion_item = 0
  71.     amn_vpromo_gameactor_setup(actor_id)
  72.   end
  73.  
  74.   #--------------------------------------------------------------------------
  75.   # * Gain EXP (Account for Experience Rate)
  76.   #--------------------------------------------------------------------------
  77.   alias :amn_vpromo_gameactor_gainexp :gain_exp
  78.   def gain_exp(exp)
  79.     req_exp = exp_for_level(next_promo_level?)
  80.     value = self.exp + (exp * final_exp_rate).to_i
  81.     if !at_promotion_level?
  82.       if value < req_exp
  83.         amn_vpromo_gameactor_gainexp(exp)
  84.       else
  85.         change_exp(req_exp, true)
  86.       end
  87.     end
  88.   end
  89.  
  90.   #--------------------------------------------------------------------------
  91.   # * Change Experience
  92.   #     show : Level up display flag
  93.   #--------------------------------------------------------------------------
  94.   def change_exp(exp, show)
  95.     @exp[@class_id] = [exp, 0].max unless at_promotion_level?
  96.     last_level = @level
  97.     last_skills = skills
  98.     level_up while !max_level? && self.exp >= next_level_exp
  99.     level_down while self.exp < current_level_exp
  100.     display_level_up(skills - last_skills) if show && @level > last_level
  101.     refresh
  102.   end
  103.  
  104.   #--------------------------------------------------------------------------
  105.   # * Sets up the actor's note                           # OVERWRITE METHOD #
  106.   #--------------------------------------------------------------------------
  107.   def set_up_actor_note(actor_id)
  108.     note= /<Promotion:\s*(\d*)\S*\s*(\w*)\S*\s*(\d*)\S*\s*(\d*)\S*\s*(\d*)\S*\s*(\d*)>/i
  109.     @actors_note = $data_actors[actor_id].note.scan(note)
  110.   end
  111.  
  112.   #--------------------------------------------------------------------------
  113.   # * Check For Promotions                                   # ALIAS METHOD #
  114.   #--------------------------------------------------------------------------
  115.   alias amn_vpromo_checkforpromo  check_for_promotion
  116.   def check_for_promotion
  117.     amn_vpromo_checkforpromo &&
  118.     @actors_note.size.times { |i| @next_promotion_item = @actors_note[i][5].to_i if @level == @actors_note[i][0].to_i }
  119.   end
  120.  
  121.   #--------------------------------------------------------------------------
  122.   # * Check Promotion Items                                    # NEW METHOD #
  123.   #--------------------------------------------------------------------------
  124.   def check_promotion_items
  125.     return true if needs_promotion_item? && $game_party.items.include?($data_items[@next_promotion_item])
  126.   end
  127.  
  128.   #--------------------------------------------------------------------------
  129.   # * Needs Promotion Item?                                    # NEW METHOD #
  130.   #--------------------------------------------------------------------------
  131.   def needs_promotion_item?
  132.     return false if @next_promotion_item == 0
  133.     return true
  134.   end
  135.  
  136.   #--------------------------------------------------------------------------
  137.   # * Checks if actor is promotable                          # ALIAS METHOD #
  138.   #--------------------------------------------------------------------------
  139.   alias amn_vpromo_promotable?  promotable?
  140.   def promotable?
  141.     if needs_promotion_item?
  142.       return true if check_promotion_items && @needs_promotion == true
  143.     else
  144.       amn_vpromo_promotable?
  145.     end
  146.   end
  147.  
  148.   #--------------------------------------------------------------------------
  149.   # * Next Promotion Level                                     # NEW METHOD #
  150.   #--------------------------------------------------------------------------
  151.   def next_promo_level?
  152.     array = []
  153.     @actors_note.size.times { |i| array.push(@actors_note[i][0].to_i) }
  154.     array.keep_if { |a| a > @level }
  155.     array.sort
  156.     if array.empty?
  157.       @next_promo_level = max_level
  158.     else
  159.       @next_promo_level = array[0]
  160.     end
  161.   end
  162.  
  163.   #--------------------------------------------------------------------------
  164.   # * At Promotion Level?                                      # NEW METHOD #
  165.   #--------------------------------------------------------------------------
  166.   # Had to do this in order for level up commands to work properly
  167.   #--------------------------------------------------------------------------
  168.   def at_promotion_level?
  169.     amn_vpromo_promotable?
  170.   end
  171.  
  172.   #--------------------------------------------------------------------------
  173.   # * Promote Processing                                     # ALIAS METHOD #
  174.   #--------------------------------------------------------------------------
  175.   alias amn_vpromo_promote  promote
  176.   def promote
  177.     if @next_promotion_item > 0
  178.       $game_party.lose_item($data_items[@next_promotion_item], 1)
  179.     end
  180.     amn_vpromo_promote
  181.   end
  182.  
  183.   #--------------------------------------------------------------------------
  184.   # * Promotion Items                                          # NEW METHOD #
  185.   #--------------------------------------------------------------------------
  186.   def promotion_items?
  187.     return @next_promotion_item
  188.   end
  189.  
  190. end
  191.  
  192. #==============================================================================
  193. # ** Game_Interpreter
  194. #------------------------------------------------------------------------------
  195. #  An interpreter for executing event commands. This class is used within the
  196. # Game_Map, Game_Troop, and Game_Event classes.
  197. #==============================================================================
  198.  
  199. class Game_Interpreter
  200.   #--------------------------------------------------------------------------
  201.   # * Change EXP
  202.   #--------------------------------------------------------------------------
  203.   alias amn_vpromo_gameint_cmd315   command_315
  204.   def command_315
  205.     value = operate_value(@params[2], @params[3], @params[4])
  206.     iterate_actor_var(@params[0], @params[1]) do |actor|
  207.       req_exp = actor.exp_for_level(actor.next_promo_level?)
  208.       if !actor.at_promotion_level?
  209.         if value < req_exp
  210.           actor.change_exp(actor.exp + value, @params[5])
  211.         else
  212.           actor.change_exp(req_exp, @params[5])
  213.         end
  214.       end
  215.     end
  216.   end
  217.  
  218.   #--------------------------------------------------------------------------
  219.   # * Change Level
  220.   #--------------------------------------------------------------------------
  221.   alias amn_vpromo_gameint_cmd316   command_316
  222.   def command_316
  223.     value = operate_value(@params[2], @params[3], @params[4])
  224.     iterate_actor_var(@params[0], @params[1]) do |actor|
  225.       if !actor.at_promotion_level?
  226.         if value < actor.next_promo_level?
  227.           actor.change_level(actor.level + value, @params[5])
  228.         else
  229.           actor.change_level(actor.next_promo_level, @params[5])
  230.         end
  231.       end
  232.     end
  233.   end
  234.  
  235. end
  236.  
  237. #==============================================================================
  238. # ** Window_Base
  239. #------------------------------------------------------------------------------
  240. #  This is a super class of all windows within the game.
  241. #==============================================================================
  242.  
  243. class Window_Base < Window
  244.  
  245.   def greyout_colour;    text_color(7);  end;    # Greyed out
  246.  
  247.   #--------------------------------------------------------------------------
  248.   # * Draw Level
  249.   #--------------------------------------------------------------------------
  250.   alias :amn_vpromo_windbase_drawactorlevel   :draw_actor_level
  251.   def draw_actor_level(actor, x, y)
  252.     amn_vpromo_windbase_drawactorlevel(actor, x, y)
  253.     if actor.promotable?
  254.       draw_v_text(x, y + 25, 150, line_height, "Promotable", 0, 24, crisis_color)
  255.     elsif actor.at_promotion_level? && !actor.promotable?
  256.       draw_v_text(x, y + 25, 150, line_height, "Promotable", 0, 24, greyout_colour)
  257.     end
  258.   end
  259.  
  260. end
  261.  
  262. #==============================================================================
  263. # ** Promotion_Info_Window
  264. #------------------------------------------------------------------------------
  265. #  This class handles all of the Promotion Info Window processing.
  266. #==============================================================================
  267.  
  268. class Promotion_Info_Window < Window_Base
  269.    
  270.   #--------------------------------------------------------------------------
  271.   # * Draws actors info                                  # OVERWRITE METHOD #
  272.   #--------------------------------------------------------------------------
  273.   def draw_actor_info(index)
  274.     actor = @promotables[@index]
  275.     cost = "Cost: " + actor.promotion_cost?.to_s
  276.     # AMN addition
  277.     if actor.next_promotion_item > 0
  278.       item = $data_items[actor.next_promotion_item]
  279.       icon = '\i[' + item.icon_index.to_s + '] '
  280.       name = item.name.to_s + ' '
  281.       amt = $game_party.item_number(item)
  282.       if amt == 0
  283.         itemtxt = icon + name + '\c[2]' + amt.to_s + '\c[2] / 1'
  284.       else
  285.         itemtxt = icon + name + amt.to_s + ' / 1'
  286.       end
  287.      
  288.     else
  289.       itemtxt = ''
  290.     end
  291.     #
  292.     draw_v_text(120, 55, (Graphics.width / 3) * 2, 75, actor.name, 0, 45)
  293.     draw_actor_face(actor, 10, 10)
  294.     draw_zoomed_actor_graphic(actor, 40, 150, 2)
  295.     draw_v_text(-105, 200, (Graphics.width / 3) * 2, 75, $data_classes[actor.class_id].name, 1, 22)
  296.     draw_v_text(-10, 150, (Graphics.width / 3) * 2, 75, ">", 1, 55)
  297.     draw_zoomed_character(actor.next_promotion_name, actor.next_promotion_index, 230, 150, 2)
  298.     draw_v_text(85, 200, (Graphics.width / 3) * 2, 75, $data_classes[actor.next_promotion_class].name, 1, 22)
  299.     draw_v_text(-10, 250, (Graphics.width / 3) * 2, 75, cost, 1, 40)
  300.     draw_text_ex(10, 250, itemtxt)
  301.   end
  302.  
  303. end
  304.  
  305. #==============================================================================
  306. # ** Promotion_Command_Window
  307. #------------------------------------------------------------------------------
  308. #  This class handles all of the Promotion Command Window processing.
  309. #==============================================================================
  310.  
  311. class Promotion_Command_Window < Window_Command
  312.    
  313.   #--------------------------------------------------------------------------
  314.   # * Checks if party has enough to buy promotion            # ALIAS METHOD #
  315.   #--------------------------------------------------------------------------
  316.   alias amn_vpromo_promocmdwdw_afford?      afford?
  317.   def afford?(id)
  318.     if @promotables[id].promotion_items? != 0
  319.       $game_party.gold >= @promotables[id].promotion_cost? && $game_party.items.include?($data_items[@promotables[id].promotion_items?])
  320.     else
  321.       $game_party.gold >= @promotables[id].promotion_cost?
  322.     end
  323.    
  324.   end
  325. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement