Skip to content

Commit

Permalink
Merge pull request #586 from ipdae/feature/implement-patrol-reward-mail
Browse files Browse the repository at this point in the history
Implement patrol reward mail
  • Loading branch information
ipdae authored Jan 31, 2025
2 parents e228078 + 9439374 commit 6fdbff3
Show file tree
Hide file tree
Showing 5 changed files with 66 additions and 4 deletions.
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

0 comments on commit 6fdbff3

Please sign in to comment.