Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/release/1.20.0' into feature/gro…
Browse files Browse the repository at this point in the history
…wth12
  • Loading branch information
eugene-doobu committed Nov 25, 2024
2 parents b5d9d30 + 5946f1f commit 2082a98
Show file tree
Hide file tree
Showing 17 changed files with 200 additions and 142 deletions.
16 changes: 16 additions & 0 deletions .Lib9c.Tests/Action/DamageHelperTest.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
namespace Lib9c.Tests.Action
{
using Xunit;

public class DamageHelperTest
{
[Theory]
[InlineData(long.MaxValue, 0.19)]
[InlineData(4000L, 0.6)]
[InlineData(long.MinValue, 0)]
public void GetDamageReductionRate(long drr, decimal expected)
{
Assert.Equal(expected, Nekoyume.Battle.DamageHelper.GetDamageReductionRate(drr));
}
}
}
114 changes: 30 additions & 84 deletions .Lib9c.Tests/Action/Guild/Migration/FixToRefundFromNonValidatorTest.cs
Original file line number Diff line number Diff line change
@@ -1,135 +1,81 @@
namespace Lib9c.Tests.Action.Guild.Migration
{
using System;
using System.Collections.Generic;
using Lib9c.Tests.Fixtures.TableCSV.Stake;
using Lib9c.Tests.Util;
using System.Linq;
using Libplanet.Action.State;
using Libplanet.Crypto;
using Libplanet.Types.Assets;
using Nekoyume;
using Nekoyume.Action;
using Nekoyume.Action.Guild.Migration;
using Nekoyume.Extensions;
using Nekoyume.Model.Stake;
using Nekoyume.Model.State;
using Nekoyume.Module;
using Nekoyume.TableData.Stake;
using Xunit;

// TODO: Remove this test class after the migration is completed.
public class FixToRefundFromNonValidatorTest : GuildTestBase
{
private IWorld _world;
private Currency _ncg;
private Currency _gg;
private Address _agentAddress;
private Address _stakeAddress;
private Address _adminAddress;

public FixToRefundFromNonValidatorTest()
{
_agentAddress = new PrivateKey().Address;
_adminAddress = new PrivateKey().Address;
_stakeAddress = StakeState.DeriveAddress(_agentAddress);
_ncg = World.GetGoldCurrency();
_gg = Currencies.GuildGold;
var sheetsOverride = new Dictionary<string, string>
{
{
"StakeRegularFixedRewardSheet_V1",
StakeRegularFixedRewardSheetFixtures.V1
},
{
"StakeRegularFixedRewardSheet_V2",
StakeRegularFixedRewardSheetFixtures.V2
},
{
"StakeRegularRewardSheet_V1",
StakeRegularRewardSheetFixtures.V1
},
{
"StakeRegularRewardSheet_V2",
StakeRegularRewardSheetFixtures.V2
},
{
nameof(StakePolicySheet),
StakePolicySheetFixtures.V2
},
};
(_, _, _, _world) = InitializeUtil.InitializeStates(
agentAddr: _agentAddress,
sheetsOverride: sheetsOverride);
var stakePolicySheet = _world.GetSheet<StakePolicySheet>();
var contract = new Contract(stakePolicySheet);
var adminState = new AdminState(_adminAddress, 100L);
var stakeState = new StakeState(new Contract(stakePolicySheet), 1L);

_world = World
.SetLegacyState(Addresses.Admin, adminState.Serialize())
.SetLegacyState(_stakeAddress, stakeState.Serialize())
.MintAsset(new ActionContext { }, Addresses.NonValidatorDelegatee, _gg * 10000)
.MintAsset(new ActionContext { }, _stakeAddress, _ncg * 10)
.MintAsset(new ActionContext { }, _stakeAddress, _gg * 5);
.MintAsset(new ActionContext { }, Addresses.NonValidatorDelegatee, Currencies.GuildGold * 500);
}

[Fact]
public void PlainValue()
{
var targets = Enumerable.Range(0, 5).Select(i => (new PrivateKey().Address, (i + 1) * 10)).ToList();
var plainValue = new FixToRefundFromNonValidator(targets).PlainValue;

var recon = new FixToRefundFromNonValidator();
recon.LoadPlainValue(plainValue);
Assert.Equal(targets, recon.Targets);
}

[Fact]
public void Execute()
{
var world = new FixToRefundFromNonValidator(new Address[] { _agentAddress }).Execute(new ActionContext
var targets = Enumerable.Range(0, 5).Select(i => (new PrivateKey().Address, (i + 1) * 10)).ToList();

var world = new FixToRefundFromNonValidator(targets).Execute(new ActionContext
{
PreviousState = _world,
Signer = _adminAddress,
BlockIndex = 2L,
});

Assert.Equal(_gg * 10, world.GetBalance(_stakeAddress, _gg));
Assert.Equal(_gg * (10000 - 5), world.GetBalance(Addresses.NonValidatorDelegatee, _gg));
foreach (var item in targets)
{
Assert.Equal(
Currencies.GuildGold * item.Item2,
world.GetBalance(StakeState.DeriveAddress(item.Item1), Currencies.GuildGold));
}

Assert.Equal(
Currencies.GuildGold * (500 - targets.Select(t => t.Item2).Sum()),
world.GetBalance(Addresses.NonValidatorDelegatee, Currencies.GuildGold));
}

[Fact]
public void AssertWhenExecutedByNonAdmin()
{
var targets = Enumerable.Range(0, 5).Select(i => (new PrivateKey().Address, (i + 1) * 10)).ToList();

Assert.Throws<PermissionDeniedException>(() =>
{
new FixToRefundFromNonValidator(new Address[] { _agentAddress }).Execute(new ActionContext
new FixToRefundFromNonValidator(targets).Execute(new ActionContext
{
PreviousState = _world,
Signer = new PrivateKey().Address,
BlockIndex = 2L,
});
});
}

[Fact]
public void AssertWhenHasSufficientGG()
{
var world = _world
.MintAsset(new ActionContext { }, _stakeAddress, _gg * 5);
Assert.Throws<InvalidOperationException>(() =>
{
new FixToRefundFromNonValidator(new Address[] { _agentAddress }).Execute(new ActionContext
{
PreviousState = world,
Signer = _adminAddress,
BlockIndex = 2L,
});
});
}

[Fact]
public void AssertWhenLegacyStakeState()
{
var stakeState = new LegacyStakeState(_stakeAddress, 0L);
var world = _world.SetLegacyState(_stakeAddress, stakeState.Serialize());
Assert.Throws<InvalidOperationException>(() =>
{
new FixToRefundFromNonValidator(new Address[] { _agentAddress }).Execute(new ActionContext
{
PreviousState = World,
Signer = _adminAddress,
BlockIndex = 2L,
});
});
}
}
}
39 changes: 35 additions & 4 deletions .Lib9c.Tests/Model/CharacterStatsTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ public CharacterStatsTest()
}

[Fact]
public void DeBuffLimit()
public void DeBuffLimitPercentage()
{
var stats =
new CharacterStats(
Expand All @@ -26,7 +26,7 @@ public void DeBuffLimit()
// -100% def but limit -50% stats
var deBuff = new StatBuff(_tableSheets.StatBuffSheet[503012]);
var groupId = deBuff.RowData.GroupId;
buffLimitSheet.Set($"group_id,percentage\n{groupId},-50");
buffLimitSheet.Set($"group_id,percentage\n{groupId},Percentage,-50");
var def = stats.DEF;
stats.AddBuff(deBuff, buffLimitSheet);
var modifier = buffLimitSheet[groupId].GetModifier(deBuff.RowData.StatType);
Expand All @@ -40,7 +40,7 @@ public void DeBuffLimit()
}

[Fact]
public void BuffLimit()
public void BuffLimitPercentage()
{
var stats =
new CharacterStats(
Expand All @@ -58,11 +58,42 @@ public void BuffLimit()
stats.RemoveBuff(buff);
Assert.Equal(atk, stats.ATK);
// +60% atk but limit 50% stats
buffLimitSheet.Set($"group_id,percentage\n{groupId},50");
buffLimitSheet.Set($"group_id,modify_type,percentage\n{groupId},Percentage,50");
var modifier = buffLimitSheet[groupId].GetModifier(buff.RowData.StatType);
stats.AddBuff(buff, buffLimitSheet);
Assert.Equal(atk * 1.5m, modifier.GetModifiedAll(atk));
Assert.Equal(atk * 1.5m, stats.ATK);
}

[Fact]
public void BuffLimitAdd()
{
const long buffDrrValue = 80;
const long buffLimitValue = 50;

var stats =
new CharacterStats(
_tableSheets.CharacterSheet[GameConfig.DefaultAvatarCharacterId],
1);
var statBuffSheet = new StatBuffSheet();
statBuffSheet.Set($"id,group,_name,chance,duration,target_type,stat_type,modify_type,modify_value,is_enhanceable,max_stack\n702001,702001,DRR (커스텀 장비),100,12,Self,DRR,Add,{buffDrrValue},true,");
var buffLimitSheet = new BuffLimitSheet();
// +80 drr with no limit
var buff = new StatBuff(statBuffSheet[702001]);
var groupId = buff.RowData.GroupId;
var drr = stats.DRR;
stats.AddBuff(buff, buffLimitSheet);
Assert.Equal(drr + buffDrrValue, stats.DRR);

// reset stats
stats.RemoveBuff(buff);
Assert.Equal(drr, stats.DRR);
// +80 drr but limit 50 stats
buffLimitSheet.Set($"group_id,modify_type,percentage\n{groupId},Add,{buffLimitValue}");
var modifier = buffLimitSheet[groupId].GetModifier(buff.RowData.StatType);
stats.AddBuff(buff, buffLimitSheet);
Assert.Equal(drr + buffLimitValue, modifier.GetModifiedAll(drr));
Assert.Equal(drr + buffLimitValue, stats.DRR);
}
}
}
3 changes: 2 additions & 1 deletion .Lib9c.Tests/Model/Skill/Adventure/CombatTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,8 @@ public CombatTest()
[InlineData(10, 10, 5000, 120, 50)]
[InlineData(0, 1000, 0, 999, 1)]
[InlineData(1000, 0, 0, 999, 1)]
[InlineData(0, 0, 10000, int.MaxValue, 1)]
[InlineData(0, 0, 10000, 300, 57)]
[InlineData(0, 0, 10000, int.MaxValue, 300)]
public void CalculateDEFAndDamageReduction(int def, int drv, int drr, int enemyATK, int expectedDamage)
{
_player.Stats.SetStatForTest(StatType.DEF, def);
Expand Down
47 changes: 47 additions & 0 deletions .Lib9c.Tests/Model/Skill/Arena/ArenaCombatTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -269,5 +269,52 @@ public void DispelOnDuration_Nothing()
Assert.True(battleStatus.SkillInfos.First().Affected);
Assert.Contains(600001, challenger.Buffs.Values.Select(bf => bf.BuffInfo.Id));
}

[Fact]
public void Drr()
{
var arenaSheets = _tableSheets.GetArenaSimulatorSheets();
var myDigest = new ArenaPlayerDigest(_avatar1, _arenaAvatar1);
var enemyDigest = new ArenaPlayerDigest(_avatar2, _arenaAvatar2);
var simulator = new ArenaSimulator(new TestRandom());
var challenger = new ArenaCharacter(
simulator,
myDigest,
arenaSheets,
simulator.HpModifier,
new List<StatModifier>()
);
var enemy = new ArenaCharacter(
simulator,
enemyDigest,
arenaSheets,
simulator.HpModifier,
new List<StatModifier>()
);
var statBuffRow = new Nekoyume.TableData.StatBuffSheet.Row();
var csv = $"101000,101000,20,10,Self,DRR,Add,{int.MaxValue},true";
statBuffRow.Set(csv.Split(","));
var buff = new StatBuff(statBuffRow);
enemy.AddBuff(buff);
Assert.True(enemy.DRR > 1000000);
var attackRow =
_tableSheets.SkillSheet.Values.First(bf => bf.Id == 100000);
var attack = new ArenaNormalAttack(attackRow, 100, 100, 0, StatType.NONE);
var arenaSkill = attack.Use(
challenger,
enemy,
simulator.Turn,
BuffFactory.GetBuffs(
challenger.Stats,
attack,
_tableSheets.SkillBuffSheet,
_tableSheets.StatBuffSheet,
_tableSheets.SkillActionBuffSheet,
_tableSheets.ActionBuffSheet
)
);
var info = arenaSkill.SkillInfos.Single();
Assert.True(info.Effect > 1);
}
}
}
1 change: 1 addition & 0 deletions .github/workflows/publish.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ on:
branches:
- development
- main
- release/*
tags:
- "*.*.*"

Expand Down
2 changes: 1 addition & 1 deletion Lib9c.Abstractions/Lib9c.Abstractions.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
<IntermediateOutputPath>.obj</IntermediateOutputPath>
<LangVersion>9</LangVersion>
<CodeAnalysisRuleSet>..\Lib9c.Common.ruleset</CodeAnalysisRuleSet>
<VersionPrefix>1.19.0</VersionPrefix>
<VersionPrefix>1.20.0</VersionPrefix>
</PropertyGroup>

<ItemGroup Condition="!'$(UseLocalLibplanet)'">
Expand Down
2 changes: 1 addition & 1 deletion Lib9c.MessagePack/Lib9c.MessagePack.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
<Platforms>AnyCPU</Platforms>
<OutputPath>.bin</OutputPath>
<IntermediateOutputPath>.obj</IntermediateOutputPath>
<VersionPrefix>1.19.0</VersionPrefix>
<VersionPrefix>1.20.0</VersionPrefix>
</PropertyGroup>

<ItemGroup>
Expand Down
2 changes: 1 addition & 1 deletion Lib9c.Renderers/Lib9c.Renderers.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
<Nullable>enable</Nullable>
<OutputPath>.bin</OutputPath>
<IntermediateOutputPath>.obj</IntermediateOutputPath>
<VersionPrefix>1.19.0</VersionPrefix>
<VersionPrefix>1.20.0</VersionPrefix>
<RootNamespace>Lib9c</RootNamespace>
</PropertyGroup>

Expand Down
6 changes: 3 additions & 3 deletions Lib9c/Action/AdventureBoss/ExploreAdventureBoss.cs
Original file line number Diff line number Diff line change
Expand Up @@ -251,8 +251,8 @@ public override IWorld Execute(IActionContext context)
for (var fl = explorer.Floor + 1; fl < explorer.MaxFloor + 1; fl++)
{
// Get Data for simulator
var floorRow = floorRows.First(row => row.Floor == fl);
if (!floorSheet.TryGetValue(fl, out var flRow))
var floorRow = floorRows.FirstOrDefault(row => row.Floor == fl);
if (floorRow == null)
{
throw new SheetRowNotFoundException(addressesHex, nameof(floorSheet), fl);
}
Expand All @@ -263,7 +263,7 @@ public override IWorld Execute(IActionContext context)
}

var rewards =
AdventureBossSimulator.GetWaveRewards(random, flRow, materialItemSheet);
AdventureBossSimulator.GetWaveRewards(random, floorRow, materialItemSheet);

// Use AP Potion
if (!avatarState.inventory.RemoveFungibleItem(material.ItemId, context.BlockIndex,
Expand Down
Loading

0 comments on commit 2082a98

Please sign in to comment.