More fixes for removal mode and cleanup of some stuff

This commit is contained in:
2026-09-13 16:42:22 +02:00
parent 861657d7ce
commit 4f029309d5
88 changed files with 273 additions and 312 deletions

View File

@@ -65,7 +65,7 @@ class ARemovableStaticMeshActor;
/**
*
*/
UCLASS(BlueprintType)
UCLASS(BlueprintType, PrioritizeCategories = ("Default", "Info", "Placeable", "Craftable", "Property Map", "Seed"))
class PROJECTELERI_API UItemDataAsset : public UPrimaryDataAsset
{
GENERATED_BODY()
@@ -120,10 +120,16 @@ public:
bool Stackable = true;
/** Mesh that the item / potion have, ignored for seeds */
UPROPERTY()
UPROPERTY(EditDefaultsOnly, BlueprintReadOnly, Category = "Placeable", meta=(EditCondition="ItemCategory==Category::Decoration", EditConditionHides))
TSoftObjectPtr<UStaticMesh> ItemMesh;
UPROPERTY(EditDefaultsOnly, BlueprintReadOnly, Category = "Info", meta=(EditCondition="ItemCategory==Category::Decoration", EditConditionHides, MetaClass="/Script/ProjectEleri.RemovableStaticMeshActor"))
UPROPERTY(EditDefaultsOnly, BlueprintReadOnly, Category = "Placeable", meta=(EditCondition="ItemCategory==Category::Decoration", EditConditionHides))
int32 GridScale = 1;
UPROPERTY(EditDefaultsOnly, BlueprintReadOnly, Category = "Placeable", meta=(EditCondition="ItemCategory==Category::Decoration", EditConditionHides))
FVector BoxExtentOverride;
UPROPERTY(EditDefaultsOnly, BlueprintReadOnly, Category = "Placeable", meta=(EditCondition="ItemCategory==Category::Decoration", EditConditionHides, MetaClass="/Script/ProjectEleri.RemovableStaticMeshActor"))
FSoftClassPath DecorationActorClassPath;
@@ -132,9 +138,6 @@ public:
UPROPERTY(VisibleAnywhere, BlueprintReadOnly, Category = "Info", AssetRegistrySearchable, meta = (AssetBundles = "Inventory, Book"))
int32 BaseCost;
UPROPERTY(EditDefaultsOnly, BlueprintReadOnly, Category = "Info", AssetRegistrySearchable, meta = (AssetBundles = "Inventory, Book"))
TSoftObjectPtr<UTexture2D> PropertyMapTexture;
/*--------------------------------------------------------------------------------------------------------------------------*/
/** What part of the world grants faster growth and higher chance to harvest an HQ ingredient */

View File

@@ -8,6 +8,9 @@
#include "Engine/AssetManager.h"
#include "BookOfAlchemyManager.h"
#include "Kismet/GameplayStatics.h"
#include "ProjectEleri/Components/MoveActorsComponent.h"
#include "ProjectEleri/Settings/EleriGameSettings.h"
#include "ProjectEleri/System/MainBlueprintFunctionLibrary.h"
UWorld* UItemDatabase::GetWorld() const {
if (const UGameInstance* GameInstance = GetGameInstance()) {
@@ -52,6 +55,9 @@ void UItemDatabase::Initialize(FSubsystemCollectionBase& Collection) {
else {
UAssetManager::CallOrRegister_OnCompletedInitialScan(FStopRenderingThreadDelegate::CreateLambda(LoadDataLambda));
}
RemovableStaticMeshClass = GetDefault<UEleriGameSettings>()->RemovableStaticMeshClass;
ItemSeedCarouselClass = GetDefault<UEleriGameSettings>()->ItemSeedCarouselClass;
}
@@ -427,6 +433,53 @@ Element UItemDatabase::GetStrongestElement(const TArray<UItemDataAsset*>& Potion
return (Element)StrongestIndex;
}
void UItemDatabase::SpawnDecorationItem(UItemDataAsset* ItemAsset)
{
if (!ItemAsset || ItemAsset->ItemMesh.IsNull())
{
return;
}
ItemAsset->ItemMesh.LoadAsync(FLoadSoftObjectPathAsyncDelegate::CreateUObject(this, &UItemDatabase::OnDecorationItemLoaded, ItemAsset));
}
void UItemDatabase::RemoveDecorationItem(ARemovableStaticMeshActor* DecorationItem)
{
if (DecorationItem->ItemDataAsset && DecorationItem->bFromInventory)
{
UInventoryComponent* InventoryComponent = UMainBlueprintFunctionLibrary::GetPlayerInventory(GetWorld());
InventoryComponent->AddItemToInventory(DecorationItem->ItemDataAsset->GetPrimaryAssetId(), 1);
}
DecorationItem->Destroy();
}
void UItemDatabase::OnDecorationItemLoaded(const FSoftObjectPath& Path, UObject* Object, UItemDataAsset* ItemAsset)
{
UStaticMesh* StaticMesh = Cast<UStaticMesh>(Object);
if (!StaticMesh || !ItemAsset) return;
ACharacter* PlayerCharacter = UGameplayStatics::GetPlayerCharacter(GetWorld(), 0);
const FVector Location = PlayerCharacter->GetActorLocation() + (PlayerCharacter->GetActorForwardVector() * 1000.f);
FActorSpawnParameters SpawnParams;
SpawnParams.Instigator = PlayerCharacter;
SpawnParams.Owner = PlayerCharacter;
ARemovableStaticMeshActor* SpawnedActor = GetWorld()->SpawnActor<ARemovableStaticMeshActor>(RemovableStaticMeshClass, Location, FRotator::ZeroRotator, SpawnParams);
if (!SpawnedActor) return;
SpawnedActor->SetMobility(EComponentMobility::Movable);
SpawnedActor->Initialize(StaticMesh, ItemAsset);
UInventoryComponent* InventoryComponent = UMainBlueprintFunctionLibrary::GetPlayerInventory(GetWorld());
SpawnedActor->BindToItem(InventoryComponent);
InventoryComponent->RemoveItemFromInventory(ItemAsset->GetPrimaryAssetId(), 1);
UMoveActorsComponent* MoveActorsComponent = PlayerCharacter->GetComponentByClass<UMoveActorsComponent>();
if (!MoveActorsComponent) return;
MoveActorsComponent->StartObjectRemoval(true);
MoveActorsComponent->PickUpObjectForPlacing(SpawnedActor);
}
void FArrayOfItemRefs::SortByName()
{
ItemArray.Sort();

View File

@@ -58,67 +58,76 @@ protected:
public:
UPROPERTY(EditDefaultsOnly)
UPROPERTY(EditDefaultsOnly, Category = "Item Database")
TSubclassOf<AActor> ItemSeedCarouselClass;
UPROPERTY(EditDefaultsOnly, Category = "Item Database")
TSubclassOf<ARemovableStaticMeshActor> RemovableStaticMeshClass;
UPROPERTY(EditAnywhere, BlueprintReadOnly)
UPROPERTY(EditAnywhere, BlueprintReadOnly, Category = "Item Database")
TArray<FPrimaryAssetId> AllAssetIds;
UPROPERTY(EditAnywhere, BlueprintReadOnly)
UPROPERTY(EditAnywhere, BlueprintReadOnly, Category = "Item Database")
TArray<UItemDataAsset*> LoadedItems;
UPROPERTY(EditAnywhere, BlueprintReadOnly)
UPROPERTY(EditAnywhere, BlueprintReadOnly, Category = "Item Database")
TMap<Category, FArrayOfItemRefs> LoadedItemsByCategory;
UPROPERTY(VisibleAnywhere, BlueprintReadWrite)
UPROPERTY(VisibleAnywhere, BlueprintReadWrite, Category = "Item Database")
TArray<ASeedCarousel*> SeedsPlanted;
public:
UFUNCTION(BlueprintCallable)
UFUNCTION(BlueprintCallable, Category = "Item Database")
void WaterAllSeeds();
UFUNCTION(BlueprintCallable)
UFUNCTION(BlueprintCallable, Category = "Item Database")
bool DoChemicalAlignmentsMatch(TArray<int32> Alignments, TArray<int32> PotionAlignments);
UFUNCTION(BlueprintCallable)
UFUNCTION(BlueprintCallable, Category = "Item Database")
UItemDataAsset* GetPotionFromItems(TArray<UItemDataAsset*> Items, bool& Found);
UFUNCTION(BlueprintCallable)
UFUNCTION(BlueprintCallable, Category = "Item Database")
UItemDataAsset* GetPotionDataFromItems(TArray<UItemDataAsset*> Items);
UFUNCTION(BlueprintCallable)
UFUNCTION(BlueprintCallable, Category = "Item Database")
TArray<UItemDataAsset*> GetPotionsMatchingChemicalAlignment(UItemDataAsset* Ingredient);
UFUNCTION(BlueprintCallable)
UFUNCTION(BlueprintCallable, Category = "Item Database")
TArray<UItemDataAsset*> GetPotionsMatchingProperties(const TArray<UItemDataAsset*> &PotionList, TMap<ItemProperty, int32> PropertyList);
UFUNCTION(BlueprintCallable)
UFUNCTION(BlueprintCallable, Category = "Item Database")
UItemDataAsset* GetDataAssetFromId(FPrimaryAssetId AssetId);
UFUNCTION(BlueprintCallable)
UFUNCTION(BlueprintCallable, Category = "Item Database")
TArray<UItemDataAsset*> GetDataAssetsFromIds(TArray<FPrimaryAssetId> AssetIds);
UFUNCTION(BlueprintCallable)
UFUNCTION(BlueprintCallable, Category = "Item Database")
float CalculatePotionPurity(TMap<ItemProperty, int32> PropertyList, TArray<FPropertyStrength> MainProperties);
UFUNCTION(BlueprintCallable)
UFUNCTION(BlueprintCallable, Category = "Item Database")
int32 GetCrystalCostForPotion(UItemDataAsset* Potion);
UFUNCTION(BlueprintCallable)
UFUNCTION(BlueprintCallable, Category = "Item Database")
int32 GetCrystalCostForItems(TArray<UItemDataAsset*> Items);
UFUNCTION(BlueprintCallable)
UFUNCTION(BlueprintCallable, Category = "Item Database")
Element GetStrongestElement(const TArray<UItemDataAsset*>& PotionList);
UFUNCTION(BlueprintCallable, Category = "Item Database")
void SpawnDecorationItem(UItemDataAsset* ItemAsset);
void RemoveDecorationItem(ARemovableStaticMeshActor* DecorationItem);
protected:
UPROPERTY(VisibleAnywhere, BlueprintReadOnly)
UPROPERTY(VisibleAnywhere, BlueprintReadOnly, Category = "Item Database")
TArray<FItemPriceData> ItemPriceDataList;
protected:
void PrepareItemPriceData();
UFUNCTION()
void OnDecorationItemLoaded(const FSoftObjectPath& Path, UObject* Object, UItemDataAsset* ItemAsset);
UFUNCTION(BlueprintCallable, BlueprintPure)
UFUNCTION(BlueprintCallable, BlueprintPure, Category = "Item Database")
int32 GetCurrentPriceForItem(FPrimaryAssetId ItemId);
UFUNCTION(BlueprintCallable, BlueprintPure)
UFUNCTION(BlueprintCallable, BlueprintPure, Category = "Item Database")
TArray<int32> GetPriceHistoryForItem(FPrimaryAssetId ItemId);
};

View File

@@ -0,0 +1,26 @@
// Fill out your copyright notice in the Description page of Project Settings.
#include "SeedBedActor.h"
// Sets default values
ASeedBedActor::ASeedBedActor()
{
// 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 ASeedBedActor::BeginPlay()
{
Super::BeginPlay();
}
// Called every frame
void ASeedBedActor::Tick(float DeltaTime)
{
Super::Tick(DeltaTime);
}

View File

@@ -0,0 +1,25 @@
// Fill out your copyright notice in the Description page of Project Settings.
#pragma once
#include "CoreMinimal.h"
#include "GameFramework/Actor.h"
#include "SeedBedActor.generated.h"
UCLASS()
class PROJECTELERI_API ASeedBedActor : public AActor
{
GENERATED_BODY()
public:
// Sets default values for this actor's properties
ASeedBedActor();
protected:
// Called when the game starts or when spawned
virtual void BeginPlay() override;
public:
// Called every frame
virtual void Tick(float DeltaTime) override;
};