Пример #1
0
        /// <summary>
        /// Adds an instance of a quest to a quester's list. If the quest's maxTimes are reached,
        /// deletes the quest from the giver. Otherwise starts cooldown timer until it can be
        /// given again.
        /// </summary>
        /// <param name="quest">Quest to give to quester.</param>
        /// <param name="questerQuestListContainer">Quester's quest list container.</param>
        public virtual void GiveQuestToQuester(Quest quest, QuestListContainer questerQuestListContainer)
        {
            if (quest == null)
            {
                return;
            }
            if (questerQuestListContainer == null)
            {
                Debug.LogWarning("Quest Machine: " + name + ".GiveQuestToQuester - quester (QuestListContainer) is null.", this);
                return;
            }
            var questerTextInfo = new QuestParticipantTextInfo(QuestMachineMessages.GetID(questerQuestListContainer.gameObject), QuestMachineMessages.GetDisplayName(questerQuestListContainer.gameObject), null, null);

            GiveQuestToQuester(quest, questerTextInfo, questerQuestListContainer);
        }
Пример #2
0
        /// <summary>
        /// Starts dialogue with the player. The content of the dialogue will depend on the quest giver's
        /// offerable quests and the player's quests.
        /// </summary>
        /// <param name="player">Player conversing with this QuestGiver. If null, searches the scene for a GameObject tagged Player.</param>
        public virtual void StartDialogue(GameObject player)
        {
            if (questDialogueUI == null && Debug.isDebugBuild)
            {
                Debug.LogWarning("Quest Machine: Can't start dialogue with " + name + ". Quest Giver doesn't have access to a quest dialogue UI.", this);
                return;
            }

            // If player isn't specified, find it in the scene and find relevant quest journal:
            if (player == null)
            {
                player = FindPlayerGameObject();
            }
            if (player == null && Debug.isDebugBuild)
            {
                Debug.LogWarning("Quest Machine: Can't start dialogue with " + name + ". No quester specified.", this);
                return;
            }
            playerQuestListContainer = player.GetComponent <QuestListContainer>();
            if (playerQuestListContainer == null)
            {
                var playerID = player.GetComponent <QuestMachineID>();
                if (playerID != null && playerID.questListContainer != null)
                {
                    playerQuestListContainer = playerID.questListContainer;
                }
                else
                {
                    var playerJournalObject = FindPlayerJournalGameObject();
                    playerQuestListContainer = (playerJournalObject != null) ? playerJournalObject.GetComponent <QuestListContainer>() : null;
                }
            }
            if (playerQuestListContainer == null && Debug.isDebugBuild)
            {
                Debug.LogWarning("Quest Machine: Can't start dialogue with " + name + ". Quester " + player.name + " doesn't have a Quest Journal and can't find one in scene.", this);
                return;
            }

            QuestMachineTags.fallbackTextTable = textTable;

            // Setup player info:
            this.player    = player;
            playerTextInfo = new QuestParticipantTextInfo(QuestMachineMessages.GetID(player), QuestMachineMessages.GetDisplayName(player), null, null);

            // Greet before recording quests in case Greet message changes a quest state:
            QuestMachineMessages.Greet(player, this, id);

            // Record quests related to this player and me:
            RecordQuestsByState();

            StartMostRelevantDialogue();

            // Note: Sends Greeted immediately after opening dialogue UI, not when closing it:
            QuestMachineMessages.Greeted(player, this, id);
        }