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.
Merge branch 'main' into feat/level-up
- Loading branch information
Showing
13 changed files
with
168 additions
and
22 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
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
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,24 @@ | ||
namespace Savor22b.GraphTypes.Types; | ||
|
||
using GraphQL.Types; | ||
using Libplanet.Blockchain; | ||
using Libplanet.Net; | ||
using Libplanet.Store; | ||
using Savor22b.States; | ||
|
||
public class DungeonStateType : ObjectGraphType<DungeonState> | ||
{ | ||
public DungeonStateType( | ||
BlockChain blockChain, | ||
BlockRenderer blockRenderer, | ||
IStore store, | ||
Swarm? swarm = null | ||
) | ||
{ | ||
Field<NonNullGraphType<IntGraphType>>( | ||
name: "DungeonKeyCount", | ||
description: "The number of dungeon keys the user has.", | ||
resolve: context => context.Source.GetDungeonKeyCount(blockChain.Count) | ||
); | ||
} | ||
} |
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,33 @@ | ||
namespace Savor22b.States; | ||
|
||
using Bencodex.Types; | ||
using Libplanet.Headless.Extensions; | ||
|
||
public class DungeonKeyHistory : State | ||
{ | ||
public long BlockIndex { get; private set; } | ||
public int DungeonId { get; private set; } | ||
|
||
public DungeonKeyHistory(long blockIndex, int dungeonId) | ||
{ | ||
BlockIndex = blockIndex; | ||
DungeonId = dungeonId; | ||
} | ||
|
||
public DungeonKeyHistory(Dictionary encoded) | ||
{ | ||
BlockIndex = encoded[nameof(BlockIndex)].ToLong(); | ||
DungeonId = encoded[nameof(DungeonId)].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()), | ||
}; | ||
|
||
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,73 @@ | ||
namespace Savor22b.States; | ||
|
||
using System.Collections.Immutable; | ||
using Bencodex.Types; | ||
|
||
public class DungeonState : State | ||
{ | ||
public static readonly int MaxDungeonKey = 5; | ||
public static readonly int DungeonKeyChargeIntervalBlock = 12; | ||
|
||
public ImmutableList<DungeonKeyHistory> DungeonKeyHistories { get; private set; } | ||
|
||
public DungeonState() | ||
{ | ||
DungeonKeyHistories = ImmutableList<DungeonKeyHistory>.Empty; | ||
} | ||
|
||
public DungeonState(ImmutableList<DungeonKeyHistory> dungeonKeyHistories) | ||
{ | ||
DungeonKeyHistories = dungeonKeyHistories; | ||
} | ||
|
||
public DungeonState(Dictionary encoded) | ||
{ | ||
if (encoded.TryGetValue((Text)nameof(DungeonKeyHistories), out var dungeonKeyHistories)) | ||
{ | ||
DungeonKeyHistories = ((List)dungeonKeyHistories) | ||
.Select(element => new DungeonKeyHistory((Dictionary)element)) | ||
.ToImmutableList(); | ||
} | ||
else | ||
{ | ||
DungeonKeyHistories = ImmutableList<DungeonKeyHistory>.Empty; | ||
} | ||
} | ||
|
||
public IValue Serialize() | ||
{ | ||
return new Dictionary(new[] | ||
{ | ||
new KeyValuePair<IKey, IValue>( | ||
(Text)nameof(DungeonKeyHistories), | ||
new List(DungeonKeyHistories.Select(element => element.Serialize()))), | ||
}); | ||
} | ||
|
||
public int GetDungeonKeyCount(long blockIndex) | ||
{ | ||
return MaxDungeonKey - GetCurrentDungeonKeyHistories(blockIndex).Count; | ||
} | ||
|
||
public ImmutableList<DungeonKeyHistory> GetCurrentDungeonKeyHistories(long blockIndex) | ||
{ | ||
var lowerBoundIndex = blockIndex - (MaxDungeonKey * DungeonKeyChargeIntervalBlock); | ||
var result = new List<DungeonKeyHistory>(); | ||
|
||
for (int i = DungeonKeyHistories.Count - 1; i >= 0; i--) | ||
{ | ||
var history = DungeonKeyHistories[i]; | ||
|
||
if (history.BlockIndex > lowerBoundIndex && history.BlockIndex <= blockIndex) | ||
{ | ||
result.Add(history); | ||
} | ||
else if (history.BlockIndex <= lowerBoundIndex) | ||
{ | ||
break; | ||
} | ||
} | ||
|
||
return result.ToImmutableList(); | ||
} | ||
} |
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