设为首页收藏本站同能贴吧 切换语言 繁体中文
开启辅助访问 切换到窄版
扫描二维码关注官方公众号
返回列表
+ 发新帖
查看: 91|回复: 0

[转载发布] Advanced Scopes - More target options for battlers

[复制链接]
累计送礼:
0 个
累计收礼:
1 个
  • TA的每日心情
    开心
    前天 04:10
  • 签到天数: 209 天

    连续签到: 2 天

    [LV.7]常住居民III

    4469

    主题

    864

    回帖

    2万

    积分

    管理员

    Rank: 9Rank: 9Rank: 9

    VIP
    7
    卡币
    22945
    OK点
    16
    推广点
    0
    同能卷
    50
    积分
    28308

    灌水之王

    发表于 3 天前 | 显示全部楼层 |阅读模式
    Introduction

    This script defines new scope types for items and skills in battle.
    More specifically, it separates the scope into distinct properties you can define independently.

    Those properties are:
    - Affects allies
    - Affects enemies
    - Affects the entire group or only one
    - Selects one randomly (new)
    - Includes the user
    - Only affects battlers that are alive
    - Only affects battlers that are dead

    You can also define completely custom restrictions by block, for example skills that can't target ghost enemies, or items that can only target allies that have a state, or more than 50% HP, etc.

    Author: Wecoc
    First Release: January 2017
    Last Version: November 2018

    Terms of use
    - Giving credits (Wecoc) is optional, but appreciated.
    - You can repost this code.
    - You can edit this code freely, and distribute the edits as well.
    - This code can be used on commercial games.

    Demo
    You can download a basic demo here: Advanced Scope.zip

    Code
    There are two versions, a normal one and a version compatible with Data File Save.

    Normal version (independent)
    Spoiler: Code
                    Ruby:        
    1. #==============================================================================
    2. # ** [XP] Advanced Scope v1.1
    3. #------------------------------------------------------------------------------
    4. # Author: Wecoc (credits are optional)
    5. #------------------------------------------------------------------------------
    6. # Defines new types of scope for items and skills in battle
    7. #------------------------------------------------------------------------------
    8. # $data_items[ID] and $data_skills[ID] work exactly the same way
    9. # To define the target use:
    10. # $data_items[ID].scope_ally   = true | false # Ally
    11. # $data_items[ID].scope_enemy  = true | false # Enemy
    12. # $data_items[ID].scope_all    = true | false # Entire group / Only one
    13. # $data_items[ID].scope_random = true | false # Pick one randomly
    14. # $data_items[ID].scope_user   = true | false # Include user
    15. # $data_items[ID].scope_alive  = true | false # Only alive members
    16. # $data_items[ID].scope_dead   = true | false # Only dead members
    17. #------------------------------------------------------------------------------
    18. # $data_items[ID].restriction(&block) # Set custom restriction
    19. # $data_items[ID].restrictions        # Get all custom restrictions
    20. # $data_items[ID].clear_restrictions  # Clear all custom restrictions
    21. #==============================================================================
    22. #==============================================================================
    23. # ** Scope Configuration
    24. #==============================================================================
    25. module Scope
    26.   #----------------------------------------------------------------------------
    27.   # Default Dead Select
    28.   #----------------------------------------------------------------------------
    29.   # By default if an item only affects members that are alive you can still
    30.   # select a dead member, but the item won't have any effect.
    31.   # The same happens with items that only affect dead members.
    32.   # Set to false if you want to disable that and apply a strict restriction.
    33.   #----------------------------------------------------------------------------
    34.   DEFAULT_DEAD_SELECT = true
    35. end
    36. #==============================================================================
    37. # ** Array
    38. #==============================================================================
    39. class Array
    40.   #--------------------------------------------------------------------------
    41.   # * Select!
    42.   #--------------------------------------------------------------------------
    43.   unless self.respond_to?(:select!)
    44.     def select!(&block)
    45.       result = self.select(&block)
    46.       self.replace(result)
    47.     end
    48.   end
    49. end
    50. #==============================================================================
    51. # ** RPG
    52. #==============================================================================
    53. for Klass in [RPG::Item, RPG::Skill]
    54.   class Klass
    55.     #--------------------------------------------------------------------------
    56.     # * Public Instance Variables
    57.     #--------------------------------------------------------------------------
    58.     attr_writer :scope_ally, :scope_enemy, :scope_all, :scope_random
    59.     attr_writer :scope_user, :scope_alive, :scope_dead
    60.     #--------------------------------------------------------------------------
    61.     # * For Allies
    62.     #--------------------------------------------------------------------------
    63.     def scope_ally
    64.       @scope_ally = [3, 4, 5, 6].include?(@scope) if @scope_ally == nil
    65.       return @scope_ally
    66.     end
    67.     #--------------------------------------------------------------------------
    68.     # * For Enemies
    69.     #--------------------------------------------------------------------------
    70.     def scope_enemy
    71.       @scope_enemy = [1, 2].include?(@scope) if @scope_enemy == nil
    72.       return @scope_enemy
    73.     end
    74.     #--------------------------------------------------------------------------
    75.     # * For All Party/Troop Members
    76.     #--------------------------------------------------------------------------
    77.     def scope_all
    78.       @scope_all = [2, 4, 6].include?(@scope) if @scope_all == nil
    79.       return @scope_all
    80.     end
    81.     #--------------------------------------------------------------------------
    82.     # * Random Pick
    83.     #--------------------------------------------------------------------------
    84.     def scope_random
    85.       @scope_random = false if @scope_random == nil
    86.       return @scope_random
    87.     end
    88.     #--------------------------------------------------------------------------
    89.     # * User included
    90.     #--------------------------------------------------------------------------
    91.     def scope_user
    92.       if Scope::DEFAULT_DEAD_SELECT == true
    93.         @scope_user = [3, 4, 5, 6, 7].include?(@scope) if @scope_user == nil
    94.       else
    95.         @scope_user = [3, 4, 7].include?(@scope) if @scope_user == nil
    96.       end
    97.       return @scope_user
    98.     end
    99.     #--------------------------------------------------------------------------
    100.     # * Only Alive
    101.     #--------------------------------------------------------------------------
    102.     def scope_alive
    103.       @scope_alive = [1, 2, 3, 4, 7].include?(@scope) if @scope_alive == nil
    104.       return @scope_alive
    105.     end
    106.     #--------------------------------------------------------------------------
    107.     # * Only Dead
    108.     #--------------------------------------------------------------------------
    109.     def scope_dead
    110.       @scope_dead = [5, 6].include?(@scope) if @scope_dead == nil
    111.       return @scope_dead
    112.     end
    113.     #--------------------------------------------------------------------------
    114.     # * Define Scope
    115.     #--------------------------------------------------------------------------
    116.     def set_scope(ally,enemy,all,random=false,user=true,alive=true,dead=false)
    117.       self.scope_ally   = ally
    118.       self.scope_enemy  = enemy
    119.       self.scope_all    = all
    120.       self.scope_random = random
    121.       self.scope_user   = user
    122.       self.scope_alive  = alive
    123.       self.scope_dead   = dead
    124.     end
    125.     #--------------------------------------------------------------------------
    126.     # * Special Restrictions
    127.     #--------------------------------------------------------------------------
    128.     def scope_rest
    129.       @scope_rest = [] if @scope_rest == nil
    130.       return @scope_rest
    131.     end
    132.     def restriction(&block)  self.scope_rest.push(block)  end
    133.     def restrictions()       self.scope_rest              end
    134.     def clear_restrictions() self.scope_rest.clear        end
    135.     #--------------------------------------------------------------------------
    136.   end
    137. end
    138. #==============================================================================
    139. # ** Arrow_Base
    140. #==============================================================================
    141. class Arrow_Base < Sprite
    142.   attr_reader :user
    143.   attr_reader :item
    144.   attr_reader :target
    145.   attr_reader :targets
    146.   #--------------------------------------------------------------------------
    147.   # * Initialize
    148.   #--------------------------------------------------------------------------
    149.   def initialize(viewport, user, item)
    150.     super(viewport)
    151.     self.bitmap = RPG::Cache.windowskin($game_system.windowskin_name)
    152.     self.ox = 16
    153.     self.oy = 64
    154.     self.z = 2500
    155.     @blink_count = 0
    156.     @index = 0
    157.     @help_window = nil
    158.     @user = user
    159.     @item = item
    160.     @targets = target_battlers
    161.     @target = @targets[0]
    162.     update_sprite
    163.   end
    164.   #--------------------------------------------------------------------------
    165.   # * Get index
    166.   #--------------------------------------------------------------------------
    167.   def index
    168.     return @targets.index(@target) rescue -1
    169.   end
    170.   #--------------------------------------------------------------------------
    171.   # * Set index
    172.   #--------------------------------------------------------------------------
    173.   def index=(index)
    174.     @target = @targets[index]
    175.   end
    176.   #--------------------------------------------------------------------------
    177.   # * Get selectable targets
    178.   #--------------------------------------------------------------------------
    179.   def target_battlers
    180.     if @user.is_a?(Game_Actor)
    181.       allies = $game_party.actors.clone
    182.       enemies = $game_troop.enemies.clone
    183.     else
    184.       allies = $game_troop.enemies.clone
    185.       enemies = $game_party.actors.clone
    186.     end
    187.     allies.delete_if {|target| target.hidden}
    188.     enemies.delete_if{|target| target.hidden}
    189.     if @item == nil
    190.       enemies.delete_if {|target| !target.exist? }
    191.       return enemies
    192.     end
    193.     result = []
    194.     if @item.scope_ally == true
    195.       for target in allies
    196.         result.push(target)
    197.       end
    198.     end
    199.     if @item.scope_enemy == true
    200.       for target in enemies
    201.         result.push(target)
    202.       end
    203.     end
    204.     if @item.scope_user == true
    205.       if !result.include?(@user)
    206.         result.push(@user)
    207.       end
    208.     end
    209.     if @item.scope_user == false
    210.       result.delete(@user)
    211.     end
    212.     if @item.scope_alive == true && Scope::DEFAULT_DEAD_SELECT == false
    213.       result.select!{|target| !target.dead?}
    214.     end
    215.     if @item.scope_dead == true && Scope::DEFAULT_DEAD_SELECT == false
    216.       result.select!{|target| target.dead?}
    217.     end
    218.     for r in @item.restrictions
    219.       if r.arity == 1
    220.         result.select!{|target| r.call(target) == true} rescue nil
    221.       else
    222.         result.select!{|target| r.call == true} rescue nil
    223.       end
    224.     end
    225.     return result
    226.   end
    227.   #--------------------------------------------------------------------------
    228.   # * Update
    229.   #--------------------------------------------------------------------------
    230.   def update
    231.     update_sprite
    232.     if @help_window != nil
    233.       update_help
    234.     end
    235.     if @target == nil
    236.       self.visible = false
    237.       return
    238.     end
    239.     self.visible = true
    240.     # Next target
    241.     if Input.repeat?(Input::RIGHT)
    242.       $game_system.se_play($data_system.cursor_se)
    243.       self.index = (self.index + 1) % @targets.size
    244.     end
    245.     # Previous target
    246.     if Input.repeat?(Input::LEFT)
    247.       $game_system.se_play($data_system.cursor_se)
    248.       self.index = (self.index - 1) % @targets.size
    249.     end
    250.     # Place arrow over target
    251.     if @target != nil
    252.       self.x = @target.screen_x
    253.       self.y = @target.screen_y
    254.     end
    255.   end
    256.   #--------------------------------------------------------------------------
    257.   # * Update Sprite
    258.   #--------------------------------------------------------------------------
    259.   def update_sprite
    260.     @blink_count = (@blink_count + 1) % 8
    261.     if @blink_count < 4
    262.       self.src_rect.set(128, 96, 32, 32)
    263.     else
    264.       self.src_rect.set(160, 96, 32, 32)
    265.     end
    266.   end
    267.   #--------------------------------------------------------------------------
    268.   # * Update Help
    269.   #--------------------------------------------------------------------------
    270.   def update_help
    271.     if @target == nil
    272.       @help_window.set_text("")
    273.       return
    274.     end
    275.     if @target.is_a?(Game_Actor)
    276.       @help_window.set_actor(@target)
    277.     else
    278.       @help_window.set_enemy(@target)
    279.     end
    280.   end
    281. end
    282. #==============================================================================
    283. # ** Game_Battler
    284. #==============================================================================
    285. class Game_Battler
    286.   #--------------------------------------------------------------------------
    287.   # * Check if the skill can be used
    288.   #--------------------------------------------------------------------------
    289.   alias wecoc_scope_skill_use? skill_can_use? unless $@
    290.   def skill_can_use?(skill_id)
    291.     skill = $data_skills[skill_id]
    292.     return false if skill.nil?   # Skill doesn't exist
    293.     return false if !self.exist? # User is hidden or dead
    294.     if self.is_a?(Game_Actor)
    295.       members = $game_party.actors.clone
    296.     else
    297.       members = $game_troop.enemies.clone
    298.     end
    299.     if members.size == 1 # User is the only member and requires an ally
    300.       if skill.user == false && skill.ally == false && skill.enemy == false
    301.         return false
    302.       end
    303.     end
    304.     for r in skill.restrictions
    305.       if r.arity == 1
    306.         members.select!{|target| r.call(target) == true} rescue nil
    307.       else
    308.         members.select!{|target| r.call == true} rescue nil
    309.       end
    310.     end
    311.     return false if members.size == 0
    312.     return wecoc_scope_skill_use?(skill_id)
    313.   end
    314.   #--------------------------------------------------------------------------
    315.   # * Check if the item can be used
    316.   #--------------------------------------------------------------------------
    317.   def item_can_use?(item_id)
    318.     item = $data_items[item_id]
    319.     return false if item.nil?    # Item doesn't exist
    320.     return false if !self.exist? # User is hidden or dead
    321.     if self.is_a?(Game_Actor)
    322.       # Party doesn't contain that item
    323.       return false if $game_party.item_number(item_id) == 0
    324.       # Item restrictions (Only menu / battle)
    325.       return false if $game_temp.in_battle  && item.occasion == 2
    326.       return false if !$game_temp.in_battle && item.occasion == 1
    327.       members = $game_party.actors.clone
    328.     else
    329.       members = $game_troop.enemies.clone
    330.     end
    331.     if members.size == 1 # User is the only member and requires an ally
    332.       if item.user == false && item.ally == false && item.enemy == false
    333.         return false
    334.       end
    335.     end
    336.     for r in item.restrictions
    337.       if r.arity == 1
    338.         members.select!{|target| r.call(target) == true} rescue nil
    339.       else
    340.         members.select!{|target| r.call == true} rescue nil
    341.       end
    342.     end
    343.     return false if members.size == 0
    344.     return true
    345.   end
    346. end
    347. #==============================================================================
    348. # ** Game_Party
    349. #==============================================================================
    350. class Game_Party
    351.   #--------------------------------------------------------------------------
    352.   # * Check if the party can use an item
    353.   #--------------------------------------------------------------------------
    354.   def item_can_use?(item_id)
    355.     for member in $game_party.actors
    356.       if member.item_can_use?(item_id)
    357.         return true
    358.       end
    359.     end
    360.     return false
    361.   end
    362. end
    363. #==============================================================================
    364. # ** Scene_Battle
    365. #==============================================================================
    366. class Scene_Battle
    367.   #--------------------------------------------------------------------------
    368.   # * Select enemy
    369.   #--------------------------------------------------------------------------
    370.   def start_enemy_select
    371.     item = nil
    372.     if @active_battler.current_action.kind == 1
    373.       item = @skill if @skill != nil
    374.     end
    375.     if @active_battler.current_action.kind == 2
    376.       item = @item  if @item != nil
    377.     end
    378.     @enemy_arrow = Arrow_Base.new(@spriteset.viewport2, @active_battler, item)
    379.     @enemy_arrow.help_window = @help_window
    380.     @actor_command_window.active = false
    381.     @actor_command_window.visible = false
    382.   end
    383.   #--------------------------------------------------------------------------
    384.   # * Select actor
    385.   #--------------------------------------------------------------------------
    386.   def start_actor_select
    387.     item = nil
    388.     if @active_battler.current_action.kind == 1
    389.       item = @skill if @skill != nil
    390.     end
    391.     if @active_battler.current_action.kind == 2
    392.       item = @item  if @item != nil
    393.     end
    394.     @actor_arrow = Arrow_Base.new(@spriteset.viewport2, @active_battler, item)
    395.     @actor_arrow.index = @actor_index
    396.     @actor_arrow.help_window = @help_window
    397.     @actor_command_window.active = false
    398.     @actor_command_window.visible = false
    399.   end
    400.   #--------------------------------------------------------------------------
    401.   # * Apply skill
    402.   #--------------------------------------------------------------------------
    403.   def make_skill_action_result
    404.     @skill = $data_skills[@active_battler.current_action.skill_id]
    405.     unless @active_battler.current_action.forcing
    406.       unless @active_battler.skill_can_use?(@skill.id)
    407.         $game_temp.forcing_battler = nil
    408.         @phase4_step = 1
    409.         return
    410.       end
    411.     end
    412.     @active_battler.sp -= @skill.sp_cost
    413.     @status_window.refresh
    414.     @help_window.set_text(@skill.name, 1)
    415.     @animation1_id = @skill.animation1_id
    416.     @animation2_id = @skill.animation2_id
    417.     @common_event_id = @skill.common_event_id
    418.     @target_battlers.clear
    419.     @target_battlers = set_target_battlers(@skill)
    420.     for target in @target_battlers
    421.       target.skill_effect(@active_battler, @skill)
    422.     end
    423.   end
    424.   #--------------------------------------------------------------------------
    425.   # * Apply item
    426.   #--------------------------------------------------------------------------
    427.   def make_item_action_result
    428.     @item = $data_items[@active_battler.current_action.item_id]
    429.     unless @active_battler.item_can_use?(@item.id)
    430.       @phase4_step = 1
    431.       return
    432.     end
    433.     if @item.consumable
    434.       $game_party.lose_item(@item.id, 1)
    435.     end
    436.     @help_window.set_text(@item.name, 1)
    437.     @animation1_id = @item.animation1_id
    438.     @animation2_id = @item.animation2_id
    439.     @common_event_id = @item.common_event_id
    440.     index = @active_battler.current_action.target_index
    441.     target = $game_party.smooth_target_actor(index)
    442.     @target_battlers.clear
    443.     @target_battlers = set_target_battlers(@item)
    444.     for target in @target_battlers
    445.       target.item_effect(@item)
    446.     end
    447.   end
    448.   #--------------------------------------------------------------------------
    449.   # * Get available targets for an item or skill
    450.   #--------------------------------------------------------------------------
    451.   def set_target_battlers(item)
    452.     if @active_battler.is_a?(Game_Actor)
    453.       allies = $game_party.actors.clone
    454.       enemies = $game_troop.enemies.clone
    455.     else
    456.       allies = $game_troop.enemies.clone
    457.       enemies = $game_party.actors.clone
    458.     end
    459.     index = @active_battler.current_action.target_index
    460.     result = []
    461.     if item.scope_ally == true
    462.       for target in allies
    463.         result.push(target)
    464.       end
    465.     end
    466.     if item.scope_enemy == true
    467.       for target in enemies
    468.         result.push(target)
    469.       end
    470.     end
    471.     if item.scope_user == true
    472.       if !result.include?(@active_battler)
    473.         result.push(@active_battler)
    474.       end
    475.     end
    476.     if item.scope_user == false
    477.       result.delete(@active_battler)
    478.     end
    479.     if item.scope_all == false
    480.       if item.scope_random == true
    481.         result.select!{|target| !target.dead?} if item.scope_alive == true
    482.         result.select!{|target| target.dead?} if item.scope_alive == false
    483.       else
    484.         if Scope::DEFAULT_DEAD_SELECT == false
    485.           result.select!{|target| !target.dead?} if item.scope_alive == true
    486.           result.select!{|target| target.dead?} if item.scope_alive == false
    487.         end
    488.       end
    489.     end
    490.     result.select!{|target| !target.dead?} if item.scope_alive == true
    491.     result.select!{|target| target.dead?} if item.scope_alive == false
    492.     for r in item.restrictions
    493.       if r.arity == 1
    494.         result.select!{|target| r.call(target) == true } rescue nil
    495.       else
    496.         result.select!{|target| r.call == true } rescue nil
    497.       end
    498.     end
    499.     if item.scope_all == false
    500.       if item.scope_random == true
    501.         result = [result[rand(result.size)]]
    502.       else
    503.         result = [result[index]]
    504.       end
    505.     end
    506.     return result
    507.   end
    508. end
    复制代码


    DFS version
    Spoiler: Code
                    Ruby:        
    1. #==============================================================================
    2. # ** [XP] Advanced Scope v1.1
    3. # This version is compatible with Data File Save, use it only if you're
    4. # using that script. This script must be placed BELOW Data File Save.
    5. #------------------------------------------------------------------------------
    6. # Author: Wecoc (credits are optional)
    7. #------------------------------------------------------------------------------
    8. # Defines new types of scope for items and skills in battle
    9. #------------------------------------------------------------------------------
    10. # $data_items[ID] and $data_skills[ID] work exactly the same way
    11. # To define the target use:
    12. # $data_items[ID].scope_ally   = true | false # Ally
    13. # $data_items[ID].scope_enemy  = true | false # Enemy
    14. # $data_items[ID].scope_all    = true | false # Entire group / Only one
    15. # $data_items[ID].scope_random = true | false # Pick one randomly
    16. # $data_items[ID].scope_user   = true | false # Include user
    17. # $data_items[ID].scope_alive  = true | false # Only alive members
    18. # $data_items[ID].scope_dead   = true | false # Only dead members
    19. #------------------------------------------------------------------------------
    20. # $data_items[ID].restriction(&block) # Set custom restriction
    21. # $data_items[ID].restrictions        # Get all custom restrictions
    22. # $data_items[ID].clear_restrictions  # Clear all custom restrictions
    23. #==============================================================================
    24. #==============================================================================
    25. # ** Scope Configuration
    26. #==============================================================================
    27. module Scope
    28.   #----------------------------------------------------------------------------
    29.   # Default Dead Select
    30.   #----------------------------------------------------------------------------
    31.   # By default if an item only affects members that are alive you can still
    32.   # select a dead member, but the item won't have any effect.
    33.   # The same happens with items that only affect dead members.
    34.   # Set to false if you want to disable that and apply a strict restriction.
    35.   #----------------------------------------------------------------------------
    36.   DEFAULT_DEAD_SELECT = true
    37. end
    38. #==============================================================================
    39. # ** Array
    40. #==============================================================================
    41. class Array
    42.   #--------------------------------------------------------------------------
    43.   # * Select!
    44.   #--------------------------------------------------------------------------
    45.   unless self.respond_to?(:select!)
    46.     def select!(&block)
    47.       result = self.select(&block)
    48.       self.replace(result)
    49.     end
    50.   end
    51. end
    52. #==============================================================================
    53. # ** RPG
    54. #==============================================================================
    55. for Klass in [RPG::Item, RPG::Skill]
    56.   class Klass
    57.    
    58.     ALLY  = [3, 4, 5, 6]
    59.     ENEMY = [1, 2]
    60.     ALL   = [2, 4, 6]
    61.     ALIVE = [1, 2, 3, 4, 7]
    62.     DEAD  = [5, 6]
    63.     USER  = [3, 4, 5, 6, 7]
    64.    
    65.     define_method(:scope_ally)   { @scope_ally |= ALLY.include?(@scope) }
    66.     define_method(:scope_enemy)  { @scope_enemy |= ENEMY.include?(@scope) }
    67.     define_method(:scope_all)    { @scope_all |= ALL.include?(@scope) }
    68.     define_method(:scope_random) { @scope_random |= false }
    69.     define_method(:scope_alive)  { @scope_alive |= ALIVE.include?(@scope) }
    70.     define_method(:scope_dead)   { @scope_dead |= DEAD.include?(@scope) }
    71.     define_method(:scope_user)   { @scope_user |= USER.include?(@scope) }
    72.     define_method(:scope_rest)   { @scope_rest = [] }
    73.     define_method(:restrictions) { @scope_rest = [] }
    74.    
    75.     def restriction(&block)
    76.       @scope_rest.push(block)
    77.     end
    78.    
    79.     def clear_restrictions
    80.       @scope_rest.clear
    81.     end
    82.    
    83.     def set_scope(ally,enemy,all,random=false,user=true,alive=true,dead=false)
    84.       @scope_ally   = ally
    85.       @scope_enemy  = enemy
    86.       @scope_all    = all
    87.       @scope_random = random
    88.       @scope_user   = user
    89.       @scope_alive  = alive
    90.       @scope_dead   = dead
    91.     end
    92.   end
    93. end
    94. #==============================================================================
    95. # ** Arrow_Base
    96. #==============================================================================
    97. class Arrow_Base < Sprite
    98.   attr_reader :user
    99.   attr_reader :item
    100.   attr_reader :target
    101.   attr_reader :targets
    102.   #--------------------------------------------------------------------------
    103.   # * Initialize
    104.   #--------------------------------------------------------------------------
    105.   def initialize(viewport, user, item)
    106.     super(viewport)
    107.     self.bitmap = RPG::Cache.windowskin($game_system.windowskin_name)
    108.     self.ox = 16
    109.     self.oy = 64
    110.     self.z = 2500
    111.     @blink_count = 0
    112.     @index = 0
    113.     @help_window = nil
    114.     @user = user
    115.     @item = item
    116.     @targets = target_battlers
    117.     @target = @targets[0]
    118.     update_sprite
    119.   end
    120.   #--------------------------------------------------------------------------
    121.   # * Get index
    122.   #--------------------------------------------------------------------------
    123.   def index
    124.     return @targets.index(@target) rescue -1
    125.   end
    126.   #--------------------------------------------------------------------------
    127.   # * Set index
    128.   #--------------------------------------------------------------------------
    129.   def index=(index)
    130.     @target = @targets[index]
    131.   end
    132.   #--------------------------------------------------------------------------
    133.   # * Get selectable targets
    134.   #--------------------------------------------------------------------------
    135.   def target_battlers
    136.     if @user.is_a?(Game_Actor)
    137.       allies = $game_party.actors.clone
    138.       enemies = $game_troop.enemies.clone
    139.     else
    140.       allies = $game_troop.enemies.clone
    141.       enemies = $game_party.actors.clone
    142.     end
    143.     allies.delete_if {|target| target.hidden}
    144.     enemies.delete_if{|target| target.hidden}
    145.     if @item == nil
    146.       enemies.delete_if {|target| !target.exist?}
    147.       return enemies
    148.     end
    149.     result = []
    150.     if @item.scope_ally == true
    151.       for target in allies
    152.         result.push(target)
    153.       end
    154.     end
    155.     if @item.scope_enemy == true
    156.       for target in enemies
    157.         result.push(target)
    158.       end
    159.     end
    160.     if @item.scope_user == true
    161.       if !result.include?(@user)
    162.         result.push(@user)
    163.       end
    164.     end
    165.     if @item.scope_user == false
    166.       result.delete(@user)
    167.     end
    168.     if @item.scope_alive == true && Scope::DEFAULT_DEAD_SELECT == false
    169.       result.select!{|target| !target.dead?}
    170.     end
    171.     if @item.scope_dead == true && Scope::DEFAULT_DEAD_SELECT == false
    172.       result.select!{|target| target.dead?}
    173.     end
    174.     for r in @item.restrictions
    175.       if r.arity == 1
    176.         result.select!{|target| r.call(target) == true} rescue nil
    177.       else
    178.         result.select!{|target| r.call == true} rescue nil
    179.       end
    180.     end
    181.     return result
    182.   end
    183.   #--------------------------------------------------------------------------
    184.   # * Update
    185.   #--------------------------------------------------------------------------
    186.   def update
    187.     update_sprite
    188.     if @help_window != nil
    189.       update_help
    190.     end
    191.     if @target == nil
    192.       self.visible = false
    193.       return
    194.     end
    195.     self.visible = true
    196.     # Next target
    197.     if Input.repeat?(Input::RIGHT)
    198.       $game_system.se_play($data_system.cursor_se)
    199.       self.index = (self.index + 1) % @targets.size
    200.     end
    201.     # Previous target
    202.     if Input.repeat?(Input::LEFT)
    203.       $game_system.se_play($data_system.cursor_se)
    204.       self.index = (self.index - 1) % @targets.size
    205.     end
    206.     # Place arrow over target
    207.     if @target != nil
    208.       self.x = @target.screen_x
    209.       self.y = @target.screen_y
    210.     end
    211.   end
    212.   #--------------------------------------------------------------------------
    213.   # * Update Sprite
    214.   #--------------------------------------------------------------------------
    215.   def update_sprite
    216.     @blink_count = (@blink_count + 1) % 8
    217.     if @blink_count < 4
    218.       self.src_rect.set(128, 96, 32, 32)
    219.     else
    220.       self.src_rect.set(160, 96, 32, 32)
    221.     end
    222.   end
    223.   #--------------------------------------------------------------------------
    224.   # * Update Help
    225.   #--------------------------------------------------------------------------
    226.   def update_help
    227.     if @target == nil
    228.       @help_window.set_text("")
    229.       return
    230.     end
    231.     if @target.is_a?(Game_Actor)
    232.       @help_window.set_actor(@target)
    233.     else
    234.       @help_window.set_enemy(@target)
    235.     end
    236.   end
    237. end
    238. #==============================================================================
    239. # ** Game_Battler
    240. #==============================================================================
    241. class Game_Battler
    242.   #--------------------------------------------------------------------------
    243.   # * Check if the skill can be used
    244.   #--------------------------------------------------------------------------
    245.   alias wecoc_scope_skill_use? skill_can_use? unless $@
    246.   def skill_can_use?(skill_id)
    247.     skill = $data_skills[skill_id]
    248.     return false if skill.nil?   # Skill doesn't exist
    249.     return false if !self.exist? # User is hidden or dead
    250.     if self.is_a?(Game_Actor)
    251.       members = $game_party.actors.clone
    252.     else
    253.       members = $game_troop.enemies.clone
    254.     end
    255.     if members.size == 1 # User is the only member and requires an ally
    256.       if skill.user == false && skill.ally == false && skill.enemy == false
    257.         return false
    258.       end
    259.     end
    260.     for r in skill.restrictions
    261.       if r.arity == 1
    262.         members.select!{|target| r.call(target) == true} rescue nil
    263.       else
    264.         members.select!{|target| r.call == true} rescue nil
    265.       end
    266.     end
    267.     return false if members.size == 0
    268.     return wecoc_scope_skill_use?(skill_id)
    269.   end
    270.   #--------------------------------------------------------------------------
    271.   # * Check if the item can be used
    272.   #--------------------------------------------------------------------------
    273.   def item_can_use?(item_id)
    274.     item = $data_items[item_id]
    275.     return false if item.nil?    # Item doesn't exist
    276.     return false if !self.exist? # User is hidden or dead
    277.     if self.is_a?(Game_Actor)
    278.       # Party doesn't contain that item
    279.       return false if $game_party.item_number(item_id) == 0
    280.       # Item restrictions (Only menu / battle)
    281.       return false if $game_temp.in_battle  && item.occasion == 2
    282.       return false if !$game_temp.in_battle && item.occasion == 1
    283.       members = $game_party.actors.clone
    284.     else
    285.       members = $game_troop.enemies.clone
    286.     end
    287.     if members.size == 1 # User is the only member and requires an ally
    288.       if item.user == false && item.ally == false && item.enemy == false
    289.         return false
    290.       end
    291.     end
    292.     for r in item.restrictions
    293.       if r.arity == 1
    294.         members.select!{|target| r.call(target) == true} rescue nil
    295.       else
    296.         members.select!{|target| r.call == true} rescue nil
    297.       end
    298.     end
    299.     return false if members.size == 0
    300.     return true
    301.   end
    302. end
    303. #==============================================================================
    304. # ** Game_Party
    305. #==============================================================================
    306. class Game_Party
    307.   #--------------------------------------------------------------------------
    308.   # * Check if the party can use an item
    309.   #--------------------------------------------------------------------------
    310.   def item_can_use?(item_id)
    311.     for member in $game_party.actors
    312.       if member.item_can_use?(item_id)
    313.         return true
    314.       end
    315.     end
    316.     return false
    317.   end
    318. end
    319. #==============================================================================
    320. # ** Scene_Battle
    321. #==============================================================================
    322. class Scene_Battle
    323.   #--------------------------------------------------------------------------
    324.   # * Select enemy
    325.   #--------------------------------------------------------------------------
    326.   def start_enemy_select
    327.     item = nil
    328.     if @active_battler.current_action.kind == 1
    329.       item = @skill if @skill != nil
    330.     end
    331.     if @active_battler.current_action.kind == 2
    332.       item = @item  if @item != nil
    333.     end
    334.     @enemy_arrow = Arrow_Base.new(@spriteset.viewport2, @active_battler, item)
    335.     @enemy_arrow.help_window = @help_window
    336.     @actor_command_window.active = false
    337.     @actor_command_window.visible = false
    338.   end
    339.   #--------------------------------------------------------------------------
    340.   # * Select actor
    341.   #--------------------------------------------------------------------------
    342.   def start_actor_select
    343.     item = nil
    344.     if @active_battler.current_action.kind == 1
    345.       item = @skill if @skill != nil
    346.     end
    347.     if @active_battler.current_action.kind == 2
    348.       item = @item  if @item != nil
    349.     end
    350.     @actor_arrow = Arrow_Base.new(@spriteset.viewport2, @active_battler, item)
    351.     @actor_arrow.index = @actor_index
    352.     @actor_arrow.help_window = @help_window
    353.     @actor_command_window.active = false
    354.     @actor_command_window.visible = false
    355.   end
    356.   #--------------------------------------------------------------------------
    357.   # * Apply skill
    358.   #--------------------------------------------------------------------------
    359.   def make_skill_action_result
    360.     @skill = $data_skills[@active_battler.current_action.skill_id]
    361.     unless @active_battler.current_action.forcing
    362.       unless @active_battler.skill_can_use?(@skill.id)
    363.         $game_temp.forcing_battler = nil
    364.         @phase4_step = 1
    365.         return
    366.       end
    367.     end
    368.     @active_battler.sp -= @skill.sp_cost
    369.     @status_window.refresh
    370.     @help_window.set_text(@skill.name, 1)
    371.     @animation1_id = @skill.animation1_id
    372.     @animation2_id = @skill.animation2_id
    373.     @common_event_id = @skill.common_event_id
    374.     @target_battlers.clear
    375.     @target_battlers = set_target_battlers(@skill)
    376.     for target in @target_battlers
    377.       target.skill_effect(@active_battler, @skill)
    378.     end
    379.   end
    380.   #--------------------------------------------------------------------------
    381.   # * Apply item
    382.   #--------------------------------------------------------------------------
    383.   def make_item_action_result
    384.     @item = $data_items[@active_battler.current_action.item_id]
    385.     unless @active_battler.item_can_use?(@item.id)
    386.       @phase4_step = 1
    387.       return
    388.     end
    389.     if @item.consumable
    390.       $game_party.lose_item(@item.id, 1)
    391.     end
    392.     @help_window.set_text(@item.name, 1)
    393.     @animation1_id = @item.animation1_id
    394.     @animation2_id = @item.animation2_id
    395.     @common_event_id = @item.common_event_id
    396.     index = @active_battler.current_action.target_index
    397.     target = $game_party.smooth_target_actor(index)
    398.     @target_battlers.clear
    399.     @target_battlers = set_target_battlers(@item)
    400.     for target in @target_battlers
    401.       target.item_effect(@item)
    402.     end
    403.   end
    404.   #--------------------------------------------------------------------------
    405.   # * Get available targets for an item or skill
    406.   #--------------------------------------------------------------------------
    407.   def set_target_battlers(item)
    408.     if @active_battler.is_a?(Game_Actor)
    409.       allies = $game_party.actors.clone
    410.       enemies = $game_troop.enemies.clone
    411.     else
    412.       allies = $game_troop.enemies.clone
    413.       enemies = $game_party.actors.clone
    414.     end
    415.     index = @active_battler.current_action.target_index
    416.     result = []
    417.     if item.scope_ally == true
    418.       for target in allies
    419.         result.push(target)
    420.       end
    421.     end
    422.     if item.scope_enemy == true
    423.       for target in enemies
    424.         result.push(target)
    425.       end
    426.     end
    427.     if item.scope_user == true
    428.       if !result.include?(@active_battler)
    429.         result.push(@active_battler)
    430.       end
    431.     end
    432.     if item.scope_user == false
    433.       result.delete(@active_battler)
    434.     end
    435.     if item.scope_all == false
    436.       if item.scope_random == true
    437.         result.select!{|target| !target.dead?} if item.scope_alive == true
    438.         result.select!{|target| target.dead?} if item.scope_alive == false
    439.       else
    440.         if Scope::DEFAULT_DEAD_SELECT == false
    441.           result.select!{|target| !target.dead?} if item.scope_alive == true
    442.           result.select!{|target| target.dead?} if item.scope_alive == false
    443.         end
    444.       end
    445.     end
    446.     result.select!{|target| !target.dead?} if item.scope_alive == true
    447.     result.select!{|target| target.dead?} if item.scope_alive == false
    448.     for r in item.restrictions
    449.       if r.arity == 1
    450.         result.select!{|target| r.call(target) == true} rescue nil
    451.       else
    452.         result.select!{|target| r.call == true} rescue nil
    453.       end
    454.     end
    455.     if item.scope_all == false
    456.       if item.scope_random == true
    457.         result = [result[rand(result.size)]]
    458.       else
    459.         result = [result[index]]
    460.       end
    461.     end
    462.     return result
    463.   end
    464. end
    复制代码


    Advanced Instructions

    Spoiler: Custom restriction examples
    Targets must have a specific class ID
    1. $data_items[1].restriction {|target| target.is_a?(Game_Actor) && target.class_id == 3}
    复制代码

    Target only certain enemy IDs
    1. $data_items[1].restriction {|target| target.is_a?(Game_Enemy) && [20, 23, 30, 31].include?(target.id) }
    复制代码

    Target battlers with more than 50% HP
    1. $data_items[1].restriction {|target| target.hp >= (target.maxhp * 50 / 100) }
    复制代码

    Target battlers that have a certain state
    1. $data_items[1].restriction {|target| target.state?(2) }
    复制代码

    Target actors that know a certain skill
    1. $data_items[1].restriction {|target| target.skill_learn?(50) }
    复制代码

    Target enemies that know a certain skill
    1. $data_items[1].restriction {|target| target.actions.any?{|action| action.skill_id == 50 }}
    复制代码

    Those should be defined both when creating a new game and when loading, but if you're using DFS you only have to define this once wherever you want.
    FAQ

    Spoiler: FAQ
    - I want to apply a new restriction from an event script call, but those lines are too long.
    Yeah, all my examples are like this
                    Code:        
    1. $data_items[ID].restriction { |target| (ACTION) }
    复制代码


    but you can separate it like this
                    Code:        
    1. $data_items[ID].restriction do |target|
    2.   (ACTION)
    3. end
    复制代码


    - I want to make a "Random Ally" skill, but when there's only one actor (alive) I don't want that skill to be active, since that wouldn't be random at all.

    Good point. You can do that with a custom restriction like this
                    Code:        
    1. $data_items[1].restriction do
    2.   n = 0 ; for target in $game_party.actors
    3.     n += 1 if target.exist?
    4.   end
    5.   (n > 1)
    6. end
    复制代码


    Monster-based Scope (AddOn)

    This AddOn allows to make some enemies untargetable based on a specific condition. That condition can be the ID of the attacker, his equipment, a switch or any other condition. The fact it cannot be selected implies that if neither meets the condition, the attack and offensive abilities will be directly deactivated for the actor in question.

    The only configurable part is the module Monster_Scope, and I made some examples on the instructions of the script.

    Normal version (independent)
    Spoiler: Code
                    Ruby:        
    1. #==============================================================================
    2. # ** [XP] Monster-based Scope v1.1
    3. #------------------------------------------------------------------------------
    4. # Author: Wecoc (no credits required)
    5. #------------------------------------------------------------------------------
    6. # This script allows to make some enemies untargetable based on a specific
    7. # condition. That condition can be the ID of the attacker, his equipment,
    8. # a switch or any other condition. The fact it cannot be selected implies
    9. # that if neither meets the condition, the attack and offensive abilities
    10. # will be directly deactivated for the actor in question.
    11. #------------------------------------------------------------------------------
    12. # It allows multiple conditions, simply define them as an array
    13. #   1 => ["actor.id == 1", "actor.weapon_id == 1", "actor.id == 1"]
    14. # When defined by string, the condition is the same
    15. # When defined by array, the first one is for attack, second for skills and
    16. # third for items.
    17. #------------------------------------------------------------------------------
    18. # To use this you only have to define the conditions as an eval on the constant
    19. # SCOPE_CONDITION in the very start of the script.
    20. #   ID monster => "condition"
    21. # Condition examples
    22. #   # Can only be attacked by the actor with ID 1
    23. #   actor.id == 1
    24. #   # Can only be attacked if the attacker has weapon with ID 1 equipped
    25. #   actor.weapon_id == 1
    26. # Conditions accept two shortcuts; 'actor' and 'target'
    27. #==============================================================================
    28. module Monster_Scope
    29.   # Set here the condition for each enemy ID
    30.   SCOPE_CONDITION = {
    31.     1 => "actor.id == 1",
    32.     2 => "actor.weapon_id == 1"
    33.   }
    34. end
    35. class Game_Actor
    36.   alias monster_scope_skill_use? skill_can_use? unless $@
    37.   def skill_can_use?(skill_id)
    38.     if [1,2].include?($data_skills[skill_id].scope)
    39.       if $scene.is_a?(Scene_Battle) && !$scene.can_select_any_enemy?(1)
    40.         return false
    41.       end
    42.     end
    43.     monster_scope_skill_use?(skill_id)
    44.   end
    45. end
    46. class Game_Party
    47.   alias monster_scope_item_use? item_can_use? unless $@
    48.   def item_can_use?(item_id)
    49.     if [1,2].include?($data_items[item_id].scope)
    50.       if $scene.is_a?(Scene_Battle) && !$scene.can_select_any_enemy?(2)
    51.         return false
    52.       end
    53.     end
    54.     monster_scope_item_use?(item_id)
    55.   end
    56. end
    57. class Scene_Battle
    58.   def can_select_any_enemy?(kind=0)
    59.     # Get if any enemy can be selected
    60.     return if @active_battler.nil? || @active_battler.is_a?(Game_Enemy)
    61.     for target in $game_troop.enemies
    62.       return true if !Monster_Scope::SCOPE_CONDITION.keys.include?(target.id)
    63.       if Monster_Scope::SCOPE_CONDITION[target.id].is_a?(Array)
    64.         e = Monster_Scope::SCOPE_CONDITION[target.id][kind]
    65.       else
    66.         e = Monster_Scope::SCOPE_CONDITION[target.id]
    67.       end
    68.       result = instance_eval("actor = @active_battler;" + e)
    69.       return true if result == true
    70.     end
    71.     return false
    72.   end
    73.   def get_selectable_enemies(kind=0)
    74.     # Set target battlers based on the monster scope condition
    75.     return if @active_battler.nil? || @active_battler.is_a?(Game_Enemy)
    76.     selectable_enemies = []
    77.     for target in $game_troop.enemies
    78.       index = $game_troop.enemies.index(target)
    79.       if Monster_Scope::SCOPE_CONDITION.keys.include?(target.id)
    80.         if Monster_Scope::SCOPE_CONDITION[target.id].is_a?(Array)
    81.           e = Monster_Scope::SCOPE_CONDITION[target.id][kind]
    82.         else
    83.           e = Monster_Scope::SCOPE_CONDITION[target.id]
    84.         end
    85.         result = instance_eval("actor = @active_battler;" + e)
    86.         selectable_enemies.push(index) if result == true
    87.       else
    88.         selectable_enemies.push(index)
    89.       end
    90.     end
    91.     return selectable_enemies
    92.   end
    93.   def start_enemy_select
    94.     targets = get_selectable_enemies(@active_battler.current_action.kind)
    95.     @enemy_arrow = Arrow_Enemy.new(@spriteset.viewport1, targets)
    96.     @enemy_arrow.help_window = @help_window
    97.     @actor_command_window.active = false
    98.     @actor_command_window.visible = false
    99.   end
    100.   alias monster_scope_next phase3_next_actor unless $@
    101.   def phase3_next_actor
    102.     @actor_command_window.refresh
    103.     monster_scope_next
    104.     # Disable Attack command when none enemies can be selected (display)
    105.     if !@active_battler.nil? && !can_select_any_enemy?(0)
    106.       @actor_command_window.disable_item(0)
    107.     end
    108.   end
    109.   alias monster_scope_prior phase3_prior_actor unless $@
    110.   def phase3_prior_actor
    111.     @actor_command_window.refresh
    112.     monster_scope_prior
    113.     # Disable Attack command when none enemies can be selected (display)
    114.     if !@active_battler.nil? && !can_select_any_enemy?(0)
    115.       @actor_command_window.disable_item(0)
    116.     end
    117.   end
    118.   alias monster_scope_phase3_upd update_phase3_basic_command unless $@
    119.   def update_phase3_basic_command
    120.     # Disable Attack command when none enemies can be selected
    121.     if Input.trigger?(Input::C)
    122.       if @actor_command_window.index == 0
    123.         if !@active_battler.nil? && !can_select_any_enemy?(0)
    124.           $game_system.se_play($data_system.buzzer_se)
    125.           return
    126.         end
    127.       end
    128.     end
    129.     monster_scope_phase3_upd
    130.   end
    131. end
    132. class Arrow_Enemy < Arrow_Base
    133.   def initialize(viewport, targets=nil)
    134.     targets = (0...$game_troop.enemies.size).to_a if targets == nil
    135.     @targets = targets
    136.     super(viewport)
    137.   end
    138.   def exist?
    139.     return self.enemy.exist? && @targets.include?(self.enemy.index)
    140.   end
    141.   def update
    142.     super
    143.     $game_troop.enemies.size.times do
    144.       break if self.exist?
    145.       @index += 1
    146.       @index %= $game_troop.enemies.size
    147.     end
    148.     if Input.repeat?(Input::RIGHT)
    149.       $game_system.se_play($data_system.cursor_se)
    150.       $game_troop.enemies.size.times do
    151.         @index += 1
    152.         @index %= $game_troop.enemies.size
    153.         break if self.exist?
    154.       end
    155.     end
    156.     if Input.repeat?(Input::LEFT)
    157.       $game_system.se_play($data_system.cursor_se)
    158.       $game_troop.enemies.size.times do
    159.         @index += $game_troop.enemies.size - 1
    160.         @index %= $game_troop.enemies.size
    161.         break if self.exist?
    162.       end
    163.     end
    164.     if self.enemy != nil
    165.       self.x = self.enemy.screen_x
    166.       self.y = self.enemy.screen_y
    167.     end
    168.   end
    169. end
    复制代码


    Advanced Scope version
    Spoiler: Code
                    Ruby:        
    1. #==============================================================================
    2. # ** [XP] Monster-based Scope v1.1 [Advanced Scope]
    3. #------------------------------------------------------------------------------
    4. # Author: Wecoc (no credits required)
    5. # This version requires the script Advanced Scope
    6. #------------------------------------------------------------------------------
    7. # This script allows to make some enemies untargetable based on a specific
    8. # condition. That condition can be the ID of the attacker, his equipment,
    9. # a switch or any other condition. The fact it cannot be selected implies
    10. # that if neither meets the condition, the attack and offensive abilities
    11. # will be directly deactivated for the actor in question.
    12. #------------------------------------------------------------------------------
    13. # It allows multiple conditions, simply define them as an array
    14. #   1 => ["actor.id == 1", "actor.weapon_id == 1", "actor.id == 1"]
    15. # When defined by string, the condition is the same
    16. # When defined by array, the first one is for attack, second for skills and
    17. # third for items.
    18. #------------------------------------------------------------------------------
    19. # To use this you only have to define the conditions as an eval on the constant
    20. # SCOPE_CONDITION in the very start of the script.
    21. #   ID monster => "condition"
    22. # Condition examples
    23. #   # Can only be attacked by the actor with ID 1
    24. #   actor.id == 1
    25. #   # Can only be attacked if the attacker has weapon with ID 1 equipped
    26. #   actor.weapon_id == 1
    27. # Conditions accept two shortcuts; 'actor' and 'target'
    28. #==============================================================================
    29. module Monster_Scope
    30.   # Set here the condition for each enemy ID
    31.   SCOPE_CONDITION = {
    32.     1 => "actor.id == 1",
    33.     2 => "actor.weapon_id == 1"
    34.   }
    35. end
    36. class Game_Actor
    37.   alias monster_scope_skill_use? skill_can_use? unless $@
    38.   def skill_can_use?(skill_id)
    39.     if $data_skills[skill_id].scope_enemy
    40.       if $scene.is_a?(Scene_Battle) && !$scene.can_select_any_enemy?(1)
    41.         return false
    42.       end
    43.     end
    44.     monster_scope_skill_use?(skill_id)
    45.   end
    46. end
    47. class Game_Party
    48.   alias monster_scope_item_use? item_can_use? unless $@
    49.   def item_can_use?(item_id)
    50.     if $data_items[item_id].scope_enemy
    51.       if $scene.is_a?(Scene_Battle) && !$scene.can_select_any_enemy?(2)
    52.         return false
    53.       end
    54.     end
    55.     monster_scope_item_use?(item_id)
    56.   end
    57. end
    58. class Arrow_Base < Sprite
    59.   alias monster_scope_ini initialize unless $@
    60.   def initialize(viewport, user, item, targets=nil)
    61.     monster_scope_ini(viewport, user, item)
    62.     if item.nil? && !targets.nil?
    63.       @targets = targets
    64.       @target = @targets[0]
    65.       update_sprite
    66.     end
    67.   end
    68. end
    69. class Scene_Battle
    70.   def can_select_any_enemy?(kind=0)
    71.     # Get if any enemy can be selected
    72.     return if @active_battler.nil? || @active_battler.is_a?(Game_Enemy)
    73.     for target in $game_troop.enemies
    74.       return true if !Monster_Scope::SCOPE_CONDITION.keys.include?(target.id)
    75.       if Monster_Scope::SCOPE_CONDITION[target.id].is_a?(Array)
    76.         e = Monster_Scope::SCOPE_CONDITION[target.id][kind]
    77.       else
    78.         e = Monster_Scope::SCOPE_CONDITION[target.id]
    79.       end
    80.       result = instance_eval("actor = @active_battler;" + e)
    81.       return true if result == true
    82.     end
    83.     return false
    84.   end
    85.   def get_selectable_enemies(kind=0)
    86.     # Set target battlers based on the monster scope condition
    87.     return if @active_battler.nil? || @active_battler.is_a?(Game_Enemy)
    88.     selectable_enemies = []
    89.     for target in $game_troop.enemies
    90.       index = $game_troop.enemies.index(target)
    91.       if Monster_Scope::SCOPE_CONDITION.keys.include?(target.id)
    92.         if Monster_Scope::SCOPE_CONDITION[target.id].is_a?(Array)
    93.           e = Monster_Scope::SCOPE_CONDITION[target.id][kind]
    94.         else
    95.           e = Monster_Scope::SCOPE_CONDITION[target.id]
    96.         end
    97.         result = instance_eval("actor = @active_battler;" + e)
    98.         selectable_enemies.push(target) if result == true
    99.       else
    100.         selectable_enemies.push(target)
    101.       end
    102.     end
    103.     return selectable_enemies
    104.   end
    105.   alias monster_scope_enemy_select start_enemy_select
    106.   def start_enemy_select
    107.     if @active_battler.current_action.kind == 0 # Attack
    108.       targets = get_selectable_enemies(@active_battler.current_action.kind)
    109.       @enemy_arrow = Arrow_Base.new(@spriteset.viewport2,
    110.       @active_battler, nil, targets)
    111.       @enemy_arrow.help_window = @help_window
    112.       @actor_command_window.active = false
    113.       @actor_command_window.visible = false
    114.       return
    115.     end
    116.     monster_scope_enemy_select
    117.   end
    118.   alias monster_scope_next phase3_next_actor unless $@
    119.   def phase3_next_actor
    120.     @actor_command_window.refresh
    121.     monster_scope_next
    122.     # Disable Attack command when none enemies can be selected (display)
    123.     if !@active_battler.nil? && !can_select_any_enemy?(0)
    124.       @actor_command_window.disable_item(0)
    125.     end
    126.   end
    127.   alias monster_scope_prior phase3_prior_actor unless $@
    128.   def phase3_prior_actor
    129.     @actor_command_window.refresh
    130.     monster_scope_prior
    131.     # Disable Attack command when none enemies can be selected (display)
    132.     if !@active_battler.nil? && !can_select_any_enemy?(0)
    133.       @actor_command_window.disable_item(0)
    134.     end
    135.   end
    136.   alias monster_scope_phase3_upd update_phase3_basic_command unless $@
    137.   def update_phase3_basic_command
    138.     # Disable Attack command when none enemies can be selected
    139.     if Input.trigger?(Input::C)
    140.       if @actor_command_window.index == 0
    141.         if !@active_battler.nil? && !can_select_any_enemy?(0)
    142.           $game_system.se_play($data_system.buzzer_se)
    143.           return
    144.         end
    145.       end
    146.     end
    147.     monster_scope_phase3_upd
    148.   end
    149.   def set_target_battlers(item)
    150.     if @active_battler.is_a?(Game_Actor)
    151.       allies = $game_party.actors.clone
    152.       enemies = $game_troop.enemies.clone
    153.     else
    154.       allies = $game_troop.enemies.clone
    155.       enemies = $game_party.actors.clone
    156.     end
    157.     index = @active_battler.current_action.target_index
    158.     result = []
    159.     if item.scope_ally == true
    160.       for target in allies
    161.         result.push(target)
    162.       end
    163.     end
    164.     if item.scope_enemy == true
    165.       for target in enemies
    166.         result.push(target)
    167.       end
    168.     end
    169.     if item.scope_user == true
    170.       if !result.include?(@active_battler)
    171.         result.push(@active_battler)
    172.       end
    173.     end
    174.     if item.scope_user == false
    175.       result.delete(@active_battler)
    176.     end
    177.     if item.scope_all == false
    178.       if item.scope_random == true
    179.         result.select!{|target| !target.dead?} if item.scope_alive == true
    180.         result.select!{|target| target.dead?} if item.scope_alive == false
    181.       else
    182.         if Scope::DEFAULT_DEAD_SELECT == false
    183.           result.select!{|target| !target.dead?} if item.scope_alive == true
    184.           result.select!{|target| target.dead?} if item.scope_alive == false
    185.         end
    186.       end
    187.     end
    188.     result.select!{|target| !target.dead?} if item.scope_alive == true
    189.     result.select!{|target| target.dead?} if item.scope_alive == false
    190.     for r in item.restrictions
    191.       if r.arity == 1
    192.         result.select!{|target| r.call(target) == true } rescue nil
    193.       else
    194.         result.select!{|target| r.call == true } rescue nil
    195.       end
    196.     end
    197.     # --- Monster Scope ---
    198.     kind = 0 # Default
    199.     kind = 1 if item.is_a?(RPG::Skill); kind = 2 if item.is_a?(RPG::Item)
    200.     selectable_enemies = $scene.get_selectable_enemies(kind)
    201.     for target in result
    202.       if target.is_a?(Game_Enemy) && !selectable_enemies.include?(target)
    203.         result.delete(target)
    204.       end
    205.     end
    206.     # ------
    207.     if item.scope_all == false
    208.       if item.scope_random == true
    209.         result = [result[rand(result.size)]]
    210.       else
    211.         result = [result[index]]
    212.       end
    213.     end
    214.     return result
    215.   end
    216. end
    复制代码


    I hope you like this. It's insane how long my posts tend to be



    本贴来自国际rpgmaker官方论坛作者:Wecoc处,因国际论坛即将永久关站,为了存档多年珍贵资料,署名转载到本论坛存档,由于官方帖子为英文原帖,需要中文翻译请点击论坛顶部切换语言为中文就可以将帖子翻译成中文浏览,方便大家随时查看,原文地址:https://forums.rpgmakerweb.com/threads/advanced-scopes-more-target-options-for-battlers.139759/
    天天去同能,天天有童年!
    回复 送礼论坛版权

    使用道具 举报

    文明发言,和谐互动
    文明发言,和谐互动
    高级模式
    您需要登录后才可以回帖 登录 | 立即注册

    本版积分规则

    简体中文
    繁體中文
    English(英语)
    日本語(日语)
    Deutsch(德语)
    Русский язык(俄语)
    بالعربية(阿拉伯语)
    Türkçe(土耳其语)
    Português(葡萄牙语)
    ภาษาไทย(泰国语)
    한어(朝鲜语/韩语)
    Français(法语)
    关闭

    幸运抽奖

    社区每日抽奖来袭,快来试试你是欧皇还是非酋~

    立即查看

    聊天机器人
    Loading...

    QQ|Archiver|手机版|小黑屋|同能RPG制作大师 ( 沪ICP备12027754号-3 )

    GMT+8, 2026-7-14 17:54 , Processed in 0.097428 second(s), 52 queries .

    Powered by Discuz! X3.4

    Copyright © 2001-2020, Tencent Cloud.

    快速回复 返回顶部 返回列表