-
Notifications
You must be signed in to change notification settings - Fork 53
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
3 changed files
with
69 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} | ||
|
||
} | ||
} |