# 地牢结构

## 概述

## 进入地牢

## 大厅

## 地牢层数

## 离开地牢

## 模块结构

### 地牢实例 Dungeon Instance

<pre class="language-cpp" data-title="DungeonInstance.c" data-overflow="wrap" data-line-numbers><code class="lang-cpp">class CHARMINGCRAFT_API ANativeBaseDungeonInstance : public AInfo
{
	GENERATED_BODY()

public:
	UPROPERTY(BlueprintReadWrite, EditAnywhere)
	bool bHasHub = true;
	UPROPERTY(BlueprintReadWrite, EditAnywhere)
	int32 MaxChildDungeonsPerInstance = 1;
	UPROPERTY(BlueprintReadWrite, EditAnywhere)
<strong>	bool bLoadDungeonsWorldsByNeed = true; 
</strong>	
	// Predefine the map for each child dungeons
	UPROPERTY(BlueprintReadWrite, EditAnywhere)
	TArray&#x3C;TSoftObjectPtr&#x3C;UWorld>> ChildDungeonsWorlds;
	// 
	UPROPERTY(BlueprintReadWrite, EditAnywhere)
	TArray&#x3C;FCharmingCraftWorld> ChildDungeonsWorldsInstance;
	// Define player in which child dungeons, for example, &#x3C;PlayerA, 3> means
	// PlayerA is in 3rd ChildDungeon;
	UPROPERTY(BlueprintReadWrite, EditAnywhere)
	TMap&#x3C;ACharacter *, int> DungeonInstancePlayerData;
};
</code></pre>

地牢实例包含该地牢的所有层的地图 **Uworld** 并且在玩家加载地牢时动态地生成在场景中并由**DungeonHandler** 管理,当玩家退出地牢时该实例会被 **DungeonHandler** 摧毁.

{% hint style="warning" %}
地牢实例并非指向单一玩家,而是由整个世界管理器和地牢管理器共同管理, 若为团体地牢则多个玩家可以进入同一个地牢实例中
{% endhint %}

`ChildDungeonsWorlds` 该数组存储地牢实例的所有地图模板, `index 0` 指向的是 *地牢大厅/准备场所*

`ChildDungeonsWorldsInstance` 该数组存储当前地牢实例加载的世界实例, 地牢加载的世界实例应当与世界管理器中也存在一份引用并且在地牢实例摧毁时也应该在世界管理器中摧毁

`DungeonInstancePlayerData` 存储玩家当前在这个地牢实例中的探索进度, `TMap`的第一个元素是玩家对象,第二个元素是当前地牢层数

{% hint style="info" %}
在最初版本地牢中不提供额外的房间比如说购买或者功能性房间, 要拓展这部分内容需要对玩家在地牢中探索的数据结构进行更换
{% endhint %}

### 地牢处理器 Dungeon Handler

{% code title=" DungeonHandler.c" lineNumbers="true" fullWidth="false" %}

```cpp
class CHARMINGCRAFT_API UNativeDungeonHandler : public UObject, public ICoreManagerInterface
{
	GENERATED_BODY()

public:
	UPROPERTY(BlueprintReadWrite, VisibleAnywhere)
	TSet<TObjectPtr<ANativeBaseDungeonInstance>> LoadedDungeonInstances;

public:
	UNativeDungeonHandler();

	bool AddInstanceToSet(ANativeBaseDungeonInstance * DungeonInstance);
	

public:
	virtual UCharmingCraftInstance* GetGameInstance_Implementation() override;
};
```

{% endcode %}

**地牢处理器** 存储游戏加载的 **地牢实例** ,每当玩家创建新的地牢时地牢处理器会加载地牢实例到 `LoadedDungeonInstances` 中并通知世界管理器加载当前玩家探索地牢层的世界地图随时准备展示到玩家视野中. 当地牢内所有玩家退出或地牢关闭/失效时, 地牢处理器则会首先通知世界管理器移除该地牢实例所加载的地牢地图并在移除完毕后再移除地牢实例.


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://charmingcraft.caizii.org/you-xi-nei-rong/di-lao-yu-fu-ben/di-lao-jie-gou.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
