88 lines
1.8 KiB
C++

// Fill out your copyright notice in the Description page of Project Settings.
#include "HYShopAOE.h"
#include "HYGameStateBase.h"
#include "Engine/DataTable.h"
// Sets default values
AHYShopAOE::AHYShopAOE()
{
// Set this actor to call Tick() every frame. You can turn this off to improve performance if you don't need it.
PrimaryActorTick.bCanEverTick = true;
}
// Called when the game starts or when spawned
void AHYShopAOE::BeginPlay()
{
Super::BeginPlay();
}
// Called every frame
void AHYShopAOE::Tick(float DeltaTime)
{
Super::Tick(DeltaTime);
}
bool AHYShopAOE::RandomizeTradableItemSets(int CurrentHonbaekAmount)
{
AHYGameStateBase* GameState = Cast<AHYGameStateBase>(GetWorld()->GetGameState());
if(GameState == nullptr)
{
return false;
}
UDataTable* ItemDataTable = GameState->GetItemDatabase();
if (ItemDataTable == nullptr)
{
return false;
}
TArray<FInventoryItem*> ItemData;
ItemDataTable->GetAllRows<FInventoryItem>("", ItemData);
if (ItemData.Num() == 0)
{
return false;
}
TArray<FInventoryItem*> FilteredItemData = ItemData.FilterByPredicate([CurrentHonbaekAmount](const FInventoryItem* ItemDataRow)
{
return ItemDataRow->ItemValue <= CurrentHonbaekAmount;
});
int maxLoopNum = FMath::Min(5, FilteredItemData.Num());
for (int i = 0; i < maxLoopNum; ++i)
{
int RandomIdx = FMath::RandRange(0, FilteredItemData.Num() - 1);
FinalItemSets.Add(*FilteredItemData[RandomIdx]);
FilteredItemData.RemoveAt(RandomIdx);
}
if (FinalItemSets.Num() == maxLoopNum)
{
return true;
}
return false;
}
void AHYShopAOE::GetTradableItemSets(TMap<FInventoryItem, int>& Item)
{
TArray<FInventoryItem> TempItems = FinalItemSets.Array();
for (FInventoryItem TempItem : TempItems)
{
int Amount = FMath::RandRange(0, 100);
Item.Add({ TempItem, Amount });
}
return;
}