#==============================================================================
# 
# ▼ Craze Script Asylum - Lunatic Targets Package - Health
# -- Requires: YEA - Lunatic Targets v1.00+
# 
#==============================================================================

$imported = {} if $imported.nil?
$imported["CSA-LTP-Health"] = true

if $imported["YEA-LunaticTargets"]
class Game_Action
  
  #--------------------------------------------------------------------------
  # ● Lunatic Targets Package Scopes - Health
  # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
  alias lunatic_targets_extension_has_chron lunatic_targets_extension
  def lunatic_targets_extension(effect, user, smooth_target, targets)
    case effect.upcase
    #----------------------------------------------------------------------
    # Condition Scope No.1: Smart Heal
    # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
    # This will let an enemy heal a low-HP ally. It is still somewhat random,
    # but will never heal a full-health ally unless everybody is at full health.
    # 
    # Recommended notetag:
    #   <custom target: smart heal>
    #----------------------------------------------------------------------
    when "SMART HEAL"
      potential = []; reduce = false
      group = friends_unit.alive_members
      for member in group; reduce = true if member.mhp > 3000; end
      for member in group
        next if member.mhp == member.hp
        n = member.mhp - member.hp
        n /= 100 if reduce # This is to help lower processing time late-game
        n = n * (n / 5.0) # n ^ 1.2
        n = n.ceil
        n.times do potential.push(member) end
      end
      potential = group if potential.empty?
      targets.push( potential[ rand(potential.size) ] )
      
    #----------------------------------------------------------------------
    # Stop editting past this point.
    #----------------------------------------------------------------------
    else
      st = smooth_target
      return lunatic_targets_extension_has_chron(effect, user, st, targets)
    end
    if $imported["YEA-BattleEngine"]
      targets.sort! { |a,b| a.screen_x <=> b.screen_x }
    end
    return targets
  end
  
end # Game_BattlerBase
end # $imported["YEA-LunaticTargets"]

#==============================================================================
# 
# ▼ End of File
# 
#==============================================================================