Skip to content

Commit

Permalink
Introduce PatrolRewardMail
Browse files Browse the repository at this point in the history
  • Loading branch information
ipdae committed Dec 13, 2024
1 parent 50d51c9 commit d037b26
Show file tree
Hide file tree
Showing 3 changed files with 69 additions and 0 deletions.
1 change: 1 addition & 0 deletions Lib9c/Model/Mail/IMail.cs
Original file line number Diff line number Diff line change
Expand Up @@ -22,5 +22,6 @@ public interface IMail
void Read(ClaimItemsMail claimItemsMail);
void Read(AdventureBossRaffleWinnerMail adventureBossRaffleWinnerMail);
void Read(CustomCraftMail customCraftMail);
void Read(PatrolRewardMail patrolRewardMail);
}
}
1 change: 1 addition & 0 deletions Lib9c/Model/Mail/Mail.cs
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ public abstract class Mail : IState
[nameof(ClaimItemsMail)] = d => new ClaimItemsMail(d),
[nameof(AdventureBossRaffleWinnerMail)] = d => new AdventureBossRaffleWinnerMail(d),
[nameof(CustomCraftMail)] = d => new CustomCraftMail(d),
[nameof(PatrolRewardMail)] = d => new PatrolRewardMail(d),
};

public Guid id;
Expand Down
67 changes: 67 additions & 0 deletions Lib9c/Model/Mail/PatrolRewardMail.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
using System;
using System.Collections.Generic;
using System.Linq;
using Bencodex.Types;
using Libplanet.Types.Assets;
using Nekoyume.Model.State;

namespace Nekoyume.Model.Mail
{
public class PatrolRewardMail : Mail
{
public override MailType MailType => MailType.Auction;

public List<FungibleAssetValue> FungibleAssetValues = new ();
public List<(int id, int count)> Items = new ();

public PatrolRewardMail(long blockIndex, Guid id, long requiredBlockIndex,
List<FungibleAssetValue> fungibleAssetValues, List<(int id, int count)> items)
: base(blockIndex, id, requiredBlockIndex)
{
FungibleAssetValues = fungibleAssetValues;
Items = items;
}

public PatrolRewardMail(Dictionary serialized) : base(serialized)
{
if (serialized.ContainsKey("f"))
{
FungibleAssetValues = serialized["f"].ToList(StateExtensions.ToFungibleAssetValue);
}

if (serialized.ContainsKey("i"))
{
Items = serialized["i"].ToList<(int, int)>(v =>
{
var list = (List) v;
return ((Integer)list[0], (Integer)list[1]);
});
}
}

public override void Read(IMail mail)
{
mail.Read(this);
}

protected override string TypeId => nameof(PatrolRewardMail);

public override IValue Serialize()
{
var dict = (Dictionary)base.Serialize();
if (FungibleAssetValues.Any())
{
dict = dict.SetItem("f", new List(FungibleAssetValues.Select(f => f.Serialize())));
}

if (Items.Any())
{
dict = dict.SetItem("i",
new List(Items.Select(tuple => List.Empty.Add(tuple.id).Add(tuple.count))));
}

return dict;
}

}
}

0 comments on commit d037b26

Please sign in to comment.