Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implement patrol reward mail #586

Merged
merged 4 commits into from
Jan 31, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions Directory.Build.props
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<Project>
<PropertyGroup>
<Lib9cVersion>1.20.1-dev.e639502afb22df4d230d52002b519b3f8ef16b4f</Lib9cVersion>
<LibplanetVersion>5.4.2</LibplanetVersion>
<Lib9cVersion>1.21.0-dev.fa7c58ff1072e2d81526c4f414c5e54a265f283f</Lib9cVersion>
<LibplanetVersion>5.5.0</LibplanetVersion>
</PropertyGroup>
</Project>
2 changes: 1 addition & 1 deletion Lib9c.Models.Tests/Lib9c.Models.Tests.csproj
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>net6.0</TargetFramework>
<TargetFramework>net8.0</TargetFramework>
<LangVersion>10</LangVersion>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
Expand Down
1 change: 1 addition & 0 deletions Lib9c.Models/Factories/MailFactory.cs
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ public static Mail Create(IValue bencoded)
"sellCancel" => new SellCancelMail(d),
"seller" => new SellerMail(d),
nameof(UnloadFromMyGaragesRecipientMail) => new UnloadFromMyGaragesRecipientMail(d),
nameof(PatrolRewardMail) => new PatrolRewardMail(d),
_ => throw new UnsupportedArgumentValueException<string>("typeId", typeId),
};
}
Expand Down
61 changes: 61 additions & 0 deletions Lib9c.Models/Mails/PatrolRewardMail.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
using Bencodex.Types;
using Lib9c.Models.Exceptions;
using Lib9c.Models.Extensions;
using Libplanet.Types.Assets;
using MongoDB.Bson.Serialization.Attributes;
using ValueKind = Bencodex.Types.ValueKind;

namespace Lib9c.Models.Mails;

/// <summary>
/// <see cref="Nekoyume.Model.Mail.PatrolRewardMail"/>
/// </summary>
[BsonIgnoreExtraElements]
public record PatrolRewardMail : Mail
{
public List<FungibleAssetValue> FungibleAssetValues { get; init; }
public List<(int id, int count)> Items { get; init; }

public override IValue Bencoded
{
get
{
var d = (Dictionary)base.Bencoded;
if (FungibleAssetValues.Count != 0)
{
d = d.SetItem("f", new List(FungibleAssetValues
.Select(f => f.Serialize())));
}

if (Items.Count != 0)
{
d = d.SetItem("i", new List(Items
.Select(tuple => List.Empty.Add(tuple.id).Add(tuple.count))));
}

return d;
}
}

public PatrolRewardMail(IValue bencoded) : base(bencoded)
{
if (bencoded is not Dictionary d)
{
throw new UnsupportedArgumentTypeException<ValueKind>(
nameof(bencoded),
new[] { ValueKind.Dictionary },
bencoded.Kind);
}

FungibleAssetValues = d.ContainsKey("f")
? d["f"].ToList(StateExtensions.ToFungibleAssetValue)
: new List<FungibleAssetValue>();
Items = d.ContainsKey("i")
? d["i"].ToList<(int, int)>(v =>
{
var list = (List)v;
return ((Integer)list[0], (Integer)list[1]);
})
: new List<(int id, int count)>();
}
}
2 changes: 1 addition & 1 deletion Mimir.Worker/Mimir.Worker.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@

<ItemGroup>
<PackageReference Include="Lib9c" Version="$(Lib9cVersion)" />
<PackageReference Include="Lib9c.Abstractions" Version="$(Lib9cVersion)" />
<PackageReference Include="Lib9c.Abstractions" Version="1.20.1-dev.fa7c58ff1072e2d81526c4f414c5e54a265f283f" />
<PackageReference Include="Libplanet.RocksDBStore" Version="$(LibplanetVersion)" />
<PackageReference Include="Libplanet" Version="$(LibplanetVersion)" />
<PackageReference Include="Microsoft.Extensions.Hosting" Version="8.0.0" />
Expand Down
Loading