Skip to content

Commit

Permalink
Update save logic
Browse files Browse the repository at this point in the history
- Get equipment data from combination slot, not creating it
- Fix wrong item ID field (why set it to 1?)
  • Loading branch information
U-lis committed Aug 13, 2024
1 parent 7a0691d commit 2287382
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 37 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ namespace NineChronicles.DataProvider.DataRendering.CustomCraft
using Nekoyume.Action.CustomEquipmentCraft;
using Nekoyume.Extensions;
using Nekoyume.Helper;
using Nekoyume.Model.Elemental;
using Nekoyume.Model.Item;
using Nekoyume.Module;
using Nekoyume.TableData;
Expand All @@ -21,29 +20,30 @@ public static class CustomEquipmentCraftData
{
public static List<CustomEquipmentCraftModel> GetCraftInfo(
IWorld prevStates,
IWorld outputStates,
long blockIndex,
DateTimeOffset blockTime,
IRandom random,
CustomEquipmentCraft craftData
)
{
Log.Verbose($"[CustomEquipmentCraft] GetCraftData");
var craftList = new List<CustomEquipmentCraftModel>();

Dictionary<Type, (Address, ISheet)> sheets = prevStates.GetSheets(sheetTypes: new[]
{
typeof(CustomEquipmentCraftRecipeSheet),
typeof(CustomEquipmentCraftRelationshipSheet),
typeof(CustomEquipmentCraftIconSheet),
typeof(CustomEquipmentCraftCostSheet),
typeof(EquipmentItemSheet),
typeof(MaterialItemSheet),
});

var craftList = new List<CustomEquipmentCraftModel>();
var i = 0;
foreach (var craft in craftData.CraftList)
{
var guid = Guid.NewGuid().ToString();

Dictionary<Type, (Address, ISheet)> sheets = prevStates.GetSheets(sheetTypes: new[]
{
typeof(CustomEquipmentCraftRecipeSheet),
typeof(CustomEquipmentCraftRelationshipSheet),
typeof(CustomEquipmentCraftIconSheet),
typeof(CustomEquipmentCraftCostSheet),
typeof(EquipmentItemSheet),
typeof(MaterialItemSheet),
});
var equipment = outputStates.GetCombinationSlotState(craftData.AvatarAddress, craft.SlotIndex).Result!.itemUsable!;

var relationship = prevStates.GetRelationship(craftData.AvatarAddress);
var recipeSheet = sheets.GetSheet<CustomEquipmentCraftRecipeSheet>();
Expand Down Expand Up @@ -85,37 +85,16 @@ CustomEquipmentCraft craftData
}
}

// Create equipment with ItemFactory
var uid = random.GenerateRandomGuid();
var equipmentItemId = relationshipRow.GetItemId(recipeRow.ItemSubType);
var equipmentRow = sheets.GetSheet<EquipmentItemSheet>()[equipmentItemId];
var equipment =
(Equipment)ItemFactory.CreateItemUsable(equipmentRow, uid, 0L);

// Set Icon
equipment.IconId = ItemFactory.SelectIconId(
craft.IconId,
craft.IconId == CustomEquipmentCraft.RandomIconId,
equipmentRow,
relationship,
sheets.GetSheet<CustomEquipmentCraftIconSheet>(),
random
);

// Set Elemental Type
var elementalList = (ElementalType[])Enum.GetValues(typeof(ElementalType));
equipment.ElementalType = elementalList[random.Next(elementalList.Length)];

craftList.Add(new CustomEquipmentCraftModel
{
Id = $"{guid}_{i++}",
BlockIndex = blockIndex,
AvatarAddress = craftData.AvatarAddress.ToString(),
EquipmentItemId = 1,
EquipmentItemId = equipment.Id,
RecipeId = craft.RecipeId,
SlotIndex = craft.SlotIndex,
ItemSubType = equipment.ItemSubType.ToString(),
IconId = equipment.IconId,
IconId = equipment.Id,
ElementalType = equipment.ElementalType.ToString(),
DrawingAmount = drawingAmount,
DrawingToolAmount = drawingToolAmount,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,11 +46,12 @@ partial void SubscribeCustomEquipmentCraft(ActionEvaluation<CustomEquipmentCraft
{
var start = DateTimeOffset.UtcNow;
var prevState = new World(_blockChainStates.GetWorldState(evt.PreviousState));
var outputState = new World(_blockChainStates.GetWorldState(evt.OutputState));
var craftList = CustomEquipmentCraftData.GetCraftInfo(
prevState,
outputState,
evt.BlockIndex,
_blockTimeOffset,
new ReplayRandom(evt.RandomSeed),
customEquipmentCraft
);
foreach (var craft in craftList)
Expand Down

0 comments on commit 2287382

Please sign in to comment.