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

Move all adventure actions to inherit GameAction #2642

Merged
merged 3 commits into from
Jun 20, 2024
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
23 changes: 12 additions & 11 deletions Lib9c/Action/AdventureBoss/ClaimAdventureBossReward.cs
Original file line number Diff line number Diff line change
Expand Up @@ -20,25 +20,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<string, IValue> PlainValueInternal =>
new Dictionary<string, IValue>
{
["s"] = (Integer)Season,
["a"] = AvatarAddress.Serialize(),
}.ToImmutableDictionary();

public override void LoadPlainValue(IValue plainValue)
protected override void LoadPlainValueInternal(
IImmutableDictionary<string, IValue> 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)
Expand Down
16 changes: 8 additions & 8 deletions Lib9c/Action/AdventureBoss/SweepAdventureBoss.cs
Original file line number Diff line number Diff line change
Expand Up @@ -39,10 +39,10 @@ public class SweepAdventureBoss : GameAction
protected override IImmutableDictionary<string, IValue> PlainValueInternal =>
new Dictionary<string, IValue>
{
["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(),
Expand All @@ -51,10 +51,10 @@ public class SweepAdventureBoss : GameAction
protected override void LoadPlainValueInternal(
IImmutableDictionary<string, IValue> 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));
}

Expand Down
29 changes: 15 additions & 14 deletions Lib9c/Action/AdventureBoss/UnlockFloor.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
using System;
using System.Collections.Generic;
using System.Collections.Immutable;
using System.Linq;
using Bencodex.Types;
using Libplanet.Action;
Expand All @@ -16,7 +18,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 OpeningFloor = 5;
Expand All @@ -27,21 +29,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<string, IValue> PlainValueInternal =>
new Dictionary<string, IValue>
{
["s"] = (Integer)Season,
["a"] = AvatarAddress.Serialize(),
["u"] = UseNcg.Serialize(),
}.ToImmutableDictionary();

public override void LoadPlainValue(IValue plainValue)
protected override void LoadPlainValueInternal(
IImmutableDictionary<string, IValue> 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)
Expand Down
31 changes: 17 additions & 14 deletions Lib9c/Action/AdventureBoss/Wanted.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
using System;
using System.Collections.Generic;
using System.Collections.Immutable;
using System.Linq;
using Bencodex.Types;
using Libplanet.Action;
Expand All @@ -19,28 +21,29 @@ namespace Nekoyume.Action.AdventureBoss
{
[Serializable]
[ActionType(TypeIdentifier)]
public class Wanted : ActionBase
public class Wanted : GameAction
{
public const string TypeIdentifier = "wanted";

public int Season;
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<string, IValue> PlainValueInternal =>
new Dictionary<string, IValue>
{
["s"] = (Integer)Season,
["b"] = Bounty.Serialize(),
["a"] = AvatarAddress.Serialize()
}.ToImmutableDictionary();

protected override void LoadPlainValueInternal(
IImmutableDictionary<string, IValue> 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)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

namespace Nekoyume.Action.Exceptions.AdventureBoss
{
[Serializable]
public class AlreadyClaimedException : Exception
{
public AlreadyClaimedException(string msg) : base(msg)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

namespace Nekoyume.Action.Exceptions.AdventureBoss
{
[Serializable]
public class ClaimExpiredException : Exception
{
public ClaimExpiredException(string msg) : base(msg)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

namespace Nekoyume.Action.Exceptions.AdventureBoss
{
[Serializable]
public class InsufficientStakingException : Exception
{
public InsufficientStakingException(string msg) : base(msg)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

namespace Nekoyume.Action.Exceptions.AdventureBoss
{
[Serializable]
public class InvalidAdventureBossSeasonException : Exception
{

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

namespace Nekoyume.Action.Exceptions.AdventureBoss
{
[Serializable]
public class InvalidBountyException : Exception
{
public InvalidBountyException(string msg) : base(msg)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

namespace Nekoyume.Action.Exceptions.AdventureBoss
{
[Serializable]
public class MaxInvestmentCountExceededException : Exception
{
public MaxInvestmentCountExceededException(string message) : base(message)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

namespace Nekoyume.Action.Exceptions.AdventureBoss
{
[Serializable]
public class PreviousBountyException : Exception
{
public PreviousBountyException(string msg) : base(msg)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

namespace Nekoyume.Action.Exceptions.AdventureBoss
{
[Serializable]
public class SeasonInProgressException : Exception
{
public SeasonInProgressException(string msg) : base(msg)
Expand Down
Loading