๐
2025-11-26
์ ์ ์์คํ ์์ ํ์๋ก ํ๋ ์ธ๋ฒคํ ๋ฆฌ ์กฐ์ ํจ์๋ค์ ์ถ๊ฐ๋ก ๊ตฌํํ๋ค:
int32 UTSInventoryMasterComponent::GetItemCount(int32 StaticDataID) const
{
int32 ResultCount = 0;
// ํซํค ์ธ๋ฒคํ ๋ฆฌ ํ์
for (const FSlotStructMaster& Slot : HotkeyInventory.InventorySlotContainer)
{
if (Slot.ItemData.StaticDataID == StaticDataID)
{
ResultCount += Slot.CurrentStackSize;
}
}
// ๊ฐ๋ฐฉ ์ธ๋ฒคํ ๋ฆฌ ํ์ (๊ฐ๋ฐฉ์ด ํ์ฑํ๋ ๊ฒฝ์ฐ๋ง)
if (GetCurrentBagSlotCount() == 0)
{
return ResultCount;
}
for (const FSlotStructMaster& Slot : BagInventory.InventorySlotContainer)
{
if (Slot.ItemData.StaticDataID == StaticDataID)
{
ResultCount += Slot.CurrentStackSize;
}
}
return ResultCount;
}
ํน์ง:
const ํจ์๋ก ์ฝ๊ธฐ ์ ์ฉ ๋ณด์ฅvoid UTSInventoryMasterComponent::ConsumeItem(int32 StaticDataID, int32 Quantity)
{
// ํซํค ์ธ๋ฒคํ ๋ฆฌ ํ์
for (int32 i = 0; i < HotkeyInventory.InventorySlotContainer.Num(); ++i)
{
FSlotStructMaster& Slot = HotkeyInventory.InventorySlotContainer[i];
if (Slot.ItemData.StaticDataID == StaticDataID)
{
int32 ToRemove = FMath::Min(Quantity, Slot.CurrentStackSize);
RemoveItem(EInventoryType::HotKey, i, ToRemove);
Quantity -= ToRemove;
if (ActiveHotkeyIndex == i)
{
HandleActiveHotkeyIndexChanged();
}
if (Quantity <= 0)
{
break;
}
}
}
// ๊ฐ๋ฐฉ ์ธ๋ฒคํ ๋ฆฌ ํ์
if (GetCurrentBagSlotCount() > 0)
{
for (int32 i = 0; i < BagInventory.InventorySlotContainer.Num(); ++i)
{
FSlotStructMaster& Slot = BagInventory.InventorySlotContainer[i];
if (Slot.ItemData.StaticDataID == StaticDataID)
{
int32 ToRemove = FMath::Min(Quantity, Slot.CurrentStackSize);
RemoveItem(EInventoryType::BackPack, i, ToRemove);
Quantity -= ToRemove;
if (Quantity <= 0)
{
break;
}
}
}
}
HandleInventoryChanged();
}
์ค๊ณ ์๋:
HandleInventoryChanged() ํธ์ถbool UTSInventoryMasterComponent::AddItem(const int32 StaticDataID, int32 Quantity, int32& OutRemainingQuantity)
{
FItemInstance ItemData = FItemInstance(StaticDataID, GetWorld()->GetTimeSeconds());
return AddItem(ItemData, Quantity, OutRemainingQuantity);
}
ํธ์์ฑ:
StaticDataID๋ง์ผ๋ก ์์ดํ
์ถ๊ฐ ๊ฐ๋ฅFItemInstance ๋ฒ์ AddItem์ ์ฌ์ฌ์ฉ์ด์ ์ ์๋์์ ๋ค์๊ณผ ๊ฐ์ด ์ฌ์ฉ ๊ฐ๋ฅ:
// ์ ์ ๊ฐ๋ฅ ์ฌ๋ถ ํ์ธ
bool ATSCraftingTable::CanCraft(int32 RecipeID, ATSCharacter* InstigatorCharacter)
{
for (const FIngredientData& Ingredient : RecipeData.Ingredients)
{
int32 ItemCount = PlayerInventoryComp->GetItemCount(Ingredient.MaterialID);
if (ItemCount < Ingredient.Count)
{
return false; // ์ฌ๋ฃ ๋ถ์กฑ
}
}
return true;
}
// ์ ์ ์คํ
void ATSCraftingTable::StartCrafting(int32 RecipeID, ATSCharacter* InstigatorCharacter)
{
// ์ฌ๋ฃ ์๋น
for (const FIngredientData& Ingredient : RecipeData.Ingredients)
{
PlayerInventoryComp->ConsumeItem(Ingredient.MaterialID, Ingredient.Count);
}
// ๊ฒฐ๊ณผ๋ฌผ ์์ฑ
int32 RemainingQuantity;
InventoryComp->AddItem(RecipeData.ResultItemID, RecipeData.ResultCount, RemainingQuantity);
}
์ค๋ฒ๋ก๋ ํจ์์ ํธ์์ฑ์ ์ฒด๊ฐํ๋ค. AddItem(int32, ...) ๋ฒ์ ํ๋ ์ถ๊ฐํ์ ๋ฟ์ธ๋ฐ, ์ ์ ์์คํ
์ฝ๋๊ฐ ํจ์ฌ ๊ฐ๊ฒฐํด์ก๋ค. FItemInstance๋ฅผ ๋งค๋ฒ ์์ฑํ์ง ์์๋ ๋๋ ์ฝ๋ ๊ฐ๋
์ฑ๋ ์ข์์ก๋ค.
์์ ฏ์ชฝ์์ ํ์ฌ ๋ถ์กฑํ ์ฌ๋ฃ ์์ดํ ์ ๊ฒฝ์ฐ์๋ ํ๋์ ๋ณผ ์ ์๋๋ก ํ์๋ฅผ ํ๊ฑฐ๋ "์ ์ ์คํจ โ ์ฌ์ฉ์ ํผ๋๋ฐฑ"๊น์ง ์ด์ด์ง๋๋ก ๋ฐํ๊ฐ์ผ๋ก ์ฑ๊ณต ์ฌ๋ถ๋ฅผ ์ ๋ฌํ๊ฑฐ๋, ์๋ฌ ๋ธ๋ฆฌ๊ฒ์ดํธ๋ฅผ ์ถ๊ฐํ๋ ๋ฐฉ์์ ๊ณ ๋ คํด๋ด์ผ๊ฒ ๋ค.