From 66046800d3d3481c60085cc4d29925a9f2ed36aa Mon Sep 17 00:00:00 2001 From: JappaWakka Date: Thu, 9 Mar 2023 19:36:47 +0100 Subject: [PATCH] =?UTF-8?q?Pok=C3=A9mon=20will=20no=20longer=20choose=20di?= =?UTF-8?q?sabled=20moves...?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit but instead pick another move. if there are no usable moves left, the pokémon uses struggle --- P3D/Battle/BattleSystemV2/Battle.vb | 21 +++++++++- P3D/Battle/BattleSystemV2/TrainerAI.vb | 58 ++++++++++++++++++-------- P3D/Pokemon/Attacks/Normal/Struggle.vb | 2 +- 3 files changed, 62 insertions(+), 19 deletions(-) diff --git a/P3D/Battle/BattleSystemV2/Battle.vb b/P3D/Battle/BattleSystemV2/Battle.vb index 93cc95ace..65b08c1ae 100644 --- a/P3D/Battle/BattleSystemV2/Battle.vb +++ b/P3D/Battle/BattleSystemV2/Battle.vb @@ -421,7 +421,26 @@ AI_MegaEvolve(BattleScreen) Return TrainerAI.GetAIMove(BattleScreen, OwnStep) Else - Return New RoundConst() With {.StepType = RoundConst.StepTypes.Move, .Argument = BattleScreen.OppPokemon.Attacks(Core.Random.Next(0, BattleScreen.OppPokemon.Attacks.Count))} + Dim AvailableAttacks As List(Of Integer) = New List(Of Integer) + For i = 0 To BattleScreen.OppPokemon.Attacks.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 BattleScreen.OppPokemon.Attacks(OppAttackChoice).Disabled > 0 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 New RoundConst() With {.StepType = RoundConst.StepTypes.Move, .Argument = BattleScreen.OppPokemon.Attacks(OppAttackChoice)} End If End Function diff --git a/P3D/Battle/BattleSystemV2/TrainerAI.vb b/P3D/Battle/BattleSystemV2/TrainerAI.vb index 913add46d..b8a4199ff 100644 --- a/P3D/Battle/BattleSystemV2/TrainerAI.vb +++ b/P3D/Battle/BattleSystemV2/TrainerAI.vb @@ -1,4 +1,6 @@ -Namespace BattleSystem +Imports P3D.BattleSystem.Battle + +Namespace BattleSystem Public Class TrainerAI @@ -106,15 +108,33 @@ 'Only applies if trainer has an AI level below 20: If BattleScreen.Trainer.AILevel < 20 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).Disabled > 0 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 If Core.Player.DifficultyMode = 0 Then 'Chance of 35% that the trainer is using a random move: If Core.Random.Next(0, 100) < 35 Then - Return ProduceOppStep(m, Core.Random.Next(0, m.Count)) + Return ProduceOppStep(m, OppAttackChoice) End If ElseIf Core.Player.DifficultyMode = 1 Then 'Chance of 18% that the trainer is using a random move: If Core.Random.Next(0, 100) < 18 Then - Return ProduceOppStep(m, Core.Random.Next(0, m.Count)) + Return ProduceOppStep(m, OppAttackChoice) End If End If End If @@ -347,12 +367,12 @@ '-------------------------------------Moves---------------------------------------------------------------------------------------' 'If own pokemon is asleep, try to use Sleep Talk (100%) - If p.Status = Pokemon.StatusProblems.Sleep And BattleScreen.FieldEffects.OppSleepTurns > 1 And HasMove(m, 214) = True Then + If p.Status = Pokemon.StatusProblems.Sleep And BattleScreen.FieldEffects.OppSleepTurns > 1 And HasMove(m, 214) = True AndAlso m(IDtoMoveIndex(m, 214)).Disabled = 0 Then Return ProduceOppStep(m, IDtoMoveIndex(m, 214)) End If 'If own pokemon is asleep, try to use Snore (100%) - If p.Status = Pokemon.StatusProblems.Sleep And BattleScreen.FieldEffects.OppSleepTurns > 1 And HasMove(m, 173) = True Then + If p.Status = Pokemon.StatusProblems.Sleep And BattleScreen.FieldEffects.OppSleepTurns > 1 And HasMove(m, 173) = True AndAlso m(IDtoMoveIndex(m, 173)).Disabled = 0 Then Return ProduceOppStep(m, IDtoMoveIndex(m, 173)) End If @@ -365,7 +385,7 @@ End If 'Fake Out if first turn -> try to inflict flinch (100%) - If HasMove(m, 252) = True Then + If HasMove(m, 252) = True AndAlso m(IDtoMoveIndex(m, 252)).Disabled = 0 Then If op.Ability.Name.ToLower() <> "inner focus" Then Dim turns As Integer = BattleScreen.FieldEffects.OppPokemonTurns If turns = 0 Then @@ -386,7 +406,7 @@ 'use attacking move if speed is higher than opp speed and opponent has low health (<= 30%) (75%) If p.Speed > op.Speed And op.HP <= CInt((op.MaxHP / 100) * 30) Then - Dim chosenMove As Integer = GetAttackingMove(BattleScreen, m) + Dim chosenMove As Integer = MoveAI(m, Attack.AIField.Damage) If chosenMove > -1 Then If CheckForTypeIneffectiveness(BattleScreen, m, chosenMove) = True Then Return ProduceOppStep(m, chosenMove) @@ -518,7 +538,7 @@ 'try to set up leech seed (75%) If op.IsType(Element.Types.Grass) = False Then If BattleScreen.FieldEffects.OwnLeechSeed = 0 Then - If HasMove(m, 73) = True Then + If HasMove(m, 73) = True AndAlso m(IDtoMoveIndex(m, 73)).Disabled = 0 Then If RPercent(75) = True Then Return ProduceOppStep(m, IDtoMoveIndex(m, 73)) End If @@ -528,7 +548,7 @@ 'try to use FocusEnergy (50%) If BattleScreen.FieldEffects.OppFocusEnergy = 0 Then - If HasMove(m, 116) = True Then + If HasMove(m, 116) = True AndAlso m(IDtoMoveIndex(m, 116)).Disabled = 0 Then If RPercent(50) = True Then Return ProduceOppStep(m, IDtoMoveIndex(m, 116)) End If @@ -622,10 +642,10 @@ 'Use LightScreen/Reflect (75%): If RPercent(75) = True Then - If HasMove(m, 113) = True And op.SpAttack > op.Attack And BattleScreen.FieldEffects.OppLightScreen = 0 Then + If HasMove(m, 113) = True And op.SpAttack > op.Attack And BattleScreen.FieldEffects.OppLightScreen = 0 AndAlso m(IDtoMoveIndex(m, 113)).Disabled = 0 Then Return ProduceOppStep(m, IDtoMoveIndex(m, 113)) End If - If HasMove(m, 115) = True And op.Attack > op.SpAttack And BattleScreen.FieldEffects.OppReflect = 0 Then + If HasMove(m, 115) = True And op.Attack > op.SpAttack And BattleScreen.FieldEffects.OppReflect = 0 AndAlso m(IDtoMoveIndex(m, 115)).Disabled = 0 Then Return ProduceOppStep(m, IDtoMoveIndex(m, 115)) End If End If @@ -633,10 +653,12 @@ 'Special Moveset combos: ' - Defense Curl + Rollout If HasMove(m, 205) = True And HasMove(m, 111) = True Then - If BattleScreen.FieldEffects.OppDefenseCurl = 0 Then + If BattleScreen.FieldEffects.OppDefenseCurl = 0 AndAlso m(IDtoMoveIndex(m, 111)).Disabled = 0 Then Return ProduceOppStep(m, IDtoMoveIndex(m, 111)) Else - Return ProduceOppStep(m, IDtoMoveIndex(m, 205)) + If m(IDtoMoveIndex(m, 205)).Disabled = 0 Then + Return ProduceOppStep(m, IDtoMoveIndex(m, 205)) + End If End If End If @@ -644,7 +666,7 @@ Dim attackDic As New Dictionary(Of Integer, Integer) For i = 0 To m.Count - 1 - If MoveHasAIField(m(i), Attack.AIField.Damage) = True Then + If MoveHasAIField(m(i), Attack.AIField.Damage) = True AndAlso m(i).Disabled = 0 Then attackDic.Add(i, 0) End If Next @@ -793,7 +815,7 @@ End If 'catch crash: return random move: - Return ProduceOppStep(m, Core.Random.Next(0, m.Count)) + Return New RoundConst() With {.StepType = RoundConst.StepTypes.Move, .Argument = Attack.GetAttackByID(165)} End Function Private Shared Function HasOtherAttackingMoveThanExplosion(ByVal m As List(Of Attack), ByVal leaveOutIndex As Integer) As Boolean @@ -836,8 +858,10 @@ Private Shared Function MoveAI(ByVal m As List(Of Attack), ByVal AIType As Attack.AIField) As Integer Dim validMoves As New List(Of Integer) For i = 0 To m.Count - 1 - If m(i).AIField1 = AIType Or m(i).AIField2 = AIType Or m(i).AIField3 = AIType Then - validMoves.Add(i) + If m(i).Disabled = 0 Then + If m(i).AIField1 = AIType Or m(i).AIField2 = AIType Or m(i).AIField3 = AIType Then + validMoves.Add(i) + End If End If Next diff --git a/P3D/Pokemon/Attacks/Normal/Struggle.vb b/P3D/Pokemon/Attacks/Normal/Struggle.vb index 648969b00..d22242ec5 100644 --- a/P3D/Pokemon/Attacks/Normal/Struggle.vb +++ b/P3D/Pokemon/Attacks/Normal/Struggle.vb @@ -55,7 +55,7 @@ End Sub Public Overrides Sub MoveSelected(own As Boolean, BattleScreen As BattleScreen) - BattleScreen.BattleQuery.Add(New TextQueryObject(BattleScreen.OwnPokemon.GetDisplayName() & " has no PP left!")) + BattleScreen.BattleQuery.Add(New TextQueryObject(BattleScreen.OwnPokemon.GetDisplayName() & " has no usable attacks left!")) End Sub Public Overrides Sub MoveHits(own As Boolean, BattleScreen As BattleScreen)