아이템 제작 레시피 구조체
FItemCraftRecipe
{
UPROPERTY(Category = RecipeInfo, EditAnywhere)
int32 RecipeID;
UPROPERTY(Category = RecipeInfo, EditAnywhere)
TMap<int32, int32> needs;
UPROPERTY(Category = RecipeInfo, EditAnywhere)
TSubclassOf<AActor> target_item;
}
Game State 추가 함수 및 프로퍼티
header
{
. . . .
UPROPERTY(EditDefaultsOnly)
class UDataTable* CraftDB;
UDataTable* GetCraftRecipeDB() const;
. . . .
}
ASciFiCombatGameState::ASciFiCombatGameState()
{
. . . .
static ConstructorHelpers::FObjectFinder<UDataTable> BP_CraftDB(TEXT("DataTable'/Game/Data/CraftDB.CraftDB'"));
CraftDB = BP_ItemDB.Object;
. . . .
}
UDataTable* ASciFiCombatGameState::GetCraftRecipeDB() const
{
return CraftDB;
}
itemActionComponent
header
class UItemActionComponent
{
. . . .
UPROPERTY(Replicated, BlueprintReadWrite)
FItemCraftRecipe selected_recipe;
. . . .
}
void UItemActionComponent::SelectRecipe(const FItemCraftRecipe& recipe_info) RPC : Server -> MultiCast 적용
{
// 아이템을 제작할 레시피를 선택함
selected_recipe = recipe_info;
}
bool UItemActionComponent::CheckItemCraftCondition()
{
int check_count = 0;
선택한 레시피와 현재 인벤토리를 비교하면서 제작이 가능한지를 체크함
selected_recipe
for ~ selected_recipe.needs
for ~ inventory
// 현재 인벤토리 내부에 레시피에서 요구로하는 재료가 존재하는지?
if exist selected_recipe.needs key value in inventory . . . .
// 가지고 있는 재료의 개수가 레시피의 요구사항보다 많거나 같은지??
if inventory[current].Quantity >= selected_recipe[current]
check_count++;
if check_count is equal selected_recipe.needs.Num();
return true;
return false;
}
void UItemActionComponent::CraftItem()
{
// 아이템 제작이 가능하다면
if CheckItemCraftCondition() is true
Spawn Actor by selected_recipe.target_item(Type is TSubclassof<AActor>)
}