crafting system is fully functional

This commit is contained in:
Ji Yoon Rhee 2024-09-17 00:05:53 +09:00
parent 63d4092c2c
commit 564f2a80cd
19 changed files with 83 additions and 21 deletions

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

View File

@ -39,9 +39,9 @@ bool AHYPlayerCharacController::AddItemToInventoryByID(FName ID)
return false;
}
void AHYPlayerCharacController::CraftItem(FInventoryItem ItemA, FInventoryItem ItemB, FInventoryItem ItemC, FInventoryItem ItemD)
void AHYPlayerCharacController::CraftItem(FInventoryItem ItemA)
{
for (auto Combination : ItemB.CraftCombinations) {
/*for (auto Combination : ItemB.CraftCombinations) {
if (Combination.ItemAID == ItemA.ItemID
&& Combination.ItemBID == ItemB.ItemID
&& Combination.ItemCID == ItemC.ItemID
@ -53,7 +53,38 @@ void AHYPlayerCharacController::CraftItem(FInventoryItem ItemA, FInventoryItem I
AddItemToInventoryByID(Combination.ProductID);
ReloadCraftUI();
}
}*/
int32 NumOfCraftingItems = CraftingItems.Num();
bool bIsValidComb;
bIsValidComb = false;
if (NumOfCraftingItems < 2 || NumOfCraftingItems > 4) { return; }
AHYGameStateBase* gameState = Cast<AHYGameStateBase>(GetWorld()->GetGameState());
UDataTable* itemDB = gameState->GetItemDatabase();
for (auto Combination : ItemA.CraftCombinations) {
if (CraftingItems.Contains(Combination.ItemBID) && NumOfCraftingItems >= 2) {
if (Combination.bDestroyItemB) Inventory.RemoveSingle(*itemDB->FindRow<FInventoryItem>(Combination.ItemBID, ""));
bIsValidComb = bIsValidComb || true;
}
if (CraftingItems.Contains(Combination.ItemCID) && NumOfCraftingItems >= 3) {
if (Combination.bDestroyItemC) Inventory.RemoveSingle(*itemDB->FindRow<FInventoryItem>(Combination.ItemCID, ""));
bIsValidComb = bIsValidComb && true;
}
if (CraftingItems.Contains(Combination.ItemDID) && NumOfCraftingItems == 4) {
if (Combination.bDestroyItemD) Inventory.RemoveSingle(*itemDB->FindRow<FInventoryItem>(Combination.ItemDID, ""));
bIsValidComb = bIsValidComb && true;
}
if (bIsValidComb) {
if (Combination.bDestroyItemA) Inventory.RemoveSingle(ItemA);
AddItemToInventoryByID(Combination.ProductID);
ReloadCraftUI();
return;
}
else continue;
}
}
void AHYPlayerCharacController::Interact()

View File

@ -38,7 +38,7 @@ public:
bool AddItemToInventoryByID(FName ID);
UFUNCTION(BlueprintCallable, Category = "Utils")
void CraftItem(FInventoryItem ItemA, FInventoryItem ItemB, FInventoryItem ItemC, FInventoryItem ItemD);
void CraftItem(FInventoryItem ItemA);
UPROPERTY(BlueprintReadWrite, VisibleAnywhere)
class AHYInteractableActor* CurrentInteractable;
@ -55,6 +55,10 @@ public:
UPROPERTY(EditAnywhere, BlueprintReadWrite)
int32 Currency;
UPROPERTY(VisibleAnywhere, BlueprintReadWrite)
TSet<FName> CraftingItems;
//interacts with the Interactable objects
UFUNCTION(BlueprintCallable, Category = "Utils")
void Interact();

View File

@ -62,4 +62,10 @@ public:
bool operator==(const FInventoryItem& OtherItem) const {
return ItemID == OtherItem.ItemID;
}
friend uint32 GetTypeHash(const FInventoryItem& InventoryItem) {
return HashCombine(GetTypeHash(InventoryItem.ItemID), InventoryItem.ItemValue);
}
};