#==============================================================================
#  @> Use Random Skills When Confused ~ Karin's Soulkeeper, 2015
#------------------------------------------------------------------------------
#   v1.0 - May 23 : Started & finished.
#------------------------------------------------------------------------------
#  * Description:
#    This script takes out the boringness from the default "Attack Anyone"
#    state by making affected battlers perform a random skill from their
#    skillset, instead of just attacking. Just like how "Confusion" should
#    really be.
#------------------------------------------------------------------------------
#  * To Use:
#    Put this script below Materials and above Main.
#------------------------------------------------------------------------------
#  * Compatibility:
#    This script overwrites Game_Action.set_confusion
#------------------------------------------------------------------------------
#  * Terms:
#    Free to use in any kind of project, with or without credit. I wouldn't
#    really mind. Though I'd appreciate it! (^w^)/
#    Just don't, you know, claim that you made this here script yourself,
#    Because that's just mean (._.)
#==============================================================================

#CUSTOMIZATION OPTIONS
module KS
  module ConFuSki
  
  #--------------------------------------------------------------------------
  # Set whether to maintain the Ratings set for each skill for the enemy
  # in the database. If false, all skills the enemy may possess will have
  # equal chances of being picked.
  #--------------------------------------------------------------------------
  # Somewhat nice against enemies who have frequent, annoyingly strong moves.
  # Now they'll get a taste of their own medicine! (there's a chance, at least.)
  #--------------------------------------------------------------------------
  KEEP_RATINGS = false
    
  end
end
# END OF CUSTOMIZATION OPTIONS

#==============================================================================
# ** Modified Class: Game_Action
#==============================================================================
class Game_Action
  #--------------------------------------------------------------------------
  # * Overwrite: Set Confusion Action
  #--------------------------------------------------------------------------
  def set_confusion
    if subject.actor?
      skill_set = subject.usable_skills
      skill = (skill_set[rand(skill_set.size)])
      return unless skill
      set_skill(skill.id)
    elsif subject.enemy? && !KS::ConFuSki::KEEP_RATINGS
      set_enemy_action(subject.make_actions_confused)
    end
  end
end

class Game_Enemy < Game_Battler
  #--------------------------------------------------------------------------
  # * New: Randomly Select Action (No Ratings Mode)
  #--------------------------------------------------------------------------
  def select_enemy_action_no_r(action_list)
    return action_list[rand(action_list.size)]
  end
  
  #--------------------------------------------------------------------------
  # * New: Create Battle Action (No Ratings Mode)
  #--------------------------------------------------------------------------
  def make_actions_confused
    return if @actions.empty?
    action_list = enemy.actions.select {|a| action_valid?(a) }
    return if action_list.empty?
    return select_enemy_action_no_r(action_list)
  end
end