修复地图生成逻辑bug
This commit is contained in:
parent
cfa74a426d
commit
776de95929
BIN
ProjectFish/Binaries/Win64/UnrealEditor-ProjectFish-0001.dll
Normal file
BIN
ProjectFish/Binaries/Win64/UnrealEditor-ProjectFish-0001.dll
Normal file
Binary file not shown.
BIN
ProjectFish/Binaries/Win64/UnrealEditor-ProjectFish-0002.dll
Normal file
BIN
ProjectFish/Binaries/Win64/UnrealEditor-ProjectFish-0002.dll
Normal file
Binary file not shown.
BIN
ProjectFish/Binaries/Win64/UnrealEditor-ProjectFish-0003.dll
Normal file
BIN
ProjectFish/Binaries/Win64/UnrealEditor-ProjectFish-0003.dll
Normal file
Binary file not shown.
BIN
ProjectFish/Binaries/Win64/UnrealEditor-ProjectFish-0004.dll
Normal file
BIN
ProjectFish/Binaries/Win64/UnrealEditor-ProjectFish-0004.dll
Normal file
Binary file not shown.
BIN
ProjectFish/Binaries/Win64/UnrealEditor-ProjectFish-0005.dll
Normal file
BIN
ProjectFish/Binaries/Win64/UnrealEditor-ProjectFish-0005.dll
Normal file
Binary file not shown.
BIN
ProjectFish/Binaries/Win64/UnrealEditor-ProjectFish-0006.dll
Normal file
BIN
ProjectFish/Binaries/Win64/UnrealEditor-ProjectFish-0006.dll
Normal file
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
@ -2,7 +2,7 @@
|
||||
"BuildId": "37670630",
|
||||
"Modules":
|
||||
{
|
||||
"ProjectFish": "UnrealEditor-ProjectFish.dll",
|
||||
"ProjectFishEditor": "UnrealEditor-ProjectFishEditor.dll"
|
||||
"ProjectFish": "UnrealEditor-ProjectFish-0006.dll",
|
||||
"ProjectFishEditor": "UnrealEditor-ProjectFishEditor-0006.dll"
|
||||
}
|
||||
}
|
||||
BIN
ProjectFish/Content/Gameplay/MapSystem/MapConfig.uasset
Normal file
BIN
ProjectFish/Content/Gameplay/MapSystem/MapConfig.uasset
Normal file
Binary file not shown.
BIN
ProjectFish/Content/Maps/MaySystem.umap
Normal file
BIN
ProjectFish/Content/Maps/MaySystem.umap
Normal file
Binary file not shown.
@ -68,7 +68,7 @@ void UFishingMapSystem::ClearMap()
|
||||
void UFishingMapSystem::GenerateNodes()
|
||||
{
|
||||
AllLayers.SetNum(MapConfig->TotalLayers);
|
||||
|
||||
UE_LOG(LogTemp, Warning, TEXT("生成layer层数: %d "), MapConfig->TotalLayers );
|
||||
for (int32 LayerIndex = 0; LayerIndex < MapConfig->TotalLayers ; ++LayerIndex)
|
||||
{
|
||||
if (LayerIndex == MapConfig->TotalLayers - 1)
|
||||
@ -98,7 +98,7 @@ void UFishingMapSystem::GenerateNodes()
|
||||
AllLayers[LayerIndex].AddNode(NewNode);
|
||||
}
|
||||
}
|
||||
|
||||
UE_LOG(LogTemp, Warning, TEXT("layer:%d node: %d "), LayerIndex, AllLayers[LayerIndex].GetNodeNum() );
|
||||
}
|
||||
}
|
||||
|
||||
@ -157,19 +157,24 @@ TArray<FSimpleConnection> UFishingMapSystem::GenerateNonCrossingConnections(int3
|
||||
{
|
||||
TArray<FSimpleConnection> Connections;
|
||||
|
||||
UE_LOG(LogTemp, Warning, TEXT("生成层级 %d -> %d 的随机连接"),FromLayer, ToLayer);
|
||||
if (FromLayer == AllLayers.Num() - 2)
|
||||
{
|
||||
//倒数第二行,所有都连接到最终boss房间
|
||||
UE_LOG(LogTemp, Warning, TEXT("生成boss节点的连接"));
|
||||
FMapLayer FromNodes = AllLayers[FromLayer];
|
||||
FGuid BossID = AllLayers[ToLayer].GetNode(0)->NodeID;
|
||||
for (int32 NodeIndex = 0; NodeIndex < FromNodes.GetNodeNum(); ++NodeIndex)
|
||||
{
|
||||
Connections.Add(FSimpleConnection(FromNodes.GetNode(NodeIndex)->NodeID, BossID));
|
||||
UE_LOG(LogTemp, Warning, TEXT("下层 %d -> 上层 %d "),GetNodeAtLayerIndex(FromNodes.GetNode(NodeIndex)->NodeID),
|
||||
GetNodeAtLayerIndex(BossID));
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
//第一步 随机为每个fromnode 分配指定范围的上层节点
|
||||
UE_LOG(LogTemp, Warning, TEXT("第一轮生成节点的连接"));
|
||||
FMapLayer FromNodes = AllLayers[FromLayer];
|
||||
FMapLayer ToNodes = AllLayers[ToLayer];
|
||||
int32 LastToNodeIndex = 0;
|
||||
@ -181,31 +186,37 @@ TArray<FSimpleConnection> UFishingMapSystem::GenerateNonCrossingConnections(int3
|
||||
int32 connectionEndIndex = FMath::Max(connectionBeginIndex,
|
||||
(FMath::RandRange(connectionBeginIndex, endIndex + (FromNodes.GetNodeNum() - NodeIndex)) - (FromNodes.GetNodeNum() - NodeIndex)) );
|
||||
//随机指定当前node 连接上层node的范围
|
||||
LastToNodeIndex = FMath::RandRange(connectionBeginIndex, connectionEndIndex);
|
||||
for(int32 i = connectionEndIndex; i < connectionEndIndex; ++i)
|
||||
LastToNodeIndex = connectionEndIndex;
|
||||
for(int32 i = connectionBeginIndex; i <= connectionEndIndex; ++i)
|
||||
{
|
||||
//添加连线
|
||||
Connections.Add(FSimpleConnection(FromNodes.GetNode(NodeIndex)->NodeID, ToNodes.GetNode(connectionEndIndex)->NodeID));
|
||||
|
||||
UE_LOG(LogTemp, Warning, TEXT("下层 %d -> 上层 %d "),GetNodeAtLayerIndex(FromNodes.GetNode(NodeIndex)->NodeID),
|
||||
GetNodeAtLayerIndex(ToNodes.GetNode(connectionEndIndex)->NodeID));
|
||||
}
|
||||
}
|
||||
//第二步 确保tolayer 每个节点都有连接线,没有连接线的分配 指定范围内的下层节点
|
||||
if(LastToNodeIndex != ToNodes.GetNodeNum() - 1)
|
||||
{
|
||||
UE_LOG(LogTemp, Warning, TEXT("第二轮生成节点的连接"));
|
||||
//还有上层节点是没有被连线状态,都连接到下层的最后一个节点
|
||||
for(int32 ToNodeIndex = LastToNodeIndex; ToNodeIndex < ToNodes.GetNodeNum(); ++ToNodeIndex)
|
||||
{
|
||||
Connections.Add(FSimpleConnection(FromNodes.GetNode(FromNodes.GetNodeNum() - 1)->NodeID, ToNodes.GetNode(ToNodeIndex)->NodeID));
|
||||
UE_LOG(LogTemp, Warning, TEXT("下层 %d -> 上层 %d "),GetNodeAtLayerIndex(FromNodes.GetNode(FromNodes.GetNodeNum() - 1)->NodeID),
|
||||
GetNodeAtLayerIndex(ToNodes.GetNode(ToNodeIndex)->NodeID));
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
UE_LOG(LogTemp, Log, TEXT("生成层级 %d -> %d 的随机连接"),FromLayer, ToLayer);
|
||||
for(auto connection: Connections)
|
||||
{
|
||||
UE_LOG(LogTemp, Log, TEXT("下层 %d -> 上层 %d "),GetNodeAtLayerIndex(connection.FromNodeID),
|
||||
GetNodeAtLayerIndex(connection.FromNodeID));
|
||||
}
|
||||
|
||||
// for(auto connection: Connections)
|
||||
// {
|
||||
// UE_LOG(LogTemp, Warning, TEXT("下层 %d -> 上层 %d "),GetNodeAtLayerIndex(connection.FromNodeID),
|
||||
// GetNodeAtLayerIndex(connection.ToNodeID));
|
||||
// }
|
||||
|
||||
|
||||
return Connections;
|
||||
|
||||
@ -66,7 +66,6 @@ public:
|
||||
void GenerateMap();
|
||||
|
||||
// 使用配置生成地图
|
||||
UFUNCTION(BlueprintCallable, Category = "FishingMap")
|
||||
void GenerateMapWithConfig(const UMapConfigAsset* Config);
|
||||
|
||||
|
||||
|
||||
@ -1,187 +0,0 @@
|
||||
#include "SimpleMapExample.h"
|
||||
#include "Engine/Engine.h"
|
||||
|
||||
ASimpleMapExample::ASimpleMapExample()
|
||||
{
|
||||
PrimaryActorTick.bCanEverTick = false;
|
||||
|
||||
// 创建地图系统
|
||||
MapSystem = CreateDefaultSubobject<UFishingMapSystem>(TEXT("MapSystem"));
|
||||
}
|
||||
|
||||
void ASimpleMapExample::BeginPlay()
|
||||
{
|
||||
Super::BeginPlay();
|
||||
|
||||
|
||||
}
|
||||
|
||||
void ASimpleMapExample::GenerateCustomMap()
|
||||
{
|
||||
if (!MapSystem)
|
||||
{
|
||||
UE_LOG(LogTemp, Error, TEXT("MapSystem 未初始化"));
|
||||
return;
|
||||
}
|
||||
|
||||
// 生成地图
|
||||
MapSystem->GenerateMap();
|
||||
|
||||
UE_LOG(LogTemp, Log, TEXT("生成自定义地图完成:%d层"), MapSystem->GetLayerCount());
|
||||
//PrintMapInfo();
|
||||
}
|
||||
|
||||
// void ASimpleMapExample::PrintMapInfo()
|
||||
// {
|
||||
// if (!MapSystem)
|
||||
// {
|
||||
// return;
|
||||
// }
|
||||
//
|
||||
// UE_LOG(LogTemp, Log, TEXT("========== 地图信息 =========="));
|
||||
// UE_LOG(LogTemp, Log, TEXT("总层数: %d"), MapSystem->GetLayerCount());
|
||||
// UE_LOG(LogTemp, Log, TEXT("总节点数: %d"), MapSystem->AllNodes.Num());
|
||||
// UE_LOG(LogTemp, Log, TEXT("总连线数: %d"), MapSystem->AllConnections.Num());
|
||||
//
|
||||
// // 打印每层信息
|
||||
// for (int32 LayerIndex = 0; LayerIndex < MapSystem->GetLayerCount(); ++LayerIndex)
|
||||
// {
|
||||
// TArray<USimpleMapNode*> LayerNodes = MapSystem->GetNodesInLayer(LayerIndex);
|
||||
// UE_LOG(LogTemp, Log, TEXT("第%d层: %d个节点"), LayerIndex + 1, LayerNodes.Num());
|
||||
//
|
||||
// for (int32 NodeIndex = 0; NodeIndex < LayerNodes.Num(); ++NodeIndex)
|
||||
// {
|
||||
// USimpleMapNode* Node = LayerNodes[NodeIndex];
|
||||
// if (Node)
|
||||
// {
|
||||
// FString NodeTypeName;
|
||||
// switch (Node->NodeType)
|
||||
// {
|
||||
// case EMapNodeType::Unknown:
|
||||
// NodeTypeName = TEXT("起始");
|
||||
// break;
|
||||
// case EMapNodeType::Enemy:
|
||||
// NodeTypeName = TEXT("敌人");
|
||||
// break;
|
||||
// case EMapNodeType::Elite:
|
||||
// NodeTypeName = TEXT("精英");
|
||||
// break;
|
||||
// case EMapNodeType::Treasure:
|
||||
// NodeTypeName = TEXT("财宝");
|
||||
// break;
|
||||
// case EMapNodeType::Rest:
|
||||
// NodeTypeName = TEXT("休息");
|
||||
// break;
|
||||
// case EMapNodeType::Merchant:
|
||||
// NodeTypeName = TEXT("商人");
|
||||
// break;
|
||||
// default:
|
||||
// NodeTypeName = TEXT("未知");
|
||||
// break;
|
||||
// }
|
||||
//
|
||||
// UE_LOG(LogTemp, Log, TEXT(" 节点%d: %s (位置: %.0f, %.0f) 连接数: %d"),
|
||||
// NodeIndex + 1, *NodeTypeName,
|
||||
// Node->Position.X, Node->Position.Y,
|
||||
// Node->ConnectedNodes.Num());
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
//
|
||||
// UE_LOG(LogTemp, Log, TEXT("==============================="));
|
||||
// }
|
||||
|
||||
// void ASimpleMapExample::VisualizeMap()
|
||||
// {
|
||||
// if (!MapSystem)
|
||||
// {
|
||||
// UE_LOG(LogTemp, Warning, TEXT("MapSystem 未初始化,无法可视化"));
|
||||
// return;
|
||||
// }
|
||||
//
|
||||
// if (MapSystem->AllNodes.Num() == 0)
|
||||
// {
|
||||
// UE_LOG(LogTemp, Warning, TEXT("地图为空,请先生成地图"));
|
||||
// return;
|
||||
// }
|
||||
//
|
||||
// #if WITH_EDITOR
|
||||
// // 在编辑器中绘制调试信息
|
||||
// UWorld* World = GetWorld();
|
||||
// if (World)
|
||||
// {
|
||||
// // 清除之前的调试绘制
|
||||
// FlushPersistentDebugLines(World);
|
||||
//
|
||||
// // 绘制节点
|
||||
// for (USimpleMapNode* Node : MapSystem->AllNodes)
|
||||
// {
|
||||
// if (Node)
|
||||
// {
|
||||
// FVector NodeLocation(Node->Position.X, Node->Position.Y, 0.0f);
|
||||
//
|
||||
// // 根据节点类型选择颜色
|
||||
// FColor NodeColor = FColor::White;
|
||||
// switch (Node->NodeType)
|
||||
// {
|
||||
// case EMapNodeType::Unknown:
|
||||
// NodeColor = FColor::Green;
|
||||
// break;
|
||||
// case EMapNodeType::Enemy:
|
||||
// NodeColor = FColor::Red;
|
||||
// break;
|
||||
// case EMapNodeType::Elite:
|
||||
// NodeColor = FColor::Purple;
|
||||
// break;
|
||||
// case EMapNodeType::Treasure:
|
||||
// NodeColor = FColor::Yellow;
|
||||
// break;
|
||||
// case EMapNodeType::Rest:
|
||||
// NodeColor = FColor::Blue;
|
||||
// break;
|
||||
// case EMapNodeType::Merchant:
|
||||
// NodeColor = FColor::Orange;
|
||||
// break;
|
||||
// }
|
||||
//
|
||||
// // 绘制节点球体
|
||||
// DrawDebugSphere(World, NodeLocation, 50.0f, 12, NodeColor, true, 10.0f, 0, 2.0f);
|
||||
// }
|
||||
// }
|
||||
//
|
||||
// // 绘制连线
|
||||
// for (const FSimpleConnection& Connection : MapSystem->AllConnections)
|
||||
// {
|
||||
// USimpleMapNode* FromNode = nullptr;
|
||||
// USimpleMapNode* ToNode = nullptr;
|
||||
//
|
||||
// // 找到连接的节点
|
||||
// for (USimpleMapNode* Node : MapSystem->AllNodes)
|
||||
// {
|
||||
// if (Node)
|
||||
// {
|
||||
// if (Node->NodeID == Connection.FromNodeID)
|
||||
// {
|
||||
// FromNode = Node;
|
||||
// }
|
||||
// else if (Node->NodeID == Connection.ToNodeID)
|
||||
// {
|
||||
// ToNode = Node;
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
//
|
||||
// if (FromNode && ToNode)
|
||||
// {
|
||||
// FVector FromLocation(FromNode->Position.X, FromNode->Position.Y, 0.0f);
|
||||
// FVector ToLocation(ToNode->Position.X, ToNode->Position.Y, 0.0f);
|
||||
//
|
||||
// // 绘制连线
|
||||
// DrawDebugLine(World, FromLocation, ToLocation, FColor::Cyan, true, 10.0f, 0, 3.0f);
|
||||
// }
|
||||
// }
|
||||
//
|
||||
// UE_LOG(LogTemp, Log, TEXT("地图可视化完成"));
|
||||
// }
|
||||
// #endif
|
||||
// }
|
||||
@ -1,38 +0,0 @@
|
||||
#pragma once
|
||||
|
||||
#include "CoreMinimal.h"
|
||||
#include "GameFramework/Actor.h"
|
||||
#include "FishingMapSystem.h"
|
||||
#include "SimpleMapExample.generated.h"
|
||||
|
||||
/**
|
||||
* 简单地图系统使用示例
|
||||
*/
|
||||
UCLASS(BlueprintType, Blueprintable)
|
||||
class PROJECTFISH_API ASimpleMapExample : public AActor
|
||||
{
|
||||
GENERATED_BODY()
|
||||
|
||||
public:
|
||||
ASimpleMapExample();
|
||||
|
||||
protected:
|
||||
virtual void BeginPlay() override;
|
||||
|
||||
public:
|
||||
UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "Map")
|
||||
TObjectPtr<UFishingMapSystem> MapSystem;
|
||||
|
||||
|
||||
// 生成自定义地图
|
||||
UFUNCTION(BlueprintCallable, Category = "Map")
|
||||
void GenerateCustomMap();
|
||||
|
||||
// // 打印地图信息
|
||||
// UFUNCTION(BlueprintCallable, Category = "Map")
|
||||
// void PrintMapInfo();
|
||||
|
||||
// // 可视化地图(在编辑器中)
|
||||
// UFUNCTION(BlueprintCallable, Category = "Map", CallInEditor = true)
|
||||
// void VisualizeMap();
|
||||
};
|
||||
Loading…
x
Reference in New Issue
Block a user