Adds optional way to set damage randomness on or off on individual integration tests.
All checks were successful
Build / Build (push) Successful in 49s
All checks were successful
Build / Build (push) Successful in 49s
This commit is contained in:
parent
405a21e887
commit
2680aeff80
@ -31,15 +31,31 @@ public class IntegrationTestRunner
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private static IDynamicLibrary? _libraryWithRandomness;
|
||||||
|
private static IDynamicLibrary? _libraryWithoutRandomness;
|
||||||
|
|
||||||
[Test, MethodDataSource(nameof(TestCases))]
|
[Test, MethodDataSource(nameof(TestCases))]
|
||||||
public async Task RunIntegrationTest(IntegrationTestModel test)
|
public async Task RunIntegrationTest(IntegrationTestModel test)
|
||||||
{
|
{
|
||||||
var library = DynamicLibraryImpl.Create([
|
IDynamicLibrary library;
|
||||||
|
if (test.BattleSetup.HasDamageRandomness)
|
||||||
|
{
|
||||||
|
library = _libraryWithRandomness ??= DynamicLibraryImpl.Create([
|
||||||
new Gen7Plugin(new Gen7PluginConfiguration
|
new Gen7Plugin(new Gen7PluginConfiguration
|
||||||
{
|
{
|
||||||
DamageCalculatorHasRandomness = true,
|
DamageCalculatorHasRandomness = true,
|
||||||
}),
|
}),
|
||||||
]);
|
]);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
library = _libraryWithoutRandomness ??= DynamicLibraryImpl.Create([
|
||||||
|
new Gen7Plugin(new Gen7PluginConfiguration
|
||||||
|
{
|
||||||
|
DamageCalculatorHasRandomness = false,
|
||||||
|
}),
|
||||||
|
]);
|
||||||
|
}
|
||||||
|
|
||||||
await TestContext.Current!.OutputWriter.WriteLineAsync("File: " + $"file://{test.FileName}");
|
await TestContext.Current!.OutputWriter.WriteLineAsync("File: " + $"file://{test.FileName}");
|
||||||
TestContext.Current.AddArtifact(new Artifact
|
TestContext.Current.AddArtifact(new Artifact
|
||||||
|
@ -18,6 +18,7 @@ public class IntegrationTestBattleSetup
|
|||||||
public bool CanFlee { get; set; }
|
public bool CanFlee { get; set; }
|
||||||
public byte NumberOfSides { get; set; }
|
public byte NumberOfSides { get; set; }
|
||||||
public byte PositionsPerSide { get; set; }
|
public byte PositionsPerSide { get; set; }
|
||||||
|
public bool HasDamageRandomness { get; set; }
|
||||||
public IntegrationTestParty[] Parties { get; set; } = null!;
|
public IntegrationTestParty[] Parties { get; set; } = null!;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -6,6 +6,7 @@
|
|||||||
"canFlee": false,
|
"canFlee": false,
|
||||||
"numberOfSides": 2,
|
"numberOfSides": 2,
|
||||||
"positionsPerSide": 1,
|
"positionsPerSide": 1,
|
||||||
|
"hasDamageRandomness": false,
|
||||||
"parties": [
|
"parties": [
|
||||||
{
|
{
|
||||||
"indices": [
|
"indices": [
|
||||||
@ -93,7 +94,7 @@
|
|||||||
{
|
{
|
||||||
"$type": "assert",
|
"$type": "assert",
|
||||||
"value": ".Sides[1].Pokemon[0].CurrentHealth",
|
"value": ".Sides[1].Pokemon[0].CurrentHealth",
|
||||||
"expected": 84
|
"expected": 78
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
}
|
}
|
@ -40,7 +40,10 @@ public class DamageCalculatorTests
|
|||||||
// Ice Fang (an Ice-type physical move with a power of 65)
|
// Ice Fang (an Ice-type physical move with a power of 65)
|
||||||
useMove.Category.Returns(MoveCategory.Physical);
|
useMove.Category.Returns(MoveCategory.Physical);
|
||||||
|
|
||||||
var damageCalculator = new Gen7DamageCalculator(false);
|
var damageCalculator = new Gen7DamageCalculator(new Gen7PluginConfiguration
|
||||||
|
{
|
||||||
|
DamageCalculatorHasRandomness = false,
|
||||||
|
});
|
||||||
var executingMove = Substitute.For<IExecutingMove>();
|
var executingMove = Substitute.For<IExecutingMove>();
|
||||||
executingMove.UseMove.Returns(useMove);
|
executingMove.UseMove.Returns(useMove);
|
||||||
executingMove.User.Returns(attacker);
|
executingMove.User.Returns(attacker);
|
||||||
|
@ -14,12 +14,12 @@ public class Gen7PluginConfiguration : IPluginConfiguration
|
|||||||
/// This should be set to true for most cases, as it simulates the actual damage calculation in the games. Only
|
/// This should be set to true for most cases, as it simulates the actual damage calculation in the games. Only
|
||||||
/// set to false for testing purposes.
|
/// set to false for testing purposes.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public bool DamageCalculatorHasRandomness { get; init; } = true;
|
public bool DamageCalculatorHasRandomness { get; set; } = true;
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// The number of times a species has been caught. This is used for critical capture calculations.
|
/// The number of times a species has been caught. This is used for critical capture calculations.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public Func<ISpecies, int> TimesSpeciesCaught { get; init; } = _ => 0;
|
public Func<ISpecies, int> TimesSpeciesCaught { get; set; } = _ => 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
public class Gen7Plugin : Plugin<Gen7PluginConfiguration>, IResourceProvider
|
public class Gen7Plugin : Plugin<Gen7PluginConfiguration>, IResourceProvider
|
||||||
@ -44,7 +44,7 @@ public class Gen7Plugin : Plugin<Gen7PluginConfiguration>, IResourceProvider
|
|||||||
{
|
{
|
||||||
registry.RegisterAssemblyScripts(typeof(Gen7Plugin).Assembly);
|
registry.RegisterAssemblyScripts(typeof(Gen7Plugin).Assembly);
|
||||||
registry.RegisterBattleStatCalculator(new Gen7BattleStatCalculator());
|
registry.RegisterBattleStatCalculator(new Gen7BattleStatCalculator());
|
||||||
registry.RegisterDamageCalculator(new Gen7DamageCalculator(Configuration.DamageCalculatorHasRandomness));
|
registry.RegisterDamageCalculator(new Gen7DamageCalculator(Configuration));
|
||||||
registry.RegisterMiscLibrary(new Gen7MiscLibrary());
|
registry.RegisterMiscLibrary(new Gen7MiscLibrary());
|
||||||
registry.RegisterCaptureLibrary(new Gen7CaptureLibrary(Configuration));
|
registry.RegisterCaptureLibrary(new Gen7CaptureLibrary(Configuration));
|
||||||
}
|
}
|
||||||
|
@ -3,7 +3,7 @@ using PkmnLib.Static.Moves;
|
|||||||
|
|
||||||
namespace PkmnLib.Plugin.Gen7.Libraries.Battling;
|
namespace PkmnLib.Plugin.Gen7.Libraries.Battling;
|
||||||
|
|
||||||
public class Gen7DamageCalculator(bool hasRandomness) : IDamageCalculator
|
public class Gen7DamageCalculator(Gen7PluginConfiguration configuration) : IDamageCalculator
|
||||||
{
|
{
|
||||||
/// <inheritdoc />
|
/// <inheritdoc />
|
||||||
public uint GetDamage(IExecutingMove executingMove, IPokemon target, byte hitNumber, IHitData hitData)
|
public uint GetDamage(IExecutingMove executingMove, IPokemon target, byte hitNumber, IHitData hitData)
|
||||||
@ -34,7 +34,7 @@ public class Gen7DamageCalculator(bool hasRandomness) : IDamageCalculator
|
|||||||
floatDamage = MathF.Floor(floatDamage * critModifier);
|
floatDamage = MathF.Floor(floatDamage * critModifier);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (hasRandomness)
|
if (configuration.DamageCalculatorHasRandomness)
|
||||||
{
|
{
|
||||||
var battle = target.BattleData?.Battle;
|
var battle = target.BattleData?.Battle;
|
||||||
if (battle == null)
|
if (battle == null)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user