> ## Documentation Index
> Fetch the complete documentation index at: https://devdocs.xbox.com/llms.txt
> Use this file to discover all available pages before exploring further.

# 為票證指定屬性

> 了解如何將玩家和票證屬性附加至 PlayFab 配對票證，讓佇列規則能評估技能、延遲和其他準則。

規則會根據玩家指定的屬性，決定要配對哪些票證。這些屬性可以透過以下兩種方式之一指定：

1. 在建立票證要求中
2. 在玩家的實體中

本教學課程說明如何指定這些屬性。

## 在建立票證要求中指定

對於設定為屬性類型「User」的規則，屬性會在 `CreateMatchmakingTicket` 要求中指定，與玩家實體一起放在屬性 `DataObject` 內。

```json theme={null}
POST https://{{TitleId}}.playfabapi.com/Match/CreateMatchmakingTicket
{
    "Creator": {
        "Entity": {
            "Id": "A8140AB9109712B",
            "Type": "title_player_account",
            "TypeString": "title_player_account"
        },
        "Attributes": {
            "DataObject": {
                "mu": 16.0,
                "sigma": 1.8,
                "nestExample": {
                    "exp": 1500
                }
            }
        }
    },
    "MembersToMatchWith": [],
    "GiveUpAfterSeconds": 2,
    "QueueName": "SkillRuleQueue"
}
```

以下是具有 `DifferenceRule` 的佇列設定範例。此規則包含屬性路徑和來源，會取得上述 `CreateMatchmakingTicket` 要求所指定的值 16.0。

```json theme={null}
"MatchmakingQueue": {
    "Name": "SkillRuleQueue",
    "MinMatchSize": 2,
    "MaxMatchSize": 2,
    "ServerAllocationEnabled": false,
    "Rules": [
        {
            "Type": "DifferenceRule",
            "Difference": 3,
            "MergeFunction": "Average",
            "Attribute": {
                "Path": "mu",
                "Source": "User"
            },
            "AttributeNotSpecifiedBehavior": "MatchAny",
            "Weight": 1,
            "Name": "SkillRule",
            "SecondsUntilOptional": 10
        }
    ]
}
```

<Note>
  規則可以使用 JSON Path 在 `DataObject` 中巡覽。將 Path 欄位取代為 "nestExample.exp"，會讓規則對上面建立的票證使用值 1500。
</Note>

## 透過玩家實體指定

對於屬性類型為「Player Entity」的規則，屬性是透過另外呼叫 `SetObjects` API 來指定。

這可讓資料為使用者儲存，而不需要遊戲在每次建立票證呼叫時指定。對於會為使用者持續保存的值，或無法信任使用者自行提交的值，這種方式可能更合適。以下顯示此 `SetObjects` 呼叫的範例。

```json theme={null}
POST https://{{TitleID}}.playfabapi.com/Object/SetObjects
{
    "Objects": [
        {
            "ObjectName": "playerSkill",
            "DataObject": {
                "skillDetail": {
                    "mu": 16.0,
                    "sigma": 2.0
                }
            }
        }
    ],
    "Entity": {
        "Id": "A8140AB9109712B",
        "Type": "title_player_account",
        "TypeString": "title_player_account"
    }
}
```

以此玩家建立票證時，具有下列設定的佇列會擷取值 16.0，以用於其 `DifferenceRule` 規則。

<Note>
  在 `Path` 欄位中，根目錄之後的第一個項目是 `ObjectName`，可讓您選擇要參考哪個已儲存的物件。
</Note>

```json theme={null}
"MatchmakingQueue": {
    "Name": "PlayerEntityRuleQueue",
    "MinMatchSize": 2,
    "MaxMatchSize": 2,
    "ServerAllocationEnabled": false,
    "Rules": [
        {
            "Type": "DifferenceRule",
            "Difference": 1,
            "MergeFunction": "Average",
            "Attribute": {
                "Path": "$.playerSkill.skillDetail.mu",
                "Source": "PlayerEntity"
            },
            "AttributeNotSpecifiedBehavior": "MatchAny",
            "Weight": 1,
            "Name": "SkillRule",
            "SecondsUntilOptional": 10
        }
    ]
}
```

## 特殊格式

大多數規則使用的屬性都是字串或數值，也就是 JSON 格式的這些值。需要傳入更複雜屬性的規則列於下方。

### 區域選取規則

區域選取規則需要具有指定結構描述的延遲測量值陣列。下列範例是區域選取規則預期的屬性格式，並與 `CreateMatchmakingTicket` 要求範例中使用的兩個屬性並列以供比較。

```json theme={null}
POST https://{{TitleId}}.playfabapi.com/Match/CreateMatchmakingTicket
{
    "Creator": {
        "Entity": {
            "Id": "A8140AB9109712B",
            "Type": "title_player_account",
            "TypeString": "title_player_account"
        },
        "Attributes": {
            "DataObject": {
                "mu": 16.0,
                "sigma": 1.8,
                "Latencies": [
                    {
                        "region": "EastUs",
                        "latency": 150
                    },
                    {
                        "region": "WestUs",
                        "latency": 400
                    }
                ]
            }
        }
    },
    "MembersToMatchWith": [],
    "GiveUpAfterSeconds": 2,
    "QueueName": "ServerEnabledQueue"
}
```

在此範例中，`Latencies` 必須與規則中 `Path` 欄位所參考的欄位相符。下方佇列中包含會使用 `Latencies` 欄位的規則範例。

```json theme={null}
"MatchmakingQueue": {
    "Name": "ServerEnabledQueue",
    "MinMatchSize": 2,
    "MaxMatchSize": 2,
    "ServerAllocationEnabled": true,
    "BuildId": "88b3e315-829c-4b6d-9872-74f427ad5331",
    "Rules": [
        {
            "Type": "RegionSelectionRule",
            "MaxLatency": 1000,
            "Path": "Latencies",
            "Weight": 1,
            "Name": "RegionRule",
            "SecondsUntilOptional": 60
        }
    ]
}
```

<Note>
  對已啟用伺服器配置的佇列使用區域選取規則時，區域必須是有效的 Azure 區域。您可以在[這裡](/zh-TW/services/playfab/api-references/events/data-types/azureregion)找到有效的 Azure 區域清單。
</Note>


## Related topics

- [對等連線的因應措施](/zh-TW/services/playfab/multiplayer/matchmaking/peer-to-peer.md)
- [了解配對中的規則權數](/zh-TW/services/playfab/multiplayer/matchmaking/rule-weights.md)
- [配對](/zh-TW/services/playfab/multiplayer/matchmaking/index.md)
- [使用 SmartMatch 配對](/zh-TW/services/xbox-services/multiplayer/matchmaking/concepts/live-matchmaking-how-tos.md)
- [屬性](/zh-TW/publishing/game-publishing/concepts/properties-overview.md)
