From bf2a8aebc625da2cfb1a4fb7bdf4d187bb68fc5f Mon Sep 17 00:00:00 2001 From: JappaWakka Date: Sat, 22 Jul 2023 12:06:03 +0200 Subject: [PATCH] Return a random move when no attacking moves --- P3D/Battle/BattleSystemV2/TrainerAI.vb | 25 ++++++++++++++++++++++++- 1 file changed, 24 insertions(+), 1 deletion(-) diff --git a/P3D/Battle/BattleSystemV2/TrainerAI.vb b/P3D/Battle/BattleSystemV2/TrainerAI.vb index 4e85c966d..7e2156f03 100644 --- a/P3D/Battle/BattleSystemV2/TrainerAI.vb +++ b/P3D/Battle/BattleSystemV2/TrainerAI.vb @@ -832,7 +832,30 @@ Namespace BattleSystem Return ProduceOppStep(m, chosenAttackMove) End If - 'catch crash: return random move: + 'if no attacking moves, return random move: + If BattleScreen.Trainer.AILevel >= 0 Then + Dim AvailableAttacks As List(Of Integer) = New List(Of Integer) + For i = 0 To m.Count - 1 + AvailableAttacks.Add(i) + Next + Dim OppAttackChoice As Integer = Core.Random.Next(0, AvailableAttacks.Count) + Dim Ready As Boolean = False + While Ready = False + If m(OppAttackChoice) Is BattleScreen.FieldEffects.OppTormentMove OrElse m(OppAttackChoice).Disabled > 0 OrElse BattleScreen.FieldEffects.OppTaunt > 0 AndAlso BattleScreen.OppPokemon.Attacks(OppAttackChoice).Category = Attack.Categories.Status Then + AvailableAttacks.Remove(OppAttackChoice) + If AvailableAttacks.Count > 0 Then + OppAttackChoice = AvailableAttacks(Core.Random.Next(0, AvailableAttacks.Count)) + Else + Return New RoundConst() With {.StepType = RoundConst.StepTypes.Move, .Argument = Attack.GetAttackByID(165)} + End If + Else + Ready = True + End If + End While + Return ProduceOppStep(m, OppAttackChoice) + End If + + 'catch crash: return struggle Return New RoundConst() With {.StepType = RoundConst.StepTypes.Move, .Argument = Attack.GetAttackByID(165)} End Function