第一次提交
This commit is contained in:
@@ -0,0 +1,50 @@
|
||||
// Copyright 2025 https://yuewu.dev/en All Rights Reserved.
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "CoreMinimal.h"
|
||||
#include "GIS_DropperComponent.h"
|
||||
#include "GIS_CurrencyDropper.generated.h"
|
||||
|
||||
class UGIS_CurrencySystemComponent;
|
||||
|
||||
/**
|
||||
* Component for handling currency drop logic.
|
||||
* 处理货币掉落逻辑的组件。
|
||||
*/
|
||||
UCLASS(ClassGroup=(GIS), meta=(BlueprintSpawnableComponent))
|
||||
class GENERICINVENTORYSYSTEM_API UGIS_CurrencyDropper : public UGIS_DropperComponent
|
||||
{
|
||||
GENERATED_BODY()
|
||||
|
||||
public:
|
||||
/**
|
||||
* Initializes the currency dropper component at the start of play.
|
||||
* 在游戏开始时初始化货币掉落组件。
|
||||
*/
|
||||
virtual void BeginPlay() override;
|
||||
|
||||
/**
|
||||
* Executes the currency drop logic.
|
||||
* 执行货币掉落逻辑。
|
||||
*/
|
||||
virtual void Drop() override;
|
||||
|
||||
protected:
|
||||
/**
|
||||
* Reference to the currency system component.
|
||||
* 货币系统组件的引用。
|
||||
*/
|
||||
UPROPERTY()
|
||||
UGIS_CurrencySystemComponent* MyCurrency;
|
||||
|
||||
#if WITH_EDITOR
|
||||
/**
|
||||
* Validates the component's data in the editor.
|
||||
* 在编辑器中验证组件的数据。
|
||||
* @param Context The data validation context. 数据验证上下文。
|
||||
* @return The result of the data validation. 数据验证的结果。
|
||||
*/
|
||||
virtual EDataValidationResult IsDataValid(FDataValidationContext& Context) const override;
|
||||
#endif
|
||||
};
|
||||
@@ -0,0 +1,79 @@
|
||||
// Copyright 2025 https://yuewu.dev/en All Rights Reserved.
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "CoreMinimal.h"
|
||||
#include "Components/SceneComponent.h"
|
||||
#include "GIS_DropperComponent.generated.h"
|
||||
|
||||
/**
|
||||
* Abstract base class for a component that handles dropping items in the game world.
|
||||
* 用于在游戏世界中处理道具掉落的抽象基类组件。
|
||||
*/
|
||||
UCLASS(Abstract, ClassGroup=(GIS))
|
||||
class GENERICINVENTORYSYSTEM_API UGIS_DropperComponent : public UActorComponent
|
||||
{
|
||||
GENERATED_BODY()
|
||||
|
||||
public:
|
||||
/**
|
||||
* Constructor for the dropper component, sets default values for properties.
|
||||
* 掉落组件的构造函数,设置属性的默认值。
|
||||
*/
|
||||
UGIS_DropperComponent();
|
||||
|
||||
/**
|
||||
* Drops an item in the game world (authority only).
|
||||
* 在游戏世界中掉落道具(仅限权限)。
|
||||
*/
|
||||
UFUNCTION(BlueprintCallable, BlueprintAuthorityOnly, Category="GIS|Dropper")
|
||||
virtual void Drop();
|
||||
|
||||
protected:
|
||||
/**
|
||||
* Creates an instance of the pickup actor using the specified PickupActorClass.
|
||||
* 使用指定的PickupActorClass创建拾取Actor的实例。
|
||||
* @return The spawned pickup actor instance, or nullptr if creation fails. 创建的拾取Actor实例,如果创建失败则返回nullptr。
|
||||
*/
|
||||
UFUNCTION(BlueprintCallable, BlueprintNativeEvent, Category="GIS|Dropper")
|
||||
AActor* CreatePickupActorInstance();
|
||||
|
||||
/**
|
||||
* Calculates the origin point for dropping the item.
|
||||
* 计算道具掉落的原点位置。
|
||||
* @return The calculated drop origin as a vector. 掉落原点的向量。
|
||||
*/
|
||||
UFUNCTION(BlueprintCallable, BlueprintNativeEvent, Category="GIS|Dropper")
|
||||
FVector CalcDropOrigin() const;
|
||||
|
||||
/**
|
||||
* Calculates a random offset to apply to the drop location.
|
||||
* 计算应用于掉落位置的随机偏移量。
|
||||
* @return The random offset vector. 随机偏移量向量。
|
||||
*/
|
||||
UFUNCTION(BlueprintCallable, BlueprintNativeEvent, Category="GIS|Dropper")
|
||||
FVector CalcDropOffset() const;
|
||||
|
||||
/**
|
||||
* The class of the actor to spawn as the dropped item.
|
||||
* 作为掉落物生成的Actor类。
|
||||
* @attention Must implement the GIS_PickupActorInterface.
|
||||
* @注意 必须实现GIS_PickupActorInterface接口。
|
||||
*/
|
||||
UPROPERTY(EditAnywhere, BlueprintReadOnly, Category="Dropper", meta=(ExposeOnSpawn, MustImplement="/Script/GenericInventorySystem.GIS_PickupActorInterface"))
|
||||
TSoftClassPtr<AActor> PickupActorClass;
|
||||
|
||||
/**
|
||||
* Optional actor whose transform is used as the drop origin.
|
||||
* 可选的Actor,其变换用作掉落原点。
|
||||
*/
|
||||
UPROPERTY(EditInstanceOnly, BlueprintReadOnly, Category="Dropper")
|
||||
TObjectPtr<AActor> DropTransform{nullptr};
|
||||
|
||||
/**
|
||||
* The radius within which the item can be dropped.
|
||||
* 道具掉落的半径。
|
||||
*/
|
||||
UPROPERTY(EditAnywhere, BlueprintReadOnly, Category="Dropper", meta=(ExposeOnSpawn))
|
||||
float DropRadius = 50.f;
|
||||
};
|
||||
@@ -0,0 +1,51 @@
|
||||
// Copyright 2025 https://yuewu.dev/en All Rights Reserved.
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "CoreMinimal.h"
|
||||
#include "GameplayTagContainer.h"
|
||||
#include "GIS_DropperComponent.h"
|
||||
#include "Items/GIS_ItemInfo.h"
|
||||
#include "GIS_ItemDropperComponent.generated.h"
|
||||
|
||||
|
||||
class UGIS_InventorySystemComponent;
|
||||
|
||||
UCLASS(ClassGroup=(GIS), meta=(BlueprintSpawnableComponent))
|
||||
class GENERICINVENTORYSYSTEM_API UGIS_ItemDropperComponent : public UGIS_DropperComponent
|
||||
{
|
||||
GENERATED_BODY()
|
||||
|
||||
public:
|
||||
/**
|
||||
* Get the item infos of this dropper will drops.
|
||||
* 获取要掉落的道具信息。
|
||||
*/
|
||||
UFUNCTION(BlueprintCallable, Category="GIS|Dropper")
|
||||
TArray<FGIS_ItemInfo> GetItemsToDrop() const;
|
||||
|
||||
virtual void Drop() override;
|
||||
|
||||
protected:
|
||||
virtual void BeginPlay() override;
|
||||
|
||||
virtual TArray<FGIS_ItemInfo> GetItemsToDropInternal() const;
|
||||
virtual void DropItemsInternal(const TArray<FGIS_ItemInfo>& ItemInfos);
|
||||
|
||||
virtual void DropInventoryPickup(const TArray<FGIS_ItemInfo>& ItemInfos);
|
||||
virtual void DropItemPickup(const FGIS_ItemInfo& ItemInfo);
|
||||
|
||||
/**
|
||||
* Target collection to drop.
|
||||
* 指定要掉落库存中的哪个集合里的道具.
|
||||
*/
|
||||
UPROPERTY(EditAnywhere, BlueprintReadOnly, Category="Dropper", meta=(Categories="GIS.Collection"))
|
||||
FGameplayTag CollectionTag;
|
||||
|
||||
/**
|
||||
* If the drops is inventory pickup or item pickups?
|
||||
* 指定以InventoryPickup的方式掉落还是以ItemPickup
|
||||
*/
|
||||
UPROPERTY(EditAnywhere, BlueprintReadOnly, Category="Dropper")
|
||||
bool bDropAsInventory{true};
|
||||
};
|
||||
@@ -0,0 +1,55 @@
|
||||
// Copyright 2025 https://yuewu.dev/en All Rights Reserved.
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "CoreMinimal.h"
|
||||
#include "GIS_ItemDropperComponent.h"
|
||||
#include "GIS_RandomItemDropperComponent.generated.h"
|
||||
|
||||
/**
|
||||
* Component for handling random item drop logic.
|
||||
* 处理随机道具掉落逻辑的组件。
|
||||
*/
|
||||
UCLASS(ClassGroup=(GIS), meta=(BlueprintSpawnableComponent))
|
||||
class GENERICINVENTORYSYSTEM_API UGIS_RandomItemDropperComponent : public UGIS_ItemDropperComponent
|
||||
{
|
||||
GENERATED_BODY()
|
||||
|
||||
protected:
|
||||
/**
|
||||
* Retrieves the list of items to drop randomly.
|
||||
* 随机获取要掉落的道具列表。
|
||||
* @return Array of item information for dropped items. 掉落道具的信息数组。
|
||||
*/
|
||||
virtual TArray<FGIS_ItemInfo> GetItemsToDropInternal() const override;
|
||||
|
||||
/**
|
||||
* Selects a random item from the provided list based on weights.
|
||||
* 根据权重从提供的列表中随机选择一个道具。
|
||||
* @param ItemInfos List of item information to choose from. 可选择的道具信息列表。
|
||||
* @param Sum Total weight sum for randomization. 用于随机化的总权重和。
|
||||
* @return Reference to the selected item information. 选中的道具信息的引用。
|
||||
*/
|
||||
const FGIS_ItemInfo& GetRandomItemInfo(const TArray<FGIS_ItemInfo>& ItemInfos, int32 Sum) const;
|
||||
|
||||
/**
|
||||
* Determines if items are dropped randomly.
|
||||
* 确定是否随机掉落道具。
|
||||
*/
|
||||
UPROPERTY(EditAnywhere, BlueprintReadOnly, Category="Dropper", meta=(DisplayAfter="bDropAsInventory"))
|
||||
bool bRandomDrop{false};
|
||||
|
||||
/**
|
||||
* Minimum number of items to drop when random drop is enabled.
|
||||
* 启用随机掉落时掉落的最小道具数量。
|
||||
*/
|
||||
UPROPERTY(EditAnywhere, BlueprintReadOnly, Category="Dropper", meta=(EditCondition="bRandomDrop", ClampMin=1))
|
||||
int32 MinAmount{1};
|
||||
|
||||
/**
|
||||
* Maximum number of items to drop when random drop is enabled.
|
||||
* 启用随机掉落时掉落的最大道具数量。
|
||||
*/
|
||||
UPROPERTY(EditAnywhere, BlueprintReadOnly, Category="Dropper", meta=(EditCondition="bRandomDrop", ClampMin=1))
|
||||
int32 MaxAmount{2};
|
||||
};
|
||||
Reference in New Issue
Block a user