From c6c2cc34cb444fea08a0f7dffa400ef0ffab864c Mon Sep 17 00:00:00 2001 From: hyeon Date: Thu, 20 Jun 2024 15:18:28 +0900 Subject: [PATCH 1/2] Move all adventure actions to inherit GameAction --- .../AdventureBoss/ClaimAdventureBossReward.cs | 23 +++++++------- .../AdventureBoss/ExploreAdventureBoss.cs | 1 - .../AdventureBoss/SweepAdventureBoss.cs | 16 +++++----- Lib9c/Action/AdventureBoss/UnlockFloor.cs | 29 ++++++++--------- Lib9c/Action/AdventureBoss/Wanted.cs | 31 ++++++++++--------- 5 files changed, 52 insertions(+), 48 deletions(-) diff --git a/Lib9c/Action/AdventureBoss/ClaimAdventureBossReward.cs b/Lib9c/Action/AdventureBoss/ClaimAdventureBossReward.cs index 57fd8de3bc..7f1c90bc75 100644 --- a/Lib9c/Action/AdventureBoss/ClaimAdventureBossReward.cs +++ b/Lib9c/Action/AdventureBoss/ClaimAdventureBossReward.cs @@ -19,25 +19,26 @@ namespace Nekoyume.Action.AdventureBoss { [Serializable] [ActionType(TypeIdentifier)] - public class ClaimAdventureBossReward : ActionBase + public class ClaimAdventureBossReward : GameAction { public const string TypeIdentifier = "claim_adventure_boss_reward"; public long Season; public Address AvatarAddress; - public override IValue PlainValue => Dictionary.Empty - .Add("type_id", TypeIdentifier) - .Add("values", List.Empty - .Add(Season.Serialize()) - .Add(AvatarAddress.Serialize()) - ); + protected override IImmutableDictionary PlainValueInternal => + new Dictionary + { + ["s"] = (Integer)Season, + ["a"] = AvatarAddress.Serialize(), + }.ToImmutableDictionary(); - public override void LoadPlainValue(IValue plainValue) + protected override void LoadPlainValueInternal( + IImmutableDictionary plainValue + ) { - var values = (List)((Dictionary)plainValue)["values"]; - Season = values[0].ToInteger(); - AvatarAddress = values[1].ToAddress(); + Season = (Integer)plainValue["s"]; + AvatarAddress = plainValue["a"].ToAddress(); } public override IWorld Execute(IActionContext context) diff --git a/Lib9c/Action/AdventureBoss/ExploreAdventureBoss.cs b/Lib9c/Action/AdventureBoss/ExploreAdventureBoss.cs index 4cd6cfcf72..f456283312 100644 --- a/Lib9c/Action/AdventureBoss/ExploreAdventureBoss.cs +++ b/Lib9c/Action/AdventureBoss/ExploreAdventureBoss.cs @@ -9,7 +9,6 @@ using Nekoyume.Action.Exceptions.AdventureBoss; using Nekoyume.Battle; using Nekoyume.Battle.AdventureBoss; -using Nekoyume.Data; using Nekoyume.Extensions; using Nekoyume.Helper; using Nekoyume.Model.AdventureBoss; diff --git a/Lib9c/Action/AdventureBoss/SweepAdventureBoss.cs b/Lib9c/Action/AdventureBoss/SweepAdventureBoss.cs index 51fdaa69bc..29ec0debb5 100644 --- a/Lib9c/Action/AdventureBoss/SweepAdventureBoss.cs +++ b/Lib9c/Action/AdventureBoss/SweepAdventureBoss.cs @@ -38,10 +38,10 @@ public class SweepAdventureBoss : GameAction protected override IImmutableDictionary PlainValueInternal => new Dictionary { - ["season"] = (Integer)Season, - ["avatarAddress"] = AvatarAddress.Serialize(), - ["costumes"] = new List(Costumes.OrderBy(i => i).Select(e => e.Serialize())), - ["equipments"] = + ["s"] = (Integer)Season, + ["a"] = AvatarAddress.Serialize(), + ["c"] = new List(Costumes.OrderBy(i => i).Select(e => e.Serialize())), + ["e"] = new List(Equipments.OrderBy(i => i).Select(e => e.Serialize())), ["r"] = RuneInfos.OrderBy(x => x.SlotIndex).Select(x => x.Serialize()) .Serialize(), @@ -50,10 +50,10 @@ public class SweepAdventureBoss : GameAction protected override void LoadPlainValueInternal( IImmutableDictionary plainValue) { - Season = (Integer)plainValue["season"]; - AvatarAddress = plainValue["avatarAddress"].ToAddress(); - Costumes = ((List)plainValue["costumes"]).Select(e => e.ToGuid()).ToList(); - Equipments = ((List)plainValue["equipments"]).Select(e => e.ToGuid()).ToList(); + Season = (Integer)plainValue["s"]; + AvatarAddress = plainValue["a"].ToAddress(); + Costumes = ((List)plainValue["c"]).Select(e => e.ToGuid()).ToList(); + Equipments = ((List)plainValue["e"]).Select(e => e.ToGuid()).ToList(); RuneInfos = plainValue["r"].ToList(x => new RuneSlotInfo((List)x)); } diff --git a/Lib9c/Action/AdventureBoss/UnlockFloor.cs b/Lib9c/Action/AdventureBoss/UnlockFloor.cs index cf53e384b9..50aa32160c 100644 --- a/Lib9c/Action/AdventureBoss/UnlockFloor.cs +++ b/Lib9c/Action/AdventureBoss/UnlockFloor.cs @@ -1,4 +1,6 @@ using System; +using System.Collections.Generic; +using System.Collections.Immutable; using System.Linq; using Bencodex.Types; using Libplanet.Action; @@ -15,7 +17,7 @@ namespace Nekoyume.Action.AdventureBoss { [Serializable] [ActionType(TypeIdentifier)] - public class UnlockFloor : ActionBase + public class UnlockFloor : GameAction { public const string TypeIdentifier = "unlock_floor"; public const int TotalFloor = 20; @@ -25,21 +27,20 @@ public class UnlockFloor : ActionBase public Address AvatarAddress; public bool UseNcg; - public override IValue PlainValue => Dictionary.Empty - .Add("type_id", TypeIdentifier) - .Add("values", - List.Empty - .Add(Season.Serialize()) - .Add(AvatarAddress.Serialize()) - .Add(UseNcg.Serialize()) - ); + protected override IImmutableDictionary PlainValueInternal => + new Dictionary + { + ["s"] = (Integer)Season, + ["a"] = AvatarAddress.Serialize(), + ["u"] = UseNcg.Serialize(), + }.ToImmutableDictionary(); - public override void LoadPlainValue(IValue plainValue) + protected override void LoadPlainValueInternal( + IImmutableDictionary plainValue) { - var list = (List)((Dictionary)plainValue)["values"]; - Season = list[0].ToInteger(); - AvatarAddress = list[1].ToAddress(); - UseNcg = list[2].ToBoolean(); + Season = (Integer)plainValue["s"]; + AvatarAddress = plainValue["a"].ToAddress(); + UseNcg = plainValue["u"].ToBoolean(); } public override IWorld Execute(IActionContext context) diff --git a/Lib9c/Action/AdventureBoss/Wanted.cs b/Lib9c/Action/AdventureBoss/Wanted.cs index 3a37ef2a06..06cfcde6c7 100644 --- a/Lib9c/Action/AdventureBoss/Wanted.cs +++ b/Lib9c/Action/AdventureBoss/Wanted.cs @@ -1,4 +1,6 @@ using System; +using System.Collections.Generic; +using System.Collections.Immutable; using System.Linq; using Bencodex.Types; using Libplanet.Action; @@ -19,7 +21,7 @@ namespace Nekoyume.Action.AdventureBoss { [Serializable] [ActionType(TypeIdentifier)] - public class Wanted : ActionBase + public class Wanted : GameAction { public const string TypeIdentifier = "wanted"; @@ -27,20 +29,21 @@ public class Wanted : ActionBase public FungibleAssetValue Bounty; public Address AvatarAddress; - public override IValue PlainValue => - Dictionary.Empty - .Add("type_id", TypeIdentifier) - .Add("values", List.Empty - .Add(Season.Serialize()) - .Add(Bounty.Serialize()) - .Add(AvatarAddress.Serialize())); - - public override void LoadPlainValue(IValue plainValue) + protected override IImmutableDictionary PlainValueInternal => + new Dictionary + { + ["s"] = (Integer)Season, + ["b"] = Bounty.Serialize(), + ["a"] = AvatarAddress.Serialize() + }.ToImmutableDictionary(); + + protected override void LoadPlainValueInternal( + IImmutableDictionary plainValue + ) { - var list = (List)((Dictionary)plainValue)["values"]; - Season = list[0].ToInteger(); - Bounty = list[1].ToFungibleAssetValue(); - AvatarAddress = list[2].ToAddress(); + Season = (Integer)plainValue["s"]; + Bounty = plainValue["b"].ToFungibleAssetValue(); + AvatarAddress = plainValue["a"].ToAddress(); } public override IWorld Execute(IActionContext context) From 919c431f40ea2b16b59a8fd0a1e042cba4b3606f Mon Sep 17 00:00:00 2001 From: hyeon Date: Thu, 20 Jun 2024 16:35:41 +0900 Subject: [PATCH 2/2] Make all exceptions serializable --- Lib9c/Action/Exceptions/AdventureBoss/AlreadyClaimedException.cs | 1 + Lib9c/Action/Exceptions/AdventureBoss/ClaimExpiredException.cs | 1 + .../Exceptions/AdventureBoss/InsufficientStakingException.cs | 1 + .../AdventureBoss/InvalidAdventureBossSeasonException.cs | 1 + Lib9c/Action/Exceptions/AdventureBoss/InvalidBountyException.cs | 1 + .../AdventureBoss/MaxInvestmentCountExceededException.cs | 1 + Lib9c/Action/Exceptions/AdventureBoss/PreviousBountyException.cs | 1 + .../Action/Exceptions/AdventureBoss/SeasonInProgressException.cs | 1 + 8 files changed, 8 insertions(+) diff --git a/Lib9c/Action/Exceptions/AdventureBoss/AlreadyClaimedException.cs b/Lib9c/Action/Exceptions/AdventureBoss/AlreadyClaimedException.cs index 848ea9c49e..c755526f0d 100644 --- a/Lib9c/Action/Exceptions/AdventureBoss/AlreadyClaimedException.cs +++ b/Lib9c/Action/Exceptions/AdventureBoss/AlreadyClaimedException.cs @@ -2,6 +2,7 @@ namespace Nekoyume.Action.Exceptions.AdventureBoss { + [Serializable] public class AlreadyClaimedException : Exception { public AlreadyClaimedException(string msg) : base(msg) diff --git a/Lib9c/Action/Exceptions/AdventureBoss/ClaimExpiredException.cs b/Lib9c/Action/Exceptions/AdventureBoss/ClaimExpiredException.cs index 22e7c18193..aadabddbca 100644 --- a/Lib9c/Action/Exceptions/AdventureBoss/ClaimExpiredException.cs +++ b/Lib9c/Action/Exceptions/AdventureBoss/ClaimExpiredException.cs @@ -2,6 +2,7 @@ namespace Nekoyume.Action.Exceptions.AdventureBoss { + [Serializable] public class ClaimExpiredException : Exception { public ClaimExpiredException(string msg) : base(msg) diff --git a/Lib9c/Action/Exceptions/AdventureBoss/InsufficientStakingException.cs b/Lib9c/Action/Exceptions/AdventureBoss/InsufficientStakingException.cs index 654f9faf05..3394f4701e 100644 --- a/Lib9c/Action/Exceptions/AdventureBoss/InsufficientStakingException.cs +++ b/Lib9c/Action/Exceptions/AdventureBoss/InsufficientStakingException.cs @@ -2,6 +2,7 @@ namespace Nekoyume.Action.Exceptions.AdventureBoss { + [Serializable] public class InsufficientStakingException : Exception { public InsufficientStakingException(string msg) : base(msg) diff --git a/Lib9c/Action/Exceptions/AdventureBoss/InvalidAdventureBossSeasonException.cs b/Lib9c/Action/Exceptions/AdventureBoss/InvalidAdventureBossSeasonException.cs index 2740ac45f8..76fa857d8d 100644 --- a/Lib9c/Action/Exceptions/AdventureBoss/InvalidAdventureBossSeasonException.cs +++ b/Lib9c/Action/Exceptions/AdventureBoss/InvalidAdventureBossSeasonException.cs @@ -2,6 +2,7 @@ namespace Nekoyume.Action.Exceptions.AdventureBoss { + [Serializable] public class InvalidAdventureBossSeasonException : Exception { diff --git a/Lib9c/Action/Exceptions/AdventureBoss/InvalidBountyException.cs b/Lib9c/Action/Exceptions/AdventureBoss/InvalidBountyException.cs index 08428ff526..d9999f1451 100644 --- a/Lib9c/Action/Exceptions/AdventureBoss/InvalidBountyException.cs +++ b/Lib9c/Action/Exceptions/AdventureBoss/InvalidBountyException.cs @@ -2,6 +2,7 @@ namespace Nekoyume.Action.Exceptions.AdventureBoss { + [Serializable] public class InvalidBountyException : Exception { public InvalidBountyException(string msg) : base(msg) diff --git a/Lib9c/Action/Exceptions/AdventureBoss/MaxInvestmentCountExceededException.cs b/Lib9c/Action/Exceptions/AdventureBoss/MaxInvestmentCountExceededException.cs index 3a1380f7f6..6212609ee8 100644 --- a/Lib9c/Action/Exceptions/AdventureBoss/MaxInvestmentCountExceededException.cs +++ b/Lib9c/Action/Exceptions/AdventureBoss/MaxInvestmentCountExceededException.cs @@ -2,6 +2,7 @@ namespace Nekoyume.Action.Exceptions.AdventureBoss { + [Serializable] public class MaxInvestmentCountExceededException : Exception { public MaxInvestmentCountExceededException(string message) : base(message) diff --git a/Lib9c/Action/Exceptions/AdventureBoss/PreviousBountyException.cs b/Lib9c/Action/Exceptions/AdventureBoss/PreviousBountyException.cs index 6debdf0264..6a030a3069 100644 --- a/Lib9c/Action/Exceptions/AdventureBoss/PreviousBountyException.cs +++ b/Lib9c/Action/Exceptions/AdventureBoss/PreviousBountyException.cs @@ -2,6 +2,7 @@ namespace Nekoyume.Action.Exceptions.AdventureBoss { + [Serializable] public class PreviousBountyException : Exception { public PreviousBountyException(string msg) : base(msg) diff --git a/Lib9c/Action/Exceptions/AdventureBoss/SeasonInProgressException.cs b/Lib9c/Action/Exceptions/AdventureBoss/SeasonInProgressException.cs index 736e77ee43..c93fc06eb6 100644 --- a/Lib9c/Action/Exceptions/AdventureBoss/SeasonInProgressException.cs +++ b/Lib9c/Action/Exceptions/AdventureBoss/SeasonInProgressException.cs @@ -2,6 +2,7 @@ namespace Nekoyume.Action.Exceptions.AdventureBoss { + [Serializable] public class SeasonInProgressException : Exception { public SeasonInProgressException(string msg) : base(msg)