This commit is contained in:
@@ -162,10 +162,14 @@ public static class TurnRunner
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (!battle.Library.MiscLibrary.CanFlee(battle, fleeChoice))
|
if (!battle.Library.MiscLibrary.CanFlee(battle, fleeChoice))
|
||||||
|
{
|
||||||
|
battle.EventHook.Invoke(new FleeEvent(user, false));
|
||||||
return;
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
var userSide = battle.Sides[battleData.SideIndex];
|
var userSide = battle.Sides[battleData.SideIndex];
|
||||||
userSide.MarkAsFled();
|
userSide.MarkAsFled();
|
||||||
|
battle.EventHook.Invoke(new FleeEvent(user, true));
|
||||||
battle.ValidateBattleState();
|
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];
|
var userSide = battle.Sides[battleData.SideIndex];
|
||||||
|
|
||||||
userSide.RegisterFleeAttempt();
|
userSide.RegisterFleeAttempt();
|
||||||
var fleeChance = (userSpeed * 32 / (opponentSpeed / 4) + 30 * userSide.FleeAttempts) / 256;
|
var fleeChance = userSpeed * 32 / (opponentSpeed / 4) + 30 * userSide.FleeAttempts;
|
||||||
var random = battle.Random.GetInt(0, 100);
|
var random = battle.Random.GetInt(0, 256);
|
||||||
return random < fleeChance;
|
return random < fleeChance;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Reference in New Issue
Block a user