#pragma once

#include "CoreMinimal.h"
#include "Engine/DataAsset.h"
#include "StructUtils/InstancedStruct.h"
#include "MyLootTable.generated.h"

/** Base of the entries of a loot table. */
USTRUCT()
struct MYGAME_API FMyLootEntry
{
	GENERATED_BODY()
};

/** Drops some gold. */
USTRUCT(meta = (Category = "Loot", PulseSummary = "{Min} to {Max} gold"))
struct MYGAME_API FMyLootEntry_Gold : public FMyLootEntry
{
	GENERATED_BODY()

	UPROPERTY(EditAnywhere, Category = "Gold", meta = (ClampMin = "0"))
	int32 Min = 5;

	UPROPERTY(EditAnywhere, Category = "Gold", meta = (ClampMin = "0"))
	int32 Max = 20;
};

/** Drops an item with a chance. */
USTRUCT(meta = (Category = "Loot", PulseSummary = "{Count}x {Item}"))
struct MYGAME_API FMyLootEntry_Item : public FMyLootEntry
{
	GENERATED_BODY()

	UPROPERTY(EditAnywhere, Category = "Item")
	FName Item;

	UPROPERTY(EditAnywhere, Category = "Item", meta = (ClampMin = "1"))
	int32 Count = 1;

	UPROPERTY(EditAnywhere, Category = "Item", meta = (ClampMin = "0", ClampMax = "1"))
	float Chance = 0.5f;
};

/** What a monster or a chest can drop. */
UCLASS(BlueprintType)
class MYGAME_API UMyLootTable : public UDataAsset
{
	GENERATED_BODY()

public:

	/** How often the table is rolled. */
	UPROPERTY(EditAnywhere, Category = "Table", meta = (ClampMin = "1"))
	int32 Rolls = 1;

	/** The parts of the table: every entry is a card in the workshop. */
	UPROPERTY(EditAnywhere, Category = "Loot", meta = (BaseStruct = "/Script/MyGame.MyLootEntry", ExcludeBaseStruct))
	TArray<FInstancedStruct> Entries;
};
