This repository has been archived on 2026-05-24. You can view files and clone it. You cannot open issues or pull requests or push a commit.
Files
AgrarianGameArchive/Source/AgrarianGame/AgrarianInventoryComponent.h
T
2026-05-17 11:05:28 -07:00

61 lines
2.0 KiB
C++

// Copyright Pacificao. All Rights Reserved.
#pragma once
#include "CoreMinimal.h"
#include "Components/ActorComponent.h"
#include "AgrarianTypes.h"
#include "AgrarianInventoryComponent.generated.h"
DECLARE_DYNAMIC_MULTICAST_DELEGATE(FAgrarianInventoryChangedSignature);
UCLASS(ClassGroup = (Agrarian), BlueprintType, Blueprintable, meta = (BlueprintSpawnableComponent))
class UAgrarianInventoryComponent : public UActorComponent
{
GENERATED_BODY()
public:
UAgrarianInventoryComponent();
virtual void GetLifetimeReplicatedProps(TArray<FLifetimeProperty>& OutLifetimeProps) const override;
UPROPERTY(BlueprintAssignable, Category = "Agrarian|Inventory")
FAgrarianInventoryChangedSignature OnInventoryChanged;
UPROPERTY(EditAnywhere, BlueprintReadOnly, ReplicatedUsing = OnRep_Items, Category = "Agrarian|Inventory")
TArray<FAgrarianItemStack> Items;
UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "Agrarian|Inventory", meta = (ClampMin = "1"))
int32 MaxSlots = 24;
UFUNCTION(BlueprintCallable, Category = "Agrarian|Inventory")
bool HasItem(FName ItemId, int32 Quantity) const;
UFUNCTION(BlueprintCallable, Category = "Agrarian|Inventory")
int32 GetItemCount(FName ItemId) const;
UFUNCTION(BlueprintCallable, Category = "Agrarian|Inventory")
float GetTotalWeight() const;
UFUNCTION(BlueprintCallable, Category = "Agrarian|Inventory")
bool AddItem(const FAgrarianItemStack& Stack);
UFUNCTION(BlueprintCallable, Category = "Agrarian|Inventory")
bool RemoveItem(FName ItemId, int32 Quantity);
UFUNCTION(BlueprintCallable, Category = "Agrarian|Inventory")
bool ExtractItem(FName ItemId, int32 Quantity, FAgrarianItemStack& OutStack);
UFUNCTION(Server, Reliable, BlueprintCallable, Category = "Agrarian|Inventory")
void ServerAddItem(const FAgrarianItemStack& Stack);
UFUNCTION(Server, Reliable, BlueprintCallable, Category = "Agrarian|Inventory")
void ServerRemoveItem(FName ItemId, int32 Quantity);
protected:
UFUNCTION()
void OnRep_Items();
void BroadcastInventoryChanged();
};