#=============================================================================== # AI In-Fighting - By Vendily [v21] #=============================================================================== # This script adds in in-fighting between AI controlled battlers, such as # Seviper/Zangoose fighting each other in horde encounters, or Mareanie # targeting Corsola when summoned by SOS. # It also allows the feature to be given to Trainers, though unlike wild battles, # Trainer controlled battlers will not actively seek out to attack allies, they # are just allowed to target them, and are not negatively scored if they do so. #=============================================================================== # An additional modification is necessary to made to the base scripts. # in `def pbGetMoveScores` in script section `AI_ChooseMove` # `next if target_data.targets_foe && !@user.battler.opposes?(b)` becomes # `next if target_data.targets_foe && !@user.battler.opposes?(b) && !@trainer.should_in_fight?(@user, b)` #=============================================================================== # Trainer Types or Wild Pokémon Species with the "Infighting" flag will be # allowed to target allies. # Wild Pokémon Species with the "InFighting_SPECIES" flag will specifically # target SPECIES allies at an increased rate. The "InFighting_SPECIES" flag # automatically applies the "Infighting" Flag. # Only the Species with the "InFighting_SPECIES" flag will target allies. #=============================================================================== PluginManager.register({ :name => "AI In-Fighting", :version => "1.0", :essentials => "21.1", :credits => "Vendily" }) class Battle::AI::AITrainer attr_reader :skill_flags alias _ai_infight_set_up_skill_flags set_up_skill_flags def set_up_skill_flags _ai_infight_set_up_skill_flags return if @trainer added_infighting = false @ai.battle.eachSameSideBattler(@side) do |b| sp_data = b.pokemon.species_data if sp_data.has_flag?("InFighting") @skill_flags.push("InFighting") added_infighting = true end sp_data.flags.each do |flag| next unless flag[/^InFighting_(\w+)$/i] target_species = $~[1].upcase.to_sym next unless GameData::Species.exists?(target_species) @skill_flags.push(sprintf("InFighting_%s_%s",target_species,sp_data.species)) unless added_infighting @skill_flags.push("InFighting") added_infighting = true end end end end def should_in_fight?(user,target) return false if !has_skill_flag?("InFighting") return true if @trainer user_species = user.battler.species target_species = target.species return has_skill_flag?(sprintf("InFighting_%s_%s",target_species,user_species)) end end class Battle::AI alias _ai_infight_add_move_to_choices add_move_to_choices def add_move_to_choices(choices, idxMove, score, idxTarget = -1) if idxTarget>=0 && @trainer.should_in_fight?(@user,@battle.battlers[idxTarget]) && !@user.battler.opposes?(idxTarget) # reverse the reversal of Ally targeting old_score = score score = ((1.85 * MOVE_BASE_SCORE) - score).to_i PBDebug.log_score_change(score - old_score, "#{@user.name} is in-fighting, intentionally targeting ally.") end _ai_infight_add_move_to_choices(choices, idxMove, score, idxTarget) return unless @user.wild? # Increase chance of infighting for wild mons that specifically target a species if idxTarget>=0 && @trainer.should_in_fight?(@user,@battle.battlers[idxTarget]) && !@user.battler.opposes?(idxTarget) PBDebug.log_ai("#{@user.name} is in-fighting, extra attempt against ally.") choices.push([idxMove, score, idxTarget]) end end end