Advertisement
roninator2

Yanfly Target Manager Mod - all but user

Dec 4th, 2024
27
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Ruby 18.18 KB | None | 0 0
  1. #==============================================================================
  2. #
  3. # ▼ Yanfly Engine Ace - Target Manager v1.04
  4. # -- Last Updated: 2012.01.13
  5. # -- Level: Normal, Hard
  6. # -- Requires: n/a
  7. # -- Addon by Roninator2
  8. #==============================================================================
  9.  
  10. $imported = {} if $imported.nil?
  11. $imported["YEA-TargetManager"] = true
  12.  
  13. #==============================================================================
  14. # ▼ Updates
  15. # =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
  16. # 2021.05.30 - Added option to use skill on random allies except user
  17. # 2012.01.13 - Bug Fixed: AoE removing targets.
  18. # 2012.01.04 - Compatibility Update: Area of Effect
  19. # 2012.01.02 - Started Script and Finished.
  20. #            - Compatibility Update: Lunatic Targets
  21. #
  22. #==============================================================================
  23. # ▼ Introduction
  24. # =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
  25. # This script provides the ability to expand the targeting scope for skills and
  26. # items. This script provides the ability to up the number of maximum hits
  27. # past 9, expand the targeting range to target different types of groups, and
  28. # give more control over random targeting.
  29. #
  30. #==============================================================================
  31. # ▼ Instructions
  32. # =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
  33. # To install this script, open up your script editor and copy/paste this script
  34. # to an open slot below ▼ Materials/素材 but above ▼ Main. Remember to save.
  35. #
  36. # -----------------------------------------------------------------------------
  37. # Skill Notetags - These notetags go in the skills notebox in the database.
  38. # -----------------------------------------------------------------------------
  39. # <total hits: x>
  40. # Sets the total hits performed to x. This value can exceed 9, the limit RPG
  41. # Maker VX Ace imposes.
  42. #
  43. # <targets: everybody>
  44. # Sets the targeting scope to hit all alive actors and all alive enemies.
  45. #
  46. # <targets: target all foes>
  47. # Sets the targeting scope to hit the selected target foe first and then the
  48. # remaining foes.
  49. #
  50. # <targets: target x random foes>
  51. # Sets the targeting scope to hit the selected target foe first and then hit
  52. # x random foes.
  53. #
  54. # <targets: x random foes>
  55. # Sets the targeting scope to random. This will hit x random foes.
  56. #
  57. # <targets: all but user>
  58. # Targets all allies except for the user.
  59. #
  60. # <targets: target all allies>
  61. # Sets the targeting scope to hit the selected target ally first and then the
  62. # remaining allies.
  63. #
  64. # <targets: target x random allies>
  65. # Sets the targeting scope to hit the selected target ally first and then hit
  66. # x random allies.
  67. #
  68. # <targets: x random allies>
  69. # Sets the targeting scope to random. This will hit x random allies.
  70. #
  71. # -----------------------------------------------------------------------------
  72. # Item Notetags - These notetags go in the items notebox in the database.
  73. # -----------------------------------------------------------------------------
  74. # <total hits: x>
  75. # Sets the total hits performed to x. This value can exceed 9, the limit RPG
  76. # Maker VX Ace imposes.
  77. #
  78. # <targets: everybody>
  79. # Sets the targeting scope to hit all alive actors and all alive enemies.
  80. #
  81. # <targets: target all foes>
  82. # Sets the targeting scope to hit the selected target foe first and then the
  83. # remaining foes.
  84. #
  85. # <targets: target x random foes>
  86. # Sets the targeting scope to hit the selected target foe first and then hit
  87. # x random foes.
  88. #
  89. # <targets: x random foes>
  90. # Sets the targeting scope to random. This will hit x random foes.
  91. #
  92. # <targets: all but user>
  93. # Targets all allies except for the user.
  94. #
  95. # <targets: target all allies>
  96. # Sets the targeting scope to hit the selected target ally first and then the
  97. # remaining allies.
  98. #
  99. # <targets: target x random allies>
  100. # Sets the targeting scope to hit the selected target ally first and then hit
  101. # x random allies.
  102. #
  103. # <targets: x random allies>
  104. # Sets the targeting scope to random. This will hit x random allies.
  105.  
  106. # <targets: x other allies>
  107. # Sets the targeting scope to random. This will hit x random allies, but not the user
  108. #
  109. #==============================================================================
  110. # ▼ Compatibility
  111. # =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
  112. # This script is made strictly for RPG Maker VX Ace. It is highly unlikely that
  113. # it will run with RPG Maker VX without adjusting.
  114. #
  115. # This script is compatible with Yanfly Engine Ace - Ace Battle Engine v1.12+.
  116. # Place this script under Ace Battle Engine in the script listing. Also, for
  117. # maximum compatibility with Yanfly Engine Ace - Lunatic Targets, place this
  118. # script under Yanfly Engine Ace - Lunatic Targets as well.
  119. #
  120. #==============================================================================
  121.  
  122. module YEA
  123.   module TARGET
  124.    
  125.     #=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
  126.     # - General Targeting Settings -
  127.     #=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
  128.     # These settings adjust how targeting operates in your game. Here, you can
  129.     # choose to have random targeting redirect to a different target if the
  130.     # selected target is dead, change the default settings used for area of
  131.     # effects, and more.
  132.     #=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
  133.     # This setting, if true, will redirect the target of a random attack to an
  134.     # alive target if the current target is dead. If there are no alive targets
  135.     # then nothing happens.
  136.     RANDOM_REDIRECT = true
  137.    
  138.   end # TARGET
  139. end # YEA
  140.  
  141. #==============================================================================
  142. # ▼ Editting anything past this point may potentially result in causing
  143. # computer damage, incontinence, explosion of user's head, coma, death, and/or
  144. # halitosis so edit at your own risk.
  145. #==============================================================================
  146.  
  147. module YEA
  148.   module REGEXP
  149.   module USABLEITEM
  150.    
  151.     TOTAL_HITS = /<(?:TOTAL_HITS|total hits):[ ](\d+)>/i
  152.     TARGETS = /<(?:TARGETS|target):[ ](.*)>/i
  153.    
  154.   end # USABLEITEM
  155.   end # REGEXP
  156. end # YEA
  157.  
  158.  
  159. #==============================================================================
  160. # ■ DataManager
  161. #==============================================================================
  162.  
  163. module DataManager
  164.  
  165.   #--------------------------------------------------------------------------
  166.   # alias method: load_database
  167.   #--------------------------------------------------------------------------
  168.   class <<self; alias load_database_target load_database; end
  169.   def self.load_database
  170.     load_database_target
  171.     load_notetags_target
  172.   end
  173.  
  174.   #--------------------------------------------------------------------------
  175.   # new method: load_notetags_target
  176.   #--------------------------------------------------------------------------
  177.   def self.load_notetags_target
  178.     groups = [$data_skills, $data_items]
  179.     for group in groups
  180.       for obj in group
  181.         next if obj.nil?
  182.         obj.load_notetags_target
  183.       end
  184.     end
  185.   end
  186.  
  187. end # DataManager
  188.  
  189. #==============================================================================
  190. # ■ RPG::UsableItem
  191. #==============================================================================
  192.  
  193. class RPG::UsableItem < RPG::BaseItem
  194.  
  195.   #--------------------------------------------------------------------------
  196.   # common cache: load_notetags_target
  197.   #--------------------------------------------------------------------------
  198.   def load_notetags_target
  199.     @random_hits = [3, 4, 5, 6].include?(@scope) ? @scope - 2 : 0
  200.     #---
  201.     self.note.split(/[\r\n]+/).each { |line|
  202.       case line
  203.       #---
  204.       when YEA::REGEXP::USABLEITEM::TOTAL_HITS
  205.         @repeats = [$1.to_i, 1].max
  206.       #---
  207.       when YEA::REGEXP::USABLEITEM::TARGETS
  208.         @random_hits = 0
  209.         case $1
  210.         when /EVERYBODY/i
  211.           @scope = :everybody
  212.         when /TARGET ALL FOES/i
  213.           @scope = :target_all_foes
  214.         when /TARGET[ ](\d+)[ ]RANDOM FOE/i
  215.           @scope = :target_random_foes
  216.           @random_hits = $1.to_i
  217.         when /(\d+)[ ]RANDOM FOE/i
  218.           @scope = 3
  219.           @random_hits = $1.to_i
  220.         when /ALL BUT USER/i
  221.           @scope = :all_but_user
  222.         when /TARGET ALL ALLIES/i
  223.           @scope = :target_all_allies
  224.         when /TARGET[ ](\d+)[ ]RANDOM ALL/i
  225.           @scope = :target_random_allies
  226.           @random_hits = $1.to_i
  227.         when /(\d+)[ ]RANDOM ALLIES/i
  228.           @scope = :random_allies
  229.           @random_hits = $1.to_i
  230.         when /(\d+)[ ]OTHER ALLIES/i
  231.           @scope = :other_allies
  232.           @random_hits = $1.to_i
  233.         end
  234.       #---
  235.       end
  236.     } # self.note.split
  237.     #---
  238.   end
  239.  
  240.   #--------------------------------------------------------------------------
  241.   # overwrite method: for_random?
  242.   #--------------------------------------------------------------------------
  243.   def for_random?; return @random_hits > 0; end
  244.  
  245.   #--------------------------------------------------------------------------
  246.   # overwrite method: number_of_targets
  247.   #--------------------------------------------------------------------------
  248.   def number_of_targets; return @random_hits; end
  249.  
  250.   #--------------------------------------------------------------------------
  251.   # alias method: for_opponent?
  252.   #--------------------------------------------------------------------------
  253.   alias rpg_usableitem_for_opponent_target for_opponent?
  254.   def for_opponent?
  255.     return true if @scope == :target_all_foes
  256.     return true if @scope == :target_random_foes
  257.     return rpg_usableitem_for_opponent_target
  258.   end
  259.  
  260.   #--------------------------------------------------------------------------
  261.   # alias method: for_friend?
  262.   #--------------------------------------------------------------------------
  263.   alias rpg_usableitem_for_friend_target for_friend?
  264.   def for_friend?
  265.     return true if @scope == :all_but_user
  266.     return true if @scope == :target_all_allies
  267.     return true if @scope == :target_random_allies
  268.     return true if @scope == :random_allies
  269.     return true if @scope == :other_allies
  270.     return rpg_usableitem_for_friend_target
  271.   end
  272.  
  273.   #--------------------------------------------------------------------------
  274.   # alias method: for_all?
  275.   #--------------------------------------------------------------------------
  276.   alias rpg_usableitem_for_all_target for_all?
  277.   def for_all?
  278.     return true if @scope == :all_but_user
  279.     return rpg_usableitem_for_all_target
  280.   end
  281.  
  282.   #--------------------------------------------------------------------------
  283.   # alias method: need_selection?
  284.   #--------------------------------------------------------------------------
  285.   alias rpg_usableitem_need_selection_target need_selection?
  286.   def need_selection?
  287.     return true if @scope == :target_all_foes
  288.     return true if @scope == :target_random_foes
  289.     return true if @scope == :target_all_allies
  290.     return true if @scope == :target_random_allies
  291.     return true if @scope == :target_other_allies
  292.     return rpg_usableitem_need_selection_target
  293.   end
  294.  
  295.   #--------------------------------------------------------------------------
  296.   # new method: for_custom?
  297.   #--------------------------------------------------------------------------
  298.   def for_custom?
  299.     return !@scope.is_a?(Integer)
  300.   end
  301.  
  302.   #--------------------------------------------------------------------------
  303.   # new method: for_everybody?
  304.   #--------------------------------------------------------------------------
  305.   def for_everybody?
  306.     return @scope == :everybody
  307.   end
  308.  
  309.   #--------------------------------------------------------------------------
  310.   # new method: for_target_all_foes?
  311.   #--------------------------------------------------------------------------
  312.   def for_target_all_foes?
  313.     return @scope == :target_all_foes
  314.   end
  315.  
  316.   #--------------------------------------------------------------------------
  317.   # new method: for_target_random_foes?
  318.   #--------------------------------------------------------------------------
  319.   def for_target_random_foes?
  320.     return @scope == :target_random_foes
  321.   end
  322.  
  323.   #--------------------------------------------------------------------------
  324.   # new method: for_all_but_user?
  325.   #--------------------------------------------------------------------------
  326.   def for_all_but_user?
  327.     return @scope == :all_but_user
  328.   end
  329.  
  330.   #--------------------------------------------------------------------------
  331.   # new method: for_target_all_allies?
  332.   #--------------------------------------------------------------------------
  333.   def for_target_all_allies?
  334.     return @scope == :target_all_allies
  335.   end
  336.  
  337.   #--------------------------------------------------------------------------
  338.   # new method: for_target_random_allies?
  339.   #--------------------------------------------------------------------------
  340.   def for_target_random_allies?
  341.     return @scope == :target_random_allies
  342.   end
  343.  
  344.   #--------------------------------------------------------------------------
  345.   # new method: for_random_allies?
  346.   #--------------------------------------------------------------------------
  347.   def for_random_allies?
  348.     return @scope == :random_allies
  349.   end
  350.  
  351.   #--------------------------------------------------------------------------
  352.   # new method: for_other_allies?
  353.   #--------------------------------------------------------------------------
  354.   def for_other_allies?
  355.     return @scope == :other_allies
  356.   end
  357.  
  358. end # class RPG::UsableItem
  359.  
  360. #==============================================================================
  361. # ■ Game_Action
  362. #==============================================================================
  363.  
  364. class Game_Action
  365.  
  366.   #--------------------------------------------------------------------------
  367.   # alias method: make_targets
  368.   #--------------------------------------------------------------------------
  369.   unless $imported["YEA-LunaticTargets"]
  370.   alias game_action_make_targets_target make_targets
  371.   def make_targets
  372.     if !forcing && subject.confusion?
  373.       targets = [confusion_target]
  374.     elsif item.for_custom?
  375.       targets = make_custom_targets
  376.     else
  377.       targets = game_action_make_targets_target
  378.     end
  379.     targets = aoe_targets(targets) if $imported["YEA-AreaofEffect"]
  380.     return targets
  381.   end
  382.   end # $imported["YEA-LunaticTargets"]
  383.  
  384.   #--------------------------------------------------------------------------
  385.   # compatibility method: default_target_set
  386.   #--------------------------------------------------------------------------
  387.   if $imported["YEA-LunaticTargets"]
  388.   def default_target_set
  389.     if !forcing && subject.confusion?
  390.       targets = [confusion_target]
  391.     elsif item.for_custom?
  392.       targets = make_custom_targets
  393.     else
  394.       targets = game_action_make_targets_ltar
  395.     end
  396.     targets = aoe_targets(targets) if $imported["YEA-AreaofEffect"]
  397.     return targets
  398.   end
  399.   end # $imported["YEA-LunaticTargets"]
  400.  
  401.   #--------------------------------------------------------------------------
  402.   # new method: make_custom_targets
  403.   #--------------------------------------------------------------------------
  404.   def make_custom_targets
  405.     array = []
  406.     if item.for_everybody?
  407.       array |= opponents_unit.alive_members
  408.       array |= friends_unit.alive_members
  409.     elsif item.for_target_all_foes?
  410.       array |= [opponents_unit.smooth_target(@target_index)]
  411.       array |= opponents_unit.alive_members
  412.     elsif item.for_target_random_foes?
  413.       array |= [opponents_unit.smooth_target(@target_index)]
  414.       array += Array.new(item.number_of_targets) { opponents_unit.random_target }
  415.     elsif item.for_all_but_user?
  416.       array |= friends_unit.alive_members
  417.       array -= [subject]
  418.     elsif item.for_target_all_allies?
  419.       array |= [friends_unit.smooth_target(@target_index)]
  420.       array |= friends_unit.alive_members
  421.     elsif item.for_target_random_allies?
  422.       array |= [friends_unit.smooth_target(@target_index)]
  423.       array += Array.new(item.number_of_targets) { friends_unit.random_target }
  424.     elsif item.for_random_allies?
  425.       array += Array.new(item.number_of_targets) { friends_unit.random_target }
  426.     elsif item.for_other_allies?
  427.       loop do
  428.         array += Array.new(item.number_of_targets) { friends_unit.random_target }
  429.         array -= [subject]
  430.         if !array.empty?
  431.           break
  432.         end
  433.       end
  434.     end
  435.     return array
  436.   end
  437.  
  438. end # Game_Action
  439.  
  440. #==============================================================================
  441. # ■ Scene_Battle
  442. #==============================================================================
  443.  
  444. class Scene_Battle < Scene_Base
  445.  
  446.   #--------------------------------------------------------------------------
  447.   # alias method: invoke_item
  448.   #--------------------------------------------------------------------------
  449.   unless $imported["YEA-BattleEngine"]
  450.   alias scene_battle_invoke_item_target invoke_item
  451.   def invoke_item(target, item)
  452.     target = alive_random_target(target, item) if item.for_random?
  453.     scene_battle_invoke_item_target(target, item)
  454.   end
  455.   end # $imported["YEA-BattleEngine"]
  456.  
  457.   #--------------------------------------------------------------------------
  458.   # new method: alive_random_target
  459.   #--------------------------------------------------------------------------
  460.   def alive_random_target(target, item)
  461.     return target if target.alive?
  462.     return target if target.dead? == item.for_dead_friend?
  463.     return target unless YEA::TARGET::RANDOM_REDIRECT
  464.     if item.for_dead_friend? && target.friends_unit.dead_members.empty?
  465.       return target
  466.     elsif item.for_dead_friend?
  467.       return target.friends_unit.random_dead_target
  468.     elsif target.friends_unit.all_dead?
  469.       return target
  470.     else
  471.       return target.friends_unit.random_target
  472.     end
  473.   end
  474.  
  475. end # Scene_Battle
  476.  
  477. #==============================================================================
  478. #
  479. # ▼ End of File
  480. #
  481. #==============================================================================
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement