This commit is contained in:
@@ -162,10 +162,14 @@ public static class TurnRunner
|
||||
}
|
||||
|
||||
if (!battle.Library.MiscLibrary.CanFlee(battle, fleeChoice))
|
||||
{
|
||||
battle.EventHook.Invoke(new FleeEvent(user, false));
|
||||
return;
|
||||
}
|
||||
|
||||
var userSide = battle.Sides[battleData.SideIndex];
|
||||
userSide.MarkAsFled();
|
||||
battle.EventHook.Invoke(new FleeEvent(user, true));
|
||||
battle.ValidateBattleState();
|
||||
}
|
||||
|
||||
|
||||
29
PkmnLib.Dynamic/Events/FleeEvent.cs
Normal file
29
PkmnLib.Dynamic/Events/FleeEvent.cs
Normal file
@@ -0,0 +1,29 @@
|
||||
using PkmnLib.Dynamic.Models;
|
||||
|
||||
namespace PkmnLib.Dynamic.Events;
|
||||
|
||||
/// <summary>
|
||||
/// Event data for when a Pokémon attempts to flee from battle. Indicates which Pokémon attempted to flee and whether the attempt was successful.
|
||||
/// </summary>
|
||||
public class FleeEvent : IEventData
|
||||
{
|
||||
/// <inheritdoc cref="FleeEvent"/>
|
||||
public FleeEvent(IPokemon pokemon, bool success)
|
||||
{
|
||||
Pokemon = pokemon;
|
||||
Success = success;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// The Pokémon that attempted to flee.
|
||||
/// </summary>
|
||||
public IPokemon Pokemon { get; }
|
||||
|
||||
/// <summary>
|
||||
/// Indicates whether the flee attempt was successful.
|
||||
/// </summary>
|
||||
public bool Success { get; }
|
||||
|
||||
/// <inheritdoc />
|
||||
public EventBatchId BatchId { get; init; }
|
||||
}
|
||||
@@ -55,8 +55,8 @@ public class Gen7MiscLibrary : IMiscLibrary
|
||||
var userSide = battle.Sides[battleData.SideIndex];
|
||||
|
||||
userSide.RegisterFleeAttempt();
|
||||
var fleeChance = (userSpeed * 32 / (opponentSpeed / 4) + 30 * userSide.FleeAttempts) / 256;
|
||||
var random = battle.Random.GetInt(0, 100);
|
||||
var fleeChance = userSpeed * 32 / (opponentSpeed / 4) + 30 * userSide.FleeAttempts;
|
||||
var random = battle.Random.GetInt(0, 256);
|
||||
return random < fleeChance;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user