tested commit

This commit is contained in:
7heIVIaze 2025-06-04 18:23:40 +09:00
parent 1096753f5f
commit 36727688ac
8 changed files with 39 additions and 9 deletions

Binary file not shown.

Binary file not shown.

View File

@ -50,10 +50,10 @@ bool AHYShopAOE::RandomizeTradableItemSets(int CurrentHonbaekAmount)
return false; return false;
} }
// Filtering match the case.(ItemValue is less and equal than honbaek amount and over than 0) // Filtering match the case.(Item can be bought, ItemValue is less and equal than honbaek amount and over than 0)
TArray<FInventoryItem*> FilteredItemData = ItemData.FilterByPredicate([CurrentHonbaekAmount](const FInventoryItem* ItemDataRow) TArray<FInventoryItem*> FilteredItemData = ItemData.FilterByPredicate([CurrentHonbaekAmount](const FInventoryItem* ItemDataRow)
{ {
return ItemDataRow->ItemValue > 0 && ItemDataRow->ItemValue <= CurrentHonbaekAmount; return !ItemDataRow->OnlyDropped && ItemDataRow->ItemValue > 0 && ItemDataRow->ItemValue <= CurrentHonbaekAmount;
}); });
int maxLoopNum = FMath::Min(5, FilteredItemData.Num()); int maxLoopNum = FMath::Min(5, FilteredItemData.Num());
@ -82,7 +82,7 @@ TMap<FInventoryItem, int> AHYShopAOE::GetTradableItemSets(int CurrentHonbaekAmou
for (FInventoryItem TempItem : TempItems) for (FInventoryItem TempItem : TempItems)
{ {
int MaxAmount = CurrentHonbaekAmount / TempItem.ItemValue; int MaxAmount = CurrentHonbaekAmount / TempItem.ItemValue;
int Amount = FMath::Clamp(FMath::RandRange(0, MaxAmount), 1, MaxAmount); int Amount = FMath::Clamp(FMath::RandRange(0, MaxAmount), 1, 10);
Item.Add({ TempItem, Amount }); Item.Add({ TempItem, Amount });
} }

View File

@ -2,6 +2,7 @@
#include "HYShopNPCActor.h" #include "HYShopNPCActor.h"
#include "Blueprint/UserWidget.h" #include "Blueprint/UserWidget.h"
#include "HYPlayerCharacController.h"
void AHYShopNPCActor::Interact_Implementation(APlayerController* Controller) void AHYShopNPCActor::Interact_Implementation(APlayerController* Controller)
{ {
@ -18,3 +19,22 @@ void AHYShopNPCActor::Interact_Implementation(APlayerController* Controller)
// ShopWidget->AddToViewport(); // ShopWidget->AddToViewport();
//} //}
} }
void AHYShopNPCActor::BuyTradableItem_Implementation(APlayerController* Controller, const FInventoryItem ItemToBuy, const int Amount)
{
int CurrentAmount = *TradableItems.Find(ItemToBuy);
TradableItems[ItemToBuy] = CurrentAmount - Amount;
AHYPlayerCharacController* PlayerController = Cast<AHYPlayerCharacController>(Controller);
if (PlayerController)
{
for (int i = 0; i < Amount; ++i)
{
PlayerController->AddItemToInventoryByID(ItemToBuy.ItemID);
}
}
return;
}

View File

@ -15,8 +15,18 @@ class HWANYOUNG2_API AHYShopNPCActor : public AHYInteractableActor
{ {
GENERATED_BODY() GENERATED_BODY()
public:
virtual void Interact_Implementation(APlayerController* Controller); virtual void Interact_Implementation(APlayerController* Controller);
// This Function will be called when player buy the item.
// @param Controller: Player Controller, ItemToBuy: the item structure(Data) to buy, Amount: the number of the item.
UFUNCTION(BlueprintNativeEvent)
void BuyTradableItem(APlayerController* Controller, const FInventoryItem ItemToBuy, const int Amount);
// This Function will be called when player buy the item.
// @param Controller: Player Controller, ItemToBuy: the item structure(Data) to buy, Amount: the number of the item.
virtual void BuyTradableItem_Implementation(APlayerController* Controller, const FInventoryItem ItemToBuy, const int Amount);
public: public:
UPROPERTY(EditDefaultsOnly, BlueprintReadWrite) UPROPERTY(EditDefaultsOnly, BlueprintReadWrite)
TMap<FInventoryItem, int> TradableItems; TMap<FInventoryItem, int> TradableItems;