Style cleanup
This commit is contained in:
@@ -44,21 +44,24 @@ public class Gen7BattleStatCalculator : IBattleStatCalculator
|
||||
var flatStat = CalculateFlatStat(pokemon, stat);
|
||||
var boostModifier = GetStatBoostModifier(pokemon, stat);
|
||||
var boostedStat = flatStat * boostModifier;
|
||||
if (boostedStat > uint.MaxValue) boostedStat = uint.MaxValue;
|
||||
if (boostedStat > uint.MaxValue)
|
||||
boostedStat = uint.MaxValue;
|
||||
return (uint)boostedStat;
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
public byte CalculateModifiedAccuracy(IExecutingMove executingMove, IPokemon target, byte hitIndex, byte moveAccuracy)
|
||||
public byte CalculateModifiedAccuracy(IExecutingMove executingMove, IPokemon target, byte hitIndex,
|
||||
byte moveAccuracy)
|
||||
{
|
||||
var accuracyModifier = 1.0f;
|
||||
executingMove.RunScriptHook(x => x.ChangeAccuracyModifier(executingMove, target, hitIndex, ref accuracyModifier));
|
||||
executingMove.RunScriptHook(
|
||||
x => x.ChangeAccuracyModifier(executingMove, target, hitIndex, ref accuracyModifier));
|
||||
var modifiedAccuracy = (int)(moveAccuracy * accuracyModifier);
|
||||
executingMove.RunScriptHook(x => x.ChangeAccuracy(executingMove, target, hitIndex, ref modifiedAccuracy));
|
||||
var targetEvasion = target.StatBoost.Evasion;
|
||||
var ignoreEvasion = false;
|
||||
executingMove.RunScriptHook(x => x.BypassEvasionStatBoosts(executingMove, target, hitIndex, ref ignoreEvasion));
|
||||
if (ignoreEvasion)
|
||||
if (ignoreEvasion)
|
||||
targetEvasion = 0;
|
||||
var userAccuracy = executingMove.User.StatBoost.Accuracy;
|
||||
var difference = targetEvasion - userAccuracy;
|
||||
@@ -66,14 +69,14 @@ public class Gen7BattleStatCalculator : IBattleStatCalculator
|
||||
{
|
||||
> 0 => 3.0f / (3.0f + Math.Min(difference, 6)),
|
||||
< 0 => 3.0f + -Math.Max(difference, -6) / 3.0f,
|
||||
_ => 1.0f
|
||||
_ => 1.0f,
|
||||
};
|
||||
modifiedAccuracy = (int)(modifiedAccuracy * statModifier);
|
||||
modifiedAccuracy = modifiedAccuracy switch
|
||||
{
|
||||
> 255 => 255,
|
||||
< 0 => 0,
|
||||
_ => modifiedAccuracy
|
||||
_ => modifiedAccuracy,
|
||||
};
|
||||
// NOTE: the main games also consider friendship here, but we don't yet have the concept of a "player Pokémon"
|
||||
// in the battle system, so for now we're just ignoring that.
|
||||
@@ -86,8 +89,9 @@ public class Gen7BattleStatCalculator : IBattleStatCalculator
|
||||
var iv = (ulong)pokemon.IndividualValues.Hp;
|
||||
var ev = (ulong)pokemon.EffortValues.Hp;
|
||||
var level = (ulong)pokemon.Level;
|
||||
var health = (((2 * baseValue + iv + (ev / 4)) * level) / 100) + level + 10;
|
||||
if (health > uint.MaxValue) health = uint.MaxValue;
|
||||
var health = (2 * baseValue + iv + ev / 4) * level / 100 + level + 10;
|
||||
if (health > uint.MaxValue)
|
||||
health = uint.MaxValue;
|
||||
return (uint)health;
|
||||
}
|
||||
|
||||
@@ -97,10 +101,11 @@ public class Gen7BattleStatCalculator : IBattleStatCalculator
|
||||
var iv = (ulong)pokemon.IndividualValues.GetStatistic(statistic);
|
||||
var ev = (ulong)pokemon.EffortValues.GetStatistic(statistic);
|
||||
var level = (ulong)pokemon.Level;
|
||||
var unmodified = (((2 * baseValue + iv + (ev / 4)) * level) / 100) + 5;
|
||||
var unmodified = (2 * baseValue + iv + ev / 4) * level / 100 + 5;
|
||||
var natureModifier = pokemon.Nature.GetStatModifier(statistic);
|
||||
var modified = (unmodified * natureModifier);
|
||||
if (modified > uint.MaxValue) modified = uint.MaxValue;
|
||||
var modified = unmodified * natureModifier;
|
||||
if (modified > uint.MaxValue)
|
||||
modified = uint.MaxValue;
|
||||
return (uint)modified;
|
||||
}
|
||||
|
||||
@@ -122,7 +127,7 @@ public class Gen7BattleStatCalculator : IBattleStatCalculator
|
||||
4 => 6.0f / 2.0f,
|
||||
5 => 7.0f / 2.0f,
|
||||
6 => 8.0f / 2.0f,
|
||||
_ => throw new System.ArgumentException("Stat boost was out of expected range of -6 to 6"),
|
||||
_ => throw new ArgumentException("Stat boost was out of expected range of -6 to 6"),
|
||||
};
|
||||
}
|
||||
}
|
||||
@@ -23,11 +23,10 @@ public class Gen7CaptureLibrary : ICaptureLibrary
|
||||
byte bonusStatus = 1;
|
||||
target.RunScriptHook(x => x.ChangeCatchRateBonus(target, captureItem, ref bonusStatus));
|
||||
|
||||
var modifiedCatchRate =
|
||||
(((3.0 * maxHealth) - (2.0 * currentHealth)) * catchRate * bonusBall) / (3.0 * maxHealth);
|
||||
var modifiedCatchRate = (3.0 * maxHealth - 2.0 * currentHealth) * catchRate * bonusBall / (3.0 * maxHealth);
|
||||
modifiedCatchRate *= bonusStatus;
|
||||
|
||||
var shakeProbability = 65536 / Math.Pow((255 / modifiedCatchRate), 0.1875);
|
||||
|
||||
var shakeProbability = 65536 / Math.Pow(255 / modifiedCatchRate, 0.1875);
|
||||
byte shakes = 0;
|
||||
if (modifiedCatchRate >= 255)
|
||||
{
|
||||
|
||||
@@ -17,7 +17,7 @@ public class Gen7DamageCalculator(bool hasRandomness) : IDamageCalculator
|
||||
if (hitData.Effectiveness == 0)
|
||||
return 0;
|
||||
|
||||
var levelModifier = (2.0f * executingMove.User.Level) / 5.0f + 2.0f;
|
||||
var levelModifier = 2.0f * executingMove.User.Level / 5.0f + 2.0f;
|
||||
var basePower = (float)hitData.BasePower;
|
||||
var statModifier = GetStatModifier(executingMove, target, hitNumber, hitData);
|
||||
var damageModifier = GetDamageModifier(executingMove, target, hitNumber);
|
||||
@@ -62,10 +62,8 @@ public class Gen7DamageCalculator(bool hasRandomness) : IDamageCalculator
|
||||
< 1 => 1,
|
||||
_ => (uint)floatDamage,
|
||||
};
|
||||
executingMove.RunScriptHook(script =>
|
||||
script.ChangeMoveDamage(executingMove, target, hitNumber, ref damage));
|
||||
target.RunScriptHook(script =>
|
||||
script.ChangeIncomingMoveDamage(executingMove, target, hitNumber, ref damage));
|
||||
executingMove.RunScriptHook(script => script.ChangeMoveDamage(executingMove, target, hitNumber, ref damage));
|
||||
target.RunScriptHook(script => script.ChangeIncomingMoveDamage(executingMove, target, hitNumber, ref damage));
|
||||
|
||||
return damage;
|
||||
}
|
||||
@@ -76,8 +74,7 @@ public class Gen7DamageCalculator(bool hasRandomness) : IDamageCalculator
|
||||
if (executingMove.UseMove.Category == MoveCategory.Status)
|
||||
return 0;
|
||||
var basePower = executingMove.UseMove.BasePower;
|
||||
executingMove.RunScriptHook(script =>
|
||||
script.ChangeBasePower(executingMove, target, hitNumber, ref basePower));
|
||||
executingMove.RunScriptHook(script => script.ChangeBasePower(executingMove, target, hitNumber, ref basePower));
|
||||
return basePower;
|
||||
}
|
||||
|
||||
@@ -100,7 +97,8 @@ public class Gen7DamageCalculator(bool hasRandomness) : IDamageCalculator
|
||||
};
|
||||
}
|
||||
|
||||
private static float GetStatModifier(IExecutingMove executingMove, IPokemon target, byte hitNumber, IHitData hitData)
|
||||
private static float GetStatModifier(IExecutingMove executingMove, IPokemon target, byte hitNumber,
|
||||
IHitData hitData)
|
||||
{
|
||||
var category = executingMove.UseMove.Category;
|
||||
if (category == MoveCategory.Status)
|
||||
@@ -135,7 +133,7 @@ public class Gen7DamageCalculator(bool hasRandomness) : IDamageCalculator
|
||||
if (bypassDefense)
|
||||
targetStats = target.FlatStats;
|
||||
var defensiveStat = targetStats.GetStatistic(defensive);
|
||||
|
||||
|
||||
executingMove.RunScriptHook(script =>
|
||||
script.ChangeOffensiveStatValue(executingMove, target, hitNumber, ref offensiveStat));
|
||||
executingMove.RunScriptHook(script =>
|
||||
|
||||
@@ -11,14 +11,12 @@ namespace PkmnLib.Plugin.Gen7.Libraries;
|
||||
public class Gen7MiscLibrary : IMiscLibrary
|
||||
{
|
||||
private readonly IMoveData _struggleData = new MoveDataImpl("struggle", new TypeIdentifier(0),
|
||||
MoveCategory.Physical, 50,
|
||||
255, 255, MoveTarget.Any, 0,
|
||||
MoveCategory.Physical, 50, 255, 255, MoveTarget.Any, 0,
|
||||
new SecondaryEffectImpl(-1, "struggle", new Dictionary<StringKey, object?>()), []);
|
||||
|
||||
/// <inheritdoc />
|
||||
public ITurnChoice ReplacementChoice(IPokemon user, byte targetSide, byte targetPosition) =>
|
||||
new MoveChoice(user, new LearnedMoveImpl(_struggleData, MoveLearnMethod.Unknown), targetSide,
|
||||
targetPosition);
|
||||
new MoveChoice(user, new LearnedMoveImpl(_struggleData, MoveLearnMethod.Unknown), targetSide, targetPosition);
|
||||
|
||||
/// <inheritdoc />
|
||||
public TimeOfDay GetTimeOfDay()
|
||||
@@ -46,18 +44,18 @@ public class Gen7MiscLibrary : IMiscLibrary
|
||||
var opponent = opponentSide.Pokemon.FirstOrDefault(x => x is not null);
|
||||
if (opponent == null)
|
||||
return true;
|
||||
|
||||
|
||||
var userSpeed = user.FlatStats.Speed;
|
||||
var opponentSpeed = opponent.FlatStats.Speed;
|
||||
// If the player's active Pokémon's Speed is greater than or equal to the wild Pokémon's Speed, fleeing will
|
||||
// always succeed
|
||||
if (userSpeed >= opponentSpeed)
|
||||
return true;
|
||||
|
||||
|
||||
var userSide = battle.Sides[battleData.SideIndex];
|
||||
|
||||
|
||||
userSide.RegisterFleeAttempt();
|
||||
var fleeChance = ((userSpeed * 32) / (opponentSpeed / 4) + (30 * userSide.FleeAttempts)) / 256;
|
||||
var fleeChance = (userSpeed * 32 / (opponentSpeed / 4) + 30 * userSide.FleeAttempts) / 256;
|
||||
var random = battle.Random.GetInt(0, 100);
|
||||
return random < fleeChance;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user