Advertisement
roninator2

Yanfly Skill cost manager - item cost

Dec 8th, 2024
30
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Ruby 13.85 KB | None | 0 0
  1. #==============================================================================
  2. #
  3. # ▼ Yanfly Engine Ace - Skill Cost Manager - Item cost addon v1.01
  4. # -- Last Updated: 2024.01.02
  5. # -- Level: Normal, Hard, Lunatic
  6. # -- Requires: n/a
  7. #
  8. #==============================================================================
  9.  
  10. #==============================================================================
  11. # ▼ Updates
  12. # =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
  13. # 2024.01.02 - Started Script and Finished.
  14. #
  15. # -----------------------------------------------------------------------------
  16. # Skill Notetags - These notetags go in the skills notebox in the database.
  17. # -----------------------------------------------------------------------------
  18. # <custom cost item requirement: list order, item needed, item type,
  19. #         item number, consume>
  20. # <custom cost item requirement:   0              3           i
  21. #             1           c>
  22. # <custom cost item requirement: 0 3 i 1 c>
  23. # this would be for requirement # 0 -> you need 3 of item #1 (potion)
  24. # starts at 0 and must be in order. You can't have 0, 1, 3, with 2 missing.
  25. # teh c is to indicate if the item is to be consumed when the skill is used
  26. #
  27. # <custom cost item requirement: 1 2 i 3>
  28. # this would be for requirement # 1 -> you need 2 of item #3 (hi potion)
  29. #
  30. # <custom cost item requirement: 2 1 w 3>
  31. # this would be for requirement # 2 -> you need 1 of weapon #3 (axe)
  32. #
  33. # Sets the custom cost item requirement of the skill with specifying the item
  34. # using numbers to indicate what item type and quantity
  35. # The first digit is to structure the order. If you place them in order
  36. # of 2, 0, 1 for the note tags, you will see them in order, 0, 1, 2.
  37. #
  38. # this will use the item icon and show the numbers required with the
  39. # amount in inventory
  40. #==============================================================================
  41.  
  42. module YEA
  43.   module REGEXP
  44.     module SKILL
  45.       CUSTOM_COST_ITEM_REQ =
  46.         /<custom cost item requirement:[ -_](\d+)[ -_](\d+)[ -_](\w+)[ -_](\d+)(?:|[ -_](\w+))>/i
  47.     end
  48.   end
  49. end
  50.  
  51. class RPG::Skill < RPG::UsableItem
  52.   attr_accessor :custom_cost_item_requirement
  53.   attr_accessor :use_custom_item_cost
  54.   alias r2_use_item_req_notetags  load_notetags_scm
  55.   def load_notetags_scm
  56.     r2_use_item_req_notetags
  57.     # ---
  58.     @custom_cost_item_requirement = []
  59.     @use_custom_item_cost = false
  60.     # ---
  61.     self.note.split(/[\r\n]+/).each do |line|
  62.       case line
  63.       when YEA::REGEXP::SKILL::CUSTOM_COST_ITEM_REQ
  64.         @use_custom_item_cost = true
  65.         @custom_cost_item_requirement[$1.to_i] = [$2.to_i, $3.to_s, $4.to_i, $5.to_s]
  66.       end
  67.     end
  68.   end
  69.  
  70. end # RPG::Skill
  71.    
  72. #==============================================================================
  73. # ?! Window_BattleStatusAid
  74. #==============================================================================
  75.  
  76. class Window_BattleSkillAid < Window_SkillList
  77.  
  78.   #--------------------------------------------------------------------------
  79.   # public instance variables
  80.   #--------------------------------------------------------------------------
  81.   attr_accessor :skill_window
  82.  
  83.   #--------------------------------------------------------------------------
  84.   # overwrite method: initialize
  85.   #--------------------------------------------------------------------------
  86.   def initialize(x, y, window_width, window_height)
  87.     super
  88.     self.visible = false
  89.     self.openness = 255
  90.   end
  91.  
  92.   #--------------------------------------------------------------------------
  93.   # overwrite method: window_width
  94.   #--------------------------------------------------------------------------
  95.   def window_width; return 128; end
  96.  
  97.   #--------------------------------------------------------------------------
  98.   # overwrite method: window_height
  99.   #--------------------------------------------------------------------------
  100.   def window_height; return 128; end
  101.  
  102.   #--------------------------------------------------------------------------
  103.   # new method: close skill
  104.   #--------------------------------------------------------------------------
  105.   def close_skill
  106.     self.visible = false
  107.   end
  108.  
  109.   #--------------------------------------------------------------------------
  110.   # new method: close skill
  111.   #--------------------------------------------------------------------------
  112.   def open_skill
  113.     self.visible = true
  114.     @skill = @skill_window.item
  115.     refresh
  116.   end
  117.  
  118.   #--------------------------------------------------------------------------
  119.   # overwrite method: refresh
  120.   #--------------------------------------------------------------------------
  121.   def refresh
  122.     contents.clear
  123.     close_skill if @skill_window.nil?
  124.     return if @skill_window.nil?
  125.     close_skill unless @skill_window.item.use_custom_item_cost
  126.     return unless @skill_window.item.use_custom_item_cost
  127.     self.height = window_height
  128.     lines = 0
  129.     4.times do |i|
  130.       self.height -= 24 if @skill.custom_cost_item_requirement[i] == nil
  131.       lines += 1 if !@skill.custom_cost_item_requirement[i].nil?
  132.     end
  133.     contents.dispose
  134.     self.contents = Bitmap.new(contents_width, lines * 24)
  135.     contents.clear
  136.     self.y = Graphics.height - self.height - window_height + 8
  137.     num = @skill.custom_cost_item_requirement.size
  138.     j = 0
  139.    
  140.     num.times { |i|
  141.               if @skill.custom_cost_item_requirement[i] == nil
  142.                 j += 1
  143.                 next
  144.               end
  145.               rect = item_rect(i-j)
  146.               draw_custom_cost(rect, i, @skill)
  147.             }
  148.   end
  149.  
  150.   #--------------------------------------------------------------------------
  151.   # * Get Number of Items
  152.   #--------------------------------------------------------------------------
  153.   def item_max
  154.     data = 4
  155.     return data if @skill_window.nil?
  156.     return data if !@skill_window.item.use_custom_item_cost
  157.     4.times do |h|
  158.       data -= 1 if @skill.custom_cost_item_requirement[h] == nil
  159.     end
  160.     return data
  161.   end
  162.  
  163.   #--------------------------------------------------------------------------
  164.   # * Get Row Count
  165.   #--------------------------------------------------------------------------
  166.   def row_max
  167.     item_max
  168.   end
  169.  
  170.   #--------------------------------------------------------------------------
  171.   # * Calculate Height of Window Contents
  172.   #--------------------------------------------------------------------------
  173.   def contents_height
  174.     row_max * item_height
  175.   end
  176.  
  177.   #--------------------------------------------------------------------------
  178.   # * Get Digit Count
  179.   #--------------------------------------------------------------------------
  180.   def col_max
  181.     return 1
  182.   end
  183.  
  184.   #--------------------------------------------------------------------------
  185.   # * update
  186.   #--------------------------------------------------------------------------
  187.   alias r2_update_window  update
  188.   def update
  189.     r2_update_window
  190.     open_skill if @skill != @skill_window.item
  191.   end
  192.  
  193.   #--------------------------------------------------------------------------
  194.   # overwrite method: refresh
  195.   #--------------------------------------------------------------------------
  196.   def draw_custom_cost(rect, i, skill)
  197.     # new data
  198.     return if skill.custom_cost_item_requirement[i].nil?
  199.     quantity = skill.custom_cost_item_requirement[i][0]
  200.     item_type = skill.custom_cost_item_requirement[i][1].downcase
  201.     item_num = skill.custom_cost_item_requirement[i][2]
  202.     item = nil
  203.     case item_type
  204.     when "i"
  205.       item = $data_items[item_num]
  206.     when "a"
  207.       item = $data_armors[item_num]
  208.     when "w"
  209.       item = $data_weapons[item_num]
  210.     end
  211.     icon = item.icon_index
  212.     if icon > 0
  213.       draw_icon(icon, rect.x, rect.y, enable?(skill))
  214.       rect.width -= 24
  215.     end
  216.     rect.x += 24
  217.     text = "x #{$game_party.item_number(item)} / #{quantity}"
  218.     draw_text(rect, text, 2)
  219.   end
  220.    
  221. end # Window_BattleStatusAid
  222.  
  223. #==============================================================================
  224. # ■ Game_BattlerBase
  225. #==============================================================================
  226.  
  227. class Game_BattlerBase
  228.  
  229.   #--------------------------------------------------------------------------
  230.   # alias method: skill_cost_payable?
  231.   #--------------------------------------------------------------------------
  232.   def skill_cost_payable?(skill)
  233.     return false if hp <= skill_hp_cost(skill)
  234.     return false unless gold_cost_met?(skill)
  235.     return false unless custom_cost_met?(skill)
  236.     return false unless custom_item_cost_met?(skill)
  237.     return game_battlerbase_skill_cost_payable_scm(skill)
  238.   end
  239.  
  240.   #--------------------------------------------------------------------------
  241.   # new method: custom_cost_met?
  242.   #--------------------------------------------------------------------------
  243.   def custom_item_cost_met?(skill)
  244.     return true unless skill.use_custom_item_cost
  245.     total = skill.custom_cost_item_requirement.size
  246.     pass = true
  247.     total.times do |i|
  248.       next if skill.custom_cost_item_requirement[i].nil?
  249.       quantity = skill.custom_cost_item_requirement[i][0]
  250.       item_type = skill.custom_cost_item_requirement[i][1].downcase
  251.       item_num = skill.custom_cost_item_requirement[i][2]
  252.       item = nil
  253.       case item_type
  254.       when "i"
  255.         item = $data_items[item_num]
  256.       when "a"
  257.         item = $data_armors[item_num]
  258.       when "w"
  259.         item = $data_weapons[item_num]
  260.       end
  261.       num = $game_party.item_number(item)
  262.       pass = false if num < quantity
  263.     end
  264.     return pass
  265.   end
  266.  
  267.   #--------------------------------------------------------------------------
  268.   # alias method: pay_skill_cost
  269.   #--------------------------------------------------------------------------
  270.   alias r2_pay_skill_cost_custom_items   pay_skill_cost
  271.   def pay_skill_cost(skill)
  272.     r2_pay_skill_cost_custom_items(skill)
  273.     pay_custom_item_cost(skill)
  274.   end
  275.  
  276.   #--------------------------------------------------------------------------
  277.   # new method: pay_custom_item_cost
  278.   #--------------------------------------------------------------------------
  279.   def pay_custom_item_cost(skill)
  280.     return unless skill.use_custom_item_cost
  281.     total = skill.custom_cost_item_requirement.size
  282.     total.times do |i|
  283.       next if skill.custom_cost_item_requirement[i].nil?
  284.       quantity = skill.custom_cost_item_requirement[i][0]
  285.       item_type = skill.custom_cost_item_requirement[i][1].downcase
  286.       item_num = skill.custom_cost_item_requirement[i][2]
  287.       consume = skill.custom_cost_item_requirement[i][3].downcase
  288.       item = nil
  289.       case item_type
  290.       when "i"
  291.         item = $data_items[item_num]
  292.       when "a"
  293.         item = $data_armors[item_num]
  294.       when "w"
  295.         item = $data_weapons[item_num]
  296.       end
  297.       $game_party.lose_item(item, quantity) if consume == "c"
  298.     end
  299.   end
  300.  
  301. end
  302.  
  303. class Scene_Battle < Scene_Base
  304.  
  305.   #--------------------------------------------------------------------------
  306.   # * Create All Windows
  307.   #--------------------------------------------------------------------------
  308.   alias r2_create_skill_custom_cost_window  create_all_windows
  309.   def create_all_windows
  310.     r2_create_skill_custom_cost_window
  311.     create_battle_skill_aid_window
  312.   end
  313.  
  314.   #--------------------------------------------------------------------------
  315.   # new method: create_battle_status_aid_window
  316.   #--------------------------------------------------------------------------
  317.   def create_battle_skill_aid_window
  318.     @skill_aid_window = Window_BattleSkillAid.new(640,640,128,128)
  319.     @skill_aid_window.skill_window = @skill_window
  320.     @skill_aid_window.x = Graphics.width - @skill_aid_window.width
  321.     @skill_aid_window.y = Graphics.height - @skill_aid_window.height * 2 + 8
  322.   end
  323.  
  324.   #--------------------------------------------------------------------------
  325.   # new method: draw_custom_skill_cost
  326.   #--------------------------------------------------------------------------
  327.   def draw_custom_skill_cost
  328.     skill = @skill_window.item
  329.     return if skill.nil?
  330.     return unless skill.use_custom_item_cost
  331.     @skill_aid_window.open_skill
  332.   end
  333.  
  334.   #--------------------------------------------------------------------------
  335.   # * [Skill] Command
  336.   #--------------------------------------------------------------------------
  337.   alias r2_skill_ok_custom_cost   command_skill
  338.   def command_skill
  339.     r2_skill_ok_custom_cost
  340.     draw_custom_skill_cost
  341.   end
  342.  
  343.   #--------------------------------------------------------------------------
  344.   # * Skill [OK]
  345.   #--------------------------------------------------------------------------
  346.   alias r2_skill_ok_custom_cost_hide  on_skill_ok
  347.   def on_skill_ok
  348.     r2_skill_ok_custom_cost_hide
  349.     if @skill.for_opponent?
  350.     elsif @skill.for_friend?
  351.     else
  352.       @skill_aid_window.close_skill
  353.     end
  354.   end
  355.  
  356.   #--------------------------------------------------------------------------
  357.   # * Skill [Cancel]
  358.   #--------------------------------------------------------------------------
  359.   alias r2_on_skill_cancel_custom_cost    on_skill_cancel
  360.   def on_skill_cancel
  361.     @skill_aid_window.close_skill
  362.     r2_on_skill_cancel_custom_cost
  363.   end
  364.  
  365.   #--------------------------------------------------------------------------
  366.   # * Actor [OK]
  367.   #--------------------------------------------------------------------------
  368.   alias r2_on_actor_ok_custom_item_cost   on_actor_ok
  369.   def on_actor_ok
  370.     @skill_aid_window.close_skill
  371.     r2_on_actor_ok_custom_item_cost
  372.   end
  373.  
  374.   #--------------------------------------------------------------------------
  375.   # * Enemy [OK]
  376.   #--------------------------------------------------------------------------
  377.   alias r2_on_enemy_ok_custom_item_cost   on_enemy_ok
  378.   def on_enemy_ok
  379.     @skill_aid_window.close_skill
  380.     @skill_aid_window.hide
  381.     r2_on_enemy_ok_custom_item_cost
  382.   end
  383. end
  384.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement