Skip to content

Commit

Permalink
Merge pull request #2885 from eugene-doobu/feature/rename-block-index
Browse files Browse the repository at this point in the history
rename block index
  • Loading branch information
eugene-doobu authored Oct 15, 2024
2 parents 7397fd3 + 4721779 commit 93fef45
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 22 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
2 changes: 1 addition & 1 deletion Lib9c/Action/RapidCombination.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down
4 changes: 2 additions & 2 deletions Lib9c/Action/RapidCombination5.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
45 changes: 27 additions & 18 deletions Lib9c/Model/State/CombinationSlotState.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,19 +11,28 @@ 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; }

/// <summary>
/// Serialize key is "unlockBlockIndex".
/// </summary>
public long WorkCompleteBlockIndex { get; private set; }
/// <summary>
/// Serialize key is "startBlockIndex".
/// </summary>
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;

/// <summary>
/// It is a CombinationSlot index. start from 0.
/// </summary>
Expand Down Expand Up @@ -59,14 +68,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))
{
Expand All @@ -78,9 +87,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))
Expand All @@ -96,7 +105,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")]
Expand All @@ -108,7 +117,7 @@ public bool Validate(AvatarState avatarState, long blockIndex)
}

return avatarState.worldInformation != null &&
blockIndex >= UnlockBlockIndex;
blockIndex >= WorkCompleteBlockIndex;
}

public bool ValidateV2(long blockIndex)
Expand All @@ -118,20 +127,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)
public void Update(AttachmentActionResult result, long blockIndex, long workCompleteBlockIndex, int? petId = null)
{
Result = result;
StartBlockIndex = blockIndex;
UnlockBlockIndex = unlockBlockIndex;
WorkStartBlockIndex = blockIndex;
WorkCompleteBlockIndex = workCompleteBlockIndex;
PetId = petId;
}

public void Update(long blockIndex)
{
UnlockBlockIndex = blockIndex;
WorkCompleteBlockIndex = blockIndex;
Result.itemUsable.Update(blockIndex);
}

Expand Down Expand Up @@ -170,8 +179,8 @@ public override IValue Serialize()
{
var values = new Dictionary<IKey, IValue>
{
[(Text)UnlockBlockIndexKey] = UnlockBlockIndex.Serialize(),
[(Text)StartBlockIndexKey] = StartBlockIndex.Serialize(),
[(Text)WorkCompleteBlockIndexKey] = WorkCompleteBlockIndex.Serialize(),
[(Text)WorkStartBlockIndexKey] = WorkStartBlockIndex.Serialize(),
[(Text)IndexKey] = (Integer)Index,
[(Text)IsUnlockedKey] = IsUnlocked.Serialize(),
};
Expand Down

0 comments on commit 93fef45

Please sign in to comment.