Page 1 of 6

Quest Generation (Domains)

Posted: Mon Feb 18, 2019 9:16 am
by dlevel
Hello!

I'm trying to create some generated quest functionality in my game, and especially when the player is inside the dungeons. What I cannot understand after following the step by step documentation guide, is that I see the Quest Domains in 2D are marked easily, in 3D is the same method? I just create an empty object and selecting the area which is the Domain in a collider?? Also my dungeons are runtime generated, should I just save the domain in a prefab and spawn it after the dungeon is created? Is my workflow thinking correct?

Re: Quest Generation (Domains)

Posted: Mon Feb 18, 2019 10:14 am
by Tony Li
Yes, that's all correct. 3D works the same as 2D. Your domain needs a trigger collider and a QuestDomain component with a DomainType asset assigned to it. Make sure the layers are set up to detect QuestEntities in the trigger collider. Prefabs are fine. You'll also want to assign the domain to one or more quest givers.

Re: Quest Generation (Domains)

Posted: Mon Feb 18, 2019 10:48 am
by dlevel
figured it out :)

Re: Quest Generation (Domains)

Posted: Mon Feb 18, 2019 11:26 am
by dlevel
One little issue I have is getting the domain in the Quest Giver after it instantiates (domain is on scene, the NPC prefab is not). If you have a small script to plug in the NPC to get the Domain or can guide me to make one would be nice. Thank you.

Re: Quest Generation (Domains)

Posted: Mon Feb 18, 2019 11:52 am
by Tony Li
Hi,

Add this script to your quest giver, and assign DomainType assets. It will find corresponding QuestDomains in Start. You can call its AddMyDomains() method manually if the QuestDomains aren't ready yet in Start.

FindQuestGiverDomains.cs

Code: Select all

using UnityEngine;
using PixelCrushers.QuestMachine;
using System.Collections.Generic;

[RequireComponent(typeof(QuestGeneratorEntity))]
public class FindQuestGiverDomains : MonoBehaviour
{
    public List<DomainType> domainTypes;

    void Start()
    {
        AddMyDomains();
    }

    public void AddMyDomains()
    {
        var generator = GetComponent<QuestGeneratorEntity>();
        var domains = new List<QuestDomain>(generator.domains);
        foreach (var domain in FindObjectsOfType<QuestDomain>())
        {
            var wantThisDomain = domainTypes.Contains(domain.domainType);
            var alreadyHaveThisDomain = domains.Find(x => x.domainType == domain.domainType) != null;
            if (wantThisDomain && !alreadyHaveThisDomain)
            {
                domains.Add(domain);
            }
        }
        generator.domains = domains.ToArray();
    }
}

Re: Quest Generation (Domains)

Posted: Mon Feb 18, 2019 12:37 pm
by dlevel
hmmm, can't get it to work, I put my domain type which is the same I have in the Domain that I have in the scene, I run it also manually, but still doesn't gets the domain gameobject in quest giver Domains. Thanks btw :)

Re: Quest Generation (Domains)

Posted: Mon Feb 18, 2019 12:44 pm
by Tony Li
Are you sure the QuestDomains are in place before the script runs its AddMyDomains() method?

Also, make sure you're using the exact same DomainType asset in the QuestDomain and this script, not two separate assets that have the same name.

As a test to get an idea of how it works, you can open the Demo scene and clear the Knight's domains list. Add the script and assign the Field and Forest DomainTypes. When you play, the script should add the domains to the Knight's domains list. should

Re: Quest Generation (Domains)

Posted: Mon Feb 18, 2019 12:54 pm
by dlevel
I tried it on the knight, same results :) (the photo is on runtime)

https://ibb.co/C7yPh4x

Re: Quest Generation (Domains)

Posted: Mon Feb 18, 2019 1:14 pm
by Tony Li
Set the Quest Generator Entity's Domains > Size to zero, or add a null check in the script's loop.

Re: Quest Generation (Domains)

Posted: Mon Feb 18, 2019 1:20 pm
by dlevel
same, stays on 0