# Quest Steps

**Quest Steps**, at runtime, will live on `GameQuest` objects: `GameQuest.questSteps`

While they can be set up to run automatically, in many cases, you may wish to manually process the status, or otherwise make use of the `QuestStep.cs` class.

## Check For Completion

The `CheckForCompletion()` method will return `true` (and do nothing else) if the `QuestStep` has already been completed (success or failure), and can not revert.

Otherwise, it will first run the `CheckForSuccess()` method. If that returns `true`, meaning we just now marked the `QuestStep` successful, then the method will also return `true`.

Otherwise, it will then run the `CheckForFailure()` method. Again, if that returns `true`, meaning we just now marked the `QuestStep` as failed, then the method will return `true`.

Otherwise, it will return `false`.

#### Example

The code below first calls `CheckForCompletion()` only if the quest is currently "In Progress", which will actively try to complete the quest based on the Quest Conditions. If it does, we call one method if the status is now "Succeeded", and another if it is not. (i.e. "Failed").

```csharp
// In this example, we are checking to see if a specific QuestStep has been
// completed. If so, we will do additional things beyond all the automatic stuff
// that is done when a QuestStep completes.

if (questStepOfInterest.status == QuestStepStatus.InProgress 
    && questStepOfInterest.CheckForCompletion())
{
    if (questStepOfInterest.status == QuestStepStatus.Succeeded)
        DoSomethingWeSucceeded();
    else
        DoSomethingWeFailed();
}

```

## Set Succeeded and Set Failed

Both `SetSucceeded()` and `SetFailed()` will `return` (not do anything) if the status is already set to successful or failed.

Otherwise, they will set the status appropriately, bypassing any `QuestConditions`. Each method also has an optional `bool` parameter `forceCanNotRevert`, which is `false` by default. If true, the `QuestStep` value for `canRevert` will be set `false`, meaning that it will not revert back to a previous status. (Unless you manually do that, of course).

These are great methods to use if you'd like to skip the `QuestStep` to a finished state, bypassing all of the conditions that are otherwise required.

## Set Succeeded or Failed if Not Completed

The `SetFailedIfNotCompleted()` and `SetSucceededIfNotCompleted()` methods first check if the opposite status is already set, and if the status can't revert, then it will return and do no actions.

If the status can revert, or if the status has not yet been marked as successful / failed, it will `CheckForSuccess()` or `CheckForFailure()`.

If that check returns false, then `SetFailed()` or `SetSucceeded()` will be called, failing or succeeding the `QuestStep` immediately.

## Set Can Revert

Defaulting to `true`, you can set the `canRevert` value to `true` or `false`.

## Add Custom  Rewards

Using `AddCustomRewardSuccess()` or `AddCustomRewardFailure()` methods, you can pass in a `QuestReward` value to be added to the respective custom reward lists. This is a great way to customize quests, perhaps providing specific rewards based on in-game actions or other data.

{% hint style="info" %}
We use a `CustomQuestReward` object in these lists. `QuestRewards` can not be serialized, so the `CustomQuestReward`, which can be serialized, will store the `Uid()` of the rewards, and auto-populate at runtime.
{% endhint %}

Whenever `SetSucceeded()` or `SetFailed()` change the status of the quest, the rewards will be given. The `QuestStep` will call the `GiveQuestStepRewards()` method on the parent `GameQuest` object, passing in the lists of rewards and custom rewards.

{% hint style="warning" %}
If `canRevert` is `true`, the rewards for success or failure may be given multiple times!
{% endhint %}

## Remove Custom Rewards

You can remove rewards from the custom rewards lists with `RemoveCustomRewardSuccess()` and `RemoveCustomRewardFailure()` and passing in a `QuestReward`.

## Add Success or Failure Conditions

You can pass a `QuestCondition` into `AddSuccessCondition()` or `AddFailureCondition()` to add those to the respective lists. They will not be added if the condition already exists in the list.

## Remove Condition

Passing in a `QuestCondition` to `RemoveCondition()` will remove it from `successConditions` and `failureConditions`. Generally it would only be present in one, but the method will attempt to remove it from both lists.

If you'd like to specify which list the `QuestCondition` should be removed from, call `RemoveSuccessCondition()` or `RemoveFailureCondition()`.


---

# 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://infinitypbr.gitbook.io/magic-pig-games/game-modules-4/module-documentation/quests/quest-steps.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.
