Esempio n. 1
0
    //When Interacting with a character, we ask the quest manager if there's a quest that starts with a step with a certain character
    void StartQuest(ActorSO actorToCheckWith)
    {
        if (_currentQuest != null)        //check if there's a current quest
        {
            return;
        }

        if (_currentQuestline != null)
        {
            //find quest index
            _currentQuestIndex = _currentQuestline.Quests.FindIndex(o => !o.IsDone && o.Steps != null && o.Steps[0].Actor == actorToCheckWith);

            if ((_currentQuestline.Quests.Count > _currentQuestIndex) && (_currentQuestIndex >= 0))
            {
                _currentQuest = _currentQuestline.Quests[_currentQuestIndex];
                //start Step
                _currentStepIndex = 0;
                _currentStepIndex = _currentQuest.Steps.FindIndex(o => o.IsDone == false);
                if (_currentStepIndex >= 0)
                {
                    StartStep();
                }
            }
        }
    }
Esempio n. 2
0
    public void ResetQuestlines()
    {
        foreach (var questline in _questlines)
        {
            questline.IsDone = false;


            foreach (var quest in questline.Quests)
            {
                quest.IsDone = false;


                foreach (var step in quest.Steps)
                {
                    step.IsDone = false;
                }
            }
        }
        _currentQuest          = null;
        _currentQuestline      = null;
        _currentStep           = null;
        _currentQuestIndex     = 0;
        _currentQuestlineIndex = 0;
        _currentStepIndex      = 0;
        //Start Questline with the new data
        StartQuestline();
    }
    private void LoadAllQuestsData()
    {
        //Load all questlines
        FindAllSOByType(out QuestlineSO[] questLineSOs);
        RefreshListView(out ListView allQuestlinesListView, "questlines-list", questLineSOs);
        ClearElements(SelectionType.Questline);
        allQuestlinesListView.onSelectionChange += (questlineEnumerable) =>
        {
            _currentSelectedQuestLine = GetDataFromListViewItem <QuestlineSO>(questlineEnumerable);
            ClearElements(SelectionType.Questline);
            _idQuestlineSelected = allQuestlinesListView.selectedIndex;

            if (_currentSelectedQuestLine.Quests != null)
            {
                RefreshListView(out ListView allQuestsListView, "quests-list", _currentSelectedQuestLine.Quests.ToArray());

                allQuestsListView.onSelectionChange += (questEnumerable) =>
                {
                    _idQuestSelected = allQuestsListView.selectedIndex;

                    _currentSeletedQuest = GetDataFromListViewItem <QuestSO>(questEnumerable);
                    ClearElements(SelectionType.Quest);
                    if (_currentSeletedQuest != null && _currentSeletedQuest.Steps != null)
                    {
                        RefreshListView(out ListView allStepsListView, "steps-list", _currentSeletedQuest.Steps.ToArray());

                        SetUpQuestPreview(_currentSeletedQuest);

                        allStepsListView.onSelectionChange += (stepEnumerable) =>
                        {
                            _idStepSelected      = allStepsListView.selectedIndex;
                            _currentSelectedStep = GetDataFromListViewItem <StepSO>(stepEnumerable);
                            DisplayAllProperties(_currentSelectedStep, "step-info-scroll");
                            ClearElements(SelectionType.Step);
                            //Find all DialogueDataSOs in the same folder of the StepSO
                            FindAllDialogueInStep(_currentSelectedStep, out DialogueDataSO[] dialogueDataSOs);
                            if (dialogueDataSOs != null)
                            {
                                RefreshListView(out ListView dialoguesListView, "dialogues-list", dialogueDataSOs);

                                dialoguesListView.onSelectionChange += (dialogueEnumerable) =>
                                {
                                    DialogueDataSO dialogueData = GetDataFromListViewItem <DialogueDataSO>(dialogueEnumerable);
                                    DisplayAllProperties(dialogueData, "dialogue-info-scroll");
                                };
                            }
                            VisualElement DialogueList = rootVisualElement.Q <VisualElement>("dialogues-list");
                            SetAddDialogueButtonsForStep(out VisualElement ButtonsPanel);
                            //DialogueList.Q<VisualElement>("buttons-panel").Clear();
                            DialogueList.Add(ButtonsPanel);
                        };
                    }
                };
            }
        };
    }
    private void LoadAllQuestsData()
    {
        Debug.Log("LoadAllQuestsData");
        //Load all questlines
        FindAllSOByType(out QuestlineSO[] questLineSOs);
        RefreshListView(out ListView allQuestlinesListView, "questlines-list", questLineSOs);

        allQuestlinesListView.onSelectionChange += (questlineEnumerable) =>
        {
            selectedQuestLine = GetDataFromListViewItem <QuestlineSO>(questlineEnumerable);
            ClearElements(selectionType.Questline);
            idQuestlineSelected = allQuestlinesListView.selectedIndex;

            if (selectedQuestLine.Quests != null)
            {
                RefreshListView(out ListView allQuestsListView, "quests-list", selectedQuestLine.Quests.ToArray());



                allQuestsListView.onSelectionChange += (questEnumerable) =>
                {
                    idQuestSelected = allQuestsListView.selectedIndex;

                    currentSeletedQuest = GetDataFromListViewItem <QuestSO>(questEnumerable);
                    ClearElements(selectionType.Quest);
                    if (currentSeletedQuest != null && currentSeletedQuest.Steps != null)
                    {
                        RefreshListView(out ListView allStepsListView, "steps-list", currentSeletedQuest.Steps.ToArray());

                        SetUpQuestPreview(currentSeletedQuest);

                        allStepsListView.onSelectionChange += (stepEnumerable) =>
                        {
                            StepSO step = GetDataFromListViewItem <StepSO>(stepEnumerable);
                            DisplayAllProperties(step, "step-info-scroll");
                            ClearElements(selectionType.Step);
                            //Find all DialogueDataSOs in the same folder of the StepSO
                            FindAllDialogueInStep(step, out DialogueDataSO[] dialogueDataSOs);
                            if (dialogueDataSOs != null)
                            {
                                RefreshListView(out ListView dialoguesListView, "dialogues-list", dialogueDataSOs);

                                dialoguesListView.onSelectionChange += (dialogueEnumerable) =>
                                {
                                    DialogueDataSO dialogueData = GetDataFromListViewItem <DialogueDataSO>(dialogueEnumerable);

                                    DisplayAllProperties(dialogueData, "dialogue-info-scroll");
                                };
                            }
                        };
                    }
                };
            }
        };
    }
Esempio n. 5
0
    public bool CompleteQuestfromCurrent(QuestSO quest)
    {
        if (currentQuests.Contains(quest))
        {
            currentQuests.Remove(quest);
            completedQuests.Add(quest);
            return(true);
        }

        return(false);
    }
Esempio n. 6
0
 public void ForceCompletedQuest(QuestSO quest)
 {
     if (!completedQuests.Contains(quest))
     {
         if (currentQuests.Contains(quest))
         {
             currentQuests.Remove(quest);
             completedQuests.Add(quest);
         }
         else
         {
             completedQuests.Add(quest);
         }
     }
 }
    void RemoveQuest(QuestSO questToRemove)
    {
        if (questToRemove == null)
        {
            return;
        }
        //when removing a step remove its dialogues
        foreach (StepSO step in questToRemove.Steps)
        {
            //When removing a step, remove its references in the parent quest
            RemoveStep(step);
        }

        AssetDatabase.DeleteAsset(questToRemove.GetPath());
    }
Esempio n. 8
0
 public void addToCurrentQuests(QuestSO quest)
 {
     if (questExistsInCurrentQuests(quest))
     {
         Debug.Log(quest.name + " already exist in current quests");
     }
     else if (questExistsInCompletedQuests(quest))
     {
         Debug.Log(quest.name + " already exsist in completed quests");
     }
     else
     {
         Debug.Log("Added " + quest.name + " to current quests");
         currentQuests.Add(quest);
     }
 }
Esempio n. 9
0
 QuestSO findQuestByQuest(QuestSO quest, List <QuestSO> quests)
 {
     if (quests.Count < 1)
     {
         return(null);
     }
     foreach (QuestSO forQuest in quests)
     {
         //Debug.Log("comparing " + forQuest.name + " with " + quest.name);
         if (forQuest == quest)
         {
             return(quest);
         }
     }
     Debug.Log("Couldn't find a quest with the name '" + quest.name);
     return(null);
 }
Esempio n. 10
0
    void EndQuest()
    {
        if (_currentQuest != null)
        {
            _currentQuest.FinishQuest();
        }

        _currentQuest      = null;
        _currentQuestIndex = -1;
        if (_currentQuestline != null)
        {
            if (!_currentQuestline.Quests.Exists(o => !o.IsDone))
            {
                EndQuestline();
            }
        }
    }
    void AddQuest()
    {
        QuestSO asset       = ScriptableObject.CreateInstance <QuestSO>();
        int     questlineId = 0;

        questlineId = selectedQuestLine.IdQuestline;
        int questId = 0;

        questId = selectedQuestLine.Quests.Count + 1;
        AssetDatabase.CreateFolder("Assets/ScriptableObjects/Quests/Questline" + questlineId, "Quest" + questId);
        AssetDatabase.CreateAsset(asset, "Assets/ScriptableObjects/Quests/Questline" + questlineId + "/Quest" + questId + "/Q" + questId + "-QL" + questlineId + ".asset");
        AssetDatabase.SaveAssets();
        asset.SetQuestId(questId);
        selectedQuestLine.Quests.Add(asset);
        //refresh
        rootVisualElement.Q <VisualElement>("questlines-list").Q <ListView>().SetSelection(idQuestlineSelected);
    }
    void RemoveQuestline()
    {
        if (_currentSelectedQuestLine == null)
        {
            return;
        }

        while (_currentSelectedQuestLine.Quests.Count > 0)
        {
            QuestSO quest = _currentSelectedQuestLine.Quests[0];
            RemoveQuest(quest);
            _currentSelectedQuestLine.Quests.RemoveAt(0);
        }
        AssetDatabase.DeleteAsset(_currentSelectedQuestLine.GetPath());
        //refresh List
        LoadAllQuestsData();
    }
    private void SetUpQuestPreview(QuestSO quest)
    {
        if (quest == null)
        {
            return;
        }
        if (quest.Steps == null)
        {
            return;
        }

        rootVisualElement.Q <VisualElement>("actor-conversations").Clear();

        foreach (StepSO step in quest.Steps)
        {
            LoadAndInitStepUXML(step);
        }
    }
Esempio n. 14
0
 public void addToCompletedQuests(QuestSO quest)
 {
     if (questExistsInCompletedQuests(quest))
     {
         Debug.Log(quest.name + " already exsist in completed quests");
     }
     else
     {
         if (questExistsInCurrentQuests(quest))
         {
             currentQuests.Remove(quest);
             completedQuests.Add(quest);
         }
         else
         {
             Debug.Log(quest.name + " dosen't exist in current quests");
         }
     }
 }
Esempio n. 15
0
 public void addToCompletedQuests(string name)
 {
     if (questExistsInCompletedQuests(name))
     {
         Debug.Log(name + " already exsist in completed quests");
     }
     else
     {
         if (questExistsInCurrentQuests(name))
         {
             QuestSO quest = findQuestInCurrentQuests(name);
             currentQuests.Remove(quest);
             completedQuests.Add(quest);
         }
         else
         {
             Debug.Log(name + " dosen't exist in current quests");
         }
     }
 }
    private void SetUpQuestPreview(QuestSO quest)
    {
        if (quest == null)
        {
            return;
        }
        if (quest.Steps == null)
        {
            return;
        }
        if (quest.Steps.Count > 0 && quest.Steps[0].Actor != null)
        {
            LoadActorImage(quest.Steps[0].Actor.name);
        }

        //Clear actor conversations area
        rootVisualElement.Q <VisualElement>("actor-conversations").Clear();

        foreach (StepSO step in quest.Steps)
        {
            LoadAndInitStepUXML(step);
        }
    }
    void AddQuest()
    {
        QuestSO asset       = CreateInstance <QuestSO>();
        int     questlineId = 0;

        questlineId = _currentSelectedQuestLine.IdQuestline;
        int questId = 0;

        questId = _currentSelectedQuestLine.Quests.Count + 1;


        if (!AssetDatabase.IsValidFolder("Assets/ScriptableObjects/Quests/Questline" + questlineId + "/Quest" + questId))
        {
            AssetDatabase.CreateFolder("Assets/ScriptableObjects/Quests/Questline" + questlineId, "Quest" + questId);
        }
        AssetDatabase.CreateAsset(asset, "Assets/ScriptableObjects/Quests/Questline" + questlineId + "/Quest" + questId + "/Q" + questId + "-QL" + questlineId + ".asset");
        asset.SetQuestId(questId);
        _currentSelectedQuestLine.Quests.Add(asset);
        EditorUtility.SetDirty(asset);
        EditorUtility.SetDirty(_currentSelectedQuestLine);
        AssetDatabase.SaveAssets();
        //refresh
        rootVisualElement.Q <VisualElement>("questlines-list").Q <ListView>().SetSelection(_idQuestlineSelected);
    }
Esempio n. 18
0
 public bool questExistsInCurrentQuests(QuestSO quest)
 {
     return(currentQuests.Contains(findQuestInCurrentQuests(quest)));
 }
Esempio n. 19
0
 public bool questExistsInCompletedQuests(QuestSO quest)
 {
     return(completedQuests.Contains(findQuestInCompletedQuests(quest)));
 }
Esempio n. 20
0
 QuestSO findQuestInCurrentQuests(QuestSO quest)
 {
     return(findQuestByQuest(quest, currentQuests));
 }
Esempio n. 21
0
 QuestSO findQuestInCompletedQuests(QuestSO quest)
 {
     return(findQuestByQuest(quest, completedQuests));
 }