Fixes for Pokemon capture
All checks were successful
Build / Build (push) Successful in 1m11s

This commit is contained in:
Deukhoofd 2025-08-08 12:45:27 +02:00
parent a5675024a4
commit e5041ec5f0
Signed by: Deukhoofd
GPG Key ID: F63E044490819F6F
4 changed files with 30 additions and 6 deletions

View File

@ -1,3 +1,4 @@
using PkmnLib.Dynamic.Events;
using PkmnLib.Dynamic.Models;
using PkmnLib.Dynamic.Models.Choices;
using PkmnLib.Dynamic.ScriptHandling;
@ -180,6 +181,7 @@ public static class TurnRunner
var side = battle.Sides[itemChoice.TargetSide.Value];
target = side.Pokemon[itemChoice.TargetPosition.Value];
}
battle.EventHook.Invoke(new ItemUseEvent(user, itemChoice.Item));
itemChoice.Item.RunItemScript(battle.Library.ScriptResolver, target ?? user, battle.EventHook);
}
}

View File

@ -0,0 +1,19 @@
using PkmnLib.Dynamic.Models;
using PkmnLib.Static;
namespace PkmnLib.Dynamic.Events;
public record ItemUseEvent : IEventData
{
public ItemUseEvent(IPokemon pokemon, IItem itemUsed)
{
Pokemon = pokemon;
ItemUsed = itemUsed;
}
public IPokemon Pokemon { get; set; }
public IItem ItemUsed { get; set; }
/// <inheritdoc />
public EventBatchId BatchId { get; init; }
}

View File

@ -535,13 +535,16 @@ public class BattleImpl : ScriptSource, IBattle
}
EventHook.Invoke(new CaptureAttemptEvent(target, attemptCapture, item));
if (!CanSlotBeFilled(sideIndex, position))
if (attemptCapture.IsCaught)
{
Sides[sideIndex].MarkPositionAsUnfillable(position);
}
Sides[sideIndex].ForceClearPokemonFromField(position);
if (!CanSlotBeFilled(sideIndex, position))
{
Sides[sideIndex].MarkPositionAsUnfillable(position);
}
Sides[sideIndex].ForceClearPokemonFromField(position);
ValidateBattleState();
ValidateBattleState();
}
return attemptCapture;
}

View File

@ -70,7 +70,7 @@ public class Gen7CaptureLibrary : ICaptureLibrary
}
}
}
var success = shakes >= 3;
var success = shakes >= 4;
return new CaptureResult(success, shakes, false);
}
}