Fix flee odds being incorrect
All checks were successful
Build / Build (push) Successful in 57s

This commit is contained in:
2025-11-08 10:32:29 +01:00
parent 90eaeb1a72
commit fa05cdd773
3 changed files with 35 additions and 2 deletions

View File

@@ -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();
}

View 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; }
}

View File

@@ -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;
}
}