Skip to content

Commit

Permalink
Move all adventure actions to inherit GameAction
Browse files Browse the repository at this point in the history
  • Loading branch information
U-lis committed Jun 20, 2024
1 parent 6eed407 commit c6c2cc3
Show file tree
Hide file tree
Showing 5 changed files with 52 additions and 48 deletions.
23 changes: 12 additions & 11 deletions Lib9c/Action/AdventureBoss/ClaimAdventureBossReward.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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<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
1 change: 0 additions & 1 deletion Lib9c/Action/AdventureBoss/ExploreAdventureBoss.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
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 @@ -38,10 +38,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 @@ -50,10 +50,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 @@ -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;
Expand All @@ -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<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

0 comments on commit c6c2cc3

Please sign in to comment.