From 6d1443512c8f887ede5b8425bceacda3b57a209a Mon Sep 17 00:00:00 2001 From: eugene-hong <58686228+eugene-doobu@users.noreply.github.com> Date: Fri, 11 Oct 2024 20:10:39 +0900 Subject: [PATCH] rename block index --- .../CustomEquipmentCraftTest.cs | 2 +- Lib9c/Action/RapidCombination.cs | 2 +- Lib9c/Action/RapidCombination5.cs | 4 +- Lib9c/Model/State/CombinationSlotState.cs | 37 ++++++++++--------- 4 files changed, 24 insertions(+), 21 deletions(-) diff --git a/.Lib9c.Tests/Action/CustomEquipmentCraft/CustomEquipmentCraftTest.cs b/.Lib9c.Tests/Action/CustomEquipmentCraft/CustomEquipmentCraftTest.cs index c136162a67..8fd4946db1 100644 --- a/.Lib9c.Tests/Action/CustomEquipmentCraft/CustomEquipmentCraftTest.cs +++ b/.Lib9c.Tests/Action/CustomEquipmentCraft/CustomEquipmentCraftTest.cs @@ -496,7 +496,7 @@ public void Execute( var slotState = resultState.GetAllCombinationSlotState(_avatarAddress) .GetSlot(craftData.SlotIndex); - Assert.Equal(currentBlockIndex + additionalBlock, slotState.UnlockBlockIndex); + Assert.Equal(currentBlockIndex + additionalBlock, slotState.WorkCompleteBlockIndex); var itemSubType = _tableSheets.CustomEquipmentCraftRecipeSheet.Values .First(row => row.Id == craftData.RecipeId).ItemSubType; diff --git a/Lib9c/Action/RapidCombination.cs b/Lib9c/Action/RapidCombination.cs index a08e693aea..b8c001e817 100644 --- a/Lib9c/Action/RapidCombination.cs +++ b/Lib9c/Action/RapidCombination.cs @@ -84,7 +84,7 @@ void ProcessRapidCombination(int si) throw new RequiredBlockIndexException($"{addressesHex}Already met the required block index. context block index: {context.BlockIndex}, required block index: {slotState.Result.itemUsable.RequiredBlockIndex}"); } - var actionableBlockIndex = slotState.StartBlockIndex; + var actionableBlockIndex = slotState.WorkStartBlockIndex; if (context.BlockIndex < actionableBlockIndex) { throw new AppraiseBlockNotReachedException( diff --git a/Lib9c/Action/RapidCombination5.cs b/Lib9c/Action/RapidCombination5.cs index 0fac67cb3b..c0b9f1c231 100644 --- a/Lib9c/Action/RapidCombination5.cs +++ b/Lib9c/Action/RapidCombination5.cs @@ -102,12 +102,12 @@ public override IWorld Execute(IActionContext context) throw new FailedLoadStateException($"{addressesHex}Aborted as the GameConfigState was failed to load."); } - if (context.BlockIndex < slotState.StartBlockIndex + GameConfig.RequiredAppraiseBlock) + if (context.BlockIndex < slotState.WorkStartBlockIndex + GameConfig.RequiredAppraiseBlock) { throw new AppraiseBlockNotReachedException( $"{addressesHex}Aborted as Item appraisal block section. " + $"context block index: {context.BlockIndex}, " + - $"actionable block index : {slotState.StartBlockIndex + GameConfig.RequiredAppraiseBlock}"); + $"actionable block index : {slotState.WorkStartBlockIndex + GameConfig.RequiredAppraiseBlock}"); } var count = RapidCombination0.CalculateHourglassCount(gameConfigState, diff); diff --git a/Lib9c/Model/State/CombinationSlotState.cs b/Lib9c/Model/State/CombinationSlotState.cs index df9da73116..6dec42756d 100644 --- a/Lib9c/Model/State/CombinationSlotState.cs +++ b/Lib9c/Model/State/CombinationSlotState.cs @@ -11,19 +11,22 @@ namespace Nekoyume.Model.State { public class CombinationSlotState : State { - private const string UnlockBlockIndexKey = "unlockBlockIndex"; - private const string StartBlockIndexKey = "startBlockIndex"; + private const string WorkCompleteBlockIndexKey = "unlockBlockIndex"; + private const string WorkStartBlockIndexKey = "startBlockIndex"; + private const string ResultKey = "result"; private const string PetIdKey = "petId"; private const string IndexKey = "index"; private const string IsUnlockedKey = "isUnlocked"; public const string DeriveFormat = "combination-slot-{0}"; - public long UnlockBlockIndex { get; private set; } - public long StartBlockIndex { get; private set; } + + public long WorkCompleteBlockIndex { get; private set; } + public long WorkStartBlockIndex { get; private set; } public AttachmentActionResult Result { get; private set; } public int? PetId { get; private set; } - public long RequiredBlockIndex => UnlockBlockIndex - StartBlockIndex; + public long RequiredBlockIndex => WorkCompleteBlockIndex - WorkStartBlockIndex; + /// /// It is a CombinationSlot index. start from 0. /// @@ -59,14 +62,14 @@ public CombinationSlotState(Address address, int index = 0) : base(address) "The index of the combination slot must be between 0 and CombinationSlotCapacity."); } - UnlockBlockIndex = 0; + WorkCompleteBlockIndex = 0; Index = index; IsUnlocked = AvatarState.DefaultCombinationSlotCount > index; } public CombinationSlotState(Dictionary serialized) : base(serialized) { - UnlockBlockIndex = serialized[UnlockBlockIndexKey].ToLong(); + WorkCompleteBlockIndex = serialized[WorkCompleteBlockIndexKey].ToLong(); if (serialized.TryGetValue((Text)IndexKey, out var index)) { @@ -78,9 +81,9 @@ public CombinationSlotState(Dictionary serialized) : base(serialized) Result = AttachmentActionResult.Deserialize((Dictionary) result); } - if (serialized.TryGetValue((Text)StartBlockIndexKey, out var value)) + if (serialized.TryGetValue((Text)WorkStartBlockIndexKey, out var value)) { - StartBlockIndex = value.ToLong(); + WorkStartBlockIndex = value.ToLong(); } if (serialized.TryGetValue((Text)PetIdKey, out var petId)) @@ -96,7 +99,7 @@ public CombinationSlotState(Dictionary serialized) : base(serialized) public static bool ValidateSlotIndex(int index) { - return index >= 0 && index < AvatarState.CombinationSlotCapacity; + return index is >= 0 and < AvatarState.CombinationSlotCapacity; } [Obsolete("Use ValidateV2")] @@ -108,7 +111,7 @@ public bool Validate(AvatarState avatarState, long blockIndex) } return avatarState.worldInformation != null && - blockIndex >= UnlockBlockIndex; + blockIndex >= WorkCompleteBlockIndex; } public bool ValidateV2(long blockIndex) @@ -118,20 +121,20 @@ public bool ValidateV2(long blockIndex) return false; } - return blockIndex >= UnlockBlockIndex; + return blockIndex >= WorkCompleteBlockIndex; } public void Update(AttachmentActionResult result, long blockIndex, long unlockBlockIndex, int? petId = null) { Result = result; - StartBlockIndex = blockIndex; - UnlockBlockIndex = unlockBlockIndex; + WorkStartBlockIndex = blockIndex; + WorkCompleteBlockIndex = unlockBlockIndex; PetId = petId; } public void Update(long blockIndex) { - UnlockBlockIndex = blockIndex; + WorkCompleteBlockIndex = blockIndex; Result.itemUsable.Update(blockIndex); } @@ -170,8 +173,8 @@ public override IValue Serialize() { var values = new Dictionary { - [(Text)UnlockBlockIndexKey] = UnlockBlockIndex.Serialize(), - [(Text)StartBlockIndexKey] = StartBlockIndex.Serialize(), + [(Text)WorkCompleteBlockIndexKey] = WorkCompleteBlockIndex.Serialize(), + [(Text)WorkStartBlockIndexKey] = WorkStartBlockIndex.Serialize(), [(Text)IndexKey] = (Integer)Index, [(Text)IsUnlockedKey] = IsUnlocked.Serialize(), };