# GameQuest

`GameQuest` is the in-game, runtime object to use, representing a Quest made with the Quest module.

{% code title="GameQuest.cs" %}

```csharp
// View GameQuest.cs for all the methods (There are more!!)

// Get the IHaveQuests owner of this
public IHaveQuests Owner

// Get the "Quest" Scriptable Object
public Quest Parent() 

// Get the in-game unique GameId of this
public virtual string GameId(bool forceNew = false)

// Get the name and type of this
public string ObjectName()
public string ObjectType()

// Get the QuestStepStatus status
public QuestStep.QuestStepStatus status
```

{% endcode %}

## Creating a GameQuest

Generally a `GameQuest` will live inside a `GameQuestList`.&#x20;

## Get `List<QuestStep>`

Each `Quest` will have a list of `QuestStep` objects.

```csharp
// All of the QuestSteps
public List<QuestStep> questSteps

// List of QuestSteps based on status
public List<QuestStep> QuestStepsInProgress
public List<QuestStep> QuestStepsSucceeded
public List<QuestStep> QuestStepsFailed
```

## Custom Rewards

You can add custom `QuestReward` objects at runtime, enabling customization of quests based on in game behavior or player choices.

```csharp
// Custom Rewards
public List<CustomQuestReward> customSuccessRewards
public List<CustomQuestReward> customFailureRewards

// Add Custom Rewards
public void AddCustomRewardSuccess(QuestReward questReward)
public void AddCustomRewardFailure(QuestReward questReward)

// Remove Custom Rewards
public void RemoveCustomRewardSuccess(QuestReward questReward)
public void RemoveCustomRewardFailure(QuestReward questReward)
```

## Quest Expiration

Quests can optionally expire, and you can check the status. `CheckExpiration()` will return `false` if the Quest either does not expire, or has not expired. Otherwise it will return `true`, and do additional actions based on the Quest settings.

```csharp
private bool CheckExpiration()
{
    if (!Parent().hasEndTime) return false; // This has no end time
    if (endTime > Now()) return false; // We have not yet reached the end time
            
    // We've reached the end time. Options are to simply expire, or to auto succeed or fail.
    if (Parent().succeedOnExpiration)
    {
        SetStepsSucceeded(true);
        return true;
    }

    if (Parent().failOnExpiration)
    {
        SetStepsFailed(true);
        return true;
    }
            
    // We will remove on expiration, without succeeding or failing...simply removing.
    RemoveQuestOperations();
    gameQuestList.RemoveGameId(GameId());
    return true;
}
```

You can also extend the time, or reduce it by adding a negative value:

```csharp
public float ExtendEndTime(float valueAdd)
```

## Force Quest Completion

You can for the `GameQuest` to complete as succeeded or failed. The rewards and all "end" operations will trigger.

```csharp
public bool CompleteQuestSuccess()
public bool CompleteQuestFail()
```

## Other methods

```csharp
// Run the GiveRewardS() method, which you can do outside of the automation
// if you'd like
GiveRewards(Parent().failureRewards);
GiveRewards(Parent().successRewards);
GiveCustomRewards(customFailureRewards);
GiveCustomRewards(customSuccessRewards);
```


---

# 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/gamequest.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.
