113 lines
3.2 KiB
C++

#pragma once
#include "CoreMinimal.h"
#include "Engine/DataAsset.h"
#include "ProjectFish/Definations.h"
#include "FishingMapSubSystem.generated.h"
DECLARE_DYNAMIC_MULTICAST_DELEGATE_TwoParams(FOnNodeStateChange, FGuid, NodeID, EMapNodeState, NewState);
// 简化的地图节点
UCLASS(BlueprintType)
class PROJECTFISH_API UFishingMapNode : public UObject
{
GENERATED_BODY()
public:
UFishingMapNode();
void RandomNodeType();
UPROPERTY(EditAnywhere, BlueprintReadWrite, meta = (ToolTip = "节点ID"))
FGuid NodeID;
UPROPERTY(EditAnywhere, BlueprintReadWrite, meta = (ToolTip = "节点类型"))
EMapNodeType NodeType = EMapNodeType::Battle;
UPROPERTY(EditAnywhere, BlueprintReadWrite, meta = (ToolTip = "节点状态"))
EMapNodeState NodeState = EMapNodeState::Moveable;
UPROPERTY(EditAnywhere, BlueprintReadWrite, meta = (ToolTip = "层级索引"))
int32 LayerIndex = 0;
UPROPERTY(EditAnywhere, BlueprintReadWrite, meta = (ToolTip = "在层内的索引"))
int32 IndexInLayer = 0;
UPROPERTY(EditAnywhere, BlueprintReadWrite, meta = (ToolTip = "连接的下层节点ID"))
TArray<FGuid> ConnectedNodes;
UPROPERTY(EditAnywhere, BlueprintReadWrite, meta = (ToolTip = "节点位置"))
FVector2D Position = FVector2D::ZeroVector;
};
/**
* 简化的地图生成系统
*/
UCLASS(BlueprintType)
class PROJECTFISH_API UFishingMapSubSystem : public UGameInstanceSubsystem
{
GENERATED_BODY()
public:
UFishingMapSubSystem();
UPROPERTY(EditAnywhere, BlueprintReadWrite, meta = (ToolTip = "地图配置"))
class UMapConfigAsset* MapConfig;
UPROPERTY(BlueprintReadOnly, meta = (ToolTip = "所有节点"))
TArray<TObjectPtr<UFishingMapNode>> AllNodes;
UPROPERTY(BlueprintReadOnly, meta = (ToolTip = "所有连线"))
TArray<FSimpleConnection> AllConnections;
UPROPERTY(BlueprintReadOnly, meta = (ToolTip = "按层级组织的节点"))
TArray<FMapLayer> AllLayers;
UPROPERTY(BlueprintAssignable)
FOnNodeStateChange OnNodeStateChange;
UPROPERTY(BlueprintReadWrite)
FGuid PlayerPosNodeID;
// 生成地图
UFUNCTION(BlueprintCallable, Category = "FishingMap")
void GenerateMap();
// 使用配置生成地图
void GenerateMapWithConfig(const UMapConfigAsset* Config);
// 获取总层数
int32 GetLayerCount() const { return AllLayers.Num(); }
UFUNCTION(BlueprintPure, Category = "FishingMap")
int32 GetNodeAtLayerIndex(FGuid NodeID) const;
UFUNCTION(BlueprintPure, Category = "FishingMap")
class UFishingMapNode* GetNode(FGuid NodeID) ;
// 清空地图
UFUNCTION(BlueprintCallable, Category = "FishingMap")
void ClearMap();
UFUNCTION(BlueprintCallable, Category = "FishingMap")
void MoveToNode(FGuid NodeID);
private:
void GetAllConnectedNodes(FGuid NodeID, TArray<FGuid>& ConnectedNodes);
protected:
// 生成节点
void GenerateNodes();
// 生成连线(无交叉)
void GenerateConnections();
// 计算节点位置
void CalculateNodePositions();
// 生成无交叉的连接方案
TArray<FSimpleConnection> GenerateNonCrossingConnections(int32 FromLayer, int32 ToLayer);
};