Skip to content

Commit

Permalink
Fix decimal point case
Browse files Browse the repository at this point in the history
  • Loading branch information
ipdae committed Jul 14, 2023
1 parent cd81e23 commit 6488222
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 1 deletion.
34 changes: 34 additions & 0 deletions .Lib9c.Tests/Action/HitHelperTest.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
namespace Lib9c.Tests.Action
{
using System;
using Nekoyume.Battle;
using Xunit;

public class HitHelperTest
{
[Fact]
public void GetHitStep2()
{
// copy from previous logic
int GetHitStep2Legacy(int attackerHit, int defenderHit)
{
attackerHit = Math.Max(1, attackerHit);
defenderHit = Math.Max(1, defenderHit);
var additionalCorrection = (int)((attackerHit - defenderHit / 3m) / defenderHit * 100);
return Math.Min(
Math.Max(additionalCorrection, HitHelper.GetHitStep2AdditionalCorrectionMin),
HitHelper.GetHitStep2AdditionalCorrectionMax);
}

for (int i = 0; i < 9; i++)
{
for (int j = 0; j < 9; j++)
{
var legacy = GetHitStep2Legacy(i, j);
var current = HitHelper.GetHitStep2(i, j);
Assert.True(legacy == current, $"{i}, {j}, {legacy}, {current}");
}
}
}
}
}
2 changes: 1 addition & 1 deletion Lib9c/Battle/HitHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ public static int GetHitStep2(int attackerHit, int defenderHit)
{
attackerHit = Math.Max(1, attackerHit);
defenderHit = Math.Max(1, defenderHit);
var additionalCorrection = (attackerHit * 100 - defenderHit * 100 / 3) / defenderHit;
var additionalCorrection = (attackerHit * 10000 - defenderHit * 10000 / 3) / defenderHit / 100;
return Math.Min(Math.Max(additionalCorrection, GetHitStep2AdditionalCorrectionMin),
GetHitStep2AdditionalCorrectionMax);
}
Expand Down

0 comments on commit 6488222

Please sign in to comment.