This repository was archived by the owner on Feb 7, 2025. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: Add dungeon detail subscription field
- Loading branch information
Showing
7 changed files
with
202 additions
and
5 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
53 changes: 53 additions & 0 deletions
53
backend/app/Savor22b/States/DungeonConquestHistoryState.cs
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,53 @@ | ||
namespace Savor22b.States; | ||
|
||
using Bencodex.Types; | ||
using Libplanet; | ||
using Libplanet.Headless.Extensions; | ||
|
||
public class DungeonConquestHistoryState : State | ||
{ | ||
public long BlockIndex { get; private set; } | ||
public int DungeonId { get; private set; } | ||
public Address TargetUserAddress { get; private set; } | ||
public int DungeonConquestStatus { get; private set; } | ||
|
||
public DungeonConquestHistoryState( | ||
long blockIndex, | ||
int dungeonId, | ||
Address targetUserAddress, | ||
int dungeonConquestStatus | ||
) | ||
{ | ||
BlockIndex = blockIndex; | ||
DungeonId = dungeonId; | ||
TargetUserAddress = targetUserAddress; | ||
DungeonConquestStatus = dungeonConquestStatus; | ||
} | ||
|
||
public DungeonConquestHistoryState(Dictionary encoded) | ||
{ | ||
BlockIndex = encoded[nameof(BlockIndex)].ToLong(); | ||
DungeonId = encoded[nameof(DungeonId)].ToInteger(); | ||
TargetUserAddress = encoded[nameof(TargetUserAddress)].ToAddress(); | ||
DungeonConquestStatus = encoded[nameof(DungeonConquestStatus)].ToInteger(); | ||
} | ||
|
||
public IValue Serialize() | ||
{ | ||
var pairs = new[] | ||
{ | ||
new KeyValuePair<IKey, IValue>((Text)nameof(BlockIndex), BlockIndex.Serialize()), | ||
new KeyValuePair<IKey, IValue>((Text)nameof(DungeonId), DungeonId.Serialize()), | ||
new KeyValuePair<IKey, IValue>( | ||
(Text)nameof(TargetUserAddress), | ||
TargetUserAddress.ToBencodex() | ||
), | ||
new KeyValuePair<IKey, IValue>( | ||
(Text)nameof(DungeonConquestStatus), | ||
DungeonConquestStatus.Serialize() | ||
), | ||
}; | ||
|
||
return new Dictionary(pairs); | ||
} | ||
} |
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,53 @@ | ||
namespace Savor22b.States; | ||
|
||
using Libplanet.Headless.Extensions; | ||
|
||
using Bencodex.Types; | ||
using Libplanet; | ||
|
||
public class GlobalDungeonState : State | ||
{ | ||
public Dictionary<string, Address> DungeonStatus { get; private set; } | ||
|
||
public GlobalDungeonState() | ||
{ | ||
DungeonStatus = new Dictionary<string, Address>(); | ||
} | ||
|
||
public GlobalDungeonState(Dictionary<string, Address> dungeonStatus) | ||
{ | ||
DungeonStatus = dungeonStatus; | ||
} | ||
|
||
public GlobalDungeonState(Bencodex.Types.Dictionary encoded) | ||
{ | ||
if (encoded.TryGetValue((Text)nameof(DungeonStatus), out var dungeonStatus)) | ||
{ | ||
DungeonStatus = ((Bencodex.Types.Dictionary)dungeonStatus).ToDictionary( | ||
pair => ((Bencodex.Types.Text)pair.Key).Value, | ||
pair => pair.Value.ToAddress() | ||
); | ||
} | ||
else | ||
{ | ||
DungeonStatus = new Dictionary<string, Address>(); | ||
} | ||
} | ||
|
||
public IValue Serialize() | ||
{ | ||
var pairs = new[] | ||
{ | ||
new KeyValuePair<IKey, IValue>( | ||
(Text)nameof(DungeonStatus), | ||
new Dictionary( | ||
DungeonStatus.Select( | ||
e => new KeyValuePair<IKey, IValue>((Text)e.Key, e.Value.ToBencodex()) | ||
) | ||
) | ||
), | ||
}; | ||
|
||
return new Dictionary(pairs); | ||
} | ||
} |
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